1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2
3
4 #include "FlameProjectile.h"
5 #include "Game/Camera.h"
6 #include "Map/Ground.h"
7 #include "Rendering/GL/VertexArray.h"
8 #include "Rendering/Textures/ColorMap.h"
9 #include "Rendering/Textures/TextureAtlas.h"
10 #include "Sim/Projectiles/ProjectileHandler.h"
11 #include "Sim/Weapons/WeaponDef.h"
12
13 CR_BIND_DERIVED(CFlameProjectile, CWeaponProjectile, (ProjectileParams()))
14
15 CR_REG_METADATA(CFlameProjectile,(
16 CR_SETFLAG(CF_Synced),
17 CR_MEMBER(spread),
18 CR_MEMBER(curTime),
19 CR_MEMBER(physLife),
20 CR_MEMBER(invttl),
21 CR_RESERVED(16)
22 ))
23
24
CFlameProjectile(const ProjectileParams & params)25 CFlameProjectile::CFlameProjectile(const ProjectileParams& params):CWeaponProjectile(params)
26 , curTime(0.0f)
27 , physLife(0.0f)
28 , invttl(1.0f / ttl)
29 , spread(params.spread)
30 {
31
32 projectileType = WEAPON_FLAME_PROJECTILE;
33
34 if (weaponDef != NULL) {
35 SetRadiusAndHeight(weaponDef->size * weaponDef->collisionSize, 0.0f);
36 drawRadius = weaponDef->size;
37
38 physLife = 1.0f / weaponDef->duration;
39 }
40 }
41
Collision()42 void CFlameProjectile::Collision()
43 {
44 const float3& norm = CGround::GetNormal(pos.x, pos.z);
45 const float ns = speed.dot(norm);
46
47 SetVelocityAndSpeed(speed - (norm * ns));
48 SetPosition(pos + UpVector * 0.05f);
49
50 curTime += 0.05f;
51 }
52
Update()53 void CFlameProjectile::Update()
54 {
55 if (!luaMoveCtrl) {
56 SetPosition(pos + speed);
57 UpdateGroundBounce();
58 SetVelocityAndSpeed(speed + spread);
59 }
60
61 UpdateInterception();
62
63 radius = radius + weaponDef->sizeGrowth;
64 sqRadius = radius * radius;
65 drawRadius = radius * weaponDef->collisionSize;
66
67 curTime += invttl;
68 if (curTime > physLife) {
69 checkCol = false;
70 }
71 if (curTime > 1) {
72 curTime = 1;
73 deleteMe = true;
74 }
75
76 explGenHandler->GenExplosion(cegID, pos, speed, curTime, 0.0f, 0.0f, NULL, NULL);
77 }
78
Draw()79 void CFlameProjectile::Draw()
80 {
81 inArray = true;
82 unsigned char col[4];
83 weaponDef->visuals.colorMap->GetColor(col, curTime);
84
85 va->AddVertexTC(drawPos - camera->right * radius - camera->up * radius, weaponDef->visuals.texture1->xstart, weaponDef->visuals.texture1->ystart, col);
86 va->AddVertexTC(drawPos + camera->right * radius - camera->up * radius, weaponDef->visuals.texture1->xend, weaponDef->visuals.texture1->ystart, col);
87 va->AddVertexTC(drawPos + camera->right * radius + camera->up * radius, weaponDef->visuals.texture1->xend, weaponDef->visuals.texture1->yend, col);
88 va->AddVertexTC(drawPos - camera->right * radius + camera->up * radius, weaponDef->visuals.texture1->xstart, weaponDef->visuals.texture1->yend, col);
89 }
90
ShieldRepulse(CPlasmaRepulser * shield,float3 shieldPos,float shieldForce,float shieldMaxSpeed)91 int CFlameProjectile::ShieldRepulse(CPlasmaRepulser* shield, float3 shieldPos, float shieldForce, float shieldMaxSpeed)
92 {
93 if (luaMoveCtrl)
94 return 0;
95
96 const float3 rdir = (pos - shieldPos).Normalize();
97
98 if (rdir.dot(speed) < shieldMaxSpeed) {
99 SetVelocityAndSpeed(speed + (rdir * shieldForce));
100 return 2;
101 }
102
103 return 0;
104 }
105
106