SpecialEvent.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /***********************************************************************
  2. *
  3. * SPACE TRADER 1.2.2
  4. *
  5. * SpecialEvent.c
  6. *
  7. * Copyright (C) 2000-2002 Pieter Spronck, All Rights Reserved
  8. *
  9. * Additional coding by Sam Anderson (rulez2@home.com)
  10. * Additional coding by Samuel Goldstein (palm@fogbound.net)
  11. *
  12. * Some code of Matt Lee's Dope Wars program has been used.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  27. *
  28. * You can contact the author at space_trader@hotmail.com
  29. *
  30. * For those who are familiar with the classic game Elite: many of the
  31. * ideas in Space Trader are heavily inspired by Elite.
  32. *
  33. **********************************************************************/
  34. // *************************************************************************
  35. // Handling of events on the Special Event screen
  36. // *************************************************************************
  37. #include "external.h"
  38. static void DrawSpecialEventForm()
  39. {
  40. FormPtr frmP;
  41. char theText[320];
  42. frmP = FrmGetActiveForm();
  43. setCurrentWinTitle( SpecialEvent[CURSYSTEM.Special].Title );
  44. if (SpecialEvent[CURSYSTEM.Special].JustAMessage)
  45. {
  46. FrmHideObject( frmP, FrmGetObjectIndex( frmP, SpecialEventYesButton ) );
  47. FrmHideObject( frmP, FrmGetObjectIndex( frmP, SpecialEventNoButton ) );
  48. FrmShowObject( frmP, FrmGetObjectIndex( frmP, SpecialEventOKButton ) );
  49. }
  50. else
  51. {
  52. FrmShowObject( frmP, FrmGetObjectIndex( frmP, SpecialEventYesButton ) );
  53. FrmShowObject( frmP, FrmGetObjectIndex( frmP, SpecialEventNoButton ) );
  54. FrmHideObject( frmP, FrmGetObjectIndex( frmP, SpecialEventOKButton ) );
  55. }
  56. FrmDrawForm ( frmP );
  57. SysCopyStringResource(theText, SpecialEvent[CURSYSTEM.Special].QuestStringID);
  58. DisplayPage(theText, 18);
  59. }
  60. Boolean SpecialEventFormHandleEvent( EventPtr eventP )
  61. {
  62. Boolean handled = false;
  63. int i, FirstEmptySlot;
  64. switch (eventP->eType)
  65. {
  66. case frmOpenEvent:
  67. case frmUpdateEvent:
  68. DrawSpecialEventForm();
  69. handled = true;
  70. break;
  71. // Special event
  72. case ctlSelectEvent:
  73. if (eventP->data.ctlSelect.controlID != SpecialEventNoButton)
  74. {
  75. if (ToSpend() < SpecialEvent[CURSYSTEM.Special].Price)
  76. {
  77. FrmAlert( NotEnoughForEventAlert );
  78. handled = true;
  79. break;
  80. }
  81. Credits -= SpecialEvent[CURSYSTEM.Special].Price;
  82. switch (CURSYSTEM.Special)
  83. {
  84. case GETREACTOR:
  85. if (FilledCargoBays() > TotalCargoBays() - 15)
  86. {
  87. FrmAlert( NotEnoughBaysAlert );
  88. handled = true;
  89. break;
  90. }
  91. else if (WildStatus == 1)
  92. {
  93. if (FrmCustomAlert(WildWontStayOnboardAlert, SolarSystemName[CURSYSTEM.NameIndex],
  94. NULL, NULL) == WildWontStayOnboardSayGoodbyetoWild)
  95. {
  96. WildStatus = 0;
  97. FrmCustomAlert( WildLeavesShipAlert,SolarSystemName[CURSYSTEM.NameIndex],
  98. NULL, NULL);
  99. }
  100. else
  101. {
  102. handled = true;
  103. break;
  104. }
  105. }
  106. FrmAlert( ReactorAlert );
  107. ReactorStatus = 1;
  108. break;
  109. case REACTORDELIVERED:
  110. CURSYSTEM.Special = GETSPECIALLASER;
  111. ReactorStatus = 21;
  112. handled = true;
  113. break;
  114. case MONSTERKILLED:
  115. break;
  116. case SCARAB:
  117. ScarabStatus = 1;
  118. break;
  119. case SCARABDESTROYED:
  120. ScarabStatus = 2;
  121. CURSYSTEM.Special = GETHULLUPGRADED;
  122. handled = true;
  123. break;
  124. case GETHULLUPGRADED:
  125. FrmAlert( HullUpgradeAlert );
  126. Ship.Hull += UPGRADEDHULL;
  127. ScarabStatus = 3;
  128. handled = true;
  129. break;
  130. case EXPERIMENT:
  131. ExperimentStatus = 1;
  132. break;
  133. case EXPERIMENTSTOPPED:
  134. ExperimentStatus = 13;
  135. CanSuperWarp = true;
  136. break;
  137. case EXPERIMENTNOTSTOPPED:
  138. break;
  139. case ARTIFACTDELIVERY:
  140. ArtifactOnBoard = false;
  141. break;
  142. case ALIENARTIFACT:
  143. ArtifactOnBoard = true;
  144. break;
  145. case FLYBARATAS:
  146. case FLYMELINA:
  147. case FLYREGULAS:
  148. ++DragonflyStatus;
  149. break;
  150. case DRAGONFLYDESTROYED:
  151. CURSYSTEM.Special = INSTALLLIGHTNINGSHIELD;
  152. handled = true;
  153. break;
  154. case GEMULONRESCUED:
  155. CURSYSTEM.Special = GETFUELCOMPACTOR;
  156. InvasionStatus = 0;
  157. handled = true;
  158. break;
  159. case MEDICINEDELIVERY:
  160. JaporiDiseaseStatus = 2;
  161. IncreaseRandomSkill();
  162. IncreaseRandomSkill();
  163. break;
  164. case MOONFORSALE:
  165. FrmAlert( BoughtMoonAlert );
  166. MoonBought = true;
  167. break;
  168. case MOONBOUGHT:
  169. EraseRectangle( 0, 0, 160, 160 );
  170. CurForm = UtopiaForm;
  171. FrmGotoForm( UtopiaForm );
  172. return true;
  173. break;
  174. case SKILLINCREASE:
  175. FrmAlert( SkillIncreaseAlert );
  176. IncreaseRandomSkill();
  177. break;
  178. case TRIBBLE:
  179. FrmAlert( YouHaveATribbleAlert );
  180. Ship.Tribbles = 1;
  181. break;
  182. case BUYTRIBBLE:
  183. FrmAlert( BeamOverTribblesAlert );
  184. Credits += (Ship.Tribbles >> 1);
  185. Ship.Tribbles = 0;
  186. break;
  187. case ERASERECORD:
  188. FrmAlert( CleanRecordAlert );
  189. PoliceRecordScore = CLEANSCORE;
  190. RecalculateSellPrices();
  191. break;
  192. case SPACEMONSTER:
  193. MonsterStatus = 1;
  194. for (i=0; i<MAXSOLARSYSTEM; ++i)
  195. if (SolarSystem[i].Special == SPACEMONSTER)
  196. SolarSystem[i].Special = -1;
  197. break;
  198. case DRAGONFLY:
  199. DragonflyStatus = 1;
  200. for (i=0; i<MAXSOLARSYSTEM; ++i)
  201. if (SolarSystem[i].Special == DRAGONFLY)
  202. SolarSystem[i].Special = -1;
  203. break;
  204. case AMBASSADORJAREK:
  205. if (Ship.Crew[Shiptype[Ship.Type].CrewQuarters-1] >= 0)
  206. {
  207. FrmCustomAlert( NoQuartersAvailableAlert, "Ambassador Jarek", NULL, NULL );
  208. handled = true;
  209. break;
  210. }
  211. FrmCustomAlert( PassengerTakenOnBoardAlert, "Ambassador Jarek", NULL, NULL );
  212. JarekStatus = 1;
  213. break;
  214. case TRANSPORTWILD:
  215. if (Ship.Crew[Shiptype[Ship.Type].CrewQuarters-1] >= 0)
  216. {
  217. FrmCustomAlert( NoQuartersAvailableAlert, "Jonathan Wild", NULL, NULL );
  218. handled = true;
  219. break;
  220. }
  221. if (!HasWeapon(&Ship, BEAMLASERWEAPON, false))
  222. {
  223. FrmAlert (WildWontGetAboardAlert);
  224. handled = true;
  225. break;
  226. }
  227. if (ReactorStatus > 0 && ReactorStatus < 21)
  228. {
  229. FrmAlert( WildAfraidOfReactorAlert );
  230. handled = true;
  231. break;
  232. }
  233. FrmCustomAlert( PassengerTakenOnBoardAlert, "Jonathan Wild", NULL, NULL );
  234. WildStatus = 1;
  235. break;
  236. case ALIENINVASION:
  237. InvasionStatus = 1;
  238. break;
  239. case JAREKGETSOUT:
  240. JarekStatus = 2;
  241. RecalculateBuyPrices(COMMANDER.CurSystem);
  242. break;
  243. case WILDGETSOUT:
  244. WildStatus = 2;
  245. Mercenary[MAXCREWMEMBER-1].CurSystem = KRAVATSYSTEM;
  246. // Zeethibal has a 10 in player's lowest score, an 8
  247. // in the next lowest score, and 5 elsewhere.
  248. Mercenary[MAXCREWMEMBER-1].Pilot = 5;
  249. Mercenary[MAXCREWMEMBER-1].Fighter = 5;
  250. Mercenary[MAXCREWMEMBER-1].Trader = 5;
  251. Mercenary[MAXCREWMEMBER-1].Engineer = 5;
  252. switch (NthLowestSkill(&Ship, 1))
  253. {
  254. case PILOTSKILL:
  255. Mercenary[MAXCREWMEMBER-1].Pilot = 10;
  256. break;
  257. case FIGHTERSKILL:
  258. Mercenary[MAXCREWMEMBER-1].Fighter = 10;
  259. break;
  260. case TRADERSKILL:
  261. Mercenary[MAXCREWMEMBER-1].Trader = 10;
  262. break;
  263. case ENGINEERSKILL:
  264. Mercenary[MAXCREWMEMBER-1].Engineer = 10;
  265. break;
  266. }
  267. switch (NthLowestSkill(&Ship, 2))
  268. {
  269. case PILOTSKILL:
  270. Mercenary[MAXCREWMEMBER-1].Pilot = 8;
  271. break;
  272. case FIGHTERSKILL:
  273. Mercenary[MAXCREWMEMBER-1].Fighter = 8;
  274. break;
  275. case TRADERSKILL:
  276. Mercenary[MAXCREWMEMBER-1].Trader = 8;
  277. break;
  278. case ENGINEERSKILL:
  279. Mercenary[MAXCREWMEMBER-1].Engineer = 8;
  280. break;
  281. }
  282. if (PoliceRecordScore < CLEANSCORE)
  283. PoliceRecordScore = CLEANSCORE;
  284. break;
  285. case CARGOFORSALE:
  286. FrmAlert( SealedCannistersAlert );
  287. i = GetRandom( MAXTRADEITEM );
  288. Ship.Cargo[i] += 3;
  289. BuyingPrice[i] += SpecialEvent[CURSYSTEM.Special].Price;
  290. break;
  291. case INSTALLLIGHTNINGSHIELD:
  292. FirstEmptySlot = GetFirstEmptySlot( Shiptype[Ship.Type].ShieldSlots, Ship.Shield );
  293. if (FirstEmptySlot < 0)
  294. {
  295. FrmAlert( NotEnoughSlotsAlert );
  296. handled = true;
  297. }
  298. else
  299. {
  300. FrmAlert( LightningShieldAlert );
  301. Ship.Shield[FirstEmptySlot] = LIGHTNINGSHIELD;
  302. Ship.ShieldStrength[FirstEmptySlot] = Shieldtype[LIGHTNINGSHIELD].Power;
  303. }
  304. break;
  305. case GETSPECIALLASER:
  306. FirstEmptySlot = GetFirstEmptySlot( Shiptype[Ship.Type].WeaponSlots, Ship.Weapon );
  307. if (FirstEmptySlot < 0)
  308. {
  309. FrmAlert( NotEnoughSlotsAlert );
  310. handled = true;
  311. }
  312. else
  313. {
  314. FrmAlert(MorganLaserAlert );
  315. Ship.Weapon[FirstEmptySlot] = MORGANLASERWEAPON;
  316. }
  317. break;
  318. case GETFUELCOMPACTOR:
  319. FirstEmptySlot = GetFirstEmptySlot( Shiptype[Ship.Type].GadgetSlots, Ship.Gadget );
  320. if (FirstEmptySlot < 0)
  321. {
  322. FrmAlert( NotEnoughSlotsAlert );
  323. handled = true;
  324. }
  325. else
  326. {
  327. FrmAlert( FuelCompactorAlert );
  328. Ship.Gadget[FirstEmptySlot] = FUELCOMPACTOR;
  329. Ship.Fuel = GetFuelTanks();
  330. }
  331. break;
  332. case JAPORIDISEASE:
  333. if (FilledCargoBays() > TotalCargoBays() - 10)
  334. {
  335. FrmAlert( NotEnoughBaysAlert );
  336. handled = true;
  337. }
  338. else
  339. {
  340. FrmAlert( AntidoteAlert );
  341. JaporiDiseaseStatus = 1;
  342. }
  343. break;
  344. }
  345. if (!handled)
  346. CURSYSTEM.Special = -1;
  347. }
  348. CurForm = SystemInformationForm;
  349. FrmGotoForm( CurForm );
  350. handled = true;
  351. break;
  352. default:
  353. break;
  354. }
  355. return handled;
  356. }