-
Notifications
You must be signed in to change notification settings - Fork 0
/
MwNavigator.gd
40 lines (37 loc) · 1.17 KB
/
MwNavigator.gd
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
29
30
31
32
33
34
35
36
37
38
39
40
extends WorldNavigator
class_name MwNavigator
enum {
WORK,
FOOD,
ENTERTAINMENT,
PERSON,
OTHERS,
ANY
}
var Workstations : Array = []
func _ready():
Workstations = get_tree().get_nodes_in_group("Workstations")
func get_nearest_workstation(position : Vector3, filter : int = ANY):
var nearest : Spatial = Spatial.new()
nearest.translation = position
var nearest_size : int
if Workstations.size()>0:
for station in Workstations:
if station.category == filter or filter == ANY:
nearest = station
nearest_size = get_navmesh_path(position, nearest.position).size()
break
for station in Workstations:
if station.category == filter or filter == ANY:
if get_navmesh_path(position, station.position).size() < nearest_size:
if get_navmesh_path(position, station.position).size() > 0:
nearest = station
nearest_size = get_navmesh_path(position, station.position).size()
return nearest
func request_workstation(worker : Worker, filter : int = ANY):
for station in Workstations:
if station.category == filter or filter == ANY:
if station.request_workstation(worker):
print("looking for ", filter)
return
worker.emit_signal("request_rejected")