SellEquipEvent.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /***********************************************************************
  2. *
  3. * SPACE TRADER 1.2.0
  4. *
  5. * SellEquipEvent.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 the events of the Sell Equipment form.
  36. // *************************************************************************
  37. #include "external.h"
  38. Boolean SellEquipmentFormHandleEvent( EventPtr eventP )
  39. {
  40. Boolean handled = false;
  41. Boolean Sale;
  42. FormPtr frmP;
  43. int i;
  44. switch (eventP->eType)
  45. {
  46. case frmOpenEvent:
  47. DrawSellEquipment();
  48. handled = true;
  49. break;
  50. case frmUpdateEvent:
  51. DrawSellEquipment();
  52. handled = true;
  53. break;
  54. case ctlSelectEvent:
  55. if (FrmAlert( SellItemAlert ) != SellItemYes)
  56. {
  57. handled = true;
  58. break;
  59. }
  60. frmP = FrmGetActiveForm();
  61. Sale = true;
  62. if (eventP->data.ctlSelect.controlID >= SellEquipmentSell0Button &&
  63. eventP->data.ctlSelect.controlID < SellEquipmentSell0Button+MAXWEAPON)
  64. {
  65. Credits += WEAPONSELLPRICE( eventP->data.ctlSelect.controlID - SellEquipmentSell0Button );
  66. for (i=eventP->data.ctlSelect.controlID - SellEquipmentSell0Button + 1; i<MAXWEAPON; ++i)
  67. Ship.Weapon[i-1] = Ship.Weapon[i];
  68. Ship.Weapon[MAXWEAPON-1] = -1;
  69. }
  70. if (eventP->data.ctlSelect.controlID >= SellEquipmentSell0Button+MAXWEAPON &&
  71. eventP->data.ctlSelect.controlID < SellEquipmentSell0Button+MAXWEAPON+MAXSHIELD)
  72. {
  73. Credits += SHIELDSELLPRICE( eventP->data.ctlSelect.controlID - SellEquipmentSell0Button - MAXWEAPON );
  74. for (i=eventP->data.ctlSelect.controlID - SellEquipmentSell0Button - MAXWEAPON + 1; i<MAXSHIELD; ++i)
  75. {
  76. Ship.Shield[i-1] = Ship.Shield[i];
  77. Ship.ShieldStrength[i-1] = Ship.ShieldStrength[i];
  78. }
  79. Ship.Shield[MAXSHIELD-1] = -1;
  80. Ship.ShieldStrength[MAXSHIELD-1] = 0;
  81. }
  82. if (eventP->data.ctlSelect.controlID >= SellEquipmentSell0Button+MAXWEAPON+MAXSHIELD &&
  83. eventP->data.ctlSelect.controlID < SellEquipmentSell0Button+MAXWEAPON+MAXSHIELD+MAXGADGET)
  84. {
  85. if (Ship.Gadget[eventP->data.ctlSelect.controlID - SellEquipmentSell0Button - MAXWEAPON - MAXSHIELD] == EXTRABAYS)
  86. {
  87. if (FilledCargoBays() > TotalCargoBays() - 5)
  88. {
  89. FrmAlert( CargoBaysFullAlert );
  90. Sale = false;
  91. }
  92. }
  93. if (Sale)
  94. {
  95. Credits += GADGETSELLPRICE( eventP->data.ctlSelect.controlID - SellEquipmentSell0Button - MAXWEAPON - MAXSHIELD );
  96. for (i=eventP->data.ctlSelect.controlID - SellEquipmentSell0Button - MAXWEAPON - MAXSHIELD + 1; i<MAXGADGET; ++i)
  97. Ship.Gadget[i-1] = Ship.Gadget[i];
  98. Ship.Gadget[MAXGADGET-1] = -1;
  99. }
  100. }
  101. if (Sale)
  102. DrawSellEquipment();
  103. handled = true;
  104. break;
  105. default:
  106. break;
  107. }
  108. return handled;
  109. }