//============================================================================================================
//
// For more JASS scripts, visit us at http://www.wc3JASS.com
//
//============================================================================================================
function GetRandomPathableLoc takes rect R, integer MaxAttempts returns location
local location L
local integer Index = 0
if MaxAttempts < 1 then
set MaxAttempts = 50
endif
loop
exitwhen Index >= MaxAttempts
set L = GetRandomLocInRect(R)
if IsLocPathable(L) then
return L
endif
set Index = Index + 1
endloop
return Location(0,0)
endfunction
function IsTempShop takes nothing returns boolean
return GetUnitTypeId(GetSellingUnit()) == 'nshf'
endfunction
function RemoveTempShop takes nothing returns nothing
call RemoveUnit(GetSellingUnit())
call RemoveUnit(GetSoldUnit())
call DestroyTrigger(GetTriggeringTrigger())
endfunction
function GetUnitGoldCostById takes integer Uid returns integer
local string Temp = DebugIdInteger2IdString(Uid)
local trigger Dispose = CreateTrigger()
local integer Val = GetPlayerState(Player(15),PLAYER_STATE_RESOURCE_GOLD)
local integer ValB = GetPlayerState(Player(15),PLAYER_STATE_RESOURCE_LUMBER)
local integer Cap = GetPlayerState(Player(15),PLAYER_STATE_RESOURCE_FOOD_CAP)
local integer Diff
local unit U
set Temp = SubStringBJ(Temp,1,1)
if Temp == "E" or Temp == "U" or Temp == "O" or Temp == "H" then
return 425
endif
set U = CreateUnitAtLoc(Player(15),'nshf',GetRandomPathableLoc(GetPlayableMapRect(),1000),bj_UNIT_FACING)
call AdjustPlayerStateBJ(50000,Player(15),PLAYER_STATE_RESOURCE_GOLD)
call AdjustPlayerStateBJ(50000,Player(15),PLAYER_STATE_RESOURCE_LUMBER)
call SetPlayerState(Player(15),PLAYER_STATE_RESOURCE_FOOD_CAP,200)
set Diff = GetPlayerState(Player(15),PLAYER_STATE_RESOURCE_GOLD)
call TriggerRegisterAnyUnitEventBJ(Dispose,EVENT_PLAYER_UNIT_SELL)
call TriggerAddCondition(Dispose,Condition(function IsTempShop))
call TriggerAddAction(Dispose,function RemoveTempShop)
call UnitAddAbilityBJ('Asud',U)
call AddUnitToStockBJ(Uid,U,1,1)
call IssueTrainOrderByIdBJ(U,Uid)
set Diff = Diff - GetPlayerState(Player(15),PLAYER_STATE_RESOURCE_GOLD)
call SetPlayerState(Player(15),PLAYER_STATE_RESOURCE_GOLD,Val)
call SetPlayerState(Player(15),PLAYER_STATE_RESOURCE_LUMBER,ValB)
call SetPlayerState(Player(15),PLAYER_STATE_RESOURCE_FOOD_CAP,Cap)
return Diff
endfunction