1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Move Modificator to separate file.

This commit is contained in:
Tomasz Zieliński 2023-05-06 10:49:18 +02:00
parent eb50ae3aa7
commit d22ec0ee0c
4 changed files with 4 additions and 154 deletions

View File

@ -121,6 +121,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
${MAIN_LIB_DIR}/rmg/TileInfo.cpp
${MAIN_LIB_DIR}/rmg/Zone.cpp
${MAIN_LIB_DIR}/rmg/Functions.cpp
${MAIN_LIB_DIR}/rmg/Modificator.cpp
${MAIN_LIB_DIR}/rmg/ObjectManager.cpp
${MAIN_LIB_DIR}/rmg/ObjectDistributor.cpp
${MAIN_LIB_DIR}/rmg/RoadPlacer.cpp
@ -406,6 +407,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
${MAIN_LIB_DIR}/rmg/TileInfo.h
${MAIN_LIB_DIR}/rmg/Zone.h
${MAIN_LIB_DIR}/rmg/Functions.h
${MAIN_LIB_DIR}/rmg/Modificator.h
${MAIN_LIB_DIR}/rmg/ObjectManager.h
${MAIN_LIB_DIR}/rmg/ObjectDistributor.h
${MAIN_LIB_DIR}/rmg/RoadPlacer.h

View File

@ -403,7 +403,6 @@ void CMapGenerator::banHero(const HeroTypeID & id)
map->map().allowedHeroes[id] = false;
}
Zone * CMapGenerator::getZoneWater() const
{
for(auto & z : map->getZones())

View File

@ -13,8 +13,6 @@
#include "RmgMap.h"
#include "Functions.h"
#include "TileInfo.h"
#include "../mapping/CMap.h"
#include "../CStopWatch.h"
#include "CMapGenerator.h"
#include "RmgPath.h"
@ -303,109 +301,4 @@ void Zone::processModificators()
logGlobal->info("Zone %d filled successfully", getId());
}
Modificator::Modificator(Zone & zone, RmgMap & map, CMapGenerator & generator) : zone(zone), map(map), generator(generator)
{
}
void Modificator::setName(const std::string & n)
{
name = n;
}
const std::string & Modificator::getName() const
{
return name;
}
bool Modificator::isFinished() const
{
return finished;
}
void Modificator::run()
{
started = true;
if(!finished)
{
for(auto * modificator : preceeders)
{
if(!modificator->started)
modificator->run();
}
logGlobal->info("Modificator zone %d - %s - started", zone.getId(), getName());
CStopWatch processTime;
try
{
process();
}
catch(rmgException &e)
{
logGlobal->error("Modificator %s, exception: %s", getName(), e.what());
}
#ifdef RMG_DUMP
dump();
#endif
finished = true;
logGlobal->info("Modificator zone %d - %s - done (%d ms)", zone.getId(), getName(), processTime.getDiff());
}
}
void Modificator::dependency(Modificator * modificator)
{
if(modificator && modificator != this)
{
if(std::find(preceeders.begin(), preceeders.end(), modificator) == preceeders.end())
preceeders.push_back(modificator);
}
}
void Modificator::postfunction(Modificator * modificator)
{
if(modificator && modificator != this)
{
if(std::find(modificator->preceeders.begin(), modificator->preceeders.end(), this) == modificator->preceeders.end())
modificator->preceeders.push_back(this);
}
}
void Modificator::dump()
{
std::ofstream out(boost::to_string(boost::format("seed_%d_modzone_%d_%s.txt") % generator.getRandomSeed() % zone.getId() % getName()));
auto & mapInstance = map.map();
int levels = mapInstance.levels();
int width = mapInstance.width;
int height = mapInstance.height;
for(int z = 0; z < levels; z++)
{
for(int j=0; j<height; j++)
{
for(int i=0; i<width; i++)
{
out << dump(int3(i, j, z));
}
out << std::endl;
}
out << std::endl;
}
out << std::endl;
}
char Modificator::dump(const int3 & t)
{
if(zone.freePaths().contains(t))
return '.'; //free path
if(zone.areaPossible().contains(t))
return ' '; //possible
if(zone.areaUsed().contains(t))
return 'U'; //used
if(zone.area().contains(t))
{
if(map.shouldBeBlocked(t))
return '#'; //obstacle
else
return '^'; //visitable points?
}
return '?';
}
VCMI_LIB_NAMESPACE_END

View File

@ -17,60 +17,16 @@
#include "RmgArea.h"
#include "RmgPath.h"
#include "RmgObject.h"
#include "Modificator.h"
//uncomment to generate dumps afger every step of map generation
//#define RMG_DUMP
#define MODIFICATOR(x) x(Zone & z, RmgMap & m, CMapGenerator & g): Modificator(z, m, g) {setName(#x);}
#define DEPENDENCY(x) dependency(zone.getModificator<x>());
#define POSTFUNCTION(x) postfunction(zone.getModificator<x>());
#define DEPENDENCY_ALL(x) for(auto & z : map.getZones()) \
{ \
dependency(z.second->getModificator<x>()); \
}
#define POSTFUNCTION_ALL(x) for(auto & z : map.getZones()) \
{ \
postfunction(z.second->getModificator<x>()); \
}
VCMI_LIB_NAMESPACE_BEGIN
class RmgMap;
class CMapGenerator;
class Zone;
class Modificator
{
public:
Modificator() = delete;
Modificator(Zone & zone, RmgMap & map, CMapGenerator & generator);
virtual void process() = 0;
virtual void init() {/*override to add dependencies*/}
virtual char dump(const int3 &);
virtual ~Modificator() = default;
void setName(const std::string & n);
const std::string & getName() const;
void run();
void dependency(Modificator * modificator);
void postfunction(Modificator * modificator);
protected:
RmgMap & map;
CMapGenerator & generator;
Zone & zone;
bool isFinished() const;
private:
std::string name;
bool started = false;
bool finished = false;
std::list<Modificator*> preceeders; //must be ordered container
void dump();
};
class Modificator;
extern std::function<bool(const int3 &)> AREA_NO_FILTER;