Made exploration task smarter by canceling if was close once
parent
a75eb4aa1d
commit
624c14150e
|
|
@ -17,19 +17,24 @@ texture = ExtResource("1_ukrsa")
|
||||||
3:0/0/custom_data_2 = 1
|
3:0/0/custom_data_2 = 1
|
||||||
3:0/8 = 8
|
3:0/8 = 8
|
||||||
3:0/8/custom_data_0 = true
|
3:0/8/custom_data_0 = true
|
||||||
|
3:0/8/custom_data_2 = 1
|
||||||
1:2/0 = 0
|
1:2/0 = 0
|
||||||
3:2/next_alternative_id = 7
|
3:2/next_alternative_id = 7
|
||||||
3:2/0 = 0
|
3:2/0 = 0
|
||||||
3:2/0/custom_data_0 = true
|
3:2/0/custom_data_0 = true
|
||||||
|
3:2/0/custom_data_2 = 1
|
||||||
3:2/4 = 4
|
3:2/4 = 4
|
||||||
|
3:2/4/custom_data_2 = 1
|
||||||
0:0/0 = 0
|
0:0/0 = 0
|
||||||
0:0/0/custom_data_0 = true
|
0:0/0/custom_data_0 = true
|
||||||
0:0/0/custom_data_2 = 2
|
0:0/0/custom_data_2 = 2
|
||||||
3:1/next_alternative_id = 4
|
3:1/next_alternative_id = 4
|
||||||
3:1/0 = 0
|
3:1/0 = 0
|
||||||
3:1/0/custom_data_0 = true
|
3:1/0/custom_data_0 = true
|
||||||
|
3:1/0/custom_data_2 = 1
|
||||||
3:1/2 = 2
|
3:1/2 = 2
|
||||||
3:1/2/custom_data_0 = true
|
3:1/2/custom_data_0 = true
|
||||||
|
3:1/2/custom_data_2 = 1
|
||||||
5:3/0 = 0
|
5:3/0 = 0
|
||||||
5:3/0/custom_data_0 = true
|
5:3/0/custom_data_0 = true
|
||||||
4:0/0 = 0
|
4:0/0 = 0
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -17,6 +17,7 @@ enum Event {
|
||||||
GAME_STATE_WIN,
|
GAME_STATE_WIN,
|
||||||
NEW_EXPLORATION_GOAL,
|
NEW_EXPLORATION_GOAL,
|
||||||
EXPLORATION_GOAL_REACHED,
|
EXPLORATION_GOAL_REACHED,
|
||||||
|
EXPLORATION_GOAL_CLOSE_ENOUGH,
|
||||||
TEMPERATURE_COLD,
|
TEMPERATURE_COLD,
|
||||||
TIME_SUNDOWN,
|
TIME_SUNDOWN,
|
||||||
};
|
};
|
||||||
|
|
@ -82,6 +83,8 @@ static func populate_visual_log_create_label(event: TrackedEvent, container: Con
|
||||||
text = "New goal " + str(params["goal"])
|
text = "New goal " + str(params["goal"])
|
||||||
elif event_id == Event.EXPLORATION_GOAL_REACHED:
|
elif event_id == Event.EXPLORATION_GOAL_REACHED:
|
||||||
text = "Goal reached"
|
text = "Goal reached"
|
||||||
|
elif event_id == Event.EXPLORATION_GOAL_CLOSE_ENOUGH:
|
||||||
|
text = "Got close enough to goal..."
|
||||||
elif event_id == Event.TEMPERATURE_COLD:
|
elif event_id == Event.TEMPERATURE_COLD:
|
||||||
text = "Temperature is cold: -" + str(params["temperature"])
|
text = "Temperature is cold: -" + str(params["temperature"])
|
||||||
elif event_id == Event.TIME_SUNDOWN:
|
elif event_id == Event.TIME_SUNDOWN:
|
||||||
|
|
|
||||||
|
|
@ -65,14 +65,9 @@ func _process(delta: float) -> void:
|
||||||
if Input.is_action_just_pressed("key_1"):
|
if Input.is_action_just_pressed("key_1"):
|
||||||
get_tree().reload_current_scene()
|
get_tree().reload_current_scene()
|
||||||
if Input.is_action_just_pressed("key_2"):
|
if Input.is_action_just_pressed("key_2"):
|
||||||
var exploration_task: TaskPlannedExploration = player.behavior_tree.find_task_by_name("TaskPlannedExploration")
|
player.exploration_task.current_goal = world.tilemap_ground.local_to_cell(world.get_local_mouse_position())
|
||||||
if exploration_task:
|
|
||||||
exploration_task.current_goal = world.tilemap_ground.local_to_cell(world.get_local_mouse_position())
|
|
||||||
player.behavior_tree.blackboard["cached_paths"] = {}
|
player.behavior_tree.blackboard["cached_paths"] = {}
|
||||||
player.behavior_tree.blackboard["path"] = []
|
player.behavior_tree.blackboard["path"] = []
|
||||||
else:
|
|
||||||
print("[ERROR] TaskPlannedExploration not found")
|
|
||||||
push_error("TaskPlannedExploration not found")
|
|
||||||
|
|
||||||
if intro_image.is_visible():
|
if intro_image.is_visible():
|
||||||
intro_image.set_scale(calculate_scale(intro_image.texture.get_size()))
|
intro_image.set_scale(calculate_scale(intro_image.texture.get_size()))
|
||||||
|
|
@ -116,6 +111,8 @@ func _on_game_tick_timeout() -> void:
|
||||||
|
|
||||||
player.game_tick()
|
player.game_tick()
|
||||||
|
|
||||||
|
apply_player_exploration_distance()
|
||||||
|
|
||||||
tree_visualizer.update_task_statuses(player.behavior_tree.blackboard)
|
tree_visualizer.update_task_statuses(player.behavior_tree.blackboard)
|
||||||
|
|
||||||
tilemap_navigation.game_tick_end()
|
tilemap_navigation.game_tick_end()
|
||||||
|
|
@ -157,6 +154,10 @@ func camera_follow_player() -> void:
|
||||||
camera.go_to_zooming(avg_position, zoom_level)
|
camera.go_to_zooming(avg_position, zoom_level)
|
||||||
|
|
||||||
|
|
||||||
|
func apply_player_exploration_distance():
|
||||||
|
player.exploration_task.closest_distance_to_goal = min(player.exploration_task.closest_distance_to_goal, TilemapNavigation.manhattan_distance(player.board_position, player.exploration_task.current_goal))
|
||||||
|
|
||||||
|
|
||||||
func distance_to_zoom_level(distance: float) -> float:
|
func distance_to_zoom_level(distance: float) -> float:
|
||||||
var a: float = 862.08
|
var a: float = 862.08
|
||||||
var b: float = 274.13
|
var b: float = 274.13
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ var board_position: Vector2i = Vector2i(0, 0):
|
||||||
|
|
||||||
@onready var behavior_tree: BehaviorTree = $BehaviorTree
|
@onready var behavior_tree: BehaviorTree = $BehaviorTree
|
||||||
|
|
||||||
|
var exploration_task: TaskPlannedExploration = null
|
||||||
var food: int = max_food
|
var food: int = max_food
|
||||||
# var water: int = 0
|
# var water: int = 0
|
||||||
var temperature_buff_timer: int = 0
|
var temperature_buff_timer: int = 0
|
||||||
|
|
@ -40,6 +41,7 @@ var inventory_slot: Vector2i = tilemap_types.EMPTY:
|
||||||
|
|
||||||
var player_memory: Dictionary = {}
|
var player_memory: Dictionary = {}
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
call_deferred("defer_ready")
|
call_deferred("defer_ready")
|
||||||
|
|
||||||
|
|
@ -52,6 +54,7 @@ func defer_ready() -> void:
|
||||||
else:
|
else:
|
||||||
push_error("No player start position found on tilemap")
|
push_error("No player start position found on tilemap")
|
||||||
update_board()
|
update_board()
|
||||||
|
exploration_task = behavior_tree.find_task_by_name("TaskPlannedExploration")
|
||||||
|
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ extends Task
|
||||||
|
|
||||||
var last_goals: Array[Vector2i] = []
|
var last_goals: Array[Vector2i] = []
|
||||||
var current_goal: Vector2i = tilemap_types.NO_TILE_FOUND
|
var current_goal: Vector2i = tilemap_types.NO_TILE_FOUND
|
||||||
|
var closest_distance_to_goal: float = 99999999
|
||||||
|
|
||||||
|
|
||||||
func run(blackboard: Dictionary) -> void:
|
func run(blackboard: Dictionary) -> void:
|
||||||
|
|
@ -10,6 +11,13 @@ func run(blackboard: Dictionary) -> void:
|
||||||
var player: PlayerManager = blackboard["player"]
|
var player: PlayerManager = blackboard["player"]
|
||||||
var navigation: TilemapNavigation = blackboard["navigation"]
|
var navigation: TilemapNavigation = blackboard["navigation"]
|
||||||
|
|
||||||
|
# check if player distance is < 10 to the camp (world, camp_manager, camp) and if he was closer than the view distance to the goal once (closest_distance_to_goal), reset the goal in that case
|
||||||
|
if TilemapNavigation.manhattan_distance(player.board_position, world.camp_manager.camp) < 10 and closest_distance_to_goal < player.view_distance:
|
||||||
|
current_goal = tilemap_types.NO_TILE_FOUND
|
||||||
|
closest_distance_to_goal = 99999999
|
||||||
|
EventsTracker.track(EventsTracker.Event.EXPLORATION_GOAL_CLOSE_ENOUGH, {"item": tilemap_types.OBJECT_I_TENT})
|
||||||
|
print("Resetting goal, player close to camp and was close to goal once")
|
||||||
|
|
||||||
# check if player distance is < 2 to the current goal
|
# check if player distance is < 2 to the current goal
|
||||||
if current_goal != tilemap_types.NO_TILE_FOUND:
|
if current_goal != tilemap_types.NO_TILE_FOUND:
|
||||||
if TilemapNavigation.manhattan_distance(player.board_position, current_goal) < 3:
|
if TilemapNavigation.manhattan_distance(player.board_position, current_goal) < 3:
|
||||||
|
|
@ -20,6 +28,7 @@ func run(blackboard: Dictionary) -> void:
|
||||||
find_new_goal(world, player, navigation)
|
find_new_goal(world, player, navigation)
|
||||||
if current_goal != tilemap_types.NO_TILE_FOUND:
|
if current_goal != tilemap_types.NO_TILE_FOUND:
|
||||||
EventsTracker.track(EventsTracker.Event.NEW_EXPLORATION_GOAL, {"goal": current_goal})
|
EventsTracker.track(EventsTracker.Event.NEW_EXPLORATION_GOAL, {"goal": current_goal})
|
||||||
|
closest_distance_to_goal = 99999999
|
||||||
|
|
||||||
if current_goal == tilemap_types.NO_TILE_FOUND:
|
if current_goal == tilemap_types.NO_TILE_FOUND:
|
||||||
status = Task.FAILURE
|
status = Task.FAILURE
|
||||||
|
|
@ -98,7 +107,7 @@ func determine_an_interesting_goal(world: World) -> Vector2i:
|
||||||
var picked_goal: Vector2i = Vector2i(0, 0)
|
var picked_goal: Vector2i = Vector2i(0, 0)
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
var check_position: Vector2i = last_walkable + Vector2i(randi_range(-10, 10), randi_range(-10, 10))
|
var check_position: Vector2i = last_walkable + Vector2i(randi_range(-10, 10), randi_range(-10, 10))
|
||||||
if world.is_walkable(check_position):
|
if world.is_walkable(check_position) and world.tilemap_ground.get_custom_data(check_position, "cost", 999) < 7:
|
||||||
picked_goal = check_position
|
picked_goal = check_position
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue