summaryrefslogtreecommitdiff
path: root/godot/scripts/CharacterAIManager.gd
blob: fb86a48ad967f23ddd4a131eb9e6e921f1b6e25c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
extends Node

var calcs_per_tick: int = 15
var request_queue: Array = [] #array of dictionaries
var cur_req: Dictionary
var cur_req_args: Dictionary
var WORLD_MAP_RID

enum Task {PATHFIND, FINDITEM}

#tasks: find path, find object 
# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

func _physics_process(_delta):
	for i in calcs_per_tick:
		if len(request_queue) == 0:
			return
		cur_req = request_queue.pop_front()
		cur_req_args = cur_req["args"]
		if cur_req["type"] == Task.PATHFIND:
			var dest_vec: Vector3 = cur_req_args["dest"] if cur_req_args["obj"] == null else cur_req_args["obj"].global_transform.origin
			var path: PoolVector3Array = NavigationServer.map_get_path(WORLD_MAP_RID, cur_req["char"].global_transform.origin, dest_vec, cur_req_args["optimize"])

#will request a path from character to dest_g, or to the global origin of obj if passed
func request_find_path(character: NetChar, dest_g: Vector3, precise: bool, obj: Spatial = null) -> void:
	request_queue.append({"char" : character, "type" : Task.PATHFIND, "args" : {"dest" : dest_g, "obj" : obj, "optimize" : !precise}})