// Item / Unit Gold Lumber and Food Cost
// Version 1.0.1.0 by deathismyfriend
// Function List
//
// ITEM FUNCTIONS
//
//
// This function is for getting an items gold cost by using the item itself.
// function RCSGetItemGoldCost takes item itm returns integer
// To use this use the custom script below. ( You can Copy and Paste it.)
// Custom script: RCSGetItemGoldCost( udg_tempItem)
//
//
// This function is for getting an items lumber cost by using the item itself.
// function RCSGetItemLumberCost takes item itm returns integer
// To use this use the custom script below. ( You can Copy and Paste it.)
// Custom script: RCSGetItemLumberCost( udg_tempItem)
//
//
// This function is for getting an items food cost by using the item itself.
// function RCSGetItemFoodCost takes item itm returns integer
// To use this use the custom script below. ( You can Copy and Paste it.)
// Custom script: RCSGetItemFoodCost( udg_tempItem)
//
//
// This function is for getting an items food cap cost by using the item itself.
// function RCSGetItemFoodCap takes item itm returns integer
// To use this use the custom script below. ( You can Copy and Paste it.)
// Custom script: RCSGetItemFoodCap( udg_tempItem)
//
//
// This function is for getting an items initial charges.
// The initial charges are the charges it starts with when the item is created.
// function RCSGetItemInitialCharges takes item itm returns integer
// To use this use the custom script below. ( You can Copy and Paste it.)
// Custom script: RCSGetItemInitialCharges( udg_tempItem)
//
// UNIT FUNCTIONS
//
//
// This function is for getting a units gold cost by using the unit itself.
// function RCSGetUnitGoldCost takes unit u returns integer
// To use this use the custom script below. ( You can Copy and Paste it.)
// Custom script: RCSGetUnitGoldCost( udg_tempUnit)
//
//
// This function is for getting a units gold cost by using the units type id.
// function RCSGetUnitGoldCostById takes integer id returns integer
// To use this use the custom script below. ( You can Copy and Paste it.)
// Custom script: RCSGetUnitGoldCostById( udg_tempUnitType)
//
//
// This function is for getting a units lumber cost by using the unit itself.
// function RCSGetUnitLumberCost takes unit u returns integer
// To use this use the custom script below. ( You can Copy and Paste it.)
// Custom script: RCSGetUnitLumberCost( udg_tempUnit)
//
//
// This function is for getting a units lumber cost by using the units type id.
// function RCSGetUnitLumberCostById takes integer id returns integer
// To use this use the custom script below. ( You can Copy and Paste it.)
// Custom script: RCSGetUnitLumberCostById( udg_tempUnitType)
//
//
// This function is for getting a units food cost by using the unit itself.
// function RCSGetUnitFoodCosttakes unit u returns integer
// To use this use the custom script below. ( You can Copy and Paste it.)
// Custom script: RCSGetUnitFoodCost( udg_tempUnit)
//
//
// This function is for getting a units food cost by using the units type id.
// function RCSGetUnitFoodCostById takes integer id returns integer
// To use this use the custom script below. ( You can Copy and Paste it.)
// Custom script: RCSGetUnitFoodCostById( udg_tempUnitType)
//
//
// This function is for getting a units food cap by using the unit itself.
// function RCSGetUnitFoodCap takes unit u returns integer
// To use this use the custom script below. ( You can Copy and Paste it.)
// Custom script: RCSGetUnitFoodCap( udg_tempUnit)
//
//
// This function is for getting a units food cap by using the units type id.
// function RCSGetUnitFoodCapById takes integer id returns integer
// To use this use the custom script below. ( You can Copy and Paste it.)
// Custom script: RCSGetUnitFoodCapById( udg_tempUnitType)
//
//
function RCSItemAUnitGALCleanupItems takes nothing returns nothing // This cleans up the items sold to get the prices.
call RemoveItem( GetEnumItem())
endfunction
function RCSStoreItemCosts takes integer id returns nothing
local player p = Player(PLAYER_NEUTRAL_PASSIVE)
local integer playerG = GetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD)
local integer playerL = GetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER)
local integer playerFC = GetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_CAP)
local integer playerFU = GetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_USED)
local integer foodCap
local item itm = CreateItem( id, udg_RCSItemAUnitGALSpawnX, udg_RCSItemAUnitGALSpawnY)
local integer charges = GetItemCharges(itm)
call RemoveItem(itm)
set itm = null
call RCSItemAUnitGALPauseSystems()
call SetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD, 1000000)
call SetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER, 1000000)
call SetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_CAP, udg_RCSItemAUnitGALFoodCapMax)
call SetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_USED, 0)
call AddItemToStock( udg_RCSItemAUnitGALMerchant, id, 1, 1)
call IssueNeutralImmediateOrderById( p, udg_RCSItemAUnitGALMerchant, id)
call RemoveItemFromStock( udg_RCSItemAUnitGALMerchant, id)
set foodCap = GetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_CAP) - udg_RCSItemAUnitGALFoodCapMax
set id = id * -1
call SaveInteger( udg_RCSHashtable, 0, id, ( 1000000 - GetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD)) / charges)
call SaveInteger( udg_RCSHashtable, 1, id, ( 1000000 - GetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER)) / charges)
call SaveInteger( udg_RCSHashtable, 2, id, ( GetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_USED)) / charges)
call SaveInteger( udg_RCSHashtable, 3, id, foodCap / charges)
call SaveInteger( udg_RCSHashtable, 4, id, charges)
call SetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD, playerG)
call SetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER, playerL)
call SetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_CAP, playerFC + foodCap)
call SetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_USED, playerFU)
call EnumItemsInRect( udg_RCSItemAUnitGALRegionSpawn , null, function RCSItemAUnitGALCleanupItems)
call RCSItemAUnitGALUnPauseSystems()
set p = null
endfunction
function RCSStoreUnitCosts takes integer id returns nothing
local player p = Player(PLAYER_NEUTRAL_PASSIVE)
local integer playerG = GetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD)
local integer playerL = GetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER)
local integer playerFC = GetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_CAP)
local integer playerFU = GetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_USED)
local integer foodCap
call RCSItemAUnitGALPauseSystems()
call SetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD, 1000000)
call SetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER, 1000000)
call SetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_CAP, udg_RCSItemAUnitGALFoodCapMax)
call SetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_USED, 0)
call AddUnitToStock( udg_RCSItemAUnitGALMerchant, id, 1, 1)
call IssueNeutralImmediateOrderById( p, udg_RCSItemAUnitGALMerchant, id)
call RemoveUnitFromStock( udg_RCSItemAUnitGALMerchant, id)
set foodCap = GetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_CAP) - udg_RCSItemAUnitGALFoodCapMax
set id = id * -1
call SaveInteger( udg_RCSHashtable, 0, id, 1000000 - GetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD))
call SaveInteger( udg_RCSHashtable, 1, id, 1000000 - GetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER))
call SaveInteger( udg_RCSHashtable, 2, id, GetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_USED))
call SaveInteger( udg_RCSHashtable, 3, id, foodCap)
call SetPlayerState( p, PLAYER_STATE_RESOURCE_GOLD, playerG)
call SetPlayerState( p, PLAYER_STATE_RESOURCE_LUMBER, playerL)
call SetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_CAP, playerFC + foodCap)
call SetPlayerState( p, PLAYER_STATE_RESOURCE_FOOD_USED, playerFU)
call RCSItemAUnitGALUnPauseSystems()
set p = null
endfunction
function RCSGetItemGoldCostById takes item itm, integer id returns integer
local integer charges = GetItemCharges(itm)
if not HaveSavedInteger( udg_RCSHashtable, 0, id * -1) then
call RCSStoreItemCosts( id)
endif
if charges > 0 then
return LoadInteger( udg_RCSHashtable, 0, id * -1) * charges
endif
return LoadInteger( udg_RCSHashtable, 0, id * -1)
endfunction
function RCSGetItemLumberCostById takes item itm, integer id returns integer
local integer charges = GetItemCharges(itm)
if not HaveSavedInteger( udg_RCSHashtable, 1, id * -1) then
call RCSStoreItemCosts( id)
endif
if charges > 0 then
return LoadInteger( udg_RCSHashtable, 1, id * -1) * charges
endif
return LoadInteger( udg_RCSHashtable, 1, id * -1)
endfunction
function RCSGetItemFoodCostById takes item itm, integer id returns integer
local integer charges = GetItemCharges(itm)
if not HaveSavedInteger( udg_RCSHashtable, 2, id * -1) then
call RCSStoreItemCosts( id)
endif
if charges > 0 then
return LoadInteger( udg_RCSHashtable, 2, id * -1) * charges
endif
return LoadInteger( udg_RCSHashtable, 2, id * -1)
endfunction
function RCSGetItemFoodCapById takes item itm, integer id returns integer
local integer charges = GetItemCharges(itm)
if not HaveSavedInteger( udg_RCSHashtable, 3, id * -1) then
call RCSStoreItemCosts( id)
endif
if charges > 0 then
return LoadInteger( udg_RCSHashtable, 3, id * -1) * charges
endif
return LoadInteger( udg_RCSHashtable, 3, id * -1)
endfunction
function RCSGetItemInitialChargesById takes item itm, integer id returns integer
local integer charges = GetItemCharges(itm)
if not HaveSavedInteger( udg_RCSHashtable, 4, id * -1) then
call RCSStoreItemCosts( id)
endif
if charges > 0 then
return LoadInteger( udg_RCSHashtable, 4, id * -1) * charges
endif
return LoadInteger( udg_RCSHashtable, 4, id * -1)
endfunction
function RCSGetItemGoldCost takes item itm returns integer
return RCSGetItemGoldCostById( itm, GetItemTypeId( itm))
endfunction
function RCSGetItemLumberCost takes item itm returns integer
return RCSGetItemLumberCostById( itm, GetItemTypeId( itm))
endfunction
function RCSGetItemFoodCost takes item itm returns integer
return RCSGetItemFoodCostById( itm, GetItemTypeId( itm))
endfunction
function RCSGetItemFoodCap takes item itm returns integer
return RCSGetItemFoodCapById( itm, GetItemTypeId( itm))
endfunction
function RCSGetItemInitialCharges takes item itm returns integer
return RCSGetItemInitialChargesById( itm, GetItemTypeId( itm))
endfunction
function RCSGetUnitGoldCostById takes integer id returns integer
if not HaveSavedInteger( udg_RCSHashtable, 0, id * -1) then
call RCSStoreUnitCosts(id)
endif
return LoadInteger( udg_RCSHashtable, 0, id * -1)
endfunction
function RCSGetUnitLumberCostById takes integer id returns integer
if not HaveSavedInteger( udg_RCSHashtable, 1, id * -1) then
call RCSStoreUnitCosts(id)
endif
return LoadInteger( udg_RCSHashtable, 1, id * -1)
endfunction
function RCSGetUnitFoodCostById takes integer id returns integer
if not HaveSavedInteger( udg_RCSHashtable, 2, id * -1) then
call RCSStoreUnitCosts(id)
endif
return LoadInteger( udg_RCSHashtable, 2, id * -1)
endfunction
function RCSGetUnitFoodCapById takes integer id returns integer
if not HaveSavedInteger( udg_RCSHashtable, 3, id * -1) then
call RCSStoreUnitCosts(id)
endif
return LoadInteger( udg_RCSHashtable, 3, id * -1)
endfunction
function RCSGetUnitGoldCost takes unit u returns integer
return RCSGetUnitGoldCostById( GetUnitTypeId( u))
endfunction
function RCSGetUnitLumberCost takes unit u returns integer
return RCSGetUnitLumberCostById( GetUnitTypeId( u))
endfunction
function RCSGetUnitFoodCost takes unit u returns integer
return RCSGetUnitFoodCostById( GetUnitTypeId( u))
endfunction
function RCSGetUnitFoodCap takes unit u returns integer
return RCSGetUnitFoodCapById( GetUnitTypeId( u))
endfunction
function RCSCheckForUnitPrice takes integer id returns boolean // This stops the system from registering the same units.
// This also stops the system from infinite looping.
if not HaveSavedInteger( udg_RCSHashtable, 0, id * -1) and GetTriggerUnit() != udg_RCSItemAUnitGALMerchant then
call RCSStoreUnitCosts( id)
endif
return false
endfunction
function RCSGetTrainedUnitType takes nothing returns boolean // This gets the unit being trained.
return RCSCheckForUnitPrice( GetTrainedUnitType())
endfunction
function RCSGetSoldUnitType takes nothing returns boolean // This is for the sold unit.
return RCSCheckForUnitPrice( GetUnitTypeId( GetSoldUnit()))
endfunction
function RCSGetConstructUnitType takes nothing returns boolean // This is for getting the constructing structure.
return RCSCheckForUnitPrice( GetUnitTypeId( GetConstructingStructure()))
endfunction
function RCSGetUpgradeUnitType takes nothing returns boolean // This is for upgrading unit.
return RCSCheckForUnitPrice( GetUnitTypeId( GetTriggerUnit()))
endfunction
function RCSCheckForItemPrice takes item itm, integer id returns boolean // This stops the system from registering the same items.
if not HaveSavedInteger( udg_RCSHashtable, 3, id * -1) and GetTriggerUnit() != udg_RCSItemAUnitGALMerchant then
call RCSStoreItemCosts( id)
endif
return false
endfunction
function RCSItemAUnitGALCleanupUnits takes nothing returns boolean // This cleans up the units sold to get the prices.
call RemoveUnit( GetSoldUnit())
return false
endfunction
function RCSGetPickedUpItemType takes nothing returns boolean
return RCSCheckForItemPrice( GetManipulatedItem(), GetItemTypeId( GetManipulatedItem()))
endfunction
function RCSItemAUnitGALRegisterSetup takes nothing returns nothing
call RCSItemAUnitGALRegisterRegion()
if udg_RCSHashtable == null then
set udg_RCSHashtable = InitHashtable()
endif
set udg_RCSItemAUnitGALSpawnX = GetRectCenterX( udg_RCSItemAUnitGALRegionSpawn)
set udg_RCSItemAUnitGALSpawnY = GetRectCenterY( udg_RCSItemAUnitGALRegionSpawn)
set udg_RCSItemAUnitGALFoodCapMax = GetPlayerState( Player(0), PLAYER_STATE_FOOD_CAP_CEILING)
set udg_RCSItemAUnitGALMerchant = CreateUnit( Player(0), udg_RCSItemAUnitGALMerchantId, udg_RCSItemAUnitGALSpawnX, udg_RCSItemAUnitGALSpawnY, 270)
call ShowUnit( udg_RCSItemAUnitGALMerchant, false)
endfunction
//===========================================================================
function InitTrig_ItemAndUnitGoldAndLumberCost takes nothing returns nothing
local integer L = 0
local player p
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
local trigger t3 = CreateTrigger()
local trigger t4 = CreateTrigger()
local trigger t5 = CreateTrigger()
local trigger t6 = CreateTrigger()
call RCSItemAUnitGALRegisterSetup()
call TriggerRegisterUnitEvent( t1, udg_RCSItemAUnitGALMerchant, EVENT_UNIT_SELL)
call TriggerAddCondition( t1, Condition( function RCSItemAUnitGALCleanupUnits))
loop
set p = Player( L)
call TriggerRegisterPlayerUnitEvent( t2, p, EVENT_PLAYER_UNIT_PICKUP_ITEM, null)
call TriggerRegisterPlayerUnitEvent( t3, p, EVENT_PLAYER_UNIT_TRAIN_START, null)
call TriggerRegisterPlayerUnitEvent( t4, p, EVENT_PLAYER_UNIT_SELL, null)
call TriggerRegisterPlayerUnitEvent( t5, p, EVENT_PLAYER_UNIT_CONSTRUCT_START, null)
call TriggerRegisterPlayerUnitEvent( t6, p, EVENT_PLAYER_UNIT_UPGRADE_START, null)
set L = L + 1
exitwhen L > 15
endloop
call TriggerAddCondition( t2, Condition( function RCSGetPickedUpItemType))
call TriggerAddCondition( t3, Condition( function RCSGetTrainedUnitType))
call TriggerAddCondition( t4, Condition( function RCSGetSoldUnitType))
call TriggerAddCondition( t5, Condition( function RCSGetConstructUnitType))
call TriggerAddCondition( t6, Condition( function RCSGetUpgradeUnitType))
set t1 = null
set t2 = null
set t3 = null
set t4 = null
set t5 = null
set t6 = null
set p = null
endfunction