1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Version set to 0.75c. Will be released as dev version.

HLP class for generating stats must not be local if used as template parameter.
This commit is contained in:
Michał W. Urbańczyk
2010-02-11 19:18:30 +00:00
parent 8f88cb19a8
commit 5d0186a10b
2 changed files with 92 additions and 92 deletions

View File

@@ -20,7 +20,7 @@ typedef boost::int8_t si8; //signed int 8 bits (1 byte)
#define THC
#endif
#define NAME_VER ("VCMI 0.75b")
#define NAME_VER ("VCMI 0.75c")
extern std::string NAME; //full name
extern std::string NAME_AFFIX; //client / server
#define CONSOLE_LOGGING_LEVEL 5
@@ -360,28 +360,28 @@ extern DLL_EXPORT CLogger<5> tlog5; //gray - minor log info
throw; \
}
#if defined(linux) && defined(sparc)
/* SPARC does not support unaligned memory access. Let gcc know when
* to emit the right code. */
struct unaligned_Uint16 { ui16 val __attribute__(( packed )); };
struct unaligned_Uint32 { ui32 val __attribute__(( packed )); };
static inline ui16 read_unaligned_u16(const void *p)
{
const struct unaligned_Uint16 *v = (const struct unaligned_Uint16 *)p;
return v->val;
}
static inline ui32 read_unaligned_u32(const void *p)
{
const struct unaligned_Uint32 *v = (const struct unaligned_Uint32 *)p;
return v->val;
}
#else
#define read_unaligned_u16(p) (* reinterpret_cast<const Uint16 *>(p))
#define read_unaligned_u32(p) (* reinterpret_cast<const Uint32 *>(p))
#endif
#if defined(linux) && defined(sparc)
/* SPARC does not support unaligned memory access. Let gcc know when
* to emit the right code. */
struct unaligned_Uint16 { ui16 val __attribute__(( packed )); };
struct unaligned_Uint32 { ui32 val __attribute__(( packed )); };
static inline ui16 read_unaligned_u16(const void *p)
{
const struct unaligned_Uint16 *v = (const struct unaligned_Uint16 *)p;
return v->val;
}
static inline ui32 read_unaligned_u32(const void *p)
{
const struct unaligned_Uint32 *v = (const struct unaligned_Uint32 *)p;
return v->val;
}
#else
#define read_unaligned_u16(p) (* reinterpret_cast<const Uint16 *>(p))
#define read_unaligned_u32(p) (* reinterpret_cast<const Uint32 *>(p))
#endif
#endif // __GLOBAL_H__

View File

@@ -3138,72 +3138,72 @@ bool CGameState::checkForStandardLoss( ui8 player ) const
return !p.heroes.size() && !p.towns.size();
}
struct statsHLP
{
typedef std::pair< ui8, si64 > TStat;
//converts [<player's color, value>] to vec[place] -> platers
static std::vector< std::list< ui8 > > getRank( std::vector<TStat> stats )
{
std::sort(stats.begin(), stats.end(), statsHLP());
//put first element
std::vector< std::list<ui8> > ret;
std::list<ui8> tmp;
tmp.push_back( stats[0].first );
ret.push_back( tmp );
//the rest of elements
for(int g=1; g<stats.size(); ++g)
{
if(stats[g].second == stats[g-1].second)
{
(ret.end()-1)->push_back( stats[g].first );
}
else
{
//create next occupied rank
std::list<ui8> tmp;
tmp.push_back(stats[g].first);
ret.push_back(tmp);
}
}
return ret;
}
bool operator()(const TStat & a, const TStat & b) const
{
return a.second > b.second;
}
static const CGHeroInstance * findBestHero(CGameState * gs, int color)
{
//best hero will be that with highest exp
int best = 0;
for(int b=1; b<gs->players[color].heroes.size(); ++b)
{
if(gs->players[color].heroes[b]->exp > gs->players[color].heroes[best]->exp)
{
best = b;
}
}
return gs->players[color].heroes[best];
}
//calculates total number of artifacts that belong to given player
static int getNumberOfArts(const PlayerState * ps)
{
int ret = 0;
for(int g=0; g<ps->heroes.size(); ++g)
{
ret += ps->heroes[g]->artifacts.size() + ps->heroes[g]->artifWorn.size();
}
return ret;
}
};
void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
{
struct HLP
{
typedef std::pair< ui8, si64 > TStat;
//converts [<player's color, value>] to vec[place] -> platers
static std::vector< std::list< ui8 > > getRank( std::vector<TStat> stats )
{
std::sort(stats.begin(), stats.end(), HLP());
//put first element
std::vector< std::list<ui8> > ret;
std::list<ui8> tmp;
tmp.push_back( stats[0].first );
ret.push_back( tmp );
//the rest of elements
for(int g=1; g<stats.size(); ++g)
{
if(stats[g].second == stats[g-1].second)
{
(ret.end()-1)->push_back( stats[g].first );
}
else
{
//create next occupied rank
std::list<ui8> tmp;
tmp.push_back(stats[g].first);
ret.push_back(tmp);
}
}
return ret;
}
bool operator()(const TStat & a, const TStat & b) const
{
return a.second > b.second;
}
static const CGHeroInstance * findBestHero(CGameState * gs, int color)
{
//best hero will be that with highest exp
int best = 0;
for(int b=1; b<gs->players[color].heroes.size(); ++b)
{
if(gs->players[color].heroes[b]->exp > gs->players[color].heroes[best]->exp)
{
best = b;
}
}
return gs->players[color].heroes[best];
}
//calculates total number of artifacts that belong to given player
static int getNumberOfArts(const PlayerState * ps)
{
int ret = 0;
for(int g=0; g<ps->heroes.size(); ++g)
{
ret += ps->heroes[g]->artifacts.size() + ps->heroes[g]->artifWorn.size();
}
return ret;
}
};
#define FILL_FIELD(FIELD, VAL_GETTER) \
{ \
std::vector< std::pair< ui8, si64 > > stats; \
@@ -3216,7 +3216,7 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
stat.second = VAL_GETTER; \
stats.push_back(stat); \
} \
tgi.FIELD = HLP::getRank(stats); \
tgi.FIELD = statsHLP::getRank(stats); \
}
for(std::map<ui8, PlayerState>::const_iterator g = players.begin(); g != players.end(); ++g)
@@ -3236,7 +3236,7 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
{
if(g->second.color == 255)
continue;
const CGHeroInstance * best = HLP::findBestHero(this, g->second.color);
const CGHeroInstance * best = statsHLP::findBestHero(this, g->second.color);
InfoAboutHero iah;
iah.initFromHero(best, level >= 8);
iah.army.slots.clear();
@@ -3261,7 +3261,7 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
}
if(level >= 5) //artifacts
{
FILL_FIELD(artifacts, HLP::getNumberOfArts(&g->second))
FILL_FIELD(artifacts, statsHLP::getNumberOfArts(&g->second))
}
if(level >= 6) //army strength
{