1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-02 00:10:22 +02:00

* 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
This commit is contained in:
mateuszb 2009-06-30 12:28:22 +00:00
parent 97287bb7d1
commit 1cac083239
8 changed files with 64 additions and 12 deletions

View File

@ -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)); 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 //blitting amount
std::ostringstream ss;
ss<<curStack.amount;
CSDL_Ext::printAtMiddleWB( CSDL_Ext::printAtMiddleWB(
ss.str(), makeNumberShort(curStack.amount),
creAnims[curStackID]->pos.x + xAdd + 14 + pos.x, creAnims[curStackID]->pos.x + xAdd + 14 + pos.x,
creAnims[curStackID]->pos.y + 260 + 4 + pos.y, creAnims[curStackID]->pos.y + 260 + 4 + pos.y,
GEOR13, GEOR13,

View File

@ -6,8 +6,6 @@
#include "../int3.h" #include "../int3.h"
#include <vector> #include <vector>
#include <sstream> #include <sstream>
#include <boost/version.hpp>
#include <boost/type_traits/is_integral.hpp>
/* /*
* SDL_Extensions.h, part of VCMI engine * SDL_Extensions.h, part of VCMI engine
@ -32,10 +30,6 @@ bool isItIn(const SDL_Rect * rect, int x, int y);
template<typename IntType> template<typename IntType>
std::string makeNumberShort(IntType number) //the output is a string containing at most 5 characters [4 if positive] (eg. intead 10000 it gives 10k) 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<IntType>::value, NON_INTEGRAL_TYPES_ARE_NOT_ALLOWED, (IntType) ); //it should make noise if IntType is not integral type
#endif
int initialLength; int initialLength;
bool negative = (number < 0); bool negative = (number < 0);
std::ostringstream ost, rets; std::ostringstream ost, rets;

View File

@ -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

View File

@ -437,6 +437,7 @@ void CHeroHandler::initHeroClasses()
heroes[gg]->heroClass = heroClasses[heroes[gg]->heroType]; heroes[gg]->heroClass = heroClasses[heroes[gg]->heroType];
} }
initTerrainCosts(); initTerrainCosts();
loadNativeTerrains();
} }
unsigned int CHeroHandler::level(unsigned int experience) unsigned int CHeroHandler::level(unsigned int experience)
@ -478,6 +479,12 @@ void CHeroHandler::initTerrainCosts()
{ {
std::ifstream inp; std::ifstream inp;
inp.open("config" PATHSEPARATOR "TERCOSTS.TXT", std::ios_base::in|std::ios_base::binary); 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; int tynum;
inp>>tynum; inp>>tynum;
for(int i=0; i<2*tynum; i+=2) for(int i=0; i<2*tynum; i+=2)
@ -495,3 +502,27 @@ void CHeroHandler::initTerrainCosts()
inp.close(); 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<F_NUMBER; ++i)
{
int faction, terrain;
inp >> faction;
inp >> terrain;
nativeTerrains[faction] = terrain;
}
inp.close();
}

View File

@ -105,6 +105,7 @@ public:
std::vector<SBallisticsLevelInfo> ballistics; //info about ballistics ability per level; [0] - none; [1] - basic; [2] - adv; [3] - expert std::vector<SBallisticsLevelInfo> ballistics; //info about ballistics ability per level; [0] - none; [1] - basic; [2] - adv; [3] - expert
std::map<int, CObstacleInfo> obstacles; //info about obstacles that may be placed on battlefield std::map<int, CObstacleInfo> obstacles; //info about obstacles that may be placed on battlefield
std::vector<int> nativeTerrains; //info about native terrains of different factions
void loadObstacles(); //loads info about obstacles void loadObstacles(); //loads info about obstacles
@ -115,6 +116,7 @@ public:
void loadHeroClasses(); void loadHeroClasses();
void initHeroClasses(); void initHeroClasses();
void initTerrainCosts(); void initTerrainCosts();
void loadNativeTerrains();
CHeroHandler(); //c-tor CHeroHandler(); //c-tor
~CHeroHandler(); //d-tor ~CHeroHandler(); //d-tor

View File

@ -540,6 +540,9 @@ ui8 CStack::howManyEffectsSet(ui16 id) const
si8 CStack::Morale() const si8 CStack::Morale() const
{ {
si8 ret = morale; si8 ret = morale;
if(hasFeatureOfType(StackFeature::NON_LIVING) || hasFeatureOfType(StackFeature::UNDEAD))
return 0;
ret += valOfFeatures(StackFeature::MORALE_BONUS); //mirth & sorrow & other 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 += (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; return ret;
} }
@ -592,7 +595,7 @@ si32 CStack::Defense(bool withFrenzy /*= true*/) const
return 0; return 0;
} }
ret += valOfFeatures(StackFeature::DEFENCE_BONUS, -1); ret += valOfFeatures(StackFeature::DEFENCE_BONUS);
return ret; return ret;
} }

View File

@ -73,7 +73,8 @@ struct StackFeature
{ {
CREATURE_ABILITY, CREATURE_ABILITY,
BONUS_FROM_HERO, BONUS_FROM_HERO,
SPELL_EFFECT SPELL_EFFECT,
OTHER_SOURCE /*eg. bonus from terrain if native*/
}; };
ui8 type;//ECombatFeatures ui8 type;//ECombatFeatures

View File

@ -934,6 +934,18 @@ void CGameHandler::setupBattle( BattleInfo * curB, int3 tile, CCreatureSet &army
stacks[g]->position -= 1; stacks[g]->position -= 1;
} }
} }
//adding native terrain bonuses
for(int g=0; g<stacks.size(); ++g)
{
if( VLC->heroh->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 //adding war machines
if(hero1) if(hero1)
{ {