2013-02-11 22:27:37 +03:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-02-14 02:55:42 +03:00
|
|
|
#define INSTANTIATE_BASE_FOR_ID_HERE
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
#include "StdInc.h"
|
|
|
|
|
2016-10-27 15:27:10 +02:00
|
|
|
#ifndef VCMI_NO_EXTRA_VERSION
|
|
|
|
#include "../Version.h"
|
|
|
|
#endif
|
|
|
|
|
2013-02-11 02:24:57 +03:00
|
|
|
#include "VCMI_Lib.h"
|
2014-06-05 14:19:47 +03:00
|
|
|
#include "mapObjects/CObjectClassesHandler.h"
|
2013-02-11 02:24:57 +03:00
|
|
|
#include "CArtHandler.h"
|
|
|
|
#include "CCreatureHandler.h"
|
2015-02-02 10:25:26 +02:00
|
|
|
#include "spells/CSpellHandler.h"
|
2016-09-15 17:22:54 +02:00
|
|
|
#include "StringConstants.h"
|
|
|
|
#include "CGeneralTextHandler.h"
|
2013-02-11 02:24:57 +03:00
|
|
|
|
2013-02-16 17:03:47 +03:00
|
|
|
const SlotID SlotID::COMMANDER_SLOT_PLACEHOLDER = SlotID(-2);
|
2016-01-29 23:53:53 +02:00
|
|
|
const SlotID SlotID::SUMMONED_SLOT_PLACEHOLDER = SlotID(-3);
|
|
|
|
const SlotID SlotID::WAR_MACHINES_SLOT = SlotID(-4);
|
|
|
|
const SlotID SlotID::ARROW_TOWERS_SLOT = SlotID(-5);
|
|
|
|
|
2013-03-03 20:06:03 +03:00
|
|
|
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);
|
2013-02-16 17:03:47 +03:00
|
|
|
|
2016-10-27 15:27:10 +02:00
|
|
|
namespace GameConstants
|
|
|
|
{
|
|
|
|
#ifdef VCMI_NO_EXTRA_VERSION
|
2016-11-01 19:25:09 +02:00
|
|
|
const std::string VCMI_VERSION = std::string("VCMI 0.99");
|
2016-10-27 15:27:10 +02:00
|
|
|
#else
|
2016-11-01 19:25:09 +02:00
|
|
|
const std::string VCMI_VERSION = std::string("VCMI 0.99 ") + GIT_SHA1;
|
2016-10-27 15:27:10 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-10-02 14:22:55 +02:00
|
|
|
const CArtifact * ArtifactID::toArtifact() const
|
2013-02-11 02:24:57 +03:00
|
|
|
{
|
2016-10-02 14:22:55 +02:00
|
|
|
return VLC->arth->artifacts.at(*this);
|
2013-02-11 02:24:57 +03:00
|
|
|
}
|
|
|
|
|
2016-10-02 14:22:55 +02:00
|
|
|
const CCreature * CreatureID::toCreature() const
|
2013-02-11 02:24:57 +03:00
|
|
|
{
|
2016-10-02 14:22:55 +02:00
|
|
|
return VLC->creh->creatures.at(*this);
|
2013-02-11 02:24:57 +03:00
|
|
|
}
|
|
|
|
|
2016-10-02 14:22:55 +02:00
|
|
|
const CSpell * SpellID::toSpell() const
|
2013-02-11 02:24:57 +03:00
|
|
|
{
|
2014-11-27 23:36:14 +02:00
|
|
|
if(num < 0 || num >= VLC->spellh->objects.size())
|
2015-03-22 21:32:22 +02:00
|
|
|
{
|
2014-11-27 23:36:14 +02:00
|
|
|
logGlobal->errorStream() << "Unable to get spell of invalid ID " << int(num);
|
|
|
|
return nullptr;
|
2015-03-22 21:32:22 +02:00
|
|
|
}
|
2014-03-07 16:21:09 +03:00
|
|
|
return VLC->spellh->objects[*this];
|
2013-02-11 02:24:57 +03:00
|
|
|
}
|
2013-02-14 02:55:42 +03:00
|
|
|
|
2013-02-14 05:17:46 +03:00
|
|
|
//template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
|
|
|
|
//template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);
|
2013-04-20 14:34:01 +03:00
|
|
|
|
|
|
|
bool PlayerColor::isValidPlayer() const
|
|
|
|
{
|
|
|
|
return num < PLAYER_LIMIT_I;
|
|
|
|
}
|
2013-11-09 19:25:20 +03:00
|
|
|
|
2016-09-15 17:22:54 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-09 19:25:20 +03:00
|
|
|
std::ostream & operator<<(std::ostream & os, const Battle::ActionType actionType)
|
|
|
|
{
|
2014-10-02 18:43:46 +03:00
|
|
|
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"}
|
|
|
|
};
|
2013-11-09 19:25:20 +03:00
|
|
|
|
|
|
|
auto it = actionTypeToString.find(actionType);
|
|
|
|
if (it == actionTypeToString.end()) return os << "<Unknown type>";
|
|
|
|
else return os << it->second;
|
|
|
|
}
|
2015-03-22 21:32:22 +02:00
|
|
|
|
2015-11-05 11:46:44 +02:00
|
|
|
std::ostream & operator<<(std::ostream & os, const ETerrainType terrainType)
|
2015-03-22 21:32:22 +02:00
|
|
|
{
|
|
|
|
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)
|
2015-11-05 11:46:44 +02:00
|
|
|
#undef DEFINE_ELEMENT
|
2015-03-22 21:32:22 +02:00
|
|
|
};
|
|
|
|
|
2015-11-05 11:46:44 +02:00
|
|
|
auto it = terrainTypeToString.find(terrainType.num);
|
2015-03-22 21:32:22 +02:00
|
|
|
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();
|
|
|
|
}
|
2015-11-02 12:25:01 +02:00
|
|
|
|
2015-11-05 11:46:44 +02:00
|
|
|
std::ostream & operator<<(std::ostream & os, const EPathfindingLayer pathfindingLayer)
|
2015-11-02 12:25:01 +02:00
|
|
|
{
|
2015-11-05 11:46:44 +02:00
|
|
|
static const std::map<EPathfindingLayer::EEPathfindingLayer, std::string> pathfinderLayerToString
|
2015-11-02 12:25:01 +02:00
|
|
|
{
|
|
|
|
#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)
|
2015-11-05 11:46:44 +02:00
|
|
|
#undef DEFINE_ELEMENT
|
2015-11-02 12:25:01 +02:00
|
|
|
};
|
|
|
|
|
2015-11-05 11:46:44 +02:00
|
|
|
auto it = pathfinderLayerToString.find(pathfindingLayer.num);
|
2015-11-02 12:25:01 +02:00
|
|
|
if (it == pathfinderLayerToString.end()) return os << "<Unknown type>";
|
|
|
|
else return os << it->second;
|
|
|
|
}
|