mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-16 10:19:47 +02:00
36c1ed670f
Removed most of hardcoded checks for fort level or for presence of fort/ citadel/castle buildings. It is now possible to define which parts of town fortifications are provided by town buildings Configuration for H3-like fortifications is provided in buildingsLibrary.json and will be used automatically by mods as long as mods have buidings named "fort", "citadel" and "castle". Alternatively, mods can separately define: - hitpoints of walls (shared value for all sections) - hitpoints of central, upper and lower towers (separate values) - presence of moat - shooters for each tower (separate values)
82 lines
1.6 KiB
C++
82 lines
1.6 KiB
C++
/*
|
|
* CTownHandler.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 "CTown.h"
|
|
|
|
#include "CFaction.h"
|
|
#include "CTownHandler.h"
|
|
#include "../building/CBuilding.h"
|
|
#include "../../texts/TextIdentifier.h"
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
CTown::CTown()
|
|
: faction(nullptr), mageLevel(0), primaryRes(0), defaultTavernChance(0)
|
|
{
|
|
}
|
|
|
|
CTown::~CTown()
|
|
{
|
|
for(auto & build : buildings)
|
|
build.second.dellNull();
|
|
|
|
for(auto & str : clientInfo.structures)
|
|
str.dellNull();
|
|
}
|
|
|
|
std::string CTown::getRandomNameTextID(size_t index) const
|
|
{
|
|
return TextIdentifier("faction", faction->modScope, faction->identifier, "randomName", index).get();
|
|
}
|
|
|
|
size_t CTown::getRandomNamesCount() const
|
|
{
|
|
return namesCount;
|
|
}
|
|
|
|
std::string CTown::getBuildingScope() const
|
|
{
|
|
if(faction == nullptr)
|
|
//no faction == random faction
|
|
return "building";
|
|
else
|
|
return "building." + faction->getJsonKey();
|
|
}
|
|
|
|
std::set<si32> CTown::getAllBuildings() const
|
|
{
|
|
std::set<si32> res;
|
|
|
|
for(const auto & b : buildings)
|
|
{
|
|
res.insert(b.first.num);
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
const CBuilding * CTown::getSpecialBuilding(BuildingSubID::EBuildingSubID subID) const
|
|
{
|
|
for(const auto & kvp : buildings)
|
|
{
|
|
if(kvp.second->subId == subID)
|
|
return buildings.at(kvp.first);
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
BuildingID CTown::getBuildingType(BuildingSubID::EBuildingSubID subID) const
|
|
{
|
|
const auto * building = getSpecialBuilding(subID);
|
|
return building == nullptr ? BuildingID::NONE : building->bid.num;
|
|
}
|
|
|
|
VCMI_LIB_NAMESPACE_END
|