~ubuntu-branches/ubuntu/natty/spring/natty

« back to all changes in this revision

Viewing changes to rts/Sim/Projectiles/WeaponProjectiles/ExplosiveProjectile.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Ritchie
  • Date: 2010-09-23 18:56:03 UTC
  • mfrom: (3.1.9 experimental)
  • Revision ID: james.westby@ubuntu.com-20100923185603-st97s5chplo42y7w
Tags: 0.82.5.1+dfsg1-1ubuntu1
* Latest upstream version for online play
* debian/control: Replace (rather than conflict) spring-engine
  - spring-engine will be a dummy package (LP: #612905)
  - also set maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ExplosiveProjectile.cpp: implementation of the CExplosiveProjectile class.
2
 
//
3
 
//////////////////////////////////////////////////////////////////////
 
1
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
4
2
 
5
3
#include "StdAfx.h"
6
4
#include "mmgr.h"
10
8
#include "Map/Ground.h"
11
9
#include "Rendering/GL/VertexArray.h"
12
10
#include "Rendering/Textures/ColorMap.h"
 
11
#include "Rendering/Textures/TextureAtlas.h"
13
12
#include "Sim/Misc/InterceptHandler.h"
14
13
#include "Sim/Projectiles/ProjectileHandler.h"
15
14
#include "Sim/Weapons/WeaponDef.h"
16
 
#include "GlobalUnsynced.h"
17
15
 
18
16
#ifdef TRACE_SYNC
19
 
        #include "Sync/SyncTracer.h"
 
17
        #include "System/Sync/SyncTracer.h"
20
18
#endif
21
19
 
22
20
CR_BIND_DERIVED(CExplosiveProjectile, CWeaponProjectile, (float3(0, 0, 0), float3(0, 0, 0), NULL, NULL, 1, 0));
31
29
// Construction/Destruction
32
30
//////////////////////////////////////////////////////////////////////
33
31
 
34
 
CExplosiveProjectile::CExplosiveProjectile(const float3& pos,
35
 
                const float3& speed, CUnit* owner, const WeaponDef *weaponDef, int ttl,
36
 
                float areaOfEffect, float g GML_PARG_C):
37
 
        CWeaponProjectile(pos, speed, owner, 0, ZeroVector, weaponDef, 0, ttl GML_PARG_P),
 
32
CExplosiveProjectile::CExplosiveProjectile(
 
33
        const float3& pos, const float3& speed,
 
34
        CUnit* owner, const WeaponDef *weaponDef,
 
35
        int ttl, float areaOfEffect, float g):
 
36
 
 
37
        CWeaponProjectile(pos, speed, owner, 0, ZeroVector, weaponDef, 0, ttl),
38
38
        areaOfEffect(areaOfEffect),
39
39
        curTime(0)
40
40
{
 
41
        projectileType = WEAPON_EXPLOSIVE_PROJECTILE;
 
42
 
41
43
        //! either map or weaponDef gravity
42
44
        mygravity = g;
43
45
        useAirLos = true;
58
60
#endif
59
61
 
60
62
 
61
 
        if (cegTag.size() > 0) {
 
63
        if (!cegTag.empty()) {
62
64
                ceg.Load(explGenHandler, cegTag);
63
65
        }
64
66
}
70
72
 
71
73
void CExplosiveProjectile::Update()
72
74
{
73
 
        pos += speed;
74
 
        speed.y += mygravity;
75
 
        ttl--;
 
75
        if (!luaMoveCtrl) {
 
76
                pos += speed;
 
77
                speed.y += mygravity;
 
78
        }
76
79
 
77
 
        if (ttl == 0) {
 
80
        if (--ttl == 0) {
78
81
                Collision();
79
82
        } else {
80
 
                if (cegTag.size() > 0 && ttl > 0) {
 
83
                if (!cegTag.empty() && ttl > 0) {
81
84
                        ceg.Explosion(pos, ttl, areaOfEffect, 0x0, 0.0f, 0x0, speed);
82
85
                }
83
86
        }
117
120
 
118
121
void CExplosiveProjectile::Draw(void)
119
122
{
120
 
        if (s3domodel) { //dont draw if a 3d model has been defined for us
 
123
        if (model) { //dont draw if a 3d model has been defined for us
121
124
                return;
122
125
        }
123
126
 
140
143
        const int    stages     = weaponDef->visuals.stages;
141
144
        const float  invStages  = 1.0f / (float)stages;
142
145
 
143
 
        float3 dir = speed;
144
 
        dir.Normalize();
145
 
        dir *= separation * 0.6f;
146
 
 
147
 
        va->EnlargeArrays(stages*4,0,VA_SIZE_TC);
 
146
        const float3 ndir = dir * separation * 0.6f;
 
147
 
 
148
        va->EnlargeArrays(stages * 4,0, VA_SIZE_TC);
 
149
 
148
150
        for (int a = 0; a < stages; ++a) { //! CAUTION: loop count must match EnlargeArrays above
149
151
                const float aDecay = (stages - (a * alphaDecay)) * invStages;
150
152
                col[0] = int(aDecay * col[0]);
155
157
                const float  size  = drawRadius * (1.0f - (a * sizeDecay));
156
158
                const float3 up    = camera->up    * size;
157
159
                const float3 right = camera->right * size;
158
 
                const float3 interPos2 = drawPos - ((noGap)?(dir * size * a):(dir * drawRadius * a));
 
160
                const float3 interPos2 = drawPos - ((noGap)? (ndir * size * a): (ndir * drawRadius * a));
159
161
 
160
162
                va->AddVertexQTC(interPos2 - right - up, tex->xstart, tex->ystart, col);
161
163
                va->AddVertexQTC(interPos2 + right - up, tex->xend,   tex->ystart, col);
164
166
        }
165
167
}
166
168
 
167
 
int CExplosiveProjectile::ShieldRepulse(CPlasmaRepulser* shield,float3 shieldPos, float shieldForce, float shieldMaxSpeed)
 
169
int CExplosiveProjectile::ShieldRepulse(CPlasmaRepulser* shield, float3 shieldPos, float shieldForce, float shieldMaxSpeed)
168
170
{
169
 
        float3 dir = pos - shieldPos;
170
 
        dir.Normalize();
171
 
        if (dir.dot(speed) < shieldMaxSpeed) {
172
 
                speed += dir * shieldForce;
173
 
                return 2;
 
171
        if (!luaMoveCtrl) {
 
172
                const float3 rdir = (pos - shieldPos).Normalize();
 
173
 
 
174
                if (rdir.dot(speed) < shieldMaxSpeed) {
 
175
                        speed += (rdir * shieldForce);
 
176
                        return 2;
 
177
                }
174
178
        }
 
179
 
175
180
        return 0;
176
181
}