function PickUnitAtLocMatching takes location pickloc, real margin, conditionfunc match returns unit
local group pickedgroup = GetUnitsInRangeOfLocMatching(margin,pickloc,match)
local unit pickedunit = FirstOfGroup(pickedgroup)
call DestroyGroup(pickedgroup)
return pickedunit
endfunction
function CheckNotNullUnit takes unit ParamUnit returns boolean
if ( not ( ParamUnit != null ) ) then
return false
endif
return true
endfunction
function GetWallIndex takes boolean north, boolean south, boolean east, boolean west returns integer
local integer index = 0
if (north==true) then
set index=index+8
endif
if (south==true) then
set index=index+4
endif
if (east==true) then
set index=index+2
endif
if (west==true) then
set index=index+1
endif
return index
endfunction
function FindWallIndex takes unit Wall returns integer
local integer index = 0
loop
exitwhen ((udg_WallType[index]==GetUnitTypeId(Wall)) or (index>15))
set index = index + 1
endloop
return index
endfunction
function IsUnitWall takes unit ParamUnit returns boolean
local integer i = 0
loop
exitwhen i>15
if ( ( GetUnitTypeId(ParamUnit) == udg_WallType[i] ) ) then
return true
endif
set i=i+1
endloop
return false
endfunction
function GetWallTypeId takes boolean north, boolean south, boolean east, boolean west returns integer
local integer index = GetWallIndex(north,south,east,west)
return udg_WallType[index]
endfunction
function IsConnectable takes unit Wall1, unit Wall2 returns boolean
// this is the wall's connectivity conditions, you can edit this function
// in this map, connection are only allowed between walls of the same player
if (GetOwningPlayer(Wall1)==GetOwningPlayer(Wall2)) then
return true
endif
return false
endfunction
function IsLinkedNorth takes unit Wall returns boolean
local integer index = FindWallIndex(Wall)
if (ModuloInteger(index,16)>=8) then
return true
else
return false
endif
endfunction
function IsLinkedSouth takes unit Wall returns boolean
local integer index = FindWallIndex(Wall)
if (ModuloInteger(index,8)>=4) then
return true
else
return false
endif
endfunction
function IsLinkedEast takes unit Wall returns boolean
local integer index = FindWallIndex(Wall)
if (ModuloInteger(index,4)>=2) then
return true
else
return false
endif
endfunction
function IsLinkedWest takes unit Wall returns boolean
local integer index = FindWallIndex(Wall)
if (ModuloInteger(index,2)>=1) then
return true
else
return false
endif
endfunction
Name | Type | is_array | initial_value |
WallSize | real | No | 0.00 |
WallType | unitcode | Yes | UnitTypeNull |
function Trig_Wall_entering_the_game_Conditions takes nothing returns boolean
return IsUnitWall(GetTriggerUnit())
endfunction
function Trig_Wall_entering_the_game_Matching takes nothing returns boolean
return IsUnitWall(GetFilterUnit())
endfunction
function Trig_Wall_entering_the_game_Actions takes nothing returns nothing
local integer TrigWallType
// init locations
local location triggerloc = GetUnitLoc(GetTriggerUnit())
local location northloc = OffsetLocation(triggerloc ,0,+udg_WallSize)
local location southloc = OffsetLocation(triggerloc ,0,-udg_WallSize)
local location eastloc = OffsetLocation(triggerloc ,+udg_WallSize,0)
local location westloc = OffsetLocation(triggerloc ,-udg_WallSize,0)
// init nearby units
local unit northunit = PickUnitAtLocMatching(northloc,10,Condition(function Trig_Wall_entering_the_game_Matching))
local unit southunit = PickUnitAtLocMatching(southloc,10,Condition(function Trig_Wall_entering_the_game_Matching))
local unit eastunit = PickUnitAtLocMatching(eastloc,10,Condition(function Trig_Wall_entering_the_game_Matching))
local unit westunit = PickUnitAtLocMatching(westloc,10,Condition(function Trig_Wall_entering_the_game_Matching))
// check connectivity between walls
if (not(IsConnectable(GetTriggerUnit(),northunit))) then
set northunit = null
endif
if (not(IsConnectable(GetTriggerUnit(),southunit))) then
set southunit = null
endif
if (not(IsConnectable(GetTriggerUnit(),eastunit))) then
set eastunit = null
endif
if (not(IsConnectable(GetTriggerUnit(),westunit))) then
set westunit = null
endif
// replace the triggering wall version
set TrigWallType = GetWallTypeId(CheckNotNullUnit(northunit),CheckNotNullUnit(southunit),CheckNotNullUnit(eastunit),CheckNotNullUnit(westunit))
if (GetUnitTypeId(GetTriggerUnit())!=TrigWallType) then
call ReplaceUnitBJ( GetTriggerUnit(), TrigWallType, bj_UNIT_STATE_METHOD_RELATIVE)
endif
// replace the nearby walls version
if (CheckNotNullUnit(northunit)) then
call ReplaceUnitBJ( northunit, GetWallTypeId(IsLinkedNorth(northunit),true,IsLinkedEast(northunit),IsLinkedWest(northunit)), bj_UNIT_STATE_METHOD_RELATIVE )
endif
if (CheckNotNullUnit(southunit)) then
call ReplaceUnitBJ( southunit, GetWallTypeId(true,IsLinkedSouth(southunit),IsLinkedEast(southunit),IsLinkedWest(southunit)), bj_UNIT_STATE_METHOD_RELATIVE )
endif
if (CheckNotNullUnit(eastunit)) then
call ReplaceUnitBJ( eastunit, GetWallTypeId(IsLinkedNorth(eastunit),IsLinkedSouth(eastunit),IsLinkedEast(eastunit),true), bj_UNIT_STATE_METHOD_RELATIVE )
endif
if (CheckNotNullUnit(westunit)) then
call ReplaceUnitBJ( westunit, GetWallTypeId(IsLinkedNorth(westunit),IsLinkedSouth(westunit),true,IsLinkedWest(westunit)), bj_UNIT_STATE_METHOD_RELATIVE )
endif
// free memory
call RemoveLocation(triggerloc)
call RemoveLocation(northloc)
call RemoveLocation(southloc)
call RemoveLocation(eastloc)
call RemoveLocation(westloc)
endfunction
//===========================================================================
function InitTrig_Wall_entering_the_game takes nothing returns nothing
set gg_trg_Wall_entering_the_game = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Wall_entering_the_game, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH )
call TriggerAddCondition( gg_trg_Wall_entering_the_game, Condition( function Trig_Wall_entering_the_game_Conditions ) )
call TriggerAddAction( gg_trg_Wall_entering_the_game, function Trig_Wall_entering_the_game_Actions )
endfunction
function Trig_Wall_leaving_the_game_Conditions takes nothing returns boolean
return IsUnitWall(GetTriggerUnit())
endfunction
function Trig_Wall_leaving_the_game_Matching takes nothing returns boolean
return IsUnitWall(GetFilterUnit())
endfunction
function Trig_Wall_leaving_the_game_Actions takes nothing returns nothing
// init locations
local location triggerloc = GetUnitLoc(GetTriggerUnit())
local location northloc = OffsetLocation(triggerloc ,0,+udg_WallSize)
local location southloc = OffsetLocation(triggerloc ,0,-udg_WallSize)
local location eastloc = OffsetLocation(triggerloc ,+udg_WallSize,0)
local location westloc = OffsetLocation(triggerloc ,-udg_WallSize,0)
//local unit northunit = PickUnitAtLoc
local unit northunit = PickUnitAtLocMatching(northloc,10,Condition(function Trig_Wall_leaving_the_game_Matching))
local unit southunit = PickUnitAtLocMatching(southloc,10,Condition(function Trig_Wall_leaving_the_game_Matching))
local unit eastunit = PickUnitAtLocMatching(eastloc,10,Condition(function Trig_Wall_leaving_the_game_Matching))
local unit westunit = PickUnitAtLocMatching(westloc,10,Condition(function Trig_Wall_leaving_the_game_Matching))
// check connectivity between walls
if (not(IsConnectable(GetTriggerUnit(),northunit))) then
set northunit = null
endif
if (not(IsConnectable(GetTriggerUnit(),southunit))) then
set southunit = null
endif
if (not(IsConnectable(GetTriggerUnit(),eastunit))) then
set eastunit = null
endif
if (not(IsConnectable(GetTriggerUnit(),westunit))) then
set westunit = null
endif
// replace the nearby walls version
if (CheckNotNullUnit(northunit)) then
call ReplaceUnitBJ( northunit, GetWallTypeId(IsLinkedNorth(northunit),false,IsLinkedEast(northunit),IsLinkedWest(northunit)), bj_UNIT_STATE_METHOD_RELATIVE )
endif
if (CheckNotNullUnit(southunit)) then
call ReplaceUnitBJ( southunit, GetWallTypeId(false,IsLinkedSouth(southunit),IsLinkedEast(southunit),IsLinkedWest(southunit)), bj_UNIT_STATE_METHOD_RELATIVE )
endif
if (CheckNotNullUnit(eastunit)) then
call ReplaceUnitBJ( eastunit, GetWallTypeId(IsLinkedNorth(eastunit),IsLinkedSouth(eastunit),IsLinkedEast(eastunit),false), bj_UNIT_STATE_METHOD_RELATIVE )
endif
if (CheckNotNullUnit(westunit)) then
call ReplaceUnitBJ( westunit, GetWallTypeId(IsLinkedNorth(westunit),IsLinkedSouth(westunit),false,IsLinkedWest(westunit)), bj_UNIT_STATE_METHOD_RELATIVE )
endif
// free memory
call RemoveLocation(triggerloc)
call RemoveLocation(northloc)
call RemoveLocation(southloc)
call RemoveLocation(eastloc)
call RemoveLocation(westloc)
endfunction
//===========================================================================
function InitTrig_Wall_leaving_the_game takes nothing returns nothing
set gg_trg_Wall_leaving_the_game = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Wall_leaving_the_game, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_Wall_leaving_the_game, Condition( function Trig_Wall_leaving_the_game_Conditions ) )
call TriggerAddAction( gg_trg_Wall_leaving_the_game, function Trig_Wall_leaving_the_game_Actions )
endfunction