2020-01-29 05:56:10 +01:00
|
|
|
# Determines any agent that is in the specified list as being neighbors with the
|
|
|
|
# owner agent, regardless of distance.
|
2020-01-08 18:46:42 +01:00
|
|
|
extends GSTProximity
|
|
|
|
class_name GSTInfiniteProximity
|
|
|
|
|
|
|
|
|
|
|
|
func _init(agent: GSTSteeringAgent, agents: Array).(agent, agents) -> void:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2020-01-28 00:31:10 +01:00
|
|
|
# Returns a number of neighbors based on a `callback` function.
|
|
|
|
#
|
2020-01-29 22:53:57 +01:00
|
|
|
# `_find_neighbors` calls `callback` for each agent in the `agents` array and
|
2020-01-29 05:56:10 +01:00
|
|
|
# adds one to the count if its `callback` returns true.
|
2020-02-02 18:48:58 +01:00
|
|
|
# tags: virtual
|
2020-01-29 22:53:57 +01:00
|
|
|
func _find_neighbors(callback: FuncRef) -> int:
|
2020-01-16 09:44:44 +01:00
|
|
|
var neighbor_count := 0
|
|
|
|
var agent_count := agents.size()
|
2020-01-08 18:46:42 +01:00
|
|
|
for i in range(agent_count):
|
2020-01-16 09:44:44 +01:00
|
|
|
var current_agent := agents[i] as GSTSteeringAgent
|
2020-01-08 18:46:42 +01:00
|
|
|
|
|
|
|
if current_agent != agent:
|
|
|
|
if callback.call_func(current_agent):
|
|
|
|
neighbor_count += 1
|
2020-01-28 00:31:10 +01:00
|
|
|
|
2020-01-08 18:46:42 +01:00
|
|
|
return neighbor_count
|