fixed worker spawner: despawns workers now correctly
This commit is contained in:
parent
1c23fc9b2f
commit
923583f0b8
@ -3,30 +3,17 @@ extends NPC
|
||||
const diffPerSecond = 5
|
||||
var _arrived_distance_threshold = 0.1
|
||||
|
||||
var _interactArea: Area
|
||||
var _navPath: Path
|
||||
var _followPath: PathFollow
|
||||
var _current_nav_index = 0
|
||||
|
||||
func _ready():
|
||||
#Logger.set_logger_level(Logger.LOG_LEVEL_FINE)
|
||||
|
||||
_followPath = get_node("../") as PathFollow
|
||||
|
||||
_navPath = get_node("../../") as Path
|
||||
|
||||
var _interactArea = get_node("InteractArea") as Area
|
||||
assert(null != _interactArea)
|
||||
_interactArea.connect("area_entered", self, "_on_area_entered")
|
||||
|
||||
func _process(_delta):
|
||||
# TODO: movement
|
||||
#if current_target: # should not be needed -> handled per navigation path
|
||||
if _followPath != null:
|
||||
_followPath.offset += diffPerSecond * _delta
|
||||
|
||||
|
||||
func _on_area_entered (area: Area):
|
||||
if area.is_in_group("FactoryEntry"):
|
||||
# despawn
|
||||
if _followPath.unit_offset > 0.99:
|
||||
#Logger.info("freeing worker! name: " + name)
|
||||
queue_free()
|
@ -2,6 +2,7 @@ extends Spatial
|
||||
|
||||
export(NodePath) var _nodepath
|
||||
export(float) var _offset
|
||||
export(bool) var ToFactory = true # otherwise it's FromFactory
|
||||
|
||||
const SPAWN_TIME_MIN = 1000 # min spawntime in ms
|
||||
const SPAWN_TIME_MAX = 3000 # max spawntime in ms
|
||||
@ -19,15 +20,22 @@ func _ready():
|
||||
|
||||
|
||||
func _process(delta):
|
||||
var day_time = Daytime.get_time()
|
||||
if ToFactory:
|
||||
if day_time > Daytime.WORK_TIME:
|
||||
return
|
||||
elif day_time < Daytime.SLEEP_TIME:
|
||||
return
|
||||
|
||||
# spawns new workers after defined time
|
||||
var cur_time = OS.get_ticks_msec()
|
||||
|
||||
if cur_time - _lastSpawn > diff:
|
||||
#Logger.info(name + " spawning new worker")
|
||||
var pathFollow = PathFollow.new()
|
||||
pathFollow.offset = _offset
|
||||
pathFollow.add_child(_worker.instance())
|
||||
var worker = _worker.instance()
|
||||
pathFollow.add_child(worker)
|
||||
_path.add_child(pathFollow)
|
||||
_lastSpawn = cur_time
|
||||
#Logger.info(name + " spawning new worker: " + worker.name + ". daytime " + String(day_time) + " <-> " + String(Daytime.WORK_TIME))
|
||||
|
||||
diff = rand_range(SPAWN_TIME_MIN, SPAWN_TIME_MAX)
|
||||
|
Loading…
x
Reference in New Issue
Block a user