# Rally Rush: src/turret.hpp Source File

Loading...
Searching...
No Matches
turret.hpp
Go to the documentation of this file.
#ifndef TURRET_HPP
#define TURRET_HPP
#include <godot_cpp/classes/area3d.hpp>
#include <godot_cpp/classes/packed_scene.hpp>
#include <godot_cpp/classes/rigid_body3d.hpp>
#include <godot_cpp/templates/hash_set.hpp>
#include <godot_cpp/templates/vector.hpp>
namespace godot {
enum class TurretState {
WAITING = 0x0,
LOCKING = 0x1,
CHARGING,
FIRING
};
class Turret : public RigidBody3D {
GDCLASS(Turret, RigidBody3D);
static void _bind_methods();
public:
virtual void _enter_tree() override;
virtual void _process(double delta_time) override;
void awareness_changed();
Node3D *select_target();
void lead_target(double delta_time);
void detect_node(Node3D *node);
void lose_node(Node3D *node);
void try_next_state();
void create_beam();
void create_guiding_beam();
void beam_ended();
void set_fire_time(float val);
float get_fire_time() const;
void set_charge_time(float val);
float get_charge_time() const;
void set_lock_time(float val);
float get_lock_time() const;
void set_invert_targets(bool value);
void set_attack_classes(Array array);
Array get_attack_classes() const;
void set_beam_scene(Ref<PackedScene> scene);
Ref<PackedScene> get_beam_scene() const;
void set_guiding_beam_scene(Ref<PackedScene> scene);
Ref<PackedScene> get_guiding_beam_scene() const;
private:
Node3D *current_target{nullptr};
bool invert_attack_classes{false};
Vector3 aim_position{0.f, 0.f, 0.f};
Vector3 last_target_position{0.f, 0.f, 0.f};
float last_state_switch{0.f};
float lead_distance{1.2f};
Node3D *gun_node{nullptr};
Vector3 gun_node_offset{0.f, 0.f, 0.f};
TurretState state{TurretState::WAITING};
Vector<StringName> attack_classes{};
HashSet<Node3D*> awareness{};
Ref<PackedScene> beam_scene{};
Ref<PackedScene> guiding_beam_scene{};
float fire_time{1.0f};
float charge_time{1.f};
float lock_time{1.3f};
};
}
#endif // !TURRET_HPP
godot::Turret
Generic turret class with the ability to target any type of node as configured. Used for both the pla...
Definition turret.hpp:24
godot::Turret::guiding_beam_scene
Ref< PackedScene > guiding_beam_scene
Scene to spawn when charging.
Definition turret.hpp:113
godot::Turret::set_charge_time
void set_charge_time(float val)
The duration of the guiding lazer.
Definition turret.cpp:177
godot::Turret::_process
virtual void _process(double delta_time) override
Update state machine. Update gun node position.
Definition turret.cpp:33
godot::Turret::set_lock_time
void set_lock_time(float val)
The delay between firing and charging the next shot.
Definition turret.cpp:185
godot::Turret::get_fire_time
float get_fire_time() const
The duration of the damaging lazer.
Definition turret.cpp:173
godot::Turret::select_target
Node3D * select_target()
Select a target from the currently known nodes.
Definition turret.cpp:59
godot::Turret::GDCLASS
GDCLASS(Turret, RigidBody3D)
godot::Turret::get_lock_time
float get_lock_time() const
The delay between firing and charging the next shot.
Definition turret.cpp:189
godot::Turret::beam_scene
Ref< PackedScene > beam_scene
Scene to spawn when firing.
Definition turret.hpp:111
godot::Turret::detect_node
void detect_node(Node3D *node)
Become aware of a node in the awareness area.
Definition turret.cpp:92
godot::Turret::state
TurretState state
Current state-machine state of the turret.
Definition turret.hpp:103
godot::Turret::awareness
HashSet< Node3D * > awareness
Set of all nodes the turret is currently aware of.
Definition turret.hpp:108
godot::Turret::fire_time
float fire_time
Definition turret.hpp:115
godot::Turret::last_target_position
Vector3 last_target_position
Position of the current_target on the last frame.
Definition turret.hpp:91
godot::Turret::lose_node
void lose_node(Node3D *node)
Lose track of a node exiting the awareness area.
Definition turret.cpp:99
godot::Turret::beam_ended
void beam_ended()
End the fire state.
Definition turret.cpp:164
godot::Turret::lead_target
void lead_target(double delta_time)
Aim ahead of the current target.
Definition turret.cpp:73
godot::Turret::get_attack_classes
Array get_attack_classes() const
Set the node classes to attack while invert_targets is false.
Definition turret.cpp:212
godot::Turret::last_state_switch
float last_state_switch
Last time the state was changed.
Definition turret.hpp:93
godot::Turret::get_charge_time
float get_charge_time() const
The duration of the guiding lazer.
Definition turret.cpp:181
godot::Turret::lead_distance
float lead_distance
Distance ahead of target to aim.
Definition turret.hpp:95
godot::Turret::set_attack_classes
void set_attack_classes(Array array)
Set the node classes to attack while invert_targets is false.
Definition turret.cpp:202
godot::Turret::gun_node_offset
Vector3 gun_node_offset
Position offset of the gun.
Definition turret.hpp:100
godot::Turret::get_beam_scene
Ref< PackedScene > get_beam_scene() const
Set the scene to spawn when firing.
Definition turret.cpp:223
godot::Turret::awareness_changed
void awareness_changed()
Check if a new target needs to be found. Find a new target if required.
Definition turret.cpp:45
godot::Turret::invert_attack_classes
bool invert_attack_classes
If true, target classes not in attack_classes.
Definition turret.hpp:87
godot::Turret::set_fire_time
void set_fire_time(float val)
The duration of the damaging lazer.
Definition turret.cpp:169
godot::Turret::_bind_methods
static void _bind_methods()
register editor properties
Definition turret.cpp:12
godot::Turret::current_target
Node3D * current_target
The current target node.
Definition turret.hpp:85
godot::Turret::set_invert_targets
void set_invert_targets(bool value)
Set to true to target everything but the attack_classes.
Definition turret.cpp:193
godot::Turret::try_next_state
void try_next_state()
Try transition to the next state if possible.
Definition turret.cpp:109
godot::Turret::create_guiding_beam
void create_guiding_beam()
Create a non-damaging guiding beam.
Definition turret.cpp:152
godot::Turret::lock_time
float lock_time
Definition turret.hpp:117
godot::Turret::gun_node
Node3D * gun_node
The child node representing the gun.
Definition turret.hpp:98
godot::Turret::get_guiding_beam_scene
Ref< PackedScene > get_guiding_beam_scene() const
Set the scene to spawn when charging.
Definition turret.cpp:231
godot::Turret::aim_position
Vector3 aim_position
Position currently being aimed at.
Definition turret.hpp:89
godot::Turret::attack_classes
Vector< StringName > attack_classes
Names of classes to attack.
Definition turret.hpp:106
godot::Turret::_enter_tree
virtual void _enter_tree() override
Freeze physics and connect awareness observers. Fetch child nodes and initialize them....
Definition turret.cpp:22
godot::Turret::charge_time
float charge_time
Definition turret.hpp:116
godot::Turret::create_beam
void create_beam()
Create a damaging beam.
Definition turret.cpp:139
godot::Turret::set_beam_scene
void set_beam_scene(Ref< PackedScene > scene)
Set the scene to spawn when firing.
Definition turret.cpp:219
godot::Turret::set_guiding_beam_scene
void set_guiding_beam_scene(Ref< PackedScene > scene)
Set the scene to spawn when charging.
Definition turret.cpp:227
godot
Definition beacon_powerup.cpp:6
godot::TurretState
TurretState
Current state of a turret.
Definition turret.hpp:12
godot::TurretState::WAITING
@ WAITING
No known valid targets.
godot::TurretState::FIRING
@ FIRING
Wait for beam to end.
godot::TurretState::CHARGING
@ CHARGING
Hold still.
godot::TurretState::LOCKING
@ LOCKING
Aim in front of an enemy.