60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
#include "clue_marker.h"
|
|
#include "core/config/engine.h"
|
|
#include "you_done_it/clue_finder.h"
|
|
#include "you_done_it/macros.h"
|
|
#include "you_done_it/ydi_networking.h"
|
|
|
|
void ClueMarker::_bind_methods() {
|
|
BIND_HPROPERTY(Variant::INT, clue_id, PROPERTY_HINT_ENUM, NetworkData::ClueID_hint());
|
|
}
|
|
|
|
void ClueMarker::enter_tree() {
|
|
ClueFinder::get_singleton()->register_clue_marker(this);
|
|
}
|
|
|
|
void ClueMarker::exit_tree() {
|
|
ClueFinder::get_singleton()->remove_clue_marker(this);
|
|
}
|
|
|
|
void ClueMarker::_notification(int what) {
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
|
return;
|
|
}
|
|
switch (what) {
|
|
case NOTIFICATION_ENTER_TREE:
|
|
enter_tree();
|
|
return;
|
|
case NOTIFICATION_EXIT_TREE:
|
|
exit_tree();
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
|
|
float ClueMarker::score_in_view() const {
|
|
Transform3D const viewpoint{ ClueFinder::get_singleton()->get_global_transform() };
|
|
Basis const basis{ viewpoint.get_basis() };
|
|
Vector3 const pos_relative{ get_global_position() - viewpoint.get_origin() };
|
|
Vector3 const pos_transformed{ basis.get_column(0).dot(pos_relative), basis.get_column(1).dot(pos_relative), basis.get_column(2).dot(pos_relative) };
|
|
if (pos_transformed.z <= 0.5f) {
|
|
return false;
|
|
}
|
|
Vector3 const transformed_dir{ pos_transformed.normalized() };
|
|
float max{ pos_transformed.z / 5.f };
|
|
if (Math::abs(transformed_dir.x) < max && Math::abs(transformed_dir.y) < max) {
|
|
return Math::INF;
|
|
}
|
|
return pos_transformed.z * (Math::abs(transformed_dir.x) + Math::abs(transformed_dir.y));
|
|
}
|
|
|
|
void ClueMarker::reveal() {
|
|
ClueDB::get_singleton()->get_clue(this->id)->reveal();
|
|
}
|
|
|
|
void ClueMarker::set_clue_id(NetworkData::ClueID id) {
|
|
this->id = id;
|
|
}
|
|
|
|
NetworkData::ClueID ClueMarker::get_clue_id() const {
|
|
return this->id;
|
|
}
|