Also, currently 'attack largest ship' is the only priority implemented - other menu items, such as automatic renaming and selective scoping, should be functional.
Code: Select all
* assign constants, i.e. values that are not expected to change
* page 8060 should be loaded by 'setup.Quinch.Laserpointer'
$rename.pattern.default = read text: page=8060 id=1411
$current.sector = [THIS]-> get sector
* class threat table, going from highest to lowest
$class.table = array alloc: size=0
append [M2] to array $class.table
append [M1] to array $class.table
append [M7] to array $class.table
append [M6] to array $class.table
append [M8] to array $class.table
append [M3] to array $class.table
append [M4] to array $class.table
append [M5] to array $class.table
append [TM] to array $class.table
append [TL] to array $class.table
append [TP] to array $class.table
append [TS] to array $class.table
append [Missile] to array $class.table
* \\\class threat table\\\
* first, pull up all the local variables and set defaults if needed
$rename = [THIS] -> get local variable : name='Quinch.Laserpointer.Menu.Rename'
if $rename == null
[THIS] -> set local variable : name='Quinch.Laserpointer.Menu.Rename' value = 'Rename.Unchanged'
$rename = [THIS] -> get local variable : name='Quinch.Laserpointer.Menu.Rename'
end
$rename.pattern = [THIS] -> get local variable : name='Quinch.Laserpointer.Menu.Rename.Pattern'
if $rename.pattern == null
[THIS] -> set local variable : name='Quinch.Laserpointer.Menu.Rename.Pattern' value = $rename.pattern.default
$rename.pattern = [THIS] -> get local variable : name='Quinch.Laserpointer.Menu.Rename.Pattern'
end
$priority = [THIS] -> get local variable : name='Quinch.Laserpointer.Menu.Priority'
if $priority == null
[THIS] -> set local variable : name='Quinch.Laserpointer.Menu.Priority' value = 'Priority.Class.Hi'
$priority = [THIS] -> get local variable : name='Quinch.Laserpointer.Menu.Priority'
end
$racial = [THIS] -> get local variable : name='Quinch.Laserpointer.Menu.Racial'
if $racial == null
[THIS] -> set local variable : name='Quinch.Laserpointer.Menu.Racial' value = 'Racial.Attack'
$priority = [THIS] -> get local variable : name='Quinch.Laserpointer.Menu.Racial'
end
*****************
* first thing to do is to rename the tower, if needed. This is done only once per task start, as it would be too resource-consuming to constantly update
* $s: Current sector
* $n: Nearest neighboring sector
* $g: Nearest gate
* $p: Target priority
if $rename == 'Rename.Change'
$new.name = $rename.pattern
* pull up wildcard information
$sector = [THIS] -> get sector
$gate = find gate: flags = [Find.Nearest], refobj = [THIS], max dist= 999999, refpos = null
$nearest.sector = $gate -> get gate destination: return sector=[TRUE]
* because string substitution doesn't work if the variable is a reference to an object, we need to force them into strings
$sector = $sector + ''
$gate = $gate + ''
$nearest.sector = $nearest.sector + ''
* set priority shorthand
if $priority == 'Priority.Class.Hi'
$priority.string = 'C+'
else if $priority == 'Priority.Class.Lo'
$priority.string = 'C-'
else if $priority == 'Priority.Shields.Hi'
$priority.string = 'S+'
else if $priority == 'Priority.Shields.Lo'
$priority.string = 'S-'
else if $priority == 'Priority.Weapons.Hi'
$priority.string = 'W+'
else if $priority == 'Priority.Weapons.Lo'
$priority.string = 'W-'
else if $priority == 'Priority.Proximity.Hi'
$priority.string = 'C+'
else if $priority == 'Priority.Proximity.Lo'
$priority.string = 'C-'
else if $priority == 'Priority.Shields.Hi'
$priority.string = 'S+'
else if $priority == 'Priority.Shields.Lo'
$priority.string = 'S-'
end
$new.name= substitute in string $new.name: pattern '$s' with $sector
$new.name = substitute in string $new.name: pattern '$n' with $nearest.sector
$new.name = substitute in string $new.name: pattern '$g' with $gate
$new.name = substitute in string $new.name: pattern '$p' with $priority.string
[THIS] -> set name to $new.name
end
while [TRUE]
* Get the engagement distance, i.e. the maximum range at which the lasertower will start appraising and engaging hostiles.
* This needs to be constantly refreshed, as pre-active towers have no equipped weapons
$equipped.laser = [THIS]-> get laser type in bay 0
$engagement.range = get range of laser $equipped.laser
* STANDBY MODE: Normally, the lasertower will only ping nearby ships every 5-6 seconds, since they spend most of their time idling
$find.flags = [Find.Enemy] | [Find.Multiple] | [Find.Nearest]
$find.ships = [Ship] | [Missile]
$enemies = find ship: sector=$current.sector class or type= $find.ships race=null flags=$find.flags refobj=[THIS] maxdist=$engagement.range maxnum=9999 refpos=null
$enemies.count = size of array $enemies
* ALERT MODE: If there are enemies in range, start responding immediately. Loop time goes down to 1-1.5 seconds and continues up to ten seconds after there are no more hostiles in range
if $enemies.count > 0
* enemies loop
$enemies.index = 0
while $enemies.index < $enemies.count
$enemy = $enemies[$enemies.index]
******************************
* first, check the racial variable in case the enemy belongs to a friendly race
if $racial == 'Racial.NoAttack'
* second, check the enemy race and player relations
$race = $enemy -> get owner race
$relation = [THIS] -> get relation to race $race
* if the race relation is not set to foe, ignore it and fall through to the next enemy
if $relation != [FOE]
gosub next.enemy:
end
* otherwise, proceed with target acquisition
end
******************************
* FORK: PRIORITY BY CLASS - DESCENDING
if $priority == 'Priority.Class.Hi'
* PRIORITY BY CLASS
$priority.rank = 999
* get the current enemy class
$class = $enemy -> get object class
* compare the enemy class against the current priority target
$current.rank = get index of $class in array $class.table offset=0
* if the current target has higher priority rank than previous one, assign it as priority
if $current.rank < $priority.rank
$priority.target = $enemy
end
end
* TO DO
next.enemy:
inc $enemies.index
end
* ///enemies check
= [THIS]-> call script '!fight.attack.object' : victim=$priority.target follow=[FALSE]
end
= wait randomly from 5000 to 6000 ms
end
return null