actors can use doors now
This commit is contained in:
parent
32bb0cca21
commit
d1f99275a9
@ -9,22 +9,20 @@ var actor_state = null: set = state_change
|
|||||||
const red = preload("res://tiles/base_tile/red.tres")
|
const red = preload("res://tiles/base_tile/red.tres")
|
||||||
const blue = preload("res://tiles/base_tile/lightblue.tres")
|
const blue = preload("res://tiles/base_tile/lightblue.tres")
|
||||||
|
|
||||||
var current_place_path: Array
|
var current_task_path: Array
|
||||||
var current_room_path: Array
|
var current_room_path: Array
|
||||||
|
|
||||||
var temp_speed = 2
|
|
||||||
var time = 0
|
|
||||||
|
|
||||||
var current_tile = null: set = change_current_tile
|
var current_tile = null: set = change_current_tile
|
||||||
var current_room = null
|
var current_room = null
|
||||||
|
|
||||||
var lookup_actor_to_task = []
|
var lookup_actor_to_task :Array = []
|
||||||
var current_task: Dictionary : set = task_change
|
var current_task: Dictionary : set = task_change
|
||||||
|
|
||||||
@onready var task_creator: TaskCreator = $TaskCreator
|
@onready var task_creator: TaskCreator = $TaskCreator
|
||||||
|
|
||||||
signal current_tile_request
|
signal current_tile_request
|
||||||
signal map_request
|
signal task_path_request
|
||||||
|
signal room_path_request
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
match actor_state:
|
match actor_state:
|
||||||
@ -34,19 +32,23 @@ func _process(delta: float) -> void:
|
|||||||
if current_tile.place_position == current_task.location:
|
if current_tile.place_position == current_task.location:
|
||||||
temp_complete_task()
|
temp_complete_task()
|
||||||
|
|
||||||
if current_room_path:
|
if current_task_path:
|
||||||
if self.position.distance_to(current_room_path[0]) > .1:
|
if current_room_path:
|
||||||
position += position.direction_to(Vector3(current_room_path[0])) * 3 * delta
|
if self.position.distance_to(current_room_path[0]) > .1:
|
||||||
DebugDraw3D.draw_line(self.position, current_room_path[0])
|
position += position.direction_to(Vector3(current_room_path[0])) * 6 * delta
|
||||||
for i in current_room_path.size():
|
DebugDraw3D.draw_line(self.position, current_room_path[0])
|
||||||
if i > 0:
|
for i in current_room_path.size():
|
||||||
var j = current_room_path[i - 1]
|
if i > 0:
|
||||||
DebugDraw3D.draw_line(current_room_path[i], j)
|
var j = current_room_path[i - 1]
|
||||||
|
DebugDraw3D.draw_line(current_room_path[i], j)
|
||||||
|
else:
|
||||||
|
current_room_path.pop_front()
|
||||||
|
if not current_room_path:
|
||||||
|
current_task_path.pop_front()
|
||||||
else:
|
else:
|
||||||
current_room_path.pop_front()
|
get_room_path(current_tile.place_position, current_task_path[0])
|
||||||
current_place_path.pop_front()
|
|
||||||
else:
|
else:
|
||||||
get_room_path(current_tile.place_position, current_place_path[0])
|
get_task_path()
|
||||||
ACTOR_STATE.IDLE:
|
ACTOR_STATE.IDLE:
|
||||||
|
|
||||||
if not lookup_actor_to_task.is_empty():
|
if not lookup_actor_to_task.is_empty():
|
||||||
@ -57,7 +59,7 @@ func _process(delta: float) -> void:
|
|||||||
ACTOR_STATE.PAUSED:
|
ACTOR_STATE.PAUSED:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func state_change(state):
|
func state_change(state :int ) -> void:
|
||||||
actor_state = state
|
actor_state = state
|
||||||
match state:
|
match state:
|
||||||
ACTOR_STATE.ACTIVE:
|
ACTOR_STATE.ACTIVE:
|
||||||
@ -111,19 +113,20 @@ func temp_complete_task():
|
|||||||
task_creator.complete_task(self, completed_task)
|
task_creator.complete_task(self, completed_task)
|
||||||
actor_state = ACTOR_STATE.IDLE
|
actor_state = ACTOR_STATE.IDLE
|
||||||
|
|
||||||
func get_task_path():
|
func get_task_path() -> void:
|
||||||
get_current_tile()
|
get_current_tile()
|
||||||
var start = current_tile.place_position
|
var start :Vector3i = current_tile.place_position
|
||||||
var end = current_task.location
|
var end :Vector3i = current_task.location
|
||||||
|
|
||||||
if destination_in_current_room(end):
|
#if destination_in_current_room(end):
|
||||||
current_place_path = [start, end]
|
#current_task_path = [start, end]
|
||||||
else:
|
#else:
|
||||||
temp_complete_task()
|
##temp_complete_task()
|
||||||
#emit_signal("map_request", self, start, end)
|
emit_signal("task_path_request", self, start, end)
|
||||||
|
|
||||||
func get_room_path(start, end):
|
func get_room_path(start :Vector3i, end :Vector3i) -> void:
|
||||||
current_room_path = current_room.get_room_path(start, end)
|
emit_signal("room_path_request", self, start, end)
|
||||||
|
#current_room_path = current_room.get_room_path(start, end)
|
||||||
|
|
||||||
func destination_in_current_room(destination):
|
func destination_in_current_room(destination):
|
||||||
for i in current_room.room_to_tile:
|
for i in current_room.room_to_tile:
|
||||||
|
|||||||
@ -27,13 +27,13 @@ var tile_count_z_hist: int = 0
|
|||||||
var build_confirm_allowed: bool = true
|
var build_confirm_allowed: bool = true
|
||||||
|
|
||||||
#The object that's currently being built
|
#The object that's currently being built
|
||||||
var current_object: Object = null
|
var current_object
|
||||||
#Where that object can be placed
|
#Where that object can be placed
|
||||||
var available_placements :Array = []
|
var available_placements :Array = []
|
||||||
var current_placement :Vector3
|
var current_placement :Vector3
|
||||||
|
|
||||||
#Tracks parts of the room currently being built
|
#Tracks parts of the room currently being built
|
||||||
var current_room: Object = null
|
var current_room
|
||||||
|
|
||||||
@onready var map :PlaceMap = $PlaceMap
|
@onready var map :PlaceMap = $PlaceMap
|
||||||
|
|
||||||
@ -188,6 +188,12 @@ func build_selection() -> void:
|
|||||||
|
|
||||||
create_room(selection_dict)
|
create_room(selection_dict)
|
||||||
|
|
||||||
|
for i :Vector3i in selection_dict.keys():
|
||||||
|
map.tile_map[i * 12]["state"] = PlaceMap.TILE_STATE.OPEN
|
||||||
|
for j :Vector3i in Tile.direction_vector_dict.values():
|
||||||
|
if not selection_dict.keys().has(i - j):
|
||||||
|
map.wall_map[(i * 12) - (j * 6)]["state"] = PlaceMap.WALL_STATE.CLOSED
|
||||||
|
|
||||||
for i :Vector3i in selection_dict.keys():
|
for i :Vector3i in selection_dict.keys():
|
||||||
var tile: Object = lookup_place_to_tile[i]
|
var tile: Object = lookup_place_to_tile[i]
|
||||||
tile.selection_mode = Tile.SEL_MODE.NONE
|
tile.selection_mode = Tile.SEL_MODE.NONE
|
||||||
@ -219,22 +225,19 @@ func create_room(selection :Dictionary) -> Room:
|
|||||||
|
|
||||||
$RoomContainer.add_child(room)
|
$RoomContainer.add_child(room)
|
||||||
|
|
||||||
for i :Vector3i in selection.keys():
|
map.room_map[room] = {
|
||||||
map.tile_map[i * 12]["state"] = PlaceMap.TILE_STATE.OPEN
|
"tiles": selection.values(),
|
||||||
for j :Vector3i in Tile.direction_vector_dict.values():
|
"doors": [],
|
||||||
if not selection.keys().has(i - j):
|
}
|
||||||
map.wall_map[(i * 12) - (j * 6)]["state"] = PlaceMap.WALL_STATE.CLOSED
|
|
||||||
|
|
||||||
map.room_map[room] = selection.values()
|
|
||||||
|
|
||||||
for i :Tile in room.room_to_tile:
|
for i :Tile in room.room_to_tile:
|
||||||
i.lookup_tile_to_room = room
|
i.lookup_tile_to_room = room
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
room.init_room(selection)
|
||||||
|
|
||||||
return room
|
return room
|
||||||
|
|
||||||
func init_object(object):
|
func init_object(object) -> void:
|
||||||
#Instantiates the object to be placed
|
#Instantiates the object to be placed
|
||||||
|
|
||||||
match object:
|
match object:
|
||||||
@ -296,7 +299,7 @@ func hover_object(mouse_pos :Vector3) -> void:
|
|||||||
closest_distance = distance
|
closest_distance = distance
|
||||||
closest = i
|
closest = i
|
||||||
|
|
||||||
current_placement = closest
|
current_placement = closest
|
||||||
current_object.position = current_placement
|
current_object.position = current_placement
|
||||||
current_object.rotation_degrees = Vector3(0, 180 * fmod(closest.x, 1), 0)
|
current_object.rotation_degrees = Vector3(0, 180 * fmod(closest.x, 1), 0)
|
||||||
|
|
||||||
@ -305,11 +308,47 @@ func hover_object(mouse_pos :Vector3) -> void:
|
|||||||
|
|
||||||
func confirm_object() -> void:
|
func confirm_object() -> void:
|
||||||
#Places the object at the hovered location
|
#Places the object at the hovered location
|
||||||
#TODO: this is very sloppy
|
|
||||||
|
|
||||||
if current_object is Door:
|
if current_object is Door:
|
||||||
|
var pos :Vector3i = Vector3i(current_placement * 12)
|
||||||
|
#map.wall_map[pos]["state"] = map.WALL_STATE.DOOR
|
||||||
|
#if pos.x % 12 == 0:
|
||||||
|
#tile_1_pos = pos + Vector3i(0, 0, -6)
|
||||||
|
#tile_2_pos = pos + Vector3i(0, 0, 6)
|
||||||
|
#else:
|
||||||
|
#tile_1_pos = pos + Vector3i(-6, 0, 0)
|
||||||
|
#tile_2_pos = pos + Vector3i(6, 0, 0)
|
||||||
|
#var tile_1 :Tile = map.tile_map[tile_1_pos]["object"]
|
||||||
|
#var tile_2 :Tile = map.tile_map[tile_2_pos]["object"]
|
||||||
|
|
||||||
pass
|
#tile_1.update_faces()
|
||||||
|
#tile_2.update_faces()
|
||||||
|
map.write_door(pos)
|
||||||
|
#map.room_map[tile_1.lookup_tile_to_room]["tiles"].append(tile_2)
|
||||||
|
#tile_1.lookup_tile_to_room.update_nav()
|
||||||
|
#var point_pos_1 :Vector3i = pos - ((pos - tile_1_pos) / 2)
|
||||||
|
#var id_1 :int = map.place_nav.get_available_point_id()
|
||||||
|
#map.place_nav.add_point(id_1, point_pos_1)
|
||||||
|
#for i :Vector3i in map.room_map[tile_1.lookup_tile_to_room]["doors"]:
|
||||||
|
#var id :int = map.place_nav.get_closest_point(i)
|
||||||
|
#map.place_nav.connect_points(id_1, id)
|
||||||
|
#map.room_map[tile_1.lookup_tile_to_room]["doors"].append(point_pos_1)
|
||||||
|
#map.room_map[tile_2.lookup_tile_to_room]["tiles"].append(tile_1)
|
||||||
|
#tile_2.lookup_tile_to_room.update_nav()
|
||||||
|
#var point_pos_2 :Vector3i = pos - ((pos - tile_2_pos) / 2)
|
||||||
|
#var id_2 :int = map.place_nav.get_available_point_id()
|
||||||
|
#map.place_nav.add_point(id_2, point_pos_2)
|
||||||
|
#for i :Vector3i in map.room_map[tile_2.lookup_tile_to_room]["doors"]:
|
||||||
|
#var id :int = map.place_nav.get_closest_point(i)
|
||||||
|
#map.place_nav.connect_points(id_2, id)
|
||||||
|
#map.room_map[tile_2.lookup_tile_to_room]["doors"].append(point_pos_2)
|
||||||
|
#
|
||||||
|
#map.place_nav.connect_points(id_1, id_2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
current_object.queue_free()
|
||||||
#
|
#
|
||||||
#var tile_1: Object
|
#var tile_1: Object
|
||||||
#var tile_2: Object
|
#var tile_2: Object
|
||||||
@ -395,7 +434,8 @@ func _on_actor_container_child_entered_tree(node: Node) -> void:
|
|||||||
#Connects signals from created actors
|
#Connects signals from created actors
|
||||||
|
|
||||||
node.connect("current_tile_request", give_tile)
|
node.connect("current_tile_request", give_tile)
|
||||||
node.connect("map_request", give_map)
|
node.connect("task_path_request", give_path)
|
||||||
|
node.connect("room_path_request", give_room)
|
||||||
if node.has_node("TaskCreator"):
|
if node.has_node("TaskCreator"):
|
||||||
var tasker = node.get_node("TaskCreator")
|
var tasker = node.get_node("TaskCreator")
|
||||||
tasker.connect("record_task", record_task)
|
tasker.connect("record_task", record_task)
|
||||||
@ -403,38 +443,49 @@ func _on_actor_container_child_entered_tree(node: Node) -> void:
|
|||||||
|
|
||||||
func _on_room_container_child_entered_tree(node: Node) -> void:
|
func _on_room_container_child_entered_tree(node: Node) -> void:
|
||||||
#Connects signals from created rooms
|
#Connects signals from created rooms
|
||||||
pass
|
|
||||||
|
|
||||||
func give_map(actor, start, end):
|
node.connect("nav_request", give_nav)
|
||||||
var end_tile:Tile = lookup_place_to_tile[end]
|
|
||||||
if end_tile.construction_mode == Tile.CON_MODE.BUILT:
|
func give_nav(room):
|
||||||
|
map.give_nav(room)
|
||||||
var start_id = map.get_available_point_id()
|
|
||||||
map.add_point(start_id, start)
|
func give_path(actor :Actor, start :Vector3i, end :Vector3i) -> void:
|
||||||
var start_room_doors = lookup_place_to_tile[start].lookup_tile_to_room.room_to_door
|
var start_tile :Tile = lookup_place_to_tile[start]
|
||||||
if start_room_doors == []:
|
var end_tile :Tile = lookup_place_to_tile[end]
|
||||||
actor.temp_complete_task()
|
map.give_path(actor, start_tile, end_tile)
|
||||||
return
|
|
||||||
for i in start_room_doors:
|
func give_room(actor, start, end):
|
||||||
var door_id = map.get_closest_point(i.position)
|
map.give_room(actor, start, end)
|
||||||
map.connect_points(start_id, door_id)
|
|
||||||
|
#var end_tile:Tile = lookup_place_to_tile[end]
|
||||||
var end_id = map.get_available_point_id()
|
#if end_tile.construction_mode == Tile.CON_MODE.BUILT:
|
||||||
map.add_point(end_id, end)
|
#
|
||||||
var end_room_doors = lookup_place_to_tile[end].lookup_tile_to_room.room_to_door
|
#var start_id = map.get_available_point_id()
|
||||||
if end_room_doors == []:
|
#map.add_point(start_id, start)
|
||||||
actor.temp_complete_task()
|
#var start_room_doors = lookup_place_to_tile[start].lookup_tile_to_room.room_to_door
|
||||||
return
|
#if start_room_doors == []:
|
||||||
for i in end_room_doors:
|
#actor.temp_complete_task()
|
||||||
var door_id = map.get_closest_point(i.position)
|
#return
|
||||||
map.connect_points(end_id, door_id)
|
#for i in start_room_doors:
|
||||||
var place_path_id = map.get_id_path(start_id, end_id)
|
#var door_id = map.get_closest_point(i.position)
|
||||||
var place_path_pos = []
|
#map.connect_points(start_id, door_id)
|
||||||
for i in place_path_id:
|
#
|
||||||
place_path_pos.append(map.get_point_position(i))
|
#var end_id = map.get_available_point_id()
|
||||||
actor.current_place_path = place_path_pos
|
#map.add_point(end_id, end)
|
||||||
else:
|
#var end_room_doors = lookup_place_to_tile[end].lookup_tile_to_room.room_to_door
|
||||||
actor.temp_complete_task()
|
#if end_room_doors == []:
|
||||||
|
#actor.temp_complete_task()
|
||||||
|
#return
|
||||||
|
#for i in end_room_doors:
|
||||||
|
#var door_id = map.get_closest_point(i.position)
|
||||||
|
#map.connect_points(end_id, door_id)
|
||||||
|
#var place_path_id = map.get_id_path(start_id, end_id)
|
||||||
|
#var place_path_pos = []
|
||||||
|
#for i in place_path_id:
|
||||||
|
#place_path_pos.append(map.get_point_position(i))
|
||||||
|
#actor.current_place_path = place_path_pos
|
||||||
|
#else:
|
||||||
|
#actor.temp_complete_task()
|
||||||
|
|
||||||
func give_tile(actor):
|
func give_tile(actor):
|
||||||
#Responds to an actor's request for its current tile
|
#Responds to an actor's request for its current tile
|
||||||
|
|||||||
@ -1,19 +1,21 @@
|
|||||||
extends Node
|
extends Node
|
||||||
class_name Room
|
class_name Room
|
||||||
|
|
||||||
var room_to_tile = []: set = setup_path_grid
|
var room_to_tile :Array = []
|
||||||
|
|
||||||
var path_grid = AStar3D.new()
|
var nav :AStar3D = AStar3D.new()
|
||||||
|
|
||||||
var room_to_door = []
|
var lookup_room_to_door :Array = []
|
||||||
|
|
||||||
var place_id: int = 0
|
var place_id: int = 0
|
||||||
|
|
||||||
|
signal nav_request
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
for i in path_grid.get_point_ids():
|
for i in nav.get_point_ids():
|
||||||
for j in path_grid.get_point_connections(i):
|
for j in nav.get_point_connections(i):
|
||||||
var i_pos = path_grid.get_point_position(i)
|
var i_pos :Vector3 = nav.get_point_position(i)
|
||||||
var j_pos = path_grid.get_point_position(j)
|
var j_pos :Vector3 = nav.get_point_position(j)
|
||||||
if i > 0:
|
if i > 0:
|
||||||
DebugDraw3D.draw_line(i_pos, j_pos, Color(0.613, 0.613, 0.613, 1.0))
|
DebugDraw3D.draw_line(i_pos, j_pos, Color(0.613, 0.613, 0.613, 1.0))
|
||||||
|
|
||||||
@ -33,36 +35,78 @@ func save():
|
|||||||
func init_room(new_dict):
|
func init_room(new_dict):
|
||||||
#When a room is created, run through these steps
|
#When a room is created, run through these steps
|
||||||
|
|
||||||
setup_path_grid(new_dict)
|
#setup_path_grid(new_dict)
|
||||||
|
update_nav()
|
||||||
for i in new_dict.values():
|
for i in new_dict.values():
|
||||||
i.room = self
|
i.lookup_tile_to_room = self
|
||||||
|
|
||||||
|
func update_nav() -> void:
|
||||||
|
emit_signal("nav_request", self)
|
||||||
|
|
||||||
func setup_path_grid(new_array):
|
func setup_path_grid(new_array):
|
||||||
#Sets up the A* grid of tiles that are in this room.
|
#Sets up the A* grid of tiles that are in this room.
|
||||||
#TODO: Better grid changing
|
#TODO: Better grid changing
|
||||||
|
pass
|
||||||
|
#nav.clear()
|
||||||
|
#room_to_tile = new_array
|
||||||
|
#var room_to_tile_positions: Array
|
||||||
|
#
|
||||||
|
#for i in room_to_tile:
|
||||||
|
#var id = nav.get_available_point_id()
|
||||||
|
#var point_pos = Vector3(i.place_position)
|
||||||
|
#nav.add_point(id, point_pos)
|
||||||
|
#room_to_tile_positions.append(point_pos)
|
||||||
|
#
|
||||||
|
#for n in Tile.direction_vector_dict.values():
|
||||||
|
#var neighbor_pos = point_pos + Vector3(n)
|
||||||
|
#if room_to_tile_positions.has(neighbor_pos):
|
||||||
|
#var closest = nav.get_closest_point(neighbor_pos)
|
||||||
|
#if (neighbor_pos) == Vector3(nav.get_point_position(closest)):
|
||||||
|
#nav.connect_points(id, closest)
|
||||||
|
|
||||||
|
func get_room_path(start :Vector3i, end :Vector3i) -> Array:
|
||||||
|
|
||||||
|
var start_point = nav.get_closest_point(Vector3(start))
|
||||||
|
var end_point = nav.get_closest_point(Vector3(end))
|
||||||
|
var path = nav.get_point_path(start_point, end_point)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
path_grid.clear()
|
|
||||||
room_to_tile = new_array
|
|
||||||
var room_to_tile_positions: Array
|
|
||||||
|
|
||||||
for i in room_to_tile:
|
|
||||||
var id = path_grid.get_available_point_id()
|
|
||||||
var point_pos = Vector3(i.place_position)
|
|
||||||
path_grid.add_point(id, point_pos)
|
|
||||||
room_to_tile_positions.append(point_pos)
|
|
||||||
|
#for i in room_to_tile:
|
||||||
|
#var place_end :Vector3 = Vector3(end)
|
||||||
|
#var pos = Vector3(i.place_position)
|
||||||
|
#if pos == place_end:
|
||||||
|
|
||||||
for n in Tile.direction_vector_dict.values():
|
#if fmod(place_end.x, 1) != 0:
|
||||||
var neighbor_pos = point_pos + Vector3(n)
|
#var tst1 = place_end + Vector3(-0.5, 0, 0)
|
||||||
if room_to_tile_positions.has(neighbor_pos):
|
#var tst2 = place_end + Vector3(0.5, 0, 0)
|
||||||
var closest = path_grid.get_closest_point(neighbor_pos)
|
#if pos == tst1:
|
||||||
if (neighbor_pos) == Vector3(path_grid.get_point_position(closest)):
|
#var start_point = nav.get_closest_point(Vector3(start))
|
||||||
path_grid.connect_points(id, closest)
|
#var end_point = nav.get_closest_point(pos)
|
||||||
|
#var path = nav.get_point_path(start_point, end_point)
|
||||||
func get_room_path(start, end):
|
#return path
|
||||||
for i in room_to_tile:
|
#if pos == tst2:
|
||||||
if i.place_position == Vector3i(end):
|
#var start_point = nav.get_closest_point(Vector3(start))
|
||||||
var start_point = path_grid.get_closest_point(Vector3(start))
|
#var end_point = nav.get_closest_point(pos)
|
||||||
var end_point = path_grid.get_closest_point(Vector3(end))
|
#var path = nav.get_point_path(start_point, end_point)
|
||||||
var path = path_grid.get_point_path(start_point, end_point)
|
#return path
|
||||||
return path
|
#elif fmod(place_end.z, 1) != 0:
|
||||||
return false
|
#var tst1 = place_end + Vector3(0, 0, -0.5)
|
||||||
|
#var tst2 = place_end + Vector3(0, 0, 0.5)
|
||||||
|
#if pos == tst1:
|
||||||
|
#var start_point = nav.get_closest_point(Vector3(start))
|
||||||
|
#var end_point = nav.get_closest_point(pos)
|
||||||
|
#var path = nav.get_point_path(start_point, end_point)
|
||||||
|
#return path
|
||||||
|
#if pos == tst2:
|
||||||
|
#var start_point = nav.get_closest_point(Vector3(start))
|
||||||
|
#var end_point = nav.get_closest_point(pos)
|
||||||
|
#var path = nav.get_point_path(start_point, end_point)
|
||||||
|
#return path
|
||||||
|
return []
|
||||||
|
|||||||
@ -10,7 +10,7 @@ var room_map :Dictionary = {}
|
|||||||
var place_nav :AStar3D = AStar3D.new()
|
var place_nav :AStar3D = AStar3D.new()
|
||||||
|
|
||||||
enum TILE_STATE {CLOSED, OPEN}
|
enum TILE_STATE {CLOSED, OPEN}
|
||||||
enum WALL_STATE {CLOSED, OPEN, DOOR}
|
enum WALL_STATE {OPEN, CLOSED, DOOR}
|
||||||
|
|
||||||
const direction_vectors :Array = [
|
const direction_vectors :Array = [
|
||||||
Vector3i(0, 0, -12),
|
Vector3i(0, 0, -12),
|
||||||
@ -26,6 +26,8 @@ func _process(_delta: float) -> void:
|
|||||||
var built_walls :Array = []
|
var built_walls :Array = []
|
||||||
var tiles :Array = []
|
var tiles :Array = []
|
||||||
var walls :Array = []
|
var walls :Array = []
|
||||||
|
var astar_points :Array = place_nav.get_point_ids()
|
||||||
|
var astar_pos :Array = []
|
||||||
for i :Vector3i in tile_map.keys():
|
for i :Vector3i in tile_map.keys():
|
||||||
var pos :Vector3 = Vector3(i) / 12
|
var pos :Vector3 = Vector3(i) / 12
|
||||||
if tile_map[i]["state"] == TILE_STATE.CLOSED:
|
if tile_map[i]["state"] == TILE_STATE.CLOSED:
|
||||||
@ -38,10 +40,13 @@ func _process(_delta: float) -> void:
|
|||||||
walls.append(pos)
|
walls.append(pos)
|
||||||
elif wall_map[i]["state"] == WALL_STATE.CLOSED:
|
elif wall_map[i]["state"] == WALL_STATE.CLOSED:
|
||||||
built_walls.append(pos)
|
built_walls.append(pos)
|
||||||
|
for i :int in astar_points:
|
||||||
|
astar_pos.append(Vector3(place_nav.get_point_position(i)) / 12)
|
||||||
DebugDraw3D.draw_points(built_tiles, 0, 0.2, color_tile_built)
|
DebugDraw3D.draw_points(built_tiles, 0, 0.2, color_tile_built)
|
||||||
DebugDraw3D.draw_points(built_walls, 0, 0.2, color_wall_built)
|
DebugDraw3D.draw_points(built_walls, 0, 0.2, color_wall_built)
|
||||||
DebugDraw3D.draw_points(tiles, 0, 0.2, Color(0.459, 0.404, 0.866, 1.0))
|
DebugDraw3D.draw_points(tiles, 0, 0.2, Color(0.459, 0.404, 0.866, 1.0))
|
||||||
DebugDraw3D.draw_points(walls, 0, 0.2, Color(0.343, 0.409, 0.528, 1.0))
|
DebugDraw3D.draw_points(walls, 0, 0.2, Color(0.343, 0.409, 0.528, 1.0))
|
||||||
|
DebugDraw3D.draw_points(astar_pos, 0, 0.2, Color(0.657, 0.004, 0.956, 1.0))
|
||||||
|
|
||||||
func temp_create_map() -> void:
|
func temp_create_map() -> void:
|
||||||
#TEMP: just makes a square. Should be replaced with premade maps eventually.
|
#TEMP: just makes a square. Should be replaced with premade maps eventually.
|
||||||
@ -68,8 +73,111 @@ func give_walls(tile :Tile) -> void:
|
|||||||
if tile_map.has(tile.map_position + i):
|
if tile_map.has(tile.map_position + i):
|
||||||
var neighbor :Tile = tile_map[tile.map_position + i]["object"]
|
var neighbor :Tile = tile_map[tile.map_position + i]["object"]
|
||||||
var room :Room = tile.lookup_tile_to_room
|
var room :Room = tile.lookup_tile_to_room
|
||||||
if not room_map[room].has(neighbor):
|
if not room_map[room]["tiles"].has(neighbor):
|
||||||
if wall_map[tile.map_position + (i / 2)]["state"] == PlaceMap.WALL_STATE.CLOSED :
|
temp_dict[Vector3(i / 2) / 12] = wall_map[tile.map_position + (i / 2)]["state"]
|
||||||
temp_dict[Vector3(i / 2) / 12] = PlaceMap.WALL_STATE.CLOSED
|
|
||||||
if temp_dict:
|
if temp_dict:
|
||||||
tile.face_dict = temp_dict.duplicate()
|
tile.face_dict = temp_dict.duplicate()
|
||||||
|
|
||||||
|
func give_nav(room :Room) -> void:
|
||||||
|
var nav :AStar3D = room.nav
|
||||||
|
nav.clear()
|
||||||
|
var pos_array :Array = []
|
||||||
|
for i :Tile in room_map[room]["tiles"]:
|
||||||
|
var id :int = nav.get_available_point_id()
|
||||||
|
var point_pos :Vector3 = Vector3(i.place_position)
|
||||||
|
nav.add_point(id, point_pos)
|
||||||
|
pos_array.append(point_pos)
|
||||||
|
|
||||||
|
for n :Vector3 in Tile.direction_vector_dict.values():
|
||||||
|
var neighbor_pos :Vector3 = point_pos + Vector3(n)
|
||||||
|
if pos_array.has(neighbor_pos):
|
||||||
|
var closest :int = nav.get_closest_point(neighbor_pos)
|
||||||
|
if (neighbor_pos) == Vector3(nav.get_point_position(closest)):
|
||||||
|
nav.connect_points(id, closest)
|
||||||
|
|
||||||
|
func give_path(actor :Actor, start :Tile, end :Tile) -> void:
|
||||||
|
# TODO: Sloppy
|
||||||
|
|
||||||
|
if tile_map[end.map_position]["state"] == TILE_STATE.OPEN:
|
||||||
|
|
||||||
|
if start.lookup_tile_to_room == end.lookup_tile_to_room:
|
||||||
|
actor.current_task_path = [start.map_position, end.map_position]
|
||||||
|
return
|
||||||
|
|
||||||
|
var start_id :int = place_nav.get_available_point_id()
|
||||||
|
place_nav.add_point(start_id, start.map_position)
|
||||||
|
var start_room_doors :Array = room_map[start.lookup_tile_to_room]["doors"]
|
||||||
|
if start_room_doors == []:
|
||||||
|
actor.temp_complete_task()
|
||||||
|
return
|
||||||
|
for i :Vector3i in start_room_doors:
|
||||||
|
var door_id :int = place_nav.get_closest_point(i)
|
||||||
|
place_nav.connect_points(start_id, door_id)
|
||||||
|
|
||||||
|
var end_id :int = place_nav.get_available_point_id()
|
||||||
|
place_nav.add_point(end_id, end.map_position)
|
||||||
|
var end_room_doors :Array = room_map[end.lookup_tile_to_room]["doors"]
|
||||||
|
if end_room_doors == []:
|
||||||
|
actor.temp_complete_task()
|
||||||
|
return
|
||||||
|
for i :Vector3i in end_room_doors:
|
||||||
|
var door_id :int = place_nav.get_closest_point(i)
|
||||||
|
place_nav.connect_points(end_id, door_id)
|
||||||
|
var place_path_id :Array = place_nav.get_id_path(start_id, end_id)
|
||||||
|
var place_path_pos :Array = []
|
||||||
|
for i :int in place_path_id:
|
||||||
|
place_path_pos.append(place_nav.get_point_position(i))
|
||||||
|
actor.current_task_path = place_path_pos
|
||||||
|
place_nav.remove_point(start_id)
|
||||||
|
place_nav.remove_point(end_id)
|
||||||
|
else:
|
||||||
|
actor.temp_complete_task()
|
||||||
|
|
||||||
|
func write_door(pos :Vector3i) -> void:
|
||||||
|
var tile_1_pos :Vector3i
|
||||||
|
var tile_2_pos :Vector3i
|
||||||
|
if pos.x % 12 == 0:
|
||||||
|
tile_1_pos = pos + Vector3i(0, 0, -6)
|
||||||
|
tile_2_pos = pos + Vector3i(0, 0, 6)
|
||||||
|
else:
|
||||||
|
tile_1_pos = pos + Vector3i(-6, 0, 0)
|
||||||
|
tile_2_pos = pos + Vector3i(6, 0, 0)
|
||||||
|
var tile_1 :Tile = tile_map[tile_1_pos]["object"]
|
||||||
|
var tile_2 :Tile = tile_map[tile_2_pos]["object"]
|
||||||
|
|
||||||
|
wall_map[pos]["state"] = WALL_STATE.DOOR
|
||||||
|
tile_1.update_faces()
|
||||||
|
tile_2.update_faces()
|
||||||
|
|
||||||
|
room_map[tile_1.lookup_tile_to_room]["tiles"].append(tile_2)
|
||||||
|
tile_1.lookup_tile_to_room.update_nav()
|
||||||
|
var point_pos_1 :Vector3i = pos - ((pos - tile_1_pos) / 2)
|
||||||
|
var id_1 :int = place_nav.get_available_point_id()
|
||||||
|
place_nav.add_point(id_1, point_pos_1)
|
||||||
|
for i :Vector3i in room_map[tile_1.lookup_tile_to_room]["doors"]:
|
||||||
|
var id :int = place_nav.get_closest_point(i)
|
||||||
|
place_nav.connect_points(id_1, id)
|
||||||
|
room_map[tile_1.lookup_tile_to_room]["doors"].append(point_pos_1)
|
||||||
|
|
||||||
|
room_map[tile_2.lookup_tile_to_room]["tiles"].append(tile_1)
|
||||||
|
tile_2.lookup_tile_to_room.update_nav()
|
||||||
|
var point_pos_2 :Vector3i = pos - ((pos - tile_2_pos) / 2)
|
||||||
|
var id_2 :int = place_nav.get_available_point_id()
|
||||||
|
place_nav.add_point(id_2, point_pos_2)
|
||||||
|
for i :Vector3i in room_map[tile_2.lookup_tile_to_room]["doors"]:
|
||||||
|
var id :int = place_nav.get_closest_point(i)
|
||||||
|
place_nav.connect_points(id_2, id)
|
||||||
|
room_map[tile_2.lookup_tile_to_room]["doors"].append(point_pos_2)
|
||||||
|
|
||||||
|
place_nav.connect_points(id_1, id_2)
|
||||||
|
|
||||||
|
func give_room(actor, start, end) -> void:
|
||||||
|
for i in room_map.keys():
|
||||||
|
for j in room_map[i]["tiles"]:
|
||||||
|
if Vector3i(end) == j.map_position:
|
||||||
|
actor.current_room_path = i.get_room_path(start, j.place_position)
|
||||||
|
return
|
||||||
|
for j in room_map[i]["doors"]:
|
||||||
|
if Vector3i(end) == j:
|
||||||
|
actor.current_room_path = i.get_room_path(start, Vector3i(round(Vector3(end) / 12)))
|
||||||
|
return
|
||||||
|
|||||||
@ -74,26 +74,29 @@ func save():
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
func update_faces():
|
func update_faces() -> void:
|
||||||
#Changes the walls when relevant
|
#Changes the walls when relevant
|
||||||
emit_signal("wall_request", self)
|
emit_signal("wall_request", self)
|
||||||
|
|
||||||
func build_faces(dict :Dictionary) -> void:
|
func build_faces(dict :Dictionary) -> void:
|
||||||
face_dict = dict
|
|
||||||
for i :Vector3 in dict:
|
for i :Vector3 in dict:
|
||||||
var wall :Wall = load_wall.instantiate()
|
match dict[i]:
|
||||||
wall.position = Vector3(i)
|
PlaceMap.WALL_STATE.OPEN:
|
||||||
$Walls.add_child(wall)
|
face_dict[i].queue_free()
|
||||||
match i:
|
PlaceMap.WALL_STATE.CLOSED:
|
||||||
Vector3(0, 0, 0.5):
|
var wall :Wall = load_wall.instantiate()
|
||||||
wall.rotation_degrees = Vector3(0, -180, 0)
|
wall.position = Vector3(i)
|
||||||
Vector3(-0.5, 0, 0):
|
$Walls.add_child(wall)
|
||||||
wall.rotation_degrees = Vector3(0, -270, 0)
|
match i:
|
||||||
Vector3(0.5, 0, 0):
|
Vector3(0, 0, 0.5):
|
||||||
wall.rotation_degrees = Vector3(0, -90, 0)
|
wall.rotation_degrees = Vector3(0, -180, 0)
|
||||||
|
Vector3(-0.5, 0, 0):
|
||||||
|
wall.rotation_degrees = Vector3(0, -270, 0)
|
||||||
|
Vector3(0.5, 0, 0):
|
||||||
|
wall.rotation_degrees = Vector3(0, -90, 0)
|
||||||
|
face_dict[i] = wall
|
||||||
|
PlaceMap.WALL_STATE.DOOR:
|
||||||
|
face_dict[i].queue_free()
|
||||||
|
|
||||||
#for i in new_dict.keys():
|
#for i in new_dict.keys():
|
||||||
#if face_dict.has(i):
|
#if face_dict.has(i):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user