diff --git a/src/physics/physical_object.hpp b/src/physics/physical_object.hpp index 41a8b8823..a06339029 100644 --- a/src/physics/physical_object.hpp +++ b/src/physics/physical_object.hpp @@ -213,6 +213,8 @@ public: // ------------------------------------------------------------------------ const std::string& getOnItemCollisionFunction() const { return m_on_item_collision; } // ------------------------------------------------------------------------ + TrackObject* getTrackObject() { return m_object; } + // Methods usable by scripts /** diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp index ee2549e12..1488de877 100644 --- a/src/physics/physics.cpp +++ b/src/physics/physics.cpp @@ -40,6 +40,7 @@ #include "race/race_manager.hpp" #include "scriptengine/script_engine.hpp" #include "tracks/track.hpp" +#include "tracks/track_object.hpp" #include "utils/profiler.hpp" // ---------------------------------------------------------------------------- @@ -189,12 +190,24 @@ void Physics::update(float dt) PhysicalObject* obj = p->getUserPointer(0)->getPointerPhysicalObject(); std::string obj_id = obj->getID(); std::string scripting_function = obj->getOnKartCollisionFunction(); + + TrackObject* to = obj->getTrackObject(); + TrackObject* library = to->getParentLibrary(); + std::string lib_id; + std::string* lib_id_ptr = NULL; + if (library != NULL) + { + lib_id = library->getID(); + lib_id_ptr = &lib_id; + } + if (scripting_function.size() > 0) { - script_engine->runFunction("void " + scripting_function + "(int, const string)", + script_engine->runFunction("void " + scripting_function + "(int, const string, const string)", [&](asIScriptContext* ctx) { ctx->SetArgDWord(0, kartId); - ctx->SetArgObject(1, &obj_id); + ctx->SetArgObject(1, lib_id_ptr); + ctx->SetArgObject(2, &obj_id); }); } if (obj->isCrashReset()) diff --git a/src/scriptengine/script_engine.cpp b/src/scriptengine/script_engine.cpp index dfd215edb..7c03d35f4 100644 --- a/src/scriptengine/script_engine.cpp +++ b/src/scriptengine/script_engine.cpp @@ -87,11 +87,9 @@ namespace Scripting */ std::string getScript(std::string fileName) { - std::string script_dir = file_manager->getAsset(FileManager::SCRIPT, ""); - script_dir += World::getWorld()->getTrack()->getIdent() + "/"; + std::string script_path = World::getWorld()->getTrack()->getTrackFile(fileName); - script_dir += fileName; - FILE *f = fopen(script_dir.c_str(), "rb"); + FILE *f = fopen(script_path.c_str(), "rb"); if (f == NULL) { Log::debug("Scripting", "File does not exist : {0}.as", fileName.c_str()); diff --git a/src/tracks/track_object.hpp b/src/tracks/track_object.hpp index 4647b6ef1..7031e9b7c 100644 --- a/src/tracks/track_object.hpp +++ b/src/tracks/track_object.hpp @@ -125,6 +125,11 @@ public: const Material **material, btVector3 *normal, bool interpolate_normal) const; + TrackObject* getParentLibrary() + { + return m_parent_library; + } + // ------------------------------------------------------------------------ /** To finish object constructions. Called after the track model * is ready. */