techitem.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. #include "pch.h"
  2. typedef struct _TYPE_TO_STRING_DATA
  3. {
  4. ObjectType ot;
  5. ObjectType reserved;
  6. CHAR * szTypeName;
  7. } TYPE_TO_STRING_DATA;
  8. TYPE_TO_STRING_DATA mTypeToStringData[] =
  9. {
  10. { OT_civilization, OT_invalid, "Civ" },
  11. { OT_station, OT_invalid, "Station" },
  12. { OT_hullType, OT_invalid, "Hull" },
  13. { OT_partType, OT_invalid, "Part" },
  14. { OT_mineType, OT_invalid, "Mine" },
  15. { OT_missileType, OT_invalid, "Missile" },
  16. { OT_probeType, OT_invalid, "Probe" },
  17. { OT_development, OT_invalid, "Development" },
  18. { OT_droneType, OT_invalid, "Drone" },
  19. // { OT_stationUpgrade, OT_invalid, "Upgrade" },
  20. { OT_invalid, OT_invalid, "Unknown" }
  21. } ;
  22. BOOL CTechItemList::CopyTo(CTechItemList * pDest)
  23. {
  24. CTechItem * pItem, * pNewItem;
  25. BOOL fSuccess;
  26. fSuccess = TRUE;
  27. pDest->Empty();
  28. for(pItem = mpHead; NULL != pItem; pItem = pItem->mpNext)
  29. {
  30. pNewItem = pItem->Clone();
  31. if (NULL != pNewItem)
  32. pDest->Enqueue(pNewItem);
  33. else
  34. fSuccess = FALSE;
  35. }
  36. return(fSuccess);
  37. }
  38. CTechItem * CTechItemList::Find(ObjectType ot, ObjectID id)
  39. {
  40. CTechItem * pItem;
  41. for(pItem = mpHead; NULL != pItem; pItem = pItem->mpNext)
  42. {
  43. if ((ot == pItem->GetObjectType()) && (id == pItem->GetObjectID()))
  44. break;
  45. }
  46. return(pItem);
  47. }
  48. CTechItem * CTechItemList::Remove(ObjectType ot, ObjectID id)
  49. {
  50. CTechItem * pItem, * pPrev;
  51. for(pItem = mpHead, pPrev = NULL; NULL != pItem; pItem = pItem->mpNext)
  52. {
  53. if ((ot == pItem->GetObjectType()) && (id == pItem->GetObjectID()))
  54. {
  55. if (NULL == pPrev)
  56. mpHead = pItem->mpNext;
  57. else
  58. pPrev->mpNext = pItem->mpNext;
  59. if (pItem == mpTail)
  60. mpTail = pPrev;
  61. mcElements--;
  62. pItem->mpNext = NULL;
  63. break;
  64. }
  65. pPrev = pItem;
  66. }
  67. return(pItem);
  68. }
  69. CTechItem * CTechItemList::RemoveNth(DWORD n)
  70. {
  71. CTechItem * pItem, * pPrev;
  72. pItem = NULL;
  73. if (n < mcElements)
  74. {
  75. if (0 == n)
  76. {
  77. pItem = mpHead;
  78. mpHead = pItem->mpNext;
  79. if (NULL == mpHead)
  80. mpTail = NULL;
  81. } else
  82. {
  83. pPrev = NULL;
  84. for(pItem = mpHead; n > 0; pItem = pItem->mpNext)
  85. {
  86. pPrev = pItem;
  87. n--;
  88. }
  89. pPrev->mpNext = pItem->mpNext;
  90. if (pItem == mpTail)
  91. mpTail = pPrev;
  92. }
  93. mcElements--;
  94. pItem->mpNext = NULL;
  95. }
  96. return(pItem);
  97. }
  98. CTechItem::CTechItem()
  99. {
  100. ZeroMemory(mszName, sizeof(mszName));
  101. mObjectType = OT_invalid;
  102. mObjectID = NA;
  103. mttbmRequired.ClearAll();
  104. mttbmEffect.ClearAll();
  105. mpOriginal = NULL;
  106. mfEverBought = FALSE;
  107. mpNext = NULL;
  108. }
  109. CTechItem::CTechItem(CTechItem * pOriginal)
  110. {
  111. CopyMemory(mszName, pOriginal->mszName, sizeof(mszName));
  112. mObjectType = pOriginal->mObjectType;
  113. mObjectID = pOriginal->mObjectID;
  114. mttbmRequired = pOriginal->mttbmRequired;
  115. mttbmEffect = pOriginal->mttbmEffect;
  116. mpOriginal = pOriginal;
  117. mfEverBought = FALSE;
  118. mpNext = NULL;
  119. }
  120. CHAR * CTechItem::GetObjectTypeName()
  121. {
  122. DWORD dwIndex;
  123. for(dwIndex = 0; OT_invalid != mTypeToStringData[dwIndex].ot; dwIndex++)
  124. {
  125. if (this->GetObjectType() == mTypeToStringData[dwIndex].ot)
  126. break;
  127. }
  128. return(mTypeToStringData[dwIndex].szTypeName);
  129. }
  130. VOID CTechItem::SetWasBought(BOOL fBought)
  131. {
  132. mfEverBought = fBought;
  133. if ((TRUE == fBought) && (NULL != mpOriginal))
  134. mpOriginal->SetWasBought(TRUE);
  135. }
  136. CTechItem * CTechItem::Clone()
  137. {
  138. CTechItem * pClone;
  139. pClone = new CTechItem(this);
  140. return(pClone);
  141. }
  142. BOOL CTechItem::CanPurchase(PURCHASE_DATA * pPurchaseData)
  143. {
  144. BOOL fCanPurchase;
  145. fCanPurchase = FALSE;
  146. if (mttbmRequired <= pPurchaseData->ttbmCurrent)
  147. fCanPurchase = TRUE;
  148. return(fCanPurchase);
  149. }
  150. VOID CTechItem::Purchase(PURCHASE_DATA * pPurchaseData)
  151. {
  152. CTechItem * pItem;
  153. DWORD dwIndex;
  154. pPurchaseData->ttbmCurrent |= mttbmEffect;
  155. this->SetWasBought(TRUE);
  156. pPurchaseData->BoughtList.Enqueue(this);
  157. //
  158. // Go through the item list and see if there's anything new we
  159. // can now buy as a result of this purchase.
  160. //
  161. for(dwIndex = pPurchaseData->TechItemList.Length(); dwIndex > 0; dwIndex--)
  162. {
  163. pItem = pPurchaseData->TechItemList.Dequeue();
  164. if (TRUE == pItem->CanPurchase(pPurchaseData))
  165. pPurchaseData->CanBuyList.Enqueue(pItem);
  166. else
  167. pPurchaseData->TechItemList.Enqueue(pItem);
  168. }
  169. }
  170. //
  171. // Civs.
  172. //
  173. CCivTechItem::CCivTechItem() : CTechItem()
  174. {
  175. mStartingStationID = NA;
  176. mConstructionDroneID = NA;
  177. mEjectPodShipID = NA;
  178. }
  179. VOID CCivTechItem::Purchase(PURCHASE_DATA * pPurchaseData)
  180. {
  181. CDroneTechItem * pDrone;
  182. CTechItem * pFound;
  183. pPurchaseData->ttbmCurrent |= mttbmEffect;
  184. //
  185. // Find the starting station in the global list and purchase it.
  186. //
  187. pFound = pPurchaseData->TechItemList.Remove(OT_station, mStartingStationID);
  188. if (NULL != pFound)
  189. pFound->Purchase(pPurchaseData);
  190. //
  191. // Make sure we mark our builder as "bought" since it's a drone
  192. // only hull and we can't buy builders.
  193. //
  194. pDrone = (CDroneTechItem *)
  195. pPurchaseData->TechItemList.Remove(OT_droneType, mConstructionDroneID);
  196. if (NULL != pDrone)
  197. pDrone->Purchase(pPurchaseData);
  198. //
  199. // Buy our escape pod.
  200. //
  201. pFound = pPurchaseData->TechItemList.Remove(OT_hullType, mEjectPodShipID);
  202. if (NULL != pFound)
  203. pFound->Purchase(pPurchaseData);
  204. }
  205. CDroneTechItem::CDroneTechItem() : CTechItem()
  206. {
  207. mHullID = NA;
  208. }
  209. CDroneTechItem::CDroneTechItem(CDroneTechItem * pOriginal) :
  210. CTechItem(pOriginal)
  211. {
  212. mHullID = pOriginal->mHullID;
  213. }
  214. CTechItem * CDroneTechItem::Clone()
  215. {
  216. CDroneTechItem * pClone;
  217. pClone = new CDroneTechItem(this);
  218. return(pClone);
  219. }
  220. VOID CDroneTechItem::Purchase(PURCHASE_DATA * pPurchaseData)
  221. {
  222. CTechItem * pFound;
  223. CTechItem::Purchase(pPurchaseData);
  224. //
  225. // Try to mark the hull.
  226. //
  227. pFound = pPurchaseData->TechItemList.Find(OT_hullType, this->GetHullID());
  228. if (NULL != pFound)
  229. pFound->SetWasBought(TRUE);
  230. }
  231. //
  232. // Station Types.
  233. //
  234. CStationTechItem::CStationTechItem() : CTechItem()
  235. {
  236. mttbmLocal.ClearAll();
  237. mUpgradeStationID = NA;
  238. // mttbmUpgradeFrom.ClearAll();
  239. // mcUpgrades = 0;
  240. }
  241. CStationTechItem::CStationTechItem(CStationTechItem * pOriginal) :
  242. CTechItem(pOriginal)
  243. {
  244. mttbmLocal = pOriginal->mttbmLocal;
  245. mUpgradeStationID = pOriginal->mUpgradeStationID;
  246. // mttbmUpgradeFrom = pOriginal->mttbmUpgradeFrom;
  247. // mcUpgrades = 0;
  248. }
  249. //VOID CStationTechItem::AddUpgradeBitmask(TechTreeBitMask ttbm)
  250. //{
  251. // if (mcUpgrades < MAX_UPGRADES_TO_STATION)
  252. // mttbmUpgrade[mcUpgrades++] = ttbm;
  253. //}
  254. CTechItem * CStationTechItem::Clone()
  255. {
  256. CStationTechItem * pClone;
  257. pClone = new CStationTechItem(this);
  258. return(pClone);
  259. }
  260. BOOL CStationTechItem::CanPurchase(PURCHASE_DATA * pPurchaseData)
  261. {
  262. BOOL fCanPurchase;
  263. // DWORD dwIndex;
  264. fCanPurchase = CTechItem::CanPurchase(pPurchaseData);
  265. if (FALSE == fCanPurchase)
  266. {
  267. //
  268. // Check to see if we can be upgraded to.
  269. //
  270. //for(dwIndex = 0; dwIndex < mcUpgrades; dwIndex++)
  271. //{
  272. // if (mttbmUpgrade[dwIndex] <= pPurchaseData->ttbmCurrent)
  273. // {
  274. // this->SetObjectType(OT_stationUpgrade);
  275. // fCanPurchase = TRUE;
  276. // }
  277. //}
  278. // need to just check the bits
  279. }
  280. return(fCanPurchase);
  281. }
  282. VOID CStationTechItem::Purchase(PURCHASE_DATA * pPurchaseData)
  283. {
  284. // CStationTechItem * pUpgrade;
  285. pPurchaseData->ttbmCurrent |= mttbmLocal;
  286. //
  287. // Now that we've been bought, find our upgrade and tell it
  288. // what it needs to be upgraded from us.
  289. //
  290. // pUpgrade = (CStationTechItem *)
  291. // pPurchaseData->TechItemList.Find(OT_station, mUpgradeStationID);
  292. // if (NULL != pUpgrade)
  293. // pUpgrade->AddUpgradeBitmask(mttbmUpgradeFrom);
  294. CTechItem::Purchase(pPurchaseData);
  295. }