From a138db7c9eb87f5ae512299a29a5a85fbc435288 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Thu, 6 Sep 2012 10:39:48 +0000 Subject: [PATCH] - removed lib headers from PCH - fixed #1062 - correct terrain penalty check --- AI/VCAI/Fuzzy.cpp | 5 +- AI/VCAI/StdInc.h | 18 ----- AI/VCAI/VCAI.cpp | 3 + AI/VCAI/VCAI.h | 22 ++++++ client/UIFramework/CIntObjectClasses.cpp | 3 +- lib/CObjectHandler.cpp | 85 +++++++++--------------- lib/IGameCallback.cpp | 12 ++-- 7 files changed, 65 insertions(+), 83 deletions(-) diff --git a/AI/VCAI/Fuzzy.cpp b/AI/VCAI/Fuzzy.cpp index 77fd02c89..47b36bd4f 100644 --- a/AI/VCAI/Fuzzy.cpp +++ b/AI/VCAI/Fuzzy.cpp @@ -1,7 +1,10 @@ #include "StdInc.h" #include "Fuzzy.h" #include -//#include "../../lib/CObjectHandler.h" + +#include "../../lib/CObjectHandler.h" +#include "../../lib/CCreatureHandler.h" +#include "../../lib/VCMI_Lib.h" /* * Fuzzy.cpp, part of VCMI engine diff --git a/AI/VCAI/StdInc.h b/AI/VCAI/StdInc.h index 008993c65..b4f34cfd2 100644 --- a/AI/VCAI/StdInc.h +++ b/AI/VCAI/StdInc.h @@ -5,27 +5,10 @@ #include #include #include -#include "../../lib/AI_Base.h" -#include "../../CCallback.h" -#include "../../lib/CObjectHandler.h" #include -#include "../../lib/CThreadHelper.h" #include -#include "../../lib/VCMI_Lib.h" -#include "../../lib/CBuildingHandler.h" -#include "../../lib/CCreatureHandler.h" -#include "../../lib/CTownHandler.h" -#include "../../lib/CSpellHandler.h" -#include "../../lib/CObjectHandler.h" -#include "../../lib/Connection.h" -#include "../../lib/CGameState.h" -#include "../../lib/map.h" -#include "../../lib/NetPacks.h" -#include "../../lib/CondSh.h" -#include "../../lib/CStopWatch.h" - #include "Fuzzy.h" #include @@ -34,7 +17,6 @@ using boost::format; using boost::str; - extern CLogger &aiLogger; #define INDENT AILogger::Tab ___dummy_ind diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 83b4e2f06..4dc842862 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -1233,6 +1233,9 @@ void VCAI::recruitCreatures(const CGDwelling * d) bool VCAI::tryBuildStructure(const CGTownInstance * t, int building, unsigned int maxDays) { + if (!vstd::contains(t->town->buildings, building)) + return false; // no such building in town + if (t->hasBuilt(building)) //Already built? Shouldn't happen in general return true; diff --git a/AI/VCAI/VCAI.h b/AI/VCAI/VCAI.h index 75645cb22..97dbda50e 100644 --- a/AI/VCAI/VCAI.h +++ b/AI/VCAI/VCAI.h @@ -1,4 +1,26 @@ #pragma once + +#include "../../lib/AI_Base.h" +#include "../../CCallback.h" +#include "../../lib/CObjectHandler.h" + +#include "../../lib/CThreadHelper.h" + +#include "../../lib/VCMI_Lib.h" +#include "../../lib/CBuildingHandler.h" +#include "../../lib/CCreatureHandler.h" +#include "../../lib/CTownHandler.h" +#include "../../lib/CSpellHandler.h" +#include "../../lib/CObjectHandler.h" +#include "../../lib/Connection.h" +#include "../../lib/CGameState.h" +#include "../../lib/map.h" +#include "../../lib/NetPacks.h" +#include "../../lib/CondSh.h" +#include "../../lib/CStopWatch.h" + +struct QuestInfo; + typedef const int3& crint3; typedef const std::string& crstring; diff --git a/client/UIFramework/CIntObjectClasses.cpp b/client/UIFramework/CIntObjectClasses.cpp index 14a54dc40..6bbd49b92 100644 --- a/client/UIFramework/CIntObjectClasses.cpp +++ b/client/UIFramework/CIntObjectClasses.cpp @@ -527,8 +527,7 @@ void CHighlightableButtonsGroup::addButton(const std::map &tool CHighlightableButton *bt = new CHighlightableButton(OnSelect, 0, tooltip, HelpBox, false, defName, 0, x, y, key); if(musicLike) { - if (buttons.size() > 3) - bt->setOffset(buttons.size()-3); + bt->setOffset(buttons.size()-3); } bt->ID = uid; bt->callback += boost::bind(&CHighlightableButtonsGroup::selectionChanged,this,bt->ID); diff --git a/lib/CObjectHandler.cpp b/lib/CObjectHandler.cpp index 0ae9b4a79..32f3c5d3a 100644 --- a/lib/CObjectHandler.cpp +++ b/lib/CObjectHandler.cpp @@ -526,8 +526,6 @@ static int lowestSpeed(const CGHeroInstance * chi) ui32 CGHeroInstance::getTileCost(const TerrainTile &dest, const TerrainTile &from) const { - //TODO: check if all creatures are on its native terrain and change cost appropriately - //base move cost unsigned ret = 100; @@ -553,30 +551,30 @@ ui32 CGHeroInstance::getTileCost(const TerrainTile &dest, const TerrainTile &fro } else { - assert(vstd::contains(VLC->townh->factions, type->heroType / 2)); - if (VLC->townh->factions[type->heroType / 2].nativeTerrain != from.tertype) //non-native terrain - ret = VLC->heroh->terrCosts[from.tertype]; + //FIXME: in H3 presence of Nomad in army will remove terrain penalty for sand. Bonus not implemented in VCMI - ret = std::max(ret - 25*unsigned(getSecSkillLevel(CGHeroInstance::PATHFINDING)), 100u); //reduce 25% of terrain penalty for each pathfinding level - } + // NOTE: in H3 neutral stacks will ignore terrain penalty only if placed as topmost stack(s) in hero army. + // This is clearly bug in H3 however intended behaviour is not clear. + // Current VCMI behaviour will ignore neutrals in calculations so army in VCMI + // will always have best penalty without any influence from player-defined stacks order + + bool nativeArmy = true; + BOOST_FOREACH(auto stack, stacks) + { + int nativeTerrain = VLC->townh->factions[stack.second->type->faction].nativeTerrain; + + if (nativeTerrain != -1 && nativeTerrain != from.tertype) + { + nativeArmy = false; + break; + } + } + if (!nativeArmy) + ret = VLC->heroh->terrCosts[from.tertype]; + } return ret; } -#if 0 -// Unused and buggy method. -// - for loop is wrong. will not find all creatures. must use iterator instead. -// - -> is the slot number. use second->first for creature index -// Is lowestSpeed() the correct equivalent ? -ui32 CGHeroInstance::getLowestCreatureSpeed() const -{ - ui32 sl = 100; - for(size_t h=0; h < stacksCount(); ++h) - { - if(VLC->creh->creatures[Slots().find(h)->first]->speedcreh->creatures[Slots().find(h)->first]->speed; - } - return sl; -} -#endif + int3 CGHeroInstance::convertPosition(int3 src, bool toh3m) //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest { if (toh3m) @@ -646,14 +644,17 @@ void CGHeroInstance::setSecSkillLevel(SecondarySkill which, int val, bool abs) int CGHeroInstance::maxMovePoints(bool onLand) const { - int base = -1; + int base; + if(onLand) { - static const int moveForSpeed[] = { 1500, 1560, 1630, 1700, 1760, 1830, 1900, 1960, 2000 }; //first element for 3 and lower; last for 11 and more - int index = lowestSpeed(this) - 3; - vstd::amin(index, ARRAY_COUNT(moveForSpeed)-1); - vstd::amax(index, 0); - base = moveForSpeed[index]; + // used function is f(x) = 66.6x + 1300, rounded to second digit, where x is lowest speed in army + static const int baseSpeed = 1300; // base speed from creature with 0 speed + + int armySpeed = lowestSpeed(this) * 20 / 3; + + base = armySpeed * 10 + baseSpeed; // separate *10 is intentional to receive same rounding as in h3 + vstd::abetween(base, 1500, 2000); // base speed is limited by these values } else { @@ -674,32 +675,6 @@ int CGHeroInstance::maxMovePoints(bool onLand) const return int(base + base*modifier) + bonus; } -// int CGHeroInstance::getSpellSecLevel(int spell) const -// { -// int bestslvl = 0; -// if(VLC->spellh->spells[spell].air) -// if(getSecSkillLevel(15) >= bestslvl) -// { -// bestslvl = getSecSkillLevel(15); -// } -// if(VLC->spellh->spells[spell].fire) -// if(getSecSkillLevel(14) >= bestslvl) -// { -// bestslvl = getSecSkillLevel(14); -// } -// if(VLC->spellh->spells[spell].water) -// if(getSecSkillLevel(16) >= bestslvl) -// { -// bestslvl = getSecSkillLevel(16); -// } -// if(VLC->spellh->spells[spell].earth) -// if(getSecSkillLevel(17) >= bestslvl) -// { -// bestslvl = getSecSkillLevel(17); -// } -// return bestslvl; -// } - CGHeroInstance::CGHeroInstance() : IBoatGenerator(this) { diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index 72e37c3d4..00fc4f4b4 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -181,13 +181,11 @@ bool CGameInfoCallback::isAllowed( int type, int id ) void CPrivilagedInfoCallback::pickAllowedArtsSet(std::vector &out) { - for (int i = 0; i < 2; i++) - { - for (int j = 0; j < 3 ; j++) - { - out.push_back(VLC->arth->artifacts[getRandomArt(CArtifact::ART_TREASURE << i)]); - } - } + for (int j = 0; j < 3 ; j++) + out.push_back(VLC->arth->artifacts[getRandomArt(CArtifact::ART_TREASURE)]); + for (int j = 0; j < 3 ; j++) + out.push_back(VLC->arth->artifacts[getRandomArt(CArtifact::ART_MINOR)]); + out.push_back(VLC->arth->artifacts[getRandomArt(CArtifact::ART_MAJOR)]); }