2023-03-29 16:54:22 +02:00
|
|
|
/*
|
|
|
|
* 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"
|
2023-04-12 07:48:44 +02:00
|
|
|
#include "ConnectionsPlacer.h"
|
2023-05-20 10:17:37 +02:00
|
|
|
#include "../CMapGenerator.h"
|
|
|
|
#include "../RmgMap.h"
|
2023-06-02 20:47:37 +02:00
|
|
|
#include "../../mapObjectConstructors/AObjectTypeHandler.h"
|
|
|
|
#include "../../mapObjectConstructors/CObjectClassesHandler.h"
|
2023-05-20 10:17:37 +02:00
|
|
|
#include "../../mapping/CMapEditManager.h"
|
|
|
|
#include "../RmgPath.h"
|
|
|
|
#include "../RmgObject.h"
|
2023-03-29 16:54:22 +02:00
|
|
|
#include "ObjectManager.h"
|
2023-05-20 10:17:37 +02:00
|
|
|
#include "../Functions.h"
|
2023-03-29 16:54:22 +02:00
|
|
|
#include "RoadPlacer.h"
|
|
|
|
#include "WaterAdopter.h"
|
2023-05-20 10:17:37 +02:00
|
|
|
#include "../TileInfo.h"
|
2023-03-29 16:54:22 +02:00
|
|
|
|
|
|
|
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);
|
2023-04-12 07:48:44 +02:00
|
|
|
DEPENDENCY(ConnectionsPlacer);
|
2023-03-29 16:54:22 +02:00
|
|
|
POSTFUNCTION(ObjectManager);
|
|
|
|
POSTFUNCTION(RoadPlacer);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MinePlacer::placeMines(ObjectManager & manager)
|
|
|
|
{
|
|
|
|
std::vector<CGMine*> createdMines;
|
|
|
|
|
|
|
|
std::vector<std::pair<CGObjectInstance*, ui32>> requiredObjects;
|
|
|
|
|
|
|
|
for(const auto & mineInfo : zone.getMinesInfo())
|
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
const auto res = GameResID(mineInfo.first);
|
2023-03-29 16:54:22 +02:00
|
|
|
for(int i = 0; i < mineInfo.second; ++i)
|
|
|
|
{
|
|
|
|
auto mineHandler = VLC->objtypeh->getHandlerFor(Obj::MINE, res);
|
|
|
|
const auto & rmginfo = mineHandler->getRMGInfo();
|
2024-01-01 16:37:48 +02:00
|
|
|
auto * mine = dynamic_cast<CGMine *>(mineHandler->create(map.mapInstance->cb, nullptr));
|
2023-03-29 16:54:22 +02:00
|
|
|
mine->producedResource = res;
|
|
|
|
mine->tempOwner = PlayerColor::NEUTRAL;
|
|
|
|
mine->producedQuantity = mine->defaultResProduction();
|
|
|
|
createdMines.push_back(mine);
|
|
|
|
|
|
|
|
|
2023-07-06 22:15:00 +02:00
|
|
|
if (!i && (res == EGameResID::WOOD || res == EGameResID::ORE))
|
|
|
|
{
|
2023-07-08 10:21:36 +02:00
|
|
|
//only first wood & ore mines are close
|
2023-07-06 22:15:00 +02:00
|
|
|
manager.addCloseObject(RequiredObjectInfo(mine, rmginfo.value));
|
|
|
|
}
|
2023-03-29 16:54:22 +02:00
|
|
|
else
|
|
|
|
requiredObjects.push_back(std::pair<CGObjectInstance*, ui32>(mine, rmginfo.value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Shuffle mines to avoid patterns, but don't shuffle key objects like towns
|
2023-05-20 11:46:32 +02:00
|
|
|
RandomGeneratorUtil::randomShuffle(requiredObjects, zone.getRand());
|
2023-03-29 16:54:22 +02:00
|
|
|
for (const auto& obj : requiredObjects)
|
|
|
|
{
|
2023-07-06 22:15:00 +02:00
|
|
|
manager.addRequiredObject(RequiredObjectInfo(obj.first, obj.second));
|
2023-03-29 16:54:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//create extra resources
|
|
|
|
if(int extraRes = generator.getConfig().mineExtraResources)
|
|
|
|
{
|
|
|
|
for(auto * mine : createdMines)
|
|
|
|
{
|
2023-05-20 11:46:32 +02:00
|
|
|
for(int rc = zone.getRand().nextInt(1, extraRes); rc > 0; --rc)
|
2023-03-29 16:54:22 +02:00
|
|
|
{
|
2024-01-01 16:37:48 +02:00
|
|
|
auto * resource = dynamic_cast<CGResource *>(VLC->objtypeh->getHandlerFor(Obj::RESOURCE, mine->producedResource)->create(map.mapInstance->cb, nullptr));
|
2023-07-06 22:15:00 +02:00
|
|
|
resource->amount = CGResource::RANDOM_AMOUNT;
|
|
|
|
|
|
|
|
RequiredObjectInfo roi;
|
|
|
|
roi.obj = resource;
|
|
|
|
roi.nearbyTarget = mine;
|
|
|
|
manager.addNearbyObject(roi);
|
2023-03-29 16:54:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-05-24 01:05:59 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|