From 8d36224bdd3e0d283df923ccb6f3722bf4434e47 Mon Sep 17 00:00:00 2001 From: darkrose Date: Wed, 22 Jan 2014 22:00:47 +1000 Subject: [PATCH] replace only_peace_mobs with max_mob_level --- minetest.conf.example | 5 ++-- src/content_sao.cpp | 6 ++--- src/content_sao.h | 4 +-- src/defaultsettings.cpp | 2 +- src/environment.cpp | 54 ++++++++++++++++++----------------------- src/serverobject.h | 24 +++++++++++++++++- 6 files changed, 56 insertions(+), 39 deletions(-) diff --git a/minetest.conf.example b/minetest.conf.example index 0940991..9164d07 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -133,8 +133,9 @@ #creative_mode = false # Enable players getting damage and dying #enable_damage = false -# Despawn all non-peaceful mobs -#only_peaceful_mobs = false +# The maximum 'level' of mobs to spawn: passive, aggressive, destructive +# roughly: passive = rats, aggressive = oerkki, destructive = DM +#max_mob_level = aggressive # A chosen map seed for a new map, leave empty for random #fixed_map_seed = # Gives some stuff to players at the beginning diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 56ba1a3..442ab56 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -1426,9 +1426,9 @@ u16 MobV2SAO::punch(const std::string &toolname, v3f dir, return 65536/100; } -bool MobV2SAO::isPeaceful() +u8 MobV2SAO::level() { - return m_properties->getBool("is_peaceful"); + return mobLevelI(m_properties->get("level")); } void MobV2SAO::sendPosition() @@ -1497,7 +1497,7 @@ void MobV2SAO::doDamage(u16 d) } else { - actionstream<<"A "<<(isPeaceful()?"peaceful":"non-peaceful") + actionstream<<"A "<get("level") <<" mob id="<setDefault("strict_protocol_version_checking", "false"); settings->setDefault("creative_mode", "false"); settings->setDefault("enable_damage", "true"); - settings->setDefault("only_peaceful_mobs", "false"); + settings->setDefault("max_mob_level", "aggressive"); settings->setDefault("fixed_map_seed", ""); settings->setDefault("give_initial_stuff", "false"); settings->setDefault("default_password", ""); diff --git a/src/environment.cpp b/src/environment.cpp index ca397f2..8bcb5a3 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -755,6 +755,7 @@ static void getMob_dungeon_master(Settings &properties) properties.set("player_hit_damage", "1"); properties.set("player_hit_distance", "1.0"); properties.set("player_hit_interval", "0.5"); + properties.set("level","destructive"); properties.setBool("mindless_rage", myrand_range(0,100)==0); } @@ -1790,40 +1791,35 @@ void ServerEnvironment::step(float dtime) ServerActiveObject *obj; Settings properties; int i = myrand()%5; - if (g_settings->getBool("only_peaceful_mobs")) { - if (i == 1) { - actionstream<<"Rat spawns at " - <get("max_mob_level")); + switch (i) { + case 0: + getMob_dungeon_master(properties); + if (mobLevelI(properties.get("level")) >= mob_level) { actionstream<<"A dungeon master spawns at " - < MOB_PASSIVE) { actionstream<<"An oerkki spawns at " - <getBool("only_peaceful_mobs"); + u8 mob_level = mobLevelI(g_settings->get("max_mob_level")); m_send_recommended_timer += dtime; if(m_send_recommended_timer > 0.10) { @@ -2436,10 +2432,8 @@ void ServerEnvironment::step(float dtime) { ServerActiveObject* obj = i.getNode()->getValue(); // Remove non-peaceful mobs on peaceful mode - if(peaceful_mobs){ - if(!obj->isPeaceful()) - obj->m_removed = true; - } + if(obj->level() > mob_level) + obj->m_removed = true; // Don't step if is to be removed or stored statically if(obj->m_removed || obj->m_pending_deactivation) continue; diff --git a/src/serverobject.h b/src/serverobject.h index 0db5f42..6269337 100644 --- a/src/serverobject.h +++ b/src/serverobject.h @@ -24,6 +24,28 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "activeobject.h" #include "utility.h" +#define MOB_PASSIVE 0 +#define MOB_AGGRESSIVE 1 +#define MOB_DESTRUCTIVE 2 + +inline u8 mobLevelI(std::string level) +{ + if (level == "destructive") + return MOB_DESTRUCTIVE; + if (level == "aggressive") + return MOB_AGGRESSIVE; + return MOB_PASSIVE; +} + +inline std::string mobLevelS(u8 level) +{ + if (level == MOB_DESTRUCTIVE) + return std::string("destructive"); + if (level == MOB_AGGRESSIVE) + return std::string("aggressive"); + return std::string("passive"); +} + /* Some planning @@ -112,7 +134,7 @@ public: */ virtual void rightClick(Player *player){} - virtual bool isPeaceful(){return true;} + virtual u8 level(){return MOB_PASSIVE;} /* Number of players which know about this object. Object won't be