]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/environment.h
Enforce PLAYER_INVENTORY_SIZE in ObjectRef::l_inventory_set_list
[dragonfireclient.git] / src / environment.h
index a8213ea6de8fadf02b32260efcb47d6fa3b74b40..fea201bb7e64ea3b9192d8fccdab804e61ca80c5 100644 (file)
@@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
        - etc.
 */
 
-#include <list>
+#include <set>
 #include "common_irrlicht.h"
 #include "player.h"
 #include "map.h"
@@ -95,6 +95,39 @@ class Environment
        u32 m_time_of_day;
 };
 
+/*
+       Active block modifier interface.
+
+       These are fed into ServerEnvironment at initialization time;
+       ServerEnvironment handles deleting them.
+*/
+
+class ActiveBlockModifier
+{
+public:
+       ActiveBlockModifier(){};
+       virtual ~ActiveBlockModifier(){};
+       
+       virtual std::set<std::string> getTriggerContents()=0;
+       virtual float getTriggerInterval() = 0;
+       // chance of (1 / return value), 0 is disallowed
+       virtual u32 getTriggerChance() = 0;
+       // This is called usually at interval for 1/chance of the nodes
+       virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n){};
+       virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
+                       u32 active_object_count, u32 active_object_count_wider){};
+};
+
+struct ABMWithState
+{
+       ActiveBlockModifier *abm;
+       float timer;
+
+       ABMWithState(ActiveBlockModifier *abm_):
+               abm(abm_)
+       {}
+};
+
 /*
        List of active blocks, used by ServerEnvironment
 */
@@ -120,6 +153,12 @@ class ActiveBlockList
 private:
 };
 
+class IBackgroundBlockEmerger
+{
+public:
+       virtual void queueBlockEmerge(v3s16 blockpos, bool allow_generate)=0;
+};
+
 /*
        The server-side environment.
 
@@ -129,7 +168,8 @@ class ActiveBlockList
 class ServerEnvironment : public Environment
 {
 public:
-       ServerEnvironment(ServerMap *map, lua_State *L, IGameDef *gamedef);
+       ServerEnvironment(ServerMap *map, lua_State *L, IGameDef *gamedef,
+                       IBackgroundBlockEmerger *emerger);
        ~ServerEnvironment();
 
        Map & getMap()
@@ -279,6 +319,8 @@ class ServerEnvironment : public Environment
        lua_State *m_lua;
        // Game definition
        IGameDef *m_gamedef;
+       // Background block emerger (the server, in practice)
+       IBackgroundBlockEmerger *m_emerger;
        // Active object list
        core::map<u16, ServerActiveObject*> m_active_objects;
        // Outgoing network message buffer for active objects
@@ -290,38 +332,14 @@ class ServerEnvironment : public Environment
        // List of active blocks
        ActiveBlockList m_active_blocks;
        IntervalLimiter m_active_blocks_management_interval;
-       IntervalLimiter m_active_blocks_test_interval;
+       IntervalLimiter m_active_block_modifier_interval;
        IntervalLimiter m_active_blocks_nodemetadata_interval;
        // Time from the beginning of the game in seconds.
        // Incremented in step().
        u32 m_game_time;
        // A helper variable for incrementing the latter
        float m_game_time_fraction_counter;
-};
-
-/*
-       Active block modifier interface.
-
-       These are fed into ServerEnvironment at initialization time;
-       ServerEnvironment handles deleting them.
-
-       NOTE: Not used currently (TODO: Use or remove)
-*/
-
-class ActiveBlockModifier
-{
-public:
-       ActiveBlockModifier(){};
-       virtual ~ActiveBlockModifier(){};
-
-       //virtual core::list<u8> update(ServerEnvironment *env) = 0;
-       virtual u32 getTriggerContentCount(){ return 1;}
-       virtual u8 getTriggerContent(u32 i) = 0;
-       virtual float getActiveInterval() = 0;
-       // chance of (1 / return value), 0 is disallowed
-       virtual u32 getActiveChance() = 0;
-       // This is called usually at interval for 1/chance of the nodes
-       virtual void triggerEvent(ServerEnvironment *env, v3s16 p) = 0;
+       core::list<ABMWithState> m_abms;
 };
 
 #ifndef SERVER
@@ -358,18 +376,18 @@ class ClientEnvironment : public Environment
 {
 public:
        ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
-                       ITextureSource *texturesource, IGameDef *gamedef);
+                       ITextureSource *texturesource, IGameDef *gamedef,
+                       IrrlichtDevice *device);
        ~ClientEnvironment();
 
        Map & getMap()
-       {
-               return *m_map;
-       }
+       { return *m_map; }
 
        ClientMap & getClientMap()
-       {
-               return *m_map;
-       }
+       { return *m_map; }
+
+       IGameDef *getGameDef()
+       { return m_gamedef; }
 
        void step(f32 dtime);
 
@@ -437,6 +455,7 @@ class ClientEnvironment : public Environment
        scene::ISceneManager *m_smgr;
        ITextureSource *m_texturesource;
        IGameDef *m_gamedef;
+       IrrlichtDevice *m_irr;
        core::map<u16, ClientActiveObject*> m_active_objects;
        Queue<ClientEnvEvent> m_client_event_queue;
        IntervalLimiter m_active_object_light_update_interval;