library CarAccident
globals
private constant integer OFFSET = 0x100000 // DONT EDIT
endglobals
////////////////////////////////////////////////////
//////// HOW TO USE THIS SYSTEM IN GUI /////////////
////////////////////////////////////////////////////
//// ////
//// If there's a car, all you have to do is ////
//// use a Custom script to call this: ////
//// ////
//// -> call RegisterCar(udg_<yourunit>) ////
//// ////
////////////////////////////////////////////////////
////////////////////////////////////////////////////
////////////////////////////////////////////////////
private keyword Car // LOL
private function IsCar takes unit u returns boolean
return Car[u] != 0
endfunction
private function filter takes nothing returns boolean
return not IsCar(GetFilterUnit())
endfunction
private struct Car
unit car
static integer array index
static integer array trigindex
static method operator [] takes unit u returns thistype
return index[GetHandleId(u)-OFFSET]
endmethod
static method getData takes trigger t returns thistype
return trigindex[GetHandleId(t)-OFFSET]
endmethod
static method check takes nothing returns boolean
local thistype this = thistype.getData(GetTriggeringTrigger())
local unit u = GetTriggerUnit()
local real a = Atan2(GetUnitY(u)-GetUnitY(.car),GetUnitX(u)-GetUnitX(.car))
local real f = GetUnitFacing(.car)*bj_DEGTORAD
if a <= f + 1.0472 and a >= f - 1.0472 then
call KillUnit(u)
endif
call BJDebugMsg("Checking")
set u = null
return false
endmethod
static method create takes unit u returns thistype
local thistype this = thistype.allocate()
local trigger t = CreateTrigger()
set this.car = u
set index[GetHandleId(u)-OFFSET]=this
set trigindex[GetHandleId(t)-OFFSET]=this
call TriggerRegisterUnitInRange(t,u,175.0,function filter)
call TriggerAddCondition(t,Condition(function thistype.check))
call BJDebugMsg("Registered")
set t = null
return this
endmethod
method destroy takes nothing returns nothing
set this.car = null
call this.deallocate()
endmethod
endstruct
// Wrapper
function RegisterCar takes unit u returns nothing
local Car c = Car.create(u)
endfunction
endlibrary