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"
|
2024-02-14 15:48:06 +02:00
|
|
|
#include "json/JsonBonus.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
|
|
|
|
2024-01-05 15:58:25 +02:00
|
|
|
info->modScope = scope;
|
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-10-21 13:50:42 +02:00
|
|
|
bonus->sid = BonusSourceID(info->getId());
|
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
|
|
|
|
{
|
2024-01-17 16:58:27 +02:00
|
|
|
static const auto types = std::vector<std::string> { "battlefield" };
|
2022-06-28 10:05:30 +02:00
|
|
|
|
|
|
|
return types;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2024-01-05 15:58:25 +02:00
|
|
|
return modScope + ':' + identifier;
|
2023-01-18 23:56:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|