aboutsummaryrefslogtreecommitdiff
path: root/advtrains/textures
ModeNameSize
-rwxr-xr-xadvtrains_across.png302logplain
-rwxr-xr-xadvtrains_across_anim.png524logplain
-rwxr-xr-xadvtrains_boiler.png413logplain
-rwxr-xr-xadvtrains_chimney.png309logplain
-rw-r--r--advtrains_copytool.png779logplain
-rwxr-xr-xadvtrains_couple.png339logplain
-rw-r--r--advtrains_cpl_lock.png209logplain
-rw-r--r--advtrains_cpl_unlock.png213logplain
-rwxr-xr-xadvtrains_discouple.png293logplain
-rwxr-xr-xadvtrains_driver_cab.png352logplain
-rwxr-xr-xadvtrains_dtrack_atc_placer.png1259logplain
-rwxr-xr-xadvtrains_dtrack_bumper_placer.png2213logplain
-rwxr-xr-xadvtrains_dtrack_detector_placer.png1253logplain
-rwxr-xr-xadvtrains_dtrack_load_placer.png1248logplain
-rwxr-xr-xadvtrains_dtrack_placer.png1097logplain
-rwxr-xr-xadvtrains_dtrack_rail.png4582logplain
-rwxr-xr-xadvtrains_dtrack_shared.png7141logplain
-rwxr-xr-xadvtrains_dtrack_shared_atc.png7215logplain
-rwxr-xr-xadvtrains_dtrack_shared_detector_off.png7180logplain
-rwxr-xr-xadvtrains_dtrack_shared_detector_on.png7181logplain
-rwxr-xr-xadvtrains_dtrack_shared_load.png7339logplain
-rwxr-xr-xadvtrains_dtrack_shared_unload.png7338logplain
-rwxr-xr-xadvtrains_dtrack_slopeplacer.png2415logplain
-rwxr-xr-xadvtrains_dtrack_unload_placer.png1260logplain
-rw-r--r--advtrains_hud_arrow.png91logplain
-rw-r--r--advtrains_hud_atc.png528logplain
-rw-r--r--advtrains_hud_bg.png67logplain
-rw-r--r--advtrains_hud_lzb.png398logplain
-rw-r--r--advtrains_hud_shunt.png476logplain
-rwxr-xr-xadvtrains_platform.png193logplain
-rw-r--r--advtrains_platform_diag.png93logplain
-rwxr-xr-xadvtrains_retrosignal.png8496logplain
-rwxr-xr-xadvtrains_retrosignal_inv.png2242logplain
-rwxr-xr-xadvtrains_signal_inv.png856logplain
-rwxr-xr-xadvtrains_signal_off.png5882logplain
-rwxr-xr-xadvtrains_signal_on.png5884logplain
-rwxr-xr-xadvtrains_signal_wall_off.png3056logplain
-rwxr-xr-xadvtrains_signal_wall_on.png3043logplain
-rwxr-xr-xadvtrains_track_cr.png33370logplain
-rwxr-xr-xadvtrains_track_cr_45.png33938logplain
-rwxr-xr-xadvtrains_track_placer.png32349logplain
-rwxr-xr-xadvtrains_track_st.png20405logplain
-rwxr-xr-xadvtrains_track_st_45.png39977logplain
-rwxr-xr-xadvtrains_track_swlcr.png33378logplain
-rwxr-xr-xadvtrains_track_swlcr_45.png45772logplain
-rwxr-xr-xadvtrains_track_swlst.png32321logplain
-rwxr-xr-xadvtrains_track_swlst_45.png46408logplain
-rwxr-xr-xadvtrains_track_swrcr.png33670logplain
-rwxr-xr-xadvtrains_track_swrcr_45.png46865logplain
-rwxr-xr-xadvtrains_track_swrst.png32654logplain
-rwxr-xr-xadvtrains_track_swrst_45.png47636logplain
-rwxr-xr-xadvtrains_trackworker.png328logplain
-rw-r--r--advtrains_wagon_placeholder.png723logplain
-rwxr-xr-xadvtrains_wheel.png582logplain
-rwxr-xr-xdrwho_screwdriver.png328logplain
script_path << std::endl; lua_State *L = getStack(); int error_handler = PUSH_ERROR_HANDLER(L); bool ok; if (m_secure) { ok = ScriptApiSecurity::safeLoadFile(L, script_path.c_str()); } else { ok = !luaL_loadfile(L, script_path.c_str()); } ok = ok && !lua_pcall(L, 0, 0, error_handler); if (!ok) { std::string error_msg = readParam<std::string>(L, -1); lua_pop(L, 2); // Pop error message and error handler throw ModError("Failed to load and run script from " + script_path + ":\n" + error_msg); } lua_pop(L, 1); // Pop error handler } #ifndef SERVER void ScriptApiBase::loadModFromMemory(const std::string &mod_name) { ModNameStorer mod_name_storer(getStack(), mod_name); sanity_check(m_type == ScriptingType::Client); const std::string init_filename = mod_name + ":init.lua"; const std::string chunk_name = "@" + init_filename; const std::string *contents = getClient()->getModFile(init_filename); if (!contents) throw ModError("Mod \"" + mod_name + "\" lacks init.lua"); verbosestream << "Loading and running script " << chunk_name << std::endl; lua_State *L = getStack(); int error_handler = PUSH_ERROR_HANDLER(L); bool ok = ScriptApiSecurity::safeLoadString(L, *contents, chunk_name.c_str()); if (ok) ok = !lua_pcall(L, 0, 0, error_handler); if (!ok) { std::string error_msg = luaL_checkstring(L, -1); lua_pop(L, 2); // Pop error message and error handler throw ModError("Failed to load and run mod \"" + mod_name + "\":\n" + error_msg); } lua_pop(L, 1); // Pop error handler } #endif // Push the list of callbacks (a lua table). // Then push nargs arguments. // Then call this function, which // - runs the callbacks // - replaces the table and arguments with the return value, // computed depending on mode // This function must only be called with scriptlock held (i.e. inside of a // code block with SCRIPTAPI_PRECHECKHEADER declared) void ScriptApiBase::runCallbacksRaw(int nargs, RunCallbacksMode mode, const char *fxn) { #ifndef SERVER // Hard fail for bad guarded callbacks // Only run callbacks when the scripting enviroment is loaded FATAL_ERROR_IF(m_type == ScriptingType::Client && !getClient()->modsLoaded(), fxn); #endif #ifdef SCRIPTAPI_LOCK_DEBUG assert(m_lock_recursion_count > 0); #endif lua_State *L = getStack(); FATAL_ERROR_IF(lua_gettop(L) < nargs + 1, "Not enough arguments"); // Insert error handler PUSH_ERROR_HANDLER(L); int error_handler = lua_gettop(L) - nargs - 1; lua_insert(L, error_handler); // Insert run_callbacks between error handler and table lua_getglobal(L, "core"); lua_getfield(L, -1, "run_callbacks"); lua_remove(L, -2); lua_insert(L, error_handler + 1); // Insert mode after table lua_pushnumber(L, (int)mode); lua_insert(L, error_handler + 3); // Stack now looks like this: // ... <error handler> <run_callbacks> <table> <mode> <arg#1> <arg#2> ... <arg#n> int result = lua_pcall(L, nargs + 2, 1, error_handler); if (result != 0) scriptError(result, fxn); lua_remove(L, error_handler); } void ScriptApiBase::realityCheck() { int top = lua_gettop(m_luastack); if (top >= 30) { dstream << "Stack is over 30:" << std::endl; stackDump(dstream); std::string traceback = script_get_backtrace(m_luastack); throw LuaError("Stack is over 30 (reality check)\n" + traceback); } } void ScriptApiBase::scriptError(int result, const char *fxn) { script_error(getStack(), result, m_last_run_mod.c_str(), fxn); } void ScriptApiBase::stackDump(std::ostream &o) { int top = lua_gettop(m_luastack); for (int i = 1; i <= top; i++) { /* repeat for each level */ int t = lua_type(m_luastack, i); switch (t) { case LUA_TSTRING: /* strings */ o << "\"" << readParam<std::string>(m_luastack, i) << "\""; break; case LUA_TBOOLEAN: /* booleans */ o << (readParam<bool>(m_luastack, i) ? "true" : "false"); break; case LUA_TNUMBER: /* numbers */ { char buf[10]; porting::mt_snprintf(buf, sizeof(buf), "%lf", lua_tonumber(m_luastack, i)); o << buf; break; } default: /* other values */ o << lua_typename(m_luastack, t); break; } o << " "; } o << std::endl; } void ScriptApiBase::setOriginDirect(const char *origin) { m_last_run_mod = origin ? origin : "??"; } void ScriptApiBase::setOriginFromTableRaw(int index, const char *fxn) { #ifdef SCRIPTAPI_DEBUG lua_State *L = getStack(); m_last_run_mod = lua_istable(L, index) ? getstringfield_default(L, index, "mod_origin", "") : ""; //printf(">>>> running %s for mod: %s\n", fxn, m_last_run_mod.c_str()); #endif } /* * How ObjectRefs are handled in Lua: * When an active object is created, an ObjectRef is created on the Lua side * and stored in core.object_refs[id]. * Methods that require an ObjectRef to a certain object retrieve it from that * table instead of creating their own.(*) * When an active object is removed, the existing ObjectRef is invalidated * using ::set_null() and removed from the core.object_refs table. * (*) An exception to this are NULL ObjectRefs and anonymous ObjectRefs * for objects without ID. * It's unclear what the latter are needed for and their use is problematic * since we lose control over the ref and the contained pointer. */ void ScriptApiBase::addObjectReference(ServerActiveObject *cobj) { SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_add_object_reference: id="<<cobj->getId()<<std::endl; // Create object on stack ObjectRef::create(L, cobj); // Puts ObjectRef (as userdata) on stack int object = lua_gettop(L); // Get core.object_refs table lua_getglobal(L, "core"); lua_getfield(L, -1, "object_refs"); luaL_checktype(L, -1, LUA_TTABLE); int objectstable = lua_gettop(L); // object_refs[id] = object lua_pushnumber(L, cobj->getId()); // Push id lua_pushvalue(L, object); // Copy object to top of stack lua_settable(L, objectstable); } void ScriptApiBase::removeObjectReference(ServerActiveObject *cobj) { SCRIPTAPI_PRECHECKHEADER //infostream<<"scriptapi_rm_object_reference: id="<<cobj->getId()<<std::endl; // Get core.object_refs table lua_getglobal(L, "core"); lua_getfield(L, -1, "object_refs"); luaL_checktype(L, -1, LUA_TTABLE); int objectstable = lua_gettop(L); // Get object_refs[id] lua_pushnumber(L, cobj->getId()); // Push id lua_gettable(L, objectstable); // Set object reference to NULL ObjectRef::set_null(L); lua_pop(L, 1); // pop object // Set object_refs[id] = nil lua_pushnumber(L, cobj->getId()); // Push id lua_pushnil(L); lua_settable(L, objectstable); } // Creates a new anonymous reference if cobj=NULL or id=0 void ScriptApiBase::objectrefGetOrCreate(lua_State *L, ServerActiveObject *cobj) { if (cobj == NULL || cobj->getId() == 0) { ObjectRef::create(L, cobj); } else { push_objectRef(L, cobj->getId()); if (cobj->isGone()) warningstream << "ScriptApiBase::objectrefGetOrCreate(): " << "Pushing ObjectRef to removed/deactivated object" << ", this is probably a bug." << std::endl; } } void ScriptApiBase::pushPlayerHPChangeReason(lua_State *L, const PlayerHPChangeReason &reason) { if (reason.hasLuaReference()) lua_rawgeti(L, LUA_REGISTRYINDEX, reason.lua_reference); else lua_newtable(L); lua_getfield(L, -1, "type"); bool has_type = (bool)lua_isstring(L, -1); lua_pop(L, 1); if (!has_type) { lua_pushstring(L, reason.getTypeAsString().c_str()); lua_setfield(L, -2, "type"); } lua_pushstring(L, reason.from_mod ? "mod" : "engine"); lua_setfield(L, -2, "from"); if (reason.object) { objectrefGetOrCreate(L, reason.object); lua_setfield(L, -2, "object"); } if (!reason.node.empty()) { lua_pushstring(L, reason.node.c_str()); lua_setfield(L, -2, "node"); } } Server* ScriptApiBase::getServer() { return dynamic_cast<Server *>(m_gamedef); } #ifndef SERVER Client* ScriptApiBase::getClient() { return dynamic_cast<Client *>(m_gamedef); } #endif