mElite  1.0
An Elite clone based on TextElite by Jan-Philipp Kappmeier and Melanie Schmidt.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
txtelite.h
Go to the documentation of this file.
1 
7 /*jm* * Within this file all comments starting with /*jm are made by
8 Jan-Philipp and Melanie. All other comments are from the
9 original file *** */
10 /*jm* * The original code has been changed like this:
11 - we splitted it into declarations (txtelite.h) and
12 program code (txtelite.cpp)
13 - the code was transformed into a class "TextEliteGame",
14 so that we can construct a textEliteGame-object and use
15 it nicely with our other cpp-classes
16 - all functions that execute user commands (like buy fuel,
17 jump somewhere, ..) were rewritten and extended with
18 more error messages (the original code only provided
19 unsharp error messages like "Can't buy any fuel" instead
20 of "tank is full" or "you don't have enough cash").
21 - all functionality for printing on the screen was deleted
22 and, if necessary, replaced by returning strings ******************** */
23 
24 /* txtelite.c1.4 */
25 /* Textual version of Elite trading (C implementation) */
26 /* Converted by Ian Bell from 6502 Elite sources.
27 Original 6502 Elite by Ian Bell & David Braben. */
28 
29 
30 /* ----------------------------------------------------------------------
31 The nature of basic mechanisms used to generate the Elite socio-economic
32 universe are now widely known. A competant games programmer should be able to
33 produce equivalent functionality. A competant hacker should be able to lift
34 the exact system from the object code base of official conversions.
35 
36 This file may be regarded as defining the Classic Elite universe.
37 
38 It contains a C implementation of the precise 6502 algorithms used in the
39 original BBC Micro version of Acornsoft Elite together with a parsed textual
40 command testbed.
41 
42 Note that this is not the universe of David Braben's 'Frontier' series.
43 
44 
45 ICGB 13/10/99
46 iancgbell@email.com
47 www.ibell.co.uk
48 ---------------------------------------------------------------------- */
49 
50 
51 /* Note that this program is "quick-hack" text parser-driven version
52 of Elite with no combat or missions.
53  */
54 
55 /*jm * added for communication with wrapper class and graphic classes ********* */
56 #include <sstream>
57 #include <string>
58 #include <vector>
59 #include "wrappDef.h"
60 
61 /*jm***************** * original includes ************************************* */
62 //#include <stdlib.h>
63 //#include <cstdio>
64 //#include <string.h>
65 //#include <time.h>
66 
67 #include <math.h>
68 
69 /*jm***************** * original defines ************************************** */
70 #define true (-1)
71 #define false (0)
72 #define tons (0)
73 
74 #define maxlen (20) /* Length of strings */
75 
76 #define galsize (256)
77 #define AlienItems (16)
78 #define lasttrade AlienItems
79 
80 #define numforLave 7/* Lave is 7th generated planet in galaxy one */
81 #define numforZaonce 129
82 #define numforDiso 147
83 #define numforRied 46
84 #define POLITICALLY_CORRECT 0
85 /* Set to 1 for NES-sanitised trade goods */
86 #define nocomms (14)
87 
88 /*jm***************** * original typedefs ************************************* */
89 typedef int myboolean;
90 typedef unsigned char uint8;
91 typedef unsigned short uint16;
92 typedef signed short int16;
93 typedef signed long int32;
94 typedef unsigned int uint;
95 typedef int planetnum;
96 
97 /*jm***************** * original structs * ************************************* */
99 { uint8 a,b,c,d;
100 };/* four byte random number used for planet description */
101 
102 
103 struct seedtype
107 };/* six byte random number used as seed for planets */
108 
109 struct plansys
110 { uint x;
111  uint y;/* One byte unsigned */
112  uint economy; /* These two are actually only 0-7*/
114  uint techlev; /* 0-16 i think */
115  uint population; /* One byte */
116  uint productivity; /* Two byte */
117  uint radius; /* Two byte (not used by game at all) */
119  char name[12];
120 };
121 
122 struct tradegood
123 {/* In 6502 version these were: */
124  uint baseprice; /* one byte */
125  int16 gradient; /* five bits plus sign */
126  uint basequant; /* one byte */
127  uint maskbyte;/* one byte */
128  uint units; /* two bits */
129  char name[20];/* longest="Radioactives" */
130 };
131 
135 };
136 
137 
138 /*jm****************************************************************************
139 ********************* * Class definition ****************************************
140  */
142 
143 private:
144 
145  /*jm********** * variables and constants ************************************** */
146 
147  /*jm******************* * new pointers **************************************** */
148  void (*userErrorFnc)(std::string); /*jm pointer to error function for user errors */
149  void (*progErrorFnc)(std::string); /*jm pointer to error function for programmers errors */
150 
151  /*jm********** * original variables ******************************************* */
152 
153  plansys galaxy[galsize]; /* Need 0 to galsize-1 inclusive */
154  seedtype seed;
155  fastseedtype rnd_seed;
156  myboolean nativerand;
157 
158  unsigned int lastrand;
159 
160  /* Player workspace */
161  uint shipshold[lasttrade+1];/* Contents of cargo bay */
162  planetnum currentplanet;/* Current planet */
163  uint galaxynum;/* Galaxy number (1-8) */
164  int32 cash;
165  uint fuel;
166  markettype localmarket;
167  uint holdspace;
168 
169  /*jm*********************variables changed into static constants ************* */
170 
171  static const int fuelcost=2; /* 0.2 CR/Light year */
172  static const int maxfuel =70; /* 7.0 LY tank */
173  static const uint16 base0=0x5A4A;
174  static const uint16 base1=0x0248;
175  static const uint16 base2=0xB753;/* Base seed for galaxy 1 */
176 
177  /*jm***arrays and structures that were originally also filled with data here. **
178  values are set in the class constructor ******************************* */
179  char unitnames[3][5];
180 
181  /* Data for DB's price/availability generation system */
182  /* BaseGrad Base Mask Un Name
183  price ient quantit */
184  tradegood commodities[17];
185 
187  char tradnames[lasttrade+1][maxlen]; /* Tradegood names used in text commands
188  Set using commodities array */
189 
190  struct desc_choice { const char *option[5];};
191 
192  /*char commands[nocomms+1][maxlen]; */
193 
194  /*jm****************************** * functions ******************************** */
195 
196  /*jm**************** * new functions: constructor and destructor ************** */
197 public:
198  TextEliteGame( void (*vuserErrorFnc)(std::string), void (*vprogErrorFnc)(std::string) );
199  ~TextEliteGame( void );
200 
201  /*jm**************** * new functions: get functions ************************** */
202  int getCurrentSystem();
203  std::vector<int> * getLocalSystems();
204  std::vector<int> * getSystemsInRectangle(unsigned int left,
205  unsigned int right, unsigned int bottom, unsigned int top);
206  System getSystemInformation(int number);
207 
208  bool systemIsReachable(int number);
209  bool systemIsInLocalRange(int number);
210 
211  float getFuel();
212  float getMaxFuel();
213 
214  std::vector<MarketplaceItem> * getCurrentMarketplace();
215  std::vector<int> * getCurrentCargo();
216 
217  unsigned int getFreeHoldspace();
218  unsigned int getCargoBaySize();
219 
221 
222  int getFuelCost();
223  bool tradegoodIsInTons(int number);
224 
225  /*jm**************** * new functions: actions ********************************* */
226  void performJump(int number);
227 
228  std::string performPurchase(uint number, uint amount);
229  std::string performSale(uint number, uint amount);
230  void buyFuel(float amount);
231 
232  /*jm************** * new functions: control functions ************************* */
233  void setFuel(uint amount);
234  void setCash(signed long amount);
235  void setCargoBay(uint amount);
236 
237  /*jm**************** * new functions: help functions ************************** */
238  void initValues();
241 
242  /*jm*************** * list of remaining original functions ******************** */
243 private:
244  void mysrand(unsigned int seed);
245  int myrand(void);
246  char randbyte(void);
247  uint mymin(uint a,uint b);
248  signed int ftoi(double value);
249  void tweakseed(seedtype *s);
250  void stripout(char *s,const char c);
251  int toupper(char c);
252  int tolower(char c);
253  markettype genmarket(uint fluct, plansys p);
254  plansys makesystem(seedtype *s);
255  uint16 rotatel(uint16 x);
256  uint16 twist(uint16 x);
257  void nextgalaxy(seedtype *s);
258  void buildgalaxy(uint galaxynum);
259  uint distance(plansys a,plansys b);
260  myboolean dogalhyp(char *s);
261  int gen_rnd_number (void);
262  std::string goat_soup(const char *source,plansys * psy);
263 
264 };
265 
266 
267 
268