1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/*
* GameConstants.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
*
*/
#define INSTANTIATE_BASE_FOR_ID_HERE
#include "StdInc.h"
#ifndef VCMI_NO_EXTRA_VERSION
#include "../Version.h"
#endif
#include "VCMI_Lib.h"
#include "mapObjects/CObjectClassesHandler.h"
#include "CArtHandler.h"
#include "CCreatureHandler.h"
#include "spells/CSpellHandler.h"
#include "StringConstants.h"
#include "CGeneralTextHandler.h"
const SlotID SlotID::COMMANDER_SLOT_PLACEHOLDER = SlotID(-2);
const SlotID SlotID::SUMMONED_SLOT_PLACEHOLDER = SlotID(-3);
const SlotID SlotID::WAR_MACHINES_SLOT = SlotID(-4);
const SlotID SlotID::ARROW_TOWERS_SLOT = SlotID(-5);
const PlayerColor PlayerColor::CANNOT_DETERMINE = PlayerColor(253);
const PlayerColor PlayerColor::UNFLAGGABLE = PlayerColor(254);
const PlayerColor PlayerColor::NEUTRAL = PlayerColor(255);
const PlayerColor PlayerColor::PLAYER_LIMIT = PlayerColor(PLAYER_LIMIT_I);
const TeamID TeamID::NO_TEAM = TeamID(255);
namespace GameConstants
{
#ifdef VCMI_NO_EXTRA_VERSION
const std::string VCMI_VERSION = std::string("VCMI 0.99");
#else
const std::string VCMI_VERSION = std::string("VCMI 0.99 ") + GIT_SHA1;
#endif
}
const CArtifact * ArtifactID::toArtifact() const
{
return VLC->arth->artifacts.at(*this);
}
const CCreature * CreatureID::toCreature() const
{
return VLC->creh->creatures.at(*this);
}
const CSpell * SpellID::toSpell() const
{
if(num < 0 || num >= VLC->spellh->objects.size())
{
logGlobal->errorStream() << "Unable to get spell of invalid ID " << int(num);
return nullptr;
}
return VLC->spellh->objects[*this];
}
//template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
//template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);
bool PlayerColor::isValidPlayer() const
{
return num < PLAYER_LIMIT_I;
}
std::string PlayerColor::getStr(bool L10n) const
{
std::string ret = "unnamed";
if(isValidPlayer())
{
if(L10n)
ret = VLC->generaltexth->colors[num];
else
ret = GameConstants::PLAYER_COLOR_NAMES[num];
}
else if(L10n)
{
ret = VLC->generaltexth->allTexts[508];
ret[0] = std::tolower(ret[0]);
}
return ret;
}
std::string PlayerColor::getStrCap(bool L10n) const
{
std::string ret = getStr(L10n);
ret[0] = std::toupper(ret[0]);
return ret;
}
std::ostream & operator<<(std::ostream & os, const Battle::ActionType actionType)
{
static const std::map<Battle::ActionType, std::string> actionTypeToString =
{
{Battle::END_TACTIC_PHASE, "End tactic phase"},
{Battle::INVALID, "Invalid"},
{Battle::NO_ACTION, "No action"},
{Battle::HERO_SPELL, "Hero spell"},
{Battle::WALK, "Walk"},
{Battle::DEFEND, "Defend"},
{Battle::RETREAT, "Retreat"},
{Battle::SURRENDER, "Surrender"},
{Battle::WALK_AND_ATTACK, "Walk and attack"},
{Battle::SHOOT, "Shoot"},
{Battle::WAIT, "Wait"},
{Battle::CATAPULT, "Catapult"},
{Battle::MONSTER_SPELL, "Monster spell"},
{Battle::BAD_MORALE, "Bad morale"},
{Battle::STACK_HEAL, "Stack heal"},
{Battle::DAEMON_SUMMONING, "Daemon summoning"}
};
auto it = actionTypeToString.find(actionType);
if (it == actionTypeToString.end()) return os << "<Unknown type>";
else return os << it->second;
}
std::ostream & operator<<(std::ostream & os, const ETerrainType terrainType)
{
static const std::map<ETerrainType::EETerrainType, std::string> terrainTypeToString =
{
#define DEFINE_ELEMENT(element) {ETerrainType::element, #element}
DEFINE_ELEMENT(WRONG),
DEFINE_ELEMENT(BORDER),
DEFINE_ELEMENT(DIRT),
DEFINE_ELEMENT(SAND),
DEFINE_ELEMENT(GRASS),
DEFINE_ELEMENT(SNOW),
DEFINE_ELEMENT(SWAMP),
DEFINE_ELEMENT(ROUGH),
DEFINE_ELEMENT(SUBTERRANEAN),
DEFINE_ELEMENT(LAVA),
DEFINE_ELEMENT(WATER),
DEFINE_ELEMENT(ROCK)
#undef DEFINE_ELEMENT
};
auto it = terrainTypeToString.find(terrainType.num);
if (it == terrainTypeToString.end()) return os << "<Unknown type>";
else return os << it->second;
}
std::string ETerrainType::toString() const
{
std::stringstream ss;
ss << *this;
return ss.str();
}
std::ostream & operator<<(std::ostream & os, const EPathfindingLayer pathfindingLayer)
{
static const std::map<EPathfindingLayer::EEPathfindingLayer, std::string> pathfinderLayerToString
{
#define DEFINE_ELEMENT(element) {EPathfindingLayer::element, #element}
DEFINE_ELEMENT(WRONG),
DEFINE_ELEMENT(AUTO),
DEFINE_ELEMENT(LAND),
DEFINE_ELEMENT(SAIL),
DEFINE_ELEMENT(WATER),
DEFINE_ELEMENT(AIR),
DEFINE_ELEMENT(NUM_LAYERS)
#undef DEFINE_ELEMENT
};
auto it = pathfinderLayerToString.find(pathfindingLayer.num);
if (it == pathfinderLayerToString.end()) return os << "<Unknown type>";
else return os << it->second;
}
|