67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
#include "map_region.h"
|
|
#include "enemy_body.h"
|
|
|
|
String const MapRegion::sig_difficulty_increased{ "difficulty_increased" };
|
|
String const MapRegion::sig_phase_changed{ "hunt_phase" };
|
|
|
|
void MapRegion::_bind_methods() {
|
|
ADD_SIGNAL(MethodInfo(sig_difficulty_increased));
|
|
ADD_SIGNAL(MethodInfo(sig_phase_changed, PropertyInfo(Variant::BOOL, "hunt")));
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
void MapRegion::raise_difficulty(double amount) {
|
|
if (this->hunt_phase) {
|
|
return;
|
|
}
|
|
double const new_difficulty{ this->difficulty + amount };
|
|
int const new_trunc{ (int)Math::floor(new_difficulty) };
|
|
int const old_trunc{ (int)Math::floor(this->difficulty) };
|
|
if (new_trunc != old_trunc) {
|
|
emit_signal(sig_difficulty_increased);
|
|
emit_signal(sig_phase_changed, true);
|
|
this->hunt_phase = true;
|
|
}
|
|
}
|
|
|
|
int MapRegion::get_current_difficulty() const {
|
|
int difficulty{ (int)Math::floor(this->difficulty) };
|
|
return difficulty;
|
|
}
|