1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

Code cleanup

This commit is contained in:
Ivan Savenko
2024-01-19 23:02:00 +02:00
parent e50f586d8b
commit d04241b10a
12 changed files with 22 additions and 22 deletions

View File

@ -236,7 +236,7 @@ int getDwellingArmyCost(const CGObjectInstance * target)
return cost; return cost;
} }
uint64_t evaluateArtifactArmyValue(CArtifactInstance * art) static uint64_t evaluateArtifactArmyValue(const CArtifactInstance * art)
{ {
if(art->artType->getId() == ArtifactID::SPELL_SCROLL) if(art->artType->getId() == ArtifactID::SPELL_SCROLL)
return 1500; return 1500;

View File

@ -373,7 +373,7 @@ HeroExchangeArmy * HeroExchangeMap::tryUpgrade(
for(auto & creatureToBuy : buyArmy) for(auto & creatureToBuy : buyArmy)
{ {
auto targetSlot = target->getSlotFor(dynamic_cast<const CCreature*>(creatureToBuy.creID.toCreature())); auto targetSlot = target->getSlotFor(creatureToBuy.creID.toCreature());
target->addToSlot(targetSlot, creatureToBuy.creID, creatureToBuy.count); target->addToSlot(targetSlot, creatureToBuy.creID, creatureToBuy.count);
target->armyCost += creatureToBuy.creID.toCreature()->getFullRecruitCost() * creatureToBuy.count; target->armyCost += creatureToBuy.creID.toCreature()->getFullRecruitCost() * creatureToBuy.count;

View File

@ -12,7 +12,7 @@
#include "../lib/VCMI_Lib.h" #include "../lib/VCMI_Lib.h"
const CGameInfo * CGI; CGameInfo * CGI;
CClientState * CCS = nullptr; CClientState * CCS = nullptr;
CServerHandler * CSH; CServerHandler * CSH;

View File

@ -99,4 +99,4 @@ public:
private: private:
const Services * globalServices; const Services * globalServices;
}; };
extern const CGameInfo* CGI; extern CGameInfo* CGI;

View File

@ -72,7 +72,7 @@ void init()
CStopWatch tmh; CStopWatch tmh;
loadDLLClasses(); loadDLLClasses();
const_cast<CGameInfo*>(CGI)->setFromLib(); CGI->setFromLib();
logGlobal->info("Initializing VCMI_Lib: %d ms", tmh.getDiff()); logGlobal->info("Initializing VCMI_Lib: %d ms", tmh.getDiff());

View File

@ -367,7 +367,7 @@ void CClient::endGame()
logNetwork->info("Ending current game!"); logNetwork->info("Ending current game!");
removeGUI(); removeGUI();
const_cast<CGameInfo *>(CGI)->mh.reset(); CGI->mh.reset();
vstd::clear_pointer(gs); vstd::clear_pointer(gs);
logNetwork->info("Deleted mapHandler and gameState."); logNetwork->info("Deleted mapHandler and gameState.");
@ -389,7 +389,7 @@ void CClient::initMapHandler()
// During loading CPlayerInterface from serialized state it's depend on MH // During loading CPlayerInterface from serialized state it's depend on MH
if(!settings["session"]["headless"].Bool()) if(!settings["session"]["headless"].Bool())
{ {
const_cast<CGameInfo *>(CGI)->mh = std::make_shared<CMapHandler>(gs->map); CGI->mh = std::make_shared<CMapHandler>(gs->map);
logNetwork->trace("Creating mapHandler: %d ms", CSH->th->getDiff()); logNetwork->trace("Creating mapHandler: %d ms", CSH->th->getDiff());
} }

View File

@ -155,9 +155,9 @@ bool CHeroClass::isMagicHero() const
return affinity == MAGIC; return affinity == MAGIC;
} }
int CHeroClass::tavernProbability(FactionID faction) const int CHeroClass::tavernProbability(FactionID targetFaction) const
{ {
auto it = selectionProbability.find(faction); auto it = selectionProbability.find(targetFaction);
if (it != selectionProbability.end()) if (it != selectionProbability.end())
return it->second; return it->second;
return 0; return 0;

View File

@ -31,7 +31,7 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
si32 JsonRandom::loadVariable(std::string variableGroup, const std::string & value, const Variables & variables, si32 defaultValue) si32 JsonRandom::loadVariable(const std::string & variableGroup, const std::string & value, const Variables & variables, si32 defaultValue)
{ {
if (value.empty() || value[0] != '@') if (value.empty() || value[0] != '@')
{ {
@ -54,7 +54,7 @@ VCMI_LIB_NAMESPACE_BEGIN
if(value.isNull()) if(value.isNull())
return defaultValue; return defaultValue;
if(value.isNumber()) if(value.isNumber())
return static_cast<si32>(value.Float()); return value.Integer();
if (value.isString()) if (value.isString())
return loadVariable("number", value.String(), variables, defaultValue); return loadVariable("number", value.String(), variables, defaultValue);
@ -68,9 +68,9 @@ VCMI_LIB_NAMESPACE_BEGIN
if(value.isStruct()) if(value.isStruct())
{ {
if (!value["amount"].isNull()) if (!value["amount"].isNull())
return static_cast<si32>(loadValue(value["amount"], rng, variables, defaultValue)); return loadValue(value["amount"], rng, variables, defaultValue);
si32 min = static_cast<si32>(loadValue(value["min"], rng, variables, 0)); si32 min = loadValue(value["min"], rng, variables, 0);
si32 max = static_cast<si32>(loadValue(value["max"], rng, variables, 0)); si32 max = loadValue(value["max"], rng, variables, 0);
return rng.getIntRange(min, max)(); return rng.getIntRange(min, max)();
} }
return defaultValue; return defaultValue;

View File

@ -41,7 +41,7 @@ private:
template<typename IdentifierType> template<typename IdentifierType>
IdentifierType decodeKey(const JsonNode & value, const Variables & variables); IdentifierType decodeKey(const JsonNode & value, const Variables & variables);
si32 loadVariable(std::string variableGroup, const std::string & value, const Variables & variables, si32 defaultValue); si32 loadVariable(const std::string & variableGroup, const std::string & value, const Variables & variables, si32 defaultValue);
public: public:
using GameCallbackHolder::GameCallbackHolder; using GameCallbackHolder::GameCallbackHolder;

View File

@ -486,7 +486,7 @@ void CBonusSystemNode::getRedParents(TCNodes & out) const
if(!actsAsBonusSourceOnly()) if(!actsAsBonusSourceOnly())
{ {
for(CBonusSystemNode *child : children) for(const CBonusSystemNode *child : children)
{ {
out.insert(child); out.insert(child);
} }

View File

@ -171,10 +171,10 @@ CGameState::~CGameState()
initialOpts.dellNull(); initialOpts.dellNull();
} }
void CGameState::preInit(Services * services, IGameCallback * callback) void CGameState::preInit(Services * newServices, IGameCallback * newCallback)
{ {
this->services = services; services = newServices;
this->callback = callback; callback = newCallback;
} }
void CGameState::init(const IMapService * mapService, StartInfo * si, Load::ProgressAccumulator & progressTracking, bool allowSavingRandomMap) void CGameState::init(const IMapService * mapService, StartInfo * si, Load::ProgressAccumulator & progressTracking, bool allowSavingRandomMap)
@ -631,7 +631,7 @@ void CGameState::initHeroes()
if (tile.terType->isWater()) if (tile.terType->isWater())
{ {
auto handler = VLC->objtypeh->getHandlerFor(Obj::BOAT, hero->getBoatType().getNum()); auto handler = VLC->objtypeh->getHandlerFor(Obj::BOAT, hero->getBoatType().getNum());
CGBoat * boat = dynamic_cast<CGBoat*>(handler->create(callback, nullptr)); auto boat = dynamic_cast<CGBoat*>(handler->create(callback, nullptr));
handler->configureObject(boat, gs->getRandomGenerator()); handler->configureObject(boat, gs->getRandomGenerator());
boat->pos = hero->pos; boat->pos = hero->pos;

View File

@ -247,7 +247,7 @@ std::vector<const CHeroClass *> HeroPoolProcessor::findAvailableClassesFor(const
const auto & heroesPool = gameHandler->gameState()->heroesPool; const auto & heroesPool = gameHandler->gameState()->heroesPool;
FactionID factionID = gameHandler->getPlayerSettings(player)->castle; FactionID factionID = gameHandler->getPlayerSettings(player)->castle;
for(auto & elem : heroesPool->unusedHeroesFromPool()) for(const auto & elem : heroesPool->unusedHeroesFromPool())
{ {
if (vstd::contains(result, elem.second->type->heroClass)) if (vstd::contains(result, elem.second->type->heroClass))
continue; continue;
@ -268,7 +268,7 @@ std::vector<CGHeroInstance *> HeroPoolProcessor::findAvailableHeroesFor(const Pl
const auto & heroesPool = gameHandler->gameState()->heroesPool; const auto & heroesPool = gameHandler->gameState()->heroesPool;
for(auto & elem : heroesPool->unusedHeroesFromPool()) for(const auto & elem : heroesPool->unusedHeroesFromPool())
{ {
assert(!vstd::contains(result, elem.second)); assert(!vstd::contains(result, elem.second));