1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ 2 3 #ifndef WEAPON_PROJECTILE_H 4 #define WEAPON_PROJECTILE_H 5 6 #include "Sim/Projectiles/Projectile.h" 7 #include "Sim/Projectiles/ProjectileParams.h" // easier to include this here 8 #include "WeaponProjectileTypes.h" 9 10 struct WeaponDef; 11 struct ProjectileParams; 12 class CVertexArray; 13 class CPlasmaRepulser; 14 15 16 17 /** 18 * Base class for all projectiles originating from a weapon or having 19 * weapon-properties. Uses data from a weapon definition. 20 */ 21 class CWeaponProjectile : public CProjectile 22 { 23 CR_DECLARE(CWeaponProjectile) 24 public: 25 CWeaponProjectile(); 26 CWeaponProjectile(const ProjectileParams& params); ~CWeaponProjectile()27 virtual ~CWeaponProjectile() {} 28 29 virtual void Explode(CUnit* hitUnit, CFeature* hitFeature, float3 impactPos, float3 impactDir); 30 virtual void Collision(); 31 virtual void Collision(CFeature* feature); 32 virtual void Collision(CUnit* unit); 33 virtual void Update(); 34 /// @return 0=unaffected, 1=instant repulse, 2=gradual repulse ShieldRepulse(CPlasmaRepulser * shield,float3 shieldPos,float shieldForce,float shieldMaxSpeed)35 virtual int ShieldRepulse(CPlasmaRepulser* shield, float3 shieldPos, float shieldForce, float shieldMaxSpeed) { return 0; } 36 37 virtual void DrawOnMinimap(CVertexArray& lines, CVertexArray& points); 38 39 void DependentDied(CObject* o); 40 void PostLoad(); 41 SetTargetObject(CWorldObject * newTarget)42 void SetTargetObject(CWorldObject* newTarget) { 43 if (newTarget != NULL) { 44 targetPos = newTarget->pos; 45 } 46 47 target = newTarget; 48 } 49 GetTargetObject()50 const CWorldObject* GetTargetObject() const { return target; } GetTargetObject()51 CWorldObject* GetTargetObject() { return target; } 52 GetWeaponDef()53 const WeaponDef* GetWeaponDef() const { return weaponDef; } 54 SetStartPos(const float3 & newStartPos)55 void SetStartPos(const float3& newStartPos) { startPos = newStartPos; } SetTargetPos(const float3 & newTargetPos)56 void SetTargetPos(const float3& newTargetPos) { targetPos = newTargetPos; } 57 GetStartPos()58 const float3& GetStartPos() const { return startPos; } GetTargetPos()59 const float3& GetTargetPos() const { return targetPos; } 60 SetBeingIntercepted(bool b)61 void SetBeingIntercepted(bool b) { targeted = b; } IsBeingIntercepted()62 bool IsBeingIntercepted() const { return targeted; } 63 64 bool TraveledRange() const; 65 66 protected: 67 void UpdateInterception(); 68 virtual void UpdateGroundBounce(); 69 70 protected: 71 const WeaponDef* weaponDef; 72 73 CWorldObject* target; 74 75 unsigned int weaponDefID; 76 77 int ttl; 78 int bounces; 79 80 /// true if we are an interceptable projectile 81 // and an interceptor projectile is on the way 82 bool targeted; 83 84 float3 startPos; 85 float3 targetPos; 86 }; 87 88 #endif /* WEAPON_PROJECTILE_H */ 89