1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ 2 3 #ifndef PROJECTILE_H 4 #define PROJECTILE_H 5 6 #include <list> 7 8 #ifdef _MSC_VER 9 #pragma warning(disable:4291) 10 #endif 11 12 #include "ExplosionGenerator.h" 13 #include "System/float3.h" 14 #include "System/type2.h" 15 16 class CUnit; 17 class CFeature; 18 class CVertexArray; 19 class CMatrix44f; 20 21 22 class CProjectile: public CExpGenSpawnable 23 { 24 CR_DECLARE(CProjectile) 25 26 /// used only by creg 27 CProjectile(); 28 29 public: 30 CProjectile( 31 const float3& pos, 32 const float3& spd, 33 const CUnit* owner, 34 bool isSynced, 35 bool isWeapon, 36 bool isPiece, 37 bool isHitScan = false 38 ); 39 virtual ~CProjectile(); 40 virtual void Detach(); 41 42 virtual void Collision(); 43 virtual void Collision(CUnit* unit); 44 virtual void Collision(CFeature* feature); 45 virtual void Update(); 46 virtual void Init(const CUnit* owner, const float3& offset); 47 Draw()48 virtual void Draw() {} 49 virtual void DrawOnMinimap(CVertexArray& lines, CVertexArray& points); DrawCallback()50 virtual void DrawCallback() {} 51 52 struct QuadFieldCellData { 53 CR_DECLARE_STRUCT(QuadFieldCellData) 54 55 // must match typeof(QuadField::Quad::projectiles) 56 typedef std::list<CProjectile*>::iterator iter; 57 GetCoorQuadFieldCellData58 const int2& GetCoor(unsigned int idx) const { return coors[idx]; } GetIterQuadFieldCellData59 const iter& GetIter(unsigned int idx) const { return iters[idx]; } 60 SetCoorQuadFieldCellData61 void SetCoor(unsigned int idx, const int2& co) { coors[idx] = co; } SetIterQuadFieldCellData62 void SetIter(unsigned int idx, const iter& it) { iters[idx] = it; } 63 64 private: 65 // coordinates and iterators for pos, (pos+spd)*0.5, pos+spd 66 // non-hitscan projectiles *only* use coors[0] and iters[0]! 67 int2 coors[3]; 68 iter iters[3]; 69 }; 70 71 // override WorldObject::SetVelocityAndSpeed so 72 // we can keep <dir> in sync with speed-vector 73 // (unlike other world objects, projectiles must 74 // always point directly along their vel-vector) 75 // 76 // should be called when speed-vector is changed 77 // s.t. both speed.w and dir need to be updated SetVelocityAndSpeed(const float3 & vel)78 void SetVelocityAndSpeed(const float3& vel) { 79 CWorldObject::SetVelocityAndSpeed(vel); 80 81 if (speed.w > 0.0f) { 82 dir = speed / speed.w; 83 } 84 } 85 SetDirectionAndSpeed(const float3 & _dir,float _spd)86 void SetDirectionAndSpeed(const float3& _dir, float _spd) { 87 dir = _dir; 88 speed.w = _spd; 89 90 // keep speed-vector in sync with <dir> 91 CWorldObject::SetVelocity(dir * _spd); 92 } 93 94 CUnit* owner() const; 95 GetOwnerID()96 unsigned int GetOwnerID() const { return ownerID; } GetTeamID()97 unsigned int GetTeamID() const { return teamID; } 98 SetQuadFieldCellData(const QuadFieldCellData & qfcd)99 void SetQuadFieldCellData(const QuadFieldCellData& qfcd) { qfCellData = qfcd; } GetQuadFieldCellData()100 const QuadFieldCellData& GetQuadFieldCellData() const { return qfCellData; } GetQuadFieldCellData()101 QuadFieldCellData& GetQuadFieldCellData() { return qfCellData; } 102 GetProjectileType()103 unsigned int GetProjectileType() const { return projectileType; } GetCollisionFlags()104 unsigned int GetCollisionFlags() const { return collisionFlags; } 105 SetCustomExplosionGeneratorID(unsigned int id)106 void SetCustomExplosionGeneratorID(unsigned int id) { cegID = id; } 107 108 // UNSYNCED ONLY 109 CMatrix44f GetTransformMatrix(bool offsetPos) const; 110 GetSortDist()111 float GetSortDist() const { return sortDist; } SetSortDist(float d)112 void SetSortDist(float d) { sortDist = d; } 113 114 public: 115 static bool inArray; 116 static CVertexArray* va; 117 static int DrawArray(); 118 119 bool synced; ///< is this projectile part of the simulation? 120 bool weapon; ///< is this a weapon projectile? (true implies synced true) 121 bool piece; ///< is this a piece projectile? (true implies synced true) 122 bool hitscan; ///< is this a hit-scan projectile? 123 124 bool luaMoveCtrl; 125 bool checkCol; 126 bool ignoreWater; 127 bool deleteMe; 128 129 bool castShadow; 130 bool drawSorted; 131 132 float3 dir; 133 float3 drawPos; 134 135 136 float mygravity; 137 float sortDist; ///< distance used for z-sorting when rendering 138 139 protected: 140 unsigned int ownerID; 141 unsigned int teamID; 142 unsigned int cegID; 143 144 unsigned int projectileType; 145 unsigned int collisionFlags; 146 147 QuadFieldCellData qfCellData; 148 }; 149 150 #endif /* PROJECTILE_H */ 151 152