/* Minetest Copyright (C) 2010-2017 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #pragma once #include "activeobject.h" #include "environment.h" #include "mapnode.h" #include "settings.h" #include "server/activeobjectmgr.h" #include "util/numeric.h" #include class IGameDef; class ServerMap; struct GameParams; class MapBlock; class RemotePlayer; class PlayerDatabase; class AuthDatabase; class PlayerSAO; class ServerEnvironment; class ActiveBlockModifier; struct StaticObject; class ServerActiveObject; class Server; class ServerScripting; /* {Active, Loading} block modifier interface. These are fed into ServerEnvironment at initialization time; ServerEnvironment handles deleting them. */ class ActiveBlockModifier { public: ActiveBlockModifier() = default; virtual ~ActiveBlockModifier() = default; // Set of contents to trigger on virtual const std::vector &getTriggerContents() const = 0; // Set of required neighbors (trigger doesn't happen if none are found) // Empty = do not check neighbors virtual const std::vector &getRequiredNeighbors() const = 0; // Trigger interval in seconds virtual float getTriggerInterval() = 0; // Random chance of (1 / return value), 0 is disallowed virtual u32 getTriggerChance() = 0; // Whether to modify chance to simulate time lost by an unnattended block virtual bool getSimpleCatchUp() = 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 = 0.0f; ABMWithState(ActiveBlockModifier *abm_); }; struct LoadingBlockModifierDef { // Set of contents to trigger on std::set trigger_contents; std::string name; bool run_at_every_load = false; virtual ~LoadingBlockModifierDef() = default; virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n){}; }; struct LBMContentMapping { typedef std::unordered_map> lbm_map; lbm_map map; std::vector lbm_list; // Needs to be separate method (not inside destructor), // because the LBMContentMapping may be copied and destructed // many times during operation in the lbm_lookup_map. void deleteContents(); void addLBM(LoadingBlockModifierDef *lbm_def, IGameDef *gamedef); const std::vector *lookup(content_t c) const; }; class LBMManager { public: LBMManager() = default; ~LBMManager(); // Don't call this after loadIntroductionTimes() ran. void addLBMDef(LoadingBlockModifierDef *lbm_def); void loadIntroductionTimes(const std::string ×, IGameDef *gamedef, u32 now); // Don't call this before loadIntroductionTimes() ran. std::string createIntroductionTimesString(); // Don't call this before loadIntroductionTimes() ran. void applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp); // Warning: do not make this std::unordered_map, order is relevant here typedef std::map lbm_lookup_map; private: // Once we set this to true, we can only query, // not modify bool m_query_mode = false; // For m_query_mode == false: // The key of the map is the LBM def's name. // TODO make this std::unordered_map std::map m_lbm_defs; // For m_query_mode == true: // The key of the map is the LBM def's first introduction time. lbm_lookup_map m_lbm_lookup; // Returns an iterator to the LBMs that were introduced // after the given time. This is guaranteed to return // valid values for everything lbm_lookup_map::const_iterator getLBMsIntroducedAfter(u32 time) { return m_lbm_lookup.lower_bound(time); } }; /* List of active blocks, used by ServerEnvironment */ class ActiveBlockList { public: void update(std::vector &active_players, s16 active_block_range, s16 active_object_range, std::set &blocks_removed, std::set &blocks_added); bool contains(v3s16 p){ return (m_list.find(p) != m_list.end()); } void clear(){ m_list.clear(); } std::set m_list; std::set m_abm_list; std::set m_forceloaded_list; private: }; /* Operation mode for ServerEnvironment::clearObjects() */ enum ClearObjectsMode { // Load and go through every mapblock, clearing objects CLEAR_OBJECTS_MODE_FULL, // Clear objects immediately in loaded mapblocks; // clear objects in unloaded mapblocks only when the mapblocks are next activated. CLEAR_OBJECTS_MODE_QUICK, }; /* The server-side environment. This is not thread-safe. Server uses an environment mutex. */ typedef std::unordered_map ServerActiveObjectMap; class ServerEnvironment : public Environment { public: ServerEnvironment(ServerMap *map, ServerScripting *scriptIface, Server *server, const std::string &path_world); ~ServerEnvironment(); Map & getMap(); ServerMap & getServerMap(); //TODO find way to remove this fct! ServerScripting* getScriptIface() { return m_script; } Server *getGameDef() { return m_server; } float getSendRecommendedInterval() { return m_recommended_send_interval; } void kickAllPlayers(AccessDeniedCode reason, const std::string &str_reason, bool reconnect); // Save players void saveLoadedPlayers(bool force = false); void savePlayer(RemotePlayer *player); PlayerSAO *loadPlayer(RemotePlayer *player, bool *new_player, session_t peer_id, bool is_singleplayer); void addPlayer(RemotePlayer *player); void removePlayer(RemotePlayer *player); bool removePlayerFromDatabase(const std::string &name); /* Save and load time of day and game timer */ void saveMeta(); void loadMeta(); u32 addParticleSpawner(float exptime); u32 addParticleSpawner(float exptime, u16 attached_id); void deleteParticleSpawner(u32 id, bool remove_from_object = true); /* External ActiveObject interface ------------------------------------------- */ ServerActiveObject* getActiveObject(u16 id) { return m_ao_manager.getActiveObject(id); } /* Add an active object to the environment. Environment handles deletion of object. Object may be deleted by environment immediately. If id o You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "mapgen_singlenode.h" #include "voxel.h" #include "mapblock.h" #include "mapnode.h" #include "map.h" #include "nodedef.h" #include "voxelalgorithms.h" #include "profiler.h" #include "emerge.h" MapgenSinglenode::MapgenSinglenode(int mapgenid, MapgenParams *params, EmergeManager *emerge) : Mapgen(mapgenid, params, emerge) { flags = params->flags; INodeDefManager *ndef = emerge->ndef; c_node = ndef->getId("mapgen_singlenode"); if (c_node == CONTENT_IGNORE) c_node = CONTENT_AIR; } MapgenSinglenode::~MapgenSinglenode() { } //////////////////////// Map generator void MapgenSinglenode::makeChunk(BlockMakeData *data) { // Pre-conditions assert(data->vmanip); assert(data->nodedef); assert(data->blockpos_requested.X >= data->blockpos_min.X && data->blockpos_requested.Y >= data->blockpos_min.Y && data->blockpos_requested.Z >= data->blockpos_min.Z); assert(data->blockpos_requested.X <= data->blockpos_max.X && data->blockpos_requested.Y <= data->blockpos_max.Y && data->blockpos_requested.Z <= data->blockpos_max.Z); this->generating = true; this->vm = data->vmanip; this->ndef = data->nodedef; v3s16 blockpos_min = data->blockpos_min; v3s16 blockpos_max = data->blockpos_max; // Area of central chunk v3s16 node_min = blockpos_min*MAP_BLOCKSIZE; v3s16 node_max = (blockpos_max+v3s16(1,1,1))*MAP_BLOCKSIZE-v3s16(1,1,1); blockseed = getBlockSeed2(node_min, data