aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/control.gd13
-rw-r--r--scripts/turret.gd35
2 files changed, 47 insertions, 1 deletions
diff --git a/scripts/control.gd b/scripts/control.gd
index ff2d8da..fafd3d8 100644
--- a/scripts/control.gd
+++ b/scripts/control.gd
@@ -79,6 +79,14 @@ func build_option (st, sttype):
opts += [ { "type": "text", "name": "back" } ]
Globals.StateType.TARGETING:
+ opts += [ { "type": "text", "name": "first" } ]
+ opts += [ { "type": "text", "name": "last" } ]
+ opts += [ { "type": "text", "name": "strongest" } ]
+ opts += [ { "type": "text", "name": "weakest" } ]
+ opts += [ { "type": "text", "name": "closest" } ]
+ opts += [ { "type": "text", "name": "furthest" } ]
+ opts += [ { "type": "text", "name": "least turning" } ]
+ opts += [ { "type": "text", "name": "most turning" } ]
opts += [ { "type": "text", "name": "back" } ]
Globals.StateType.MODULES:
@@ -225,6 +233,11 @@ func do (action, par = {}):
"back":
statetype = Globals.StateType.TURRET
build_option(state, statetype)
+ _:
+ statetype = Globals.StateType.TURRET
+ var turr = turret_holder.get_node(editing_turret)
+ turr.aim_mode = par.name
+ build_option(state, statetype)
Globals.StateType.MODULES:
selected = par.name
diff --git a/scripts/turret.gd b/scripts/turret.gd
index 32fb17a..62c9f6f 100644
--- a/scripts/turret.gd
+++ b/scripts/turret.gd
@@ -126,6 +126,39 @@ func filter_visible(set):
if hit == node:
filtered += [ target ]
return filtered
+
+func targeting (set, aim):
+ var pick = set[0]
+ var pick_val = value(pick, aim)
+ for target in set:
+ var enemy = _enemies.enemies[target]
+ var d = value(target, aim)
+ if d > pick_val:
+ pick_val = d
+ pick = target
+ return pick
+
+func value(a, aim):
+ var enemy = _enemies.enemies[a]
+ match aim:
+ "first": return enemy.cur+enemy.rel
+ "last": return - (enemy.cur+enemy.rel)
+ "strongest": return enemy.hp
+ "weakest": return -enemy.hp
+ "closest":
+ var node = _enemies.node_from_id(a)
+ return - _shooting_point.distance_squared_to(node.transform.origin)
+ "furthest":
+ var node = _enemies.node_from_id(a)
+ return _shooting_point.distance_squared_to(node.transform.origin)
+ "least turning":
+ var node = _enemies.node_from_id(a)
+ return node.transform.basis.z.signed_angle_to(
+ gun.transform.basis.z, Vector3.UP)
+ "most turning":
+ var node = _enemies.node_from_id(a)
+ return -node.transform.basis.z.signed_angle_to(
+ gun.transform.basis.z, Vector3.UP)
func get_target():
var ids = []
@@ -135,7 +168,7 @@ func get_target():
set = filter_visible(set)
if set.size() > 0:
- return set[0]
+ return targeting(set, aim_mode)
else: return null
func _physics_process(delta):