diff --git a/source/FeatureFlags.gd b/source/FeatureFlags.gd index 70fefea..c6f9d79 100644 --- a/source/FeatureFlags.gd +++ b/source/FeatureFlags.gd @@ -3,10 +3,13 @@ extends Node @export_group("Game") @export var show_logos_on_startup = true @export var save_user_files_in_tmp = false + @export_group("Match") @export var allow_resources_deficit_spending = false @export var handle_match_end = true @export var show_minimap = true +@export var allow_navigation_rebaking = true + @export_group("Match/Debug") @export var frame_incrementer = false @export var god_mode = false diff --git a/source/FeatureFlags.tscn b/source/FeatureFlags.tscn index aabe467..222625d 100644 --- a/source/FeatureFlags.tscn +++ b/source/FeatureFlags.tscn @@ -4,4 +4,5 @@ [node name="FeatureFlags" type="Node"] script = ExtResource("1_wihie") +allow_navigation_rebaking = false god_mode = true diff --git a/source/match/Match.gd b/source/match/Match.gd index 19b4085..7f1ec54 100644 --- a/source/match/Match.gd +++ b/source/match/Match.gd @@ -35,8 +35,6 @@ func _enter_tree(): func _ready(): MatchSignals.setup_and_spawn_unit.connect(_setup_and_spawn_unit) - MatchSignals.unit_died.connect(_on_unit_died) - MatchSignals.resource_depleted.connect(_on_resource_depleted) _setup_subsystems_dependent_on_map() _setup_players() _setup_player_units() @@ -44,8 +42,6 @@ func _ready(): _move_camera_to_initial_position() if settings.visibility == settings.Visibility.FULL: fog_of_war.reveal() - await get_tree().process_frame - navigation.update_terrain() func _unhandled_input(event): @@ -150,8 +146,6 @@ func _setup_and_spawn_unit(unit, a_transform, player, mark_structure_under_const unit.mark_as_under_construction() _setup_unit_groups(unit, player) player.add_child(unit) - if unit is Structure and mark_structure_under_construction: - navigation.update_terrain() MatchSignals.unit_spawned.emit(unit) @@ -208,12 +202,3 @@ func _conceal_player_units(player): func(a_unit): return a_unit.player == player ): unit.remove_from_group("revealed_units") - - -func _on_unit_died(unit): - if unit is Structure: - navigation.update_terrain() - - -func _on_resource_depleted(): - navigation.update_terrain() diff --git a/source/match/Match.tscn b/source/match/Match.tscn index b0dcfe8..a2471dc 100644 --- a/source/match/Match.tscn +++ b/source/match/Match.tscn @@ -101,9 +101,8 @@ geometry_parsed_geometry_type = 2 geometry_collision_mask = 4278190082 geometry_source_geometry_mode = 2 geometry_source_group_name = &"terrain_navigation_input" -cell_size = 0.2 agent_height = 2.0 -agent_radius = 0.6 +agent_radius = 1.0 agent_max_climb = 0.0 [sub_resource type="ViewportTexture" id="ViewportTexture_vu2gm"] diff --git a/source/match/MatchConstants.gd b/source/match/MatchConstants.gd index 595423c..011830d 100644 --- a/source/match/MatchConstants.gd +++ b/source/match/MatchConstants.gd @@ -21,6 +21,11 @@ const MAPS = { class Navigation: enum Domain { AIR, TERRAIN } + const DOMAIN_TO_GROUP_MAPPING = { + Domain.AIR: "air_navigation_input", + Domain.TERRAIN: "terrain_navigation_input", + } + class Air: const Y = 1.5 @@ -36,9 +41,9 @@ class Terrain: const PLANE = Plane(Vector3.UP, 0) class Navmesh: - const CELL_SIZE = 0.2 + const CELL_SIZE = 0.25 const CELL_HEIGHT = 0.25 - const MAX_AGENT_RADIUS = 0.6 # max radius of movable units + const MAX_AGENT_RADIUS = 1.0 # max radius of movable units class Resources: diff --git a/source/match/MatchSignals.gd b/source/match/MatchSignals.gd index 580c62d..0de06d9 100644 --- a/source/match/MatchSignals.gd +++ b/source/match/MatchSignals.gd @@ -4,6 +4,7 @@ extends Node signal deselect_all_units signal setup_and_spawn_unit(unit, transform, player) signal place_structure(structure_prototype) +signal schedule_navigation_rebake(domain) # notifications signal terrain_targeted(position) @@ -12,4 +13,3 @@ signal unit_targeted(unit) signal unit_selected(unit) signal unit_deselected(unit) signal unit_died(unit) -signal resource_depleted diff --git a/source/match/Navigation.gd b/source/match/Navigation.gd index 1968de1..69a64a6 100644 --- a/source/match/Navigation.gd +++ b/source/match/Navigation.gd @@ -21,22 +21,12 @@ func get_navigation_map_rid_by_domain(domain): func rebake(map): - var obstacles = get_tree().get_nodes_in_group("terrain_navigation_input") - for obstacle in obstacles: - if obstacle.name.to_lower() != "terrain": - obstacle.remove_from_group("terrain_navigation_input") air.rebake(map) - terrain.rebake(false) - for obstacle in obstacles: - obstacle.add_to_group("terrain_navigation_input") + terrain.rebake() _clear_static_obstacles() _setup_static_obstacles() -func update_terrain(): - terrain.rebake(true) - - func _clear_static_obstacles(): for static_obstacle in _static_obstacles: NavigationServer3D.free_rid(static_obstacle) diff --git a/source/match/TerrainNavigation.gd b/source/match/TerrainNavigation.gd index fe65e97..e35421d 100644 --- a/source/match/TerrainNavigation.gd +++ b/source/match/TerrainNavigation.gd @@ -1,5 +1,10 @@ extends Node3D +const DOMAIN = Constants.Match.Navigation.Domain.TERRAIN + +var _earliest_frame_to_perform_next_rebake = null +var _is_baking = false + @onready var navigation_map_rid = get_world_3d().navigation_map @onready var _navigation_region = find_child("NavigationRegion3D") @@ -14,10 +19,23 @@ func _ready(): navigation_map_rid, Constants.Match.Terrain.Navmesh.CELL_HEIGHT ) NavigationServer3D.map_force_update(navigation_map_rid) + MatchSignals.schedule_navigation_rebake.connect(_on_schedule_navigation_rebake) + _navigation_region.bake_finished.connect(_on_bake_finished) + + +func _process(_delta): + if ( + not _is_baking + and _earliest_frame_to_perform_next_rebake != null + and get_tree().get_frame() >= _earliest_frame_to_perform_next_rebake + ): + _is_baking = true + _earliest_frame_to_perform_next_rebake = null + _navigation_region.bake_navigation_mesh(true) -func rebake(on_thread: bool): - _navigation_region.bake_navigation_mesh(on_thread) +func rebake(): + _navigation_region.bake_navigation_mesh(false) func _safety_checks(): @@ -42,3 +60,14 @@ func _safety_checks(): "Navmesh 'cell_height' must match established constant" ) return true + + +func _on_schedule_navigation_rebake(domain): + if domain != DOMAIN or not is_inside_tree() or not FeatureFlags.allow_navigation_rebaking: + return + if _earliest_frame_to_perform_next_rebake == null: + _earliest_frame_to_perform_next_rebake = get_tree().get_frame() + 1 + + +func _on_bake_finished(): + _is_baking = false diff --git a/source/match/units/AircraftFactory.tscn b/source/match/units/AircraftFactory.tscn index 4a933a1..a4dbda0 100644 --- a/source/match/units/AircraftFactory.tscn +++ b/source/match/units/AircraftFactory.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=3 uid="uid://cxilu6668nda6"] +[gd_scene load_steps=13 format=3 uid="uid://cxilu6668nda6"] [ext_resource type="Script" path="res://source/match/units/AircraftFactory.gd" id="1_n6n1v"] [ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="1_r5i7t"] @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://bklfapayb1ryk" path="res://source/match/units/structure-geometries/AircraftFactory.tscn" id="2_mlisu"] [ext_resource type="PackedScene" uid="uid://d4cwip5hpxlmo" path="res://source/match/units/traits/MovementObstacle.tscn" id="3_j1buj"] [ext_resource type="PackedScene" uid="uid://c3ssj2p6voauk" path="res://source/match/units/traits/HealthBar.tscn" id="4_igtfr"] +[ext_resource type="PackedScene" uid="uid://c471ahpwuxv57" path="res://source/match/units/traits/StaticMovementObstacle.tscn" id="6_rvkkl"] [ext_resource type="PackedScene" uid="uid://b8jwlpdvxgrr6" path="res://source/match/units/traits/RallyPoint.tscn" id="8_opfgx"] [ext_resource type="PackedScene" uid="uid://cd3v6508vjcu3" path="res://source/match/units/traits/ProductionQueue.tscn" id="9_c3qd5"] [ext_resource type="PackedScene" uid="uid://d4cm4yhtf11ur" path="res://source/match/units/traits/Targetability.tscn" id="9_qqlap"] @@ -14,8 +15,9 @@ height = 1.0 radius = 1.5 -[sub_resource type="BoxMesh" id="BoxMesh_oki0p"] -size = Vector3(2, 1, 2) +[sub_resource type="CylinderShape3D" id="CylinderShape3D_ea0ur"] +height = 1.0 +radius = 1.5 [node name="AircraftFactory" type="Area3D"] collision_layer = 2 @@ -40,6 +42,9 @@ radius = 1.5 radius = 1.5 path_height_offset = 0.5 +[node name="StaticMovementObstacle" parent="." instance=ExtResource("6_rvkkl")] +shape = SubResource("CylinderShape3D_ea0ur") + [node name="HealthBar" parent="." instance=ExtResource("4_igtfr")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0) size = Vector2(250, 10) @@ -52,10 +57,4 @@ radius = 1.5 [node name="ProductionQueue" parent="." instance=ExtResource("9_c3qd5")] -[node name="NavMeshObstacle" type="MeshInstance3D" parent="." groups=["terrain_navigation_input"]] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0) -layers = 0 -mesh = SubResource("BoxMesh_oki0p") -skeleton = NodePath("../CollisionShape3D") - [editable path="Geometry"] diff --git a/source/match/units/AntiAirTurret.tscn b/source/match/units/AntiAirTurret.tscn index 1a350cf..f024198 100644 --- a/source/match/units/AntiAirTurret.tscn +++ b/source/match/units/AntiAirTurret.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=3 uid="uid://cfa8cpnpk5pcb"] +[gd_scene load_steps=12 format=3 uid="uid://cfa8cpnpk5pcb"] [ext_resource type="Script" path="res://source/match/units/AntiAirTurret.gd" id="1_ec2s5"] [ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="1_tbjvv"] @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://3c1h14nqdumt" path="res://source/match/units/traits/Selection.tscn" id="2_ookx0"] [ext_resource type="PackedScene" uid="uid://d4cwip5hpxlmo" path="res://source/match/units/traits/MovementObstacle.tscn" id="3_hgb44"] [ext_resource type="PackedScene" uid="uid://c3ssj2p6voauk" path="res://source/match/units/traits/HealthBar.tscn" id="4_qhoj1"] +[ext_resource type="PackedScene" uid="uid://c471ahpwuxv57" path="res://source/match/units/traits/StaticMovementObstacle.tscn" id="6_tt140"] [ext_resource type="PackedScene" uid="uid://d4cm4yhtf11ur" path="res://source/match/units/traits/Targetability.tscn" id="7_6bghh"] [ext_resource type="PackedScene" uid="uid://cd66t0u7kf84j" path="res://source/match/units/traits/RotateRandomlyWhenLookingForTargetsIdle.tscn" id="8_hqxqv"] @@ -13,10 +14,9 @@ height = 0.8 radius = 0.6 -[sub_resource type="CylinderMesh" id="CylinderMesh_v80fm"] -top_radius = 0.6 -bottom_radius = 0.6 +[sub_resource type="CylinderShape3D" id="CylinderShape3D_65kle"] height = 0.8 +radius = 0.6 [node name="AntiAirTurret" type="Area3D"] collision_layer = 2 @@ -62,6 +62,9 @@ radius = 0.6 radius = 0.6 path_height_offset = 0.5 +[node name="StaticMovementObstacle" parent="." instance=ExtResource("6_tt140")] +shape = SubResource("CylinderShape3D_65kle") + [node name="HealthBar" parent="." instance=ExtResource("4_qhoj1")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.1, 0) size = Vector2(110, 10) @@ -73,11 +76,5 @@ radius = 0.6 [node name="RotateRandomlyWhenLookingForTargetsIdle" parent="." instance=ExtResource("8_hqxqv")] node_to_rotate = NodePath("../DetachTransform/Geometry/turret_double/tmpParent/turret_double2/turret") -[node name="NavMeshObstacle" type="MeshInstance3D" parent="." groups=["terrain_navigation_input"]] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4, 0) -layers = 0 -mesh = SubResource("CylinderMesh_v80fm") -skeleton = NodePath("../CollisionShape3D") - [editable path="DetachTransform/Geometry"] [editable path="DetachTransform/Geometry/turret_double"] diff --git a/source/match/units/AntiGroundTurret.tscn b/source/match/units/AntiGroundTurret.tscn index caaac03..c7b1854 100644 --- a/source/match/units/AntiGroundTurret.tscn +++ b/source/match/units/AntiGroundTurret.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=3 uid="uid://b8pckq1xn44ss"] +[gd_scene load_steps=12 format=3 uid="uid://b8pckq1xn44ss"] [ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="1_5gp2d"] [ext_resource type="Script" path="res://source/match/units/AntiGroundTurret.gd" id="1_6hw4x"] @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://bmiqncjpgsw2e" path="res://source/match/units/structure-geometries/AntiGroundTurret.tscn" id="2_tlome"] [ext_resource type="PackedScene" uid="uid://d4cwip5hpxlmo" path="res://source/match/units/traits/MovementObstacle.tscn" id="3_ds80w"] [ext_resource type="PackedScene" uid="uid://c3ssj2p6voauk" path="res://source/match/units/traits/HealthBar.tscn" id="4_r6emo"] +[ext_resource type="PackedScene" uid="uid://c471ahpwuxv57" path="res://source/match/units/traits/StaticMovementObstacle.tscn" id="6_w6nbo"] [ext_resource type="PackedScene" uid="uid://d4cm4yhtf11ur" path="res://source/match/units/traits/Targetability.tscn" id="7_4hifs"] [ext_resource type="PackedScene" uid="uid://cd66t0u7kf84j" path="res://source/match/units/traits/RotateRandomlyWhenLookingForTargetsIdle.tscn" id="8_l7mop"] @@ -13,10 +14,9 @@ height = 0.8 radius = 0.6 -[sub_resource type="CylinderMesh" id="CylinderMesh_ymrt0"] -top_radius = 0.6 -bottom_radius = 0.6 +[sub_resource type="CylinderShape3D" id="CylinderShape3D_t2frt"] height = 0.8 +radius = 0.6 [node name="AntiGroundTurret" type="Area3D"] collision_layer = 2 @@ -56,6 +56,9 @@ radius = 0.6 radius = 0.6 path_height_offset = 0.5 +[node name="StaticMovementObstacle" parent="." instance=ExtResource("6_w6nbo")] +shape = SubResource("CylinderShape3D_t2frt") + [node name="HealthBar" parent="." instance=ExtResource("4_r6emo")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.1, 0) size = Vector2(110, 10) @@ -67,11 +70,5 @@ radius = 0.6 [node name="RotateRandomlyWhenLookingForTargets" parent="." instance=ExtResource("8_l7mop")] node_to_rotate = NodePath("../DetachTransform/Geometry/turret_single/tmpParent/turret_single2/turret") -[node name="NavMeshObstacle" type="MeshInstance3D" parent="." groups=["terrain_navigation_input"]] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4, 0) -layers = 0 -mesh = SubResource("CylinderMesh_ymrt0") -skeleton = NodePath("../CollisionShape3D") - [editable path="DetachTransform/Geometry"] [editable path="DetachTransform/Geometry/turret_single"] diff --git a/source/match/units/CommandCenter.tscn b/source/match/units/CommandCenter.tscn index 1130658..48f9b10 100644 --- a/source/match/units/CommandCenter.tscn +++ b/source/match/units/CommandCenter.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=3 uid="uid://ct0ejt0trkhrf"] +[gd_scene load_steps=13 format=3 uid="uid://ct0ejt0trkhrf"] [ext_resource type="Script" path="res://source/match/units/CommandCenter.gd" id="1_hpo2s"] [ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="2_c41i5"] @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://3c1h14nqdumt" path="res://source/match/units/traits/Selection.tscn" id="3_slmue"] [ext_resource type="PackedScene" uid="uid://d4cwip5hpxlmo" path="res://source/match/units/traits/MovementObstacle.tscn" id="4_f5u8t"] [ext_resource type="PackedScene" uid="uid://c3ssj2p6voauk" path="res://source/match/units/traits/HealthBar.tscn" id="5_xuulo"] +[ext_resource type="PackedScene" uid="uid://c471ahpwuxv57" path="res://source/match/units/traits/StaticMovementObstacle.tscn" id="6_5gbe5"] [ext_resource type="PackedScene" uid="uid://b8jwlpdvxgrr6" path="res://source/match/units/traits/RallyPoint.tscn" id="8_8qw5y"] [ext_resource type="PackedScene" uid="uid://cd3v6508vjcu3" path="res://source/match/units/traits/ProductionQueue.tscn" id="9_y6bg8"] [ext_resource type="PackedScene" uid="uid://d4cm4yhtf11ur" path="res://source/match/units/traits/Targetability.tscn" id="17_dco2r"] @@ -14,10 +15,9 @@ height = 0.8 radius = 1.8 -[sub_resource type="CylinderMesh" id="CylinderMesh_tf5as"] -top_radius = 1.8 -bottom_radius = 1.8 +[sub_resource type="CylinderShape3D" id="CylinderShape3D_2xy8f"] height = 0.8 +radius = 1.8 [node name="CommandCenter" type="Area3D"] collision_layer = 2 @@ -42,6 +42,9 @@ radius = 2.0 radius = 2.0 path_height_offset = 0.5 +[node name="StaticMovementObstacle" parent="." instance=ExtResource("6_5gbe5")] +shape = SubResource("CylinderShape3D_2xy8f") + [node name="HealthBar" parent="." instance=ExtResource("5_xuulo")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0) size = Vector2(380, 10) @@ -54,9 +57,4 @@ radius = 2.0 [node name="ProductionQueue" parent="." instance=ExtResource("9_y6bg8")] -[node name="NavMeshObstacle" type="MeshInstance3D" parent="." groups=["terrain_navigation_input"]] -transform = Transform3D(0.707107, 0, 0.707107, 0, 1, 0, -0.707107, 0, 0.707107, 0, 0.4, 0) -layers = 0 -mesh = SubResource("CylinderMesh_tf5as") - [editable path="Geometry"] diff --git a/source/match/units/Tank.tscn b/source/match/units/Tank.tscn index a42a4f5..e5f35b1 100644 --- a/source/match/units/Tank.tscn +++ b/source/match/units/Tank.tscn @@ -11,7 +11,7 @@ [sub_resource type="CylinderShape3D" id="CylinderShape3D_sjc11"] height = 0.6 -radius = 0.6 +radius = 0.8 [node name="Tank" type="Area3D"] collision_layer = 2 @@ -45,7 +45,7 @@ path_desired_distance = 0.5 target_desired_distance = 0.5 path_height_offset = 0.5 path_max_distance = 0.51 -radius = 0.6 +radius = 1.0 neighbor_distance = 8.0 max_neighbors = 40 time_horizon_agents = 3.0 diff --git a/source/match/units/VehicleFactory.tscn b/source/match/units/VehicleFactory.tscn index 71705c0..c7f23d3 100644 --- a/source/match/units/VehicleFactory.tscn +++ b/source/match/units/VehicleFactory.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=3 uid="uid://h5lqor1xl2sf"] +[gd_scene load_steps=13 format=3 uid="uid://h5lqor1xl2sf"] [ext_resource type="Script" path="res://source/match/units/VehicleFactory.gd" id="1_1a20j"] [ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="1_8fcgb"] @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://inepf56pyube" path="res://source/match/units/structure-geometries/VehicleFactory.tscn" id="2_j6xs6"] [ext_resource type="PackedScene" uid="uid://d4cwip5hpxlmo" path="res://source/match/units/traits/MovementObstacle.tscn" id="3_cp6bx"] [ext_resource type="PackedScene" uid="uid://c3ssj2p6voauk" path="res://source/match/units/traits/HealthBar.tscn" id="4_xd2eg"] +[ext_resource type="PackedScene" uid="uid://c471ahpwuxv57" path="res://source/match/units/traits/StaticMovementObstacle.tscn" id="6_rohol"] [ext_resource type="PackedScene" uid="uid://d4cm4yhtf11ur" path="res://source/match/units/traits/Targetability.tscn" id="7_j4kwk"] [ext_resource type="PackedScene" uid="uid://b8jwlpdvxgrr6" path="res://source/match/units/traits/RallyPoint.tscn" id="8_h714l"] [ext_resource type="PackedScene" uid="uid://cd3v6508vjcu3" path="res://source/match/units/traits/ProductionQueue.tscn" id="9_3s532"] @@ -14,10 +15,9 @@ height = 1.0 radius = 1.5 -[sub_resource type="CylinderMesh" id="CylinderMesh_nlnof"] -top_radius = 1.5 -bottom_radius = 1.5 +[sub_resource type="CylinderShape3D" id="CylinderShape3D_x8l2r"] height = 1.0 +radius = 1.5 [node name="VehicleFactory" type="Area3D"] collision_layer = 2 @@ -42,6 +42,9 @@ radius = 1.5 radius = 1.5 path_height_offset = 0.5 +[node name="StaticMovementObstacle" parent="." instance=ExtResource("6_rohol")] +shape = SubResource("CylinderShape3D_x8l2r") + [node name="HealthBar" parent="." instance=ExtResource("4_xd2eg")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.75, 0) size = Vector2(250, 10) @@ -54,10 +57,4 @@ radius = 1.5 [node name="ProductionQueue" parent="." instance=ExtResource("9_3s532")] -[node name="NavMeshObstacle" type="MeshInstance3D" parent="." groups=["terrain_navigation_input"]] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0) -layers = 0 -mesh = SubResource("CylinderMesh_nlnof") -skeleton = NodePath("../CollisionShape3D") - [editable path="Geometry"] diff --git a/source/match/units/non-player/ResourceA.gd b/source/match/units/non-player/ResourceA.gd index 699b4c3..95643e7 100644 --- a/source/match/units/non-player/ResourceA.gd +++ b/source/match/units/non-player/ResourceA.gd @@ -7,7 +7,6 @@ const MATERIAL_ALBEDO_TO_REPLACE_EPSILON = 0.05 set(value): resource_a = max(0, value) if resource_a == 0: - tree_exited.connect(func(): MatchSignals.resource_depleted.emit()) queue_free() var color = Constants.Match.Resources.A.COLOR: diff --git a/source/match/units/non-player/ResourceA.tscn b/source/match/units/non-player/ResourceA.tscn index 2f9958a..80a46c9 100644 --- a/source/match/units/non-player/ResourceA.tscn +++ b/source/match/units/non-player/ResourceA.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://bf3jjdafqvh0w"] +[gd_scene load_steps=10 format=3 uid="uid://bf3jjdafqvh0w"] [ext_resource type="Script" path="res://source/match/units/non-player/ResourceA.gd" id="1_3daqx"] [ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="1_d3pi2"] @@ -6,14 +6,13 @@ [ext_resource type="PackedScene" uid="uid://3c1h14nqdumt" path="res://source/match/units/traits/Selection.tscn" id="2_pgrb1"] [ext_resource type="PackedScene" uid="uid://d4cwip5hpxlmo" path="res://source/match/units/traits/MovementObstacle.tscn" id="3_xabt4"] [ext_resource type="PackedScene" uid="uid://d4cm4yhtf11ur" path="res://source/match/units/traits/Targetability.tscn" id="5_vqxvf"] +[ext_resource type="PackedScene" uid="uid://c471ahpwuxv57" path="res://source/match/units/traits/StaticMovementObstacle.tscn" id="6_y2ye1"] [sub_resource type="CylinderShape3D" id="CylinderShape3D_msmnm"] height = 0.6 -[sub_resource type="CylinderMesh" id="CylinderMesh_ep7dh"] -top_radius = 0.4 -bottom_radius = 0.4 -height = 1.0 +[sub_resource type="CylinderShape3D" id="CylinderShape3D_wb6so"] +height = 0.6 [node name="ResourceA" type="Area3D" groups=["resource_units"]] script = ExtResource("1_3daqx") @@ -39,12 +38,9 @@ radius = 0.6 radius = 0.6 path_height_offset = 0.5 +[node name="StaticMovementObstacle" parent="." instance=ExtResource("6_y2ye1")] +shape = SubResource("CylinderShape3D_wb6so") + [node name="Targetability" parent="." instance=ExtResource("5_vqxvf")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0) radius = 0.6 - -[node name="NavMeshObstacle" type="MeshInstance3D" parent="." groups=["terrain_navigation_input"]] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0) -layers = 0 -mesh = SubResource("CylinderMesh_ep7dh") -skeleton = NodePath("../CollisionShape3D") diff --git a/source/match/units/non-player/ResourceB.gd b/source/match/units/non-player/ResourceB.gd index 4f6780d..53a1c45 100644 --- a/source/match/units/non-player/ResourceB.gd +++ b/source/match/units/non-player/ResourceB.gd @@ -7,7 +7,6 @@ const MATERIAL_ALBEDO_TO_REPLACE_EPSILON = 0.05 set(value): resource_b = max(0, value) if resource_b == 0: - tree_exited.connect(func(): MatchSignals.resource_depleted.emit()) queue_free() var color = Constants.Match.Resources.B.COLOR: diff --git a/source/match/units/non-player/ResourceB.tscn b/source/match/units/non-player/ResourceB.tscn index bc553b3..d792713 100644 --- a/source/match/units/non-player/ResourceB.tscn +++ b/source/match/units/non-player/ResourceB.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://bufgjfa3ne3uk"] +[gd_scene load_steps=10 format=3 uid="uid://bufgjfa3ne3uk"] [ext_resource type="Script" path="res://source/match/units/non-player/ResourceB.gd" id="1_57n8v"] [ext_resource type="PackedScene" uid="uid://cgsi062w5fjia" path="res://source/match/units/traits/Highlight.tscn" id="2_c8mwe"] @@ -6,14 +6,13 @@ [ext_resource type="PackedScene" uid="uid://3c1h14nqdumt" path="res://source/match/units/traits/Selection.tscn" id="3_6dh54"] [ext_resource type="PackedScene" uid="uid://d4cwip5hpxlmo" path="res://source/match/units/traits/MovementObstacle.tscn" id="4_sxjck"] [ext_resource type="PackedScene" uid="uid://d4cm4yhtf11ur" path="res://source/match/units/traits/Targetability.tscn" id="5_y6273"] +[ext_resource type="PackedScene" uid="uid://c471ahpwuxv57" path="res://source/match/units/traits/StaticMovementObstacle.tscn" id="6_vvgyq"] [sub_resource type="CylinderShape3D" id="CylinderShape3D_msmnm"] height = 0.8 -[sub_resource type="CylinderMesh" id="CylinderMesh_ajrhd"] -top_radius = 0.4 -bottom_radius = 0.4 -height = 1.0 +[sub_resource type="CylinderShape3D" id="CylinderShape3D_002vj"] +height = 0.8 [node name="ResourceB" type="Area3D" groups=["resource_units"]] script = ExtResource("1_57n8v") @@ -39,12 +38,9 @@ radius = 0.6 radius = 0.6 path_height_offset = 0.5 +[node name="StaticMovementObstacle" parent="." instance=ExtResource("6_vvgyq")] +shape = SubResource("CylinderShape3D_002vj") + [node name="Targetability" parent="." instance=ExtResource("5_y6273")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.05, 0) radius = 0.6 - -[node name="NavMeshObstacle" type="MeshInstance3D" parent="." groups=["terrain_navigation_input"]] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0) -layers = 0 -mesh = SubResource("CylinderMesh_ajrhd") -skeleton = NodePath("../CollisionShape3D") diff --git a/source/match/units/traits/StaticMovementObstacle.gd b/source/match/units/traits/StaticMovementObstacle.gd new file mode 100644 index 0000000..e561bc5 --- /dev/null +++ b/source/match/units/traits/StaticMovementObstacle.gd @@ -0,0 +1,25 @@ +@tool +extends StaticBody3D + +@export var domain = Constants.Match.Navigation.Domain.TERRAIN +@export var shape: Shape3D = null: + set(a_shape): + shape = a_shape + find_child("CollisionShape3D").shape = shape + + +func _enter_tree(): + if Engine.is_editor_hint(): + return + var match = find_parent("Match") + if not match.is_node_ready(): + await match.ready + add_to_group(Constants.Match.Navigation.DOMAIN_TO_GROUP_MAPPING[domain]) + MatchSignals.schedule_navigation_rebake.emit(domain) + + +func _exit_tree(): + if Engine.is_editor_hint(): + return + remove_from_group(Constants.Match.Navigation.DOMAIN_TO_GROUP_MAPPING[domain]) + MatchSignals.schedule_navigation_rebake.emit(domain) diff --git a/source/match/units/traits/StaticMovementObstacle.tscn b/source/match/units/traits/StaticMovementObstacle.tscn new file mode 100644 index 0000000..07f574e --- /dev/null +++ b/source/match/units/traits/StaticMovementObstacle.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=2 format=3 uid="uid://c471ahpwuxv57"] + +[ext_resource type="Script" path="res://source/match/units/traits/StaticMovementObstacle.gd" id="1_yolf4"] + +[node name="StaticMovementObstacle" type="StaticBody3D"] +collision_layer = 6 +collision_mask = 0 +input_ray_pickable = false +script = ExtResource("1_yolf4") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="."] diff --git a/source/match/utils/UnitPlacementUtils.gd b/source/match/utils/UnitPlacementUtils.gd index cd84736..2a5ab5b 100644 --- a/source/match/utils/UnitPlacementUtils.gd +++ b/source/match/utils/UnitPlacementUtils.gd @@ -1,7 +1,5 @@ enum { VALID, COLLIDES_WITH_AGENT, NOT_NAVIGABLE } -const EPSILON = 0.05 # Custom approximation variable check for terrain - static func find_valid_position_radially( starting_position: Vector3, radius: float, navigation_map_rid: RID, scene_tree @@ -81,16 +79,13 @@ static func validate_agent_placement_position(position, radius, existing_units, position + Vector3(x, 0, z).normalized() * radius ) for point_expected_to_be_navigable in points_expected_to_be_navigable: - if not ( - (point_expected_to_be_navigable * Vector3(1, 0, 1)).distance_to( - ( - NavigationServer3D.map_get_closest_point( - navigation_map_rid, point_expected_to_be_navigable - ) - * Vector3(1, 0, 1) + if not (point_expected_to_be_navigable * Vector3(1, 0, 1)).is_equal_approx( + ( + NavigationServer3D.map_get_closest_point( + navigation_map_rid, point_expected_to_be_navigable ) + * Vector3(1, 0, 1) ) - < EPSILON ): return NOT_NAVIGABLE return VALID