// ************************************
// * RoofControl module by Shadow1500 *
// ************************************
// CONFIG
constant function Roof_GetFloorDestructables takes nothing returns string
return [B]"B003;B004;B005;B006;B007"[/B]
endfunction
constant function Roof_GetRoofDoodads takes nothing returns string
return [B]"D00A;D00B;D00C;D00N;D00Q;D00P;D00R;D00O"[/B]
endfunction
constant function Roof_GetRoofWindowDoodads takes nothing returns string
return [B]"D00A;D00B;D00C"[/B]
endfunction
constant function Roof_GetFloorWidth takes integer floorId returns real
return 64.0
endfunction
constant function Roof_GetFloorHeight takes integer floorId returns real
return 64.0
endfunction
function Roof_RoofVisibleAnim takes integer roofId returns string
local real time = GetFloatGameState(GAME_STATE_TIME_OF_DAY)
if (not IsItemInPool(bj_forLoopAIndex,roofId)) or (time>=6 and time<=18) then
return "Stand"
endif
return "Stand Alternate"
endfunction
constant function Roof_RoofHiddenAnim takes integer roofId returns string
return "Death"
endfunction
// FUNCS
function I2Region takes integer i returns region
return i
return null
endfunction
function I2Destructable takes integer i returns destructable
return i
return null
endfunction
function InitBuildingsRegionFilter takes nothing returns boolean
return IsItemInPool(bj_forLoopAIndex,GetDestructableTypeId(GetFilterDestructable()))
endfunction
function InitBuildingsRegionEnum takes nothing returns nothing
local destructable d = GetEnumDestructable()
local integer id = GetDestructableTypeId(d)
local real w = Roof_GetFloorWidth(id)
local real h = Roof_GetFloorHeight(id)
local real x = GetWidgetX(d)
local real y = GetWidgetY(d)
local rect r = Rect(x-w,y-h,x+w,y+h)
call RegionAddRect(I2Region(bj_forLoopBIndex),r)
call RemoveRect(r)
set r = null
set d = null
endfunction
function HideRoofs takes player p, boolean flag returns nothing
local integer roofPool = GetStoredInteger(CSCache(),"RoofControl","RoofObjects")
local integer x = 0
local integer len = CountItemsInPool(roofPool)
local integer id
call StoreBoolean(CSCache(),"RoofControl","isHidden_"+I2S(GetPlayerId(p)),flag)
set bj_forLoopAIndex = GetStoredInteger(CSCache(),"RoofControl","RoofWindows")
loop
exitwhen x>len
set id = PoolGetItem(roofPool,x)
if GetLocalPlayer()==p then
if flag then
call SetDoodadAnimationRect(bj_mapInitialPlayableArea,id,Roof_RoofHiddenAnim(id),false)
else
call SetDoodadAnimationRect(bj_mapInitialPlayableArea,id,Roof_RoofVisibleAnim(id),false)
endif
endif
set x = x + 1
endloop
endfunction
function Trig_RoofControl_Actions takes nothing returns nothing
call HideRoofs(GetOwningPlayer(GetTriggerUnit()),GetTriggerEventId()==EVENT_GAME_ENTER_REGION)
endfunction
function InitTrig_RoofControl takes nothing returns nothing
local region buildings = CreateRegion()
local boolexpr filter = Condition(function InitBuildingsRegionFilter)
set gg_trg_RoofControl = CreateTrigger()
set bj_forLoopAIndex = Rawcodes2Pool(Roof_GetFloorDestructables())
set bj_forLoopBIndex = CS_H2I(buildings)
call EnumDestructablesInRect(bj_mapInitialPlayableArea,filter,function InitBuildingsRegionEnum)
call DestroyBoolExpr(filter)
set filter = null
call TriggerRegisterEnterRegion(gg_trg_RoofControl,buildings,null)
call TriggerRegisterLeaveRegion(gg_trg_RoofControl,buildings,null)
call TriggerAddAction(gg_trg_RoofControl,function Trig_RoofControl_Actions)
call StoreInteger(CSCache(),"RoofControl","RoofWindows",Rawcodes2Pool(Roof_GetRoofWindowDoodads()))
call StoreInteger(CSCache(),"RoofControl","RoofObjects",Rawcodes2Pool(Roof_GetRoofDoodads()))
call HideRoofs(Player(0),true)
endfunction