Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooses2k committed Jan 8, 2024
2 parents 50b22d8 + f7d81fe commit f0beddd
Show file tree
Hide file tree
Showing 76 changed files with 1,075 additions and 596 deletions.
33 changes: 20 additions & 13 deletions core/ai/bt_root.gd
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
class_name BTRoot extends BTSequence


onready var character: Character = owner
signal pre_tick()
signal post_tick()

var tick_delta : float = 0.1

onready var character: Character = owner


func _ready() -> void:
._ready()
_setup_ai_tree()
var timer = Timer.new()
timer.one_shot = false
timer.wait_time = tick_delta
timer.connect("timeout", self, "run_tick")
add_child(timer)
timer.start()


func run_tick():
emit_signal("pre_tick")
tick(character.character_state)
emit_signal("post_tick")

# Delete mind, cancelling further planning and speech.
func _on_character_died() -> void:
queue_free()


func _setup_ai_tree() -> void:
_setup_node(self)


func _setup_node(node : BTNode) -> void:
connect("pre_tick", node, "pre_tick")
connect("post_tick", node, "post_tick")
Expand All @@ -27,12 +39,7 @@ func _setup_node(node : BTNode) -> void:
if child is BTNode:
_setup_node(child)

func _ready() -> void:
._ready()
_setup_ai_tree()
var timer = Timer.new()
timer.one_shot = false
timer.wait_time = tick_delta
timer.connect("timeout", self, "run_tick")
add_child(timer)
timer.start()

# Delete mind, cancelling further planning and speech.
func _on_character_died() -> void:
queue_free()
2 changes: 0 additions & 2 deletions core/ai/character_state.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ var interest_machine
var character
var target


var move_direction := Vector3.ZERO setget set_move_direction
var face_direction := Vector3.FORWARD setget set_face_direction
var target_position := Vector3.ZERO setget set_target_position
var interaction_target : Node = null


var path := [] setget , get_path
var path_needs_update := false

Expand Down
4 changes: 2 additions & 2 deletions core/ai/flow_nodes/bt_selector.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class_name BTSelector, "res://core/ai/phold_icons/selector.svg" extends BTControlFlow


# If and when a node is a SUCCESS, end Selector.


Expand All @@ -10,7 +9,8 @@ func _tick(state : CharacterState) -> int:
if status != BTResult.FAILED:
return status
return BTResult.FAILED
#


#func _tick(_state : CharacterState, root : BTNode) -> int:
# var result = BTResult.OK
# for child in self.child_nodes_bt:
Expand Down
6 changes: 5 additions & 1 deletion core/ai/gun_nodes/action_nodes/bt_gun_reload.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ signal character_reloaded # For signalling speech
func _tick(state : CharacterState) -> int:
var inventory = state.character.inventory
var equipment = state.character.inventory.current_mainhand_equipment as GunItem

var animation_tree : AnimationTree = $"%AnimationTree"
var animation_player : AnimationPlayer = $"%AnimationPlayer"
for ammo_type in equipment.ammo_types:
if inventory.tiny_items.has(ammo_type) and inventory.tiny_items[ammo_type] > 0:
if equipment.current_ammo < 1:
equipment.reload()
animation_tree.set("parameters/" + str(equipment.item_name) + "/active", true)
equipment.animation_player.play("reload")
# yield(get_tree().create_timer(equipment.animation_player.get_animation("reload").length), "timeout")
emit_signal("character_reloaded")
return BTResult.OK
return BTResult.FAILED
26 changes: 12 additions & 14 deletions core/ai/interest_nodes/check_nodes/bt_interest_machine.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,25 @@ class_name BTInterestMachine extends BTCheck
signal player_detected(player, position)
signal indirect_event_detected()


export var detection_threshold := 0.8
export var attention_span := 5.0
export var decay_rate := 2.0


var events := {}


class Event:
var emissor: CharacterSense = null
var emitter: CharacterSense = null
var position := Vector3.ZERO
var interest := 0.0
var object: Object

var time := 0.0

func _init(_interest: int, _position: Vector3, _object: Object, _emissor: CharacterSense) -> void:
func _init(_interest: int, _position: Vector3, _object: Object, _emitter: CharacterSense) -> void:
interest = _interest
position = _position
emissor = _emissor
emitter = _emitter
object = _object
time = 0.0

Expand All @@ -43,26 +41,26 @@ class Event:
return str({"interest": interest, "position": position, "object": object.name})


func set_event(interest: int, position: Vector3, object: Object, emissor: CharacterSense) -> void:
func set_event(interest: int, position: Vector3, object: Object, emitter: CharacterSense) -> void:
if !events.has(object) or (events.has(object) and events[object].interest < ( interest * detection_threshold)):
if interest > detection_threshold and (emissor is TouchSensor or emissor is VisualSensor) and object is Player:
if interest > detection_threshold and (emitter is TouchSensor or emitter is VisualSensor) and object is Player:
emit_signal("player_detected", object, position)
else: emit_signal("indirect_event_detected")

if events.has(object):
# prints("Has object", events[object].interest, interest)

if interest >= events[object].interest:
# print("Overriding event")
events[object].set_interest_level(interest)
events[object].position = position
events[object].emissor = emissor
else: events[object] = Event.new(interest, position, object, emissor)
events[object].emitter = emitter
else: events[object] = Event.new(interest, position, object, emitter)


func remove_event(object: Object) -> void:
if events.has(object): events.erase(object)


func _process(delta: float) -> void:
for event in events.values(): if event.tick(delta, self):
Expand All @@ -83,11 +81,11 @@ func get_most_interesting() -> Event:
func _tick(state: CharacterState) -> int:
var most_interesting := get_most_interesting()
state.interest_machine = self

if is_instance_valid(most_interesting):
state.target_position = most_interesting.position
state.target = most_interesting
# prints("Set new position", state.target.position , state.target.interest, state.target.emissor.name, state.target.object.name)
# prints("Set new position", state.target.position , state.target.interest, state.target.emitter.name, state.target.object.name)
return BTResult.OK

state.target = null
Expand Down
2 changes: 1 addition & 1 deletion core/ai/misc_nodes/action_nodes/bt_is_player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ class_name BTIsPlayer extends BTCheck

func _tick(state: CharacterState) -> int:
if is_instance_valid(state.target):
if state.target.object is Player and state.target.emissor is VisualSensor and state.target.interest > 200:
if state.target.object is Player and state.target.emitter is VisualSensor and state.target.interest > 200:
return BTResult.OK
return BTResult.FAILED
4 changes: 2 additions & 2 deletions resources/models/items/melee/sap/M_Sap.material
Git LFS file not shown
4 changes: 2 additions & 2 deletions resources/models/items/melee/sap/T_Sap_Base_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/models/items/melee/sap/sap.gltf
Git LFS file not shown
2 changes: 1 addition & 1 deletion resources/world/world_data.gd
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func get_starting_room_data() -> RoomData:

func get_cell_index_from_local_position(pos : Vector3) -> int:
pos /= CELL_SIZE
return get_cell_index_from_int_position(pos.x, pos.z)
return get_cell_index_from_int_position(int(pos.x), int(pos.z))


func is_inside_world_bounds(x: int, z: int) -> bool:
Expand Down
Loading

0 comments on commit f0beddd

Please sign in to comment.