wave-survival/modules/wave_survival/map_region.cpp

46 lines
950 B
C++

#include "map_region.h"
#include "enemy_body.h"
String const MapRegion::sig_phase_changed{ "phase_changed" };
void MapRegion::_bind_methods() {
ADD_SIGNAL(MethodInfo(sig_phase_changed, PropertyInfo(Variant::BOOL, "hunt_phase")));
}
void MapRegion::on_node_entered(Node *node) {
if (EnemyBody * body{ cast_to<EnemyBody>(node) }) {
if (!this->units.has(body->get_unit())) {
body->get_unit()->set_region(this);
}
}
}
void MapRegion::ready() {
connect("body_entered", callable_mp(this, &self_type::on_node_entered));
}
void MapRegion::_notification(int what) {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
switch (what) {
default:
return;
case NOTIFICATION_READY:
ready();
return;
}
}
void MapRegion::register_unit(NpcUnit *unit) {
if (!this->units.has(unit)) {
this->units.insert(unit);
}
}
void MapRegion::remove_unit(NpcUnit *unit) {
if (this->units.has(unit)) {
this->units.erase(unit);
}
}