private struct s_OrbSys
private unit planet
private unit array sat [SLOT]
private real array a [SLOT]
private real array d [SLOT]
private real angle = 0.00
method preventBuilding takes unit sat returns nothing
local integer i = 0
local player owner = GetOwningPlayer(sat)
call RemoveUnit(sat)
loop
set i = i + 1
exitwhen i > CostMax
if GetUnitTypeId(sat)== CostUnitId[i] then
call DisplayTextToPlayer(owner, 0, 0, C)
call ErrorSound(owner)
call SetResource(owner,CostGold[i],CostLumber[i])
set owner = null
return
endif
endloop
set owner = null
endmethod
method linkSat takes unit sat returns nothing
local integer i = 0
local real x = 0.
local real y = 0.
//Refresh: dead sat are cancelled
loop
exitwhen i > SLOT-1
if GetUnitState(.sat[i], UNIT_STATE_LIFE) <= 0 then
set .sat[i] = null
endif
set i = i + 1
endloop
//Seting the new satellite
set i = 0
loop
exitwhen i > SLOT-1
if .sat[i] == null and i <= 13 then
set .sat[i] = sat
call SetUnitPathing(sat,false)
set x = GetUnitX(.planet)+.d[i]*Cos(.a[i]*bj_DEGTORAD)
set y = GetUnitY(.planet)+.d[i]*Sin(.a[i]*bj_DEGTORAD)
call SetUnitPosition(sat,x,y)
return
endif
set i = i + 1
endloop
call .preventBuilding(sat)
endmethod
method setPlanetProperties takes nothing returns nothing
local integer i = 0
loop
exitwhen i > SLOT
if i <=5 then
set .a[i]= 60.00*i
set .d[i] = 100.
endif
if i >5 and i <= 13 then
set .a[i]= 45.00*i
set .d[i] = 162.5
endif
set i = i + 1
endloop
endmethod
method destroy takes nothing returns nothing
local integer i = 0
loop
exitwhen i > SLOT - 1
call KillUnit(.sat[i])
set .sat[i] = null
set i = i + 1
endloop
set .planet = null
endmethod
//Constructor
static method create takes unit planet returns s_OrbSys
local s_OrbSys this = s_OrbSys.allocate()
set this.planet = planet
return this
endmethod
endstruct
function OrbSys takes unit planet returns s_OrbSys
if( planet==null )then
return 0
endif
if( not TABLE.exists(planet) )then
set TABLE[planet] = s_OrbSys.create(planet)
endif
return s_OrbSys(TABLE[planet])
endfunction
private function AddPirateBase takes nothing returns boolean
if GetUnitTypeId(GetConstructedStructure()) == PIRATEBASE then
call OrbSys(GetConstructedStructure()).setPlanetProperties()
endif
return false
endfunction
private function AddPlanet takes nothing returns boolean
if IsUnitType(GetTriggerUnit(), UNIT_TYPE_ANCIENT) == true then
call OrbSys(GetTriggerUnit()).setPlanetProperties()
endif
return false
endfunction
private function DeathPlanet takes nothing returns boolean
if IsUnitType(GetTriggerUnit(), UNIT_TYPE_ANCIENT) == true then
call OrbSys(GetTriggerUnit()).destroy()
endif
return false
endfunction
private function AddSat takes nothing returns boolean
if IsUnitType(GetTrainedUnit(), UNIT_TYPE_MECHANICAL) == true and IsUnitType(GetTriggerUnit(), UNIT_TYPE_ANCIENT) == true then
call OrbSys(GetTriggerUnit()).linkSat(GetTrainedUnit())
endif
return false
endfunction
private function init takes nothing returns nothing
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
local trigger t3 = CreateTrigger()
local trigger t4 = CreateTrigger()
set TABLE = HandleTable.create()
call TriggerRegisterAnyUnitEventBJ(t1, EVENT_PLAYER_UNIT_TRAIN_FINISH )
call TriggerAddCondition(t1, Condition(function AddSat))
call TriggerRegisterAnyUnitEventBJ(t2, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition(t2, Condition(function DeathPlanet))
call TriggerRegisterEnterRectSimple(t3, bj_mapInitialPlayableArea)
call TriggerAddCondition( t3, Condition( function AddPlanet ) )
call TriggerRegisterAnyUnitEventBJ(t4, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH )
call TriggerAddCondition(t4, Condition(function AddPirateBase))
endfunction
Page 1 sur 1 La question posée dans ce topic a été résolue !
Vous ne pouvez pas poster de nouveaux sujets dans ce forum Vous ne pouvez pas répondre aux sujets dans ce forum Vous ne pouvez pas éditer vos messages dans ce forum Vous ne pouvez pas supprimer vos messages dans ce forum Vous ne pouvez pas voter dans les sondages de ce forum