]> git.lizzy.rs Git - minetest.git/blobdiff - src/environment.h
Fix addon and configuration file paths
[minetest.git] / src / environment.h
index 48e9cfa75729a679c46141cc0d393406a33b25e4..fcd16e2967bebd271303940541af8894a08f991f 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"
@@ -39,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "activeobject.h"
 
 class Server;
+class ServerEnvironment;
 class ActiveBlockModifier;
 class ServerActiveObject;
 typedef struct lua_State lua_State;
@@ -95,6 +96,43 @@ 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(){};
+       
+       // Set of contents to trigger on
+       virtual std::set<std::string> getTriggerContents()=0;
+       // Set of required neighbors (trigger doesn't happen if none are found)
+       // Empty = do not check neighbors
+       virtual std::set<std::string> getRequiredNeighbors()
+       { return std::set<std::string>(); }
+       // Trigger interval in seconds
+       virtual float getTriggerInterval() = 0;
+       // Random 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_);
+};
+
 /*
        List of active blocks, used by ServerEnvironment
 */
@@ -222,18 +260,24 @@ class ServerEnvironment : public Environment
        void activateBlock(MapBlock *block, u32 additional_dtime=0);
 
        /*
-               ActiveBlockModifiers (TODO)
+               ActiveBlockModifiers
                -------------------------------------------
-               NOTE: Not used currently (TODO: Use or remove)
        */
 
        void addActiveBlockModifier(ActiveBlockModifier *abm);
 
-       /* Other stuff */
+       /*
+               Other stuff
+               -------------------------------------------
+       */
+       
+       // Find all active objects inside a radius around a point
+       std::set<u16> getObjectsInsideRadius(v3f pos, float radius);
        
        // Clear all objects, loading and going through every MapBlock
        void clearAllObjects();
        
+       // This makes stuff happen
        void step(f32 dtime);
        
 private:
@@ -299,43 +343,20 @@ 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
 
 #include "clientobject.h"
+class ClientSimpleObject;
 
 /*
        The client-side environment.
@@ -359,6 +380,7 @@ struct ClientEnvEvent
                } none;
                struct{
                        u8 amount;
+                       bool send_to_server;
                } player_damage;
        };
 };
@@ -367,7 +389,8 @@ class ClientEnvironment : public Environment
 {
 public:
        ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
-                       ITextureSource *texturesource, IGameDef *gamedef);
+                       ITextureSource *texturesource, IGameDef *gamedef,
+                       IrrlichtDevice *device);
        ~ClientEnvironment();
 
        Map & getMap()
@@ -402,6 +425,12 @@ class ClientEnvironment : public Environment
                }
        }
 
+       /*
+               ClientSimpleObjects
+       */
+
+       void addSimpleObject(ClientSimpleObject *simple);
+
        /*
                ActiveObjects
        */
@@ -427,7 +456,7 @@ class ClientEnvironment : public Environment
                Callbacks for activeobjects
        */
 
-       void damageLocalPlayer(u8 damage);
+       void damageLocalPlayer(u8 damage, bool handle_hp=true);
 
        /*
                Client likes to call these
@@ -445,7 +474,9 @@ class ClientEnvironment : public Environment
        scene::ISceneManager *m_smgr;
        ITextureSource *m_texturesource;
        IGameDef *m_gamedef;
+       IrrlichtDevice *m_irr;
        core::map<u16, ClientActiveObject*> m_active_objects;
+       core::list<ClientSimpleObject*> m_simple_objects;
        Queue<ClientEnvEvent> m_client_event_queue;
        IntervalLimiter m_active_object_light_update_interval;
        IntervalLimiter m_lava_hurt_interval;