Merge remote branch 'upstream/master' into sapier_experimental
authorsapier <sapier at gmx dot net>
Sat, 4 Feb 2012 11:41:25 +0000 (12:41 +0100)
committersapier <sapier at gmx dot net>
Sat, 4 Feb 2012 11:41:25 +0000 (12:41 +0100)
Conflicts:
src/scriptapi.cpp

1  2 
src/CMakeLists.txt
src/content_cao.cpp
src/content_sao.cpp
src/environment.cpp
src/environment.h
src/mesh.cpp
src/mesh.h
src/scriptapi.cpp
src/serverobject.cpp
src/serverobject.h

index baf9fed5a5345c27c9e52fd611fc22b876c89ee7,ee02d66f0acefdd658c4e3948020c07e80e99bae..a736991b4ef65d1eda83f14c27006e571d8acf32
@@@ -115,9 -114,7 +114,8 @@@ set(common_SRC
        collision.cpp
        nodemetadata.cpp
        serverobject.cpp
 +      serverlinkableobject.cpp
        noise.cpp
-       mineral.cpp
        porting.cpp
        materials.cpp
        defaultsettings.cpp
Simple merge
index b8189b258d80897f6f520ecc54b38cc9c6eb3f47,02be64c64fd20b85fa1a5c5e2d724974abcd602f..4a2bef8724410e000ce20f461360680322241c2b
@@@ -24,9 -24,11 +24,9 @@@ with this program; if not, write to th
  #include "main.h" // For g_profiler
  #include "profiler.h"
  #include "serialization.h" // For compressZlib
- #include "materials.h" // For MaterialProperties
- #include "tooldef.h" // ToolDiggingProperties
+ #include "materials.h" // For MaterialProperties and ToolDiggingProperties
+ #include "gamedef.h"
  
 -core::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
 -
  /* Some helper functions */
  
  // Y is copied, X and Z change is limited
Simple merge
Simple merge
diff --cc src/mesh.cpp
Simple merge
diff --cc src/mesh.h
Simple merge
index 39a3b06ff73597c24198ddfa20fa8f0bf954ecc9,a064cd688a0b318cdac5c92fb5263c3389a333d6..23063a3c8366107d33d8a59ec046f8a1c7c538a0
@@@ -2602,35 -2913,38 +2972,67 @@@ private
                return 1;
        }
  
 +      // EnvRef:get_objects_inside_radius(pos, radius)
 +      static int l_get_nodes_inside_radius(lua_State *L)
 +      {
 +              // Get the table insert function
 +              lua_getglobal(L, "table");
 +              lua_getfield(L, -1, "insert");
 +              int table_insert = lua_gettop(L);
 +              // Get environemnt
 +              EnvRef *o = checkobject(L, 1);
 +              ServerEnvironment *env = o->m_env;
 +              if(env == NULL) return 0;
 +              // Do it
 +              v3s16 pos = read_v3s16(L, 2);
 +              float radius = luaL_checknumber(L, 3);// * BS;
 +              core::list<MapNode> nodes = env->getNodesInsideRadius(pos, radius);
 +              lua_newtable(L);
 +              int table = lua_gettop(L);
 +              for(core::list<MapNode>::Iterator
 +                              i = nodes.begin(); i != nodes.end(); i++){
 +                      // Insert object reference into table
 +                      lua_pushvalue(L, table_insert);
 +                      lua_pushvalue(L, table);
 +                      pushnode(L, *i, env->getGameDef()->ndef());
 +                      if(lua_pcall(L, 2, 0, 0))
 +                              script_error(L, "error: %s", lua_tostring(L, -1));
 +              }
 +              return 1;
 +      }
 +
+       // EnvRef:set_timeofday(val)
+       // val = 0...1
+       static int l_set_timeofday(lua_State *L)
+       {
+               EnvRef *o = checkobject(L, 1);
+               ServerEnvironment *env = o->m_env;
+               if(env == NULL) return 0;
+               // Do it
+               float timeofday_f = luaL_checknumber(L, 2);
+               assert(timeofday_f >= 0.0 && timeofday_f <= 1.0);
+               int timeofday_mh = (int)(timeofday_f * 24000.0);
+               // This should be set directly in the environment but currently
+               // such changes aren't immediately sent to the clients, so call
+               // the server instead.
+               //env->setTimeOfDay(timeofday_mh);
+               get_server(L)->setTimeOfDay(timeofday_mh);
+               return 0;
+       }
+       // EnvRef:get_timeofday() -> 0...1
+       static int l_get_timeofday(lua_State *L)
+       {
+               EnvRef *o = checkobject(L, 1);
+               ServerEnvironment *env = o->m_env;
+               if(env == NULL) return 0;
+               // Do it
+               int timeofday_mh = env->getTimeOfDay();
+               float timeofday_f = (float)timeofday_mh / 24000.0;
+               lua_pushnumber(L, timeofday_f);
+               return 1;
+       }
        static int gc_object(lua_State *L) {
                EnvRef *o = *(EnvRef **)(lua_touserdata(L, 1));
                delete o;
@@@ -2708,7 -3022,8 +3110,9 @@@ const luaL_reg EnvRef::methods[] = 
        method(EnvRef, get_meta),
        method(EnvRef, get_player_by_name),
        method(EnvRef, get_objects_inside_radius),
 +      method(EnvRef, get_nodes_inside_radius),
+       method(EnvRef, set_timeofday),
+       method(EnvRef, get_timeofday),
        {0,0}
  };
  
index b5fd6fc3a249d2f1fe358dcd718aa547625e7a11,2609e301534a82abb2fd61112eb56c549e22d5fb..76a70ca5b3144c08541b49d5868627655871f9c8
@@@ -58,19 -58,40 +58,40 @@@ ServerActiveObject* ServerActiveObject:
        return object;
  }
  
 -void ServerActiveObject::registerType(u16 type, Factory f)
 +void ServerActiveObject::registerType(u8 type, Factory f)
  {
 -      core::map<u16, Factory>::Node *n;
 -      n = m_types.find(type);
 +      core::map<u8, Factory>::Node *n;
 +      n = ServerActiveObject::getTypes().find(type);
        if(n)
                return;
 -      m_types.insert(type, f);
 +      ServerActiveObject::getTypes().insert(type, f);
  }
  
- void ServerActiveObject::getWieldDiggingProperties(ToolDiggingProperties *dst)
+ ItemStack ServerActiveObject::getWieldedItem() const
  {
-       *dst = ToolDiggingProperties();
+       const Inventory *inv = getInventory();
+       if(inv)
+       {
+               const InventoryList *list = inv->getList(getWieldList());
+               if(list)
+                       return list->getItem(getWieldIndex());
+       }
+       return ItemStack();
  }
  
+ bool ServerActiveObject::setWieldedItem(const ItemStack &item)
+ {
+       Inventory *inv = getInventory();
+       if(inv)
+       {
+               InventoryList *list = inv->getList(getWieldList());
+               if (list)
+               {
+                       list->changeItem(getWieldIndex(), item);
+                       setInventoryModified();
+                       return true;
+               }
+       }
+       return false;
+ }
  
Simple merge