sideigc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. /*
  2. ** Copyright (C) 1996, 1997 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: sideIGC.h
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Header for the CsideIGC class. This file was initially created by
  10. ** the ATL wizard.
  11. **
  12. ** History:
  13. */
  14. // sideIGC.h : Declaration of the CsideIGC
  15. #ifndef __SIDEIGC_H_
  16. #define __SIDEIGC_H_
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CsideIGC
  19. class CsideIGC : public IsideIGC
  20. {
  21. public:
  22. CsideIGC(void)
  23. :
  24. m_activeF(false), // sides are inactive until mission creation is over
  25. m_dwPrivate(NULL)
  26. {
  27. }
  28. ~CsideIGC(void)
  29. {
  30. }
  31. public:
  32. // IbaseIGC
  33. virtual HRESULT Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize);
  34. virtual void Terminate(void);
  35. virtual void Update(Time now)
  36. {
  37. //Update the buckets attached to the station.
  38. for (BucketLinkIGC* l = m_buckets.first();
  39. (l != NULL);
  40. l = l->next())
  41. {
  42. l->data()->Update(now);
  43. }
  44. m_lastUpdate = now;
  45. }
  46. virtual int Export(void* data) const;
  47. virtual ObjectType GetObjectType(void) const
  48. {
  49. return OT_side;
  50. }
  51. virtual ObjectID GetObjectID(void) const
  52. {
  53. return m_data.sideID;
  54. }
  55. virtual ImissionIGC* GetMission(void) const
  56. {
  57. return m_pMission;
  58. }
  59. // IsideIGC
  60. virtual IcivilizationIGC* GetCivilization(void) const
  61. {
  62. return m_pCivilization;
  63. }
  64. virtual void SetCivilization(IcivilizationIGC* pciv)
  65. {
  66. assert (pciv);
  67. assert (m_pCivilization);
  68. if (m_pCivilization != pciv)
  69. {
  70. m_pCivilization->Release();
  71. m_pCivilization = pciv;
  72. pciv->AddRef();
  73. // set the tech bits for the new civ
  74. m_data.ttbmDevelopmentTechs = GetCivilization()->GetBaseTechs();
  75. m_ttbmBuildingTechs.ClearAll();
  76. m_data.civilizationID = GetCivilization()->GetObjectID();
  77. //Turn all space stations into the base space station for the new civ
  78. {
  79. for (StationLinkIGC* psl = m_stations.first(); (psl != NULL); psl = psl->next())
  80. {
  81. IstationIGC* pstation = psl->data();
  82. pstation->SetBaseStationType(pciv->GetInitialStationType());
  83. }
  84. }
  85. }
  86. }
  87. virtual void DestroyBuckets(void);
  88. virtual void CreateBuckets(void);
  89. void SetName(const char* newVal)
  90. {
  91. UTL::putName(m_data.name, newVal);
  92. }
  93. virtual const char* GetName(void) const
  94. {
  95. return m_data.name;
  96. }
  97. virtual SquadID GetSquadID() const
  98. {
  99. return m_data.squadID;
  100. }
  101. virtual void SetSquadID(SquadID squadID)
  102. {
  103. m_data.squadID = squadID;
  104. }
  105. virtual const TechTreeBitMask GetTechs(void) const
  106. {
  107. return m_ttbmBuildingTechs | m_data.ttbmDevelopmentTechs;
  108. }
  109. virtual const TechTreeBitMask& GetBuildingTechs(void) const
  110. {
  111. return m_ttbmBuildingTechs;
  112. }
  113. virtual void ResetBuildingTechs(void)
  114. {
  115. //See what the new set of building techs is, from scratch
  116. TechTreeBitMask ttbm;
  117. ttbm.ClearAll();
  118. {
  119. for (StationLinkIGC* l = m_stations.first();
  120. (l != NULL);
  121. l = l->next())
  122. {
  123. ttbm |= l->data()->GetStationType()->GetEffectTechs();
  124. }
  125. }
  126. SetBuildingTechs(ttbm);
  127. }
  128. virtual void SetBuildingTechs(const TechTreeBitMask& ttbm)
  129. {
  130. if (ttbm != m_ttbmBuildingTechs)
  131. {
  132. m_ttbmBuildingTechs = ttbm;
  133. m_pMission->GetIgcSite()->SideBuildingTechChange(this);
  134. AdjustBuckets();
  135. }
  136. }
  137. virtual const TechTreeBitMask& GetDevelopmentTechs(void) const
  138. {
  139. return m_data.ttbmDevelopmentTechs;
  140. }
  141. virtual void SetDevelopmentTechs(const TechTreeBitMask& ttbm)
  142. {
  143. if (ttbm != m_data.ttbmDevelopmentTechs)
  144. {
  145. m_data.ttbmDevelopmentTechs = ttbm;
  146. m_pMission->GetIgcSite()->SideDevelopmentTechChange(this);
  147. AdjustBuckets();
  148. }
  149. }
  150. virtual bool ApplyDevelopmentTechs(const TechTreeBitMask& ttbm)
  151. {
  152. bool rc;
  153. if (!(ttbm <= m_data.ttbmDevelopmentTechs))
  154. {
  155. rc = true;
  156. m_data.ttbmDevelopmentTechs |= ttbm;
  157. m_pMission->GetIgcSite()->SideDevelopmentTechChange(this);
  158. AdjustBuckets();
  159. }
  160. else
  161. rc = false;
  162. return rc;
  163. }
  164. virtual const TechTreeBitMask& GetInitialTechs(void) const
  165. {
  166. return m_data.ttbmInitialTechs;
  167. }
  168. virtual void SetInitialTechs(const TechTreeBitMask& ttbm)
  169. {
  170. m_data.ttbmInitialTechs = ttbm;
  171. }
  172. virtual void UpdateInitialTechs(void)
  173. {
  174. m_data.ttbmInitialTechs = m_data.ttbmDevelopmentTechs;
  175. }
  176. virtual bool CanBuy(const IbuyableIGC* b) const
  177. {
  178. ObjectType type = b->GetObjectType();
  179. if (type == OT_bucket)
  180. {
  181. b = ((IbucketIGC*)b)->GetBuyable();
  182. type = b->GetObjectType();
  183. }
  184. TechTreeBitMask ttbmSide = (m_ttbmBuildingTechs | m_data.ttbmDevelopmentTechs);
  185. const TechTreeBitMask& ttbmRequired = b->GetRequiredTechs();
  186. bool bAvailable;
  187. if (type == OT_development)
  188. {
  189. //A non-localized item ... buyable based only on global tech bits
  190. bAvailable = (ttbmRequired <= ttbmSide) ||
  191. (b->GetObjectID() == c_didTeamMoney); //If you have the team money dev ... you can buy it
  192. }
  193. else
  194. {
  195. //Station types can not be bought if they are obsolete
  196. if (type == OT_stationType)
  197. {
  198. //Station types can not be bought if their successor is available
  199. const IstationTypeIGC* pstSuccessor = ((IstationTypeIGC*)b)->GetSuccessorStationType(this);
  200. if (pstSuccessor != b)
  201. return false;
  202. }
  203. //Station type or drone type: these are built at stations so see if any station
  204. //can build them.
  205. bAvailable = false;
  206. for (StationLinkIGC* psl = m_stations.first(); (psl != NULL); psl = psl->next())
  207. {
  208. TechTreeBitMask ttbmStation = psl->data()->GetStationType()->GetLocalTechs() |
  209. ttbmSide;
  210. if (ttbmRequired <= ttbmStation)
  211. {
  212. bAvailable = true;
  213. break;
  214. }
  215. }
  216. }
  217. return bAvailable;
  218. }
  219. virtual void AddStation(IstationIGC* s)
  220. {
  221. AddIbaseIGC((BaseListIGC*)&m_stations, s);
  222. SetBuildingTechs(m_ttbmBuildingTechs |
  223. s->GetStationType()->GetEffectTechs());
  224. }
  225. virtual void DeleteStation(IstationIGC* s)
  226. {
  227. DeleteIbaseIGC((BaseListIGC*)&m_stations, s);
  228. //See what the new set of building techs is, from scratch
  229. ResetBuildingTechs();
  230. }
  231. virtual IstationIGC* GetStation(StationID id) const
  232. {
  233. return (IstationIGC*)GetIbaseIGC((BaseListIGC*)&m_stations, id);
  234. }
  235. virtual const StationListIGC* GetStations(void) const
  236. {
  237. return &m_stations;
  238. }
  239. virtual void AddShip(IshipIGC* s)
  240. {
  241. AddIbaseIGC((BaseListIGC*)&m_ships, s);
  242. }
  243. virtual void DeleteShip(IshipIGC* s)
  244. {
  245. DeleteIbaseIGC((BaseListIGC*)&m_ships, s);
  246. }
  247. virtual IshipIGC* GetShip(ShipID id) const
  248. {
  249. return (IshipIGC*)GetIbaseIGC((BaseListIGC*)&m_ships, id);
  250. }
  251. virtual const ShipListIGC* GetShips(void) const
  252. {
  253. return &m_ships;
  254. }
  255. virtual void AddBucket(IbucketIGC* b)
  256. {
  257. AddIbaseIGC((BaseListIGC*)&m_buckets, b);
  258. }
  259. virtual void DeleteBucket(IbucketIGC* b)
  260. {
  261. DeleteIbaseIGC((BaseListIGC*)&m_buckets, b);
  262. }
  263. virtual IbucketIGC* GetBucket(BucketID bucketID) const
  264. {
  265. return (IbucketIGC*)GetIbaseIGC((BaseListIGC*)&m_buckets, bucketID);
  266. }
  267. virtual const BucketListIGC* GetBuckets(void) const
  268. {
  269. return &m_buckets;
  270. }
  271. virtual const GlobalAttributeSet& GetGlobalAttributeSet(void) const
  272. {
  273. return m_data.gasAttributes;
  274. }
  275. virtual void SetGlobalAttributeSet(const GlobalAttributeSet& gas)
  276. {
  277. m_data.gasAttributes = gas;
  278. m_pMission->GetIgcSite()->SideGlobalAttributeChange(this);
  279. }
  280. virtual void ApplyGlobalAttributeSet(const GlobalAttributeSet& gas)
  281. {
  282. m_data.gasAttributes.Apply(gas);
  283. m_pMission->GetIgcSite()->SideGlobalAttributeChange(this);
  284. }
  285. virtual void ResetGlobalAttributeSet(void)
  286. {
  287. m_data.gasAttributes.Initialize();
  288. m_pMission->GetIgcSite()->SideGlobalAttributeChange(this);
  289. }
  290. virtual const TechTreeBitMask& GetUltimateTechs(void) const
  291. {
  292. return m_ttbmUltimateTechs;
  293. }
  294. virtual bool GetActiveF(void) const
  295. {
  296. return m_activeF;
  297. }
  298. virtual void SetActiveF(bool activeF)
  299. {
  300. m_activeF = activeF;
  301. }
  302. virtual const Color& GetColor(void) const
  303. {
  304. return m_data.color;
  305. }
  306. virtual void SetPrivateData(DWORD dwPrivate)
  307. {
  308. m_dwPrivate = dwPrivate;
  309. }
  310. virtual DWORD GetPrivateData(void) const
  311. {
  312. return m_dwPrivate;
  313. }
  314. virtual void AddToStockpile(IbuyableIGC* b, short count)
  315. {
  316. assert (count > 0);
  317. //See if there are already entries in the stockpile
  318. StockpileLink* plink = m_stockpile.first();
  319. {
  320. while (plink)
  321. {
  322. if (plink->data().buyable == b)
  323. break;
  324. plink = plink->next();
  325. }
  326. }
  327. if (!plink)
  328. {
  329. plink = new StockpileLink;
  330. plink->data().buyable = b;
  331. plink->data().count = 0;
  332. m_stockpile.first(plink);
  333. }
  334. assert (plink);
  335. plink->data().count += count;
  336. }
  337. virtual short RemoveFromStockpile(IbuyableIGC* b, short count)
  338. {
  339. assert (count > 0);
  340. StockpileLink* plink = m_stockpile.first();
  341. while (plink)
  342. {
  343. assert (plink->data().count > 0);
  344. if (plink->data().buyable == b)
  345. {
  346. if (count >= plink->data().count)
  347. {
  348. count = plink->data().count;
  349. delete plink;
  350. }
  351. else
  352. plink->data().count -= count;
  353. return count;
  354. }
  355. plink = plink->next();
  356. }
  357. return 0;
  358. }
  359. virtual short GetStockpile(IbuyableIGC* b) const
  360. {
  361. StockpileLink* plink = m_stockpile.first();
  362. while (plink)
  363. {
  364. if (plink->data().buyable == b)
  365. return plink->data().count;
  366. plink = plink->next();
  367. }
  368. return 0;
  369. }
  370. virtual const StockpileList* GetStockpile(void) const
  371. {
  372. return &m_stockpile;
  373. }
  374. virtual short GetKills(void) const
  375. {
  376. return m_data.nKills;
  377. }
  378. virtual void AddKill(void)
  379. {
  380. m_data.nKills++;
  381. }
  382. virtual short GetDeaths(void) const
  383. {
  384. return m_data.nDeaths;
  385. }
  386. virtual void AddDeath(void)
  387. {
  388. m_data.nDeaths++;
  389. }
  390. virtual short GetEjections(void) const
  391. {
  392. return m_data.nEjections;
  393. }
  394. virtual void AddEjection(void)
  395. {
  396. m_data.nEjections++;
  397. }
  398. virtual short GetBaseKills(void) const
  399. {
  400. return m_data.nBaseKills;
  401. }
  402. virtual void AddBaseKill(void)
  403. {
  404. m_data.nBaseKills++;
  405. }
  406. virtual short GetBaseCaptures(void) const
  407. {
  408. return m_data.nBaseCaptures;
  409. }
  410. virtual void AddBaseCapture(void)
  411. {
  412. m_data.nBaseCaptures++;
  413. }
  414. unsigned char GetConquestPercent(void) const
  415. {
  416. return m_data.conquest;
  417. }
  418. void SetConquestPercent(unsigned char newVal)
  419. {
  420. m_data.conquest = newVal;
  421. }
  422. unsigned char GetTerritoryCount(void) const
  423. {
  424. return m_data.territory;
  425. }
  426. void SetTerritoryCount(unsigned char newVal)
  427. {
  428. m_data.territory = newVal;
  429. }
  430. short GetFlags(void) const
  431. {
  432. return m_data.nFlags;
  433. }
  434. void SetFlags(short newVal)
  435. {
  436. m_data.nFlags = newVal;
  437. }
  438. short GetArtifacts(void) const
  439. {
  440. return m_data.nArtifacts;
  441. }
  442. void SetArtifacts(short newVal)
  443. {
  444. m_data.nArtifacts = newVal;
  445. }
  446. float GetTimeEndured() const
  447. {
  448. return m_data.fTimeEndured;
  449. }
  450. void SetTimeEndured(float fSeconds)
  451. {
  452. m_data.fTimeEndured = fSeconds;
  453. }
  454. virtual long GetProsperityPercentBought(void) const;
  455. virtual long GetProsperityPercentComplete(void) const;
  456. void Reset(void)
  457. {
  458. m_data.nFlags = 0;
  459. m_data.nArtifacts = 0;
  460. m_data.nDeaths = 0;
  461. m_data.nEjections = 0;
  462. m_data.nKills = 0;
  463. m_data.nBaseKills = 0;
  464. m_data.nBaseCaptures = 0;
  465. m_data.conquest = 0;
  466. }
  467. private:
  468. void AdjustBuckets(void)
  469. {
  470. //Empty the side buckets we can no longer build
  471. for (BucketLinkIGC* l = m_buckets.first();
  472. (l != NULL);
  473. l = l->next())
  474. {
  475. IbucketIGC* b = l->data();
  476. if (!b->GetCompleteF())
  477. {
  478. IbuyableIGC* pbuy = b->GetBuyable();
  479. switch (pbuy->GetObjectType())
  480. {
  481. case OT_development:
  482. {
  483. IdevelopmentIGC* d = (IdevelopmentIGC*)pbuy;
  484. assert (d->GetObjectType() == OT_development);
  485. if (d->IsObsolete(m_data.ttbmDevelopmentTechs))
  486. {
  487. //This will not give us anything ... so mark it as complete
  488. b->SetTimeAndMoney(1000 * b->GetTimeToBuild(),
  489. b->GetPrice());
  490. }
  491. else if ((b->GetMoney() != 0) && !CanBuy(pbuy))
  492. b->SetEmpty();
  493. }
  494. break;
  495. case OT_stationType:
  496. {
  497. Money money = b->GetMoney();
  498. if ((money != 0) && !CanBuy(pbuy))
  499. {
  500. IstationTypeIGC* pstSuccessor = ((IstationTypeIGC*)pbuy)->GetSuccessorStationType(this);
  501. if (pstSuccessor != pbuy)
  502. {
  503. //Find the bucket that corresponds to the successor station
  504. for (BucketLinkIGC* l2 = m_buckets.first();
  505. (l2 != NULL);
  506. l2 = l2->next())
  507. {
  508. IbucketIGC* b2 = l2->data();
  509. if (b2->GetBuyable() == pstSuccessor)
  510. {
  511. b2->SetTimeAndMoney(b->GetTime(), money);
  512. break;
  513. }
  514. }
  515. }
  516. b->SetEmpty();
  517. }
  518. }
  519. break;
  520. default:
  521. {
  522. if ((b->GetMoney() != 0) && !CanBuy(pbuy))
  523. b->SetEmpty();
  524. }
  525. }
  526. }
  527. }
  528. }
  529. ImissionIGC* m_pMission;
  530. DWORD m_dwPrivate; // private data for consumer
  531. DataSideIGC m_data;
  532. IcivilizationIGC* m_pCivilization;
  533. TechTreeBitMask m_ttbmBuildingTechs;
  534. TechTreeBitMask m_ttbmUltimateTechs;
  535. StationListIGC m_stations;
  536. BucketListIGC m_buckets;
  537. ShipListIGC m_ships;
  538. StockpileList m_stockpile;
  539. Time m_lastUpdate;
  540. bool m_activeF;
  541. };
  542. #endif //__SIDEIGC_H_