load.cpp 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195
  1. #include "pch.h"
  2. const Money moneyLots = 0x7fffffff;
  3. //////////////////////////////////////////////////////////////////////////////
  4. //
  5. // Loadout
  6. //
  7. //////////////////////////////////////////////////////////////////////////////
  8. static const char* GetBuyableName(IbuyableIGC* ppt)
  9. {
  10. const char* name = ppt->GetName();
  11. Money cost = ppt->GetPrice();
  12. if (cost == 0)
  13. return name;
  14. else
  15. {
  16. static char bfr[c_cbName + 10];
  17. strcpy(bfr, name);
  18. strcat(bfr, " $(");
  19. _itoa(cost, bfr + strlen(bfr), 10);
  20. strcat(bfr, ")");
  21. return bfr;
  22. }
  23. }
  24. bool g_bTest = false;
  25. const int c_midOtherParts = -2;
  26. const int ET_Turret = -2;
  27. class LoadoutImpl :
  28. public Loadout,
  29. public EventTargetContainer<LoadoutImpl>,
  30. public TrekClientEventSink,
  31. public ISubmenuEventSink,
  32. public IMenuCommandSink
  33. {
  34. public:
  35. //////////////////////////////////////////////////////////////////////////////
  36. //
  37. // Slot
  38. //
  39. //////////////////////////////////////////////////////////////////////////////
  40. class Slot : public Pane, public TrekClientEventSink {
  41. private:
  42. LoadoutImpl* m_ploadout;
  43. TRef<Image> m_pimageDefault;
  44. TRef<Image> m_pimage;
  45. EquipmentType m_equipmentType;
  46. Mount m_mount;
  47. TRef<IpartIGC> m_ppart;
  48. ZString m_strPrefix;
  49. public:
  50. Slot(
  51. LoadoutImpl* ploadout,
  52. EquipmentType equipmentType,
  53. Mount mount,
  54. Image* pimageDefault,
  55. const ZString& strPrefix
  56. ) :
  57. m_equipmentType(equipmentType),
  58. m_mount(mount),
  59. m_ploadout(ploadout),
  60. m_pimageDefault(pimageDefault),
  61. m_pimage(pimageDefault),
  62. m_strPrefix(strPrefix)
  63. {
  64. }
  65. //////////////////////////////////////////////////////////////////////////////
  66. //
  67. // Methods
  68. //
  69. //////////////////////////////////////////////////////////////////////////////
  70. IpartIGC* GetPart()
  71. {
  72. return m_ppart;
  73. }
  74. EquipmentType GetEquipmentType()
  75. {
  76. if (m_equipmentType == ET_Turret)
  77. return ET_Weapon;
  78. else
  79. return m_equipmentType;
  80. }
  81. Mount GetMount()
  82. {
  83. if (m_equipmentType == ET_Turret)
  84. return m_mount + m_ploadout->m_phullType->GetMaxFixedWeapons();
  85. else
  86. return m_mount;
  87. }
  88. static bool SlotValidForHull(const IhullTypeIGC* pht, EquipmentType equipmentType, Mount mount)
  89. {
  90. if (equipmentType == NA)
  91. return true;
  92. else if (equipmentType == ET_Weapon)
  93. return mount < pht->GetMaxFixedWeapons();
  94. else if (equipmentType == ET_Turret)
  95. return mount < pht->GetMaxWeapons() - pht->GetMaxFixedWeapons();
  96. else
  97. return pht->GetPartMask(equipmentType, mount) != 0;
  98. }
  99. void SetPart(IpartIGC* ppart)
  100. {
  101. m_ppart = ppart;
  102. if (ppart) {
  103. IpartTypeIGC* ppartType = m_ppart->GetPartType();
  104. //
  105. // Try to load the bitmap that fits this slot.
  106. //
  107. ZString str = (m_strPrefix + ZString(ppartType->GetModelName()) + "bmp").ToLower();
  108. m_pimage = GetModeler()->LoadImage(str, false, false);
  109. //
  110. // If we can't find the right bitmap load the default bitmap.
  111. //
  112. if (m_pimage == NULL) {
  113. ZString str = (ZString("l") + ZString(ppartType->GetModelName()) + "bmp").ToLower();
  114. m_pimage = GetModeler()->LoadImage(str, false);
  115. }
  116. } else {
  117. m_pimage = m_pimageDefault;
  118. }
  119. NeedPaint();
  120. }
  121. //////////////////////////////////////////////////////////////////////////////
  122. //
  123. // Pane Methods
  124. //
  125. //////////////////////////////////////////////////////////////////////////////
  126. void UpdateLayout()
  127. {
  128. m_pimageDefault->Update();
  129. InternalSetSize(
  130. WinPoint(133, 37)
  131. //::Cast(m_pimageDefault->GetBounds().GetRect().Size())
  132. );
  133. Pane::UpdateLayout();
  134. }
  135. void Paint(Surface* psurface)
  136. {
  137. psurface->BitBlt(WinPoint(0, 0), m_pimage->GetSurface());
  138. if (m_ppart)
  139. {
  140. // if this is a turret with a mounted weapon
  141. if (m_equipmentType == ET_Turret)
  142. {
  143. IhullTypeIGC* pht = trekClient.GetShip()->GetBaseHullType();
  144. if (pht)
  145. {
  146. // display the current gunner for that turret
  147. IshipIGC* pshipGunner
  148. = trekClient.GetShip()->GetGunner(GetMount() + pht->GetMaxFixedWeapons() -
  149. m_ppart->GetShip()->GetBaseHullType()->GetMaxFixedWeapons());
  150. if (pshipGunner)
  151. {
  152. psurface->DrawString(
  153. TrekResources::SmallFont(),
  154. MakeColorFromCOLORREF(TrekResources::WhiteColor()),
  155. WinPoint(3,24),
  156. pshipGunner->GetName()
  157. );
  158. }
  159. else
  160. {
  161. psurface->DrawString(
  162. TrekResources::SmallFont(),
  163. MakeColorFromCOLORREF(TrekResources::WhiteColor()),
  164. WinPoint(3,24),
  165. "<open>"
  166. );
  167. }
  168. }
  169. }
  170. // otherwise, if this is a launcher
  171. else
  172. {
  173. ObjectType type = m_ppart->GetObjectType();
  174. if ((type == OT_pack) || IlauncherIGC::IsLauncher(m_ppart->GetObjectType()))
  175. {
  176. ZString strText((int)m_ppart->GetAmount());
  177. int nTextWidth = TrekResources::SmallFont()->GetTextExtent(strText).X();
  178. // display the count of expendibles
  179. psurface->DrawString(
  180. TrekResources::SmallFont(),
  181. MakeColorFromCOLORREF(TrekResources::WhiteColor()),
  182. WinPoint(130 - nTextWidth, 24),
  183. strText
  184. );
  185. }
  186. }
  187. }
  188. }
  189. //////////////////////////////////////////////////////////////////////////////
  190. //
  191. // IMouseInput Methods
  192. //
  193. //////////////////////////////////////////////////////////////////////////////
  194. void MouseEnter(IInputProvider* pprovider, const Point& point)
  195. {
  196. m_ploadout->SlotEntered(this);
  197. trekClient.PlaySoundEffect(mouseoverSound);
  198. }
  199. void MouseLeave(IInputProvider* pprovider)
  200. {
  201. m_ploadout->SlotLeft(this);
  202. }
  203. MouseResult Button(IInputProvider* pprovider, const Point& point, int button, bool bCaptured, bool bInside, bool bDown)
  204. {
  205. if (bDown) {
  206. //m_ploadout->SlotEntered(this);
  207. m_ploadout->SlotClicked(this, button == 0, WinPoint::Cast(point));
  208. }
  209. return MouseResult();
  210. }
  211. void OnBoardShip(IshipIGC* pshipChild, IshipIGC* pshipParent)
  212. {
  213. if (pshipParent == trekClient.GetShip() || pshipParent == NULL)
  214. {
  215. NeedPaint();
  216. }
  217. }
  218. };
  219. typedef TList<TRef<Slot> > SlotList;
  220. //////////////////////////////////////////////////////////////////////////////
  221. //
  222. // Members
  223. //
  224. //////////////////////////////////////////////////////////////////////////////
  225. TRef<Modeler> m_pmodeler;
  226. TRef<Number> m_ptime;
  227. TRef<Pane> m_ppane;
  228. TRef<Pane> m_ppaneGeo;
  229. TRef<Image> m_pBlankImage;
  230. TRef<INameSpace> m_pnsLoadout;
  231. TRef<INameSpace> m_pnsLoadoutPane;
  232. TRef<INameSpace> m_pnsDefaultLoadout;
  233. SlotList m_listSlots;
  234. TRef<Slot> m_pslotMenu;
  235. TRef<IMenu> m_pmenu;
  236. TRef<IMenu> m_phullMenu;
  237. TRef<ISubmenuEventSink> m_psubmenuEventSink;
  238. //
  239. // IGC stuff
  240. //
  241. IshipIGC* m_pship;
  242. const IhullTypeIGC* m_phullType;
  243. IhullTypeIGC* m_phullTypeBase;
  244. float m_fSpecSignature;
  245. float m_fSpecMass;
  246. //
  247. // Geo Pane
  248. //
  249. TRef<Camera> m_pcamera;
  250. TRef<Viewport> m_pviewport;
  251. TRef<WrapGeo> m_pwrapGeo;
  252. TRef<WrapImage> m_pwrapImageGeo;
  253. /*
  254. TRef<Material> m_pmaterialCone;
  255. TRef<VisibleGeo> m_pvisibleGeoCone;
  256. TRef<MatrixTransform> m_ptransformCone;
  257. TRef<ModifiableNumber> m_pnumberAngleCone;
  258. float m_scaleCone;
  259. */
  260. TRef<StringPane> m_pstringPartMask;
  261. //
  262. // Buttons
  263. //
  264. TRef<ButtonPane> m_pbuttonDefault;
  265. TRef<ButtonPane> m_pbuttonNext;
  266. TRef<ButtonPane> m_pbuttonPrevious;
  267. TRef<ButtonPane> m_pbuttonLaunch;
  268. TRef<ButtonPane> m_pbuttonBuy;
  269. TRef<ButtonPane> m_pbuttonConfirm;
  270. TRef<ButtonPane> m_pbuttonBack;
  271. TRef<ButtonPane> m_pbuttonHullList;
  272. TRef<Pane> m_ppaneHoverBuy;
  273. TRef<Pane> m_ppaneHoverConfirm;
  274. TRef<PointValue> m_ppointBuyButton;
  275. //
  276. // Exported Values
  277. //
  278. TRef<WrapImage> m_pwrapImagePart;
  279. TRef<WrapImage> m_pwrapImageCiv;
  280. TRef<WrapImage> m_pwrapImageHullCiv;
  281. TRef<ModifiableString> m_pstringGunners[c_maxMountedWeapons];
  282. TRef<ModifiableString> m_pstringTitle ;
  283. TRef<ModifiableString> m_pstringPartName ;
  284. TRef<ModifiableString> m_pstringPartDescription;
  285. TRef<ModifiableString> m_pstringHullDescription;
  286. TRef<ModifiableNumber> m_pnumberMoney;
  287. TRef<ModifiableNumber> m_pnumberOldShipCost;
  288. TRef<ModifiableNumber> m_pnumberNewShipCost;
  289. TRef<ModifiableNumber> m_pnumberLoadoutShipState;
  290. // parts
  291. TRef<ModifiableNumber> m_pnumberPartID ;
  292. TRef<ModifiableNumber> m_pnumberPartMask ;
  293. TRef<ModifiableNumber> m_pnumberEquipmentType ;
  294. TRef<ModifiableNumber> m_pnumberSignature ;
  295. TRef<ModifiableNumber> m_pnumberMass ;
  296. TRef<ModifiableNumber> m_pnumberSignatureNumber ;
  297. TRef<ModifiableNumber> m_pnumberMassNumber ;
  298. TRef<ModifiableNumber> m_pnumberWeaponDamage ;
  299. TRef<ModifiableNumber> m_pnumberWeaponRate ;
  300. TRef<ModifiableNumber> m_pnumberWeaponRange ;
  301. TRef<ModifiableNumber> m_pnumberWeaponSpeed ;
  302. TRef<ModifiableNumber> m_pnumberWeaponDamageNumber ;
  303. TRef<ModifiableNumber> m_pnumberWeaponRateNumber ;
  304. TRef<ModifiableNumber> m_pnumberWeaponRangeNumber ;
  305. TRef<ModifiableNumber> m_pnumberWeaponSpeedNumber ;
  306. TRef<ModifiableNumber> m_pnumberShieldRegen ;
  307. TRef<ModifiableNumber> m_pnumberShieldHitPts ;
  308. TRef<ModifiableNumber> m_pnumberShieldRegenNumber ;
  309. TRef<ModifiableNumber> m_pnumberShieldHitPtsNumber ;
  310. TRef<ModifiableNumber> m_pnumberCloakCloaking ;
  311. TRef<ModifiableNumber> m_pnumberCloakDuration ;
  312. TRef<ModifiableNumber> m_pnumberCloakCloakingNumber ;
  313. TRef<ModifiableNumber> m_pnumberCloakDurationNumber ;
  314. TRef<ModifiableNumber> m_pnumberMagazineDamage ;
  315. TRef<ModifiableNumber> m_pnumberMagazineRange ;
  316. TRef<ModifiableNumber> m_pnumberMagazineLockTime ;
  317. TRef<ModifiableNumber> m_pnumberMagazineMaxLock ;
  318. TRef<ModifiableNumber> m_pnumberMagazineDamageNumber ;
  319. TRef<ModifiableNumber> m_pnumberMagazineRangeNumber ;
  320. TRef<ModifiableNumber> m_pnumberMagazineLockTimeNumber ;
  321. TRef<ModifiableNumber> m_pnumberMagazineMaxLockNumber ;
  322. TRef<ModifiableNumber> m_pnumberAfterburnerMaxSpeed ;
  323. TRef<ModifiableNumber> m_pnumberAfterburnerBurnRate ;
  324. TRef<ModifiableNumber> m_pnumberAfterburnerMaxSpeedNumber ;
  325. TRef<ModifiableNumber> m_pnumberAfterburnerBurnRateNumber ;
  326. TRef<ModifiableNumber> m_pnumberChaffStrength ;
  327. TRef<ModifiableNumber> m_pnumberChaffStrengthNumber ;
  328. TRef<ModifiableNumber> m_pnumberPackQuantityNumber ;
  329. TRef<ModifiableNumber> m_pnumberProbeScanRange ;
  330. TRef<ModifiableNumber> m_pnumberProbeVisibility ;
  331. TRef<ModifiableNumber> m_pnumberProbeHitPts ;
  332. TRef<ModifiableNumber> m_pnumberProbeLifespan ;
  333. TRef<ModifiableNumber> m_pnumberProbeScanRangeNumber ;
  334. TRef<ModifiableNumber> m_pnumberProbeVisibilityNumber ;
  335. TRef<ModifiableNumber> m_pnumberProbeHitPtsNumber ;
  336. TRef<ModifiableNumber> m_pnumberProbeLifespanNumber ;
  337. TRef<ModifiableNumber> m_pnumberMineVisibility ;
  338. TRef<ModifiableNumber> m_pnumberMineVisibilityNumber ;
  339. TRef<ModifiableNumber> m_pnumberMineDamage ;
  340. TRef<ModifiableNumber> m_pnumberMineRadius ;
  341. TRef<ModifiableNumber> m_pnumberMineLifespan ;
  342. TRef<ModifiableNumber> m_pnumberMineDamageNumber ;
  343. TRef<ModifiableNumber> m_pnumberMineRadiusNumber ;
  344. TRef<ModifiableNumber> m_pnumberMineLifespanNumber ;
  345. // hull
  346. TRef<ModifiableNumber> m_pnumberHullMaxSpeed ;
  347. TRef<ModifiableNumber> m_pnumberHullAcceleration;
  348. TRef<ModifiableNumber> m_pnumberHullTurnRate ;
  349. TRef<ModifiableNumber> m_pnumberHullHitPoints ;
  350. TRef<ModifiableNumber> m_pnumberHullEnergy ;
  351. TRef<ModifiableNumber> m_pnumberHullScanRange ;
  352. TRef<ModifiableNumber> m_pnumberHullSignature ;
  353. TRef<ModifiableNumber> m_pnumberHullMass ;
  354. TRef<ModifiableNumber> m_pnumberHullMaxSpeedNumber ;
  355. TRef<ModifiableNumber> m_pnumberHullAccelerationNumber;
  356. TRef<ModifiableNumber> m_pnumberHullTurnRateNumber ;
  357. TRef<ModifiableNumber> m_pnumberHullHitPointsNumber ;
  358. TRef<ModifiableNumber> m_pnumberHullEnergyNumber ;
  359. TRef<ModifiableNumber> m_pnumberHullScanRangeNumber ;
  360. TRef<ModifiableNumber> m_pnumberHullSignatureNumber ;
  361. TRef<ModifiableNumber> m_pnumberHullMassNumber ;
  362. TRef<ModifiableNumber> m_pnumberBaseHullMaxSpeed ;
  363. TRef<ModifiableNumber> m_pnumberBaseHullAcceleration;
  364. TRef<ModifiableNumber> m_pnumberBaseHullTurnRate ;
  365. TRef<ModifiableNumber> m_pnumberBaseHullHitPoints ;
  366. TRef<ModifiableNumber> m_pnumberBaseHullEnergy ;
  367. TRef<ModifiableNumber> m_pnumberBaseHullScanRange ;
  368. TRef<ModifiableNumber> m_pnumberBaseHullSignature ;
  369. TRef<ModifiableNumber> m_pnumberBaseHullMass ;
  370. TRef<ModifiableNumber> m_pnumberBaseHullMaxSpeedNumber ;
  371. TRef<ModifiableNumber> m_pnumberBaseHullAccelerationNumber;
  372. TRef<ModifiableNumber> m_pnumberBaseHullTurnRateNumber ;
  373. TRef<ModifiableNumber> m_pnumberBaseHullHitPointsNumber ;
  374. TRef<ModifiableNumber> m_pnumberBaseHullEnergyNumber ;
  375. TRef<ModifiableNumber> m_pnumberBaseHullScanRangeNumber ;
  376. TRef<ModifiableNumber> m_pnumberBaseHullSignatureNumber ;
  377. TRef<ModifiableNumber> m_pnumberBaseHullMassNumber ;
  378. TRef<ModifiableNumber> m_pnumberHullDefenseClass ;
  379. TRef<ModifiableNumber> m_pnumberBaseHullDefenseClass ;
  380. TRef<ModifiableNumber> m_pnumberShieldDefenseClass ;
  381. TRef<ModifiableNumber> m_pnumberWeaponDamageBonus ;
  382. TRef<ModifiableNumber> m_pnumberMagazineDamageBonus ;
  383. //
  384. // Imported Values
  385. //
  386. float m_maxWeaponRate ;
  387. float m_maxWeaponPower ;
  388. float m_maxWeaponRange ;
  389. float m_maxWeaponSpeed ;
  390. float m_maxShieldParticle;
  391. float m_maxShieldEnergy ;
  392. float m_maxShieldRegen ;
  393. float m_maxShieldHitPts ;
  394. float m_maxCloakEnergy ;
  395. float m_maxPartMass ;
  396. float m_maxPartSignature ;
  397. float m_maxMagazineHitDamage ;
  398. float m_maxMagazineAreaDamage ;
  399. float m_maxMagazineRange ;
  400. float m_maxMagazineLockTime ;
  401. float m_maxMagazineMaxLock ;
  402. float m_maxAfterburnerMaxThrust;
  403. float m_maxAfterburnerBurnRate;
  404. float m_maxAfterburnerOnRate;
  405. float m_maxChaffStrength;
  406. float m_maxProbeScanRange;
  407. float m_maxProbeHitPts;
  408. float m_maxProbeLifespan;
  409. float m_maxMineDamage ;
  410. float m_maxMineRadius ;
  411. float m_maxMineLifespan ;
  412. float m_maxMaxSpeed ;
  413. float m_maxAcceleration ;
  414. float m_maxTurnRate ;
  415. float m_maxHitPoints ;
  416. float m_maxEnergy ;
  417. float m_maxScanRange ;
  418. float m_maxHullSignature;
  419. float m_maxHullMass ;
  420. //////////////////////////////////////////////////////////////////////////////
  421. //
  422. // Constructor
  423. //
  424. //////////////////////////////////////////////////////////////////////////////
  425. LoadoutImpl(Modeler* pmodeler, Number* ptime) :
  426. m_pmodeler(pmodeler),
  427. m_ptime(ptime),
  428. m_phullType(NULL),
  429. m_phullTypeBase(NULL)
  430. {
  431. // calculate the mass and signature of the default loadout
  432. IshipIGC* pshipSource = trekClient.GetShip()->GetSourceShip();
  433. Money budget = moneyLots;
  434. m_pship = trekClient.CreateEmptyShip();
  435. trekClient.BuyDefaultLoadout(m_pship, trekClient.GetShip()->GetStation(),
  436. pshipSource->GetBaseHullType(), &budget);
  437. m_fSpecMass = m_pship->GetMass();
  438. m_fSpecSignature = m_pship->GetSignature();
  439. m_pship->Terminate();
  440. m_pship->Release();
  441. // copy their current loadout, upgrading if we can.
  442. m_pship = trekClient.CreateEmptyShip();
  443. trekClient.RestoreLoadout(pshipSource, m_pship, trekClient.GetShip()->GetStation(),
  444. trekClient.GetMoney() + pshipSource->GetValue());
  445. InitializeMDL();
  446. InitializePanes();
  447. UpdateHullType();
  448. UpdateCivBitmap();
  449. UpdatePartInfo(NULL, NULL, NULL);
  450. UpdateNextAndPrevButtons();
  451. m_psubmenuEventSink = ISubmenuEventSink::CreateDelegate(this);
  452. }
  453. ~LoadoutImpl()
  454. {
  455. CloseMenu();
  456. trekClient.SaveLoadout(m_pship);
  457. m_pship->Terminate();
  458. m_pship->Release();
  459. m_pmodeler->UnloadNameSpace("defaultloadout");
  460. m_pmodeler->UnloadNameSpace("loadoutpane");
  461. m_pmodeler->UnloadNameSpace("loadout");
  462. m_pmodeler->UnloadNameSpace("loadoutdata");
  463. m_pmodeler->UnloadNameSpace("loadoutinclude");
  464. }
  465. //////////////////////////////////////////////////////////////////////////////
  466. //
  467. // Initialization
  468. //
  469. //////////////////////////////////////////////////////////////////////////////
  470. void InitializeMDL()
  471. {
  472. //
  473. // exports
  474. //
  475. TRef<INameSpace> pnsLoadoutData = m_pmodeler->CreateNameSpace("loadoutdata", m_pmodeler->GetNameSpace("effect"));
  476. for (int index = 0; index < c_maxMountedWeapons; index++) {
  477. pnsLoadoutData->AddMember(
  478. "gunner" + ZString(index),
  479. m_pstringGunners[index] = new ModifiableString("unmanned")
  480. );
  481. }
  482. pnsLoadoutData->AddMember("titleString", m_pstringTitle = new ModifiableString(ZString()));
  483. pnsLoadoutData->AddMember("hullDescriptionString", m_pstringHullDescription = new ModifiableString(ZString()));
  484. pnsLoadoutData->AddMember("partNameString", m_pstringPartName = new ModifiableString(ZString()));
  485. pnsLoadoutData->AddMember("partDescriptionString", m_pstringPartDescription = new ModifiableString(ZString()));
  486. pnsLoadoutData->AddMember("money", m_pnumberMoney = new ModifiableNumber((float)trekClient.GetMoney()));
  487. pnsLoadoutData->AddMember("oldShipCost", m_pnumberOldShipCost = new ModifiableNumber((float)trekClient.GetShip()->GetValue()));
  488. pnsLoadoutData->AddMember("newShipCost", m_pnumberNewShipCost = new ModifiableNumber((float)m_pship->GetValue()));
  489. pnsLoadoutData->AddMember("loadoutShipState", m_pnumberLoadoutShipState = new ModifiableNumber(0));
  490. pnsLoadoutData->AddMember("partID", m_pnumberPartID = new ModifiableNumber(0));
  491. pnsLoadoutData->AddMember("partMask", m_pnumberPartMask = new ModifiableNumber(0));
  492. //pnsLoadoutData->AddMember("partEquipmentType", m_pnumberEquipmentType = new ModifiableNumber(0));
  493. pnsLoadoutData->AddMember("partSignature", m_pnumberSignature = new ModifiableNumber(0));
  494. pnsLoadoutData->AddMember("partMass", m_pnumberMass = new ModifiableNumber(0));
  495. pnsLoadoutData->AddMember("partSignatureNumber", m_pnumberSignatureNumber = new ModifiableNumber(0));
  496. pnsLoadoutData->AddMember("partMassNumber", m_pnumberMassNumber = new ModifiableNumber(0));
  497. pnsLoadoutData->AddMember("weaponDamage", m_pnumberWeaponDamage = new ModifiableNumber(0));
  498. pnsLoadoutData->AddMember("weaponRate", m_pnumberWeaponRate = new ModifiableNumber(0));
  499. pnsLoadoutData->AddMember("weaponRange", m_pnumberWeaponRange = new ModifiableNumber(0));
  500. pnsLoadoutData->AddMember("weaponSpeed", m_pnumberWeaponSpeed = new ModifiableNumber(0));
  501. pnsLoadoutData->AddMember("weaponDamageNumber", m_pnumberWeaponDamageNumber = new ModifiableNumber(0));
  502. pnsLoadoutData->AddMember("weaponRateNumber", m_pnumberWeaponRateNumber = new ModifiableNumber(0));
  503. pnsLoadoutData->AddMember("weaponRangeNumber", m_pnumberWeaponRangeNumber = new ModifiableNumber(0));
  504. pnsLoadoutData->AddMember("weaponSpeedNumber", m_pnumberWeaponSpeedNumber = new ModifiableNumber(0));
  505. pnsLoadoutData->AddMember("shieldRegen", m_pnumberShieldRegen = new ModifiableNumber(0));
  506. pnsLoadoutData->AddMember("shieldHitPts", m_pnumberShieldHitPts = new ModifiableNumber(0));
  507. pnsLoadoutData->AddMember("shieldRegenNumber", m_pnumberShieldRegenNumber = new ModifiableNumber(0));
  508. pnsLoadoutData->AddMember("shieldHitPtsNumber", m_pnumberShieldHitPtsNumber = new ModifiableNumber(0));
  509. pnsLoadoutData->AddMember("equipmentType", m_pnumberEquipmentType = new ModifiableNumber(0));
  510. pnsLoadoutData->AddMember("cloakCloaking", m_pnumberCloakCloaking = new ModifiableNumber(0));
  511. pnsLoadoutData->AddMember("cloakDuration", m_pnumberCloakDuration = new ModifiableNumber(0));
  512. pnsLoadoutData->AddMember("cloakCloakingNumber", m_pnumberCloakCloakingNumber = new ModifiableNumber(0));
  513. pnsLoadoutData->AddMember("cloakDurationNumber", m_pnumberCloakDurationNumber = new ModifiableNumber(0));
  514. pnsLoadoutData->AddMember("magazineDamage", m_pnumberMagazineDamage = new ModifiableNumber(0));
  515. pnsLoadoutData->AddMember("magazineRange", m_pnumberMagazineRange = new ModifiableNumber(0));
  516. pnsLoadoutData->AddMember("magazineLockTime", m_pnumberMagazineLockTime = new ModifiableNumber(0));
  517. pnsLoadoutData->AddMember("magazineMaxLock", m_pnumberMagazineMaxLock = new ModifiableNumber(0));
  518. pnsLoadoutData->AddMember("magazineDamageNumber", m_pnumberMagazineDamageNumber = new ModifiableNumber(0));
  519. pnsLoadoutData->AddMember("magazineRangeNumber", m_pnumberMagazineRangeNumber = new ModifiableNumber(0));
  520. pnsLoadoutData->AddMember("magazineLockTimeNumber", m_pnumberMagazineLockTimeNumber = new ModifiableNumber(0));
  521. pnsLoadoutData->AddMember("magazineMaxLockNumber", m_pnumberMagazineMaxLockNumber = new ModifiableNumber(0));
  522. pnsLoadoutData->AddMember("afterburnerMaxSpeed", m_pnumberAfterburnerMaxSpeed = new ModifiableNumber(0));
  523. pnsLoadoutData->AddMember("afterburnerBurnRate", m_pnumberAfterburnerBurnRate = new ModifiableNumber(0));
  524. pnsLoadoutData->AddMember("afterburnerMaxSpeedNumber", m_pnumberAfterburnerMaxSpeedNumber = new ModifiableNumber(0));
  525. pnsLoadoutData->AddMember("afterburnerBurnRateNumber", m_pnumberAfterburnerBurnRateNumber = new ModifiableNumber(0));
  526. pnsLoadoutData->AddMember("chaffStrength", m_pnumberChaffStrength = new ModifiableNumber(0));
  527. pnsLoadoutData->AddMember("chaffStrengthNumber", m_pnumberChaffStrengthNumber = new ModifiableNumber(0));
  528. pnsLoadoutData->AddMember("packQuantityNumber", m_pnumberPackQuantityNumber = new ModifiableNumber(0));
  529. pnsLoadoutData->AddMember("probeScanRange", m_pnumberProbeScanRange = new ModifiableNumber(0));
  530. pnsLoadoutData->AddMember("probeVisibility", m_pnumberProbeVisibility = new ModifiableNumber(0));
  531. pnsLoadoutData->AddMember("probeHitPts", m_pnumberProbeHitPts = new ModifiableNumber(0));
  532. pnsLoadoutData->AddMember("probeLifespan", m_pnumberProbeLifespan = new ModifiableNumber(0));
  533. pnsLoadoutData->AddMember("probeScanRangeNumber", m_pnumberProbeScanRangeNumber = new ModifiableNumber(0));
  534. pnsLoadoutData->AddMember("probeVisibilityNumber", m_pnumberProbeVisibilityNumber = new ModifiableNumber(0));
  535. pnsLoadoutData->AddMember("probeHitPtsNumber", m_pnumberProbeHitPtsNumber = new ModifiableNumber(0));
  536. pnsLoadoutData->AddMember("probeLifespanNumber", m_pnumberProbeLifespanNumber = new ModifiableNumber(0));
  537. pnsLoadoutData->AddMember("mineVisibility", m_pnumberMineVisibility = new ModifiableNumber(0));
  538. pnsLoadoutData->AddMember("mineVisibilityNumber", m_pnumberMineVisibilityNumber = new ModifiableNumber(0));
  539. pnsLoadoutData->AddMember("mineDamage", m_pnumberMineDamage = new ModifiableNumber(0));
  540. pnsLoadoutData->AddMember("mineRadius", m_pnumberMineRadius = new ModifiableNumber(0));
  541. pnsLoadoutData->AddMember("mineLifespan", m_pnumberMineLifespan = new ModifiableNumber(0));
  542. pnsLoadoutData->AddMember("mineDamageNumber", m_pnumberMineDamageNumber = new ModifiableNumber(0));
  543. pnsLoadoutData->AddMember("mineRadiusNumber", m_pnumberMineRadiusNumber = new ModifiableNumber(0));
  544. pnsLoadoutData->AddMember("mineLifespanNumber", m_pnumberMineLifespanNumber = new ModifiableNumber(0));
  545. pnsLoadoutData->AddMember("hullMaxSpeed", m_pnumberHullMaxSpeed = new ModifiableNumber(0));
  546. pnsLoadoutData->AddMember("hullAcceleration", m_pnumberHullAcceleration = new ModifiableNumber(0));
  547. pnsLoadoutData->AddMember("hullTurnRate", m_pnumberHullTurnRate = new ModifiableNumber(0));
  548. pnsLoadoutData->AddMember("hullHitPoints", m_pnumberHullHitPoints = new ModifiableNumber(0));
  549. pnsLoadoutData->AddMember("hullMaxEnergy", m_pnumberHullEnergy = new ModifiableNumber(0));
  550. pnsLoadoutData->AddMember("hullScanRange", m_pnumberHullScanRange = new ModifiableNumber(0));
  551. pnsLoadoutData->AddMember("hullSignature", m_pnumberHullSignature = new ModifiableNumber(0));
  552. pnsLoadoutData->AddMember("hullMass", m_pnumberHullMass = new ModifiableNumber(0));
  553. pnsLoadoutData->AddMember("hullMaxSpeedNumber", m_pnumberHullMaxSpeedNumber = new ModifiableNumber(0));
  554. pnsLoadoutData->AddMember("hullAccelerationNumber", m_pnumberHullAccelerationNumber = new ModifiableNumber(0));
  555. pnsLoadoutData->AddMember("hullTurnRateNumber", m_pnumberHullTurnRateNumber = new ModifiableNumber(0));
  556. pnsLoadoutData->AddMember("hullHitPointsNumber", m_pnumberHullHitPointsNumber = new ModifiableNumber(0));
  557. pnsLoadoutData->AddMember("hullMaxEnergyNumber", m_pnumberHullEnergyNumber = new ModifiableNumber(0));
  558. pnsLoadoutData->AddMember("hullScanRangeNumber", m_pnumberHullScanRangeNumber = new ModifiableNumber(0));
  559. pnsLoadoutData->AddMember("hullSignatureNumber", m_pnumberHullSignatureNumber = new ModifiableNumber(0));
  560. pnsLoadoutData->AddMember("hullMassNumber", m_pnumberHullMassNumber = new ModifiableNumber(0));
  561. pnsLoadoutData->AddMember("baseHullMaxSpeed", m_pnumberBaseHullMaxSpeed = new ModifiableNumber(0));
  562. pnsLoadoutData->AddMember("baseHullAcceleration", m_pnumberBaseHullAcceleration = new ModifiableNumber(0));
  563. pnsLoadoutData->AddMember("baseHullTurnRate", m_pnumberBaseHullTurnRate = new ModifiableNumber(0));
  564. pnsLoadoutData->AddMember("baseHullHitPoints", m_pnumberBaseHullHitPoints = new ModifiableNumber(0));
  565. pnsLoadoutData->AddMember("baseHullMaxEnergy", m_pnumberBaseHullEnergy = new ModifiableNumber(0));
  566. pnsLoadoutData->AddMember("baseHullScanRange", m_pnumberBaseHullScanRange = new ModifiableNumber(0));
  567. pnsLoadoutData->AddMember("baseHullSignature", m_pnumberBaseHullSignature = new ModifiableNumber(0));
  568. pnsLoadoutData->AddMember("baseHullMass", m_pnumberBaseHullMass = new ModifiableNumber(0));
  569. pnsLoadoutData->AddMember("baseHullMaxSpeedNumber", m_pnumberBaseHullMaxSpeedNumber = new ModifiableNumber(0));
  570. pnsLoadoutData->AddMember("baseHullAccelerationNumber", m_pnumberBaseHullAccelerationNumber = new ModifiableNumber(0));
  571. pnsLoadoutData->AddMember("baseHullTurnRateNumber", m_pnumberBaseHullTurnRateNumber = new ModifiableNumber(0));
  572. pnsLoadoutData->AddMember("baseHullHitPointsNumber", m_pnumberBaseHullHitPointsNumber = new ModifiableNumber(0));
  573. pnsLoadoutData->AddMember("baseHullMaxEnergyNumber", m_pnumberBaseHullEnergyNumber = new ModifiableNumber(0));
  574. pnsLoadoutData->AddMember("baseHullScanRangeNumber", m_pnumberBaseHullScanRangeNumber = new ModifiableNumber(0));
  575. pnsLoadoutData->AddMember("baseHullSignatureNumber", m_pnumberBaseHullSignatureNumber = new ModifiableNumber(0));
  576. pnsLoadoutData->AddMember("baseHullMassNumber", m_pnumberBaseHullMassNumber = new ModifiableNumber(0));
  577. pnsLoadoutData->AddMember("partImage", (Value*)(m_pwrapImagePart = new WrapImage(Image::GetEmpty())));
  578. pnsLoadoutData->AddMember("civImage", (Value*)(m_pwrapImageCiv = new WrapImage(Image::GetEmpty())));
  579. pnsLoadoutData->AddMember("civHullImage", (Value*)(m_pwrapImageHullCiv = new WrapImage(Image::GetEmpty())));
  580. pnsLoadoutData->AddMember("hullDefenseClassNumber", m_pnumberHullDefenseClass = new ModifiableNumber(0));
  581. pnsLoadoutData->AddMember("baseHullDefenseClassNumber", m_pnumberBaseHullDefenseClass = new ModifiableNumber(0));
  582. pnsLoadoutData->AddMember("shieldDefenseClassNumber", m_pnumberShieldDefenseClass = new ModifiableNumber(0));
  583. pnsLoadoutData->AddMember("weaponDamageClassNumber", m_pnumberWeaponDamageBonus = new ModifiableNumber(0));
  584. pnsLoadoutData->AddMember("magazineDamageClassNumber", m_pnumberMagazineDamageBonus = new ModifiableNumber(0));
  585. //
  586. // imports
  587. //
  588. TRef<INameSpace> pnsPartInfo = m_pmodeler->GetNameSpace("partinfo");
  589. m_maxWeaponRate = pnsPartInfo->FindNumber("maxWeaponRate");
  590. m_maxWeaponPower = pnsPartInfo->FindNumber("maxWeaponPower");
  591. m_maxWeaponRange = pnsPartInfo->FindNumber("maxWeaponRange");
  592. m_maxWeaponSpeed = pnsPartInfo->FindNumber("maxWeaponSpeed");
  593. m_maxShieldRegen = pnsPartInfo->FindNumber("maxShieldRegen");
  594. m_maxShieldHitPts = pnsPartInfo->FindNumber("maxShieldHitPts");
  595. m_maxCloakEnergy = pnsPartInfo->FindNumber("maxCloakEnergy");
  596. m_maxPartMass = pnsPartInfo->FindNumber("maxPartMass");
  597. m_maxPartSignature = pnsPartInfo->FindNumber("maxPartSignature");
  598. m_maxMagazineHitDamage = pnsPartInfo->FindNumber("maxMagazineHitDamage");
  599. m_maxMagazineAreaDamage = pnsPartInfo->FindNumber("maxMagazineAreaDamage");
  600. m_maxMagazineRange = pnsPartInfo->FindNumber("maxMagazineRange");
  601. m_maxMagazineLockTime = pnsPartInfo->FindNumber("maxMagazineLockTime");
  602. m_maxMagazineMaxLock = pnsPartInfo->FindNumber("maxMagazineMaxLock");
  603. m_maxAfterburnerMaxThrust = pnsPartInfo->FindNumber("maxAfterburnerMaxThrust");
  604. m_maxAfterburnerBurnRate = pnsPartInfo->FindNumber("maxAfterburnerBurnRate");
  605. m_maxAfterburnerOnRate = pnsPartInfo->FindNumber("maxAfterburnerOnRate");
  606. m_maxChaffStrength = pnsPartInfo->FindNumber("maxChaffStrength");
  607. m_maxProbeScanRange = pnsPartInfo->FindNumber("maxProbeScanRange");
  608. m_maxProbeHitPts = pnsPartInfo->FindNumber("maxProbeHitPts");
  609. m_maxProbeLifespan = pnsPartInfo->FindNumber("maxProbeLifespan");
  610. m_maxMineDamage = pnsPartInfo->FindNumber("maxMineDamage");
  611. m_maxMineRadius = pnsPartInfo->FindNumber("maxMineRadius");
  612. m_maxMineLifespan = pnsPartInfo->FindNumber("maxMineLifespan");
  613. m_pmodeler->UnloadNameSpace("partinfo");
  614. TRef<INameSpace> pnsHullInfo = m_pmodeler->GetNameSpace("hullinfo");
  615. m_maxMaxSpeed = pnsHullInfo->FindNumber("maxHullMaxSpeed" );
  616. m_maxAcceleration = pnsHullInfo->FindNumber("maxHullAcceleration");
  617. m_maxTurnRate = pnsHullInfo->FindNumber("maxHullTurnRate" );
  618. m_maxHitPoints = pnsHullInfo->FindNumber("maxHullHitPoints" );
  619. m_maxEnergy = pnsHullInfo->FindNumber("maxHullMaxEnergy" );
  620. m_maxScanRange = pnsHullInfo->FindNumber("maxHullScanRange" );
  621. m_maxHullSignature = pnsHullInfo->FindNumber("maxHullSignature" );
  622. m_maxHullMass = pnsHullInfo->FindNumber("maxHullMass" );
  623. m_pmodeler->UnloadNameSpace("hullinfo");
  624. //
  625. // we use these namespaces
  626. //
  627. m_pnsLoadout = m_pmodeler->GetNameSpace("loadout");
  628. m_pnsLoadoutPane = m_pmodeler->GetNameSpace("loadoutpane");
  629. m_pnsDefaultLoadout = m_pmodeler->GetNameSpace("defaultloadout");
  630. }
  631. void InitializePanes()
  632. {
  633. //
  634. // Get the pane
  635. //
  636. CastTo(m_ppane, m_pnsLoadoutPane->FindMember("loadoutPane"));
  637. //
  638. // Add the Geo Pane
  639. //
  640. m_ppaneGeo = CreateGeoPane(
  641. m_pnsLoadoutPane->FindPoint("geoSize"),
  642. m_pnsLoadoutPane->FindPoint("geoPosition")
  643. );
  644. m_ppaneGeo->SetOffset(m_pnsLoadoutPane->FindWinPoint("geoPosition"));
  645. m_ppane->InsertAtTop(m_ppaneGeo);
  646. //
  647. // The Buttons
  648. //
  649. CastTo(m_pbuttonDefault , m_pnsLoadoutPane->FindMember("defaultButtonPane" ));
  650. CastTo(m_pbuttonNext , m_pnsLoadoutPane->FindMember("nextButtonPane" ));
  651. CastTo(m_pbuttonPrevious, m_pnsLoadoutPane->FindMember("previousButtonPane"));
  652. CastTo(m_pbuttonLaunch , m_pnsLoadoutPane->FindMember("launchButtonPane" ));
  653. CastTo(m_pbuttonBuy , m_pnsLoadoutPane->FindMember("buyButtonPane" ));
  654. CastTo(m_pbuttonConfirm , m_pnsLoadoutPane->FindMember("confirmButtonPane" ));
  655. CastTo(m_pbuttonBack , m_pnsLoadoutPane->FindMember("backButtonPane" ));
  656. CastTo(m_pbuttonHullList, m_pnsLoadoutPane->FindMember("hullListButtonPane"));
  657. CastTo(m_ppaneHoverBuy , m_pnsLoadoutPane->FindMember("buyHoverPane" ));
  658. CastTo(m_ppaneHoverConfirm, m_pnsLoadoutPane->FindMember("confirmHoverPane"));
  659. CastTo(m_ppointBuyButton , m_pnsLoadoutPane->FindMember("buyBtnPosition" ));
  660. m_pbuttonHullList->SetDownTrigger(true);
  661. AddEventTarget(OnButtonDefault , m_pbuttonDefault ->GetEventSource());
  662. AddEventTarget(OnButtonNext , m_pbuttonNext ->GetEventSource());
  663. AddEventTarget(OnButtonPrevious, m_pbuttonPrevious->GetEventSource());
  664. AddEventTarget(OnButtonLaunch , m_pbuttonLaunch ->GetEventSource());
  665. AddEventTarget(OnButtonBuy , m_pbuttonBuy ->GetEventSource());
  666. AddEventTarget(OnButtonBuy , m_pbuttonConfirm ->GetEventSource());
  667. AddEventTarget(OnButtonBack , m_pbuttonBack ->GetEventSource());
  668. AddEventTarget(OnButtonHullList, m_pbuttonHullList->GetEventSource());
  669. }
  670. //////////////////////////////////////////////////////////////////////////////
  671. //
  672. // Screen public methods
  673. //
  674. //////////////////////////////////////////////////////////////////////////////
  675. Pane* GetPane()
  676. {
  677. return m_ppane;
  678. }
  679. void OnFrame()
  680. {
  681. UpdateButtons();
  682. }
  683. //////////////////////////////////////////////////////////////////////////////
  684. //
  685. // Methods
  686. //
  687. //////////////////////////////////////////////////////////////////////////////
  688. void UpdateCivBitmap()
  689. {
  690. IsideIGC* pside = trekClient.GetSide();
  691. if (pside) {
  692. ZString str = ZString(pside->GetCivilization()->GetIconName()).ToLower() + "loadoutpanebmp";
  693. m_pwrapImageCiv->SetImage(GetModeler()->LoadImage(str, false));
  694. ZString str2 = ZString(pside->GetCivilization()->GetIconName()).ToLower() + "hullinfobmp";
  695. m_pwrapImageHullCiv->SetImage(GetModeler()->LoadImage(str2, false));
  696. } else {
  697. m_pwrapImageCiv->SetImage(GetModeler()->LoadImage("loadoutpanemp", false));
  698. m_pwrapImageHullCiv->SetImage(GetModeler()->LoadImage("hullinfomp", false));
  699. }
  700. }
  701. TRef<Pane> CreateGeoPane(const Point& size, const Point& offset)
  702. {
  703. m_pcamera = new Camera();
  704. m_pcamera->SetZClip(1, 10000);
  705. m_pcamera->SetFOV(RadiansFromDegrees(50));
  706. Rect rect(Point(0, 0), size);
  707. TRef<RectValue> prect = new RectValue(rect);
  708. m_pviewport = new Viewport(m_pcamera, prect);
  709. m_pwrapGeo = new WrapGeo(Geo::GetEmpty());
  710. TRef<Image> pimage =
  711. new GroupImage(
  712. m_pwrapImageGeo = new WrapImage(Image::GetEmpty()),
  713. new GeoImage(
  714. new TransformGeo(
  715. new TransformGeo(
  716. m_pwrapGeo,
  717. new AnimateRotateTransform(
  718. new VectorValue(Vector(0, 1, 0)),
  719. Multiply(m_ptime, new Number(1.0))
  720. )
  721. ),
  722. new RotateTransform(Vector(1, 0, 0), pi/8)
  723. ),
  724. m_pviewport,
  725. true
  726. ),
  727. new TranslateImage(
  728. m_pwrapImageCiv,
  729. Point(-offset.X(), -(600 - size.Y() - offset.Y()))
  730. )
  731. );
  732. //
  733. // Give this guy a zbuffer
  734. //
  735. return
  736. new AnimatedImagePane(
  737. CreatePaneImage(
  738. GetEngine(),
  739. SurfaceType3D() | SurfaceTypeZBuffer(),
  740. false,
  741. new AnimatedImagePane(
  742. pimage,
  743. rect
  744. )
  745. )
  746. );
  747. }
  748. //////////////////////////////////////////////////////////////////////////////
  749. //
  750. //
  751. //
  752. //////////////////////////////////////////////////////////////////////////////
  753. void SetGeo(Geo* pgeo)
  754. {
  755. m_pwrapGeo->SetGeo(pgeo);
  756. float radius = pgeo->GetRadius(Matrix::GetIdentity());
  757. //m_scaleCone = 0.75f * radius;
  758. m_pcamera->SetPosition(
  759. Vector(
  760. 0,
  761. 0,
  762. 2.4f * radius
  763. )
  764. );
  765. }
  766. //////////////////////////////////////////////////////////////////////////////
  767. //
  768. // m_pship->SetBaseHullType(phullType);
  769. //
  770. //////////////////////////////////////////////////////////////////////////////
  771. //////////////////////////////////////////////////////////////////////////////
  772. //
  773. //
  774. //
  775. //////////////////////////////////////////////////////////////////////////////
  776. //////////////////////////////////////////////////////////////////////////////
  777. //
  778. // Gunner Info
  779. //
  780. //////////////////////////////////////////////////////////////////////////////
  781. void UpdateGunnerInfo()
  782. {
  783. for (int index = 0; index < c_maxMountedWeapons; index++) {
  784. IweaponIGC* pweapon;
  785. CastTo(pweapon, m_pship->GetMountedPart(ET_Weapon, index));
  786. if (pweapon) {
  787. IshipIGC* pshipGunner = pweapon->GetGunner();
  788. if (pshipGunner) {
  789. m_pstringGunners[index]->SetValue(pshipGunner->GetName());
  790. } else {
  791. m_pstringGunners[index]->SetValue("unmanned");
  792. }
  793. }
  794. }
  795. }
  796. //////////////////////////////////////////////////////////////////////////////
  797. //
  798. // Hull Info
  799. //
  800. //////////////////////////////////////////////////////////////////////////////
  801. void SetHullTitle()
  802. {
  803. m_pstringTitle->SetValue(ZString(m_phullType->GetName()).ToUpper());
  804. m_pstringHullDescription->SetValue(m_phullType->GetDescription());
  805. }
  806. void UpdatePerformanceInfo()
  807. {
  808. SetHullTitle();
  809. float acceleration = m_phullType->GetThrust() / m_pship->GetMass();
  810. float turnRate =
  811. (
  812. m_phullType->GetMaxTurnRate(c_axisYaw)
  813. + m_phullType->GetMaxTurnRate(c_axisPitch)
  814. + m_phullType->GetMaxTurnRate(c_axisRoll)
  815. )
  816. * (180.0f / (3.0f * pi));
  817. float accelerationBase = m_phullTypeBase->GetThrust() / m_fSpecMass;
  818. float turnRateBase =
  819. (
  820. m_phullTypeBase->GetMaxTurnRate(c_axisYaw)
  821. + m_phullTypeBase->GetMaxTurnRate(c_axisPitch)
  822. + m_phullTypeBase->GetMaxTurnRate(c_axisRoll)
  823. )
  824. * (180.0f / (3.0f * pi));
  825. const GlobalAttributeSet& ga = trekClient.GetSide()->GetGlobalAttributeSet();
  826. float maxSpeed = m_phullType->GetMaxSpeed();
  827. float hitPoints = m_phullType->GetHitPoints();
  828. float maxEnergy = m_phullType->GetMaxEnergy();
  829. float scannerRange = m_phullType->GetScannerRange();
  830. float signature = m_pship->GetSignature() / ga.GetAttribute(c_gaSignature);
  831. float specSignature = m_fSpecSignature / ga.GetAttribute(c_gaSignature);
  832. m_pnumberHullMaxSpeed ->SetValue(maxSpeed / m_maxMaxSpeed );
  833. m_pnumberHullAcceleration->SetValue(acceleration / m_maxAcceleration );
  834. m_pnumberHullTurnRate ->SetValue(turnRate / m_maxTurnRate );
  835. m_pnumberHullHitPoints ->SetValue(hitPoints / m_maxHitPoints );
  836. m_pnumberHullEnergy ->SetValue(maxEnergy / m_maxEnergy );
  837. m_pnumberHullScanRange ->SetValue(scannerRange / m_maxScanRange );
  838. m_pnumberHullSignature ->SetValue((1/signature) / m_maxHullSignature);
  839. m_pnumberHullMass ->SetValue(m_pship->GetMass() / m_maxHullMass );
  840. m_pnumberHullMaxSpeedNumber ->SetValue(maxSpeed);
  841. m_pnumberHullAccelerationNumber->SetValue(acceleration);
  842. m_pnumberHullTurnRateNumber ->SetValue(turnRate);
  843. m_pnumberHullHitPointsNumber ->SetValue(hitPoints);
  844. m_pnumberHullEnergyNumber ->SetValue(maxEnergy);
  845. m_pnumberHullScanRangeNumber ->SetValue(scannerRange);
  846. m_pnumberHullSignatureNumber ->SetValue(signature * 100);
  847. m_pnumberHullMassNumber ->SetValue(m_pship->GetMass());
  848. m_pnumberBaseHullMaxSpeed ->SetValue(m_phullTypeBase->GetMaxSpeed() / m_maxMaxSpeed);
  849. m_pnumberBaseHullAcceleration->SetValue(accelerationBase / m_maxAcceleration);
  850. m_pnumberBaseHullTurnRate ->SetValue(turnRateBase / m_maxTurnRate);
  851. m_pnumberBaseHullHitPoints ->SetValue(m_phullTypeBase->GetHitPoints() / m_maxHitPoints);
  852. m_pnumberBaseHullEnergy ->SetValue(m_phullTypeBase->GetMaxEnergy() / m_maxEnergy);
  853. m_pnumberBaseHullScanRange ->SetValue(m_phullTypeBase->GetScannerRange() / m_maxScanRange);
  854. m_pnumberBaseHullSignature ->SetValue((1/specSignature) / m_maxHullSignature);
  855. m_pnumberBaseHullMass ->SetValue(m_fSpecMass / m_maxHullMass);
  856. m_pnumberBaseHullMaxSpeedNumber ->SetValue(m_phullTypeBase->GetMaxSpeed());
  857. m_pnumberBaseHullAccelerationNumber->SetValue(accelerationBase);
  858. m_pnumberBaseHullTurnRateNumber ->SetValue(turnRateBase);
  859. m_pnumberBaseHullHitPointsNumber ->SetValue(m_phullTypeBase->GetHitPoints());
  860. m_pnumberBaseHullEnergyNumber ->SetValue(m_phullTypeBase->GetMaxEnergy());
  861. m_pnumberBaseHullScanRangeNumber ->SetValue(m_phullTypeBase->GetScannerRange());
  862. m_pnumberBaseHullSignatureNumber ->SetValue(specSignature * 100);
  863. m_pnumberBaseHullMassNumber ->SetValue(m_fSpecMass);
  864. m_pnumberHullDefenseClass ->SetValue(m_phullType->GetDefenseType());
  865. m_pnumberBaseHullDefenseClass ->SetValue(m_phullTypeBase->GetDefenseType());
  866. }
  867. //////////////////////////////////////////////////////////////////////////////
  868. //
  869. // Part Info
  870. //
  871. //////////////////////////////////////////////////////////////////////////////
  872. void UpdateWeaponPartInfo(IpartTypeIGC* ppartType)
  873. {
  874. const GlobalAttributeSet& ga = trekClient.GetSide()->GetGlobalAttributeSet();
  875. DataWeaponTypeIGC* pdwt = (DataWeaponTypeIGC*)ppartType->GetData();
  876. IprojectileTypeIGC* ppt = trekClient.GetCore()->GetProjectileType(pdwt->projectileTypeID);
  877. float rate = 1.0f / pdwt->dtimeBurst;
  878. float power = (ppt->GetPower() + ppt->GetBlastPower()) * rate * ga.GetAttribute(c_gaDamageGuns);
  879. bool bAmmo = pdwt->cAmmoPerShot != 0;
  880. float speed = ppt->GetSpeed();
  881. if (bAmmo)
  882. speed *= ga.GetAttribute(c_gaSpeedAmmo);
  883. float range = speed * ppt->GetLifespan();
  884. if (!bAmmo)
  885. range *= ga.GetAttribute(c_gaLifespanEnergy);
  886. m_pnumberWeaponDamage->SetValue(power / m_maxWeaponPower);
  887. m_pnumberWeaponRange ->SetValue(range / m_maxWeaponRange);
  888. m_pnumberWeaponSpeed ->SetValue(speed / m_maxWeaponSpeed);
  889. m_pnumberWeaponRate ->SetValue(rate / m_maxWeaponRate);
  890. m_pnumberWeaponDamageNumber->SetValue(power);
  891. m_pnumberWeaponRangeNumber ->SetValue(range); // !!! should get a 'm' suffix
  892. m_pnumberWeaponSpeedNumber ->SetValue(speed); // !!! should get a 'mps' suffix
  893. m_pnumberWeaponRateNumber ->SetValue(rate); // !!! should get a '/s' suffix
  894. m_pnumberWeaponDamageBonus ->SetValue(ppt->GetDamageType());
  895. }
  896. void UpdateMagazinePartInfo(IpartTypeIGC* ppartType)
  897. {
  898. const GlobalAttributeSet& ga = trekClient.GetSide()->GetGlobalAttributeSet();
  899. ImissileTypeIGC* pmt = (ImissileTypeIGC*)((IlauncherTypeIGC*)ppartType)->GetExpendableType();
  900. float power = (pmt->GetPower() + pmt->GetBlastPower()) * ga.GetAttribute(c_gaDamageMissiles);
  901. float lifespan = pmt->GetLifespan();
  902. float range = pmt->GetInitialSpeed() * lifespan + 0.5f * (pmt->GetAcceleration() * lifespan * lifespan);
  903. float lockTime = pmt->GetLockTime();
  904. float lock = pmt->GetMaxLock();
  905. m_pnumberMagazineDamage ->SetValue(power / (m_maxMagazineHitDamage + m_maxMagazineAreaDamage));
  906. m_pnumberMagazineRange ->SetValue(range / m_maxMagazineRange);
  907. m_pnumberMagazineLockTime->SetValue(lockTime / m_maxMagazineLockTime);
  908. m_pnumberMagazineMaxLock ->SetValue(lock);
  909. m_pnumberMagazineDamageNumber ->SetValue(power);
  910. m_pnumberMagazineRangeNumber ->SetValue(range); // !!! Should get a 'm' suffix
  911. m_pnumberMagazineLockTimeNumber->SetValue(lockTime); // !!! Should get a 's' suffix
  912. m_pnumberMagazineMaxLockNumber ->SetValue(lock * 100.0f); // !!! Should get a '%' suffix
  913. m_pnumberMagazineDamageBonus ->SetValue(pmt->GetDamageType());
  914. }
  915. void UpdateDispenserPartInfo(IpartTypeIGC* ppartType)
  916. {
  917. const GlobalAttributeSet& ga = trekClient.GetSide()->GetGlobalAttributeSet();
  918. IexpendableTypeIGC* pet = ((IlauncherTypeIGC*)ppartType)->GetExpendableType();
  919. if (pet->GetObjectType() == OT_probeType)
  920. {
  921. DataProbeTypeIGC* pdprt = (DataProbeTypeIGC*)(pet->GetData());
  922. float scanRange;
  923. {
  924. IprojectileTypeIGC* ppt = ((IprobeTypeIGC*)pet)->GetProjectileType();
  925. if (ppt)
  926. {
  927. //Scan range for something with guns is the gun range
  928. scanRange = ppt->GetLifespan() * ppt->GetSpeed() / 1.2f;
  929. if (((IprobeTypeIGC*)pet)->GetAmmo() != 0)
  930. scanRange *= trekClient.GetSide()->GetGlobalAttributeSet().GetAttribute(c_gaSpeedAmmo);
  931. }
  932. else
  933. scanRange = pdprt->scannerRange * ga.GetAttribute(c_gaScanRange);
  934. }
  935. float signature = pdprt->signature / ga.GetAttribute(c_gaSignature);
  936. m_pnumberProbeScanRange ->SetValue(scanRange / m_maxProbeScanRange);
  937. m_pnumberProbeVisibility ->SetValue(signature);
  938. m_pnumberProbeHitPts ->SetValue(pdprt->hitPoints / m_maxProbeHitPts);
  939. m_pnumberProbeLifespan ->SetValue(pdprt->lifespan / m_maxProbeLifespan);
  940. m_pnumberProbeScanRangeNumber ->SetValue(scanRange); //Should get a 'm' suffix
  941. m_pnumberProbeVisibilityNumber ->SetValue(signature * 100.0f); //Should get a '%' suffix
  942. m_pnumberProbeHitPtsNumber ->SetValue(pdprt->hitPoints);
  943. m_pnumberProbeLifespanNumber ->SetValue(pdprt->lifespan); //Should get a 's' suffix
  944. }
  945. else
  946. {
  947. DataMineTypeIGC* pdmt = (DataMineTypeIGC*)(pet->GetData());
  948. float signature = pdmt->signature / ga.GetAttribute(c_gaSignature);
  949. m_pnumberMineDamage ->SetValue(pdmt->power / m_maxMineDamage);
  950. m_pnumberMineVisibility ->SetValue(signature);
  951. m_pnumberMineRadius ->SetValue(pdmt->radius / m_maxMineRadius);
  952. m_pnumberMineLifespan ->SetValue(pdmt->lifespan / m_maxMineLifespan);
  953. m_pnumberMineDamageNumber ->SetValue(pdmt->power);
  954. m_pnumberMineVisibilityNumber->SetValue(signature * 100.0f); //Should get a '%' suffix
  955. m_pnumberMineRadiusNumber ->SetValue(pdmt->radius); //Should get a 'm' suffix
  956. m_pnumberMineLifespanNumber ->SetValue(pdmt->lifespan); //Should get a 's' suffix
  957. }
  958. }
  959. void UpdateChaffLauncherPartInfo(IpartTypeIGC* ppartType)
  960. {
  961. DataChaffTypeIGC* pdct = (DataChaffTypeIGC*)
  962. ((((IlauncherTypeIGC*)ppartType)->GetExpendableType())->GetData());
  963. float effectiveness = (pdct->chaffStrength <= 1.0f) ?
  964. pdct->chaffStrength / 2.0f : 1.0f - 1.0f/(2.0f * pdct->chaffStrength);
  965. m_pnumberChaffStrength ->SetValue(effectiveness / m_maxChaffStrength);
  966. m_pnumberChaffStrengthNumber->SetValue(effectiveness * 100); //Should get a % suffix
  967. }
  968. void UpdateShieldPartInfo(IpartTypeIGC* ppartType)
  969. {
  970. const GlobalAttributeSet& ga = trekClient.GetSide()->GetGlobalAttributeSet();
  971. DataShieldTypeIGC* pdst = (DataShieldTypeIGC*)ppartType->GetData();
  972. float maxStrength = pdst->maxStrength * ga.GetAttribute(c_gaMaxShieldShip);
  973. float regen = maxStrength / (pdst->rateRegen * ga.GetAttribute(c_gaShieldRegenerationShip));
  974. m_pnumberShieldRegen ->SetValue(regen / m_maxShieldRegen);
  975. m_pnumberShieldHitPts ->SetValue(maxStrength / m_maxShieldHitPts);
  976. m_pnumberShieldRegenNumber ->SetValue(regen); //Should have a 's' suffix
  977. m_pnumberShieldHitPtsNumber ->SetValue(maxStrength);
  978. m_pnumberShieldDefenseClass ->SetValue(pdst->defenseType);
  979. }
  980. void UpdateCloakPartInfo(IpartTypeIGC* ppartType)
  981. {
  982. DataCloakTypeIGC* pdct = (DataCloakTypeIGC*)ppartType->GetData();
  983. m_pnumberCloakCloaking ->SetValue(pdct->maxCloaking);
  984. m_pnumberCloakCloakingNumber ->SetValue(pdct->maxCloaking * 100); //Should get a '%' suffix
  985. const IhullTypeIGC* pht = m_pship->GetHullType();
  986. float recharge = pht->GetRechargeRate();
  987. float maxEnergy = pht->GetMaxEnergy();
  988. float duration = pdct->energyConsumption <= recharge ?
  989. -1.0f : maxEnergy / (pdct->energyConsumption - recharge);
  990. float maxDuration = m_maxCloakEnergy <= recharge ?
  991. -1.0 : maxEnergy / (m_maxCloakEnergy - recharge);
  992. m_pnumberCloakDuration ->SetValue(duration/maxDuration);
  993. m_pnumberCloakDurationNumber ->SetValue(duration); //Should get a 's' suffix
  994. }
  995. void UpdatePackPartInfo(IpartIGC* ppart, IpartTypeIGC* ppartType)
  996. {
  997. }
  998. void UpdateAfterburnerPartInfo(IpartTypeIGC* ppartType)
  999. {
  1000. DataAfterburnerTypeIGC* pdat = (DataAfterburnerTypeIGC*)ppartType->GetData();
  1001. float hullSpeed = m_phullType->GetMaxSpeed();
  1002. float hullThrust = m_phullType->GetThrust();
  1003. float maxSpeed = hullSpeed * (1.0f + (pdat->maxThrust / hullThrust));
  1004. float absoluteMaxSpeed = hullSpeed * (1.0f + (m_maxAfterburnerMaxThrust / hullThrust));
  1005. float endurance = m_phullType->GetMaxFuel() / (pdat->maxThrust * pdat->fuelConsumption);
  1006. m_pnumberAfterburnerMaxSpeed->SetValue(maxSpeed / absoluteMaxSpeed);
  1007. m_pnumberAfterburnerBurnRate ->SetValue(endurance / m_maxAfterburnerBurnRate);
  1008. m_pnumberAfterburnerMaxSpeedNumber->SetValue(maxSpeed); //Should have a 'mps' suffix
  1009. m_pnumberAfterburnerBurnRateNumber ->SetValue(endurance); //Should have a 's' suffix
  1010. }
  1011. void UpdatePartInfo(Slot* pslot, IpartIGC* ppart, IpartTypeIGC* ppartType)
  1012. {
  1013. if (ppartType) {
  1014. m_pnumberPartID ->SetValue(ppartType->GetObjectID() );
  1015. m_pnumberPartMask ->SetValue(ppartType->GetPartMask() );
  1016. if (ppartType->GetEquipmentType() == ET_Dispenser)
  1017. {
  1018. if (((IlauncherTypeIGC*)ppartType)->GetExpendableType()->GetObjectType() == OT_probeType)
  1019. m_pnumberEquipmentType->SetValue(ppartType->GetEquipmentType());
  1020. else
  1021. m_pnumberEquipmentType->SetValue(-4); // equipmentTypeMine
  1022. }
  1023. else
  1024. {
  1025. m_pnumberEquipmentType->SetValue(ppartType->GetEquipmentType());
  1026. }
  1027. m_pstringPartDescription->SetValue(ppartType->GetDescription() );
  1028. float signature = ppartType->GetSignature() / trekClient.GetSide()->GetGlobalAttributeSet().GetAttribute(c_gaSignature);
  1029. m_pnumberSignature ->SetValue(signature / m_maxPartSignature);
  1030. m_pnumberMass ->SetValue(ppartType->GetMass() / m_maxPartMass);
  1031. m_pnumberSignatureNumber ->SetValue(signature * 100);
  1032. m_pnumberMassNumber ->SetValue(ppartType->GetMass());
  1033. //m_pstringPartDescription->SetValue("Part desc");
  1034. m_pstringPartName->SetValue(GetBuyableName(ppartType));
  1035. ZString str = ZString("l") + ZString(ppartType->GetModelName()) + ZString("bmp").ToLower();
  1036. TRef<Image> pimage = GetModeler()->LoadImage(str, false);
  1037. m_pwrapImagePart->SetImage(pimage);
  1038. switch (ppartType->GetEquipmentType()) {
  1039. case ET_Weapon: UpdateWeaponPartInfo(ppartType); break;
  1040. case ET_Magazine: UpdateMagazinePartInfo(ppartType); break;
  1041. case ET_ChaffLauncher: UpdateChaffLauncherPartInfo(ppartType); break;
  1042. case ET_Dispenser: UpdateDispenserPartInfo(ppartType); break;
  1043. case ET_Shield: UpdateShieldPartInfo(ppartType); break;
  1044. case ET_Cloak: UpdateCloakPartInfo(ppartType); break;
  1045. case ET_Pack: UpdatePackPartInfo(ppart, ppartType); break;
  1046. case ET_Afterburner: UpdateAfterburnerPartInfo(ppartType); break;
  1047. }
  1048. } else {
  1049. m_pnumberEquipmentType->SetValue(-3); // equipmentTypeNone
  1050. ZString str = ZString("ldefaultbmp");
  1051. TRef<Image> pimage = GetModeler()->LoadImage(str, false);
  1052. m_pwrapImagePart->SetImage(pimage);
  1053. if (pslot) {
  1054. EquipmentType equipmentType = pslot->GetEquipmentType();
  1055. if (equipmentType == -1) {
  1056. m_pnumberPartID->SetValue(-1.0f);
  1057. } else {
  1058. m_pnumberPartID->SetValue((float)(-(10 + pslot->GetEquipmentType())));
  1059. }
  1060. } else {
  1061. m_pnumberPartID->SetValue(0);
  1062. }
  1063. }
  1064. }
  1065. //////////////////////////////////////////////////////////////////////////////
  1066. //
  1067. // Cone of fire
  1068. //
  1069. //////////////////////////////////////////////////////////////////////////////
  1070. /*
  1071. void UpdateCone(Slot* pslot)
  1072. {
  1073. //m_pmaterialCone;
  1074. if (
  1075. pslot != NULL
  1076. && pslot->GetEquipmentType() == ET_Weapon
  1077. ) {
  1078. Mount mount = pslot->GetMount();
  1079. const HardpointData& hd = m_phullType->GetHardpointData(mount);
  1080. if ((hd.bFixed != true) && (hd.minDot >= -0.75f)) {
  1081. m_pvisibleGeoCone->SetVisible(true);
  1082. m_pnumberAngleCone->SetValue(acos(hd.minDot));
  1083. const Vector& position = m_phullType->GetWeaponPosition(mount) * (1 / m_phullType->GetScale());
  1084. const Orientation& orient = m_phullType->GetWeaponOrientation(mount);
  1085. m_ptransformCone->SetValue(
  1086. Matrix(
  1087. Orientation(orient.GetBackward()),
  1088. position,
  1089. m_scaleCone
  1090. )
  1091. );
  1092. return;
  1093. }
  1094. }
  1095. m_pvisibleGeoCone->SetVisible(false);
  1096. }
  1097. */
  1098. //////////////////////////////////////////////////////////////////////////////
  1099. //
  1100. // Slot callbacks
  1101. //
  1102. //////////////////////////////////////////////////////////////////////////////
  1103. void SlotEntered(Slot* pslot)
  1104. {
  1105. IpartIGC* ppart = pslot->GetPart();
  1106. UpdatePartInfo(
  1107. pslot, ppart,
  1108. ppart ? ppart->GetPartType() : NULL
  1109. );
  1110. //UpdateCone(pslot);
  1111. }
  1112. void SlotLeft(Slot* pslot)
  1113. {
  1114. //CloseMenu();
  1115. UpdatePartInfo(NULL, NULL, NULL);
  1116. //UpdateCone(NULL);
  1117. }
  1118. void SlotClicked(Slot* pslot, bool bNext, const WinPoint& point)
  1119. {
  1120. assert (trekClient.GetShip()->GetStation() != NULL);
  1121. BuyPartMenu(pslot, point);
  1122. }
  1123. //////////////////////////////////////////////////////////////////////////////
  1124. //
  1125. // Slot finder
  1126. //
  1127. //////////////////////////////////////////////////////////////////////////////
  1128. Slot* FindSlot(EquipmentType equipmentType, Mount mount)
  1129. {
  1130. SlotList::Iterator iter(m_listSlots);
  1131. while (!iter.End()) {
  1132. Slot* pslot = iter.Value();
  1133. if ((pslot->GetMount() == mount) &&
  1134. ((mount < 0) || (pslot->GetEquipmentType() == equipmentType)))
  1135. {
  1136. return pslot;
  1137. }
  1138. iter.Next();
  1139. }
  1140. return NULL;
  1141. }
  1142. //////////////////////////////////////////////////////////////////////////////
  1143. //
  1144. // Buy and sell parts
  1145. //
  1146. //////////////////////////////////////////////////////////////////////////////
  1147. void OnMoneyChange(PlayerInfo* pPlayerInfo)
  1148. {
  1149. if (pPlayerInfo == trekClient.MyPlayerInfo()) {
  1150. m_pnumberMoney->SetValue((float)trekClient.GetMoney());
  1151. }
  1152. }
  1153. void SellPart(Slot* pslot)
  1154. {
  1155. IpartIGC* ppart = pslot->GetPart();
  1156. if (ppart != NULL)
  1157. {
  1158. ppart->Terminate();
  1159. pslot->SetPart(NULL);
  1160. }
  1161. UpdateHullType();
  1162. }
  1163. void BuyPart(Slot* pslot, IpartTypeIGC* ppartType)
  1164. {
  1165. SellPart(pslot);
  1166. short amount;
  1167. if (IlauncherTypeIGC::IsLauncherType(ppartType->GetEquipmentType()))
  1168. amount = ((IlauncherTypeIGC*)ppartType)->GetAmount(m_pship);
  1169. else
  1170. amount = 0x7fff;
  1171. IpartIGC* ppart = m_pship->CreateAndAddPart(ppartType, pslot->GetMount(), amount);
  1172. assert (ppart);
  1173. pslot->SetPart(ppart);
  1174. UpdateHullType();
  1175. }
  1176. void BuyHull(IhullTypeIGC* phullType)
  1177. {
  1178. trekClient.SaveLoadout(m_pship);
  1179. // remove all of the current parts
  1180. {
  1181. SlotList::Iterator iter(m_listSlots);
  1182. while (!iter.End())
  1183. {
  1184. Slot* pslot = iter.Value();
  1185. if (pslot->GetPart())
  1186. {
  1187. pslot->GetPart()->Terminate();
  1188. pslot->SetPart(NULL);
  1189. }
  1190. iter.Next();
  1191. }
  1192. assert (m_pship->GetParts()->n() == 0);
  1193. }
  1194. // give it the default loadout for this hull
  1195. trekClient.ReplaceLoadout(m_pship, trekClient.GetShip()->GetStation(), phullType, moneyLots);
  1196. // recalculate the mass and signature of the default loadout
  1197. m_fSpecMass = m_pship->GetMass();
  1198. m_fSpecSignature = m_pship->GetSignature();
  1199. trekClient.PlaySoundEffect(mountSound);
  1200. UpdateHullType();
  1201. }
  1202. //////////////////////////////////////////////////////////////////////////////
  1203. //
  1204. // buttons
  1205. //
  1206. //////////////////////////////////////////////////////////////////////////////
  1207. bool OnButtonLaunch()
  1208. {
  1209. if ((trekClient.GetShip()->GetValue() + trekClient.GetMoney()) >= m_pship->GetValue())
  1210. {
  1211. if (trekClient.GetShip()->GetParentShip() != NULL)
  1212. trekClient.DisembarkAndBuy(m_pship, true);
  1213. else
  1214. trekClient.BuyLoadout(m_pship, true);
  1215. }
  1216. return true;
  1217. }
  1218. bool OnButtonBuy()
  1219. {
  1220. Money cost = m_pship->GetValue() - (trekClient.GetShip()->GetValue() + trekClient.GetMoney());
  1221. if (cost > 0)
  1222. {
  1223. trekClient.SetMessageType(BaseClient::c_mtGuaranteed);
  1224. BEGIN_PFM_CREATE(trekClient.m_fm, pfmRequest, CS, REQUEST_MONEY)
  1225. END_PFM_CREATE
  1226. pfmRequest->amount = cost;
  1227. pfmRequest->hidFor = m_pship->GetBaseHullType()->GetObjectID();
  1228. }
  1229. else if (trekClient.GetShip()->GetParentShip() != NULL)
  1230. trekClient.DisembarkAndBuy(m_pship, false);
  1231. else
  1232. trekClient.BuyLoadout(m_pship, false);
  1233. return true;
  1234. }
  1235. bool OnButtonBack()
  1236. {
  1237. //GetWindow()->ToggleOverlayFlags(ofLoadout);
  1238. GetWindow()->SetViewMode(TrekWindow::vmHangar);
  1239. return true;
  1240. }
  1241. bool OnButtonHullList()
  1242. {
  1243. assert(trekClient.GetShip()->GetStation() != NULL);
  1244. HullMenu();
  1245. return true;
  1246. }
  1247. //////////////////////////////////////////////////////////////////////////////
  1248. //
  1249. // Button Events
  1250. //
  1251. //////////////////////////////////////////////////////////////////////////////
  1252. void OnTechTreeChanged(SideID sideID)
  1253. {
  1254. if (trekClient.GetSideID() == sideID)
  1255. UpdateNextAndPrevButtons();
  1256. }
  1257. void UpdateNextAndPrevButtons()
  1258. {
  1259. bool bEnableNextAndPrev = (GetNextHullType(true) != m_pship->GetBaseHullType());
  1260. m_pbuttonNext->SetEnabled(bEnableNextAndPrev);
  1261. m_pbuttonPrevious->SetEnabled(bEnableNextAndPrev);
  1262. }
  1263. IhullTypeIGC* GetNextHullType(bool bForward)
  1264. {
  1265. IhullTypeIGC* phtCurrent = m_pship->GetBaseHullType();
  1266. IstationIGC* pstation = trekClient.GetShip()->GetStation();
  1267. if (pstation != NULL)
  1268. {
  1269. const HullTypeListIGC* phullList = trekClient.m_pCoreIGC->GetHullTypes();
  1270. //
  1271. // Seach for the next buyable hulltype
  1272. //
  1273. HullTypeLinkIGC* phtlStart = phullList->find(phtCurrent);
  1274. assert (phtlStart);
  1275. HullTypeLinkIGC* phtlNow = phtlStart;
  1276. while (true)
  1277. {
  1278. assert (phtlNow);
  1279. if (bForward)
  1280. {
  1281. phtlNow = phtlNow->next();
  1282. if (phtlNow == NULL)
  1283. phtlNow = phullList->first();
  1284. }
  1285. else
  1286. {
  1287. phtlNow = phtlNow->txen();
  1288. if (phtlNow == NULL)
  1289. phtlNow = phullList->last();
  1290. }
  1291. IhullTypeIGC* pht = phtlNow->data();
  1292. // if we can buy this hull or if we've come full circle
  1293. if ((pht == phtCurrent)
  1294. || (pht->GetGroupID() >= 0)
  1295. && pstation->CanBuy(pht)
  1296. && (!pstation->IsObsolete(pht)))
  1297. {
  1298. return pht;
  1299. }
  1300. }
  1301. }
  1302. else
  1303. {
  1304. return phtCurrent;
  1305. }
  1306. }
  1307. void NextHull(bool bForward)
  1308. {
  1309. IhullTypeIGC* pht = GetNextHullType(bForward);
  1310. IhullTypeIGC* phtCurrent = m_pship->GetBaseHullType();
  1311. if (pht != phtCurrent)
  1312. BuyHull(pht);
  1313. }
  1314. bool OnButtonNext()
  1315. {
  1316. NextHull(true);
  1317. return true;
  1318. }
  1319. bool OnButtonPrevious()
  1320. {
  1321. NextHull(false);
  1322. return true;
  1323. }
  1324. bool OnButtonDefault()
  1325. {
  1326. Money budget = moneyLots;
  1327. trekClient.BuyDefaultLoadout (m_pship, trekClient.GetShip()->GetStation(), m_phullTypeBase, &budget);
  1328. UpdateHullType();
  1329. return true;
  1330. }
  1331. //////////////////////////////////////////////////////////////////////////////
  1332. //
  1333. //
  1334. //
  1335. //////////////////////////////////////////////////////////////////////////////
  1336. bool CanMount(IpartTypeIGC* pparttype)
  1337. {
  1338. if (pparttype->GetEquipmentType() == ET_Pack)
  1339. {
  1340. return true;
  1341. }
  1342. else if (pparttype->GetEquipmentType() == ET_Weapon)
  1343. {
  1344. Mount mountMax = m_phullType->GetMaxWeapons();
  1345. for (Mount mount = 0; mount < mountMax; mount++)
  1346. {
  1347. if (m_phullType->CanMount(pparttype, mount))
  1348. return true;
  1349. }
  1350. return false;
  1351. }
  1352. else
  1353. {
  1354. return m_phullType->CanMount(pparttype, 0);
  1355. }
  1356. }
  1357. void BuyPartMenu(Slot* pslot, const WinPoint& pointLocal)
  1358. {
  1359. m_pslotMenu = pslot;
  1360. if (m_phullMenu) {
  1361. GetWindow()->GetPopupContainer()->ClosePopup(m_phullMenu);
  1362. m_phullMenu = NULL;
  1363. }
  1364. m_pmenu =
  1365. CreateMenu(
  1366. GetModeler(),
  1367. TrekResources::SmallFont(),
  1368. IMenuCommandSink::CreateDelegate(this)
  1369. );
  1370. bool bAnyItems = false;
  1371. if (pslot->GetEquipmentType() == NA)
  1372. {
  1373. m_pmenu->AddMenuItem(c_midOtherParts, "Parts For Other Ships", 0, m_psubmenuEventSink);
  1374. bAnyItems = true;
  1375. }
  1376. m_pmenu->AddMenuItem(-1, "-Make Slot Empty-");
  1377. IstationIGC* pstation = trekClient.GetShip()->GetStation();
  1378. assert(pstation);
  1379. const PartTypeListIGC* plist = trekClient.m_pCoreIGC->GetPartTypes();
  1380. for (PartTypeLinkIGC* ppartTypeNode = plist->first();
  1381. ppartTypeNode != NULL;
  1382. ppartTypeNode = ppartTypeNode->next())
  1383. {
  1384. IpartTypeIGC* ppartType = ppartTypeNode->data();
  1385. if ((ppartType->GetGroupID() >= 0) &&
  1386. pstation->CanBuy(ppartType) &&
  1387. !pstation->IsObsolete(ppartType))
  1388. {
  1389. EquipmentType equipmentType = ppartType->GetEquipmentType();
  1390. if (pslot->GetEquipmentType() == NA)
  1391. {
  1392. if (CanMount(ppartType))
  1393. {
  1394. bAnyItems = true;
  1395. m_pmenu->AddMenuItem(
  1396. ppartType->GetObjectID(),
  1397. GetBuyableName(ppartType)
  1398. );
  1399. }
  1400. }
  1401. else
  1402. {
  1403. if ((equipmentType == pslot->GetEquipmentType()) &&
  1404. m_phullType->CanMount(ppartType, pslot->GetMount()))
  1405. {
  1406. bAnyItems = true;
  1407. m_pmenu->AddMenuItem(
  1408. ppartType->GetObjectID(),
  1409. GetBuyableName(ppartType)
  1410. );
  1411. }
  1412. }
  1413. }
  1414. }
  1415. if (bAnyItems) {
  1416. Point point = pslot->TransformLocalToImage(pointLocal);
  1417. GetWindow()->GetPopupContainer()->OpenPopup(m_pmenu, Rect(point, point), true, false);
  1418. }
  1419. }
  1420. TRef<IPopup> GetSubMenu(IMenuItem* pitem)
  1421. {
  1422. assert(pitem->GetID() == c_midOtherParts);
  1423. TRef<IMenu> pmenu =
  1424. CreateMenu(
  1425. GetModeler(),
  1426. TrekResources::SmallFont(),
  1427. IMenuCommandSink::CreateDelegate(this)
  1428. );
  1429. // create a menu with every part we can't mount
  1430. IstationIGC* pstation = trekClient.GetShip()->GetStation();
  1431. const PartTypeListIGC* plist = trekClient.m_pCoreIGC->GetPartTypes();
  1432. for (PartTypeLinkIGC* ppartTypeNode = plist->first();
  1433. ppartTypeNode != NULL;
  1434. ppartTypeNode = ppartTypeNode->next())
  1435. {
  1436. IpartTypeIGC* ppartType = ppartTypeNode->data();
  1437. if ((ppartType->GetGroupID() >= 0) &&
  1438. pstation->CanBuy(ppartType) &&
  1439. !pstation->IsObsolete(ppartType))
  1440. {
  1441. if (!CanMount(ppartType))
  1442. {
  1443. pmenu->AddMenuItem(
  1444. ppartType->GetObjectID(),
  1445. GetBuyableName(ppartType)
  1446. );
  1447. }
  1448. }
  1449. }
  1450. return pmenu;
  1451. }
  1452. void HullMenu(void)
  1453. {
  1454. IhullTypeIGC* phullTypeCurrent = m_pship->GetBaseHullType();
  1455. IstationIGC* pstation = trekClient.GetShip()->GetStation();
  1456. if (m_pmenu) {
  1457. GetWindow()->GetPopupContainer()->ClosePopup(m_pmenu);
  1458. m_pmenu = NULL;
  1459. m_pslotMenu = NULL;
  1460. }
  1461. m_phullMenu =
  1462. CreateMenu(
  1463. GetModeler(),
  1464. TrekResources::SmallFont(),
  1465. IMenuCommandSink::CreateDelegate(this)
  1466. );
  1467. const HullTypeListIGC* phullList = trekClient.m_pCoreIGC->GetHullTypes();
  1468. for (
  1469. HullTypeLinkIGC* phullTypeNode = phullList->first();
  1470. phullTypeNode != NULL;
  1471. phullTypeNode = phullTypeNode->next()
  1472. ) {
  1473. IhullTypeIGC* phullType = phullTypeNode->data();
  1474. if ((phullType == phullTypeCurrent) ||
  1475. ((phullType->GetGroupID() >= 0) &&
  1476. (pstation->CanBuy(phullType)) &&
  1477. (!pstation->IsObsolete(phullType))))
  1478. {
  1479. m_phullMenu->AddMenuItem(
  1480. phullType->GetObjectID(),
  1481. GetBuyableName(phullType)
  1482. );
  1483. }
  1484. #if 0
  1485. {
  1486. const GlobalAttributeSet& ga = trekClient.GetSide()->GetGlobalAttributeSet();
  1487. if (pstation->CanBuy(phullType))
  1488. {
  1489. debugf("%s\n", phullType->GetName());
  1490. debugf("\tTop speed\t\t%8.2f mps\n", phullType->GetMaxSpeed() * ga.GetAttribute(c_gaMaxSpeed));
  1491. debugf("\tAcceleration\t%8.2f mpss\n", phullType->GetThrust() * ga.GetAttribute(c_gaThrust) /
  1492. phullType->GetMass());
  1493. debugf("\tTurn rate\t\t%8.2f degrees/second\n", 180.0f * phullType->GetMaxTurnRate(c_axisYaw) * ga.GetAttribute(c_gaTurnRate) / pi);
  1494. debugf("\tHit points\t\t%8.2f\n", phullType->GetHitPoints() * ga.GetAttribute(c_gaMaxArmorShip));
  1495. debugf("\tScan range\t\t%8.2f m\n", phullType->GetScannerRange() * ga.GetAttribute(c_gaScanRange));
  1496. }
  1497. }
  1498. #endif
  1499. }
  1500. GetWindow()->GetPopupContainer()->OpenPopup(m_phullMenu, Rect(260, 450, 340, 530), true, false);
  1501. }
  1502. void CloseMenu()
  1503. {
  1504. if (m_pmenu) {
  1505. GetWindow()->GetPopupContainer()->ClosePopup(m_pmenu);
  1506. m_pmenu = NULL;
  1507. m_pslotMenu = NULL;
  1508. }
  1509. if (m_phullMenu) {
  1510. GetWindow()->GetPopupContainer()->ClosePopup(m_phullMenu);
  1511. m_phullMenu = NULL;
  1512. }
  1513. }
  1514. void OnMenuCommand(IMenuItem* pitem)
  1515. {
  1516. // , I don't know why this is getting called twice for the same
  1517. // menu
  1518. if (m_pslotMenu != NULL) {
  1519. SellPart(m_pslotMenu);
  1520. IpartTypeIGC* ppartType =
  1521. trekClient.m_pCoreIGC->GetPartType(
  1522. pitem->GetID()
  1523. );
  1524. if (pitem->GetID() != -1) {
  1525. IpartTypeIGC* ppartType =
  1526. trekClient.m_pCoreIGC->GetPartType(
  1527. pitem->GetID()
  1528. );
  1529. //
  1530. // !!! make sure the part is available
  1531. //
  1532. if (ppartType) {
  1533. BuyPart(m_pslotMenu, ppartType);
  1534. }
  1535. trekClient.PlaySoundEffect(mountSound);
  1536. } else {
  1537. trekClient.PlaySoundEffect(unmountSound);
  1538. }
  1539. UpdatePartInfo(NULL, NULL, ppartType);
  1540. CloseMenu();
  1541. } else if (m_phullMenu !=NULL) {
  1542. IhullTypeIGC* phullType = trekClient.m_pCoreIGC->GetHullType(pitem->GetID());
  1543. if (phullType != m_pship->GetBaseHullType()) {
  1544. BuyHull(phullType);
  1545. }
  1546. CloseMenu();
  1547. } else {
  1548. ZAssert(m_pmenu == NULL);
  1549. }
  1550. }
  1551. void OnMenuSelect(IMenuItem* pitem)
  1552. {
  1553. if (m_pslotMenu != NULL) {
  1554. if (pitem->GetID() == -1) {
  1555. UpdatePartInfo(NULL, NULL, NULL);
  1556. } else {
  1557. IpartTypeIGC* ppartType =
  1558. trekClient.m_pCoreIGC->GetPartType(
  1559. pitem->GetID()
  1560. );
  1561. UpdatePartInfo(NULL, NULL, ppartType);
  1562. }
  1563. }
  1564. }
  1565. void OnMenuClose(IMenu* pmenu)
  1566. {
  1567. UpdatePartInfo(NULL, NULL, NULL);
  1568. }
  1569. //////////////////////////////////////////////////////////////////////////////
  1570. //
  1571. // Update Hull Type
  1572. //
  1573. // This is called whenever something external has changed the hull,
  1574. // the game starts, or when a player docks.
  1575. //
  1576. //////////////////////////////////////////////////////////////////////////////
  1577. void HullSwitched()
  1578. {
  1579. //
  1580. // Fix the hull info
  1581. //
  1582. UpdatePerformanceInfo();
  1583. //
  1584. // Remove the old slots
  1585. //
  1586. SlotList::Iterator iter(m_listSlots);
  1587. while (!iter.End()) {
  1588. Slot* pslot = iter.Value();
  1589. pslot->RemoveSelf();
  1590. iter.Remove();
  1591. }
  1592. //
  1593. // Load the Geo
  1594. //
  1595. {
  1596. TRef<INameSpace> pns = m_pmodeler->GetNameSpace(m_phullType->GetModelName());
  1597. if (pns) {
  1598. TRef<ThingGeo> pthing = ThingGeo::Create(m_pmodeler, m_ptime);
  1599. pthing->LoadMDL(0, pns, NULL);
  1600. pthing->SetShadeAlways(true);
  1601. SetGeo(pthing->GetGeo());
  1602. }
  1603. }
  1604. //
  1605. // Update the geo image overlay
  1606. //
  1607. {
  1608. ZString str =
  1609. ZString("loadout")
  1610. + ZString(m_phullType->GetObjectID())
  1611. + ZString("overlay");
  1612. TRef<Image> pimage = m_pnsLoadout->FindImage(str);
  1613. if (pimage != NULL) {
  1614. m_pwrapImageGeo->SetImage(pimage);
  1615. } else {
  1616. m_pwrapImageGeo->SetImage(Image::GetEmpty());
  1617. }
  1618. }
  1619. //
  1620. // Load the slots
  1621. //
  1622. {
  1623. //
  1624. // Find the loadout definition
  1625. //
  1626. ZString str = ZString("loadout") + ZString(m_phullType->GetObjectID());
  1627. TRef<IObjectList> plist = m_pnsLoadout->FindList(str);
  1628. if (plist == NULL) {
  1629. plist = m_pnsLoadout->FindList("loadoutDefault");
  1630. }
  1631. //
  1632. // Parse the slot info
  1633. //
  1634. plist->GetFirst();
  1635. while (plist->GetCurrent() != NULL) {
  1636. TRef<IObjectPair> ppair; CastTo(ppair, plist->GetCurrent());
  1637. EquipmentType equipmentType = (EquipmentType)(int)GetNumber(ppair->GetNth(0));
  1638. Mount mount = (Mount)GetNumber(ppair->GetNth(1));
  1639. TRef<StringValue> pstrPrefix = StringValue::Cast((Value*)ppair->GetNth(2));
  1640. TRef<Image> pimageDefault = Image::Cast((Value*)ppair->GetNth(3));
  1641. TRef<PointValue> ppointOffset = PointValue::Cast(ppair->GetLastNth(4));
  1642. TRef<RowPane> pRowPane = new RowPane();
  1643. //
  1644. // Does the ship support the slot?
  1645. //
  1646. bool bMount = Slot::SlotValidForHull(m_phullType, equipmentType, mount);
  1647. //
  1648. // Add the slot if the ship supports it
  1649. //
  1650. if (bMount) {
  1651. TRef<Slot> pslot =
  1652. new Slot(
  1653. this,
  1654. equipmentType,
  1655. equipmentType == NA ? (mount - c_maxCargo) : mount,
  1656. pimageDefault,
  1657. pstrPrefix->GetValue()
  1658. );
  1659. pslot->SetOffset(WinPoint::Cast(ppointOffset->GetValue()));
  1660. m_ppane->InsertAtTop(pslot);
  1661. m_listSlots.PushEnd(pslot);
  1662. }
  1663. plist->GetNext();
  1664. }
  1665. }
  1666. PartsSwitched();
  1667. }
  1668. void PartsSwitched()
  1669. {
  1670. //
  1671. // Update all of the slots to the stuff that is actually on the ship
  1672. //
  1673. const PartListIGC* plist = m_pship->GetParts();
  1674. for(
  1675. const PartLinkIGC* ppartLink = plist->first();
  1676. ppartLink != NULL;
  1677. ppartLink = ppartLink->next()
  1678. ) {
  1679. IpartIGC* ppart = ppartLink->data();
  1680. IpartTypeIGC* ppartType = ppart->GetPartType();
  1681. EquipmentType equipmentType = ppart->GetEquipmentType();
  1682. Mount mount = ppart->GetMountID();
  1683. //
  1684. // Find the slot
  1685. //
  1686. Slot* pslot = FindSlot(equipmentType, mount);
  1687. if (pslot) {
  1688. pslot->SetPart(ppart);
  1689. }
  1690. }
  1691. }
  1692. void UpdateHullType(void)
  1693. {
  1694. UpdateButtons();
  1695. {
  1696. //
  1697. // Close the menu
  1698. //
  1699. //CloseMenu();
  1700. //
  1701. // Grab the new hull type
  1702. //
  1703. bool bNewHull = (m_phullTypeBase != m_pship->GetBaseHullType());
  1704. m_phullType = m_pship->GetHullType();
  1705. m_phullTypeBase = m_pship->GetBaseHullType();
  1706. if (m_phullTypeBase == NULL)
  1707. {
  1708. //
  1709. // Don't have a hull the game must be exiting
  1710. //
  1711. return;
  1712. }
  1713. //
  1714. // Update the slots
  1715. //
  1716. if (bNewHull)
  1717. HullSwitched();
  1718. else
  1719. {
  1720. //
  1721. // Empty all of the slots
  1722. //
  1723. SlotList::Iterator iter(m_listSlots);
  1724. while (!iter.End()) {
  1725. Slot* pslot = iter.Value();
  1726. pslot->SetPart(NULL);
  1727. iter.Next();
  1728. }
  1729. PartsSwitched();
  1730. //
  1731. // Update the performance info
  1732. //
  1733. UpdatePerformanceInfo();
  1734. }
  1735. }
  1736. }
  1737. void UpdateButtons()
  1738. {
  1739. Money cost = m_pship->GetValue();
  1740. Money shortfall;
  1741. if (cost <= trekClient.GetMoney())
  1742. shortfall = 0;
  1743. else
  1744. shortfall = cost - (trekClient.GetShip()->GetValue() + trekClient.GetMoney());
  1745. bool bAlreadyOwn = m_pship->EquivalentShip(trekClient.GetShip());
  1746. bool bCanAfford = shortfall <= 0;
  1747. bool bCanBuy = bCanAfford;
  1748. if (!bCanBuy)
  1749. {
  1750. //Can anyone on the team afford it?
  1751. for (ShipLinkIGC* psl = trekClient.GetSide()->GetShips()->first(); (psl != NULL); psl = psl->next())
  1752. {
  1753. if (psl->data() != trekClient.GetShip())
  1754. {
  1755. PlayerInfo* ppi = (PlayerInfo*)(psl->data()->GetPrivateData());
  1756. if (ppi->GetMoney() >= shortfall)
  1757. {
  1758. bCanBuy = true;
  1759. break;
  1760. }
  1761. }
  1762. }
  1763. }
  1764. m_pnumberNewShipCost->SetValue(cost);
  1765. if (bAlreadyOwn)
  1766. m_pnumberLoadoutShipState->SetValue(0);
  1767. else if (cost <= 0)
  1768. m_pnumberLoadoutShipState->SetValue(1);
  1769. else if (bCanAfford)
  1770. m_pnumberLoadoutShipState->SetValue(2);
  1771. else
  1772. m_pnumberLoadoutShipState->SetValue(3);
  1773. m_pbuttonLaunch->SetEnabled(bAlreadyOwn || bCanAfford);
  1774. m_pbuttonBuy->SetEnabled(!bAlreadyOwn && bCanBuy);
  1775. m_pbuttonConfirm->SetEnabled(!bAlreadyOwn);
  1776. if (m_pship->GetValue() != 0){
  1777. m_ppaneHoverBuy->SetOffset(WinPoint::Cast(m_ppointBuyButton->GetValue()));
  1778. m_ppaneHoverConfirm->SetOffset(WinPoint(-100, -100));
  1779. } else {
  1780. m_ppaneHoverBuy->SetOffset(WinPoint(-100, -100));
  1781. m_ppaneHoverConfirm->SetOffset(WinPoint::Cast(m_ppointBuyButton->GetValue()));
  1782. }
  1783. }
  1784. void OnPurchaseCompleted(bool bAllPartsBought)
  1785. {
  1786. if (!bAllPartsBought)
  1787. {
  1788. TRef<IMessageBox> pmsgBox = CreateMessageBox(
  1789. "Some of the parts you requested are no longer available");
  1790. GetWindow()->GetPopupContainer()->OpenPopup(pmsgBox, false);
  1791. // copy their new loadout
  1792. m_pship->Terminate();
  1793. m_pship->Release();
  1794. m_pship = trekClient.CopyCurrentShip();
  1795. }
  1796. m_pnumberOldShipCost->SetValue(trekClient.GetShip()->GetValue());
  1797. UpdateHullType();
  1798. }
  1799. };
  1800. //////////////////////////////////////////////////////////////////////////////
  1801. //
  1802. // Constructor
  1803. //
  1804. //////////////////////////////////////////////////////////////////////////////
  1805. TRef<Loadout> CreateLoadout(Modeler* pmodeler, Number* ptime)
  1806. {
  1807. return new LoadoutImpl(pmodeler, ptime);
  1808. }