]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/scriptapi.cpp
Pre-select current game in world creation dialog
[dragonfireclient.git] / src / scriptapi.cpp
index f95f5a29de908a48170e7cd9e119c90408c3403d..f0fe1950e0127b270fb58a0e8908cf5c5dc4079a 100644 (file)
@@ -30,6 +30,7 @@ extern "C" {
 #include "settings.h" // For accessing g_settings
 #include "main.h" // For g_settings
 #include "biome.h"
+#include "emerge.h"
 #include "script.h"
 #include "rollback.h"
 
@@ -44,6 +45,7 @@ extern "C" {
 #include "scriptapi_item.h"
 #include "scriptapi_content.h"
 #include "scriptapi_craft.h"
+#include "scriptapi_particles.h"
 
 /*****************************************************************************/
 /* Mod related                                                               */
@@ -241,6 +243,14 @@ struct EnumString es_BiomeTerrainType[] =
        {0, NULL},
 };
 
+struct EnumString es_OreType[] =
+{
+       {ORE_SCATTER,  "scatter"},
+       {ORE_SHEET,    "sheet"},
+       {ORE_CLAYLIKE, "claylike"},
+       {0, NULL},
+};
+
 /*****************************************************************************/
 /* Parameters                                                                */
 /*****************************************************************************/
@@ -606,78 +616,36 @@ static int l_get_server_status(lua_State *L)
        return 1;
 }
 
-// register_biome_groups({frequencies})
-static int l_register_biome_groups(lua_State *L)
-{
-       luaL_checktype(L, 1, LUA_TTABLE);
-       int index = 1;
-       if (!lua_istable(L, index))
-               throw LuaError(L, "register_biome_groups: parameter is not a table");
-
-       BiomeDefManager *bmgr = get_server(L)->getBiomeDef();
-       if (!bmgr) {
-               verbosestream << "register_biome_groups: BiomeDefManager not active" << std::endl;
-               return 0;
-       }
-
-       lua_pushnil(L);
-       for (int i = 1; lua_next(L, index) != 0; i++) {
-               bmgr->addBiomeGroup(lua_tonumber(L, -1));
-               lua_pop(L, 1);
-       }
-       lua_pop(L, 1);
-
-       return 0;
-}
 
 // register_biome({lots of stuff})
 static int l_register_biome(lua_State *L)
 {
-       luaL_checktype(L, 1, LUA_TTABLE);
-       int index = 1, groupid;
-       std::string nodename;
+       int index = 1;
+       luaL_checktype(L, index, LUA_TTABLE);
 
-       IWritableNodeDefManager *ndef = get_server(L)->getWritableNodeDefManager();
-       BiomeDefManager *bmgr = get_server(L)->getBiomeDef();
+       BiomeDefManager *bmgr = get_server(L)->getEmergeManager()->biomedef;
        if (!bmgr) {
                verbosestream << "register_biome: BiomeDefManager not active" << std::endl;
                return 0;
        }
-
-       groupid = getintfield_default(L, index, "group_id", 0);
-
+       
        enum BiomeTerrainType terrain = (BiomeTerrainType)getenumfield(L, index,
                                        "terrain_type", es_BiomeTerrainType, BIOME_TERRAIN_NORMAL);
        Biome *b = bmgr->createBiome(terrain);
 
-       b->name = getstringfield_default(L, index, "name", "");
-
-       if (getstringfield(L, index, "node_top", nodename))
-               b->n_top = MapNode(ndef->getId(nodename));
-       else
-               b->n_top = MapNode(CONTENT_IGNORE);
-
-       if (getstringfield(L, index, "node_filler", nodename))
-               b->n_filler = MapNode(ndef->getId(nodename));
-       else
-               b->n_filler = b->n_top;
-
-       b->ntopnodes = getintfield_default(L, index, "num_top_nodes", 0);
-
-       b->height_min   = getintfield_default(L, index, "height_min", 0);
-       b->height_max   = getintfield_default(L, index, "height_max", 0);
-       b->heat_min     = getfloatfield_default(L, index, "heat_min", 0.);
-       b->heat_max     = getfloatfield_default(L, index, "heat_max", 0.);
-       b->humidity_min = getfloatfield_default(L, index, "humidity_min", 0.);
-       b->humidity_max = getfloatfield_default(L, index, "humidity_max", 0.);
-
-       b->np = new NoiseParams; // should read an entire NoiseParams later on...
-       getfloatfield(L, index, "scale", b->np->scale);
-       getfloatfield(L, index, "offset", b->np->offset);
-
-       b->groupid = (s8)groupid;
-       b->flags   = 0; //reserved
-
+       b->name            = getstringfield_default(L, index, "name", "");
+       b->top_nodename    = getstringfield_default(L, index, "top_node", "");
+       b->top_depth       = getintfield_default(L, index, "top_depth", 0);
+       b->filler_nodename = getstringfield_default(L, index, "filler_node", "");
+       b->filler_height   = getintfield_default(L, index, "filler_height", 0);
+       b->height_min      = getintfield_default(L, index, "height_min", 0);
+       b->height_max      = getintfield_default(L, index, "height_max", 0);
+       b->heat_point      = getfloatfield_default(L, index, "heat_point", 0.);
+       b->humidity_point  = getfloatfield_default(L, index, "humidity_point", 0.);
+
+       b->flags    = 0; //reserved
+       b->c_top    = CONTENT_IGNORE;
+       b->c_filler = CONTENT_IGNORE;
        bmgr->addBiome(b);
 
        verbosestream << "register_biome: " << b->name << std::endl;
@@ -685,6 +653,53 @@ static int l_register_biome(lua_State *L)
 }
 
 
+static int l_register_ore(lua_State *L)
+{
+       int index = 1;
+       luaL_checktype(L, index, LUA_TTABLE);
+       
+       EmergeManager *emerge = get_server(L)->getEmergeManager();
+       
+       enum OreType oretype = (OreType)getenumfield(L, index,
+                               "ore_type", es_OreType, ORE_SCATTER);   
+       Ore *ore = createOre(oretype);
+       if (!ore) {
+               errorstream << "register_ore: ore_type "
+                       << oretype << " not implemented";
+               return 0;
+       }
+       
+       ore->ore_name       = getstringfield_default(L, index, "ore", "");
+       ore->ore_param2     = (u8)getintfield_default(L, index, "ore_param2", 0);
+       ore->wherein_name   = getstringfield_default(L, index, "wherein", "");
+       ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 1);
+       ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 1);
+       ore->clust_size     = getintfield_default(L, index, "clust_size", 0);
+       ore->height_min     = getintfield_default(L, index, "height_min", 0);
+       ore->height_max     = getintfield_default(L, index, "height_max", 0);
+       ore->flags          = getflagsfield(L, index, "flags", flagdesc_ore);
+       ore->nthresh        = getfloatfield_default(L, index, "noise_threshhold", 0.);
+
+       lua_getfield(L, index, "noise_params");
+       ore->np = read_noiseparams(L, -1);
+       lua_pop(L, 1);
+       
+       ore->noise = NULL;
+       
+       if (ore->clust_scarcity <= 0 || ore->clust_num_ores <= 0) {
+               errorstream << "register_ore: clust_scarcity and clust_num_ores"
+                       " must be greater than 0" << std::endl;
+               delete ore;
+               return 0;
+       }
+       
+       emerge->ores.push_back(ore);
+       
+       verbosestream << "register_ore: ore '" << ore->ore_name
+               << "' registered" << std::endl;
+       return 0;
+}
+
 
 // setting_set(name, value)
 static int l_setting_set(lua_State *L)
@@ -739,15 +754,18 @@ static int l_chat_send_all(lua_State *L)
        return 0;
 }
 
-// chat_send_player(name, text)
+// chat_send_player(name, text, prepend)
 static int l_chat_send_player(lua_State *L)
 {
        const char *name = luaL_checkstring(L, 1);
        const char *text = luaL_checkstring(L, 2);
+       bool prepend = true;
+       if (lua_isboolean(L, 3))
+               prepend = lua_toboolean(L, 3);
        // Get server from registry
        Server *server = get_server(L);
        // Send
-       server->notifyPlayer(name, narrow_to_wide(text));
+       server->notifyPlayer(name, narrow_to_wide(text), prepend);
        return 0;
 }
 
@@ -770,6 +788,31 @@ static int l_get_player_privs(lua_State *L)
        return 1;
 }
 
+// get_player_ip()
+static int l_get_player_ip(lua_State *L)
+{
+       const char * name = luaL_checkstring(L, 1);
+       Player *player = get_env(L)->getPlayer(name);
+       if(player == NULL)
+       {
+               lua_pushnil(L); // no such player
+               return 1;
+       }
+       try
+       {
+               Address addr = get_server(L)->getPeerAddress(get_env(L)->getPlayer(name)->peer_id);
+               std::string ip_str = addr.serializeString();
+               lua_pushstring(L, ip_str.c_str());
+               return 1;
+       }
+       catch(con::PeerNotFoundException) // unlikely
+       {
+               dstream << __FUNCTION_NAME << ": peer was not found" << std::endl;
+               lua_pushnil(L); // error
+               return 1;
+       }
+}
+
 // get_ban_list()
 static int l_get_ban_list(lua_State *L)
 {
@@ -906,7 +949,7 @@ static int l_get_modnames(lua_State *L)
        {
                bool added = false;
                for(std::list<std::string>::iterator x = mods_sorted.begin();
-                   x != mods_unsorted.end(); ++x)
+                   x != mods_sorted.end(); ++x)
                {
                        // I doubt anybody using Minetest will be using
                        // anything not ASCII based :)
@@ -1058,7 +1101,7 @@ static const struct luaL_Reg minetest_f [] = {
        {"register_alias_raw", l_register_alias_raw},
        {"register_craft", l_register_craft},
        {"register_biome", l_register_biome},
-       {"register_biome_groups", l_register_biome_groups},
+       {"register_ore", l_register_ore},
        {"setting_set", l_setting_set},
        {"setting_get", l_setting_get},
        {"setting_getbool", l_setting_getbool},
@@ -1066,6 +1109,7 @@ static const struct luaL_Reg minetest_f [] = {
        {"chat_send_all", l_chat_send_all},
        {"chat_send_player", l_chat_send_player},
        {"get_player_privs", l_get_player_privs},
+       {"get_player_ip", l_get_player_ip},
        {"get_ban_list", l_get_ban_list},
        {"get_ban_description", l_get_ban_description},
        {"ban_player", l_ban_player},
@@ -1089,6 +1133,9 @@ static const struct luaL_Reg minetest_f [] = {
        {"get_all_craft_recipes", l_get_all_craft_recipes},
        {"rollback_get_last_node_actor", l_rollback_get_last_node_actor},
        {"rollback_revert_actions_by", l_rollback_revert_actions_by},
+       {"add_particle", l_add_particle},
+       {"add_particlespawner", l_add_particlespawner},
+       {"delete_particlespawner", l_delete_particlespawner},
        {NULL, NULL}
 };