scope RoadSystem initializer Init
globals
private constant integer ROAD_ID = 'h000' // <- Rawcode of road.
private constant string CANT_BUILD = "No road in range."
endglobals
// Here you have to regitser all buildings which need a road in range.
private module init
private static method onInit takes nothing returns nothing
call Road.create('hhou', 140) // (buildingType, maximumRange)
call Road.create('hbar', 300)
endmethod
endmodule
// ======= END CONFIG ====== //
globals
private group g = CreateGroup()
private constant integer ORDER_STOP = 851972
endglobals
struct Road
private static key k
private static Table table = k
readonly integer orderId
readonly real offset
static method create takes integer order, real offSet returns thistype
local thistype this = allocate()
set table[order] = this
set this.orderId = order
set this.offset = offSet
return this
endmethod
static method operator [] takes integer i returns thistype
return table
endmethod
implement init
endstruct
private function Order takes nothing returns boolean
local unit u
local unit builder
local boolean b = true
if (Road[GetIssuedOrderId()] != 0) then
call GroupEnumUnitsInRange(g, GetOrderPointX(), GetOrderPointY(), Road[GetIssuedOrderId()].offset, null)
loop
set u = FirstOfGroup(g)
call GroupRemoveUnit(g, u)
exitwhen u == null
if (GetUnitTypeId(u) == ROAD_ID) then
set b = false
endif
endloop
if (b) then
set builder = GetTriggerUnit()
call PauseUnit(builder, true)
call IssueImmediateOrderById(builder, ORDER_STOP)
call PauseUnit(builder, false)
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 7, CANT_BUILD)
call StartSound(gg_snd_Warning) // <- Error Sound.
set builder = null
endif
endif
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
call TriggerAddCondition(t, Filter(function Order))
endfunction
endscope