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
Wrapper.cpp
Go to the documentation of this file.
1 
11 #include "Wrapper.h"
12 
13 
18 
19 
22 Wrapper::Wrapper( void (*userErrorFnc)(std::string), void (*progErrorFnc)(std::string) )
23 {
24  vprogErrorFnc = progErrorFnc;
25  vuserErrorFnc = userErrorFnc;
26 
27  tradegoods[0].name = "Food";
28  tradegoods[1].name = "Textiles";
29  tradegoods[2].name = "Radioactives";
30  tradegoods[5].name = "Luxuries";
31  tradegoods[7].name = "Computers";
32  tradegoods[8].name = "Machinery";
33  tradegoods[9].name = "Alloys";
34  tradegoods[10].name = "Firearms";
35  tradegoods[11].name = "Furs";
36  tradegoods[12].name = "Minerals";
37  tradegoods[13].name = "Gold";
38  tradegoods[14].name = "Platinum";
39  tradegoods[15].name = "Gem-Stones";
40  tradegoods[16].name = "Alien Items";
41 #if POLITICALLY_CORRECT
42  tradegoods[3].name = "Robot Slaves";
43  tradegoods[4].name = "Beverages";
44  tradegoods[6].name = "Rare Species";
45 #else
46  tradegoods[3].name = "Slaves";
47  tradegoods[4].name = "Liquor/Wines";
48  tradegoods[6].name = "Narcotics";
49 #endif
50 
51  for (int i = 0; i < numberOfTradegoods; i++)
52  {
53  tradegoods[i].unit = "t";
54  }
55  tradegoods[13].unit = "kg";
56  tradegoods[14].unit = "kg";
57  tradegoods[15].unit = "g";
58 
59  txtgame = new TextEliteGame( userErrorFnc, progErrorFnc );
60 };
61 
64 {
65  delete(txtgame);
66 };
68 
74 
76 
81 {
82  System zwSystem = txtgame->getSystemInformation(number);
83 
84  /* the distance function in textelite divides distances in y-dimension
85  by 2. We decided to divide the y-coordinates of positions by 2 as
86  well to make distances more reasonable to the player*/
87  zwSystem.posy = zwSystem.posy/2;
88  return zwSystem;
89  };
90 
92 
96 {
97  return txtgame->getCurrentSystem();
98 };
99 
101 
109 std::vector<int> * Wrapper::getLocalSystems()
110 {
111  return txtgame->getLocalSystems();
112 };
113 
115 
121 std::vector<int> * Wrapper::getSystemsInRectangle(int left, int right, int bottom, int top)
122 {
123  /* if the original y-coordinate was odd, multiplying by 2 will not restore
124  the original coordinate. Thus we subtract / add 1 to the y-coordinates
125  in a way such that the rectangular is maybe greater, but never smaller
126  than the meant rectangle. */
127  return txtgame->getSystemsInRectangle(left, right, (bottom-1)*2, (top+1)*2);
128 };
129 
131 
136 {
137  return txtgame->systemIsReachable(number);
138 };
139 
141 
147 {
148  return txtgame->systemIsInLocalRange(number);
149 };
150 
152 
159 {
160  return txtgame->getMaxFuel();
161 }
162 
164 
168 {
169  return txtgame->getFuel();
170 };
171 
173 
178 {
179  return numberOfTradegoods;
180 };
181 
183 
190 std::vector<Tradegood> * Wrapper::getAllTradegoodDescriptions()
191 {
192  std::vector<Tradegood> * list = new std::vector<Tradegood>;
193  for (int i = 0; i < numberOfTradegoods; i++) {
194  list->push_back(tradegoods[i]);
195  }
196  return list;
197 };
198 
200 
209 {
210  Tradegood result;
211  if (number < 0 || number >= numberOfTradegoods)
212  vprogErrorFnc("Error! 'number' not in range!");
213  else
214  result = tradegoods[number];
215  return result;
216 };
217 
219 
227 {
228  return txtgame->tradegoodIsInTons(number);
229 }
230 
232 
238 std::vector<MarketplaceItem> * Wrapper::getCurrentMarketplace()
239 {
240  return txtgame->getCurrentMarketplace();
241 };
242 
244 
249  return (float)txtgame->getFuelCost();
250 }
251 
253 
257 std::vector<int> * Wrapper::getCurrentCargo()
258 {
259  return txtgame->getCurrentCargo();
260 };
261 
263 
269 {
270  return txtgame->getFreeHoldspace();
271 };
272 
274 
279 {
280  /* the value is stored as int in the textelite class and therefor
281  multiplied by 10; thus we must divide it by 10. */
282  float fvalue = (float)txtgame->getCurrentCash();
283  return (float)(fvalue/10);
284 };
285 
287 
292 {
293  return txtgame->getCargoBaySize();
294 }
296 
301 
302 
312 void Wrapper::buyFuel(float amount)
313 {
314  if (amount < 0)
315  {
316  vprogErrorFnc("'amount' must not be less than 0! Error occured in getFuelAmount() in Wrapper.cpp");
317  return;
318  }
319  txtgame->buyFuel(amount);
320 };
321 
323 
332 void Wrapper::performJump(int number)
333 {
334  txtgame->performJump(number);
335 };
336 
338 
352 std::string Wrapper::performPurchase(int number, int amount)
353 {
354  if (amount < 0) {
355  vprogErrorFnc("Error! 'amount' is not allowed to be less than 0. Error occured in Wrapper.cpp in the function performPurchase(int number);");
356  }
357  if (number < 0) {
358  vprogErrorFnc("Error! 'number' is not allowed to be less than 0. Error occured in Wrapper.cpp in the function performPurchase(int number);");
359  }
360  std::string report = txtgame->performPurchase((uint)number, (uint)amount);
361  /* * Delete spaces at the end and add a dot * */
362  size_t i = report.size()-1;
363  while (i >= 0 && report[i] == ' ')
364  {
365  report.replace(i,1,"");
366  i--;
367  }
368  report +=".";
369  return report;
370 };
371 
373 
385 std::string Wrapper::performSale(int number, int amount)
386 {
387  if (amount < 0) {
388  vprogErrorFnc("Error! 'amount' is not allowed to be less than 0. Error occured in Wrapper.cpp in the function performPurchase(int number);");
389  }
390  if (number < 0) {
391  vprogErrorFnc("Error! 'number' is not allowed to be less than 0. Error occured in Wrapper.cpp in the function performPurchase(int number);");
392  }
393  std::string report = txtgame->performSale((uint)number, (uint)amount);
394  /* * Delete spaces at the end and add a dot * */
395  size_t i = report.size()-1;
396  while (i >= 0 && report[i] == ' ')
397  {
398  report.replace(i,1,"");
399  i--;
400  }
401  report +=".";
402  return report;
403 };
405 
412 
413 
417 void Wrapper::setCash(float amount){
418  if (amount < -100000 || amount > 100000){
419  vprogErrorFnc("'amount' has to be between -100000 and 100000. Error occured in setCash(float amount) in Wrapper.cpp");
420  return;
421  }
422  float f = amount * 10;
423  signed long i = (signed long) f;
424  txtgame->setCash(i);
425 };
426 
428 
432 void Wrapper::setFuel(float amount){
433  if (amount < 0 || amount > 7.0){
434  vprogErrorFnc("'amount' has to be between 0 and 7. Error occured in setFuel(float amount) in Wrapper.cpp");
435  return;
436  }
437  float f = amount * 10;
438  signed long i = (signed long) f;
439  txtgame->setFuel(i);
440 };
441 
443 
447 void Wrapper::setCargoBay(unsigned int amount){
448  txtgame->setCargoBay(amount);
449 };
450 
452 
455 void Wrapper::addFuel(float amount)
456 {
457  if (amount < 0 || amount > 7.0){
458  vprogErrorFnc("'amount' has to be between 0 and 7. Error occured in adFuel(float amount) in Wrapper.cpp");
459  return;
460  }
461  float newValue = getFuelAmount() + amount;
462  if (newValue > 7.0){
463  vprogErrorFnc("'amount' does not fit into the tank and was reduced (in addFuel in Wrapper.cpp)");
464  newValue = 7.0;
465  }
466  setFuel(newValue);
467 };
468 
470 
473 void Wrapper::addCash(float amount)
474 {
475  float newValue = getCurrentCash() + amount;
476  setCash(newValue);
477 };
478 
480 void Wrapper::addCargoSpace(unsigned int amount)
481 {
482  unsigned int newValue = getCargoBaySize() + amount;
483  txtgame->setCargoBay(newValue);
484 }