Working on taxi logic

This commit is contained in:
Vladislav Khorev 2026-06-09 14:06:43 +03:00
parent 77c8471636
commit b94f02bd77
10 changed files with 95 additions and 15 deletions

View File

@ -15,15 +15,15 @@
}, },
{ {
"id": "tp_loc2_to_loc1", "id": "tp_loc2_to_loc1",
"positionX": 8.2, "positionX": 6.6335,
"positionY": 0.0, "positionY": 0.0,
"positionZ": -9.9, "positionZ": -9.65,
"radius": 1.5, "radius": 1.5,
"active": true, "active": true,
"destinationLocation": "uni_interior", "destinationLocation": "uni_interior",
"destinationPositionX": 2.64621, "destinationPositionX": 1.05971,
"destinationPositionY": 0.0, "destinationPositionY": 0.0,
"destinationPositionZ": -9.37259, "destinationPositionZ": -9.63831,
"destinationRotationY": -1.5708 "destinationRotationY": -1.5708
} }
] ]

View File

@ -2,15 +2,15 @@
"teleports": [ "teleports": [
{ {
"id": "tp_loc1_to_loc2", "id": "tp_loc1_to_loc2",
"positionX": 2.64621, "positionX": 3.39902,
"positionY": 0.0, "positionY": 0.0,
"positionZ": -9.37259, "positionZ": -10.1046,
"radius": 1.5, "radius": 1.8,
"active": true, "active": true,
"destinationLocation": "uni_exterior", "destinationLocation": "uni_exterior",
"destinationPositionX": 8.2, "destinationPositionX": 8.9718,
"destinationPositionY": 0.0, "destinationPositionY": 0.0,
"destinationPositionZ": -9.9, "destinationPositionZ": -9.57324,
"destinationRotationY": 0.0 "destinationRotationY": 0.0
} }
] ]

View File

@ -4,7 +4,7 @@
"id": "taxi_zone001", "id": "taxi_zone001",
"positionX": -15.0359, "positionX": -15.0359,
"positionY": 0.0, "positionY": 0.0,
"positionZ": -30.2937, "positionZ": -36.135,
"radius": 4.0, "radius": 4.0,
"hysteresis": 0.4, "hysteresis": 0.4,
"enabled": true "enabled": true

View File

@ -244,6 +244,7 @@ game_api.set_location_callbacks(
print("Enter location dorm") print("Enter location dorm")
local hp = game_api.getFloatValue("player_hp") local hp = game_api.getFloatValue("player_hp")
game_api.set_player_hp(hp) game_api.set_player_hp(hp)
game_api.set_teleport_active(0, false)
end, end,
function() function()
print("Exit location dorm") print("Exit location dorm")
@ -257,5 +258,13 @@ game_api.deactivate_interactive_object("Room_Cover_LivingRoom_W_N_2_001")
game_api.rotate_object("Door_Utility_-1_1_2_Leaf_001", 90, 0.01, nil) game_api.rotate_object("Door_Utility_-1_1_2_Leaf_001", 90, 0.01, nil)
game_api.rotate_object("Door_Utility_-1_-1_2_Leaf_001", -90, 0.01, nil) game_api.rotate_object("Door_Utility_-1_-1_2_Leaf_001", -90, 0.01, nil)
game_api.set_call_taxi_callback(
function()
game_api.set_teleport_active(0, true)
game_api.set_trigger_zone_enabled(0, false)
end
)
game_api.switch_navigation(0) game_api.switch_navigation(0)
print("Lua script loaded successfully--!") print("Lua script loaded successfully--!")

View File

@ -55,6 +55,7 @@ game_api.set_location_callbacks(
print("Enter location uni exterior") print("Enter location uni exterior")
local hp = game_api.getFloatValue("player_hp") local hp = game_api.getFloatValue("player_hp")
game_api.set_player_hp(hp) game_api.set_player_hp(hp)
game_api.set_teleport_active(0, false)
end, end,
function() function()
print("Exit location uni exterior") print("Exit location uni exterior")
@ -75,3 +76,24 @@ game_api.set_trigger_zone_callbacks("darklands_exit003",
darklands_exit001_enter_callback, darklands_exit001_enter_callback,
nil nil
) )
function taxi_zone001_enter_callback()
game_api.start_dialogue("dialog_taxi001")
game_api.set_trigger_zone_enabled(0, false)
end
game_api.set_call_taxi_callback(
function()
game_api.set_teleport_active(0, true)
game_api.set_trigger_zone_enabled(0, false)
end
)
game_api.set_trigger_zone_callbacks("taxi_zone001",
taxi_zone001_enter_callback,
nil
)

View File

@ -368,10 +368,7 @@ namespace ZL
if (currentLocation) if (currentLocation)
{ {
if (currentLocation->teleportZones.size() > 0) currentLocation->scriptEngine.callCallTaxiCallback();
{
currentLocation->teleportZones[0].active = true;
}
} }
}; };

View File

@ -26,6 +26,7 @@ namespace ZL {
sol::protected_function darklandsEnterCallback; sol::protected_function darklandsEnterCallback;
sol::protected_function darklandsExitCallback; sol::protected_function darklandsExitCallback;
sol::protected_function triggerNightEnterCallback; sol::protected_function triggerNightEnterCallback;
sol::protected_function callTaxiCallback;
sol::protected_function chatOpenCallbacks[3]; sol::protected_function chatOpenCallbacks[3];
}; };
@ -382,6 +383,12 @@ namespace ZL {
this_impl->triggerNightEnterCallback = onEnter.as<sol::protected_function>(); this_impl->triggerNightEnterCallback = onEnter.as<sol::protected_function>();
}); });
api.set_function("set_call_taxi_callback",
[this_impl = impl.get()](sol::object onTaxi) {
if (onTaxi.is<sol::protected_function>())
this_impl->callTaxiCallback = onTaxi.as<sol::protected_function>();
});
api.set_function("set_trigger_zone_enabled", api.set_function("set_trigger_zone_enabled",
[game](int index, bool value) { [game](int index, bool value) {
auto& triggerZones = game->triggerZones; auto& triggerZones = game->triggerZones;
@ -392,6 +399,29 @@ namespace ZL {
triggerZones[index].enabled = value; triggerZones[index].enabled = value;
}); });
// 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;
if (index < 0 || index >= static_cast<int>(zones.size())) {
std::cerr << "[script] set_teleport_active: index " << index << " out of range\n";
return;
}
zones[index].setActive(value);
});
// is_teleport_active(index) → bool
api.set_function("is_teleport_active",
[game](int index) -> bool {
auto& zones = game->teleportZones;
if (index < 0 || index >= static_cast<int>(zones.size())) {
std::cerr << "[script] is_teleport_active: index " << index << " out of range\n";
return false;
}
return zones[index].active;
});
// npc_set_hp(index, value) — sets an NPC's current HP directly. // npc_set_hp(index, value) — sets an NPC's current HP directly.
api.set_function("npc_set_hp", api.set_function("npc_set_hp",
@ -837,6 +867,15 @@ namespace ZL {
} }
} }
void ScriptEngine::callCallTaxiCallback() {
if (!impl || !impl->callTaxiCallback.valid()) return;
auto result = impl->callTaxiCallback();
if (!result.valid()) {
sol::error err = result;
std::cerr << "[SCRIPT] call_taxi callback error: " << err.what() << "\n";
}
}
void ScriptEngine::callCutsceneCompleteCallback(const std::string& cutsceneId) { void ScriptEngine::callCutsceneCompleteCallback(const std::string& cutsceneId) {
if (!impl) return; if (!impl) return;
auto it = impl->cutsceneCompleteCallbacks.find(cutsceneId); auto it = impl->cutsceneCompleteCallbacks.find(cutsceneId);

View File

@ -49,6 +49,7 @@ public:
void callCutsceneCompleteCallback(const std::string& cutsceneId); void callCutsceneCompleteCallback(const std::string& cutsceneId);
void callChatOpenCallback(int chatIndex); void callChatOpenCallback(int chatIndex);
void callCallTaxiCallback();
private: private:
struct Impl; struct Impl;

View File

@ -6,6 +6,8 @@ namespace ZL {
void TeleportZone::initSparks(std::shared_ptr<Texture> activeTex, std::shared_ptr<Texture> inactiveTex) void TeleportZone::initSparks(std::shared_ptr<Texture> activeTex, std::shared_ptr<Texture> inactiveTex)
{ {
activeTexture = activeTex;
inactiveTexture = inactiveTex;
sparks = std::make_unique<SparkEmitter>(); sparks = std::make_unique<SparkEmitter>();
std::vector<Vector3f> emitPoints; std::vector<Vector3f> emitPoints;
emitPoints.push_back(Vector3f{ position.x(), position.y(), position.z() }); emitPoints.push_back(Vector3f{ position.x(), position.y(), position.z() });
@ -25,6 +27,13 @@ void TeleportZone::initSparks(std::shared_ptr<Texture> activeTex, std::shared_pt
sparks->markConfigured(); sparks->markConfigured();
} }
void TeleportZone::setActive(bool isActive)
{
active = isActive;
if (sparks && activeTexture && inactiveTexture)
sparks->setTexture(isActive ? activeTexture : inactiveTexture);
}
void TeleportZone::update(float deltaMs) void TeleportZone::update(float deltaMs)
{ {
if (sparks) sparks->update(deltaMs); if (sparks) sparks->update(deltaMs);

View File

@ -17,8 +17,11 @@ struct TeleportZone {
Eigen::Vector3f destinationPosition = Eigen::Vector3f::Zero(); Eigen::Vector3f destinationPosition = Eigen::Vector3f::Zero();
float destinationRotationY = 0.0f; float destinationRotationY = 0.0f;
std::unique_ptr<SparkEmitter> sparks; std::unique_ptr<SparkEmitter> sparks;
std::shared_ptr<Texture> activeTexture;
std::shared_ptr<Texture> inactiveTexture;
void initSparks(std::shared_ptr<Texture> activeTex, std::shared_ptr<Texture> inactiveTex); void initSparks(std::shared_ptr<Texture> activeTex, std::shared_ptr<Texture> inactiveTex);
void setActive(bool isActive);
void update(float deltaMs); void update(float deltaMs);
void prepareForDraw(const Eigen::Matrix4f& viewMatrix); void prepareForDraw(const Eigen::Matrix4f& viewMatrix);
void draw(Renderer& renderer, float zoom, int width, int height); void draw(Renderer& renderer, float zoom, int width, int height);