diff options
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_mapgen.cpp | 35 | ||||
-rw-r--r-- | src/script/lua_api/l_mapgen.h | 6 | ||||
-rw-r--r-- | src/script/lua_api/l_object.cpp | 262 | ||||
-rw-r--r-- | src/script/lua_api/l_object.h | 41 |
4 files changed, 342 insertions, 2 deletions
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 76e94e97e..57090a58f 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -637,6 +637,20 @@ int ModApiMapgen::l_set_noiseparams(lua_State *L) } +// get_noiseparams(name) +int ModApiMapgen::l_get_noiseparams(lua_State *L) +{ + std::string name = luaL_checkstring(L, 1); + + NoiseParams np; + if (!g_settings->getNoiseParams(name, np)) + return 0; + + push_noiseparams(L, &np); + return 1; +} + + // set_gen_notify(flags, {deco_id_table}) int ModApiMapgen::l_set_gen_notify(lua_State *L) { @@ -661,6 +675,25 @@ int ModApiMapgen::l_set_gen_notify(lua_State *L) } +// get_gen_notify() +int ModApiMapgen::l_get_gen_notify(lua_State *L) +{ + EmergeManager *emerge = getServer(L)->getEmergeManager(); + push_flags_string(L, flagdesc_gennotify, emerge->gen_notify_on, + emerge->gen_notify_on); + + lua_newtable(L); + int i = 1; + for (std::set<u32>::iterator it = emerge->gen_notify_on_deco_ids.begin(); + it != emerge->gen_notify_on_deco_ids.end(); ++it) { + lua_pushnumber(L, *it); + lua_rawseti(L, -2, i); + i++; + } + return 2; +} + + // register_biome({lots of stuff}) int ModApiMapgen::l_register_biome(lua_State *L) { @@ -1187,7 +1220,9 @@ void ModApiMapgen::Initialize(lua_State *L, int top) API_FCT(get_mapgen_params); API_FCT(set_mapgen_params); API_FCT(set_noiseparams); + API_FCT(get_noiseparams); API_FCT(set_gen_notify); + API_FCT(get_gen_notify); API_FCT(register_biome); API_FCT(register_decoration); diff --git a/src/script/lua_api/l_mapgen.h b/src/script/lua_api/l_mapgen.h index 84e556f63..7440d1285 100644 --- a/src/script/lua_api/l_mapgen.h +++ b/src/script/lua_api/l_mapgen.h @@ -39,9 +39,15 @@ private: // set_noiseparam_defaults(name, noiseparams, set_default) static int l_set_noiseparams(lua_State *L); + // get_noiseparam_defaults(name) + static int l_get_noiseparams(lua_State *L); + // set_gen_notify(flagstring) static int l_set_gen_notify(lua_State *L); + // set_gen_notify(flagstring) + static int l_get_gen_notify(lua_State *L); + // register_biome({lots of stuff}) static int l_register_biome(lua_State *L); diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index c83c8c747..48d054dcd 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -29,7 +29,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content_sao.h" #include "server.h" #include "hud.h" +#include "scripting_game.h" +#define GET_ENV_PTR ServerEnvironment* env = \ + dynamic_cast<ServerEnvironment*>(getEnv(L)); \ + if (env == NULL) return 0 struct EnumString es_HudElementType[] = { @@ -376,6 +380,20 @@ int ObjectRef::l_set_armor_groups(lua_State *L) return 0; } +// get_armor_groups(self) +int ObjectRef::l_get_armor_groups(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + ObjectRef *ref = checkobject(L, 1); + ServerActiveObject *co = getobject(ref); + if (co == NULL) + return 0; + // Do it + ItemGroupList groups = co->getArmorGroups(); + push_groups(L, groups); + return 1; +} + // set_physics_override(self, physics_override_speed, physics_override_jump, // physics_override_gravity, sneak, sneak_glitch) int ObjectRef::l_set_physics_override(lua_State *L) @@ -409,6 +427,28 @@ int ObjectRef::l_set_physics_override(lua_State *L) return 0; } +// get_physics_override(self) +int ObjectRef::l_get_physics_override(lua_State *L) +{ + ObjectRef *ref = checkobject(L, 1); + PlayerSAO *co = (PlayerSAO *)getobject(ref); + if (co == NULL) + return 0; + // Do it + lua_newtable(L); + lua_pushnumber(L, co->m_physics_override_speed); + lua_setfield(L, -2, "speed"); + lua_pushnumber(L, co->m_physics_override_jump); + lua_setfield(L, -2, "jump"); + lua_pushnumber(L, co->m_physics_override_gravity); + lua_setfield(L, -2, "gravity"); + lua_pushboolean(L, co->m_physics_override_sneak); + lua_setfield(L, -2, "sneak"); + lua_pushboolean(L, co->m_physics_override_sneak_glitch); + lua_setfield(L, -2, "sneak_glitch"); + return 1; +} + // set_animation(self, frame_range, frame_speed, frame_blend) int ObjectRef::l_set_animation(lua_State *L) { @@ -430,6 +470,26 @@ int ObjectRef::l_set_animation(lua_State *L) return 0; } +// get_animation(self) +int ObjectRef::l_get_animation(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + ObjectRef *ref = checkobject(L, 1); + ServerActiveObject *co = getobject(ref); + if (co == NULL) + return 0; + // Do it + v2f frames = v2f(1,1); + float frame_speed = 15; + float frame_blend = 0; + co->getAnimation(&frames, &frame_speed, &frame_blend); + + push_v2f(L, frames); + lua_pushnumber(L, frame_speed); + lua_pushnumber(L, frame_blend); + return 3; +} + // set_local_animation(self, {stand/idle}, {walk}, {dig}, {walk+dig}, frame_speed) int ObjectRef::l_set_local_animation(lua_State *L) { @@ -455,6 +515,27 @@ int ObjectRef::l_set_local_animation(lua_State *L) return 0; } +// get_local_animation(self) +int ObjectRef::l_get_local_animation(lua_State *L) +{ + //NO_MAP_LOCK_REQUIRED + ObjectRef *ref = checkobject(L, 1); + Player *player = getplayer(ref); + if (player == NULL) + return 0; + + v2s32 frames[4]; + float frame_speed; + player->getLocalAnimations(frames, &frame_speed); + + for (int i = 0; i < 4; i++) { + push_v2s32(L, frames[i]); + } + + lua_pushnumber(L, frame_speed); + return 5; +} + // set_eye_offset(self, v3f first pv, v3f third pv) int ObjectRef::l_set_eye_offset(lua_State *L) { @@ -485,6 +566,20 @@ int ObjectRef::l_set_eye_offset(lua_State *L) return 0; } +// get_eye_offset(self) +int ObjectRef::l_get_eye_offset(lua_State *L) +{ + //NO_MAP_LOCK_REQUIRED; + ObjectRef *ref = checkobject(L, 1); + Player *player = getplayer(ref); + if (player == NULL) + return 0; + // Do it + push_v3f(L, player->eye_offset_first); + push_v3f(L, player->eye_offset_third); + return 2; +} + // set_bone_position(self, std::string bone, v3f position, v3f rotation) int ObjectRef::l_set_bone_position(lua_State *L) { @@ -506,6 +601,28 @@ int ObjectRef::l_set_bone_position(lua_State *L) return 0; } +// get_bone_position(self, bone) +int ObjectRef::l_get_bone_position(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + ObjectRef *ref = checkobject(L, 1); + ServerActiveObject *co = getobject(ref); + if (co == NULL) + return 0; + // Do it + std::string bone = ""; + if(!lua_isnil(L, 2)) + bone = lua_tostring(L, 2); + + v3f position = v3f(0, 0, 0); + v3f rotation = v3f(0, 0, 0); + co->getBonePosition(bone, &position, &rotation); + + push_v3f(L, position); + push_v3f(L, rotation); + return 2; +} + // set_attach(self, parent, bone, position, rotation) int ObjectRef::l_set_attach(lua_State *L) { @@ -530,6 +647,34 @@ int ObjectRef::l_set_attach(lua_State *L) return 0; } +// get_attach(self) +int ObjectRef::l_get_attach(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + GET_ENV_PTR; + + ObjectRef *ref = checkobject(L, 1); + ServerActiveObject *co = getobject(ref); + if (co == NULL) + return 0; + + // Do it + int parent_id = 0; + std::string bone = ""; + v3f position = v3f(0, 0, 0); + v3f rotation = v3f(0, 0, 0); + co->getAttachment(&parent_id, &bone, &position, &rotation); + if (!parent_id) + return 0; + ServerActiveObject *parent = env->getActiveObject(parent_id); + + getScriptApiBase(L)->objectrefGetOrCreate(L, parent); + lua_pushlstring(L, bone.c_str(), bone.size()); + push_v3f(L, position); + push_v3f(L, rotation); + return 4; +} + // set_detach(self) int ObjectRef::l_set_detach(lua_State *L) { @@ -557,6 +702,21 @@ int ObjectRef::l_set_properties(lua_State *L) return 0; } +// get_properties(self) +int ObjectRef::l_get_properties(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + ObjectRef *ref = checkobject(L, 1); + ServerActiveObject *co = getobject(ref); + if (co == NULL) + return 0; + ObjectProperties *prop = co->accessObjectProperties(); + if (!prop) + return 0; + push_object_properties(L, prop); + return 1; +} + // is_player(self) int ObjectRef::l_is_player(lua_State *L) { @@ -1185,6 +1345,20 @@ int ObjectRef::l_hud_set_hotbar_itemcount(lua_State *L) return 1; } +// hud_get_hotbar_itemcount(self) +int ObjectRef::l_hud_get_hotbar_itemcount(lua_State *L) +{ + ObjectRef *ref = checkobject(L, 1); + Player *player = getplayer(ref); + if (player == NULL) + return 0; + + s32 hotbar_itemcount = getServer(L)->hudGetHotbarItemcount(player); + + lua_pushnumber(L, hotbar_itemcount); + return 1; +} + // hud_set_hotbar_image(self, name) int ObjectRef::l_hud_set_hotbar_image(lua_State *L) { @@ -1199,6 +1373,19 @@ int ObjectRef::l_hud_set_hotbar_image(lua_State *L) return 1; } +// hud_get_hotbar_image(self) +int ObjectRef::l_hud_get_hotbar_image(lua_State *L) +{ + ObjectRef *ref = checkobject(L, 1); + Player *player = getplayer(ref); + if (player == NULL) + return 0; + + std::string name = getServer(L)->hudGetHotbarImage(player); + lua_pushlstring(L, name.c_str(), name.size()); + return 1; +} + // hud_set_hotbar_selected_image(self, name) int ObjectRef::l_hud_set_hotbar_selected_image(lua_State *L) { @@ -1213,6 +1400,19 @@ int ObjectRef::l_hud_set_hotbar_selected_image(lua_State *L) return 1; } +// hud_get_hotbar_selected_image(self) +int ObjectRef::l_hud_get_hotbar_selected_image(lua_State *L) +{ + ObjectRef *ref = checkobject(L, 1); + Player *player = getplayer(ref); + if (player == NULL) + return 0; + + std::string name = getServer(L)->hudGetHotbarSelectedImage(player); + lua_pushlstring(L, name.c_str(), name.size()); + return 1; +} + // set_sky(self, bgcolor, type, list) int ObjectRef::l_set_sky(lua_State *L) { @@ -1251,6 +1451,33 @@ int ObjectRef::l_set_sky(lua_State *L) return 1; } +// get_sky(self) +int ObjectRef::l_get_sky(lua_State *L) +{ + ObjectRef *ref = checkobject(L, 1); + Player *player = getplayer(ref); + if (player == NULL) + return 0; + video::SColor bgcolor(255, 255, 255, 255); + std::string type; + std::vector<std::string> params; + + player->getSky(&bgcolor, &type, ¶ms); + type = type == "" ? "regular" : type; + + push_ARGB8(L, bgcolor); + lua_pushlstring(L, type.c_str(), type.size()); + lua_newtable(L); + s16 i = 1; + for (std::vector<std::string>::iterator it = params.begin(); + it != params.end(); ++it) { + lua_pushlstring(L, it->c_str(), it->size()); + lua_rawseti(L, -2, i); + i++; + } + return 3; +} + // override_day_night_ratio(self, brightness=0...1) int ObjectRef::l_override_day_night_ratio(lua_State *L) { @@ -1273,6 +1500,26 @@ int ObjectRef::l_override_day_night_ratio(lua_State *L) return 1; } +// get_day_night_ratio(self) +int ObjectRef::l_get_day_night_ratio(lua_State *L) +{ + ObjectRef *ref = checkobject(L, 1); + Player *player = getplayer(ref); + if (player == NULL) + return 0; + + bool do_override; + float ratio; + player->getDayNightRatio(&do_override, &ratio); + + if (do_override) + lua_pushnumber(L, ratio); + else + lua_pushnil(L); + + return 1; +} + // set_nametag_attributes(self, attributes) int ObjectRef::l_set_nametag_attributes(lua_State *L) { @@ -1389,12 +1636,16 @@ const luaL_reg ObjectRef::methods[] = { luamethod(ObjectRef, get_wielded_item), luamethod(ObjectRef, set_wielded_item), luamethod(ObjectRef, set_armor_groups), - luamethod(ObjectRef, set_physics_override), + luamethod(ObjectRef, get_armor_groups), luamethod(ObjectRef, set_animation), + luamethod(ObjectRef, get_animation), luamethod(ObjectRef, set_bone_position), + luamethod(ObjectRef, get_bone_position), luamethod(ObjectRef, set_attach), + luamethod(ObjectRef, get_attach), luamethod(ObjectRef, set_detach), luamethod(ObjectRef, set_properties), + luamethod(ObjectRef, get_properties), // LuaEntitySAO-only luamethod(ObjectRef, setvelocity), luamethod(ObjectRef, getvelocity), @@ -1421,6 +1672,8 @@ const luaL_reg ObjectRef::methods[] = { luamethod(ObjectRef, get_inventory_formspec), luamethod(ObjectRef, get_player_control), luamethod(ObjectRef, get_player_control_bits), + luamethod(ObjectRef, set_physics_override), + luamethod(ObjectRef, get_physics_override), luamethod(ObjectRef, hud_add), luamethod(ObjectRef, hud_remove), luamethod(ObjectRef, hud_change), @@ -1428,12 +1681,19 @@ const luaL_reg ObjectRef::methods[] = { luamethod(ObjectRef, hud_set_flags), luamethod(ObjectRef, hud_get_flags), luamethod(ObjectRef, hud_set_hotbar_itemcount), + luamethod(ObjectRef, hud_get_hotbar_itemcount), luamethod(ObjectRef, hud_set_hotbar_image), + luamethod(ObjectRef, hud_get_hotbar_image), luamethod(ObjectRef, hud_set_hotbar_selected_image), + luamethod(ObjectRef, hud_get_hotbar_selected_image), luamethod(ObjectRef, set_sky), + luamethod(ObjectRef, get_sky), luamethod(ObjectRef, override_day_night_ratio), + luamethod(ObjectRef, get_day_night_ratio), luamethod(ObjectRef, set_local_animation), + luamethod(ObjectRef, get_local_animation), luamethod(ObjectRef, set_eye_offset), + luamethod(ObjectRef, get_eye_offset), luamethod(ObjectRef, set_nametag_attributes), luamethod(ObjectRef, get_nametag_attributes), {0,0} diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h index af3ed5ef0..02bb06ecc 100644 --- a/src/script/lua_api/l_object.h +++ b/src/script/lua_api/l_object.h @@ -101,25 +101,43 @@ private: // set_armor_groups(self, groups) static int l_set_armor_groups(lua_State *L); + // get_armor_groups(self) + static int l_get_armor_groups(lua_State *L); + // set_physics_override(self, physics_override_speed, physics_override_jump, // physics_override_gravity, sneak, sneak_glitch) static int l_set_physics_override(lua_State *L); + // get_physics_override(self) + static int l_get_physics_override(lua_State *L); + // set_animation(self, frame_range, frame_speed, frame_blend) static int l_set_animation(lua_State *L); + // get_animation(self) + static int l_get_animation(lua_State *L); + // set_bone_position(self, std::string bone, v3f position, v3f rotation) static int l_set_bone_position(lua_State *L); + // get_bone_position(self, bone) + static int l_get_bone_position(lua_State *L); + // set_attach(self, parent, bone, position, rotation) static int l_set_attach(lua_State *L); + // get_attach(self) + static int l_get_attach(lua_State *L); + // set_detach(self) static int l_set_detach(lua_State *L); // set_properties(self, properties) static int l_set_properties(lua_State *L); + // get_properties(self) + static int l_get_properties(lua_State *L); + // is_player(self) static int l_is_player(lua_State *L); @@ -222,24 +240,45 @@ private: // hud_set_hotbar_itemcount(self, hotbar_itemcount) static int l_hud_set_hotbar_itemcount(lua_State *L); + // hud_get_hotbar_itemcount(self) + static int l_hud_get_hotbar_itemcount(lua_State *L); + // hud_set_hotbar_image(self, name) static int l_hud_set_hotbar_image(lua_State *L); + // hud_get_hotbar_image(self) + static int l_hud_get_hotbar_image(lua_State *L); + // hud_set_hotbar_selected_image(self, name) static int l_hud_set_hotbar_selected_image(lua_State *L); + // hud_get_hotbar_selected_image(self) + static int l_hud_get_hotbar_selected_image(lua_State *L); + // set_sky(self, type, list) static int l_set_sky(lua_State *L); - // override_day_night_ratio(self, type, list) + // get_sky(self, type, list) + static int l_get_sky(lua_State *L); + + // override_day_night_ratio(self, type) static int l_override_day_night_ratio(lua_State *L); + // get_day_night_ratio(self) + static int l_get_day_night_ratio(lua_State *L); + // set_local_animation(self, {stand/idle}, {walk}, {dig}, {walk+dig}, frame_speed) static int l_set_local_animation(lua_State *L); + // get_local_animation(self) + static int l_get_local_animation(lua_State *L); + // set_eye_offset(self, v3f first pv, v3f third pv) static int l_set_eye_offset(lua_State *L); + // get_eye_offset(self) + static int l_get_eye_offset(lua_State *L); + // set_nametag_attributes(self, attributes) static int l_set_nametag_attributes(lua_State *L); |