Name | Type | is_array | initial_value |
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
MOUNT SYSTEM v1.2 BY OXYGEND
Instruction:
--- Setting ---
MSAddUnit(unit id,unit dummy id) - register unit in system
MSAddMount(mount id, sit height) - register mount in system
--- Control ---
MountUnit(unit, target) - mount unit
UnMountUnit(unit) - unmount unit
This functions return true with success and false with fail.
P.S Write my nickname somewhere in credit if you will use this system:)
*/
library MountSys initializer InitSystem
globals
private constant integer Maxunit = 100
private constant real TIMER_PEREODIC = 0.025 // optimal
private constant boolean DEBUG_FLAG = false
endglobals
globals
// General
private timer UpTimer = CreateTimer()
private unit array MountedUnit [Maxunit]
private unit array UnitMounted [Maxunit]
private unit array InvisUnit [Maxunit]
private boolean array OnMOUNT [Maxunit]
private integer MaxUnit = 0
// For registration
integer NOW_MOUNTED = 0
integer REGISTRED_UNITS = 0
integer MOUNT_COUNT = 0
integer array GENERAL_ID [Maxunit]
integer array CLONE_ID [Maxunit]
integer array MOUNT_ID [Maxunit]
integer array MISSED_SLOT [Maxunit]
real array MOUNT_HIGHT [Maxunit]
endglobals
function MSAddUnit takes integer uid,integer cid returns nothing
set REGISTRED_UNITS = REGISTRED_UNITS + 1
set GENERAL_ID[REGISTRED_UNITS] = uid
set CLONE_ID[REGISTRED_UNITS] = cid
endfunction
function MSAddMount takes integer mid,real height returns nothing
set MOUNT_COUNT = MOUNT_COUNT + 1
set MOUNT_ID[MOUNT_COUNT] = mid
set MOUNT_HIGHT[MOUNT_COUNT] = height
endfunction
private function GetMountId takes integer m returns integer
local integer i=1
loop
exitwhen(i>MOUNT_COUNT)
if m == MOUNT_ID[i] then
return i
endif
set i = i + 1
endloop
return 0
endfunction
private function GetMountedUnitId takes unit u returns integer
local integer i = 1
loop
exitwhen(i>MaxUnit)
if u == InvisUnit[i] then
return i
endif
set i = i + 1
endloop
return 0
endfunction
private function GetMissSlot takes nothing returns integer
local integer i = 1
loop
exitwhen(i>MaxUnit)
if MISSED_SLOT[i]>0 then
return MISSED_SLOT[i]
endif
set i = i + 1
endloop
return 0
endfunction
function OnMount takes unit u returns boolean
return OnMOUNT[GetMountedUnitId(u)]
endfunction
function MountUnit takes unit u,unit t returns boolean
local integer id=GetPlayerId(GetOwningPlayer(u))
local integer i = 0
local integer j = 0
local integer ms
loop
exitwhen(i>REGISTRED_UNITS)
if GetUnitTypeId(u) == GENERAL_ID[i] and GetUnitTypeId(t) == MOUNT_ID[GetMountId(GetUnitTypeId(t))] then
loop
exitwhen(j > MaxUnit)
if t == UnitMounted[j] then
static if DEBUG_FLAG then
call BJDebugMsg("Mounted: fail(no place to mount)!")
endif
return false // fail
endif
set j = j + 1
endloop
set ms = GetMissSlot()
if ms != 0 then
set NOW_MOUNTED = NOW_MOUNTED + 1
set InvisUnit[ms] = u
call ShowUnit(u,false)
call SetUnitOwner(t,Player(id),false)
set MountedUnit[ms] = CreateUnit(Player(id),CLONE_ID[i],GetUnitX(t),GetUnitY(t),GetUnitFacing(t))
set UnitMounted[ms] = t
call UnitAddAbility(MountedUnit[ms],'Aave')
call UnitRemoveAbility(MountedUnit[ms],'Aave')
call UnitAddAbility(MountedUnit[ms],'Aloc')
call UnitRemoveAbility(MountedUnit[ms],'Aloc')
set OnMOUNT[ms] = true
set MISSED_SLOT[ms] = 0
else
set NOW_MOUNTED = NOW_MOUNTED + 1
set MaxUnit = MaxUnit + 1
set InvisUnit[MaxUnit] = u
call ShowUnit(u,false)
call SetUnitOwner(t,Player(id),false)
set MountedUnit[MaxUnit] = CreateUnit(Player(id),CLONE_ID[i],GetUnitX(t),GetUnitY(t),GetUnitFacing(t))
set UnitMounted[MaxUnit] = t
call UnitAddAbility(MountedUnit[MaxUnit],'Aave')
call UnitRemoveAbility(MountedUnit[MaxUnit],'Aave')
call UnitAddAbility(MountedUnit[MaxUnit],'Aloc')
call UnitRemoveAbility(MountedUnit[MaxUnit],'Aloc')
set OnMOUNT[MaxUnit] = true
set MISSED_SLOT[MaxUnit] = 0
endif
static if DEBUG_FLAG then
call BJDebugMsg("Mounted: success!")
endif
return true // success
endif
set i = i + 1
endloop
static if DEBUG_FLAG then
call BJDebugMsg("Mounted: fail(unregistred unit)!")
endif
return false // fail
endfunction
function UnMountUnit takes unit u returns boolean
local integer i=0
loop
exitwhen(i>MaxUnit)
if (u == MountedUnit[i]) or (u == InvisUnit[i]) or (u == UnitMounted[i]) then
set OnMOUNT[i] = false
set NOW_MOUNTED = NOW_MOUNTED - 1
call SetUnitFlyHeight(MountedUnit[i],0.0,300.0)
call SetUnitX(InvisUnit[i],GetUnitX(MountedUnit[i]))
call SetUnitY(InvisUnit[i],GetUnitY(MountedUnit[i]))
call SetUnitFacing(InvisUnit[i],GetUnitFacing(MountedUnit[i]))
call SetUnitOwner(UnitMounted[i],Player(15),false)
call RemoveUnit(MountedUnit[i])
call ShowUnit(InvisUnit[i],true)
set MountedUnit[i] = null
set UnitMounted[i] = null
set InvisUnit[i] = null
set MISSED_SLOT[i] = i
static if DEBUG_FLAG then
call BJDebugMsg("Unmounted: success!")
endif
return true // success
endif
set i = i + 1
endloop
static if DEBUG_FLAG then
call BJDebugMsg("Unmounted: fail!")
endif
return false // fail
endfunction
private function UnitPlusMaunt takes nothing returns nothing
local integer i=1
if NOW_MOUNTED > 0 then
loop
exitwhen(i>MaxUnit)
if OnMOUNT[i] then
call SetUnitFacing(MountedUnit[i],GetUnitFacing(UnitMounted[i]))
call SetUnitX(MountedUnit[i],GetUnitX(UnitMounted[i]))
call SetUnitY(MountedUnit[i],GetUnitY(UnitMounted[i]))
call SetUnitFlyHeight(MountedUnit[i],MOUNT_HIGHT[GetMountId(GetUnitTypeId(UnitMounted[i]))],0.0)
endif
set i = i + 1
endloop
endif
endfunction
private function InitSystem takes nothing returns nothing
call TimerStart(UpTimer,TIMER_PEREODIC,true,function UnitPlusMaunt)
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope Registration initializer Init
private function Init takes nothing returns nothing
call MSAddUnit('hrif','h000')
call MSAddUnit('hfoo','h001')
call MSAddMount('hmtt',70.0)
endfunction
endscope
//TESH.scrollpos=51
//TESH.alwaysfold=0
function GetPolarX takes real source, real dist, real angle returns real
local real a = source + dist * Cos(angle * bj_DEGTORAD)
return a
endfunction
function GetPolarY takes real source, real dist, real angle returns real
local real a = source + dist * Sin(angle * bj_DEGTORAD)
return a
endfunction
globals
real ALL_DIST = 0.00
unit array parad
integer nowparad = 0
integer from = 0
integer stage = 1
constant real CreateDist = 300.0
constant real MoveDist = 3000.0
constant integer ParadCount = 10
endglobals
function UnMountParad takes nothing returns nothing
local integer i = from
loop
exitwhen(i>ParadCount*stage)
if OnMount(parad[i]) == true then
call UnMountUnit(parad[i])
endif
set i = i + 1
endloop
set from = from + ParadCount
set stage = stage+1
endfunction
function Trig_Test_system_max_Actions takes nothing returns nothing
local integer i = 0
local unit u1
local unit u2
local timer t = CreateTimer()
local real orderx
local real ordery
local real createx
local real createy
call FogModifierStart(CreateFogModifierRect(Player(0), FOG_OF_WAR_VISIBLE,bj_mapInitialPlayableArea,true,false))
loop
exitwhen(i>ParadCount)
set createx = GetPolarX(-1000.0+(CreateDist*i),250,360.0)
set createy = GetPolarY(-3025.0+(CreateDist*i),250,360.0)
set u1=CreateUnit(Player(15),'hfoo',createx,createy,90.0)
set u2=CreateUnit(Player(15),'hmtt',createx,createy,90.0)
set parad[i+nowparad] = u1
call MountUnit(u1,u2)
set orderx = GetPolarX(GetUnitX(u2),MoveDist,90.0)
set ordery= GetPolarY(GetUnitY(u2),MoveDist,90.0)
call IssuePointOrder(u2,"move",orderx,ordery)
set i = i + 1
endloop
set nowparad=nowparad+ParadCount
set ALL_DIST = (SquareRoot((orderx - createx)*(orderx - createx) + (ordery -createy) * (ordery - createy))/400)
debug call BJDebugMsg("Parade time = "+R2S(ALL_DIST))
call TimerStart(t,ALL_DIST,false,function UnMountParad)
set t = null
set u1=null
set u2=null
endfunction
//===========================================================================
function InitTrig_Test_system_max takes nothing returns nothing
set gg_trg_Test_system_max = CreateTrigger( )
call TriggerRegisterPlayerEventEndCinematic( gg_trg_Test_system_max, Player(0) )
call TriggerAddAction( gg_trg_Test_system_max, function Trig_Test_system_max_Actions )
endfunction