update
This commit is contained in:
+131
-16
@@ -23,6 +23,18 @@ var action_points: int = 2
|
|||||||
var target_rotation: float = 0.0
|
var target_rotation: float = 0.0
|
||||||
var rotation_speed: float = 10.0
|
var rotation_speed: float = 10.0
|
||||||
|
|
||||||
|
var spawn_locations = [
|
||||||
|
Vector2i(0, 0), # (0,1,0)
|
||||||
|
Vector2i(0, 1), # (0,1,1)
|
||||||
|
Vector2i(0, 2), # (0,1,2)
|
||||||
|
Vector2i(0, 3), # (0,1,3)
|
||||||
|
Vector2i(0, 4), # (0,1,4)
|
||||||
|
Vector2i(0, 5) # (0,1,5)
|
||||||
|
]
|
||||||
|
|
||||||
|
var spawn_point_selected = false
|
||||||
|
var highlighted_spawn_points = []
|
||||||
|
|
||||||
# Action
|
# Action
|
||||||
var _is_processing_action = false
|
var _is_processing_action = false
|
||||||
var _is_highlighting = false
|
var _is_highlighting = false
|
||||||
@@ -82,12 +94,23 @@ func _ready():
|
|||||||
|
|
||||||
rpc("sync_bot_status", true)
|
rpc("sync_bot_status", true)
|
||||||
|
|
||||||
# Initialize bot-specific components
|
## Initialize bot-specific components
|
||||||
|
#if enhanced_gridmap:
|
||||||
|
#current_position = find_valid_starting_position()
|
||||||
|
#update_player_position(current_position)
|
||||||
|
|
||||||
if enhanced_gridmap:
|
if enhanced_gridmap:
|
||||||
current_position = find_valid_starting_position()
|
current_position = _find_random_spawn_position()
|
||||||
update_player_position(current_position)
|
update_player_position(current_position)
|
||||||
|
spawn_point_selected = true
|
||||||
# Remove this line as goals are now managed by the host
|
|
||||||
|
else:
|
||||||
|
# Human player initialization
|
||||||
|
if enhanced_gridmap:
|
||||||
|
enhanced_gridmap.initialize_astar()
|
||||||
|
enhanced_gridmap.set_diagonal_movement(use_diagonal_movement)
|
||||||
|
highlight_available_spawn_points()
|
||||||
|
# Remove this line as goals are now managed by the host
|
||||||
#append_random_goals()
|
#append_random_goals()
|
||||||
|
|
||||||
playerboard.resize(25)
|
playerboard.resize(25)
|
||||||
@@ -166,7 +189,19 @@ func _unhandled_input(event):
|
|||||||
if not is_multiplayer_authority() or is_bot or is_in_group("Bots"):
|
if not is_multiplayer_authority() or is_bot or is_in_group("Bots"):
|
||||||
set_process_unhandled_input(false)
|
set_process_unhandled_input(false)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Handle spawn point selection if not yet selected
|
||||||
|
if not spawn_point_selected and highlighted_spawn_points.size() > 0:
|
||||||
|
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
|
||||||
|
var camera = get_viewport().get_camera_3d()
|
||||||
|
var from = camera.project_ray_origin(event.position)
|
||||||
|
var to = from + camera.project_ray_normal(event.position) * 1000
|
||||||
|
|
||||||
|
var click_position = raycast_to_grid(from, to)
|
||||||
|
if click_position in highlighted_spawn_points:
|
||||||
|
if select_spawn_point(click_position):
|
||||||
|
return # Spawn point selected successfully
|
||||||
|
|
||||||
# Use get_node_or_null for safer node access
|
# Use get_node_or_null for safer node access
|
||||||
var main = get_tree().get_root().get_node_or_null("Main")
|
var main = get_tree().get_root().get_node_or_null("Main")
|
||||||
if not main:
|
if not main:
|
||||||
@@ -239,21 +274,101 @@ func is_position_occupied(pos: Vector2i) -> bool:
|
|||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
#func find_valid_starting_position() -> Vector2i:
|
||||||
|
#var rng = RandomNumberGenerator.new()
|
||||||
|
#rng.randomize()
|
||||||
|
#
|
||||||
|
#var max_attempts = 100
|
||||||
|
#var attempts = 0
|
||||||
|
#
|
||||||
|
#while attempts < max_attempts:
|
||||||
|
#var x = rng.randi_range(0, enhanced_gridmap.columns - 1)
|
||||||
|
#var y = rng.randi_range(0, enhanced_gridmap.rows - 1)
|
||||||
|
#var pos = Vector2i(x, y)
|
||||||
|
#if not is_position_occupied(pos):
|
||||||
|
#return pos
|
||||||
|
#attempts += 1
|
||||||
|
#
|
||||||
|
#return Vector2i.ZERO
|
||||||
|
|
||||||
func find_valid_starting_position() -> Vector2i:
|
func find_valid_starting_position() -> Vector2i:
|
||||||
var rng = RandomNumberGenerator.new()
|
if is_bot:
|
||||||
rng.randomize()
|
return _find_random_spawn_position()
|
||||||
|
else:
|
||||||
|
highlight_available_spawn_points()
|
||||||
|
# Return temporary position, will be updated when player selects spawn point
|
||||||
|
return Vector2i(-1, -1)
|
||||||
|
|
||||||
var max_attempts = 100
|
func highlight_available_spawn_points():
|
||||||
var attempts = 0
|
if not is_multiplayer_authority() or is_bot or spawn_point_selected:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Clear any existing highlights
|
||||||
|
clear_highlights()
|
||||||
|
highlighted_spawn_points.clear()
|
||||||
|
|
||||||
|
# Check each spawn location
|
||||||
|
for spawn_pos in spawn_locations:
|
||||||
|
if not is_position_occupied(spawn_pos):
|
||||||
|
highlighted_spawn_points.append(spawn_pos)
|
||||||
|
if enhanced_gridmap:
|
||||||
|
# Highlight the cell at y=0 (ground level)
|
||||||
|
enhanced_gridmap.set_cell_item(
|
||||||
|
Vector3i(spawn_pos.x, 0, spawn_pos.y),
|
||||||
|
enhanced_gridmap.hover_item
|
||||||
|
)
|
||||||
|
|
||||||
while attempts < max_attempts:
|
func select_spawn_point(spawn_pos: Vector2i) -> bool:
|
||||||
var x = rng.randi_range(0, enhanced_gridmap.columns - 1)
|
if not is_multiplayer_authority() or is_bot or spawn_point_selected:
|
||||||
var y = rng.randi_range(0, enhanced_gridmap.rows - 1)
|
return false
|
||||||
var pos = Vector2i(x, y)
|
|
||||||
if not is_position_occupied(pos):
|
if spawn_pos in highlighted_spawn_points:
|
||||||
return pos
|
current_position = spawn_pos
|
||||||
attempts += 1
|
spawn_point_selected = true
|
||||||
|
|
||||||
|
# Update position in the world
|
||||||
|
position = grid_to_world(spawn_pos)
|
||||||
|
|
||||||
|
# Clear ALL highlights comprehensively
|
||||||
|
clear_spawn_highlights()
|
||||||
|
|
||||||
|
# Sync with other clients
|
||||||
|
if is_multiplayer_authority():
|
||||||
|
rpc("sync_position", current_position)
|
||||||
|
|
||||||
|
return true
|
||||||
|
return false
|
||||||
|
|
||||||
|
func clear_spawn_highlights():
|
||||||
|
# Clear the highlighted spawn points array
|
||||||
|
for spawn_pos in highlighted_spawn_points:
|
||||||
|
if enhanced_gridmap:
|
||||||
|
# Reset the cell to its original state
|
||||||
|
var cell_item = enhanced_gridmap.get_cell_item(Vector3i(spawn_pos.x, 1, spawn_pos.y))
|
||||||
|
enhanced_gridmap.set_cell_item(
|
||||||
|
Vector3i(spawn_pos.x, 0, spawn_pos.y),
|
||||||
|
enhanced_gridmap.normal_items[0] if cell_item != -1 else -1
|
||||||
|
)
|
||||||
|
|
||||||
|
# Clear the array
|
||||||
|
highlighted_spawn_points.clear()
|
||||||
|
|
||||||
|
# Force an update of the grid visualization
|
||||||
|
if enhanced_gridmap:
|
||||||
|
enhanced_gridmap._update_cell_option_buttons()
|
||||||
|
|
||||||
|
func _find_random_spawn_position() -> Vector2i:
|
||||||
|
var available_positions = []
|
||||||
|
|
||||||
|
for spawn_pos in spawn_locations:
|
||||||
|
if not is_position_occupied(spawn_pos):
|
||||||
|
available_positions.append(spawn_pos)
|
||||||
|
|
||||||
|
if available_positions.size() > 0:
|
||||||
|
var rng = RandomNumberGenerator.new()
|
||||||
|
rng.randomize()
|
||||||
|
return available_positions[rng.randi() % available_positions.size()]
|
||||||
|
|
||||||
return Vector2i.ZERO
|
return Vector2i.ZERO
|
||||||
|
|
||||||
func find_random_valid_position_in_range() -> Vector2i:
|
func find_random_valid_position_in_range() -> Vector2i:
|
||||||
|
|||||||
Reference in New Issue
Block a user