Fixing minor bugs in scripts

This commit is contained in:
Vladislav Khorev committed 2026-06-09 23:57:27 +03:00
1 parent 80133aa8c8
commit 87fb6d4655
14 files changed
+490 -234

No files matched your search

+31 -1
View File
@@ -247,6 +247,7 @@ namespace ZL
"resources/navigation/uni_interior4_locked.json" //17
};
/*
uniInteriorParams.navigationJsonPaths = {
"resources/navigation/uni_interior3_darklands_all_open.json",
@@ -310,7 +311,16 @@ namespace ZL
locations["uni_exterior"]->setup(uniExteriorParams, &menuManager.questJournal);
locations["uni_exterior"]->scriptEngine.setGlobalStore(&globalInts);
locations["uni_exterior"]->scriptEngine.setGlobalFloatStore(&globalFloats);
locations["uni_exterior"]->requestNightDayTransition = [this](bool isNight, bool isDawn) { this->menuManager.isNight = isNight; this->menuManager.isDawn = isDawn; };
locations["uni_exterior"]->requestNightDayTransition = [this](bool isNight, bool isDawn) {
this->menuManager.isNight = isNight;
this->menuManager.isDawn = isDawn;
/*for (auto& locPair : locations) {
if (locPair.second) {
locPair.second->isNight = isNight;
locPair.second->isDawn = isDawn;
}
}*/
};
locations["uni_exterior"]->requestDarklandsTransition = [this]() { return startDarklandsTransition(); };
locations["uni_exterior"]->requestClosePhone = [this]() { menuManager.closePhoneEntirely(); };
locations["uni_exterior"]->requestReturnToMainMenu = [this]() { menuManager.showMainMenu(); };
@@ -407,7 +417,12 @@ namespace ZL
currentLocation->player->targetFacingAngle = destRotY;
}
currentLocation->cameraAzimuth = destRotY;
currentLocation->isDarklands = isDarklands;
currentLocation->isNight = menuManager.isNight;
currentLocation->isDawn = menuManager.isDawn;
currentLocation->scriptEngine.callLocationEnterCallback();
menuManager.onLocationChanged(destName);
};
@@ -863,6 +878,7 @@ namespace ZL
currentLocation->dialogueSystem.startCutscene("lection_cutscene001"); //.startDialogue("test_cutscene_pan_dialogue");
break;
case SDLK_n:
if (editorMode == EditorMode::None)
editorMode = EditorMode::Navigation;
@@ -1239,6 +1255,18 @@ namespace ZL
bool Game::startDarklandsTransition()
{
if (!menuManager.isNight)
{
currentLocation->dialogueSystem.startDialogue("darklands_day_dialog001");
return false;
}
if (menuManager.isDawn)
{
currentLocation->dialogueSystem.startDialogue("darklands_morning_dialog001");
return false;
}
if (darklandsFlashActive) return false;
darklandsFlashActive = true;
darklandsFlashFadingIn = true;
@@ -1271,6 +1299,7 @@ namespace ZL
if (currentLocation)
{
//currentLocation->dialogueSystem.startDialogue("dialog_video001");
currentLocation->isNight = menuManager.isNight;
currentLocation->scriptEngine.callTriggerNightEnterCallback();
}
} else {
@@ -1280,6 +1309,7 @@ namespace ZL
menuManager.setDarklandsMode(isDarklands);
if (currentLocation) {
currentLocation->isDarklands = isDarklands;
if (isDarklands)
currentLocation->scriptEngine.callDarklandsEnterCallback();
else
+4
View File
@@ -572,6 +572,7 @@ namespace ZL {
refreshChatUnreadIndicators();
}
void MenuManager::closePhoneEntirely() {
activeChatIndex_ = -1;
state = GameState::Gameplay;
@@ -583,6 +584,9 @@ namespace ZL {
{
uiManager.setNodeVisible("hint7", true);
uiManager.setNodeVisible("hint7arrow", true);
uiManager.setNodeVisible("hint6a", false);
uiManager.setNodeVisible("hint6aarrow", false);
}
else
{
+95 -95
View File
@@ -33,7 +33,7 @@ namespace ZL {
ScriptEngine::ScriptEngine() = default;
ScriptEngine::~ScriptEngine() = default;
void ScriptEngine::init(Location* game, Inventory* inventory, const std::string& scriptPath) {
void ScriptEngine::init(Location* loc, Inventory* inventory, const std::string& scriptPath) {
impl = std::make_unique<Impl>();
sol::state& lua = impl->lua;
@@ -45,8 +45,8 @@ namespace ZL {
// on_arrived is an optional Lua function called when the NPC reaches the target.
// It can call npc_walk_to again (or anything else) to chain behaviour.
api.set_function("npc_walk_to",
[game](int index, float x, float y, float z, sol::object on_arrived) {
auto& npcs = game->npcs;
[loc](int index, float x, float y, float z, sol::object on_arrived) {
auto& npcs = loc->npcs;
if (index < 0 || index >= static_cast<int>(npcs.size())) {
std::cerr << "[script] npc_walk_to: index " << index
<< " out of range (0.." << npcs.size() - 1 << ")\n";
@@ -68,7 +68,7 @@ namespace ZL {
});
api.set_function("player_walk_to",
[game](float x, float y, float z, sol::object on_arrived) {
[loc](float x, float y, float z, sol::object on_arrived) {
std::function<void()> cb;
if (on_arrived.is<sol::protected_function>()) {
@@ -81,8 +81,8 @@ namespace ZL {
}
};
}
game->player->homePosition = Eigen::Vector3f(x, 0.f, z);
game->player->setTarget(Eigen::Vector3f(x, y, z), std::move(cb));
loc->player->homePosition = Eigen::Vector3f(x, 0.f, z);
loc->player->setTarget(Eigen::Vector3f(x, y, z), std::move(cb));
});
@@ -117,14 +117,14 @@ namespace ZL {
});
// remove_item(item_id)
api.set_function("remove_item", [game, inventory](const std::string& id) {
api.set_function("remove_item", [loc, inventory](const std::string& id) {
std::cout << "[script] remove_item: " << id << std::endl;
inventory->removeItem(id);
});
// deactivate_interactive_object(object_name)
api.set_function("deactivate_interactive_object", [game](const std::string& objectName) {
for (auto& intObj : game->interactiveObjects) {
api.set_function("deactivate_interactive_object", [loc](const std::string& objectName) {
for (auto& intObj : loc->interactiveObjects) {
if (intObj.loadedObject.name == objectName) {
intObj.isActive = false;
std::cout << "[script] deactivate_interactive_object: " << objectName << std::endl;
@@ -135,8 +135,8 @@ namespace ZL {
});
// activate_interactive_object(object_name)
api.set_function("activate_interactive_object", [game](const std::string& objectName) {
for (auto& intObj : game->interactiveObjects) {
api.set_function("activate_interactive_object", [loc](const std::string& objectName) {
for (auto& intObj : loc->interactiveObjects) {
if (intObj.loadedObject.name == objectName) {
intObj.isActive = true;
std::cout << "[script] activate_interactive_object: " << objectName << std::endl;
@@ -146,8 +146,8 @@ namespace ZL {
std::cerr << "[script] activate_interactive_object: not found: " << objectName << std::endl;
});
api.set_function("set_object_rotation", [game](const std::string& objectName, float value) {
for (auto& intObj : game->interactiveObjects) {
api.set_function("set_object_rotation", [loc](const std::string& objectName, float value) {
for (auto& intObj : loc->interactiveObjects) {
if (intObj.loadedObject.name == objectName) {
intObj.rotationY = value * static_cast<float>(M_PI) / 180.f;
std::cout << "[script] set_object_rotation: " << objectName << " " << value << std::endl;
@@ -157,8 +157,8 @@ namespace ZL {
std::cerr << "[script] set_object_rotation: not found: " << objectName << std::endl;
});
api.set_function("set_object_alpha", [game](const std::string& objectName, float value) {
for (auto& intObj : game->interactiveObjects) {
api.set_function("set_object_alpha", [loc](const std::string& objectName, float value) {
for (auto& intObj : loc->interactiveObjects) {
if (intObj.loadedObject.name == objectName) {
intObj.alpha = value;
std::cout << "[script] set_object_alpha: " <<objectName << " " << value << std::endl;
@@ -179,16 +179,16 @@ namespace ZL {
});
api.set_function("start_dialogue",
[game](const std::string& dialogueId) {
if (!game->requestDialogueStart(dialogueId)) {
[loc](const std::string& dialogueId) {
if (!loc->requestDialogueStart(dialogueId)) {
std::cerr << "[script] start_dialogue failed for id: " << dialogueId << "\n";
}
});
// start_cutscene(cutscene_id)
api.set_function("start_cutscene",
[game](const std::string& cutsceneId) {
if (!game->requestCutsceneStart(cutsceneId))
[loc](const std::string& cutsceneId) {
if (!loc->requestCutsceneStart(cutsceneId))
std::cerr << "[script] start_cutscene failed for id: " << cutsceneId << "\n";
});
@@ -201,26 +201,26 @@ namespace ZL {
});
api.set_function("set_dialogue_flag",
[game](const std::string& flag, int value) {
game->setDialogueFlag(flag, value);
[loc](const std::string& flag, int value) {
loc->setDialogueFlag(flag, value);
});
api.set_function("get_dialogue_flag",
[game](const std::string& flag) {
return game->getDialogueFlag(flag);
[loc](const std::string& flag) {
return loc->getDialogueFlag(flag);
});
api.set_function("set_navigation_area_available",
[game](const std::string& areaName, bool available) {
if (!game->setNavigationAreaAvailable(areaName, available)) {
[loc](const std::string& areaName, bool available) {
if (!loc->setNavigationAreaAvailable(areaName, available)) {
std::cerr << "[script] set_navigation_area_available: area not found: "
<< areaName << "\n";
}
});
api.set_function("switch_navigation",
[game](int index) {
if (!game->switchNavigation(index)) {
[loc](int index) {
if (!loc->switchNavigation(index)) {
std::cerr << "[script] switch_navigation: index " << index << " out of range\n";
}
});
@@ -240,47 +240,47 @@ namespace ZL {
// Triggers the white-flash transition to toggle darklands mode.
// Does nothing if a transition is already in progress.
api.set_function("start_darklands_transition",
[game]() {
if (game->requestDarklandsTransition)
game->requestDarklandsTransition();
[loc]() {
if (loc->requestDarklandsTransition)
loc->requestDarklandsTransition();
});
api.set_function("set_day",
[game]() {
game->requestNightDayTransition(false, false);
[loc]() {
loc->requestNightDayTransition(false, false);
});
api.set_function("set_night",
[game]() {
game->requestNightDayTransition(true, false);
[loc]() {
loc->requestNightDayTransition(true, false);
std::cout << "Set night called" << std::endl;
});
api.set_function("set_dawn",
[game]() {
game->requestNightDayTransition(true, true);
[loc]() {
loc->requestNightDayTransition(true, true);
std::cout << "Set dawn called" << std::endl;
});
api.set_function("is_night",
[game]() {
return game->isNight;
[loc]() {
return loc->isNight;
});
api.set_function("is_dawn",
[game]() {
return game->isDawn;
[loc]() {
return loc->isDawn;
});
// advance_darklands_hud()
// Advances the uni_interior darklands HUD from step12 to step13.
// Call when the player enters the ghost trigger zone in darklands.
api.set_function("advance_darklands_hud",
[game]() {
if (game->requestAdvanceDarklandsHud)
game->requestAdvanceDarklandsHud();
[loc]() {
if (loc->requestAdvanceDarklandsHud)
loc->requestAdvanceDarklandsHud();
});
// set_location_callbacks(on_enter, on_exit)
@@ -296,7 +296,7 @@ namespace ZL {
// is_darklands() → bool
api.set_function("is_darklands",
[game]() { return game->isDarklands; });
[loc]() { return loc->isDarklands; });
api.set_function("setFloatValue",
[this_impl = impl.get()](const std::string& key, float value) {
@@ -311,31 +311,31 @@ namespace ZL {
});
api.set_function("get_player_x",
[game]() -> float {
return game->player ? game->player->position.x() : 0.0f;
[loc]() -> float {
return loc->player ? loc->player->position.x() : 0.0f;
});
api.set_function("get_player_z",
[game]() -> float {
return game->player ? game->player->position.z() : 0.0f;
[loc]() -> float {
return loc->player ? loc->player->position.z() : 0.0f;
});
// set_player_hp(value) — sets the player's current HP directly.
api.set_function("set_player_hp",
[game](float value) {
if (game->player)
[loc](float value) {
if (loc->player)
{
game->player->hp = value;
if (game->player->currentState == AnimationState::ACTION_TO_DEATH || game->player->currentState == AnimationState::DEATH_IDLE)
loc->player->hp = value;
if (loc->player->currentState == AnimationState::ACTION_TO_DEATH || loc->player->currentState == AnimationState::DEATH_IDLE)
{
game->player->currentState = AnimationState::STAND;
game->player->resetAnim = true;
loc->player->currentState = AnimationState::STAND;
loc->player->resetAnim = true;
}
}
});
// get_player_hp() → float (0 if no player)
api.set_function("get_player_hp",
[game]() -> float {
return game->player ? game->player->hp : 0.0f;
[loc]() -> float {
return loc->player ? loc->player->hp : 0.0f;
});
// Global integer store — shared across all location scripts.
@@ -365,15 +365,15 @@ namespace ZL {
});
api.set_function("close_phone",
[game]() {
if (game->requestClosePhone)
game->requestClosePhone();
[loc]() {
if (loc->requestClosePhone)
loc->requestClosePhone();
});
api.set_function("return_to_main_menu",
[game]() {
if (game->requestReturnToMainMenu)
game->requestReturnToMainMenu();
[loc]() {
if (loc->requestReturnToMainMenu)
loc->requestReturnToMainMenu();
});
api.set_function("set_chat_callbacks",
@@ -396,8 +396,8 @@ namespace ZL {
});
api.set_function("set_trigger_zone_enabled",
[game](int index, bool value) {
auto& triggerZones = game->triggerZones;
[loc](int index, bool value) {
auto& triggerZones = loc->triggerZones;
if (index < 0 || index >= static_cast<int>(triggerZones.size())) {
std::cerr << "[script] set_trigger_zone_enabled: index " << index << " out of range\n";
return;
@@ -408,8 +408,8 @@ namespace ZL {
// set_teleport_active(index, active) — activates or deactivates a teleport zone by index.
// Swaps the particle effect texture to match the new state.
api.set_function("set_teleport_active",
[game](int index, bool value) {
auto& zones = game->teleportZones;
[loc](int index, bool value) {
auto& zones = loc->teleportZones;
if (index < 0 || index >= static_cast<int>(zones.size())) {
std::cerr << "[script] set_teleport_active: index " << index << " out of range\n";
return;
@@ -419,8 +419,8 @@ namespace ZL {
// is_teleport_active(index) → bool
api.set_function("is_teleport_active",
[game](int index) -> bool {
auto& zones = game->teleportZones;
[loc](int index) -> bool {
auto& zones = loc->teleportZones;
if (index < 0 || index >= static_cast<int>(zones.size())) {
std::cerr << "[script] is_teleport_active: index " << index << " out of range\n";
return false;
@@ -431,8 +431,8 @@ namespace ZL {
// npc_set_hp(index, value) — sets an NPC's current HP directly.
api.set_function("npc_set_hp",
[game](int index, float value) {
auto& npcs = game->npcs;
[loc](int index, float value) {
auto& npcs = loc->npcs;
if (index < 0 || index >= static_cast<int>(npcs.size())) {
std::cerr << "[script] npc_set_hp: index " << index << " out of range\n";
return;
@@ -442,8 +442,8 @@ namespace ZL {
// npc_set_position(index, x, y, z) — teleports an NPC instantly, no walking.
api.set_function("npc_set_position",
[game](int index, float x, float y, float z) {
auto& npcs = game->npcs;
[loc](int index, float x, float y, float z) {
auto& npcs = loc->npcs;
if (index < 0 || index >= static_cast<int>(npcs.size())) {
std::cerr << "[script] npc_set_position: index " << index << " out of range\n";
return;
@@ -456,8 +456,8 @@ namespace ZL {
// npc_set_rotation(index, angle) — sets NPC facing angle around Y axis (degrees).
api.set_function("npc_set_rotation",
[game](int index, float angle) {
auto& npcs = game->npcs;
[loc](int index, float angle) {
auto& npcs = loc->npcs;
if (index < 0 || index >= static_cast<int>(npcs.size())) {
std::cerr << "[script] npc_set_rotation: index " << index << " out of range\n";
return;
@@ -469,8 +469,8 @@ namespace ZL {
// set_npc_enabled(index, enabled)
api.set_function("set_npc_enabled",
[game](int index, bool value) {
auto& npcs = game->npcs;
[loc](int index, bool value) {
auto& npcs = loc->npcs;
if (index < 0 || index >= static_cast<int>(npcs.size())) {
std::cerr << "[script] set_npc_enabled: index " << index << " out of range\n";
return;
@@ -481,16 +481,16 @@ namespace ZL {
npcs[index]->currentState = AnimationState::STAND;
if (npcs[index]->canAttack)
{
npcs[index]->attackTarget = game->player.get();
npcs[index]->attackTarget = loc->player.get();
}
npcs[index]->battle_state = 0;
});
// move_object(name, x, y, z, duration_sec [, on_complete])
api.set_function("move_object",
[game](const std::string& name, float x, float y, float z,
[loc](const std::string& name, float x, float y, float z,
float durationSec, sol::object onComplete) {
for (auto& intObj : game->interactiveObjects) {
for (auto& intObj : loc->interactiveObjects) {
if (intObj.loadedObject.name != name) continue;
if (intObj.isAnimating) {
std::cerr << "[script] move_object: '" << name << "' is already animating\n";
@@ -515,9 +515,9 @@ namespace ZL {
// rotate_object(name, angle_deg, duration_sec [, on_complete])
api.set_function("rotate_object",
[game](const std::string& name, float angleDeg,
[loc](const std::string& name, float angleDeg,
float durationSec, sol::object onComplete) {
for (auto& intObj : game->interactiveObjects) {
for (auto& intObj : loc->interactiveObjects) {
if (intObj.loadedObject.name != name) continue;
if (intObj.isAnimating) {
std::cerr << "[script] rotate_object: '" << name << "' is already animating\n";
@@ -543,9 +543,9 @@ namespace ZL {
// fade_object(name, target_alpha, duration_sec [, on_complete])
api.set_function("fade_object",
[game](const std::string& name, float targetAlpha,
[loc](const std::string& name, float targetAlpha,
float durationSec, sol::object onComplete) {
for (auto& intObj : game->interactiveObjects) {
for (auto& intObj : loc->interactiveObjects) {
if (intObj.loadedObject.name != name) continue;
if (intObj.isAnimating) {
std::cerr << "[script] fade_object: '" << name << "' is already animating\n";
@@ -570,9 +570,9 @@ namespace ZL {
// scale_object(name, target_scale, duration_sec [, on_complete])
api.set_function("scale_object",
[game](const std::string& name, float targetScale,
[loc](const std::string& name, float targetScale,
float durationSec, sol::object onComplete) {
for (auto& intObj : game->interactiveObjects) {
for (auto& intObj : loc->interactiveObjects) {
if (intObj.loadedObject.name != name) continue;
if (intObj.isAnimating) {
std::cerr << "[script] scale_object: '" << name << "' is already animating\n";
@@ -596,20 +596,20 @@ namespace ZL {
});
api.set_function("resetPlayerAfterDeath",
[game]() {
if (game->player) game->player->resetPlayerAfterDeath();
[loc]() {
if (loc->player) loc->player->resetPlayerAfterDeath();
});
// player_stop() — cancels the player's current walk target and stops them immediately.
api.set_function("player_stop",
[game]() {
if (game->player) game->player->stopInPlace();
[loc]() {
if (loc->player) loc->player->stopInPlace();
});
// npc_stop(index) — cancels an NPC's current walk target and stops them immediately.
api.set_function("npc_stop",
[game](int index) {
auto& npcs = game->npcs;
[loc](int index) {
auto& npcs = loc->npcs;
if (index < 0 || index >= static_cast<int>(npcs.size())) {
std::cerr << "[script] npc_stop: index " << index
<< " out of range (0.." << npcs.size() - 1 << ")\n";
@@ -694,11 +694,11 @@ namespace ZL {
});
api.set_function("call_tutorial_taxi_required",
[game]() -> void {
if (game->onPlayerTaxiRequired)
[loc]() -> void {
if (loc->onPlayerTaxiRequired)
{
game->onPlayerTaxiRequired();
game->onPlayerTaxiRequired = nullptr;
loc->onPlayerTaxiRequired();
loc->onPlayerTaxiRequired = nullptr;
}
else {
std::cerr << "[script] call_tutorial_taxi_required: function is empty\n";
+7 -6
View File
@@ -48,6 +48,7 @@ void DialogueOverlay::update(const PresentationModel& model, int deltaMs) {
}
}
void DialogueOverlay::draw(Renderer& renderer, const PresentationModel& model) {
if (model.mode != PresentationMode::Dialogue && model.mode != PresentationMode::Choice) {
lastChoiceRects.clear();
@@ -59,7 +60,7 @@ void DialogueOverlay::draw(Renderer& renderer, const PresentationModel& model) {
UiRect portraitRect{ 24.0f + 90, 24.0f + 16, 176.0f, 176.0f };
UiRect textboxRect{ 30.f, -48.f, 1222.f, 340.0f };
UiRect textboxChoiceRect{ 30.f, -48.f, 1200.f, 619.5f };
UiRect textboxChoiceRect{ 30.f, -90.f, 1200.f, 619.5f };
lastDialogueAdvanceRect = { portraitRect.x, portraitRect.y, textboxRect.x + textboxRect.w - portraitRect.x, textboxRect.h };
@@ -87,7 +88,7 @@ void DialogueOverlay::draw(Renderer& renderer, const PresentationModel& model) {
if (model.mode == PresentationMode::Choice)
{
glBindTexture(GL_TEXTURE_2D, textboxTexture->getTexID());
glBindTexture(GL_TEXTURE_2D, textboxChoiceTexture->getTexID());
renderer.DrawVertexRenderStruct(textboxChoiceQuad.mesh);
}
else
@@ -101,7 +102,7 @@ void DialogueOverlay::draw(Renderer& renderer, const PresentationModel& model) {
if (model.mode == PresentationMode::Choice)
{
renderer.TranslateMatrix(Vector3f{ 0, 230, 0 });
renderer.TranslateMatrix(Vector3f{ 20, 230, 0 });
}
auto portrait = loadTextureCached(model.portraitPath);
@@ -128,12 +129,12 @@ void DialogueOverlay::draw(Renderer& renderer, const PresentationModel& model) {
if (model.mode == PresentationMode::Choice)
{
nameRenderer->drawText(model.speaker, nameX+x, nameY+230, 1.0f, false, { 1.0f, 0.88f, 0.45f, 1.0f });
nameRenderer->drawText(model.speaker, nameX+20, nameY+230, 1.0f, false, { 1.0f, 0.88f, 0.45f, 1.0f });
}
else
{
nameRenderer->drawText(model.speaker, nameX+x, nameY, 1.0f, false, { 1.0f, 0.88f, 0.45f, 1.0f });
nameRenderer->drawText(model.speaker, nameX, nameY, 1.0f, false, { 1.0f, 0.88f, 0.45f, 1.0f });
}
}
@@ -164,7 +165,7 @@ void DialogueOverlay::draw(Renderer& renderer, const PresentationModel& model) {
for (size_t i = 0; i < model.choices.size(); ++i) {
const float cy = choiceStartY + (choiceHeight + choiceSpacing) * static_cast<float>(model.choices.size() - 1 - i);
UiRect rect{ 300.f, cy, choiceWidth, choiceHeight };
UiRect rect{ 320.f, cy, choiceWidth, choiceHeight };
lastChoiceRects.push_back(rect);
choiceQuads[i].rebuild(rect);