generated from Jaysyn/ModuleTemplate
776 lines
27 KiB
Plaintext
776 lines
27 KiB
Plaintext
#include "prc_x2_itemprop"
|
|
// The base price of all craft goods. The sale and buy price is calculated from this
|
|
|
|
const int CRAFT_ITEM_PRICE=14;
|
|
|
|
// The various trade items - the constants are used to refer
|
|
// to them in various functions
|
|
|
|
const int TRADE_ITEM_SILK = 1;
|
|
const int TRADE_ITEM_LINEN =2;
|
|
const int TRADE_ITEM_CLOTH=3;
|
|
const int TRADE_ITEM_IRON=4;
|
|
const int TRADE_ITEM_STUDS=5;
|
|
const int TRADE_ITEM_IRONRINGS=6;
|
|
const int TRADE_ITEM_BOOTSOLE = 7;
|
|
const int TRADE_ITEM_BUCKLE = 8;
|
|
const int TRADE_ITEM_RINGMOLD=9;
|
|
const int TRADE_ITEM_AMULETMOLD=10;
|
|
const int TRADE_ITEM_BLANKSCROLL=11;
|
|
const int TRADE_ITEM_LIGHTCROSSMECH=12;
|
|
const int TRADE_ITEM_HEAVYCROSSMECH=13;
|
|
const int TRADE_ITEM_BOTTLES=14;
|
|
|
|
// If the number of trade items changes, this must be changed:
|
|
|
|
const int TRADE_ITEMS_NUMBER = 14;
|
|
|
|
// Tells us whether a settlement buys, sells or is neutral about a
|
|
// product.
|
|
|
|
const int TRADE_SUPPLY_SELLS = 1;
|
|
const int TRADE_SUPPLY_BUYS = 2;
|
|
const int TRADE_SUPPLY_NOTINTERESTED = 3;
|
|
|
|
// Total number of trade merchants we have
|
|
const int TRADE_NUMBER_OF_MERCHANTS = 6;
|
|
|
|
// The tag of the trade bag carried by the PCs
|
|
|
|
const string TRADE_ITEM_BAG = "jw_tradit_bag";
|
|
|
|
// function to get the relevant TAG of the trade item
|
|
// nItem should be one of the TRADE_ITEM constants
|
|
string GetTradeItemTag(int nItem);
|
|
|
|
// function to get the relevant NAME of the trade item
|
|
// nItem should be one of the TRADE_ITEM constants
|
|
string GetTradeItemName(int nItem);
|
|
|
|
|
|
// Will return TRADE_SUPPLY_SELLS, TRADE_SUPPLY_BUYS or TRADE_SUPPLY_NOTINTERESTED
|
|
// nSettlement is 1 for Settlement a, 2 for settlement b, 3 for settlement c and
|
|
// 4 for settlement d, and 5 for Brighthaven
|
|
// nItemType is one of the TRADE_ITEM constants
|
|
int GetSettlementBuysOrSells(int nSettlement, int nTradeItemType);
|
|
|
|
// This only needs to be done when the server first starts
|
|
void InitiateTradeMerchants();
|
|
|
|
// Will return the amount of stock this merchant has of the given item
|
|
// The localint should always be the same as the number saved in the database
|
|
// However we get this figure from a local int to avoid accessing the database
|
|
// nSettlement is 1 for Settlement a, 2 for settlement b, 3 for settlement c and
|
|
// 4 for settlement d, and 5 for Brighthaven
|
|
// nItemType is one of the TRADE_ITEM constants
|
|
int GetTradeMerchantStockLocalInt(int nSettlement, int nTradeItemType);
|
|
|
|
|
|
// Will set the amount of stock this merchant has of the given item
|
|
// Sets it BOTH to the database and to a local int
|
|
// The localint should always be the same as the number saved in the database
|
|
// nSettlement is 1 for Settlement a, 2 for settlement b, 3 for settlement c and
|
|
// 4 for settlement d, and 5 for Brighthaven
|
|
// nItemType is one of the TRADE_ITEM constants
|
|
// nAmount is the amount of stock
|
|
void SetTradeMerchantStock(int nSettlement, int nTradeItemType, int nAmount);
|
|
|
|
// Goes through all the trade merchants and randomly fiddles with their stock
|
|
void UpdateTradeMerchants();
|
|
|
|
// Looks up how much of item nTradeItemType the settlement has and generates the
|
|
// correct price for how much the settlement SELLS the goods for
|
|
// nSettlement is 1 for Settlement a, 2 for settlement b, 3 for settlement c and
|
|
// 4 for settlement d, and 5 for Brighthaven
|
|
// nItemType is one of the TRADE_ITEM constants
|
|
int GetCurrentTradeItemSalePrice(int nSettlement, int nTradeItemType);
|
|
|
|
|
|
// Looks up how much of item nTradeItemType the settlement has and generates the
|
|
// correct price for how much the settlement BUYS the goods for
|
|
// nSettlement is 1 for Settlement a, 2 for settlement b, 3 for settlement c and
|
|
// 4 for settlement d, and 5 for Brighthaven
|
|
// nItemType is one of the TRADE_ITEM constants
|
|
int GetCurrentTradeItemBuyPrice(int nSettlement, int nTradeItemType);
|
|
|
|
// Gives or takes trade items to a PC's trade item bag
|
|
// Should be called when a PC sells or buys items or takes one out to use
|
|
// oPC is the PC in question
|
|
// nTradeItemType is one of the TRADE_ITEM constants
|
|
// nAmount is how many items
|
|
// Automatically changes the number of trade items carried and does stuff to his bag
|
|
// Will NOT spawn the item on the PC
|
|
void GiveOrTakeTradeItemsToPC(object oPC, int nTradeItemType, int nAmount);
|
|
|
|
// Returns how many trade items a PC carries in their trade item bag
|
|
int GetNumberOfTradeItemsCarried(object oPC);
|
|
|
|
// Change the number of trade items carried by the PC in their trade item bag
|
|
// nNumber is the CHANGE in the amount, not the total.
|
|
// nNumber CAN BE NEGATIVE to reduce the total
|
|
// The function automatically checks how many they currently have and adds nNumber to that
|
|
// The function automatically changes the weight of the bag
|
|
// The function automatically destroys the bag if the number reaches 0
|
|
// The function automatically creates the bag if the player doesn't have one
|
|
void ChangeNumberOfTradeItemsCarried(object oPC, int nNumber);
|
|
|
|
// Gets how many specific items a PC has
|
|
// nTradeItemType is one of the TRADE_ITEM constants
|
|
int GetNumberOfSpecificTradeItemsCarried(object oPC, int nTradeItemType);
|
|
|
|
// Takes trade items from the PCs bag and spawns them in his inventory
|
|
// This will also change the number of trade items in his bag
|
|
// nTradeItemType is one of the TRADE_ITEM constants
|
|
// nAmount is the number of items - default is 1
|
|
void PCTakesTradeItemsFromBag(object oPC, int nTradeItemType, int nAmount=1);
|
|
|
|
|
|
|
|
|
|
string GetTradeItemTag (int nItem)
|
|
{
|
|
string sString="Error in GetTradeItemTag function- please report to a DM";
|
|
|
|
switch (nItem)
|
|
{
|
|
case TRADE_ITEM_SILK: sString = "ctr0_xx_xx_xx_bc"; break;
|
|
case TRADE_ITEM_LINEN: sString = "ctr0_xx_xx_xx_bk"; break;
|
|
case TRADE_ITEM_CLOTH: sString = "ctr0_xx_xx_xx_bl"; break;
|
|
case TRADE_ITEM_IRON: sString = "ctr1_xx_xx_xx_aa"; break;
|
|
case TRADE_ITEM_STUDS: sString = "ctr0_xx_xx_xx_bm"; break;
|
|
case TRADE_ITEM_IRONRINGS: sString = "ctr0_xx_xx_xx_bt"; break;
|
|
case TRADE_ITEM_BOOTSOLE: sString = "ctr0_xx_xx_xx_b2"; break;
|
|
case TRADE_ITEM_BUCKLE: sString = "ctr0_xx_xx_xx_b3"; break;
|
|
case TRADE_ITEM_RINGMOLD: sString = "ctr1_xx_xx_xx_b4"; break;
|
|
case TRADE_ITEM_AMULETMOLD: sString = "ctr1_xx_xx_xx_b5"; break;
|
|
case TRADE_ITEM_BLANKSCROLL: sString = "jw_blank_scroll"; break;
|
|
case TRADE_ITEM_LIGHTCROSSMECH: sString = "ctr0_xx_xx_xx_bf"; break;
|
|
case TRADE_ITEM_HEAVYCROSSMECH: sString = "ctr0_xx_xx_xx_bg"; break;
|
|
case TRADE_ITEM_BOTTLES: sString = "ccr0_xx_xx_xx_b9"; break;
|
|
}
|
|
|
|
return sString;
|
|
}
|
|
|
|
|
|
|
|
string GetTradeItemName (int nItem)
|
|
{
|
|
string sString="Error in GetTradeItemName function- please report to a DM";
|
|
|
|
switch (nItem)
|
|
{
|
|
case TRADE_ITEM_SILK: sString = "Silk String"; break;
|
|
case TRADE_ITEM_LINEN: sString = "Linen Thread"; break;
|
|
case TRADE_ITEM_CLOTH: sString = "Bolt of Cloth"; break;
|
|
case TRADE_ITEM_IRON: sString = "Iron Ore"; break;
|
|
case TRADE_ITEM_STUDS: sString = "Iron Studs"; break;
|
|
case TRADE_ITEM_IRONRINGS: sString = "Iron Rings"; break;
|
|
case TRADE_ITEM_BOOTSOLE: sString = "Boot Sole"; break;
|
|
case TRADE_ITEM_BUCKLE: sString = "Belt Buckle"; break;
|
|
case TRADE_ITEM_RINGMOLD: sString = "Ring Mold"; break;
|
|
case TRADE_ITEM_AMULETMOLD: sString = "Amulet Mold"; break;
|
|
case TRADE_ITEM_BLANKSCROLL: sString = "Blank Scroll"; break;
|
|
case TRADE_ITEM_LIGHTCROSSMECH: sString = "Light Crossbow Mechanism"; break;
|
|
case TRADE_ITEM_HEAVYCROSSMECH: sString = "Heavy Crossbow Mechanism"; break;
|
|
case TRADE_ITEM_BOTTLES: sString = "Bottle"; break;
|
|
}
|
|
|
|
return sString;
|
|
}
|
|
|
|
|
|
int GetSettlementBuysOrSells (int nSettlement, int nTradeItemType)
|
|
{
|
|
int nBuysorSells = TRADE_SUPPLY_NOTINTERESTED;
|
|
|
|
// Settlement a - buys amulet mold and silk string
|
|
if (nSettlement==1)
|
|
{
|
|
switch (nTradeItemType)
|
|
{
|
|
case TRADE_ITEM_SILK: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_LINEN: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_CLOTH: nBuysorSells = TRADE_SUPPLY_SELLS; break;
|
|
case TRADE_ITEM_IRON: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_STUDS: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_IRONRINGS: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BOOTSOLE: nBuysorSells = TRADE_SUPPLY_SELLS; break;
|
|
case TRADE_ITEM_BUCKLE: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_RINGMOLD: nBuysorSells = TRADE_SUPPLY_SELLS; break;
|
|
case TRADE_ITEM_AMULETMOLD: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_BLANKSCROLL: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_LIGHTCROSSMECH: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_HEAVYCROSSMECH: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BOTTLES: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
}
|
|
}
|
|
else
|
|
// Settlement b - Doesn't buy
|
|
if (nSettlement==2)
|
|
{
|
|
switch (nTradeItemType)
|
|
{
|
|
case TRADE_ITEM_SILK: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_LINEN: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_CLOTH: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_IRON: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_STUDS: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_IRONRINGS: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BOOTSOLE: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BUCKLE: nBuysorSells = TRADE_SUPPLY_SELLS; break;
|
|
case TRADE_ITEM_RINGMOLD: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_AMULETMOLD: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BLANKSCROLL: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_LIGHTCROSSMECH: nBuysorSells = TRADE_SUPPLY_SELLS; break;
|
|
case TRADE_ITEM_HEAVYCROSSMECH: nBuysorSells = TRADE_SUPPLY_SELLS; break;
|
|
case TRADE_ITEM_BOTTLES: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
}
|
|
}
|
|
else
|
|
// Settlement c - buys ring molds and iron
|
|
if (nSettlement==3)
|
|
{
|
|
switch (nTradeItemType)
|
|
{
|
|
case TRADE_ITEM_SILK: nBuysorSells = TRADE_SUPPLY_SELLS; break;
|
|
case TRADE_ITEM_LINEN: nBuysorSells = TRADE_SUPPLY_SELLS; break;
|
|
case TRADE_ITEM_CLOTH: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_IRON: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_STUDS: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_IRONRINGS: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BOOTSOLE: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BUCKLE: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_RINGMOLD: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_AMULETMOLD: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BLANKSCROLL: nBuysorSells = TRADE_SUPPLY_SELLS; break;
|
|
case TRADE_ITEM_LIGHTCROSSMECH: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_HEAVYCROSSMECH: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BOTTLES: nBuysorSells = TRADE_SUPPLY_SELLS; break;
|
|
}
|
|
}
|
|
else
|
|
// Settlement d - buys bolts of cloth and blank scrolls
|
|
if (nSettlement==4)
|
|
{
|
|
switch (nTradeItemType)
|
|
{
|
|
case TRADE_ITEM_SILK: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_LINEN: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_CLOTH: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_IRON: nBuysorSells = TRADE_SUPPLY_SELLS; break;
|
|
case TRADE_ITEM_STUDS: nBuysorSells = TRADE_SUPPLY_SELLS; break;
|
|
case TRADE_ITEM_IRONRINGS: nBuysorSells = TRADE_SUPPLY_SELLS; break;
|
|
case TRADE_ITEM_BOOTSOLE: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BUCKLE: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_RINGMOLD: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_AMULETMOLD: nBuysorSells = TRADE_SUPPLY_SELLS; break;
|
|
case TRADE_ITEM_BLANKSCROLL: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_LIGHTCROSSMECH: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_HEAVYCROSSMECH: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BOTTLES: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
}
|
|
}
|
|
else
|
|
// Brighthaven 1 - buys half of stuff
|
|
if (nSettlement==5)
|
|
{
|
|
switch (nTradeItemType)
|
|
{
|
|
case TRADE_ITEM_SILK: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_LINEN: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_CLOTH: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_IRON: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_STUDS: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_IRONRINGS: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_BOOTSOLE: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_BUCKLE: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_RINGMOLD: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_AMULETMOLD: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BLANKSCROLL: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_LIGHTCROSSMECH: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_HEAVYCROSSMECH: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BOTTLES: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
}
|
|
}
|
|
|
|
else
|
|
// Brighthaven 2 - buys half of stuff
|
|
if (nSettlement==6)
|
|
{
|
|
switch (nTradeItemType)
|
|
{
|
|
case TRADE_ITEM_SILK: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_LINEN: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_CLOTH: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_IRON: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_STUDS: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_IRONRINGS: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BOOTSOLE: nBuysorSells = TRADE_SUPPLY_NOTINTERESTED; break;
|
|
case TRADE_ITEM_BUCKLE: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_RINGMOLD: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_AMULETMOLD: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_BLANKSCROLL: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_LIGHTCROSSMECH: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_HEAVYCROSSMECH: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
case TRADE_ITEM_BOTTLES: nBuysorSells = TRADE_SUPPLY_BUYS; break;
|
|
}
|
|
}
|
|
|
|
return nBuysorSells;
|
|
}
|
|
|
|
void InitiateTradeMerchants()
|
|
{
|
|
// We go through our five trade merchants to check their stock
|
|
// This is the only time we get the details from the database
|
|
|
|
|
|
int nSettlement;
|
|
int nTradeItemType;
|
|
int nNumber;
|
|
|
|
// Start by going through our five merchants
|
|
for (nSettlement=1; nSettlement<=TRADE_NUMBER_OF_MERCHANTS; nSettlement++)
|
|
{
|
|
// For each settlement, we go through our trade items
|
|
for (nTradeItemType=1; nTradeItemType<=TRADE_ITEMS_NUMBER; nTradeItemType++)
|
|
{
|
|
nNumber=GetCampaignInt("NEW_WORLD","tradestock_"+IntToString(nSettlement)+"_"+IntToString(nTradeItemType));
|
|
// Now we do some checks to see if this is the first time the module has run
|
|
if ((GetSettlementBuysOrSells (nSettlement,nTradeItemType) == TRADE_SUPPLY_SELLS)&&(nNumber<100))
|
|
{
|
|
// The settlement is supposed to sell this stuff but has little stock
|
|
nNumber=nNumber+Random(50);
|
|
|
|
}
|
|
else
|
|
if ((GetSettlementBuysOrSells (nSettlement,nTradeItemType) == TRADE_SUPPLY_SELLS)&&(nNumber<250))
|
|
{
|
|
// Stock may go up or down but most likely to go up
|
|
nNumber=nNumber+(Random(50)-20);
|
|
|
|
}
|
|
|
|
else
|
|
if ((GetSettlementBuysOrSells (nSettlement,nTradeItemType) == TRADE_SUPPLY_SELLS)&&(nNumber>=250))
|
|
{
|
|
// Stock may go up or down but most likely to go down
|
|
nNumber=nNumber+(Random(50)-30);
|
|
|
|
}
|
|
// this next section has the merchants possibly carry a small amount of goods they don't normally stock
|
|
// It has been removed for now
|
|
/*
|
|
if ((GetSettlementBuysOrSells (nSettlement,nTradeItemType) == TRADE_SUPPLY_NOTINTERESTED)&&(nNumber<50))
|
|
{
|
|
// The settlement might have a little bit of stock
|
|
if (d2()==1)
|
|
{
|
|
nNumber=nNumber+(Random(30)-15);
|
|
|
|
}
|
|
}
|
|
else
|
|
if ((GetSettlementBuysOrSells (nSettlement,nTradeItemType) == TRADE_SUPPLY_NOTINTERESTED)&&(nNumber>=50))
|
|
{
|
|
// The settlement has stock but isn't really meant to
|
|
nNumber=nNumber-(Random(20));
|
|
}
|
|
*/
|
|
// Replaced with this section just to keep the stock at 0
|
|
else
|
|
if (GetSettlementBuysOrSells (nSettlement,nTradeItemType) == TRADE_SUPPLY_NOTINTERESTED)
|
|
{
|
|
// The settlement has no stock
|
|
nNumber=0;
|
|
}
|
|
|
|
// Better just check we don't have a negative number
|
|
if (nNumber<0)
|
|
{
|
|
nNumber=0;
|
|
|
|
}
|
|
// Or too much
|
|
if (nNumber>400)
|
|
{
|
|
nNumber=400;
|
|
|
|
}
|
|
// So here we have the correct nNumber for this settlement and this type of product
|
|
SetTradeMerchantStock(nSettlement, nTradeItemType, nNumber);
|
|
}
|
|
// The next bracket moves us on to the next settlement
|
|
}
|
|
|
|
}
|
|
|
|
|
|
int GetTradeMerchantStockLocalInt(int nSettlement, int nTradeItemType)
|
|
{
|
|
return GetLocalInt(GetModule(),"tradestock_"+IntToString(nSettlement)+"_"+IntToString(nTradeItemType));
|
|
}
|
|
|
|
void SetTradeMerchantStock(int nSettlement, int nTradeItemType, int nAmount)
|
|
{
|
|
|
|
// First set it to the local int
|
|
SetLocalInt(GetModule(),"tradestock_"+IntToString(nSettlement)+"_"+IntToString(nTradeItemType), nAmount);
|
|
// Then save it to the database
|
|
SetCampaignInt("NEW_WORLD","tradestock_"+IntToString(nSettlement)+"_"+IntToString(nTradeItemType), nAmount);
|
|
}
|
|
|
|
void UpdateTradeMerchants()
|
|
{
|
|
|
|
// We go through our five trade merchants to check their stock
|
|
// And make changes if we want to
|
|
|
|
|
|
int nSettlement;
|
|
int nTradeItemType;
|
|
int nNumber;
|
|
int HasChanged;
|
|
|
|
// Start by going through our five merchants
|
|
for (nSettlement=1; nSettlement<=TRADE_NUMBER_OF_MERCHANTS; nSettlement++)
|
|
{
|
|
// For each settlement, we go through our trade items
|
|
for (nTradeItemType=1; nTradeItemType<=TRADE_ITEMS_NUMBER; nTradeItemType++)
|
|
{
|
|
HasChanged=0;
|
|
nNumber=GetTradeMerchantStockLocalInt(nSettlement,nTradeItemType);
|
|
// Now we do some checks to see if we feel like changing the amount of stock
|
|
if ((GetSettlementBuysOrSells (nSettlement,nTradeItemType) == TRADE_SUPPLY_SELLS)&&(nNumber<100)&&(d4()==1))
|
|
{
|
|
// The settlement is supposed to sell this stuff but has little stock
|
|
nNumber=nNumber+Random(50);
|
|
HasChanged=1;
|
|
}
|
|
else
|
|
if ((GetSettlementBuysOrSells (nSettlement,nTradeItemType) == TRADE_SUPPLY_SELLS)&&(nNumber<250)&&(d4()==1))
|
|
{
|
|
// Stock may go up or down but most likely to go up
|
|
nNumber=nNumber+(Random(50)-20);
|
|
HasChanged=1;
|
|
}
|
|
else
|
|
if ((GetSettlementBuysOrSells (nSettlement,nTradeItemType) == TRADE_SUPPLY_SELLS)&&(nNumber>=250)&&(d4()==1))
|
|
{
|
|
// Stock may go up or down but most likely to go down
|
|
nNumber=nNumber+(Random(50)-30);
|
|
HasChanged=1;
|
|
}
|
|
// this next section has the merchants possibly carry a small amount of goods they don't normally stock
|
|
// It has been removed for now
|
|
/*
|
|
else
|
|
if ((GetSettlementBuysOrSells (nSettlement,nTradeItemType) == TRADE_SUPPLY_NOTINTERESTED)&&(nNumber<50))
|
|
{
|
|
// The settlement might have a little bit of stock
|
|
if (d2()==1)
|
|
{
|
|
nNumber=nNumber+(Random(30)-15);
|
|
HasChanged=1;
|
|
}
|
|
}
|
|
else
|
|
if ((GetSettlementBuysOrSells (nSettlement,nTradeItemType) == TRADE_SUPPLY_NOTINTERESTED)&&(nNumber>=50))
|
|
{
|
|
// The settlement has stock but isn't really meant to
|
|
nNumber=nNumber-(Random(20));
|
|
HasChanged=1;
|
|
}
|
|
*/
|
|
|
|
else
|
|
if ((GetSettlementBuysOrSells (nSettlement,nTradeItemType) == TRADE_SUPPLY_BUYS)&&(nNumber>=200)&&(d4()==1))
|
|
{
|
|
// The settlement buys stock but has a lot in - someone must have sold it to them
|
|
// It will lose some
|
|
nNumber=nNumber-(Random(40)+1);
|
|
HasChanged=1;
|
|
}
|
|
else
|
|
if ((GetSettlementBuysOrSells (nSettlement,nTradeItemType) == TRADE_SUPPLY_BUYS)&&(nNumber>=100)&&(d4()==1))
|
|
{
|
|
// The settlement buys stock but has some in - someone must have sold it to them
|
|
// It will lose some
|
|
nNumber=nNumber-(Random(8)+1);
|
|
HasChanged=1;
|
|
}
|
|
else
|
|
if ((GetSettlementBuysOrSells (nSettlement,nTradeItemType) == TRADE_SUPPLY_BUYS)&&(nNumber>=1)&&(d4()==1))
|
|
{
|
|
// The settlement buys stock but has some in - someone must have sold it to them
|
|
// It will a small amount
|
|
nNumber=nNumber-(Random(3)+1);
|
|
HasChanged=1;
|
|
}
|
|
// Better just check we don't have a negative number
|
|
if (nNumber<0)
|
|
{
|
|
nNumber=0;
|
|
HasChanged=1;
|
|
}
|
|
// Or too much
|
|
if (nNumber>400)
|
|
{
|
|
nNumber=400;
|
|
HasChanged=1;
|
|
}
|
|
// So here we have the correct nNumber for this settlement and this type of product
|
|
if (HasChanged==1)
|
|
{
|
|
SetTradeMerchantStock(nSettlement, nTradeItemType, nNumber);
|
|
}
|
|
}
|
|
// The next bracket moves us on to the next settlement
|
|
}
|
|
|
|
}
|
|
|
|
int GetCurrentTradeItemSalePrice (int nSettlement, int nTradeItemType)
|
|
{
|
|
|
|
|
|
// Assumes the basic stock amount should be 200
|
|
// A high stock means a high price
|
|
|
|
int nAmount=GetTradeMerchantStockLocalInt(nSettlement, nTradeItemType);
|
|
float fAmount;
|
|
fAmount=IntToFloat(nAmount);
|
|
float fModifier;
|
|
|
|
if (fAmount>0.0)
|
|
{
|
|
fModifier=200/fAmount;
|
|
}
|
|
else
|
|
{
|
|
fModifier=5.0;
|
|
}
|
|
|
|
if (fModifier>5.0)
|
|
{
|
|
fModifier=5.0;
|
|
}
|
|
|
|
if (fModifier<0.1)
|
|
{
|
|
fModifier=0.1;
|
|
}
|
|
|
|
float fPrice=fModifier*(IntToFloat(CRAFT_ITEM_PRICE));
|
|
|
|
if (fPrice==0.0)
|
|
{
|
|
fPrice=0.1;
|
|
}
|
|
|
|
// This is the SALE price so we add a 20 per cent mark up
|
|
fPrice=fPrice*1.20;
|
|
|
|
|
|
|
|
int nPrice=FloatToInt(fPrice);
|
|
|
|
if (nPrice<1)
|
|
{
|
|
nPrice=1;
|
|
}
|
|
|
|
return nPrice;
|
|
}
|
|
|
|
int GetCurrentTradeItemBuyPrice (int nSettlement, int nTradeItemType)
|
|
{
|
|
|
|
|
|
// Assumes the basic stock amount should be 200
|
|
// A high stock means a high price
|
|
|
|
int nAmount=GetTradeMerchantStockLocalInt(nSettlement, nTradeItemType);
|
|
float fAmount;
|
|
fAmount=IntToFloat(nAmount);
|
|
float fModifier;
|
|
|
|
if (fAmount>0.0)
|
|
{
|
|
fModifier=200/fAmount;
|
|
}
|
|
else
|
|
{
|
|
fModifier=5.0;
|
|
}
|
|
|
|
if (fModifier>5.0)
|
|
{
|
|
fModifier=5.0;
|
|
}
|
|
|
|
if (fModifier<0.1)
|
|
{
|
|
fModifier=0.1;
|
|
}
|
|
|
|
float fPrice=fModifier*(IntToFloat(CRAFT_ITEM_PRICE));
|
|
|
|
if (fPrice==0.0)
|
|
{
|
|
fPrice=0.1;
|
|
}
|
|
|
|
// This is the BUY price so we add a 20 per cent mark down
|
|
fPrice=fPrice*0.80;
|
|
|
|
int nPrice=FloatToInt(fPrice);
|
|
|
|
if (nPrice<1)
|
|
{
|
|
nPrice=1;
|
|
}
|
|
|
|
return nPrice;
|
|
}
|
|
|
|
int GetNumberOfTradeItemsCarried (object oPC)
|
|
{
|
|
object oBag=GetItemPossessedBy(oPC,TRADE_ITEM_BAG);
|
|
|
|
if (!GetIsObjectValid(oBag))
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int nNumber=GetLocalInt(oBag,"totalitems");
|
|
return nNumber;
|
|
}
|
|
|
|
// Change the number of trade items carried by the PC in their trade item bag
|
|
// nNumber is the CHANGE in the amount, not the total.
|
|
// nNumber CAN BE NEGATIVE to reduce the total
|
|
// The function automatically checks how many they currently have and adds nNumber to that
|
|
// The function automatically changes the weight of the bag
|
|
// The function automatically destroys the bag if the number reaches 0
|
|
void ChangeNumberOfTradeItemsCarried (object oPC, int nNumber)
|
|
{
|
|
object oBag=GetItemPossessedBy(oPC,TRADE_ITEM_BAG);
|
|
|
|
if ((!GetIsObjectValid(oBag))&&(nNumber>0))
|
|
{
|
|
// The PC has no bag and is getting items so we need to give him a bag
|
|
oBag=CreateItemOnObject(TRADE_ITEM_BAG,oPC);
|
|
}
|
|
else
|
|
if ((!GetIsObjectValid(oBag))&&(nNumber<=0))
|
|
{
|
|
// The PC has no bag and we are trying to
|
|
// take items from it. This must be an error
|
|
return;
|
|
}
|
|
// This gives us the current number of items in the bag
|
|
int nCurrentNumber=GetLocalInt(oBag,"totalitems");
|
|
// This gives us the new number of items in the bag
|
|
int nNewNumber=nCurrentNumber+nNumber;
|
|
|
|
|
|
if (nNewNumber<=0)
|
|
{
|
|
// We have taken the last item out of the bag
|
|
SetPlotFlag(oBag,FALSE);
|
|
DestroyObject(oBag);
|
|
}
|
|
|
|
// Set the weight
|
|
if ((nNewNumber>0)&&(nNewNumber<10))
|
|
{
|
|
IPSafeAddItemProperty(oBag,ItemPropertyWeightIncrease(IP_CONST_WEIGHTINCREASE_5_LBS),0.0,X2_IP_ADDPROP_POLICY_REPLACE_EXISTING,FALSE,TRUE);
|
|
}
|
|
else
|
|
if ((nNewNumber>=10)&&(nNewNumber<50))
|
|
{
|
|
IPSafeAddItemProperty(oBag,ItemPropertyWeightIncrease(IP_CONST_WEIGHTINCREASE_10_LBS),0.0,X2_IP_ADDPROP_POLICY_REPLACE_EXISTING,FALSE,TRUE);
|
|
}
|
|
else
|
|
if ((nNewNumber>=50)&&(nNewNumber<100))
|
|
{
|
|
IPSafeAddItemProperty(oBag,ItemPropertyWeightIncrease(IP_CONST_WEIGHTINCREASE_15_LBS),0.0,X2_IP_ADDPROP_POLICY_REPLACE_EXISTING,FALSE,TRUE);
|
|
}
|
|
else
|
|
if (nNewNumber>=150)
|
|
{
|
|
IPSafeAddItemProperty(oBag,ItemPropertyWeightIncrease(IP_CONST_WEIGHTINCREASE_30_LBS),0.0,X2_IP_ADDPROP_POLICY_REPLACE_EXISTING,FALSE,TRUE);
|
|
}
|
|
|
|
// Set the new number of items on the bag
|
|
SetLocalInt(oBag,"totalitems",nNewNumber);
|
|
}
|
|
|
|
void GiveOrTakeTradeItemsToPC (object oPC, int nTradeItemType, int nAmount)
|
|
{
|
|
// First of all, change the number of items they carry
|
|
// Should spawn a bag on them if needed
|
|
ChangeNumberOfTradeItemsCarried (oPC,nAmount);
|
|
|
|
object oBag=GetItemPossessedBy(oPC,TRADE_ITEM_BAG);
|
|
|
|
if (!GetIsObjectValid(oBag))
|
|
{
|
|
// The PC has zero items
|
|
return;
|
|
}
|
|
|
|
// Tells us how many items of this type the PC has
|
|
int nCurrentAmount=GetLocalInt(oBag,"tradeitems"+IntToString(nTradeItemType));
|
|
int nNewAmount=nCurrentAmount+nAmount;
|
|
|
|
// Set the number of items in the bag now
|
|
SetLocalInt(oBag,"tradeitems"+IntToString(nTradeItemType),nNewAmount);
|
|
}
|
|
|
|
int GetNumberOfSpecificTradeItemsCarried (object oPC, int nTradeItemType)
|
|
{
|
|
object oBag=GetItemPossessedBy(oPC,TRADE_ITEM_BAG);
|
|
|
|
if (!GetIsObjectValid(oBag))
|
|
{
|
|
// The PC has zero items
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return GetLocalInt(oBag,"tradeitems"+IntToString(nTradeItemType));
|
|
}
|
|
}
|
|
|
|
void PCTakesTradeItemsFromBag (object oPC, int nTradeItemType, int nAmount=1)
|
|
{
|
|
object oBag=GetItemPossessedBy(oPC,TRADE_ITEM_BAG);
|
|
int nCurrentAmount=GetNumberOfSpecificTradeItemsCarried(oPC,nTradeItemType);
|
|
if (nCurrentAmount<nAmount)
|
|
{
|
|
// PC is trying to take out more items than they have
|
|
SendMessageToPC(oPC,"You are trying to take "+IntToString(nAmount)+" "+GetTradeItemName(nTradeItemType)+"s from your trade item bag but you only have "+IntToString(nCurrentAmount)+".");
|
|
return;
|
|
}
|
|
|
|
if (nAmount==0)
|
|
{
|
|
// This should never happen
|
|
return;
|
|
}
|
|
|
|
// The CHANGE in the number in his bag is, of course, a negative number
|
|
int nAmountLost=0-nAmount;
|
|
// Does the relevant stuff to his bag
|
|
GiveOrTakeTradeItemsToPC(oPC,nTradeItemType,nAmountLost);
|
|
// Physically spawn the items on the PC
|
|
int nIdx;
|
|
for (nIdx=1; nIdx<=nAmount; nIdx++)
|
|
{
|
|
CreateItemOnObject(GetTradeItemTag(nTradeItemType),oPC,1);
|
|
}
|
|
}
|