Add peaceful / not peaceful distinction in mobs and the only_peaceful_mobs setting
authorPerttu Ahola <celeron55@gmail.com>
Sun, 16 Oct 2011 08:52:33 +0000 (11:52 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 16 Oct 2011 08:52:33 +0000 (11:52 +0300)
minetest.conf.example
src/content_sao.cpp
src/content_sao.h
src/defaultsettings.cpp
src/environment.cpp
src/serverobject.h

index 440a26903c81dc500cf29d7a3c44a602ee5f3592..c8cfbe85cb930de050721c9113469df0815b9453 100644 (file)
@@ -122,6 +122,8 @@ screenH# = 600
 #creative_mode = false
 # Enable players getting damage and dying
 #enable_damage = false
+# Despawn all non-peaceful mobs
+#only_peaceful_mobs = false
 # A chosen map seed for a new map, leave empty for random
 #fixed_map_seed =
 # Gives some stuff to players at the beginning
index 8b1002c5a3d91f8ca4464e08963cada5d2268966..e218fc765e89623a5636519dd8162e6bee68913a 100644 (file)
@@ -1370,6 +1370,11 @@ u16 MobV2SAO::punch(const std::string &toolname, v3f dir,
        return 65536/100;
 }
 
+bool MobV2SAO::isPeaceful()
+{
+       return m_properties->getBool("is_peaceful");
+}
+
 void MobV2SAO::sendPosition()
 {
        m_last_sent_position = m_base_position;
@@ -1388,6 +1393,7 @@ void MobV2SAO::sendPosition()
 
 void MobV2SAO::setPropertyDefaults()
 {
+       m_properties->setDefault("is_peaceful", "false");
        m_properties->setDefault("move_type", "ground_nodes");
        m_properties->setDefault("speed", "(0,0,0)");
        m_properties->setDefault("age", "0");
index 42e8cab7d6e816fa745c618f12a476be4f330eb8..a335c12b8b638f58311165cfe0fc96e588a63880 100644 (file)
@@ -97,6 +97,7 @@ public:
        std::string getStaticData();
        InventoryItem* createPickedUpItem(){return NULL;}
        u16 punch(const std::string &toolname, v3f dir);
+       bool isPeaceful(){return false;}
 private:
        void doDamage(u16 d);
 
@@ -157,6 +158,7 @@ public:
        InventoryItem* createPickedUpItem(){return NULL;}
        u16 punch(const std::string &toolname, v3f dir,
                        const std::string &playername);
+       bool isPeaceful();
 private:
        void sendPosition();
        void setPropertyDefaults();
index be787dd6bbc77da0cb3d0a444a058ec6d5455578..a3a833327d86517d7814526fefba16a4000e6b09 100644 (file)
@@ -83,6 +83,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("strict_protocol_version_checking", "true");
        settings->setDefault("creative_mode", "false");
        settings->setDefault("enable_damage", "true");
+       settings->setDefault("only_peaceful_mobs", "false");
        settings->setDefault("fixed_map_seed", "");
        settings->setDefault("give_initial_stuff", "false");
        settings->setDefault("default_password", "");
index a88d600bb8bb0875a812390093dd7ca5d1a96a0d..f6b9b0a22c8fa36aa7a541d2c405fc4993b61a3a 100644 (file)
@@ -1039,6 +1039,11 @@ void ServerEnvironment::step(float dtime)
                                i.atEnd()==false; i++)
                {
                        ServerActiveObject* obj = i.getNode()->getValue();
+                       // Remove non-peaceful mobs on peaceful mode
+                       if(g_settings->getBool("only_peaceful_mobs")){
+                               if(!obj->isPeaceful())
+                                       obj->m_removed = true;
+                       }
                        // Don't step if is to be removed or stored statically
                        if(obj->m_removed || obj->m_pending_deactivation)
                                continue;
index a9bd0a7c4afc38b3d375f1b5cb56063222dda4ea..cbb50949cf8a4ff0064098fd03cbed5d98d47245 100644 (file)
@@ -111,6 +111,8 @@ public:
        /*
        */
        virtual void rightClick(Player *player){}
+
+       virtual bool isPeaceful(){return true;}
        
        /*
                Number of players which know about this object. Object won't be