Created
November 8, 2012 16:05
-
-
Save hsyed/4039741 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
objectdef obj_Configuration_MiningLaserCycle | |
{ | |
variable string SetName = "MiningLaserCycle" | |
method Initialize() | |
{ | |
if !${BaseConfig.BaseRef.FindSet[${This.SetName}](exists)} | |
{ | |
UI:Update["obj_Configuration", " ${This.SetName} settings missing - initializing", "o"] | |
This:Set_Default_Values[] | |
} | |
UI:Update["obj_Configuration", " ${This.SetName}: Initialized", "-g"] | |
} | |
member:settingsetref CommonRef() | |
{ | |
return ${BaseConfig.BaseRef.FindSet[${This.SetName}]} | |
} | |
method Set_Default_Values() | |
{ | |
BaseConfig.BaseRef:AddSet[${This.SetName}] | |
;This.CommonRef:AddSetting[substring, "Undock"] | |
} | |
;Setting(string, substring, Setsubstring) | |
} | |
objectdef obj_MiningLaserCycle inherits obj_State | |
{ | |
variable obj_Configuration_MiningLaserCycle Config | |
variable set RegisteredActiveLasers | |
method Initialize() | |
{ | |
This[parent]:Initialize | |
;This.NonGameTiedPulse:Set[TRUE] | |
DynamicAddMiniMode("MiningLaserCycle", "MiningLaserCycle") | |
} | |
method Start() | |
{ | |
This:QueueState["MiningLaserCycle"] | |
} | |
method Stop() | |
{ | |
This:Clear | |
} | |
; remove \/ | |
member:bool IsAllreadyRegistered(obj_module target_module) | |
{ | |
variable iterator active_iterator | |
RegisteredActiveLasers:GetIterator[active_iterator] | |
if ${active_iterator:First(exists)} | |
{ | |
do | |
{ | |
if ${active_iterator.Value} == ${target_module} | |
{ | |
return TRUE | |
} | |
} | |
while ${active_iterator:Next(exists)} | |
} | |
return FALSE | |
} | |
member:bool DeactivateLaser(obj_Module module_to_deactivate) | |
{ | |
UI:Update["obj_MiningLaserCycle","entering deactivate method","-g"] | |
RegisteredActiveLasers:Remove[${module_to_deactivate}] | |
; ignore if laser no longer exists | |
; ignore if laser has been removed | |
; ignore if laser is allready off | |
return FALSE | |
} | |
member:bool MiningLaserCycle() | |
{ | |
if ${Ship.ModuleList_MiningLaser.ActiveCount} | |
{ | |
; common case : all lasers running all lasers registered | |
if ${Ship.ModuleList_MiningLaser.ActiveCount} == ${RegisteredActiveLasers.Used} | |
{ | |
UI:Update["obj_MiningLaserCycle","all lasers registered for deactivation ... leaving module","-g"] | |
return FALSE | |
} | |
; iterate over the list of mining lasers | |
variable iterator ml_iterator | |
Ship.ModuleList_MiningLaser:GetIterator[ml_iterator] | |
if ${ml_iterator:First(exists)} | |
{ | |
do | |
{ | |
; ignore a registered active laser | |
if ${RegisteredActiveLasers.Contains[${ml_iterator.Value}]} | |
{ | |
UI:Update["obj_MiningLaserCycle","laser allready registered for deactivation","-g"] | |
} | |
; register a deactive callback on a laser not allready registered | |
else | |
{ | |
UI:Update["obj_MiningLaserCycle","registering and queueing deactivation ${ml_iterator.Value} ${RegisteredActiveLasers.Used}","-g"] | |
RegisteredActiveLasers:Add[${ml_iterator.Value}] | |
; TODO -> ; deactivate laser in 45 miliseconds TODO: make configureable (currently 5 seconds} | |
This:QueueState["DeactivateLaser",5000, ${ml_iterator.Value}] | |
} | |
} | |
while ${ml_iterator:Next(exists)} | |
} | |
} | |
UI:Update["obj_MiningLaserCycle","leaving module","-g"] | |
return FALSE | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment