From 1cac0832394cff03a216dbcd97be14d024a2d0d2 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Tue, 30 Jun 2009 12:28:22 +0000 Subject: [PATCH] * added native terrain bonuses in battles * number of units in stack in battle should now fit the box * non-living and undead creatures have now always 0 morale --- client/CBattleInterface.cpp | 4 +--- client/SDL_Extensions.h | 6 ------ config/native_terrains.txt | 11 +++++++++++ hch/CHeroHandler.cpp | 31 +++++++++++++++++++++++++++++++ hch/CHeroHandler.h | 2 ++ lib/CGameState.cpp | 7 +++++-- lib/StackFeature.h | 3 ++- server/CGameHandler.cpp | 12 ++++++++++++ 8 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 config/native_terrains.txt diff --git a/client/CBattleInterface.cpp b/client/CBattleInterface.cpp index e012a7c81..31d5582fb 100644 --- a/client/CBattleInterface.cpp +++ b/client/CBattleInterface.cpp @@ -585,10 +585,8 @@ void CBattleInterface::show(SDL_Surface * to) } SDL_BlitSurface(amountBG, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[curStackID]->pos.x + xAdd + pos.x, creAnims[curStackID]->pos.y + 260 + pos.y)); //blitting amount - std::ostringstream ss; - ss<pos.x + xAdd + 14 + pos.x, creAnims[curStackID]->pos.y + 260 + 4 + pos.y, GEOR13, diff --git a/client/SDL_Extensions.h b/client/SDL_Extensions.h index 92da0b790..0dc4a1f89 100644 --- a/client/SDL_Extensions.h +++ b/client/SDL_Extensions.h @@ -6,8 +6,6 @@ #include "../int3.h" #include #include -#include -#include /* * SDL_Extensions.h, part of VCMI engine @@ -32,10 +30,6 @@ bool isItIn(const SDL_Rect * rect, int x, int y); template std::string makeNumberShort(IntType number) //the output is a string containing at most 5 characters [4 if positive] (eg. intead 10000 it gives 10k) { -#if BOOST_VERSION >= 103800 - BOOST_MPL_ASSERT_MSG( boost::is_integral::value, NON_INTEGRAL_TYPES_ARE_NOT_ALLOWED, (IntType) ); //it should make noise if IntType is not integral type -#endif - int initialLength; bool negative = (number < 0); std::ostringstream ost, rets; diff --git a/config/native_terrains.txt b/config/native_terrains.txt new file mode 100644 index 000000000..d90ef9bb7 --- /dev/null +++ b/config/native_terrains.txt @@ -0,0 +1,11 @@ +//list of native terrains of different factions +//[faction ID] [terrain ID] +0 2 +1 2 +2 3 +3 7 +4 0 +5 6 +6 5 +7 4 +8 2 \ No newline at end of file diff --git a/hch/CHeroHandler.cpp b/hch/CHeroHandler.cpp index 556e3eeed..48c8d64fb 100644 --- a/hch/CHeroHandler.cpp +++ b/hch/CHeroHandler.cpp @@ -437,6 +437,7 @@ void CHeroHandler::initHeroClasses() heroes[gg]->heroClass = heroClasses[heroes[gg]->heroType]; } initTerrainCosts(); + loadNativeTerrains(); } unsigned int CHeroHandler::level(unsigned int experience) @@ -478,6 +479,12 @@ void CHeroHandler::initTerrainCosts() { std::ifstream inp; inp.open("config" PATHSEPARATOR "TERCOSTS.TXT", std::ios_base::in|std::ios_base::binary); + + if(!inp.is_open()) + { + tlog1 << "Error while opening config/TERCOSTS.TXT file!" << std::endl; + } + int tynum; inp>>tynum; for(int i=0; i<2*tynum; i+=2) @@ -495,3 +502,27 @@ void CHeroHandler::initTerrainCosts() inp.close(); } +void CHeroHandler::loadNativeTerrains() +{ + std::ifstream inp; + inp.open("config" PATHSEPARATOR "native_terrains.txt", std::ios_base::in|std::ios_base::binary); + + if(!inp.is_open()) + { + tlog1 << "Error while opening config/native_terrains.txt file!" << std::endl; + } + const int MAX_ELEM = 1000; + char buf[MAX_ELEM+1]; + inp.getline(buf, MAX_ELEM); + inp.getline(buf, MAX_ELEM); + + nativeTerrains.resize(F_NUMBER); + for(int i=0; i> faction; + inp >> terrain; + nativeTerrains[faction] = terrain; + } + inp.close(); +} diff --git a/hch/CHeroHandler.h b/hch/CHeroHandler.h index 534639563..2dfc9a16c 100644 --- a/hch/CHeroHandler.h +++ b/hch/CHeroHandler.h @@ -105,6 +105,7 @@ public: std::vector ballistics; //info about ballistics ability per level; [0] - none; [1] - basic; [2] - adv; [3] - expert std::map obstacles; //info about obstacles that may be placed on battlefield + std::vector nativeTerrains; //info about native terrains of different factions void loadObstacles(); //loads info about obstacles @@ -115,6 +116,7 @@ public: void loadHeroClasses(); void initHeroClasses(); void initTerrainCosts(); + void loadNativeTerrains(); CHeroHandler(); //c-tor ~CHeroHandler(); //d-tor diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index a0f9255e9..89aa56692 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -540,6 +540,9 @@ ui8 CStack::howManyEffectsSet(ui16 id) const si8 CStack::Morale() const { si8 ret = morale; + + if(hasFeatureOfType(StackFeature::NON_LIVING) || hasFeatureOfType(StackFeature::UNDEAD)) + return 0; ret += valOfFeatures(StackFeature::MORALE_BONUS); //mirth & sorrow & other @@ -578,7 +581,7 @@ si32 CStack::Attack() const ret += (VLC->spellh->spells[56].powers[getEffect(56)->level]/100.0) * Defense(false); } - ret += valOfFeatures(StackFeature::ATTACK_BONUS, -1); + ret += valOfFeatures(StackFeature::ATTACK_BONUS); return ret; } @@ -592,7 +595,7 @@ si32 CStack::Defense(bool withFrenzy /*= true*/) const return 0; } - ret += valOfFeatures(StackFeature::DEFENCE_BONUS, -1); + ret += valOfFeatures(StackFeature::DEFENCE_BONUS); return ret; } diff --git a/lib/StackFeature.h b/lib/StackFeature.h index 3ae628640..e5958de96 100644 --- a/lib/StackFeature.h +++ b/lib/StackFeature.h @@ -73,7 +73,8 @@ struct StackFeature { CREATURE_ABILITY, BONUS_FROM_HERO, - SPELL_EFFECT + SPELL_EFFECT, + OTHER_SOURCE /*eg. bonus from terrain if native*/ }; ui8 type;//ECombatFeatures diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 98df1d251..4c06bb9e2 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -934,6 +934,18 @@ void CGameHandler::setupBattle( BattleInfo * curB, int3 tile, CCreatureSet &army stacks[g]->position -= 1; } } + + //adding native terrain bonuses + for(int g=0; gheroh->nativeTerrains[stacks[g]->creature->faction] == gs->map->terrain[tile.x][tile.y][tile.z].tertype ) + { + stacks[g]->features.push_back(makeFeature(StackFeature::SPEED_BONUS, StackFeature::WHOLE_BATTLE, 0, 1, StackFeature::OTHER_SOURCE)); + stacks[g]->features.push_back(makeFeature(StackFeature::ATTACK_BONUS, StackFeature::WHOLE_BATTLE, 0, 1, StackFeature::OTHER_SOURCE)); + stacks[g]->features.push_back(makeFeature(StackFeature::DEFENCE_BONUS, StackFeature::WHOLE_BATTLE, 0, 1, StackFeature::OTHER_SOURCE)); + } + } + //adding war machines if(hero1) {