mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-15 13:33:36 +02:00
Add new files
This commit is contained in:
parent
bc4d6bb7ee
commit
a9a3c456f1
110
lib/rmg/QuestArtifactPlacer.cpp
Normal file
110
lib/rmg/QuestArtifactPlacer.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* QuestArtifact.cpp, 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
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "StdInc.h"
|
||||
#include "QuestArtifactPlacer.h"
|
||||
#include "CMapGenerator.h"
|
||||
#include "RmgMap.h"
|
||||
#include "TreasurePlacer.h"
|
||||
#include "CZonePlacer.h"
|
||||
#include "../VCMI_Lib.h"
|
||||
#include "../mapObjects/CObjectHandler.h"
|
||||
#include "../mapObjects/CommonConstructors.h"
|
||||
#include "../mapObjects/MapObjects.h"
|
||||
|
||||
void QuestArtifactPlacer::process()
|
||||
{
|
||||
findZonesForQuestArts();
|
||||
placeQuestArtifacts(&generator.rand);
|
||||
}
|
||||
|
||||
void QuestArtifactPlacer::init()
|
||||
{
|
||||
DEPENDENCY_ALL(TreasurePlacer);
|
||||
}
|
||||
|
||||
void QuestArtifactPlacer::addQuestArtZone(std::shared_ptr<Zone> otherZone)
|
||||
{
|
||||
questArtZones.push_back(otherZone);
|
||||
}
|
||||
|
||||
void QuestArtifactPlacer::addQuestArtifact(const ArtifactID& id)
|
||||
{
|
||||
logGlobal->info((boost::format("Need to place quest artifact artifact %s")
|
||||
% VLC->arth->getById(id)->getNameTranslated()).str());
|
||||
questArtifactsToPlace.emplace_back(id);
|
||||
}
|
||||
|
||||
void QuestArtifactPlacer::rememberPotentialArtifactToReplace(CGObjectInstance* obj)
|
||||
{
|
||||
artifactsToReplace.push_back(obj);
|
||||
}
|
||||
|
||||
std::vector<CGObjectInstance*> QuestArtifactPlacer::getPossibleArtifactsToReplace() const
|
||||
{
|
||||
return artifactsToReplace;
|
||||
}
|
||||
|
||||
void QuestArtifactPlacer::findZonesForQuestArts()
|
||||
{
|
||||
//FIXME: Store and access CZonePlacer from CMapGenerator
|
||||
|
||||
const auto& distances = generator.getZonePlacer()->getDistanceMap().at(zone.getId());
|
||||
for (auto const& connectedZone : distances)
|
||||
{
|
||||
// Choose zones that are 1 or 2 connections away
|
||||
if (vstd::iswithin(connectedZone.second, 1, 2))
|
||||
{
|
||||
addQuestArtZone(map.getZones().at(connectedZone.first));
|
||||
}
|
||||
}
|
||||
|
||||
logGlobal->info((boost::format("Number of nearby zones suitable for quest artifacts: %d") % questArtZones.size()).str());
|
||||
logGlobal->info((boost::format("Number of possible quest artifacts remaining: %d") % generator.getQuestArtsRemaning().size()).str());
|
||||
}
|
||||
|
||||
void QuestArtifactPlacer::placeQuestArtifacts(CRandomGenerator * rand)
|
||||
{
|
||||
for (const auto & artifactToPlace : questArtifactsToPlace)
|
||||
{
|
||||
RandomGeneratorUtil::randomShuffle(questArtZones, *rand);
|
||||
for (auto zone : questArtZones)
|
||||
{
|
||||
auto* qap = zone->getModificator<QuestArtifactPlacer>();
|
||||
std::vector<CGObjectInstance *> artifactsToReplace = qap->getPossibleArtifactsToReplace();
|
||||
if (artifactsToReplace.empty())
|
||||
continue;
|
||||
|
||||
auto artifactToReplace = *RandomGeneratorUtil::nextItem(artifactsToReplace, *rand);
|
||||
logGlobal->info((boost::format("Replacing %s at %s with the quest artifact %s")
|
||||
% artifactToReplace->getObjectName()
|
||||
% artifactToReplace->getPosition().toString()
|
||||
% VLC->arth->getById(artifactToPlace)->getNameTranslated()).str());
|
||||
artifactToReplace->ID = Obj::ARTIFACT;
|
||||
artifactToReplace->subID = artifactToPlace;
|
||||
|
||||
//Update appearance. Terrain is irrelevant.
|
||||
auto handler = VLC->objtypeh->getHandlerFor(Obj::ARTIFACT, artifactToPlace);
|
||||
auto templates = handler->getTemplates();
|
||||
artifactToReplace->appearance = templates.front();
|
||||
//FIXME: Instance name is still "randomArtifact"
|
||||
|
||||
qap->dropReplacedArtifact(artifactToReplace);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QuestArtifactPlacer::dropReplacedArtifact(CGObjectInstance* obj)
|
||||
{
|
||||
boost::remove(artifactsToReplace, obj);
|
||||
}
|
43
lib/rmg/QuestArtifactPlacer.h
Normal file
43
lib/rmg/QuestArtifactPlacer.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* QuestArtifactPlacer, 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"
|
||||
#include "../mapObjects/ObjectTemplate.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
class CRandomGenerator;
|
||||
|
||||
class QuestArtifactPlacer : public Modificator
|
||||
{
|
||||
public:
|
||||
MODIFICATOR(QuestArtifactPlacer);
|
||||
|
||||
void process() override;
|
||||
void init() override;
|
||||
|
||||
void addQuestArtZone(std::shared_ptr<Zone> otherZone);
|
||||
void findZonesForQuestArts();
|
||||
|
||||
void addQuestArtifact(const ArtifactID& id);
|
||||
void rememberPotentialArtifactToReplace(CGObjectInstance* obj);
|
||||
std::vector<CGObjectInstance*> getPossibleArtifactsToReplace() const;
|
||||
void placeQuestArtifacts(CRandomGenerator* rand);
|
||||
void dropReplacedArtifact(CGObjectInstance* obj);
|
||||
|
||||
protected:
|
||||
|
||||
std::vector<std::shared_ptr<Zone>> questArtZones; //artifacts required for Seer Huts will be placed here - or not if null
|
||||
std::vector<ArtifactID> questArtifactsToPlace;
|
||||
std::vector<CGObjectInstance*> artifactsToReplace; //Common artifacts which may be replaced by quest artifacts from other zones
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
Loading…
x
Reference in New Issue
Block a user