mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Merge pull request #3610 from IvanSavenko/sonarcloud_fixes
Sonarcloud fixes
This commit is contained in:
commit
76b4a4c297
@ -10,7 +10,6 @@
|
||||
#pragma once
|
||||
#include "../../lib/battle/CUnitState.h"
|
||||
#include "../../CCallback.h"
|
||||
#include "common.h"
|
||||
#include "StackWithBonuses.h"
|
||||
|
||||
#define BATTLE_TRACE_LEVEL 0
|
||||
|
@ -49,7 +49,6 @@ CBattleAI::~CBattleAI()
|
||||
|
||||
void CBattleAI::initBattleInterface(std::shared_ptr<Environment> ENV, std::shared_ptr<CBattleCallback> CB)
|
||||
{
|
||||
setCbc(CB);
|
||||
env = ENV;
|
||||
cb = CB;
|
||||
playerID = *CB->getPlayerID();
|
||||
@ -121,7 +120,6 @@ void CBattleAI::activeStack(const BattleID & battleID, const CStack * stack )
|
||||
};
|
||||
|
||||
BattleAction result = BattleAction::makeDefend(stack);
|
||||
setCbc(cb); //TODO: make solid sure that AIs always use their callbacks (need to take care of event handlers too)
|
||||
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
|
@ -2,7 +2,6 @@ set(battleAI_SRCS
|
||||
AttackPossibility.cpp
|
||||
BattleAI.cpp
|
||||
BattleEvaluator.cpp
|
||||
common.cpp
|
||||
EnemyInfo.cpp
|
||||
PossibleSpellcast.cpp
|
||||
PotentialTargets.cpp
|
||||
@ -17,7 +16,6 @@ set(battleAI_HEADERS
|
||||
AttackPossibility.h
|
||||
BattleAI.h
|
||||
BattleEvaluator.h
|
||||
common.h
|
||||
EnemyInfo.h
|
||||
PotentialTargets.h
|
||||
PossibleSpellcast.h
|
||||
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* common.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
|
||||
*
|
||||
*/
|
||||
#include "StdInc.h"
|
||||
#include "common.h"
|
||||
|
||||
std::shared_ptr<CBattleCallback> cbc;
|
||||
|
||||
void setCbc(std::shared_ptr<CBattleCallback> cb)
|
||||
{
|
||||
cbc = cb;
|
||||
}
|
||||
|
||||
std::shared_ptr<CBattleCallback> getCbc()
|
||||
{
|
||||
return cbc;
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
* common.h, 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
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
class CBattleCallback;
|
||||
|
||||
template<typename Key, typename Val, typename Val2>
|
||||
const Val getValOr(const std::map<Key, Val> &Map, const Key &key, const Val2 defaultValue)
|
||||
{
|
||||
//returning references here won't work: defaultValue must be converted into Val, creating temporary
|
||||
auto i = Map.find(key);
|
||||
if(i != Map.end())
|
||||
return i->second;
|
||||
else
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
void setCbc(std::shared_ptr<CBattleCallback> cb);
|
||||
std::shared_ptr<CBattleCallback> getCbc();
|
@ -15,7 +15,7 @@
|
||||
#define strcpy_s(a, b, c) strncpy(a, c, b)
|
||||
#endif
|
||||
|
||||
static const char *g_cszAiName = "Battle AI";
|
||||
static const char * const g_cszAiName = "Battle AI";
|
||||
|
||||
extern "C" DLL_EXPORT int GetGlobalAiVersion()
|
||||
{
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
#include "CEmptyAI.h"
|
||||
|
||||
std::set<CGlobalAI*> ais;
|
||||
extern "C" DLL_EXPORT int GetGlobalAiVersion()
|
||||
{
|
||||
return AI_INTERFACE_VER;
|
||||
|
@ -16,7 +16,7 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
HitMapInfo HitMapInfo::NoThreat;
|
||||
const HitMapInfo HitMapInfo::NoThreat;
|
||||
|
||||
double HitMapInfo::value() const
|
||||
{
|
||||
@ -285,8 +285,6 @@ const HitMapNode & DangerHitMapAnalyzer::getTileThreat(const int3 & tile) const
|
||||
return hitMap[tile.x][tile.y][tile.z];
|
||||
}
|
||||
|
||||
const std::set<const CGObjectInstance *> empty = {};
|
||||
|
||||
std::set<const CGObjectInstance *> DangerHitMapAnalyzer::getOneTurnAccessibleObjects(const CGHeroInstance * enemy) const
|
||||
{
|
||||
std::set<const CGObjectInstance *> result;
|
||||
|
@ -18,7 +18,7 @@ struct AIPath;
|
||||
|
||||
struct HitMapInfo
|
||||
{
|
||||
static HitMapInfo NoThreat;
|
||||
static const HitMapInfo NoThreat;
|
||||
|
||||
uint64_t danger;
|
||||
uint8_t turn;
|
||||
|
@ -17,7 +17,7 @@
|
||||
namespace NKAI
|
||||
{
|
||||
|
||||
SecondarySkillEvaluator HeroManager::wariorSkillsScores = SecondarySkillEvaluator(
|
||||
const SecondarySkillEvaluator HeroManager::wariorSkillsScores = SecondarySkillEvaluator(
|
||||
{
|
||||
std::make_shared<SecondarySkillScoreMap>(
|
||||
std::map<SecondarySkill, float>
|
||||
@ -46,7 +46,7 @@ SecondarySkillEvaluator HeroManager::wariorSkillsScores = SecondarySkillEvaluato
|
||||
std::make_shared<AtLeastOneMagicRule>()
|
||||
});
|
||||
|
||||
SecondarySkillEvaluator HeroManager::scountSkillsScores = SecondarySkillEvaluator(
|
||||
const SecondarySkillEvaluator HeroManager::scountSkillsScores = SecondarySkillEvaluator(
|
||||
{
|
||||
std::make_shared<SecondarySkillScoreMap>(
|
||||
std::map<SecondarySkill, float>
|
||||
@ -332,7 +332,7 @@ void WisdomRule::evaluateScore(const CGHeroInstance * hero, SecondarySkill skill
|
||||
score += 1.5;
|
||||
}
|
||||
|
||||
std::vector<SecondarySkill> AtLeastOneMagicRule::magicSchools = {
|
||||
const std::vector<SecondarySkill> AtLeastOneMagicRule::magicSchools = {
|
||||
SecondarySkill::AIR_MAGIC,
|
||||
SecondarySkill::EARTH_MAGIC,
|
||||
SecondarySkill::FIRE_MAGIC,
|
||||
|
@ -58,8 +58,8 @@ public:
|
||||
class DLL_EXPORT HeroManager : public IHeroManager
|
||||
{
|
||||
private:
|
||||
static SecondarySkillEvaluator wariorSkillsScores;
|
||||
static SecondarySkillEvaluator scountSkillsScores;
|
||||
static const SecondarySkillEvaluator wariorSkillsScores;
|
||||
static const SecondarySkillEvaluator scountSkillsScores;
|
||||
|
||||
CCallback * cb; //this is enough, but we downcast from CCallback
|
||||
const Nullkiller * ai;
|
||||
@ -114,7 +114,7 @@ public:
|
||||
class AtLeastOneMagicRule : public ISecondarySkillRule
|
||||
{
|
||||
private:
|
||||
static std::vector<SecondarySkill> magicSchools;
|
||||
static const std::vector<SecondarySkill> magicSchools;
|
||||
|
||||
public:
|
||||
void evaluateScore(const CGHeroInstance * hero, SecondarySkill skill, float & score) const override;
|
||||
|
@ -332,7 +332,7 @@ std::vector<CGPathNode *> AINodeStorage::calculateNeighbours(
|
||||
return neighbours;
|
||||
}
|
||||
|
||||
EPathfindingLayer phisycalLayers[2] = {EPathfindingLayer::LAND, EPathfindingLayer::SAIL};
|
||||
constexpr std::array phisycalLayers = {EPathfindingLayer::LAND, EPathfindingLayer::SAIL};
|
||||
|
||||
bool AINodeStorage::increaseHeroChainTurnLimit()
|
||||
{
|
||||
@ -843,6 +843,7 @@ ExchangeCandidate HeroChainCalculationTask::calculateExchange(
|
||||
candidate.turns = carrierParentNode->turns;
|
||||
candidate.setCost(carrierParentNode->getCost() + otherParentNode->getCost() / 1000.0);
|
||||
candidate.moveRemains = carrierParentNode->moveRemains;
|
||||
candidate.danger = carrierParentNode->danger;
|
||||
|
||||
if(carrierParentNode->turns < otherParentNode->turns)
|
||||
{
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
using namespace NKAI;
|
||||
|
||||
CCreatureSet emptyArmy;
|
||||
const CCreatureSet emptyArmy;
|
||||
|
||||
bool HeroExchangeArmy::needsLastStack() const
|
||||
{
|
||||
|
@ -51,24 +51,24 @@ protected:
|
||||
|
||||
public:
|
||||
uint64_t chainMask;
|
||||
bool isMovable;
|
||||
bool allowUseResources;
|
||||
bool allowBattle;
|
||||
bool allowSpellCast;
|
||||
bool isMovable = false;
|
||||
bool allowUseResources = false;
|
||||
bool allowBattle = false;
|
||||
bool allowSpellCast = false;
|
||||
std::shared_ptr<SpecialAction> actorAction;
|
||||
const CGHeroInstance * hero;
|
||||
HeroRole heroRole;
|
||||
const CCreatureSet * creatureSet;
|
||||
const ChainActor * battleActor;
|
||||
const ChainActor * castActor;
|
||||
const ChainActor * resourceActor;
|
||||
const ChainActor * carrierParent;
|
||||
const ChainActor * otherParent;
|
||||
const ChainActor * baseActor;
|
||||
const CCreatureSet * creatureSet = nullptr;
|
||||
const ChainActor * battleActor = nullptr;
|
||||
const ChainActor * castActor = nullptr;
|
||||
const ChainActor * resourceActor = nullptr;
|
||||
const ChainActor * carrierParent = nullptr;
|
||||
const ChainActor * otherParent = nullptr;
|
||||
const ChainActor * baseActor = nullptr;
|
||||
int3 initialPosition;
|
||||
EPathfindingLayer layer;
|
||||
uint32_t initialMovement;
|
||||
uint32_t initialTurn;
|
||||
uint32_t initialMovement = 0;
|
||||
uint32_t initialTurn = 0;
|
||||
uint64_t armyValue;
|
||||
float heroFightingStrength;
|
||||
uint8_t actorExchangeCount;
|
||||
|
@ -14,7 +14,7 @@
|
||||
#define strcpy_s(a, b, c) strncpy(a, c, b)
|
||||
#endif
|
||||
|
||||
static const char * g_cszAiName = "Nullkiller";
|
||||
static const char * const g_cszAiName = "Nullkiller";
|
||||
|
||||
extern "C" DLL_EXPORT int GetGlobalAiVersion()
|
||||
{
|
||||
|
@ -16,7 +16,7 @@
|
||||
#define strcpy_s(a, b, c) strncpy(a, c, b)
|
||||
#endif
|
||||
|
||||
static const char *g_cszAiName = "Stupid AI 0.1";
|
||||
static const char * const g_cszAiName = "Stupid AI 0.1";
|
||||
|
||||
extern "C" DLL_EXPORT int GetGlobalAiVersion()
|
||||
{
|
||||
|
@ -148,7 +148,7 @@ BuildingID::DWELL_LVL_4_UP, BuildingID::DWELL_LVL_5_UP, BuildingID::DWELL_LVL_6_
|
||||
static const std::vector<BuildingID> unitGrowth = { BuildingID::HORDE_1, BuildingID::HORDE_1_UPGR, BuildingID::HORDE_2, BuildingID::HORDE_2_UPGR };
|
||||
static const std::vector<BuildingID> _spells = { BuildingID::MAGES_GUILD_1, BuildingID::MAGES_GUILD_2, BuildingID::MAGES_GUILD_3,
|
||||
BuildingID::MAGES_GUILD_4, BuildingID::MAGES_GUILD_5 };
|
||||
static const std::vector<BuildingID> extra = { BuildingID::MARKETPLACE, BuildingID::BLACKSMITH, BuildingID::RESOURCE_SILO, BuildingID::SPECIAL_1, BuildingID::SPECIAL_2,
|
||||
static const std::vector<BuildingID> extra = { BuildingID::MARKETPLACE, BuildingID::BLACKSMITH, BuildingID::RESOURCE_SILO, BuildingID::SPECIAL_1, BuildingID::SPECIAL_2,
|
||||
BuildingID::SPECIAL_3, BuildingID::SPECIAL_4, BuildingID::SHIPYARD }; // all remaining buildings
|
||||
|
||||
bool BuildingManager::getBuildingOptions(const CGTownInstance * t)
|
||||
|
@ -109,51 +109,52 @@ bool AbstractGoal::operator==(const AbstractGoal & g) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AbstractGoal::operator<(AbstractGoal & g) //for std::unique
|
||||
{
|
||||
//TODO: make sure it gets goals consistent with == operator
|
||||
if (goalType < g.goalType)
|
||||
return true;
|
||||
if (goalType > g.goalType)
|
||||
return false;
|
||||
if (hero < g.hero)
|
||||
return true;
|
||||
if (hero > g.hero)
|
||||
return false;
|
||||
if (tile < g.tile)
|
||||
return true;
|
||||
if (g.tile < tile)
|
||||
return false;
|
||||
if (objid < g.objid)
|
||||
return true;
|
||||
if (objid > g.objid)
|
||||
return false;
|
||||
if (town < g.town)
|
||||
return true;
|
||||
if (town > g.town)
|
||||
return false;
|
||||
if (value < g.value)
|
||||
return true;
|
||||
if (value > g.value)
|
||||
return false;
|
||||
if (priority < g.priority)
|
||||
return true;
|
||||
if (priority > g.priority)
|
||||
return false;
|
||||
if (resID < g.resID)
|
||||
return true;
|
||||
if (resID > g.resID)
|
||||
return false;
|
||||
if (bid < g.bid)
|
||||
return true;
|
||||
if (bid > g.bid)
|
||||
return false;
|
||||
if (aid < g.aid)
|
||||
return true;
|
||||
if (aid > g.aid)
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
// FIXME: unused code?
|
||||
//bool AbstractGoal::operator<(AbstractGoal & g) //for std::unique
|
||||
//{
|
||||
// //TODO: make sure it gets goals consistent with == operator
|
||||
// if (goalType < g.goalType)
|
||||
// return true;
|
||||
// if (goalType > g.goalType)
|
||||
// return false;
|
||||
// if (hero < g.hero)
|
||||
// return true;
|
||||
// if (hero > g.hero)
|
||||
// return false;
|
||||
// if (tile < g.tile)
|
||||
// return true;
|
||||
// if (g.tile < tile)
|
||||
// return false;
|
||||
// if (objid < g.objid)
|
||||
// return true;
|
||||
// if (objid > g.objid)
|
||||
// return false;
|
||||
// if (town < g.town)
|
||||
// return true;
|
||||
// if (town > g.town)
|
||||
// return false;
|
||||
// if (value < g.value)
|
||||
// return true;
|
||||
// if (value > g.value)
|
||||
// return false;
|
||||
// if (priority < g.priority)
|
||||
// return true;
|
||||
// if (priority > g.priority)
|
||||
// return false;
|
||||
// if (resID < g.resID)
|
||||
// return true;
|
||||
// if (resID > g.resID)
|
||||
// return false;
|
||||
// if (bid < g.bid)
|
||||
// return true;
|
||||
// if (bid > g.bid)
|
||||
// return false;
|
||||
// if (aid < g.aid)
|
||||
// return true;
|
||||
// if (aid > g.aid)
|
||||
// return false;
|
||||
// return false;
|
||||
//}
|
||||
|
||||
//TODO: find out why the following are not generated automatically on MVS?
|
||||
bool TSubgoal::operator==(const TSubgoal & rhs) const
|
||||
|
@ -165,16 +165,16 @@ namespace Goals
|
||||
virtual float accept(FuzzyHelper * f);
|
||||
|
||||
virtual bool operator==(const AbstractGoal & g) const;
|
||||
bool operator<(AbstractGoal & g); //final
|
||||
// bool operator<(AbstractGoal & g); //final
|
||||
virtual bool fulfillsMe(Goals::TSubgoal goal) //TODO: multimethod instead of type check
|
||||
{
|
||||
return false; //use this method to check if goal is fulfilled by another (not equal) goal, operator == is handled spearately
|
||||
}
|
||||
|
||||
bool operator!=(const AbstractGoal & g) const
|
||||
{
|
||||
return !(*this == g);
|
||||
}
|
||||
// bool operator!=(const AbstractGoal & g) const
|
||||
// {
|
||||
// return !(*this == g);
|
||||
// }
|
||||
|
||||
template<typename Handler> void serialize(Handler & h)
|
||||
{
|
||||
|
@ -14,7 +14,7 @@
|
||||
#define strcpy_s(a, b, c) strncpy(a, c, b)
|
||||
#endif
|
||||
|
||||
static const char * g_cszAiName = "VCAI";
|
||||
static const char * const g_cszAiName = "VCAI";
|
||||
|
||||
extern "C" DLL_EXPORT int GetGlobalAiVersion()
|
||||
{
|
||||
|
@ -56,7 +56,6 @@ namespace po = boost::program_options;
|
||||
namespace po_style = boost::program_options::command_line_style;
|
||||
|
||||
static std::atomic<bool> quitRequestedDuringOpeningPlayback = false;
|
||||
static po::variables_map vm;
|
||||
|
||||
#ifndef VCMI_IOS
|
||||
void processCommand(const std::string &message);
|
||||
@ -118,6 +117,8 @@ int main(int argc, char * argv[])
|
||||
#endif
|
||||
std::cout << "Starting... " << std::endl;
|
||||
po::options_description opts("Allowed options");
|
||||
po::variables_map vm;
|
||||
|
||||
opts.add_options()
|
||||
("help,h", "display help and exit")
|
||||
("version,v", "display version information and exit")
|
||||
@ -200,17 +201,17 @@ int main(int argc, char * argv[])
|
||||
preinitDLL(::console, false);
|
||||
|
||||
Settings session = settings.write["session"];
|
||||
auto setSettingBool = [](std::string key, std::string arg) {
|
||||
auto setSettingBool = [&](std::string key, std::string arg) {
|
||||
Settings s = settings.write(vstd::split(key, "/"));
|
||||
if(::vm.count(arg))
|
||||
if(vm.count(arg))
|
||||
s->Bool() = true;
|
||||
else if(s->isNull())
|
||||
s->Bool() = false;
|
||||
};
|
||||
auto setSettingInteger = [](std::string key, std::string arg, si64 defaultValue) {
|
||||
auto setSettingInteger = [&](std::string key, std::string arg, si64 defaultValue) {
|
||||
Settings s = settings.write(vstd::split(key, "/"));
|
||||
if(::vm.count(arg))
|
||||
s->Integer() = ::vm[arg].as<si64>();
|
||||
if(vm.count(arg))
|
||||
s->Integer() = vm[arg].as<si64>();
|
||||
else if(s->isNull())
|
||||
s->Integer() = defaultValue;
|
||||
};
|
||||
|
@ -30,7 +30,7 @@
|
||||
#define VCMI_SOUND_FILE(y) #y,
|
||||
|
||||
// sounds mapped to soundBase enum
|
||||
static std::string sounds[] = {
|
||||
static const std::string sounds[] = {
|
||||
"", // invalid
|
||||
"", // todo
|
||||
VCMI_SOUND_LIST
|
||||
|
@ -59,8 +59,8 @@ template<typename T> class CApplyOnCL;
|
||||
class CBaseForCLApply
|
||||
{
|
||||
public:
|
||||
virtual void applyOnClAfter(CClient * cl, void * pack) const =0;
|
||||
virtual void applyOnClBefore(CClient * cl, void * pack) const =0;
|
||||
virtual void applyOnClAfter(CClient * cl, CPack * pack) const =0;
|
||||
virtual void applyOnClBefore(CClient * cl, CPack * pack) const =0;
|
||||
virtual ~CBaseForCLApply(){}
|
||||
|
||||
template<typename U> static CBaseForCLApply * getApplier(const U * t = nullptr)
|
||||
@ -72,13 +72,13 @@ public:
|
||||
template<typename T> class CApplyOnCL : public CBaseForCLApply
|
||||
{
|
||||
public:
|
||||
void applyOnClAfter(CClient * cl, void * pack) const override
|
||||
void applyOnClAfter(CClient * cl, CPack * pack) const override
|
||||
{
|
||||
T * ptr = static_cast<T *>(pack);
|
||||
ApplyClientNetPackVisitor visitor(*cl, *cl->gameState());
|
||||
ptr->visit(visitor);
|
||||
}
|
||||
void applyOnClBefore(CClient * cl, void * pack) const override
|
||||
void applyOnClBefore(CClient * cl, CPack * pack) const override
|
||||
{
|
||||
T * ptr = static_cast<T *>(pack);
|
||||
ApplyFirstClientNetPackVisitor visitor(*cl, *cl->gameState());
|
||||
@ -89,12 +89,12 @@ public:
|
||||
template<> class CApplyOnCL<CPack>: public CBaseForCLApply
|
||||
{
|
||||
public:
|
||||
void applyOnClAfter(CClient * cl, void * pack) const override
|
||||
void applyOnClAfter(CClient * cl, CPack * pack) const override
|
||||
{
|
||||
logGlobal->error("Cannot apply on CL plain CPack!");
|
||||
assert(0);
|
||||
}
|
||||
void applyOnClBefore(CClient * cl, void * pack) const override
|
||||
void applyOnClBefore(CClient * cl, CPack * pack) const override
|
||||
{
|
||||
logGlobal->error("Cannot apply on CL plain CPack!");
|
||||
assert(0);
|
||||
@ -537,7 +537,7 @@ void CClient::handlePack(CPack * pack)
|
||||
|
||||
int CClient::sendRequest(const CPackForServer * request, PlayerColor player)
|
||||
{
|
||||
static ui32 requestCounter = 0;
|
||||
static ui32 requestCounter = 1;
|
||||
|
||||
ui32 requestID = requestCounter++;
|
||||
logNetwork->trace("Sending a request \"%s\". It'll have an ID=%d.", typeid(*request).name(), requestID);
|
||||
|
@ -304,7 +304,7 @@ void InputHandler::dispatchMainThread(const std::function<void()> & functor)
|
||||
auto heapFunctor = new std::function<void()>(functor);
|
||||
|
||||
SDL_Event event;
|
||||
event.type = SDL_USEREVENT;
|
||||
event.user.type = SDL_USEREVENT;
|
||||
event.user.code = 0;
|
||||
event.user.data1 = static_cast <void*>(heapFunctor);
|
||||
event.user.data2 = nullptr;
|
||||
|
@ -191,7 +191,7 @@ void CGuiHandler::drawFPSCounter()
|
||||
int y = screen->h-20;
|
||||
int width3digitFPSIncludingPadding = 48;
|
||||
int heightFPSTextIncludingPadding = 11;
|
||||
static SDL_Rect overlay = { x, y, width3digitFPSIncludingPadding, heightFPSTextIncludingPadding};
|
||||
SDL_Rect overlay = { x, y, width3digitFPSIncludingPadding, heightFPSTextIncludingPadding};
|
||||
uint32_t black = SDL_MapRGB(screen->format, 10, 10, 10);
|
||||
SDL_FillRect(screen, &overlay, black);
|
||||
|
||||
|
@ -137,7 +137,7 @@ void CBonusSelection::createBonusesIcons()
|
||||
const std::vector<CampaignBonus> & bonDescs = scenario.travelOptions.bonusesToChoose;
|
||||
groupBonuses = std::make_shared<CToggleGroup>(std::bind(&IServerAPI::setCampaignBonus, CSH, _1));
|
||||
|
||||
static const char * bonusPics[] =
|
||||
constexpr std::array bonusPics =
|
||||
{
|
||||
"SPELLBON.DEF", // Spell
|
||||
"TWCRPORT.DEF", // Monster
|
||||
|
@ -154,7 +154,7 @@ InfoCard::InfoCard()
|
||||
|
||||
iconDifficulty = std::make_shared<CToggleGroup>(0);
|
||||
{
|
||||
static const char * difButns[] = {"GSPBUT3.DEF", "GSPBUT4.DEF", "GSPBUT5.DEF", "GSPBUT6.DEF", "GSPBUT7.DEF"};
|
||||
constexpr std::array difButns = {"GSPBUT3.DEF", "GSPBUT4.DEF", "GSPBUT5.DEF", "GSPBUT6.DEF", "GSPBUT7.DEF"};
|
||||
|
||||
for(int i = 0; i < 5; i++)
|
||||
{
|
||||
|
@ -278,9 +278,9 @@ CMainMenuConfig::CMainMenuConfig()
|
||||
|
||||
}
|
||||
|
||||
CMainMenuConfig & CMainMenuConfig::get()
|
||||
const CMainMenuConfig & CMainMenuConfig::get()
|
||||
{
|
||||
static CMainMenuConfig config;
|
||||
static const CMainMenuConfig config;
|
||||
return config;
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ public:
|
||||
class CMainMenuConfig
|
||||
{
|
||||
public:
|
||||
static CMainMenuConfig & get();
|
||||
static const CMainMenuConfig & get();
|
||||
const JsonNode & getConfig() const;
|
||||
const JsonNode & getCampaigns() const;
|
||||
|
||||
|
@ -157,11 +157,11 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(const ImagePath & path)
|
||||
ret->format->palette->colors[0].g == 0 &&
|
||||
ret->format->palette->colors[0].b == 255 )
|
||||
{
|
||||
static SDL_Color shadow[3] =
|
||||
constexpr std::array shadow =
|
||||
{
|
||||
{ 0, 0, 0, 0},// 100% - transparency
|
||||
{ 0, 0, 0, 32},// 75% - shadow border,
|
||||
{ 0, 0, 0, 128},// 50% - shadow body
|
||||
SDL_Color{ 0, 0, 0, 0},// 100% - transparency
|
||||
SDL_Color{ 0, 0, 0, 32},// 75% - shadow border,
|
||||
SDL_Color{ 0, 0, 0, 128},// 50% - shadow body
|
||||
};
|
||||
|
||||
CSDL_Ext::setColorKey(ret, ret->format->palette->colors[0]);
|
||||
|
@ -562,27 +562,6 @@ void HeroSlots::swapArmies()
|
||||
LOCPLINT->cb->swapGarrisonHero(town);
|
||||
}
|
||||
|
||||
class SORTHELP
|
||||
{
|
||||
public:
|
||||
bool operator() (const CIntObject * a, const CIntObject * b)
|
||||
{
|
||||
auto b1 = dynamic_cast<const CBuildingRect *>(a);
|
||||
auto b2 = dynamic_cast<const CBuildingRect *>(b);
|
||||
|
||||
if(!b1 && !b2)
|
||||
return intptr_t(a) < intptr_t(b);
|
||||
if(b1 && !b2)
|
||||
return false;
|
||||
if(!b1 && b2)
|
||||
return true;
|
||||
|
||||
return (*b1)<(*b2);
|
||||
}
|
||||
};
|
||||
|
||||
SORTHELP buildSorter;
|
||||
|
||||
CCastleBuildings::CCastleBuildings(const CGTownInstance* Town):
|
||||
town(Town),
|
||||
selectedBuilding(nullptr)
|
||||
@ -650,6 +629,21 @@ void CCastleBuildings::recreate()
|
||||
buildings.push_back(std::make_shared<CBuildingRect>(this, town, toAdd));
|
||||
}
|
||||
|
||||
auto const & buildSorter = [] (const CIntObject * a, const CIntObject * b)
|
||||
{
|
||||
auto b1 = dynamic_cast<const CBuildingRect *>(a);
|
||||
auto b2 = dynamic_cast<const CBuildingRect *>(b);
|
||||
|
||||
if(!b1 && !b2)
|
||||
return intptr_t(a) < intptr_t(b);
|
||||
if(b1 && !b2)
|
||||
return false;
|
||||
if(!b1 && b2)
|
||||
return true;
|
||||
|
||||
return (*b1)<(*b2);
|
||||
};
|
||||
|
||||
boost::sort(children, buildSorter); //TODO: create building in blit order
|
||||
}
|
||||
|
||||
@ -1427,11 +1421,11 @@ CHallInterface::CBuildingBox::CBuildingBox(int x, int y, const CGTownInstance *
|
||||
|
||||
state = LOCPLINT->cb->canBuildStructure(town, building->bid);
|
||||
|
||||
static int panelIndex[12] =
|
||||
constexpr std::array panelIndex =
|
||||
{
|
||||
3, 3, 3, 0, 0, 2, 2, 1, 2, 2, 3, 3
|
||||
};
|
||||
static int iconIndex[12] =
|
||||
constexpr std::array iconIndex =
|
||||
{
|
||||
-1, -1, -1, 0, 0, 1, 2, -1, 1, 1, -1, -1
|
||||
};
|
||||
|
@ -76,7 +76,7 @@ void CPuzzleWindow::showAll(Canvas & to)
|
||||
|
||||
void CPuzzleWindow::show(Canvas & to)
|
||||
{
|
||||
static int animSpeed = 2;
|
||||
constexpr int animSpeed = 2;
|
||||
|
||||
if(currentAlpha < animSpeed)
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ public:
|
||||
|
||||
return A->getNameTranslated() < B->getNameTranslated();
|
||||
}
|
||||
} spellsorter;
|
||||
};
|
||||
|
||||
CSpellWindow::CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _myInt, bool openOnBattleSpells):
|
||||
CWindowObject(PLAYER_COLORED | (settings["gameTweaks"]["enableLargeSpellbook"].Bool() ? BORDERED : 0)),
|
||||
@ -293,6 +293,8 @@ void CSpellWindow::processSpells()
|
||||
if(!spell->isCreatureAbility() && myHero->canCastThisSpell(spell) && searchTextFound)
|
||||
mySpells.push_back(spell);
|
||||
}
|
||||
|
||||
SpellbookSpellSorter spellsorter;
|
||||
std::sort(mySpells.begin(), mySpells.end(), spellsorter);
|
||||
|
||||
//initializing sizes of spellbook's parts
|
||||
|
@ -1558,7 +1558,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner):
|
||||
|
||||
//data for information table:
|
||||
// fields[row][column] = list of id's of players for this box
|
||||
static std::vector< std::vector< PlayerColor > > SThievesGuildInfo::* fields[] =
|
||||
constexpr std::vector< std::vector< PlayerColor > > SThievesGuildInfo::* fields[] =
|
||||
{ &SThievesGuildInfo::numOfTowns, &SThievesGuildInfo::numOfHeroes, &SThievesGuildInfo::gold,
|
||||
&SThievesGuildInfo::woodOre, &SThievesGuildInfo::mercSulfCrystGems, &SThievesGuildInfo::obelisks,
|
||||
&SThievesGuildInfo::artifacts, &SThievesGuildInfo::army, &SThievesGuildInfo::income };
|
||||
|
@ -54,9 +54,7 @@ CDownloadManager::FileEntry & CDownloadManager::getEntry(QNetworkReply * reply)
|
||||
if(entry.reply == reply)
|
||||
return entry;
|
||||
}
|
||||
assert(0);
|
||||
static FileEntry errorValue;
|
||||
return errorValue;
|
||||
throw std::runtime_error("Failed to find download entry");
|
||||
}
|
||||
|
||||
void CDownloadManager::downloadFinished(QNetworkReply * reply)
|
||||
|
@ -38,7 +38,7 @@ QString CModListModel::modIndexToName(const QModelIndex & index) const
|
||||
|
||||
QString CModListModel::modTypeName(QString modTypeID) const
|
||||
{
|
||||
static QMap<QString, QString> modTypes = {
|
||||
static const QMap<QString, QString> modTypes = {
|
||||
{"Translation", tr("Translation")},
|
||||
{"Town", tr("Town") },
|
||||
{"Test", tr("Test") },
|
||||
|
@ -96,7 +96,7 @@ void UpdateDialog::loadFromJson(const JsonNode & node)
|
||||
node["updateType"].getType() != JsonNode::JsonType::DATA_STRING ||
|
||||
node["version"].getType() != JsonNode::JsonType::DATA_STRING ||
|
||||
node["changeLog"].getType() != JsonNode::JsonType::DATA_STRING ||
|
||||
node.getType() != JsonNode::JsonType::DATA_STRUCT) //we need at least one link - other are optional
|
||||
node["downloadLinks"].getType() != JsonNode::JsonType::DATA_STRUCT) //we need at least one link - other are optional
|
||||
{
|
||||
ui->plainTextEdit->setPlainText("Cannot read JSON from url or incorrect JSON data");
|
||||
return;
|
||||
|
@ -502,7 +502,7 @@ CGeneralTextHandler::CGeneralTextHandler():
|
||||
readToVector("core.mineevnt", "DATA/MINEEVNT.TXT" );
|
||||
readToVector("core.xtrainfo", "DATA/XTRAINFO.TXT" );
|
||||
|
||||
static const char * QE_MOD_COMMANDS = "DATA/QECOMMANDS.TXT";
|
||||
static const std::string QE_MOD_COMMANDS = "DATA/QECOMMANDS.TXT";
|
||||
if (CResourceHandler::get()->existsResource(TextPath::builtin(QE_MOD_COMMANDS)))
|
||||
readToVector("vcmi.quickExchange", QE_MOD_COMMANDS);
|
||||
|
||||
|
@ -1259,7 +1259,7 @@ namespace Validation
|
||||
|
||||
const TFormatMap & getKnownFormats()
|
||||
{
|
||||
static TFormatMap knownFormats = createFormatMap();
|
||||
static const TFormatMap knownFormats = createFormatMap();
|
||||
return knownFormats;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ namespace vstd
|
||||
|
||||
explicit ScopeGuard(Func && f):
|
||||
fire(true),
|
||||
f(std::forward<Func>(f))
|
||||
f(std::move(f))
|
||||
{}
|
||||
~ScopeGuard()
|
||||
{
|
||||
|
@ -443,7 +443,7 @@ BattleInfo * BattleInfo::setupBattle(const int3 & tile, TerrainId terrain, const
|
||||
}
|
||||
|
||||
//native terrain bonuses
|
||||
static auto nativeTerrain = std::make_shared<CreatureTerrainLimiter>();
|
||||
auto nativeTerrain = std::make_shared<CreatureTerrainLimiter>();
|
||||
|
||||
curB->addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::STACKS_SPEED, BonusSource::TERRAIN_NATIVE, 1, BonusSourceID())->addLimiter(nativeTerrain));
|
||||
curB->addNewBonus(std::make_shared<Bonus>(BonusDuration::ONE_BATTLE, BonusType::PRIMARY_SKILL, BonusSource::TERRAIN_NATIVE, 1, BonusSourceID(), BonusSubtypeID(PrimarySkill::ATTACK))->addLimiter(nativeTerrain));
|
||||
|
@ -59,7 +59,7 @@ template <typename T> class CApplyOnGS;
|
||||
class CBaseForGSApply
|
||||
{
|
||||
public:
|
||||
virtual void applyOnGS(CGameState *gs, void *pack) const =0;
|
||||
virtual void applyOnGS(CGameState *gs, CPack * pack) const =0;
|
||||
virtual ~CBaseForGSApply() = default;
|
||||
template<typename U> static CBaseForGSApply *getApplier(const U * t=nullptr)
|
||||
{
|
||||
@ -70,7 +70,7 @@ public:
|
||||
template <typename T> class CApplyOnGS : public CBaseForGSApply
|
||||
{
|
||||
public:
|
||||
void applyOnGS(CGameState *gs, void *pack) const override
|
||||
void applyOnGS(CGameState *gs, CPack * pack) const override
|
||||
{
|
||||
T *ptr = static_cast<T*>(pack);
|
||||
|
||||
|
22
lib/int3.h
22
lib/int3.h
@ -84,19 +84,13 @@ public:
|
||||
|
||||
constexpr bool operator<(const int3 & i) const
|
||||
{
|
||||
if (z < i.z)
|
||||
return true;
|
||||
if (z > i.z)
|
||||
return false;
|
||||
if (y < i.y)
|
||||
return true;
|
||||
if (y > i.y)
|
||||
return false;
|
||||
if (x < i.x)
|
||||
return true;
|
||||
if (x > i.x)
|
||||
return false;
|
||||
return false;
|
||||
if (z != i.z)
|
||||
return z < i.z;
|
||||
|
||||
if (y != i.y)
|
||||
return y < i.y;
|
||||
|
||||
return x < i.x;
|
||||
}
|
||||
|
||||
enum EDistanceFormula
|
||||
@ -224,4 +218,4 @@ struct std::hash<VCMI_LIB_WRAP_NAMESPACE(int3)> {
|
||||
std::size_t operator()(VCMI_LIB_WRAP_NAMESPACE(int3) const& pos) const noexcept {
|
||||
return hash_value(pos);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -64,7 +64,7 @@ struct DLL_LINKAGE Query : public CPackForClient
|
||||
struct DLL_LINKAGE CPackForServer : public CPack
|
||||
{
|
||||
mutable PlayerColor player = PlayerColor::NEUTRAL;
|
||||
mutable si32 requestID;
|
||||
mutable uint32_t requestID = 0;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
{
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
std::function<bool(const int3 &)> AREA_NO_FILTER = [](const int3 & t)
|
||||
const std::function<bool(const int3 &)> AREA_NO_FILTER = [](const int3 & t)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
@ -30,7 +30,7 @@ class CMapGenerator;
|
||||
class Modificator;
|
||||
class CRandomGenerator;
|
||||
|
||||
extern std::function<bool(const int3 &)> AREA_NO_FILTER;
|
||||
extern const std::function<bool(const int3 &)> AREA_NO_FILTER;
|
||||
|
||||
typedef std::list<std::shared_ptr<Modificator>> TModificators;
|
||||
|
||||
|
@ -126,12 +126,8 @@ public:
|
||||
return true;
|
||||
if (y>i.y)
|
||||
return false;
|
||||
if (x<i.x)
|
||||
return true;
|
||||
if (x>i.x)
|
||||
return false;
|
||||
|
||||
return false;
|
||||
return x<i.x;
|
||||
}
|
||||
|
||||
std::string toString() const
|
||||
|
@ -161,7 +161,7 @@ DefFile::DefFile(std::string Name):
|
||||
#endif // 0
|
||||
|
||||
//First 8 colors in def palette used for transparency
|
||||
static QRgb H3Palette[8] =
|
||||
constexpr std::array H3Palette =
|
||||
{
|
||||
qRgba(0, 0, 0, 0), // 100% - transparency
|
||||
qRgba(0, 0, 0, 32), // 75% - shadow border,
|
||||
|
@ -17,7 +17,7 @@
|
||||
#define strcpy_s(a, b, c) strncpy(a, c, b)
|
||||
#endif
|
||||
|
||||
static const char *g_cszAiName = "Lua interpreter";
|
||||
static const char * const g_cszAiName = "Lua interpreter";
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
|
@ -82,7 +82,7 @@ template <typename T> class CApplyOnGH;
|
||||
class CBaseForGHApply
|
||||
{
|
||||
public:
|
||||
virtual bool applyOnGH(CGameHandler * gh, CGameState * gs, void * pack) const =0;
|
||||
virtual bool applyOnGH(CGameHandler * gh, CGameState * gs, CPack * pack) const =0;
|
||||
virtual ~CBaseForGHApply(){}
|
||||
template<typename U> static CBaseForGHApply *getApplier(const U * t=nullptr)
|
||||
{
|
||||
@ -93,7 +93,7 @@ public:
|
||||
template <typename T> class CApplyOnGH : public CBaseForGHApply
|
||||
{
|
||||
public:
|
||||
bool applyOnGH(CGameHandler * gh, CGameState * gs, void * pack) const override
|
||||
bool applyOnGH(CGameHandler * gh, CGameState * gs, CPack * pack) const override
|
||||
{
|
||||
T *ptr = static_cast<T*>(pack);
|
||||
try
|
||||
@ -116,7 +116,7 @@ template <>
|
||||
class CApplyOnGH<CPack> : public CBaseForGHApply
|
||||
{
|
||||
public:
|
||||
bool applyOnGH(CGameHandler * gh, CGameState * gs, void * pack) const override
|
||||
bool applyOnGH(CGameHandler * gh, CGameState * gs, CPack * pack) const override
|
||||
{
|
||||
logGlobal->error("Cannot apply on GH plain CPack!");
|
||||
assert(0);
|
||||
|
@ -31,8 +31,8 @@ template<typename T> class CApplyOnServer;
|
||||
class CBaseForServerApply
|
||||
{
|
||||
public:
|
||||
virtual bool applyOnServerBefore(CVCMIServer * srv, void * pack) const =0;
|
||||
virtual void applyOnServerAfter(CVCMIServer * srv, void * pack) const =0;
|
||||
virtual bool applyOnServerBefore(CVCMIServer * srv, CPack * pack) const =0;
|
||||
virtual void applyOnServerAfter(CVCMIServer * srv, CPack * pack) const =0;
|
||||
virtual ~CBaseForServerApply() {}
|
||||
template<typename U> static CBaseForServerApply * getApplier(const U * t = nullptr)
|
||||
{
|
||||
@ -43,7 +43,7 @@ public:
|
||||
template <typename T> class CApplyOnServer : public CBaseForServerApply
|
||||
{
|
||||
public:
|
||||
bool applyOnServerBefore(CVCMIServer * srv, void * pack) const override
|
||||
bool applyOnServerBefore(CVCMIServer * srv, CPack * pack) const override
|
||||
{
|
||||
T * ptr = static_cast<T *>(pack);
|
||||
ClientPermissionsCheckerNetPackVisitor checker(*srv);
|
||||
@ -59,7 +59,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
void applyOnServerAfter(CVCMIServer * srv, void * pack) const override
|
||||
void applyOnServerAfter(CVCMIServer * srv, CPack * pack) const override
|
||||
{
|
||||
T * ptr = static_cast<T *>(pack);
|
||||
ApplyOnServerAfterAnnounceNetPackVisitor applier(*srv);
|
||||
@ -71,13 +71,13 @@ template <>
|
||||
class CApplyOnServer<CPack> : public CBaseForServerApply
|
||||
{
|
||||
public:
|
||||
bool applyOnServerBefore(CVCMIServer * srv, void * pack) const override
|
||||
bool applyOnServerBefore(CVCMIServer * srv, CPack * pack) const override
|
||||
{
|
||||
logGlobal->error("Cannot apply plain CPack!");
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
void applyOnServerAfter(CVCMIServer * srv, void * pack) const override
|
||||
void applyOnServerAfter(CVCMIServer * srv, CPack * pack) const override
|
||||
{
|
||||
logGlobal->error("Cannot apply plain CPack!");
|
||||
assert(0);
|
||||
|
@ -1573,8 +1573,11 @@ bool BattleActionProcessor::makePlayerBattleAction(const CBattleInfoCallback & b
|
||||
else
|
||||
{
|
||||
auto active = battle.battleActiveUnit();
|
||||
if(!active && gameHandler->complain("No active unit in battle!"))
|
||||
if(!active)
|
||||
{
|
||||
gameHandler->complain("No active unit in battle!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ba.isUnitAction() && ba.stackNumber != active->unitId())
|
||||
{
|
||||
@ -1584,8 +1587,11 @@ bool BattleActionProcessor::makePlayerBattleAction(const CBattleInfoCallback & b
|
||||
|
||||
auto unitOwner = battle.battleGetOwner(active);
|
||||
|
||||
if(player != unitOwner && gameHandler->complain("Can not make actions in battles you are not part of!"))
|
||||
if(player != unitOwner)
|
||||
{
|
||||
gameHandler->complain("Can not make actions in battles you are not part of!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return makeBattleActionImpl(battle, ba);
|
||||
|
Loading…
Reference in New Issue
Block a user