UFO: Alien Invasion
Doxygen documentation generating
cp_market.cpp
Go to the documentation of this file.
1 
7 /*
8 Copyright (C) 2002-2023 UFO: Alien Invasion.
9 
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 See the GNU General Public License for more details.
20 
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 */
25 
26 #include "../../DateTime.h"
27 #include "../../cl_shared.h"
28 #include "cp_campaign.h"
29 #include "cp_market.h"
30 #include "cp_popup.h"
31 #include "save/save_market.h"
32 
33 #define BID_FACTOR 0.9
34 
35 #define BS_GetMarket() (&ccs.eMarket)
36 
42 bool BS_IsOnMarket (const objDef_t* item)
43 {
44  assert(item);
45  return !(item->isVirtual || item->notOnMarket);
46 }
47 
54 {
55  const market_t* market = BS_GetMarket();
56  return BS_IsOnMarket(od) ? market->numItems[od->idx] : 0;
57 }
58 
64 void BS_AddItemToMarket (const objDef_t* od, int amount)
65 {
66  market_t* market = BS_GetMarket();
67  assert(amount >= 0);
68  market->numItems[od->idx] += amount;
69 }
70 
76 static void BS_RemoveItemFromMarket (const objDef_t* od, int amount)
77 {
78  market_t* market = BS_GetMarket();
79 
80  assert(amount >= 0);
81 
82  market->numItems[od->idx] = std::max(market->numItems[od->idx] - amount, 0);
83 }
84 
91 {
92  const market_t* market = BS_GetMarket();
93  return market->bidItems[od->idx];
94 }
95 
102 {
103  const market_t* market = BS_GetMarket();
104  return market->askItems[od->idx];
105 }
106 
112 bool BS_AircraftIsOnMarket (const aircraft_t* aircraft)
113 {
114  if (AIR_IsUFO(aircraft))
115  return false;
116  if (aircraft->price == -1)
117  return false;
118 
119  return true;
120 }
121 
127 int BS_GetAircraftOnMarket (const aircraft_t* aircraft)
128 {
129  const humanAircraftType_t type = cgi->Com_DropShipShortNameToID(aircraft->id);
130  const market_t* market = BS_GetMarket();
131 
132  return BS_AircraftIsOnMarket(aircraft) ? market->numAircraft[type] : 0;
133 }
134 
140 static void BS_AddAircraftToMarket (const aircraft_t* aircraft, int amount)
141 {
142  const humanAircraftType_t type = cgi->Com_DropShipShortNameToID(aircraft->id);
143  market_t* market = BS_GetMarket();
144  assert(amount >= 0);
145  assert(!AIR_IsUFO(aircraft));
146  market->numAircraft[type] += amount;
147 }
148 
154 static void BS_RemoveAircraftFromMarket (const aircraft_t* aircraft, int amount)
155 {
156  const humanAircraftType_t type = cgi->Com_DropShipShortNameToID(aircraft->id);
157  market_t* market = BS_GetMarket();
158 
159  assert(amount >= 0);
160  assert(!AIR_IsUFO(aircraft));
161 
162  market->numAircraft[type] = std::max(market->numAircraft[type] - amount, 0);
163 }
164 
171 {
172  const humanAircraftType_t type = cgi->Com_DropShipShortNameToID(aircraft->id);
173  const market_t* market = BS_GetMarket();
174  int sellPrice = market->bidAircraft[type];
175 
176  assert(!AIR_IsUFO(aircraft));
177 
178  if (aircraft->tpl != aircraft) {
179  int i;
180 
181  if (aircraft->stats[AIR_STATS_DAMAGE] > 0)
182  sellPrice *= (float)aircraft->damage / aircraft->stats[AIR_STATS_DAMAGE];
183 
184  if (aircraft->shield.item)
185  sellPrice += BS_GetItemSellingPrice(aircraft->shield.item);
186  if (aircraft->shield.ammo)
187  sellPrice += BS_GetItemSellingPrice(aircraft->shield.ammo);
188 
189  for (i = 0; i < aircraft->maxWeapons; i++) {
190  if (aircraft->weapons[i].item)
191  sellPrice += BS_GetItemSellingPrice(aircraft->weapons[i].item);
192  if (aircraft->weapons[i].ammo)
193  sellPrice += BS_GetItemSellingPrice(aircraft->weapons[i].ammo);
194  }
195 
196  for (i = 0; i < aircraft->maxElectronics; i++) {
197  if (aircraft->electronics[i].item)
198  sellPrice += BS_GetItemSellingPrice(aircraft->electronics[i].item);
199  if (aircraft->electronics[i].ammo)
200  sellPrice += BS_GetItemSellingPrice(aircraft->electronics[i].ammo);
201  }
202  }
203  return sellPrice;
204 }
205 
212 {
213  const humanAircraftType_t type = cgi->Com_DropShipShortNameToID(aircraft->id);
214  const market_t* market = BS_GetMarket();
215  assert(!AIR_IsUFO(aircraft));
216  return market->askAircraft[type];
217 }
218 
223 static void BS_ProcessCraftItemSale (const objDef_t* craftitem, const int numItems)
224 {
225  if (craftitem) {
226  BS_AddItemToMarket(craftitem, numItems);
227  CP_UpdateCredits(ccs.credits + BS_GetItemSellingPrice(craftitem) * numItems);
228  }
229 }
230 
237 bool BS_BuyAircraft (const aircraft_t* aircraftTemplate, base_t* base)
238 {
239  if (!base)
240  cgi->Com_Error(ERR_DROP, "BS_BuyAircraft: No base given.");
241  if (!aircraftTemplate)
242  cgi->Com_Error(ERR_DROP, "BS_BuyAircraft: No aircraft template given.");
243 
244  const int amount = BS_GetAircraftOnMarket(aircraftTemplate);
245  if (amount <= 0)
246  return false;
247 
248  const int price = BS_GetAircraftBuyingPrice(aircraftTemplate);
249  if (ccs.credits < price)
250  return false;
251 
252  /* Hangar capacities are being updated in AIR_NewAircraft().*/
253  BS_RemoveAircraftFromMarket(aircraftTemplate, 1);
254  CP_UpdateCredits(ccs.credits - price);
255  AIR_NewAircraft(base, aircraftTemplate);
256 
257  return true;
258 }
259 
265 bool BS_SellAircraft (aircraft_t* aircraft)
266 {
267  int j;
268 
269  if (AIR_GetTeamSize(aircraft) > 0)
270  return false;
271 
272  if (!AIR_IsAircraftInBase(aircraft))
273  return false;
274 
275  /* sell off any items which are mounted on it */
276  for (j = 0; j < aircraft->maxWeapons; j++) {
277  const aircraftSlot_t* slot = &aircraft->weapons[j];
278  BS_ProcessCraftItemSale(slot->item, 1);
279  BS_ProcessCraftItemSale(slot->ammo, 1);
280  }
281 
282  BS_ProcessCraftItemSale(aircraft->shield.item, 1);
283  /* there should be no ammo here, but checking can't hurt */
284  BS_ProcessCraftItemSale(aircraft->shield.ammo, 1);
285 
286  for (j = 0; j < aircraft->maxElectronics; j++) {
287  const aircraftSlot_t* slot = &aircraft->electronics[j];
288  BS_ProcessCraftItemSale(slot->item, 1);
289  /* there should be no ammo here, but checking can't hurt */
290  BS_ProcessCraftItemSale(slot->ammo, 1);
291  }
292 
293  /* the capacities are also updated here */
294  BS_AddAircraftToMarket(aircraft, 1);
296  AIR_DeleteAircraft(aircraft);
297 
298  return true;
299 }
300 
308 bool BS_BuyUGV (const ugv_t* ugv, base_t* base)
309 {
310  const objDef_t* ugvWeapon;
311 
312  if (!ugv)
313  cgi->Com_Error(ERR_DROP, "BS_BuyUGV: Called on nullptr UGV!");
314  if (!base)
315  cgi->Com_Error(ERR_DROP, "BS_BuyUGV: Called on nullptr base!");
316  ugvWeapon = INVSH_GetItemByID(ugv->weapon);
317  if (!ugvWeapon)
318  cgi->Com_Error(ERR_DROP, "BS_BuyItem_f: Could not get weapon '%s' for ugv/tank '%s'.", ugv->weapon, ugv->id);
319 
320  if (ccs.credits < ugv->price)
321  return false;
322  if (E_CountUnhiredRobotsByType(ugv) <= 0)
323  return false;
324  if (BS_GetItemOnMarket(ugvWeapon) <= 0)
325  return false;
326  if (CAP_GetFreeCapacity(base, CAP_ITEMS) < UGV_SIZE + ugvWeapon->size)
327  return false;
328  if (!E_HireRobot(base, ugv))
329  return false;
330 
331  BS_RemoveItemFromMarket(ugvWeapon, 1);
333  B_AddToStorage(base, ugvWeapon, 1);
334 
335  return true;
336 }
337 
344 bool BS_SellUGV (Employee* robot)
345 {
346  const objDef_t* ugvWeapon;
347  const ugv_t* ugv;
348  base_t* base;
349 
350  if (!robot)
351  cgi->Com_Error(ERR_DROP, "Selling nullptr UGV!");
352  if (!robot->getUGV())
353  cgi->Com_Error(ERR_DROP, "Selling invalid UGV with UCN: %i", robot->chr.ucn);
354  ugv = robot->getUGV();
355  base = robot->baseHired;
356 
357  /* Check if we have a weapon for this ugv in the market to sell it. */
358  ugvWeapon = INVSH_GetItemByID(ugv->weapon);
359  if (!ugvWeapon)
360  cgi->Com_Error(ERR_DROP, "BS_BuyItem_f: Could not get wepaon '%s' for ugv/tank '%s'.", ugv->weapon, ugv->id);
361 
362  if (!robot->unhire()) {
364  cgi->Com_DPrintf(DEBUG_CLIENT, "Couldn't sell/fire robot/ugv.\n");
365  return false;
366  }
367 
368  BS_AddItemToMarket(ugvWeapon, 1);
370  B_AddToStorage(base, ugvWeapon, -1);
371 
372  return true;
373 }
374 
382 bool BS_BuyItem (const objDef_t* od, base_t* base, int count)
383 {
384  if (!od)
385  cgi->Com_Error(ERR_DROP, "BS_BuyItem: Called on nullptr objDef!");
386  if (!base)
387  cgi->Com_Error(ERR_DROP, "BS_BuyItem: Called on nullptr base!");
388 
389  if (count <= 0)
390  return false;
391  if (!BS_IsOnMarket(od))
392  return false;
394  return false;
395  if (BS_GetItemOnMarket(od) < count)
396  return false;
397  if (CAP_GetFreeCapacity(base, CAP_ITEMS) < od->size * count)
398  return false;
399 
400  B_AddToStorage(base, od, count);
403 
404  return true;
405 }
406 
414 bool BS_SellItem (const objDef_t* od, base_t* base, int count)
415 {
416  if (!od)
417  cgi->Com_Error(ERR_DROP, "BS_SellItem: Called on nullptr objDef!");
418 
419  if (count <= 0)
420  return false;
421  if (!BS_IsOnMarket(od))
422  return false;
423 
424  if (base) {
425  if (B_ItemInBase(od, base) < count)
426  return false;
427  B_AddToStorage(base, od, -count);
428  }
429 
432 
433  return true;
434 }
435 
442 bool BS_SaveXML (xmlNode_t* parent)
443 {
444  int i;
445  xmlNode_t* node;
446  const market_t* market = BS_GetMarket();
447 
448  /* store market */
449  node = cgi->XML_AddNode(parent, SAVE_MARKET_MARKET);
450  for (i = 0; i < cgi->csi->numODs; i++) {
451  const objDef_t* od = INVSH_GetItemByIDX(i);
452  if (BS_IsOnMarket(od)) {
453  xmlNode_t* snode = cgi->XML_AddNode(node, SAVE_MARKET_ITEM);
454  cgi->XML_AddString(snode, SAVE_MARKET_ID, od->id);
455  cgi->XML_AddIntValue(snode, SAVE_MARKET_NUM, market->numItems[i]);
456  cgi->XML_AddIntValue(snode, SAVE_MARKET_BID, market->bidItems[i]);
457  cgi->XML_AddIntValue(snode, SAVE_MARKET_ASK, market->askItems[i]);
458  cgi->XML_AddDoubleValue(snode, SAVE_MARKET_EVO, market->currentEvolutionItems[i]);
459  cgi->XML_AddBoolValue(snode, SAVE_MARKET_AUTOSELL, market->autosell[i]);
460  }
461  }
462  const int maxAircraft = cgi->Com_GetHumanAircraftIdsNum();
463  for (i = 0; i < maxAircraft; i++) {
464  if (market->bidAircraft[i] > 0 || market->askAircraft[i] > 0) {
466  const char* shortName = cgi->Com_DropShipTypeToShortName((humanAircraftType_t)i);
467  cgi->XML_AddString(snode, SAVE_MARKET_ID, shortName);
468  cgi->XML_AddIntValue(snode, SAVE_MARKET_NUM, market->numAircraft[i]);
469  cgi->XML_AddIntValue(snode, SAVE_MARKET_BID, market->bidAircraft[i]);
470  cgi->XML_AddIntValue(snode, SAVE_MARKET_ASK, market->askAircraft[i]);
471  cgi->XML_AddDoubleValue(snode, SAVE_MARKET_EVO, market->currentEvolutionAircraft[i]);
472  }
473  }
474  return true;
475 }
476 
483 bool BS_LoadXML (xmlNode_t* parent)
484 {
485  xmlNode_t* node, *snode;
486  market_t* market = BS_GetMarket();
487 
488  node = cgi->XML_GetNode(parent, SAVE_MARKET_MARKET);
489  if (!node)
490  return false;
491 
492  for (snode = cgi->XML_GetNode(node, SAVE_MARKET_ITEM); snode; snode = cgi->XML_GetNextNode(snode, node, SAVE_MARKET_ITEM)) {
493  const char* s = cgi->XML_GetString(snode, SAVE_MARKET_ID);
494  const objDef_t* od = INVSH_GetItemByID(s);
495 
496  if (!od) {
497  cgi->Com_Printf("BS_LoadXML: Could not find item '%s'\n", s);
498  continue;
499  }
500 
501  market->numItems[od->idx] = cgi->XML_GetInt(snode, SAVE_MARKET_NUM, 0);
502  market->bidItems[od->idx] = cgi->XML_GetInt(snode, SAVE_MARKET_BID, 0);
503  market->askItems[od->idx] = cgi->XML_GetInt(snode, SAVE_MARKET_ASK, 0);
504  market->currentEvolutionItems[od->idx] = cgi->XML_GetDouble(snode, SAVE_MARKET_EVO, 0.0);
505  market->autosell[od->idx] = cgi->XML_GetBool(snode, SAVE_MARKET_AUTOSELL, false);
506  }
507  for (snode = cgi->XML_GetNode(node, SAVE_MARKET_AIRCRAFT); snode; snode = cgi->XML_GetNextNode(snode, node, SAVE_MARKET_AIRCRAFT)) {
508  const char* s = cgi->XML_GetString(snode, SAVE_MARKET_ID);
509  const humanAircraftType_t type = cgi->Com_DropShipShortNameToID(s);
510 
511  market->numAircraft[type] = cgi->XML_GetInt(snode, SAVE_MARKET_NUM, 0);
512  market->bidAircraft[type] = cgi->XML_GetInt(snode, SAVE_MARKET_BID, 0);
513  market->askAircraft[type] = cgi->XML_GetInt(snode, SAVE_MARKET_ASK, 0);
514  market->currentEvolutionAircraft[type] = cgi->XML_GetDouble(snode, SAVE_MARKET_EVO, 0.0);
515  }
516 
517  return true;
518 }
519 
526 void BS_InitMarket (const campaign_t* campaign)
527 {
528  int i;
529  market_t* market = BS_GetMarket();
530 
531  for (i = 0; i < cgi->csi->numODs; i++) {
532  const objDef_t* od = INVSH_GetItemByIDX(i);
533  if (market->askItems[i] == 0) {
534  market->askItems[i] = od->price;
535  market->bidItems[i] = floor(market->askItems[i] * BID_FACTOR);
536  }
537 
538  if (campaign->marketDef->numItems[i] <= 0)
539  continue;
540 
542  /* the other relevant values were already set above */
543  market->numItems[i] = campaign->marketDef->numItems[i];
544  } else {
545  cgi->Com_Printf("BS_InitMarket: Could not add item %s to the market - not marked as researched in campaign %s\n",
546  od->id, campaign->id);
547  }
548  }
549 
550  const int maxAircraft = cgi->Com_GetHumanAircraftIdsNum();
551  for (i = 0; i < maxAircraft; i++) {
553  const aircraft_t* aircraft = AIR_GetAircraft(name);
554  if (market->askAircraft[i] == 0) {
555  market->askAircraft[i] = aircraft->price;
556  market->bidAircraft[i] = floor(market->askAircraft[i] * BID_FACTOR);
557  }
558 
559  if (campaign->marketDef->numAircraft[i] <= 0)
560  continue;
561 
562  if (RS_IsResearched_ptr(aircraft->tech)) {
563  /* the other relevant values were already set above */
564  market->numAircraft[i] = campaign->marketDef->numAircraft[i];
565  } else {
566  cgi->Com_Printf("BS_InitMarket: Could not add aircraft %s to the market - not marked as researched in campaign %s\n",
567  aircraft->id, campaign->id);
568  }
569  }
570 }
571 
580 {
581  int i;
582  const float TYPICAL_TIME = 10.f;
583  const int RESEARCH_LIMIT_DELAY = 30;
585  market_t* market = BS_GetMarket();
586 
587  assert(campaign->marketDef);
588  assert(campaign->asymptoticMarketDef);
589 
590  for (i = 0; i < cgi->csi->numODs; i++) {
591  const objDef_t* od = INVSH_GetItemByIDX(i);
592  const technology_t* tech = RS_GetTechForItem(od);
593  int asymptoticNumber;
594 
595  if (RS_IsResearched_ptr(tech) && (campaign->marketDef->numItems[i] != 0 || ccs.date.getDateAsDays() > tech->researchedDate.getDateAsDays() + RESEARCH_LIMIT_DELAY)) {
596  /* if items are researched for more than RESEARCH_LIMIT_DELAY or was on the initial market,
597  * there number tend to the value defined in equipment.ufo.
598  * This value is the asymptotic value if it is not 0, or initial value else */
599  asymptoticNumber = campaign->asymptoticMarketDef->numItems[i] ? campaign->asymptoticMarketDef->numItems[i] : campaign->marketDef->numItems[i];
600  } else {
601  /* items that have just been researched don't appear on market, but they can disappear */
602  asymptoticNumber = 0;
603  }
604 
605  /* Store the evolution of the market in currentEvolution */
606  market->currentEvolutionItems[i] += (asymptoticNumber - market->numItems[i]) / TYPICAL_TIME;
607 
608  /* Check if new items appeared or disappeared on market */
609  if (fabs(market->currentEvolutionItems[i]) >= 1.0f) {
610  const int num = (int)(market->currentEvolutionItems[i]);
611  if (num >= 0)
612  BS_AddItemToMarket(od, num);
613  else
614  BS_RemoveItemFromMarket(od, -num);
615  market->currentEvolutionItems[i] -= num;
616  }
617  }
618 
619  const int maxAircraft = cgi->Com_GetHumanAircraftIdsNum();
620  for (i = 0; i < maxAircraft; i++) {
622  const char* aircraftID = cgi->Com_DropShipTypeToShortName(type);
623  const aircraft_t* aircraft = AIR_GetAircraft(aircraftID);
624  const technology_t* tech = aircraft->tech;
625  int asymptoticNumber;
626 
627  if (RS_IsResearched_ptr(tech) && (campaign->marketDef->numAircraft[i] != 0 || ccs.date.getDateAsDays() > tech->researchedDate.getDateAsDays() + RESEARCH_LIMIT_DELAY)) {
628  /* if aircraft is researched for more than RESEARCH_LIMIT_DELAY or was on the initial market,
629  * there number tend to the value defined in equipment.ufo.
630  * This value is the asymptotic value if it is not 0, or initial value else */
631  asymptoticNumber = campaign->asymptoticMarketDef->numAircraft[i] ? campaign->asymptoticMarketDef->numAircraft[i] : campaign->marketDef->numAircraft[i];
632  } else {
633  /* items that have just been researched don't appear on market, but they can disappear */
634  asymptoticNumber = 0;
635  }
636  /* Store the evolution of the market in currentEvolution */
637  market->currentEvolutionAircraft[i] += (asymptoticNumber - market->numAircraft[i]) / TYPICAL_TIME;
638 
639  /* Check if new items appeared or disappeared on market */
640  if (fabs(market->currentEvolutionAircraft[i]) >= 1.0f) {
641  const int num = (int)(market->currentEvolutionAircraft[i]);
642  if (num >= 0)
643  BS_AddAircraftToMarket(aircraft, num);
644  else
645  BS_RemoveAircraftFromMarket(aircraft, -num);
646  market->currentEvolutionAircraft[i] -= num;
647  }
648  }
649 }
650 
656 bool BS_BuySellAllowed (const base_t* base)
657 {
658  return !B_IsUnderAttack(base) && B_GetBuildingStatus(base, B_STORAGE);
659 }
xmlNode_t *IMPORT * XML_GetNode(xmlNode_t *parent, const char *name)
int B_ItemInBase(const objDef_t *item, const base_t *base)
Check if the item has been collected (i.e it is in the storage) in the given base.
Definition: cp_base.cpp:2133
bool BS_SaveXML(xmlNode_t *parent)
Save callback for savegames.
Definition: cp_market.cpp:442
int BS_GetAircraftBuyingPrice(const aircraft_t *aircraft)
Get the price for an aircraft that you want to buy on the market.
Definition: cp_market.cpp:211
bool AIR_IsAircraftInBase(const aircraft_t *aircraft)
Checks whether given aircraft is in its homebase.
int askAircraft[AIRCRAFTTYPE_MAX]
Definition: cp_market.h:36
csi_t * csi
Definition: cgame.h:100
int numItems[MAX_OBJDEFS]
Definition: cp_market.h:29
double currentEvolutionAircraft[AIRCRAFTTYPE_MAX]
Definition: cp_market.h:37
bool RS_IsResearched_ptr(const technology_t *tech)
Checks whether an item is already researched.
const objDef_t * INVSH_GetItemByID(const char *id)
Returns the item that belongs to the given id or nullptr if it wasn&#39;t found.
Definition: inv_shared.cpp:282
QGL_EXTERN GLint GLenum type
Definition: r_gl.h:94
#define SAVE_MARKET_MARKET
Definition: save_market.h:27
bool B_GetBuildingStatus(const base_t *const base, const buildingType_t buildingType)
Get the status associated to a building.
Definition: cp_base.cpp:478
bool BS_SellUGV(Employee *robot)
Sells the given UGV with all the equipment.
Definition: cp_market.cpp:344
aircraft_t * AIR_NewAircraft(base_t *base, const aircraft_t *aircraftTemplate)
Places a new aircraft in the given base.
A base with all it&#39;s data.
Definition: cp_base.h:84
short humanAircraftType_t
Definition: inv_shared.h:28
int maxWeapons
Definition: cp_aircraft.h:145
char * id
Definition: cp_aircraft.h:120
int numAircraft[AIRCRAFTTYPE_MAX]
Definition: inv_shared.h:610
int B_AddToStorage(base_t *base, const objDef_t *obj, int amount)
Add/remove items to/from the storage.
Definition: cp_base.cpp:2576
#define B_IsUnderAttack(base)
Definition: cp_base.h:53
const equipDef_t * marketDef
Definition: cp_campaign.h:175
bool BS_IsOnMarket(const objDef_t *item)
Check if an item is on market.
Definition: cp_market.cpp:42
static void BS_ProcessCraftItemSale(const objDef_t *craftitem, const int numItems)
Update storage, the market, and the player&#39;s credits.
Definition: cp_market.cpp:223
Header for single player market stuff.
#define SAVE_MARKET_ITEM
Definition: save_market.h:28
bool BS_LoadXML(xmlNode_t *parent)
Load callback for savegames.
Definition: cp_market.cpp:483
const aircraft_t * AIR_GetAircraft(const char *name)
Searches the global array of aircraft types for a given aircraft.
#define BID_FACTOR
Definition: cp_market.cpp:33
int BS_GetItemBuyingPrice(const objDef_t *od)
Get the price for an item that you want to buy on the market.
Definition: cp_market.cpp:101
void BS_InitMarket(const campaign_t *campaign)
sets market prices at start of the game
Definition: cp_market.cpp:526
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
#define BS_GetMarket()
Definition: cp_market.cpp:35
bool BS_BuySellAllowed(const base_t *base)
Returns true if you can buy or sell equipment.
Definition: cp_market.cpp:656
bool autosell[MAX_OBJDEFS]
Definition: cp_market.h:33
int askItems[MAX_OBJDEFS]
Definition: cp_market.h:31
bool E_HireRobot(base_t *base, const ugv_t *ugvType)
Hires the first free employee of that type.
#define SAVE_MARKET_NUM
Definition: save_market.h:31
int maxElectronics
Definition: cp_aircraft.h:148
int CAP_GetFreeCapacity(const base_t *base, baseCapacities_t capacityType)
Returns the free capacity of a type.
#define xmlNode_t
Definition: xml.h:24
static void BS_AddAircraftToMarket(const aircraft_t *aircraft, int amount)
Internal function to add aircraft to the market.
Definition: cp_market.cpp:140
int numAircraft[AIRCRAFTTYPE_MAX]
Definition: cp_market.h:34
int BS_GetAircraftSellingPrice(const aircraft_t *aircraft)
Get the price for an aircraft that you want to sell on the market.
Definition: cp_market.cpp:170
#define ERR_DROP
Definition: common.h:211
#define DEBUG_CLIENT
Definition: defines.h:59
slot of aircraft
Definition: cp_aircraft.h:78
aircraftSlot_t weapons[MAX_AIRCRAFTSLOT]
Definition: cp_aircraft.h:144
bool BS_BuyUGV(const ugv_t *ugv, base_t *base)
Buys the given UGV.
Definition: cp_market.cpp:308
class DateTime researchedDate
Definition: cp_research.h:187
bool BS_BuyItem(const objDef_t *od, base_t *base, int count)
Buys items from the market.
Definition: cp_market.cpp:382
int E_CountUnhiredRobotsByType(const ugv_t *ugvType)
Counts all available Robots/UGVs that are for sale.
bool unhire()
Fires an employee.
const char *IMPORT * XML_GetString(xmlNode_t *parent, const char *name)
XML tag constants for savegame.
const cgame_import_t * cgi
int BS_GetItemOnMarket(const objDef_t *od)
Get the number of items of the given type on the market.
Definition: cp_market.cpp:53
void CP_UpdateCredits(int credits)
Sets credits and update mn_credits cvar.
struct aircraft_s * tpl
Definition: cp_aircraft.h:119
ccs_t ccs
Definition: cp_campaign.cpp:63
#define SAVE_MARKET_AIRCRAFT
Definition: save_market.h:29
int numODs
Definition: q_shared.h:518
int numItems[MAX_OBJDEFS]
Definition: inv_shared.h:608
int price
Definition: inv_shared.h:332
char id[MAX_VAR]
Definition: cp_campaign.h:166
const objDef_t * ammo
Definition: cp_aircraft.h:86
char weapon[MAX_VAR]
Definition: chr_shared.h:248
xmlNode_t *IMPORT * XML_GetNextNode(xmlNode_t *current, xmlNode_t *parent, const char *name)
bool BS_SellItem(const objDef_t *od, base_t *base, int count)
Sells items from the market.
Definition: cp_market.cpp:414
int stats[AIR_STATS_MAX]
Definition: cp_aircraft.h:160
#define SAVE_MARKET_ID
Definition: save_market.h:30
QGL_EXTERN GLuint count
Definition: r_gl.h:99
#define SAVE_MARKET_BID
Definition: save_market.h:32
int getDateAsDays() const
Return the date part of the DateTime as days.
Definition: DateTime.cpp:46
An aircraft with all it&#39;s data.
Definition: cp_aircraft.h:115
int price
Definition: chr_shared.h:252
struct technology_s * tech
Definition: cp_aircraft.h:163
bool isVirtual
Definition: inv_shared.h:284
const char * id
Definition: inv_shared.h:268
int bidAircraft[AIRCRAFTTYPE_MAX]
Definition: cp_market.h:35
QGL_EXTERN GLint i
Definition: r_gl.h:113
base_t * baseHired
Definition: cp_employee.h:117
aircraftSlot_t shield
Definition: cp_aircraft.h:146
#define AIR_IsUFO(aircraft)
Definition: cp_aircraft.h:206
int AIR_GetTeamSize(const aircraft_t *aircraft)
Counts the number of soldiers in given aircraft.
void BS_AddItemToMarket(const objDef_t *od, int amount)
Internal function to add items to the market.
Definition: cp_market.cpp:64
int BS_GetAircraftOnMarket(const aircraft_t *aircraft)
Get the number of aircraft of the given type on the market.
Definition: cp_market.cpp:127
This is the technology parsed from research.ufo.
Definition: cp_research.h:139
character_t chr
Definition: cp_employee.h:119
int BS_GetItemSellingPrice(const objDef_t *od)
Get the price for an item that you want to sell on the market.
Definition: cp_market.cpp:90
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
class DateTime date
Definition: cp_campaign.h:246
#define SAVE_MARKET_AUTOSELL
Definition: save_market.h:35
Defines all attributes of objects used in the inventory.
Definition: inv_shared.h:264
const struct ugv_s * getUGV() const
Definition: cp_employee.h:107
Header file for single player campaign control.
bool BS_AircraftIsOnMarket(const aircraft_t *aircraft)
Checks whether a given aircraft should appear on the market.
Definition: cp_market.cpp:112
const objDef_t * INVSH_GetItemByIDX(int index)
Returns the item that belongs to the given index or nullptr if the index is invalid.
Definition: inv_shared.cpp:266
#define SAVE_MARKET_EVO
Definition: save_market.h:34
aircraftSlot_t electronics[MAX_AIRCRAFTSLOT]
Definition: cp_aircraft.h:147
#define SAVE_MARKET_ASK
Definition: save_market.h:33
xmlNode_t *IMPORT * XML_AddNode(xmlNode_t *parent, const char *name)
#define UGV_SIZE
Definition: cp_produce.h:33
const objDef_t * item
Definition: cp_aircraft.h:85
const equipDef_t * asymptoticMarketDef
Definition: cp_campaign.h:176
int bidItems[MAX_OBJDEFS]
Definition: cp_market.h:30
char * id
Definition: chr_shared.h:246
const char *IMPORT * Com_DropShipTypeToShortName(humanAircraftType_t type)
technology_t * RS_GetTechForItem(const objDef_t *item)
Returns technology entry for an item.
int size
Definition: inv_shared.h:334
int credits
Definition: cp_campaign.h:243
void CP_CampaignRunMarket(campaign_t *campaign)
make number of items change every day.
Definition: cp_market.cpp:579
bool BS_SellAircraft(aircraft_t *aircraft)
Sells the given aircraft with all the equipment.
Definition: cp_market.cpp:265
static void BS_RemoveAircraftFromMarket(const aircraft_t *aircraft, int amount)
Internal function to remove aircraft from the market.
Definition: cp_market.cpp:154
bool notOnMarket
Definition: inv_shared.h:336
Defines a type of UGV/Robot.
Definition: chr_shared.h:245
static void BS_RemoveItemFromMarket(const objDef_t *od, int amount)
Internal function to remove items from the market.
Definition: cp_market.cpp:76
void AIR_DeleteAircraft(aircraft_t *aircraft)
Removes an aircraft from its base and the game.
bool BS_BuyAircraft(const aircraft_t *aircraftTemplate, base_t *base)
Buys an aircraft.
Definition: cp_market.cpp:237
double currentEvolutionItems[MAX_OBJDEFS]
Definition: cp_market.h:32