CmdrStatusEvent.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /***********************************************************************
  2. *
  3. * SPACE TRADER 1.2.0
  4. *
  5. * CmdrStatusEvent.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. // Commander Status Event Module
  36. // *************************************************************************
  37. #include "external.h"
  38. // *************************************************************************
  39. // Show skill on the Commander Status screen
  40. // *************************************************************************
  41. static void DisplaySkill( int Skill, int AdaptedSkill, FormPtr frmP, long Label )
  42. {
  43. StrIToA( SBuf, Skill );
  44. StrCat( SBuf, " [" );
  45. StrIToA( SBuf2, AdaptedSkill );
  46. StrCat( SBuf, SBuf2 );
  47. StrCat( SBuf, "]" );
  48. setLabelText( frmP, Label, SBuf );
  49. }
  50. // *************************************************************************
  51. // Show the Commander Status screen
  52. // *************************************************************************
  53. static void ShowCommanderStatus( void )
  54. {
  55. FormPtr frmP;
  56. int i;
  57. frmP = FrmGetActiveForm();
  58. RectangularShortcuts( frmP, CommanderStatusBButton );
  59. setLabelText( frmP, CommanderStatusNameLabel, NameCommander );
  60. DisplaySkill( COMMANDER.Pilot, PilotSkill( &Ship ), frmP, CommanderStatusPilotLabel );
  61. DisplaySkill( COMMANDER.Fighter, FighterSkill( &Ship ), frmP, CommanderStatusFighterLabel );
  62. DisplaySkill( COMMANDER.Trader, TraderSkill( &Ship ), frmP, CommanderStatusTraderLabel );
  63. DisplaySkill( COMMANDER.Engineer, EngineerSkill( &Ship ), frmP, CommanderStatusEngineerLabel );
  64. StrIToA( SBuf, PoliceKills + TraderKills + PirateKills );
  65. setLabelText( frmP, CommanderStatusKillsLabel, SBuf );
  66. i = 0;
  67. while (i < MAXPOLICERECORD && PoliceRecordScore >= PoliceRecord[i].MinScore)
  68. ++i;
  69. --i;
  70. if (i < 0)
  71. ++i;
  72. setLabelText( frmP, CommanderStatusPoliceRecordLabel, PoliceRecord[i].Name );
  73. i = 0;
  74. while (i < MAXREPUTATION && ReputationScore >= Reputation[i].MinScore)
  75. ++i;
  76. --i;
  77. if (i < 0)
  78. i = 0;
  79. setLabelText( frmP, CommanderStatusReputationLabel, Reputation[i].Name );
  80. setLabelText( frmP, CommanderStatusLevelLabel, DifficultyLevel[Difficulty] );
  81. StrIToA( SBuf, Days );
  82. StrCat( SBuf, " days" );
  83. setLabelText( frmP, CommanderStatusDaysLabel, SBuf );
  84. StrIToA( SBuf, Credits );
  85. StrCat( SBuf, " cr." );
  86. setLabelText( frmP, CommanderStatusCreditsLabel, SBuf );
  87. StrIToA( SBuf, Debt );
  88. StrCat( SBuf, " cr." );
  89. setLabelText( frmP, CommanderStatusDebtLabel, SBuf );
  90. StrIToA (SBuf, CurrentWorth());
  91. StrCat (SBuf, " cr." );
  92. setLabelText(frmP, CommanderStatusNetWorthLabel, SBuf);
  93. #ifdef _STRA_CHEAT_
  94. if (CheatCounter == 3)
  95. FrmShowObject( frmP, FrmGetObjectIndex( frmP, CommanderStatusCheatButton ));
  96. else
  97. FrmHideObject( frmP, FrmGetObjectIndex( frmP, CommanderStatusCheatButton ));
  98. #endif
  99. FrmDrawForm( frmP );
  100. }
  101. // *************************************************************************
  102. // Handling of events on the Commander Status screen
  103. // *************************************************************************
  104. Boolean CommanderStatusFormHandleEvent(EventPtr eventP)
  105. {
  106. Boolean handled = false;
  107. static FormPtr frm;
  108. static int i;
  109. static Handle AmountH[4];
  110. switch (eventP->eType)
  111. {
  112. // Show information on current system
  113. case frmOpenEvent:
  114. ShowCommanderStatus();
  115. CheatCounter = 0;
  116. handled = true;
  117. break;
  118. case frmUpdateEvent:
  119. ShowCommanderStatus();
  120. handled = true;
  121. break;
  122. case ctlSelectEvent:
  123. #ifdef _STRA_CHEAT_ // cheat enable defined ?
  124. if (eventP->data.ctlSelect.controlID == CommanderStatusCheatButton)
  125. {
  126. frm = FrmInitForm( CheatForm );
  127. StrIToA( SBuf, Credits );
  128. AmountH[0] = SetField( frm, CheatCreditsField, SBuf, 9, true );
  129. StrIToA( SBuf, Debt );
  130. AmountH[1] = SetField( frm, CheatDebtField, SBuf, 9, true );
  131. StrIToA( SBuf, ReputationScore );
  132. AmountH[2] = SetField( frm, CheatReputationField, SBuf, 5, false );
  133. StrIToA( SBuf, ABS( PoliceRecordScore ) );
  134. AmountH[3] = SetField( frm, CheatPoliceRecordField, SBuf, 5, false );
  135. SetCheckBox( frm, CheatNegativeCheckbox, (PoliceRecordScore < 0) );
  136. SetCheckBox( frm, CheatMoonCheckbox, MoonBought );
  137. SetCheckBox( frm, CheatLightningShieldCheckbox, HasShield( &Ship, LIGHTNINGSHIELD ) );
  138. SetCheckBox( frm, CheatFuelCompactorCheckbox, HasGadget( &Ship, FUELCOMPACTOR ) );
  139. SetCheckBox( frm, CheatMorganLaserCheckbox, HasWeapon( &Ship, MORGANLASERWEAPON, true ) );
  140. SetCheckBox( frm, CheatSingularityCheckbox, CanSuperWarp );
  141. FrmDoDialog( frm );
  142. GetField( frm, CheatCreditsField, SBuf, AmountH[0] );
  143. if (SBuf[0] != '\0')
  144. Credits = StrAToI( SBuf );
  145. GetField(frm, CheatDebtField, SBuf, AmountH[1]);
  146. if (SBuf[0] != '\0')
  147. Debt = StrAToI(SBuf);
  148. GetField( frm, CheatReputationField, SBuf, AmountH[2] );
  149. if (SBuf[0] != '\0')
  150. ReputationScore = StrAToI( SBuf );
  151. GetField( frm, CheatPoliceRecordField, SBuf, AmountH[3] );
  152. if (SBuf[0] != '\0')
  153. PoliceRecordScore = StrAToI( SBuf );
  154. if (GetCheckBox( frm, CheatNegativeCheckbox ))
  155. PoliceRecordScore = -PoliceRecordScore;
  156. MoonBought = GetCheckBox( frm, CheatMoonCheckbox );
  157. if (GetCheckBox( frm, CheatLightningShieldCheckbox ) && !HasShield( &Ship, LIGHTNINGSHIELD ) &&
  158. Shiptype[Ship.Type].ShieldSlots > 0)
  159. Ship.Shield[0] = LIGHTNINGSHIELD;
  160. else if (!GetCheckBox( frm, CheatLightningShieldCheckbox ) && HasShield( &Ship, LIGHTNINGSHIELD ))
  161. {
  162. for (i=0; i<MAXSHIELD; ++i)
  163. if (Ship.Shield[i] == LIGHTNINGSHIELD)
  164. Ship.Shield[i] = 1;
  165. }
  166. if (GetCheckBox( frm, CheatFuelCompactorCheckbox ) && !HasGadget( &Ship, FUELCOMPACTOR ) &&
  167. Shiptype[Ship.Type].GadgetSlots > 0)
  168. Ship.Gadget[0] = FUELCOMPACTOR;
  169. else if (!GetCheckBox( frm, CheatFuelCompactorCheckbox ) && HasGadget( &Ship, FUELCOMPACTOR ))
  170. {
  171. for (i=0; i<MAXGADGET; ++i)
  172. if (Ship.Gadget[i] == FUELCOMPACTOR)
  173. Ship.Gadget[i] = 1;
  174. }
  175. if (GetCheckBox( frm, CheatMorganLaserCheckbox ) && !HasWeapon( &Ship, MORGANLASERWEAPON, true) &&
  176. Shiptype[Ship.Type].WeaponSlots > 0)
  177. Ship.Weapon[0] = MORGANLASERWEAPON;
  178. else if (!GetCheckBox( frm, CheatMorganLaserCheckbox ) && HasWeapon( &Ship, MORGANLASERWEAPON, true ))
  179. {
  180. for (i=0; i<MAXWEAPON; ++i)
  181. if (Ship.Weapon[i] == MORGANLASERWEAPON)
  182. Ship.Weapon[i] = 1;
  183. }
  184. CanSuperWarp = GetCheckBox( frm, CheatSingularityCheckbox );
  185. FrmDeleteForm( frm );
  186. ShowCommanderStatus();
  187. }
  188. else
  189. #endif // Cheat Enabled End
  190. if (eventP->data.ctlSelect.controlID == CommanderStatusQuestsButton)
  191. {
  192. CurForm = QuestsForm;
  193. }
  194. else if (eventP->data.ctlSelect.controlID == CommanderStatusSpecialButton)
  195. {
  196. CurForm = SpecialCargoForm;
  197. }
  198. else
  199. {
  200. CurForm = CurrentShipForm;
  201. }
  202. FrmGotoForm( CurForm );
  203. handled = true;
  204. break;
  205. default:
  206. break;
  207. }
  208. return handled;
  209. }