From 38e45d67b8ba5b139f711d70bad8603850979fb4 Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Sun, 12 Jul 2026 19:09:26 +0300 Subject: [PATCH] Working on viewing distance for enemies --- resources/config/npcs_uni_interior.json | 6 +++++- src/Character.cpp | 7 +++---- src/CharacterState.cpp | 2 ++ src/CharacterState.h | 4 ++++ src/items/GameObjectLoader.cpp | 2 ++ src/items/GameObjectLoader.h | 1 + 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/resources/config/npcs_uni_interior.json b/resources/config/npcs_uni_interior.json index 93a61bd..a02d264 100644 --- a/resources/config/npcs_uni_interior.json +++ b/resources/config/npcs_uni_interior.json @@ -49,7 +49,7 @@ "meshTextures": { "Ghost": "resources/w/ghost/Ghost_BaseColor.png" }, - "positionX": -0.28594, + "positionX": 0, "positionY": 0, "positionZ": 13.9641, "walkSpeed": 1.5, @@ -60,6 +60,7 @@ "modelCorrectionRotZ": 0.0, "interactionRadius": 1.0, "hp": 35, + "visibleRange" : 5.5, "canAttack": false }, { @@ -86,6 +87,7 @@ "modelCorrectionRotY": 180.0, "modelCorrectionRotZ": 0.0, "hp": 35, + "visibleRange" : 6.5, "canAttack": true }, { @@ -112,6 +114,7 @@ "modelCorrectionRotY": 180.0, "modelCorrectionRotZ": 0.0, "hp": 35, + "visibleRange" : 6.0, "canAttack": true }, { @@ -138,6 +141,7 @@ "modelCorrectionRotY": 180.0, "modelCorrectionRotZ": 0.0, "hp": 35, + "visibleRange" : 4.8, "canAttack": true }, { diff --git a/src/Character.cpp b/src/Character.cpp index d082f2e..cc48362 100644 --- a/src/Character.cpp +++ b/src/Character.cpp @@ -16,8 +16,7 @@ namespace ZL { extern float x; extern float y; const float ATTACK_RANGE = 1.25f; - const float VISIBLE_RANGE = 6.f; - + Dialogue::TranslationDatabase Character::nameTranslations; void Character::loadAnimation(AnimationState animState, const std::string& filename, const std::string& zipFile) { @@ -252,12 +251,12 @@ void Character::update(int64_t deltaMs, const CharacterResolver& resolver) { if (attackTarget != nullptr) { float distToGhost = (attackTarget->state.position - state.position).norm(); - if (distToGhost >= VISIBLE_RANGE) { + if (distToGhost >= state.visibleRange) { if (state.isPlayer) { setTarget(attackTarget->state.position); } state.battle_state = 0; - } else if (distToGhost < VISIBLE_RANGE && distToGhost >= ATTACK_RANGE) { + } else if (distToGhost < state.visibleRange && distToGhost >= ATTACK_RANGE) { setTarget(attackTarget->state.position); state.battle_state = 0; } else { diff --git a/src/CharacterState.cpp b/src/CharacterState.cpp index ca7e2bd..6c88923 100644 --- a/src/CharacterState.cpp +++ b/src/CharacterState.cpp @@ -53,6 +53,7 @@ void CharacterState::save(nlohmann::json& out) const out["pathWaypoints"] = std::move(wpArr); out["currentWaypointIndex"] = currentWaypointIndex; out["homeDriftCheckTimer"] = homeDriftCheckTimer; + out["visibleRange"] = visibleRange; if (!onArrivedCallbackName.empty()) out["onArrivedCallbackName"] = onArrivedCallbackName; } @@ -69,6 +70,7 @@ void CharacterState::load(const nlohmann::json& in) facingAngle = in.value("facingAngle", facingAngle); targetFacingAngle = in.value("targetFacingAngle", targetFacingAngle); hp = in.value("hp", hp); + visibleRange = in.value("visibleRange", visibleRange); enabled = in.value("enabled", enabled); battle_state = in.value("battle_state", battle_state); currentState = static_cast(in.value("currentState", static_cast(currentState))); diff --git a/src/CharacterState.h b/src/CharacterState.h index 7ec2db6..db25e3c 100644 --- a/src/CharacterState.h +++ b/src/CharacterState.h @@ -10,6 +10,8 @@ namespace ZL { + constexpr float VISIBLE_RANGE = 6.f; + enum class AnimationState { STAND = 0, WALK = 1, @@ -70,6 +72,8 @@ public: float hp = 200.f; float initialHp = 200.f; + float visibleRange = VISIBLE_RANGE; + // --- Combat flags --- int battle_state = 0; bool resetAnim = false; diff --git a/src/items/GameObjectLoader.cpp b/src/items/GameObjectLoader.cpp index 1f64a7c..1a7c1ad 100644 --- a/src/items/GameObjectLoader.cpp +++ b/src/items/GameObjectLoader.cpp @@ -295,6 +295,7 @@ namespace ZL { data.modelCorrectionRotZ = item.value("modelCorrectionRotZ", 0.0f) * static_cast(M_PI) / 180.0f; data.facingAngle = item.value("facingAngle", 0.0f) * static_cast(M_PI) / 180.0f; data.hp = item.value("hp", 100.0f); + data.visibleRange = item.value("visibleRange", VISIBLE_RANGE); data.canAttack = item.value("canAttack", false); data.enabled = item.value("enabled", true); @@ -321,6 +322,7 @@ namespace ZL { st.modelScale = modelScale; st.setHp(hp); st.initialHp = hp; + st.visibleRange = visibleRange; st.canAttack = canAttack; st.enabled = enabled; st.interactionRadius = interactionRadius; diff --git a/src/items/GameObjectLoader.h b/src/items/GameObjectLoader.h index 8f7c029..030fc43 100644 --- a/src/items/GameObjectLoader.h +++ b/src/items/GameObjectLoader.h @@ -74,6 +74,7 @@ namespace ZL { float modelCorrectionRotZ = 0.0f; float facingAngle = 0.0f; float hp = 100.0f; + float visibleRange = VISIBLE_RANGE; bool canAttack = false; bool enabled = true; float interactionRadius = 0.0f;