ShipEvent.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /***********************************************************************
  2. *
  3. * SPACE TRADER 1.2.0
  4. *
  5. * ShipEvent.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. #include "external.h"
  35. static void DrawCurrentShipForm()
  36. {
  37. FormPtr frmP = FrmGetActiveForm();
  38. int i, j, k, Line, FirstEmptySlot;
  39. RectangularShortcuts( frmP, CurrentShipBButton );
  40. FrmDrawForm( frmP );
  41. FntSetFont( boldFont );
  42. DrawChars( "Type:", 0, 18 );
  43. DrawChars( "Equipment:", 0, 32 );
  44. FntSetFont( stdFont );
  45. if (ScarabStatus == 3)
  46. {
  47. StrCopy( SBuf, Shiptype[Ship.Type].Name);
  48. StrCat ( SBuf, "/hardened hull");
  49. DrawChars( SBuf, 60, 18 );
  50. }
  51. else
  52. DrawChars( Shiptype[Ship.Type].Name, 60, 18 );
  53. Line = 32;
  54. for (i=0; i<MAXWEAPONTYPE+EXTRAWEAPONS; ++i)
  55. {
  56. j = 0;
  57. for (k=0; k<MAXWEAPON; ++k)
  58. {
  59. if (Ship.Weapon[k] == i)
  60. ++j;
  61. }
  62. if (j > 0)
  63. {
  64. SBuf[0] = '\0';
  65. SBufMultiples( j, Weapontype[i].Name );
  66. StrToLower( SBuf2, SBuf );
  67. DrawChars( SBuf2, 60, Line );
  68. Line += 14;
  69. }
  70. }
  71. for (i=0; i<MAXSHIELDTYPE+EXTRASHIELDS; ++i)
  72. {
  73. j = 0;
  74. for (k=0; k<MAXSHIELD; ++k)
  75. {
  76. if (Ship.Shield[k] == i)
  77. ++j;
  78. }
  79. if (j > 0)
  80. {
  81. SBuf[0] = '\0';
  82. SBufMultiples( j, Shieldtype[i].Name );
  83. StrToLower( SBuf2, SBuf );
  84. DrawChars( SBuf2, 60, Line );
  85. Line += 14;
  86. }
  87. }
  88. for (i=0; i<MAXGADGETTYPE+EXTRAGADGETS; ++i)
  89. {
  90. j = 0;
  91. for (k=0; k<MAXGADGET; ++k)
  92. {
  93. if (Ship.Gadget[k] == i)
  94. ++j;
  95. }
  96. if (j > 0)
  97. {
  98. if (i == EXTRABAYS)
  99. {
  100. j = j*5;
  101. StrIToA( SBuf, j );
  102. StrCat( SBuf, " extra cargo bays" );
  103. }
  104. else
  105. {
  106. StrCopy(SBuf, Gadgettype[i].Name );
  107. }
  108. StrToLower( SBuf2, SBuf );
  109. DrawChars( SBuf2, 60, Line );
  110. Line += 14;
  111. }
  112. }
  113. if (EscapePod)
  114. {
  115. DrawChars( "an escape pod", 60, Line );
  116. Line += 14;
  117. }
  118. if (AnyEmptySlots(&Ship))
  119. {
  120. FntSetFont( boldFont );
  121. DrawChars( "Unfilled: ", 0, Line );
  122. FntSetFont( stdFont );
  123. FirstEmptySlot = GetFirstEmptySlot( Shiptype[Ship.Type].WeaponSlots, Ship.Weapon );
  124. if (FirstEmptySlot >= 0)
  125. {
  126. SBuf[0] = '\0';
  127. SBufMultiples( Shiptype[Ship.Type].WeaponSlots - FirstEmptySlot, "weapon slot" );
  128. DrawChars( SBuf, 60, Line );
  129. Line += 14;
  130. }
  131. FirstEmptySlot = GetFirstEmptySlot( Shiptype[Ship.Type].ShieldSlots, Ship.Shield );
  132. if (FirstEmptySlot >= 0)
  133. {
  134. SBuf[0] = '\0';
  135. SBufMultiples( Shiptype[Ship.Type].ShieldSlots - FirstEmptySlot, "shield slot" );
  136. DrawChars( SBuf, 60, Line );
  137. Line += 14;
  138. }
  139. FirstEmptySlot = GetFirstEmptySlot( Shiptype[Ship.Type].GadgetSlots, Ship.Gadget );
  140. if (FirstEmptySlot >= 0)
  141. {
  142. SBuf[0] = '\0';
  143. SBufMultiples( Shiptype[Ship.Type].GadgetSlots - FirstEmptySlot, "gadget slot" );
  144. DrawChars( SBuf, 60, Line );
  145. Line += 14;
  146. }
  147. }
  148. }
  149. // *************************************************************************
  150. // Event handler for the Current Ship screen
  151. // ********************************************************************
  152. Boolean CurrentShipFormHandleEvent( EventPtr eventP )
  153. {
  154. Boolean handled = false;
  155. switch (eventP->eType)
  156. {
  157. case frmOpenEvent:
  158. case frmUpdateEvent:
  159. DrawCurrentShipForm();
  160. handled = true;
  161. break;
  162. case ctlSelectEvent:
  163. if (eventP->data.ctlSelect.controlID == CurrentShipStatusButton)
  164. {
  165. CurForm = CommanderStatusForm;
  166. }
  167. else if (eventP->data.ctlSelect.controlID == CurrentShipQuestsButton)
  168. {
  169. CurForm = QuestsForm;
  170. }
  171. else if (eventP->data.ctlSelect.controlID == CurrentShipSpecialButton)
  172. {
  173. CurForm = SpecialCargoForm;
  174. }
  175. FrmGotoForm( CurForm );
  176. handled = true;
  177. break;
  178. default:
  179. break;
  180. }
  181. return handled;
  182. }