2022-06-28 10:05:30 +02:00
|
|
|
/*
|
2022-09-15 10:06:54 +02:00
|
|
|
* BattleFieldHandler.cpp, part of VCMI engine
|
2022-06-28 10:05:30 +02:00
|
|
|
*
|
|
|
|
* 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 <vcmi/Entity.h>
|
|
|
|
#include "BattleFieldHandler.h"
|
2023-05-05 23:45:09 +02:00
|
|
|
#include "JsonNode.h"
|
2022-06-28 10:05:30 +02:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2022-06-28 10:05:30 +02:00
|
|
|
BattleFieldInfo * BattleFieldHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index)
|
|
|
|
{
|
2023-01-18 23:56:01 +02:00
|
|
|
assert(identifier.find(':') == std::string::npos);
|
|
|
|
|
2023-03-13 23:26:44 +02:00
|
|
|
auto * info = new BattleFieldInfo(BattleField(index), identifier);
|
2022-06-28 10:05:30 +02:00
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
info->graphics = ImagePath::fromJson(json["graphics"]);
|
2023-01-18 23:56:01 +02:00
|
|
|
info->icon = json["icon"].String();
|
|
|
|
info->name = json["name"].String();
|
2023-03-13 23:26:44 +02:00
|
|
|
for(const auto & b : json["bonuses"].Vector())
|
2022-06-28 10:05:30 +02:00
|
|
|
{
|
2023-01-18 23:56:01 +02:00
|
|
|
auto bonus = JsonUtils::parseBonus(b);
|
2022-06-28 10:05:30 +02:00
|
|
|
|
2023-05-01 00:20:01 +02:00
|
|
|
bonus->source = BonusSource::TERRAIN_OVERLAY;
|
2023-01-18 23:56:01 +02:00
|
|
|
bonus->sid = info->getIndex();
|
2023-05-01 00:20:01 +02:00
|
|
|
bonus->duration = BonusDuration::ONE_BATTLE;
|
2022-06-28 10:05:30 +02:00
|
|
|
|
2023-01-18 23:56:01 +02:00
|
|
|
info->bonuses.push_back(bonus);
|
2022-06-28 10:05:30 +02:00
|
|
|
}
|
|
|
|
|
2023-01-18 23:56:01 +02:00
|
|
|
info->isSpecial = json["isSpecial"].Bool();
|
|
|
|
for(auto node : json["impassableHexes"].Vector())
|
2023-03-13 23:26:44 +02:00
|
|
|
info->impassableHexes.emplace_back(node.Integer());
|
2022-06-28 10:05:30 +02:00
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2023-03-15 21:34:29 +02:00
|
|
|
std::vector<JsonNode> BattleFieldHandler::loadLegacyData()
|
2022-06-28 10:05:30 +02:00
|
|
|
{
|
|
|
|
return std::vector<JsonNode>();
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<std::string> & BattleFieldHandler::getTypeNames() const
|
|
|
|
{
|
|
|
|
static const std::vector<std::string> types = std::vector<std::string> { "battlefield" };
|
|
|
|
|
|
|
|
return types;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<bool> BattleFieldHandler::getDefaultAllowed() const
|
|
|
|
{
|
|
|
|
return std::vector<bool>();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t BattleFieldInfo::getIndex() const
|
|
|
|
{
|
|
|
|
return battlefield.getNum();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t BattleFieldInfo::getIconIndex() const
|
|
|
|
{
|
|
|
|
return iconIndex;
|
|
|
|
}
|
|
|
|
|
2023-01-18 23:56:01 +02:00
|
|
|
std::string BattleFieldInfo::getJsonKey() const
|
|
|
|
{
|
|
|
|
return identifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string BattleFieldInfo::getNameTextID() const
|
2022-06-28 10:05:30 +02:00
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2023-01-18 23:56:01 +02:00
|
|
|
std::string BattleFieldInfo::getNameTranslated() const
|
2022-06-28 10:05:30 +02:00
|
|
|
{
|
2023-01-18 23:56:01 +02:00
|
|
|
return name; // TODO?
|
2022-06-28 10:05:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BattleFieldInfo::registerIcons(const IconRegistar & cb) const
|
|
|
|
{
|
|
|
|
//cb(getIconIndex(), "BATTLEFIELD", icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
BattleField BattleFieldInfo::getId() const
|
|
|
|
{
|
|
|
|
return battlefield;
|
2022-07-26 15:07:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|