Fuel.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /***********************************************************************
  2. *
  3. * SPACE TRADER 1.2.0
  4. *
  5. * Fuel.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. // Fuel.c - Functions include:
  36. // char GetFuelTanks( void )
  37. // char GetFuel( void )
  38. // void BuyFuel( int Amount )
  39. //
  40. // Modifications:
  41. // mm/dd/yy - description - author
  42. // *************************************************************************
  43. #include "external.h"
  44. // *************************************************************************
  45. // Determine size of fueltanks
  46. // *************************************************************************
  47. char GetFuelTanks( void )
  48. {
  49. return (HasGadget( &Ship, FUELCOMPACTOR ) ? 18 : Shiptype[Ship.Type].FuelTanks);
  50. }
  51. // *************************************************************************
  52. // Determine fuel in tank
  53. // *************************************************************************
  54. char GetFuel( void )
  55. {
  56. return min( Ship.Fuel, GetFuelTanks() );
  57. }
  58. // *************************************************************************
  59. // Buy Fuel for Amount credits
  60. // *************************************************************************
  61. void BuyFuel( int Amount )
  62. {
  63. int MaxFuel;
  64. int Parsecs;
  65. MaxFuel = (GetFuelTanks() - GetFuel()) * Shiptype[Ship.Type].CostOfFuel;
  66. if (Amount > MaxFuel)
  67. Amount = MaxFuel;
  68. if (Amount > Credits)
  69. Amount = Credits;
  70. Parsecs = Amount / Shiptype[Ship.Type].CostOfFuel;
  71. Ship.Fuel += Parsecs;
  72. Credits -= Parsecs * Shiptype[Ship.Type].CostOfFuel;
  73. }