ShipPrice.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /***********************************************************************
  2. *
  3. * SPACE TRADER 1.2.0
  4. *
  5. * Shipprice.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. // ShipPrice.c - Functions include:
  36. // long CurrentShipPriceWithoutCargo( Boolean ForInsurance )
  37. // long CurrentShipPrice( Boolean ForInsurance )
  38. //
  39. // Modifications:
  40. // mm/dd/yy - description - author
  41. // *************************************************************************
  42. #include "external.h"
  43. // *************************************************************************
  44. // Determine value of ship
  45. // *************************************************************************
  46. long EnemyShipPrice( SHIP* Sh )
  47. {
  48. int i;
  49. long CurPrice;
  50. CurPrice = Shiptype[Sh->Type].Price;
  51. for (i=0; i<MAXWEAPON; ++i)
  52. if (Sh->Weapon[i] >= 0)
  53. CurPrice += Weapontype[Sh->Weapon[i]].Price;
  54. for (i=0; i<MAXSHIELD; ++i)
  55. if (Sh->Shield[i] >= 0)
  56. CurPrice += Shieldtype[Sh->Shield[i]].Price;
  57. // Gadgets aren't counted in the price, because they are already taken into account in
  58. // the skill adjustment of the price.
  59. CurPrice = CurPrice * (2 * PilotSkill( Sh ) + EngineerSkill( Sh ) + 3 * FighterSkill( Sh )) / 60;
  60. return CurPrice;
  61. }
  62. // *************************************************************************
  63. // Determine value of current ship, including equipment.
  64. // *************************************************************************
  65. long CurrentShipPriceWithoutCargo( Boolean ForInsurance )
  66. {
  67. int i;
  68. long CurPrice;
  69. CurPrice =
  70. // Trade-in value is three-fourths the original price
  71. ((Shiptype[Ship.Type].Price * (Ship.Tribbles > 0 && !ForInsurance? 1 : 3)) / 4)
  72. // subtract repair costs
  73. - (GetHullStrength() - Ship.Hull) * Shiptype[Ship.Type].RepairCosts
  74. // subtract costs to fill tank with fuel
  75. - (Shiptype[Ship.Type].FuelTanks - GetFuel()) * Shiptype[Ship.Type].CostOfFuel;
  76. // Add 2/3 of the price of each item of equipment
  77. for (i=0; i<MAXWEAPON; ++i)
  78. if (Ship.Weapon[i] >= 0)
  79. CurPrice += WEAPONSELLPRICE( i );
  80. for (i=0; i<MAXSHIELD; ++i)
  81. if (Ship.Shield[i] >= 0)
  82. CurPrice += SHIELDSELLPRICE( i );
  83. for (i=0; i<MAXGADGET; ++i)
  84. if (Ship.Gadget[i] >= 0)
  85. CurPrice += GADGETSELLPRICE( i );
  86. return CurPrice;
  87. }
  88. // *************************************************************************
  89. // Determine value of current ship, including goods and equipment.
  90. // *************************************************************************
  91. long CurrentShipPrice( Boolean ForInsurance )
  92. {
  93. int i;
  94. long CurPrice;
  95. CurPrice = CurrentShipPriceWithoutCargo( ForInsurance );
  96. for (i=0; i<MAXTRADEITEM; ++i)
  97. CurPrice += BuyingPrice[i];
  98. return CurPrice;
  99. }