UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_market.cpp File Reference

Single player market stuff. More...

#include "../../DateTime.h"
#include "../../cl_shared.h"
#include "cp_campaign.h"
#include "cp_market.h"
#include "cp_popup.h"
#include "save/save_market.h"
Include dependency graph for cp_market.cpp:

Go to the source code of this file.

Macros

#define BID_FACTOR   0.9
#define BS_GetMarket()

Functions

bool BS_IsOnMarket (const objDef_t *item)
 Check if an item is on market.
int BS_GetItemOnMarket (const objDef_t *od)
 Get the number of items of the given type on the market.
void BS_AddItemToMarket (const objDef_t *od, int amount)
 Internal function to add items to the market.
static void BS_RemoveItemFromMarket (const objDef_t *od, int amount)
 Internal function to remove items from the market.
int BS_GetItemSellingPrice (const objDef_t *od)
 Get the price for an item that you want to sell on the market.
int BS_GetItemBuyingPrice (const objDef_t *od)
 Get the price for an item that you want to buy on the market.
bool BS_AircraftIsOnMarket (const aircraft_t *aircraft)
 Checks whether a given aircraft should appear on the market.
int BS_GetAircraftOnMarket (const aircraft_t *aircraft)
 Get the number of aircraft of the given type on the market.
static void BS_AddAircraftToMarket (const aircraft_t *aircraft, int amount)
 Internal function to add aircraft to the market.
static void BS_RemoveAircraftFromMarket (const aircraft_t *aircraft, int amount)
 Internal function to remove aircraft from the market.
int BS_GetAircraftSellingPrice (const aircraft_t *aircraft)
 Get the price for an aircraft that you want to sell on the market.
int BS_GetAircraftBuyingPrice (const aircraft_t *aircraft)
 Get the price for an aircraft that you want to buy on the market.
static void BS_ProcessCraftItemSale (const objDef_t *craftitem, const int numItems)
 Update storage, the market, and the player's credits.
bool BS_BuyAircraft (const aircraft_t *aircraftTemplate, base_t *base)
 Buys an aircraft.
bool BS_SellAircraft (aircraft_t *aircraft)
 Sells the given aircraft with all the equipment.
bool BS_BuyUGV (const ugv_t *ugv, base_t *base)
 Buys the given UGV.
bool BS_SellUGV (Employee *robot)
 Sells the given UGV with all the equipment.
bool BS_BuyItem (const objDef_t *od, base_t *base, int count)
 Buys items from the market.
bool BS_SellItem (const objDef_t *od, base_t *base, int count)
 Sells items from the market.
bool BS_SaveXML (xmlNode_t *parent)
 Save callback for savegames.
bool BS_LoadXML (xmlNode_t *parent)
 Load callback for savegames.
void BS_InitMarket (const campaign_t *campaign)
 sets market prices at start of the game
void CP_CampaignRunMarket (campaign_t *campaign)
 make number of items change every day.
bool BS_BuySellAllowed (const base_t *base)
 Returns true if you can buy or sell equipment.

Detailed Description

Single player market stuff.

Note
Buy/Sell functions prefix: BS_

Definition in file cp_market.cpp.

Macro Definition Documentation

◆ BID_FACTOR

#define BID_FACTOR   0.9

Definition at line 33 of file cp_market.cpp.

Referenced by BS_InitMarket().

◆ BS_GetMarket

Function Documentation

◆ BS_AddAircraftToMarket()

void BS_AddAircraftToMarket ( const aircraft_t * aircraft,
int amount )
static

Internal function to add aircraft to the market.

Parameters
[in]aircraftAircraft template definition
[in]amountNon-negative number of aircraft to add

Definition at line 140 of file cp_market.cpp.

References AIR_IsUFO, BS_GetMarket, cgi, aircraft_t::id, market_t::numAircraft, and type.

Referenced by BS_SellAircraft(), and CP_CampaignRunMarket().

◆ BS_AddItemToMarket()

void BS_AddItemToMarket ( const objDef_t * od,
int amount )

Internal function to add items to the market.

Parameters
[in]odObject definition (the item itself)
[in]amountNon-negative number of items to add

Definition at line 64 of file cp_market.cpp.

References BS_GetMarket, objDef_t::idx, and market_t::numItems.

Referenced by BS_ProcessCraftItemSale(), BS_SellItem(), BS_SellUGV(), and CP_CampaignRunMarket().

◆ BS_AircraftIsOnMarket()

bool BS_AircraftIsOnMarket ( const aircraft_t * aircraft)

Checks whether a given aircraft should appear on the market.

Parameters
aircraftThe aircraft to check
Returns
true if the aircraft should appear on the market

Definition at line 112 of file cp_market.cpp.

References AIR_IsUFO, and aircraft_t::price.

Referenced by BS_FillMarket_f(), and BS_GetAircraftOnMarket().

◆ BS_BuyAircraft()

bool BS_BuyAircraft ( const aircraft_t * aircraftTemplate,
base_t * base )

Buys an aircraft.

Parameters
[in]aircraftTemplateThe aircraft template to buy
[out]baseBase to buy at
Returns
true if the aircraft could get bought, false otherwise

Definition at line 237 of file cp_market.cpp.

References AIR_NewAircraft(), BS_GetAircraftBuyingPrice(), BS_GetAircraftOnMarket(), BS_RemoveAircraftFromMarket(), ccs, cgi, CP_UpdateCredits(), and ERR_DROP.

Referenced by BS_Buy_f().

◆ BS_BuyItem()

bool BS_BuyItem ( const objDef_t * od,
base_t * base,
int count )

Buys items from the market.

Parameters
[in]odpointer to the item (Object Definition record)
[out]baseBase to buy at
[in]countNumber of items to buy
Returns
true if the ugv could get bought, false otherwise

Definition at line 382 of file cp_market.cpp.

References B_AddToStorage(), BS_GetItemBuyingPrice(), BS_GetItemOnMarket(), BS_IsOnMarket(), BS_RemoveItemFromMarket(), CAP_GetFreeCapacity(), CAP_ITEMS, ccs, cgi, count, CP_UpdateCredits(), ERR_DROP, and objDef_t::size.

Referenced by BS_Buy_f().

◆ BS_BuySellAllowed()

bool BS_BuySellAllowed ( const base_t * base)

Returns true if you can buy or sell equipment.

Parameters
[in]basePointer to base to check on
See also
B_BaseInit_f

Definition at line 656 of file cp_market.cpp.

References B_GetBuildingStatus(), B_IsUnderAttack, and B_STORAGE.

Referenced by B_BaseInit_f(), and B_BuildingOpenAfterClick_f().

◆ BS_BuyUGV()

bool BS_BuyUGV ( const ugv_t * ugv,
base_t * base )

Buys the given UGV.

Parameters
[in]ugvThe ugv template of the UGV to buy
[out]baseBase to buy at
Returns
true if the ugv could get bought, false otherwise
Todo
Implement this correctly once we have UGV

Definition at line 308 of file cp_market.cpp.

References B_AddToStorage(), BS_GetItemOnMarket(), BS_RemoveItemFromMarket(), CAP_GetFreeCapacity(), CAP_ITEMS, ccs, cgi, CP_UpdateCredits(), E_CountUnhiredRobotsByType(), E_HireRobot(), ERR_DROP, ugv_t::id, INVSH_GetItemByID(), ugv_t::price, objDef_t::size, UGV_SIZE, and ugv_t::weapon.

Referenced by BS_Buy_f().

◆ BS_GetAircraftBuyingPrice()

int BS_GetAircraftBuyingPrice ( const aircraft_t * aircraft)

Get the price for an aircraft that you want to buy on the market.

Parameters
[in]aircraftThe aircraft to buy
Returns
The price of the aircraft

Definition at line 211 of file cp_market.cpp.

References AIR_IsUFO, market_t::askAircraft, BS_GetMarket, cgi, aircraft_t::id, and type.

Referenced by BS_Buy_f(), BS_BuyAircraft(), and BS_FillMarket_f().

◆ BS_GetAircraftOnMarket()

int BS_GetAircraftOnMarket ( const aircraft_t * aircraft)

Get the number of aircraft of the given type on the market.

Parameters
[in]aircraftThe aircraft to search the market for
Returns
The amount of aircraft for the given type

Definition at line 127 of file cp_market.cpp.

References BS_AircraftIsOnMarket(), BS_GetMarket, cgi, aircraft_t::id, market_t::numAircraft, and type.

Referenced by BS_BuyAircraft(), and BS_FillMarket_f().

◆ BS_GetAircraftSellingPrice()

int BS_GetAircraftSellingPrice ( const aircraft_t * aircraft)

Get the price for an aircraft that you want to sell on the market.

Parameters
[in]aircraftThe aircraft to sell
Returns
The price of the aircraft

Definition at line 170 of file cp_market.cpp.

References AIR_IsUFO, AIR_STATS_DAMAGE, aircraftSlot_t::ammo, market_t::bidAircraft, BS_GetItemSellingPrice(), BS_GetMarket, cgi, aircraft_t::damage, aircraft_t::electronics, i, aircraft_t::id, aircraftSlot_t::item, aircraft_t::maxElectronics, aircraft_t::maxWeapons, aircraft_t::shield, aircraft_t::stats, aircraft_t::tpl, type, and aircraft_t::weapons.

Referenced by BS_FillMarket_f(), and BS_SellAircraft().

◆ BS_GetItemBuyingPrice()

int BS_GetItemBuyingPrice ( const objDef_t * od)

Get the price for an item that you want to buy on the market.

Parameters
[in]odThe item to buy
Returns
The price of the item

Definition at line 101 of file cp_market.cpp.

References market_t::askItems, BS_GetMarket, and objDef_t::idx.

Referenced by BS_Buy_f(), BS_BuyItem(), and BS_FillMarket_f().

◆ BS_GetItemOnMarket()

int BS_GetItemOnMarket ( const objDef_t * od)

Get the number of items of the given type on the market.

Parameters
[in]odthe item (objDef) to search the market for
Returns
The amount of items for the given type

Definition at line 53 of file cp_market.cpp.

References BS_GetMarket, BS_IsOnMarket(), objDef_t::idx, and market_t::numItems.

Referenced by BS_Buy_f(), BS_BuyItem(), BS_BuyUGV(), and BS_FillMarket_f().

◆ BS_GetItemSellingPrice()

int BS_GetItemSellingPrice ( const objDef_t * od)

Get the price for an item that you want to sell on the market.

Parameters
[in]odThe item to sell
Returns
The price of the item

Definition at line 90 of file cp_market.cpp.

References market_t::bidItems, BS_GetMarket, and objDef_t::idx.

Referenced by B_SellOrAddItems(), BS_FillMarket_f(), BS_GetAircraftSellingPrice(), BS_ProcessCraftItemSale(), and BS_SellItem().

◆ BS_InitMarket()

◆ BS_IsOnMarket()

bool BS_IsOnMarket ( const objDef_t * item)

Check if an item is on market.

Parameters
[in]itemPointer to the item to check
Note
this function doesn't check if the item is available on market (buyable > 0)

Definition at line 42 of file cp_market.cpp.

References objDef_t::isVirtual, and objDef_t::notOnMarket.

Referenced by BS_Buy_f(), BS_BuyItem(), BS_FillMarket_f(), BS_GetItemOnMarket(), BS_SaveXML(), BS_SellItem(), BS_ShowInfo_f(), and CP_ItemsSanityCheck().

◆ BS_LoadXML()

◆ BS_ProcessCraftItemSale()

void BS_ProcessCraftItemSale ( const objDef_t * craftitem,
const int numItems )
static

Update storage, the market, and the player's credits.

Note
Don't update capacity here because we can sell items directly from aircraft (already removed from storage).

Definition at line 223 of file cp_market.cpp.

References BS_AddItemToMarket(), BS_GetItemSellingPrice(), ccs, and CP_UpdateCredits().

Referenced by BS_SellAircraft().

◆ BS_RemoveAircraftFromMarket()

void BS_RemoveAircraftFromMarket ( const aircraft_t * aircraft,
int amount )
static

Internal function to remove aircraft from the market.

Parameters
[in]aircraftAircraft template definition
[in]amountNon-negative number of aircraft to remove

Definition at line 154 of file cp_market.cpp.

References AIR_IsUFO, BS_GetMarket, cgi, aircraft_t::id, market_t::numAircraft, and type.

Referenced by BS_BuyAircraft(), and CP_CampaignRunMarket().

◆ BS_RemoveItemFromMarket()

void BS_RemoveItemFromMarket ( const objDef_t * od,
int amount )
static

Internal function to remove items from the market.

Parameters
[in]odObject definition (the item itself)
[in]amountNon-negative number of items to remove

Definition at line 76 of file cp_market.cpp.

References BS_GetMarket, objDef_t::idx, and market_t::numItems.

Referenced by BS_BuyItem(), BS_BuyUGV(), and CP_CampaignRunMarket().

◆ BS_SaveXML()

◆ BS_SellAircraft()

bool BS_SellAircraft ( aircraft_t * aircraft)

Sells the given aircraft with all the equipment.

Parameters
aircraftThe aircraft to sell
Returns
true if the aircraft could get sold, false otherwise

Definition at line 265 of file cp_market.cpp.

References AIR_DeleteAircraft(), AIR_GetTeamSize(), AIR_IsAircraftInBase(), aircraftSlot_t::ammo, BS_AddAircraftToMarket(), BS_GetAircraftSellingPrice(), BS_ProcessCraftItemSale(), ccs, CP_UpdateCredits(), aircraft_t::electronics, aircraftSlot_t::item, aircraft_t::maxElectronics, aircraft_t::maxWeapons, aircraft_t::shield, and aircraft_t::weapons.

Referenced by BS_Buy_f().

◆ BS_SellItem()

bool BS_SellItem ( const objDef_t * od,
base_t * base,
int count )

Sells items from the market.

Parameters
[in]odpointer to the item (Object Definition record)
[out]baseBase to sell at
[in]countNumber of items to sell
Returns
true if the ugv could get sold, false otherwise

Definition at line 414 of file cp_market.cpp.

References B_AddToStorage(), B_ItemInBase(), BS_AddItemToMarket(), BS_GetItemSellingPrice(), BS_IsOnMarket(), ccs, cgi, count, CP_UpdateCredits(), and ERR_DROP.

Referenced by B_SellOrAddItems(), and BS_Buy_f().

◆ BS_SellUGV()

bool BS_SellUGV ( Employee * robot)

Sells the given UGV with all the equipment.

Parameters
robotThe employee record of the UGV to sell
Returns
true if the ugv could get sold, false otherwise
Todo
Implement this correctly once we have UGV
Todo
message - Couldn't fire employee.

Definition at line 344 of file cp_market.cpp.

References B_AddToStorage(), Employee::baseHired, BS_AddItemToMarket(), ccs, cgi, Employee::chr, CP_UpdateCredits(), DEBUG_CLIENT, ERR_DROP, Employee::getUGV(), ugv_t::id, INVSH_GetItemByID(), ugv_t::price, character_t::ucn, Employee::unhire(), and ugv_t::weapon.

Referenced by BS_Buy_f().

◆ CP_CampaignRunMarket()

void CP_CampaignRunMarket ( campaign_t * campaign)

make number of items change every day.

See also
CP_CampaignRun
daily called
Note
This function makes items number on market slowly reach the asymptotic number of items defined in equipment.ufo If an item has just been researched, it's not available on market until RESEARCH_LIMIT_DELAY days is reached.

< Number of days to reach the asymptotic number of items

< Numbers of days after end of research to wait in order to have items added on market

Definition at line 579 of file cp_market.cpp.

References AIR_GetAircraft(), campaign_t::asymptoticMarketDef, BS_AddAircraftToMarket(), BS_AddItemToMarket(), BS_GetMarket, BS_RemoveAircraftFromMarket(), BS_RemoveItemFromMarket(), ccs, cgi, market_t::currentEvolutionAircraft, market_t::currentEvolutionItems, DateTime::getDateAsDays(), i, int(), INVSH_GetItemByIDX(), campaign_t::marketDef, equipDef_t::numAircraft, market_t::numAircraft, equipDef_t::numItems, market_t::numItems, technology_t::researchedDate, RS_GetTechForItem(), RS_IsResearched_ptr(), aircraft_t::tech, and type.

Referenced by CP_CampaignRun(), and TEST_F().