stationIGC.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. /*
  2. ** Copyright (C) 1996, 1997 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: stationIGC.h
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Header for the CstationIGC class. This file was initially created by
  10. ** the ATL wizard.
  11. **
  12. ** History:
  13. */
  14. // shipIGC.h : Declaration of the CshipIGC
  15. #ifndef __STATIONIGC_H_
  16. #define __STATIONIGC_H_
  17. #include "modelIGC.h"
  18. class CstationIGC;
  19. class MyStationType : public IstationTypeIGC
  20. {
  21. public:
  22. MyStationType(CstationIGC* pstation)
  23. :
  24. m_pstation(pstation),
  25. m_pStationType(NULL)
  26. {
  27. }
  28. ~MyStationType(void)
  29. {
  30. if (m_pStationType)
  31. m_pStationType->Release();
  32. }
  33. //IbaseIGC
  34. virtual HRESULT Initialize(ImissionIGC* pMission, Time now, const void* data, int length);
  35. virtual void Terminate(void);
  36. virtual void Update(Time now);
  37. virtual ObjectType GetObjectType(void) const;
  38. virtual ObjectID GetObjectID(void) const;
  39. //ItypeIGC
  40. virtual const void* GetData(void) const;
  41. //IbuyableIGC
  42. virtual const char* GetName(void) const;
  43. virtual const char* GetDescription(void) const;
  44. virtual const char* GetModelName(void) const;
  45. virtual const TechTreeBitMask& GetRequiredTechs(void) const;
  46. virtual const TechTreeBitMask& GetEffectTechs(void) const;
  47. virtual Money GetPrice(void) const;
  48. virtual DWORD GetTimeToBuild(void) const;
  49. virtual BuyableGroupID GetGroupID(void) const;
  50. // IstationTypeIGC
  51. virtual HitPoints GetMaxArmorHitPoints(void) const;
  52. virtual DefenseTypeID GetArmorDefenseType(void) const;
  53. virtual HitPoints GetMaxShieldHitPoints(void) const;
  54. virtual DefenseTypeID GetShieldDefenseType(void) const;
  55. virtual float GetArmorRegeneration(void) const;
  56. virtual float GetShieldRegeneration(void) const;
  57. virtual float GetSignature(void) const;
  58. virtual float GetRadius(void) const;
  59. virtual float GetScannerRange(void) const;
  60. virtual Money GetIncome(void) const;
  61. virtual const TechTreeBitMask& GetLocalTechs(void) const;
  62. virtual StationAbilityBitMask GetCapabilities(void) const;
  63. virtual bool HasCapability(StationAbilityBitMask sabm) const;
  64. virtual const char* GetTextureName(void) const;
  65. virtual const char* GetBuilderName(void) const;
  66. virtual const char* GetIconName(void) const;
  67. virtual IstationTypeIGC* GetSuccessorStationType(const IsideIGC* pside);
  68. virtual AsteroidAbilityBitMask GetBuildAABM(void) const;
  69. virtual int GetLaunchSlots(void) const;
  70. virtual const Vector& GetLaunchPosition(int slotID) const;
  71. virtual const Vector& GetLaunchDirection(int slotID) const;
  72. virtual int GetLandSlots(void) const;
  73. virtual int GetCapLandSlots(void) const;
  74. virtual int GetLandPlanes(int slotID) const;
  75. virtual const Vector& GetLandPosition(int slotID, int planeID) const;
  76. virtual const Vector& GetLandDirection(int slotID, int planeID) const;
  77. virtual SoundID GetInteriorSound() const;
  78. virtual SoundID GetInteriorAlertSound() const;
  79. virtual SoundID GetExteriorSound() const;
  80. virtual SoundID GetConstructorNeedRockSound() const;
  81. virtual SoundID GetConstructorUnderAttackSound() const;
  82. virtual SoundID GetConstructorDestroyedSound() const;
  83. virtual SoundID GetCompletionSound() const;
  84. virtual SoundID GetUnderAttackSound() const;
  85. virtual SoundID GetCriticalSound() const;
  86. virtual SoundID GetDestroyedSound() const;
  87. virtual SoundID GetCapturedSound() const;
  88. virtual SoundID GetEnemyCapturedSound() const;
  89. virtual SoundID GetEnemyDestroyedSound() const;
  90. virtual StationClassID GetClassID() const;
  91. virtual IdroneTypeIGC* GetConstructionDroneType(void) const;
  92. private:
  93. IstationTypeIGC* GetStationType(void) const
  94. {
  95. return m_pStationType;
  96. }
  97. void SetStationType(IstationTypeIGC* pst)
  98. {
  99. if (m_pStationType)
  100. m_pStationType->Release();
  101. m_pStationType = pst;
  102. if (pst)
  103. {
  104. pst->AddRef();
  105. m_pStationData = (const DataStationTypeIGC*)(m_pStationType->GetData());
  106. }
  107. else
  108. m_pStationData = NULL;
  109. }
  110. CstationIGC* m_pstation;
  111. IstationTypeIGC* m_pStationType;
  112. const DataStationTypeIGC* m_pStationData;
  113. friend class CstationIGC;
  114. };
  115. class CstationIGC : public TmodelIGC<IstationIGC>
  116. {
  117. public:
  118. CstationIGC(void)
  119. :
  120. m_myStationType(this),
  121. m_hullFraction(1.0f),
  122. m_shieldFraction(0.0f)
  123. {
  124. }
  125. /*
  126. DWORD AddRef(void)
  127. {
  128. return TmodelIGC<IstationIGC>::AddRef();
  129. }
  130. DWORD Release(void)
  131. {
  132. return TmodelIGC<IstationIGC>::Release();
  133. }
  134. */
  135. // IbaseIGC
  136. virtual HRESULT Initialize(ImissionIGC* pMission, Time now, const void* data, int length);
  137. virtual void Terminate(void)
  138. {
  139. AddRef();
  140. {
  141. //Force all of the ships docked at the station to undock
  142. //NYI terminate all of the ships docked at the station?
  143. ShipLinkIGC* l;
  144. while (l = m_shipsDocked.first()) //intentional assignment
  145. l->data()->SetStation(NULL);
  146. }
  147. GetMyMission()->DeleteStation(this);
  148. TmodelIGC<IstationIGC>::Terminate();
  149. m_myStationType.SetStationType(NULL);
  150. Release();
  151. }
  152. virtual void Update(Time now)
  153. {
  154. float dt = now - GetMyLastUpdate();
  155. if (dt > 0.0f)
  156. {
  157. if (m_hullFraction != 1.0f)
  158. {
  159. m_hullFraction += dt * m_myStationType.GetArmorRegeneration() / m_myStationType.GetMaxArmorHitPoints();
  160. if (m_hullFraction > 1.0f)
  161. m_hullFraction = 1.0f;
  162. }
  163. else
  164. {
  165. float m = m_myStationType.GetMaxShieldHitPoints();
  166. if ((m_shieldFraction != 1.0f) && (m != 0.0f))
  167. {
  168. //Use SetShieldFraction so the station's shape will be adjusted as appropriate.
  169. SetShieldFraction(m_shieldFraction + dt * m_myStationType.GetShieldRegeneration() / m);
  170. }
  171. }
  172. TmodelIGC<IstationIGC>::Update(now);
  173. }
  174. }
  175. virtual int Export(void* data) const;
  176. virtual ObjectType GetObjectType(void) const
  177. {
  178. return OT_station;
  179. }
  180. virtual ObjectID GetObjectID(void) const
  181. {
  182. return m_stationID;
  183. }
  184. // ImodelIGC
  185. virtual void SetCluster(IclusterIGC* cluster)
  186. {
  187. AddRef();
  188. //Overrride the model's cluster method so that we can maintain the cluster's warp list
  189. //(as well as letting the model maintain its model list)
  190. {
  191. IclusterIGC* c = GetCluster();
  192. if (c)
  193. {
  194. assert (cluster == NULL);
  195. c->DeleteStation(this);
  196. c->GetClusterSite()->MoveStation();
  197. }
  198. }
  199. TmodelIGC<IstationIGC>::SetCluster(cluster);
  200. if (cluster)
  201. {
  202. cluster->AddStation(this);
  203. cluster->GetClusterSite()->MoveStation();
  204. }
  205. Release();
  206. }
  207. virtual void SetSide(IsideIGC* psideNew)
  208. {
  209. IsideIGC* psideOld = GetSide();
  210. if (psideOld != psideNew)
  211. {
  212. IclusterIGC* pcluster = GetCluster();
  213. if (psideOld != NULL)
  214. {
  215. //Remove the station from previous side's list of stations
  216. if (pcluster)
  217. pcluster->GetClusterSite()->DeleteScanner(psideOld->GetObjectID(), this);
  218. psideOld->DeleteStation(this);
  219. }
  220. TmodelIGC<IstationIGC>::SetSide(psideNew);
  221. if (psideNew != NULL)
  222. {
  223. //Add the station to the new side's list of stations
  224. psideNew->AddStation(this);
  225. if (pcluster)
  226. pcluster->GetClusterSite()->AddScanner(psideNew->GetObjectID(), this);
  227. GetHitTest()->SetUseTrueShapeSelf(psideNew);
  228. }
  229. if (pcluster != NULL)
  230. pcluster->GetClusterSite()->MoveStation();
  231. }
  232. }
  233. // IdamageIGC
  234. virtual DamageResult ReceiveDamage(DamageTypeID type,
  235. float amount,
  236. Time timeCollision,
  237. const Vector& position1,
  238. const Vector& position2,
  239. ImodelIGC* launcher);
  240. virtual float GetFraction(void) const
  241. {
  242. return m_hullFraction;
  243. }
  244. virtual void SetFraction(float newVal)
  245. {
  246. m_hullFraction = newVal;
  247. }
  248. virtual float GetHitPoints(void) const
  249. {
  250. return m_hullFraction * (float)m_myStationType.GetMaxArmorHitPoints();
  251. }
  252. // IscannerIGC
  253. bool InScannerRange(ImodelIGC* pModel) const
  254. {
  255. assert (pModel);
  256. bool rc;
  257. IclusterIGC* pcluster = GetCluster();
  258. if (pModel->GetCluster() == pcluster)
  259. {
  260. if (pModel->GetFlag() == NA)
  261. {
  262. float m = m_myStationType.GetScannerRange() * pModel->GetSignature();
  263. {
  264. IsideIGC* pside = pModel->GetSide();
  265. if (pside)
  266. m /= pside->GetGlobalAttributeSet().GetAttribute(c_gaSignature);
  267. }
  268. float r = GetRadius() + pModel->GetRadius() + m;
  269. rc = ((GetPosition() - pModel->GetPosition()).LengthSquared() <= r * r) &&
  270. LineOfSightExist(pcluster, this, pModel);
  271. }
  272. else
  273. rc = true;
  274. }
  275. else
  276. rc = false;
  277. return rc;
  278. }
  279. bool CanSee(ImodelIGC* pModel) const
  280. {
  281. assert (pModel);
  282. IsideIGC* side = GetSide();
  283. return (pModel->GetSide() == side) || //Always see things on our side
  284. pModel->SeenBySide(side) ||
  285. InScannerRange(pModel); //or we can see it ourselves
  286. }
  287. // IstationIGC
  288. virtual const IstationTypeIGC* GetStationType(void) const
  289. {
  290. return &m_myStationType;
  291. }
  292. virtual IstationTypeIGC* GetBaseStationType(void) const
  293. {
  294. return m_myStationType.GetStationType();
  295. }
  296. virtual void SetBaseStationType(IstationTypeIGC* pst);
  297. virtual float GetShieldFraction(void) const
  298. {
  299. return m_shieldFraction;
  300. }
  301. virtual void SetShieldFraction(float newVal)
  302. {
  303. if (newVal < 0.0f)
  304. newVal = 0.0f;
  305. else if (newVal > 1.0f)
  306. newVal = 1.0f;
  307. m_shieldFraction = newVal;
  308. }
  309. virtual bool CanBuy(const IbuyableIGC* b) const
  310. {
  311. IsideIGC* s = GetSide();
  312. assert (s);
  313. assert (b->GetObjectType() != OT_bucket);
  314. return b->GetRequiredTechs() <= (m_myStationType.GetLocalTechs() | s->GetTechs());
  315. }
  316. virtual bool IsObsolete(IbuyableIGC* b) const
  317. {
  318. IbuyableIGC* pSuccessor = GetSuccessor(b);
  319. return (pSuccessor != b);
  320. }
  321. virtual IbuyableIGC* GetSuccessor(IbuyableIGC* b) const
  322. {
  323. assert (b);
  324. IbuyableIGC* pSuccessor = b;
  325. if (CanBuy(b))
  326. {
  327. IbuyableIGC* pNext = pSuccessor;
  328. ObjectType type = b->GetObjectType();
  329. while (true)
  330. {
  331. switch (type)
  332. {
  333. case OT_partType:
  334. {
  335. pNext = ((IpartTypeIGC*)pNext)->GetSuccessorPartType();
  336. }
  337. break;
  338. case OT_hullType:
  339. {
  340. pNext = ((IhullTypeIGC*)pNext)->GetSuccessorHullType();
  341. }
  342. break;
  343. default:
  344. {
  345. pNext = NULL;
  346. }
  347. }
  348. if (pNext == NULL)
  349. break;
  350. if (CanBuy(pNext))
  351. pSuccessor = pNext;
  352. }
  353. assert (pSuccessor);
  354. }
  355. return pSuccessor;
  356. }
  357. virtual IpartTypeIGC* GetSimilarPart(IpartTypeIGC* ppt) const
  358. {
  359. //Walk through the predecessor parts until one is found that can be bought
  360. //We need to make only a single pass because sucessors always precede their predecessors
  361. for (PartTypeLinkIGC* pptl = GetMission()->GetPartTypes()->first(); (pptl != NULL); pptl = pptl->next())
  362. {
  363. IpartTypeIGC* pptTry = pptl->data();
  364. if (pptTry->GetSuccessorPartType() == ppt)
  365. {
  366. if (CanBuy(pptTry))
  367. return pptTry;
  368. else
  369. ppt = pptTry;
  370. }
  371. }
  372. return NULL;
  373. }
  374. virtual void AddShip(IshipIGC* s);
  375. virtual void DeleteShip(IshipIGC* s);
  376. virtual IshipIGC* GetShip(ShipID shipID) const;
  377. virtual const ShipListIGC* GetShips(void) const;
  378. virtual void Launch(IshipIGC* pship);
  379. virtual void RepairAndRefuel(IshipIGC* pship) const;
  380. virtual bool InGarage(IshipIGC* pship, const Vector& position);
  381. virtual void SetLastDamageReport(Time timeLastDamage)
  382. {
  383. m_timeLastDamageReport = timeLastDamage;
  384. }
  385. virtual Time GetLastDamageReport(void) const
  386. {
  387. return m_timeLastDamageReport;
  388. }
  389. virtual SoundID GetInteriorSound() const
  390. {
  391. return (GetFraction() > 0.8) ? m_myStationType.GetInteriorSound()
  392. : m_myStationType.GetInteriorAlertSound();
  393. }
  394. virtual SoundID GetExteriorSound() const
  395. {
  396. return m_myStationType.GetExteriorSound();
  397. }
  398. private:
  399. MyStationType m_myStationType;
  400. float m_hullFraction;
  401. float m_shieldFraction;
  402. Time m_timeLastDamageReport;
  403. ShipListIGC m_shipsDocked;
  404. StationID m_stationID;
  405. unsigned char m_undockPosition;
  406. };
  407. #endif //__STATIONIGC_H_