BuyEquipEvent.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /***********************************************************************
  2. *
  3. * SPACE TRADER 1.2.0
  4. *
  5. * BuyEquipEvent.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. // *************************************************************************
  36. // Draw an item on the screen
  37. // *************************************************************************
  38. static void DrawItem( char* Name, int y, long Price )
  39. {
  40. int j;
  41. FntSetFont( stdFont );
  42. DrawChars( Name, 30, y );
  43. EraseRectangle( 110, y, 56, 9 );
  44. StrIToA( SBuf, Price );
  45. StrCat( SBuf, " cr." );
  46. j = MAXDIGITS - StrLen( SBuf );
  47. if (Price > 0)
  48. DrawChars( SBuf, 124+j*5, y );
  49. else
  50. DrawChars( "not sold", 122, y );
  51. }
  52. static void DrawBuyEquipmentForm()
  53. {
  54. FormPtr frmP = FrmGetActiveForm();
  55. int i;
  56. RectangularShortcuts( frmP, BuyEquipmentBButton );
  57. for (i=0; i<MAXWEAPONTYPE+MAXSHIELDTYPE+MAXGADGETTYPE; ++i)
  58. {
  59. RectangularButton( frmP, BuyEquipmentBuy0Button + i );
  60. if (i < MAXWEAPONTYPE)
  61. {
  62. if (BASEWEAPONPRICE( i ) <= 0)
  63. FrmHideObject( frmP, FrmGetObjectIndex( frmP, BuyEquipmentBuy0Button + i ) );
  64. else
  65. FrmShowObject( frmP, FrmGetObjectIndex( frmP, BuyEquipmentBuy0Button + i ) );
  66. }
  67. else if (i < MAXWEAPONTYPE + MAXSHIELDTYPE)
  68. {
  69. if (BASESHIELDPRICE( i-MAXWEAPONTYPE ) <= 0)
  70. FrmHideObject( frmP, FrmGetObjectIndex( frmP, BuyEquipmentBuy0Button + i ) );
  71. else
  72. FrmShowObject( frmP, FrmGetObjectIndex( frmP, BuyEquipmentBuy0Button + i ) );
  73. }
  74. else
  75. {
  76. if (BASEGADGETPRICE( i-MAXWEAPONTYPE-MAXSHIELDTYPE ) <= 0)
  77. FrmHideObject( frmP, FrmGetObjectIndex( frmP, BuyEquipmentBuy0Button + i ) );
  78. else
  79. FrmShowObject( frmP, FrmGetObjectIndex( frmP, BuyEquipmentBuy0Button + i ) );
  80. }
  81. }
  82. FrmDrawForm( frmP );
  83. for (i=0; i<MAXWEAPONTYPE; ++i)
  84. DrawItem( Weapontype[i].Name, 17+i*13, BASEWEAPONPRICE( i ) );
  85. for (i=0; i<MAXSHIELDTYPE; ++i)
  86. DrawItem( Shieldtype[i].Name, 17+(i+MAXWEAPONTYPE)*13, BASESHIELDPRICE( i ) );
  87. for (i=0; i<MAXGADGETTYPE; ++i)
  88. DrawItem( Gadgettype[i].Name, 17+(i+MAXWEAPONTYPE+MAXSHIELDTYPE)*13, BASEGADGETPRICE( i ) );
  89. DisplayTradeCredits();
  90. }
  91. // *************************************************************************
  92. // Handling of the events of the Buy Equipment form.
  93. // *************************************************************************
  94. Boolean BuyEquipmentFormHandleEvent( EventPtr eventP )
  95. {
  96. Boolean handled = false;
  97. switch (eventP->eType)
  98. {
  99. case frmOpenEvent:
  100. case frmUpdateEvent:
  101. DrawBuyEquipmentForm();
  102. handled = true;
  103. break;
  104. case ctlSelectEvent:
  105. if (eventP->data.ctlSelect.controlID >= BuyEquipmentBuy0Button &&
  106. eventP->data.ctlSelect.controlID < BuyEquipmentBuy0Button+MAXWEAPONTYPE)
  107. {
  108. BuyItem( Shiptype[Ship.Type].WeaponSlots,
  109. Ship.Weapon,
  110. BASEWEAPONPRICE( eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button ),
  111. Weapontype[eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button].Name,
  112. eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button );
  113. }
  114. if (eventP->data.ctlSelect.controlID >= BuyEquipmentBuy0Button+MAXWEAPONTYPE &&
  115. eventP->data.ctlSelect.controlID < BuyEquipmentBuy0Button+MAXWEAPONTYPE+MAXSHIELDTYPE)
  116. {
  117. BuyItem( Shiptype[Ship.Type].ShieldSlots,
  118. Ship.Shield,
  119. BASESHIELDPRICE( eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE ),
  120. Shieldtype[eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE].Name,
  121. eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE );
  122. }
  123. if (eventP->data.ctlSelect.controlID >= BuyEquipmentBuy0Button+MAXWEAPONTYPE+MAXSHIELDTYPE &&
  124. eventP->data.ctlSelect.controlID < BuyEquipmentBuy0Button+MAXWEAPONTYPE+MAXSHIELDTYPE+MAXGADGETTYPE )
  125. {
  126. if (HasGadget( &Ship, eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE - MAXSHIELDTYPE ) &&
  127. EXTRABAYS != eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE - MAXSHIELDTYPE)
  128. FrmAlert( NoMoreOfItemAlert );
  129. else
  130. {
  131. BuyItem( Shiptype[Ship.Type].GadgetSlots,
  132. Ship.Gadget,
  133. BASEGADGETPRICE( eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE - MAXSHIELDTYPE ),
  134. Gadgettype[eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE - MAXSHIELDTYPE].Name,
  135. eventP->data.ctlSelect.controlID - BuyEquipmentBuy0Button - MAXWEAPONTYPE - MAXSHIELDTYPE );
  136. }
  137. }
  138. handled = true;
  139. break;
  140. default:
  141. break;
  142. }
  143. return handled;
  144. }