mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Place Mines after Towns and Monoliths.
This commit is contained in:
@@ -107,6 +107,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
|
|||||||
${MAIN_LIB_DIR}/rmg/RmgMap.cpp
|
${MAIN_LIB_DIR}/rmg/RmgMap.cpp
|
||||||
${MAIN_LIB_DIR}/rmg/ConnectionsPlacer.cpp
|
${MAIN_LIB_DIR}/rmg/ConnectionsPlacer.cpp
|
||||||
${MAIN_LIB_DIR}/rmg/WaterAdopter.cpp
|
${MAIN_LIB_DIR}/rmg/WaterAdopter.cpp
|
||||||
|
${MAIN_LIB_DIR}/rmg/MinePlacer.cpp
|
||||||
${MAIN_LIB_DIR}/rmg/TownPlacer.cpp
|
${MAIN_LIB_DIR}/rmg/TownPlacer.cpp
|
||||||
${MAIN_LIB_DIR}/rmg/WaterProxy.cpp
|
${MAIN_LIB_DIR}/rmg/WaterProxy.cpp
|
||||||
${MAIN_LIB_DIR}/rmg/WaterRoutes.cpp
|
${MAIN_LIB_DIR}/rmg/WaterRoutes.cpp
|
||||||
@@ -345,6 +346,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
|
|||||||
${MAIN_LIB_DIR}/rmg/RmgMap.h
|
${MAIN_LIB_DIR}/rmg/RmgMap.h
|
||||||
${MAIN_LIB_DIR}/rmg/ConnectionsPlacer.h
|
${MAIN_LIB_DIR}/rmg/ConnectionsPlacer.h
|
||||||
${MAIN_LIB_DIR}/rmg/WaterAdopter.h
|
${MAIN_LIB_DIR}/rmg/WaterAdopter.h
|
||||||
|
${MAIN_LIB_DIR}/rmg/MinePlacer.h
|
||||||
${MAIN_LIB_DIR}/rmg/TownPlacer.h
|
${MAIN_LIB_DIR}/rmg/TownPlacer.h
|
||||||
${MAIN_LIB_DIR}/rmg/WaterProxy.h
|
${MAIN_LIB_DIR}/rmg/WaterProxy.h
|
||||||
${MAIN_LIB_DIR}/rmg/WaterRoutes.h
|
${MAIN_LIB_DIR}/rmg/WaterRoutes.h
|
||||||
|
97
lib/rmg/MinePlacer.cpp
Normal file
97
lib/rmg/MinePlacer.cpp
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* License: GNU General Public License v2.0 or later
|
||||||
|
* Full text of license available in license.txt file, in main folder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "StdInc.h"
|
||||||
|
#include "MinePlacer.h"
|
||||||
|
#include "TownPlacer.h"
|
||||||
|
#include "CMapGenerator.h"
|
||||||
|
#include "RmgMap.h"
|
||||||
|
#include "../mapping/CMap.h"
|
||||||
|
#include "../mapping/CMapEditManager.h"
|
||||||
|
#include "../mapObjects/CObjectClassesHandler.h"
|
||||||
|
#include "../spells/CSpellHandler.h" //for choosing random spells
|
||||||
|
#include "RmgPath.h"
|
||||||
|
#include "RmgObject.h"
|
||||||
|
#include "ObjectManager.h"
|
||||||
|
#include "Functions.h"
|
||||||
|
#include "RoadPlacer.h"
|
||||||
|
#include "WaterAdopter.h"
|
||||||
|
#include "TileInfo.h"
|
||||||
|
|
||||||
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
void MinePlacer::process()
|
||||||
|
{
|
||||||
|
auto * manager = zone.getModificator<ObjectManager>();
|
||||||
|
if(!manager)
|
||||||
|
{
|
||||||
|
logGlobal->error("ObjectManager doesn't exist for zone %d, skip modificator %s", zone.getId(), getName());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
placeMines(*manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MinePlacer::init()
|
||||||
|
{
|
||||||
|
DEPENDENCY(TownPlacer);
|
||||||
|
POSTFUNCTION(ObjectManager);
|
||||||
|
POSTFUNCTION(RoadPlacer);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MinePlacer::placeMines(ObjectManager & manager)
|
||||||
|
{
|
||||||
|
using namespace Res;
|
||||||
|
std::vector<CGMine*> createdMines;
|
||||||
|
|
||||||
|
std::vector<std::pair<CGObjectInstance*, ui32>> requiredObjects;
|
||||||
|
|
||||||
|
for(const auto & mineInfo : zone.getMinesInfo())
|
||||||
|
{
|
||||||
|
ERes res = static_cast<ERes>(mineInfo.first);
|
||||||
|
for(int i = 0; i < mineInfo.second; ++i)
|
||||||
|
{
|
||||||
|
auto mineHandler = VLC->objtypeh->getHandlerFor(Obj::MINE, res);
|
||||||
|
const auto & rmginfo = mineHandler->getRMGInfo();
|
||||||
|
auto * mine = dynamic_cast<CGMine *>(mineHandler->create());
|
||||||
|
mine->producedResource = res;
|
||||||
|
mine->tempOwner = PlayerColor::NEUTRAL;
|
||||||
|
mine->producedQuantity = mine->defaultResProduction();
|
||||||
|
createdMines.push_back(mine);
|
||||||
|
|
||||||
|
|
||||||
|
if(!i && (res == ERes::WOOD || res == ERes::ORE))
|
||||||
|
manager.addCloseObject(mine, rmginfo.value); //only first wood&ore mines are close
|
||||||
|
else
|
||||||
|
requiredObjects.push_back(std::pair<CGObjectInstance*, ui32>(mine, rmginfo.value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Shuffle mines to avoid patterns, but don't shuffle key objects like towns
|
||||||
|
RandomGeneratorUtil::randomShuffle(requiredObjects, generator.rand);
|
||||||
|
for (const auto& obj : requiredObjects)
|
||||||
|
{
|
||||||
|
manager.addRequiredObject(obj.first, obj.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
//create extra resources
|
||||||
|
if(int extraRes = generator.getConfig().mineExtraResources)
|
||||||
|
{
|
||||||
|
for(auto * mine : createdMines)
|
||||||
|
{
|
||||||
|
for(int rc = generator.rand.nextInt(1, extraRes); rc > 0; --rc)
|
||||||
|
{
|
||||||
|
auto * resourse = dynamic_cast<CGResource *>(VLC->objtypeh->getHandlerFor(Obj::RESOURCE, mine->producedResource)->create());
|
||||||
|
resourse->amount = CGResource::RANDOM_AMOUNT;
|
||||||
|
manager.addNearbyObject(resourse, mine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
VCMI_LIB_NAMESPACE_END
|
30
lib/rmg/MinePlacer.h
Normal file
30
lib/rmg/MinePlacer.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* MinePlacer.h, part of VCMI engine
|
||||||
|
*
|
||||||
|
* Authors: listed in file AUTHORS in main folder
|
||||||
|
*
|
||||||
|
* License: GNU General Public License v2.0 or later
|
||||||
|
* Full text of license available in license.txt file, in main folder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include "Zone.h"
|
||||||
|
|
||||||
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
class ObjectManager;
|
||||||
|
|
||||||
|
class MinePlacer: public Modificator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MODIFICATOR(MinePlacer);
|
||||||
|
|
||||||
|
void process() override;
|
||||||
|
void init() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool placeMines(ObjectManager & manager);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
VCMI_LIB_NAMESPACE_END
|
@@ -21,6 +21,7 @@
|
|||||||
#include "ObjectManager.h"
|
#include "ObjectManager.h"
|
||||||
#include "Functions.h"
|
#include "Functions.h"
|
||||||
#include "RoadPlacer.h"
|
#include "RoadPlacer.h"
|
||||||
|
#include "MinePlacer.h"
|
||||||
#include "WaterAdopter.h"
|
#include "WaterAdopter.h"
|
||||||
#include "TileInfo.h"
|
#include "TileInfo.h"
|
||||||
|
|
||||||
@@ -35,13 +36,12 @@ void TownPlacer::process()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
placeTowns(*manager);
|
placeTowns(*manager);
|
||||||
placeMines(*manager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TownPlacer::init()
|
void TownPlacer::init()
|
||||||
{
|
{
|
||||||
|
POSTFUNCTION(MinePlacer);
|
||||||
POSTFUNCTION(ObjectManager);
|
POSTFUNCTION(ObjectManager);
|
||||||
POSTFUNCTION(RoadPlacer);
|
POSTFUNCTION(RoadPlacer);
|
||||||
}
|
}
|
||||||
@@ -153,58 +153,6 @@ int3 TownPlacer::placeMainTown(ObjectManager & manager, CGTownInstance & town)
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TownPlacer::placeMines(ObjectManager & manager)
|
|
||||||
{
|
|
||||||
using namespace Res;
|
|
||||||
std::vector<CGMine*> createdMines;
|
|
||||||
|
|
||||||
std::vector<std::pair<CGObjectInstance*, ui32>> requiredObjects;
|
|
||||||
|
|
||||||
for(const auto & mineInfo : zone.getMinesInfo())
|
|
||||||
{
|
|
||||||
ERes res = static_cast<ERes>(mineInfo.first);
|
|
||||||
for(int i = 0; i < mineInfo.second; ++i)
|
|
||||||
{
|
|
||||||
auto mineHandler = VLC->objtypeh->getHandlerFor(Obj::MINE, res);
|
|
||||||
const auto & rmginfo = mineHandler->getRMGInfo();
|
|
||||||
auto * mine = dynamic_cast<CGMine *>(mineHandler->create());
|
|
||||||
mine->producedResource = res;
|
|
||||||
mine->tempOwner = PlayerColor::NEUTRAL;
|
|
||||||
mine->producedQuantity = mine->defaultResProduction();
|
|
||||||
createdMines.push_back(mine);
|
|
||||||
|
|
||||||
|
|
||||||
if(!i && (res == ERes::WOOD || res == ERes::ORE))
|
|
||||||
manager.addCloseObject(mine, rmginfo.value); //only first wood&ore mines are close
|
|
||||||
else
|
|
||||||
requiredObjects.push_back(std::pair<CGObjectInstance*, ui32>(mine, rmginfo.value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Shuffle mines to avoid patterns, but don't shuffle key objects like towns
|
|
||||||
RandomGeneratorUtil::randomShuffle(requiredObjects, generator.rand);
|
|
||||||
for (const auto& obj : requiredObjects)
|
|
||||||
{
|
|
||||||
manager.addRequiredObject(obj.first, obj.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
//create extra resources
|
|
||||||
if(int extraRes = generator.getConfig().mineExtraResources)
|
|
||||||
{
|
|
||||||
for(auto * mine : createdMines)
|
|
||||||
{
|
|
||||||
for(int rc = generator.rand.nextInt(1, extraRes); rc > 0; --rc)
|
|
||||||
{
|
|
||||||
auto * resourse = dynamic_cast<CGResource *>(VLC->objtypeh->getHandlerFor(Obj::RESOURCE, mine->producedResource)->create());
|
|
||||||
resourse->amount = CGResource::RANDOM_AMOUNT;
|
|
||||||
manager.addNearbyObject(resourse, mine);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TownPlacer::cleanupBoundaries(const rmg::Object & rmgObject)
|
void TownPlacer::cleanupBoundaries(const rmg::Object & rmgObject)
|
||||||
{
|
{
|
||||||
for(const auto & t : rmgObject.getArea().getBorderOutside())
|
for(const auto & t : rmgObject.getArea().getBorderOutside())
|
||||||
|
Reference in New Issue
Block a user