mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Const-transitiveness of CGI almost reached
This commit is contained in:
parent
b15deaa203
commit
8b831c1f46
@ -158,7 +158,7 @@ const CGTownInstance * CCallback::getTownInfo(int val, bool mode) const //mode =
|
||||
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
|
||||
if (!mode)
|
||||
{
|
||||
const std::vector<CGTownInstance *> &towns = gs->players[gs->currentPlayer].towns;
|
||||
const std::vector<ConstTransitivePtr<CGTownInstance> > &towns = gs->players[gs->currentPlayer].towns;
|
||||
if(val < towns.size())
|
||||
return towns[val];
|
||||
else
|
||||
|
@ -51,7 +51,7 @@ struct Mapa;
|
||||
*/
|
||||
class CGameInfo
|
||||
{
|
||||
CGameState * state; //don't touch it in client's code
|
||||
ConstTransitivePtr<CGameState> state; //don't touch it in client's code
|
||||
public:
|
||||
ConstTransitivePtr<CArtHandler> arth;
|
||||
ConstTransitivePtr<CHeroHandler> heroh;
|
||||
@ -73,7 +73,7 @@ public:
|
||||
CGameInfo();
|
||||
};
|
||||
|
||||
// ConstTransitivePtr<CGameState> state; //don't touch it in client's code
|
||||
//
|
||||
// public:
|
||||
//
|
||||
// ConstTransitivePtr<CGeneralTextHandler> generaltexth;
|
||||
|
@ -173,7 +173,7 @@ void initVillagesCapitols(Mapa * map)
|
||||
ifs>>ccc;
|
||||
for(int i=0;i<ccc*2;i++)
|
||||
{
|
||||
CGDefInfo *n;
|
||||
const CGDefInfo *n;
|
||||
if(i<ccc)
|
||||
{
|
||||
n = CGI->state->villages[i];
|
||||
@ -182,11 +182,11 @@ void initVillagesCapitols(Mapa * map)
|
||||
else
|
||||
n = CGI->state->capitols[i%ccc];
|
||||
|
||||
ifs >> n->name;
|
||||
ifs >> const_cast<CGDefInfo*>(n)->name;
|
||||
if(!n)
|
||||
tlog1 << "*HUGE* Warning - missing town def for " << i << std::endl;
|
||||
else
|
||||
map->defy.push_back(n);
|
||||
map->defy.push_back(const_cast<CGDefInfo*>(n));
|
||||
}
|
||||
}
|
||||
|
||||
@ -364,7 +364,7 @@ void CClient::newGame( CConnection *con, StartInfo *si )
|
||||
tlog0 <<"\tSending/Getting info to/from the server: "<<tmh.getDif()<<std::endl;
|
||||
tlog0 << "\tUsing random seed: "<<seed << std::endl;
|
||||
|
||||
gs = CGI->state;
|
||||
gs = const_cast<CGameInfo*>(CGI)->state;
|
||||
gs->scenarioOps = si;
|
||||
gs->init(si, sum, seed);
|
||||
|
||||
@ -399,7 +399,7 @@ void CClient::newGame( CConnection *con, StartInfo *si )
|
||||
playerint[color]->init(cb);
|
||||
}
|
||||
|
||||
serv->addStdVecItems(CGI->state);
|
||||
serv->addStdVecItems(const_cast<CGameInfo*>(CGI)->state);
|
||||
hotSeat = (humanPlayers > 1);
|
||||
|
||||
playerint[255] = CAIHandler::getNewAI(cb,conf.cc.defaultAI);
|
||||
|
@ -294,7 +294,7 @@ void CMapHandler::initObjectRects()
|
||||
}
|
||||
}
|
||||
}
|
||||
static void processDef (CGDefInfo* def)
|
||||
static void processDef (const CGDefInfo* def)
|
||||
{
|
||||
if(def->id == EVENTI_TYPE)
|
||||
{
|
||||
@ -335,11 +335,11 @@ static void processDef (CGDefInfo* def)
|
||||
CSDL_Ext::alphaTransform(ourDef->ourImages[yy].bitmap);
|
||||
}
|
||||
}
|
||||
void CMapHandler::initHeroDef(CGHeroInstance * h)
|
||||
void CMapHandler::initHeroDef(const CGHeroInstance * h)
|
||||
{
|
||||
graphics->advmapobjGraphics[h->defInfo->id][h->defInfo->subid] = graphics->flags1[0];
|
||||
h->defInfo->width =graphics->getDef(h)->ourImages[0].bitmap->w/32;
|
||||
h->defInfo->height = graphics->getDef(h)->ourImages[0].bitmap->h/32;
|
||||
// h->defInfo->width =graphics->getDef(h)->ourImages[0].bitmap->w/32;
|
||||
// h->defInfo->height = graphics->getDef(h)->ourImages[0].bitmap->h/32;
|
||||
}
|
||||
void CMapHandler::init()
|
||||
{
|
||||
|
@ -110,7 +110,7 @@ public:
|
||||
bool printObject(const CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map
|
||||
bool hideObject(const CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
|
||||
bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope)
|
||||
void initHeroDef(CGHeroInstance * h);
|
||||
void initHeroDef(const CGHeroInstance * h);
|
||||
void init();
|
||||
void calculateBlockedPos();
|
||||
void initObjectRects();
|
||||
|
@ -1053,7 +1053,7 @@ std::string CStack::nodeName() const
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, const CTown *town, std::map<ui32,CGHeroInstance *> &available, const CHeroClass *bannedClass /*= NULL*/) const
|
||||
CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, const CTown *town, bmap<ui32, ConstTransitivePtr<CGHeroInstance> > &available, const CHeroClass *bannedClass /*= NULL*/) const
|
||||
{
|
||||
CGHeroInstance *ret = NULL;
|
||||
|
||||
@ -1067,7 +1067,7 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, co
|
||||
|
||||
if(native)
|
||||
{
|
||||
for(std::map<ui32,CGHeroInstance *>::iterator i=available.begin(); i!=available.end(); i++)
|
||||
for(bmap<ui32, ConstTransitivePtr<CGHeroInstance> >::iterator i=available.begin(); i!=available.end(); i++)
|
||||
{
|
||||
if(pavailable.find(i->first)->second & 1<<player
|
||||
&& i->second->type->heroType/2 == town->typeID)
|
||||
@ -1089,7 +1089,7 @@ CGHeroInstance * CGameState::HeroesPool::pickHeroFor(bool native, int player, co
|
||||
{
|
||||
int sum=0, r;
|
||||
|
||||
for(std::map<ui32,CGHeroInstance *>::iterator i=available.begin(); i!=available.end(); i++)
|
||||
for(bmap<ui32, ConstTransitivePtr<CGHeroInstance> >::iterator i=available.begin(); i!=available.end(); i++)
|
||||
{
|
||||
if(pavailable.find(i->first)->second & 1<<player
|
||||
&& !bannedClass || i->second->type->heroClass != bannedClass)
|
||||
@ -1921,7 +1921,7 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
|
||||
break;
|
||||
}
|
||||
}
|
||||
std::vector<CGHeroInstance *> & heroes = players[humanPlayer].heroes;
|
||||
std::vector<ConstTransitivePtr<CGHeroInstance> > & heroes = players[humanPlayer].heroes;
|
||||
|
||||
if (chosenBonus.info1 == 0xFFFD) //most powerful
|
||||
{
|
||||
@ -3952,7 +3952,7 @@ struct statsHLP
|
||||
|
||||
static const CGHeroInstance * findBestHero(CGameState * gs, int color)
|
||||
{
|
||||
std::vector<CGHeroInstance *> &h = gs->players[color].heroes;
|
||||
std::vector<ConstTransitivePtr<CGHeroInstance> > &h = gs->players[color].heroes;
|
||||
if(!h.size())
|
||||
return NULL;
|
||||
//best hero will be that with highest exp
|
||||
@ -4140,11 +4140,11 @@ int CGameState::lossCheck( ui8 player ) const
|
||||
return false;
|
||||
}
|
||||
|
||||
std::map<ui32,CGHeroInstance *> CGameState::unusedHeroesFromPool()
|
||||
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > CGameState::unusedHeroesFromPool()
|
||||
{
|
||||
std::map<ui32,CGHeroInstance *> pool = hpool.heroesPool;
|
||||
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > pool = hpool.heroesPool;
|
||||
for ( std::map<ui8, PlayerState>::iterator i = players.begin() ; i != players.end();i++)
|
||||
for(std::vector<CGHeroInstance *>::iterator j = i->second.availableHeroes.begin(); j != i->second.availableHeroes.end(); j++)
|
||||
for(std::vector< ConstTransitivePtr<CGHeroInstance> >::iterator j = i->second.availableHeroes.begin(); j != i->second.availableHeroes.end(); j++)
|
||||
if(*j)
|
||||
pool.erase((**j).subID);
|
||||
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include "../tchar_amigaos4.h"
|
||||
#endif
|
||||
|
||||
#include "ConstTransitivePtr.h"
|
||||
|
||||
|
||||
/*
|
||||
* CGameState.h, part of VCMI engine
|
||||
@ -131,12 +133,11 @@ public:
|
||||
ui8 human; //true if human controlled player, false for AI
|
||||
ui32 currentSelection; //id of hero/town, 0xffffffff if none
|
||||
ui8 team;
|
||||
//std::vector<std::vector<std::vector<ui8> > > * fogOfWarMap; //pointer to team's fog of war
|
||||
std::vector<si32> resources;
|
||||
std::vector<CGHeroInstance *> heroes;
|
||||
std::vector<CGTownInstance *> towns;
|
||||
std::vector<CGHeroInstance *> availableHeroes; //heroes available in taverns
|
||||
std::vector<CGDwelling *> dwellings; //used for town growth
|
||||
std::vector<ConstTransitivePtr<CGHeroInstance> > heroes;
|
||||
std::vector<ConstTransitivePtr<CGTownInstance> > towns;
|
||||
std::vector<ConstTransitivePtr<CGHeroInstance> > availableHeroes; //heroes available in taverns
|
||||
std::vector<ConstTransitivePtr<CGDwelling> > dwellings; //used for town growth
|
||||
|
||||
ui8 enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory
|
||||
ui8 status; //0 - in game, 1 - loser, 2 - winner <- uses EStatus enum
|
||||
@ -432,24 +433,24 @@ struct DLL_EXPORT CPathsInfo
|
||||
class DLL_EXPORT CGameState
|
||||
{
|
||||
public:
|
||||
StartInfo* scenarioOps, *initialOpts; //second one is a copy of settings received from pregame (not randomized)
|
||||
ConstTransitivePtr<StartInfo> scenarioOps, initialOpts; //second one is a copy of settings received from pregame (not randomized)
|
||||
CCampaignState *campaign;
|
||||
ui32 seed;
|
||||
ui8 currentPlayer; //ID of player currently having turn
|
||||
BattleInfo *curB; //current battle
|
||||
ui32 day; //total number of days in game
|
||||
Mapa * map;
|
||||
std::map<ui8, PlayerState> players; //ID <-> player state
|
||||
std::map<ui8, TeamState> teams; //ID <-> team state
|
||||
std::map<int, CGDefInfo*> villages, forts, capitols; //def-info for town graphics
|
||||
ConstTransitivePtr<Mapa> map;
|
||||
bmap<ui8, PlayerState> players; //ID <-> player state
|
||||
bmap<ui8, TeamState> teams; //ID <-> team state
|
||||
bmap<int, ConstTransitivePtr<CGDefInfo> > villages, forts, capitols; //def-info for town graphics
|
||||
CBonusSystemNode globalEffects;
|
||||
|
||||
struct DLL_EXPORT HeroesPool
|
||||
{
|
||||
std::map<ui32,CGHeroInstance *> heroesPool; //[subID] - heroes available to buy; NULL if not available
|
||||
std::map<ui32,ui8> pavailable; // [subid] -> which players can recruit hero (binary flags)
|
||||
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > heroesPool; //[subID] - heroes available to buy; NULL if not available
|
||||
bmap<ui32,ui8> pavailable; // [subid] -> which players can recruit hero (binary flags)
|
||||
|
||||
CGHeroInstance * pickHeroFor(bool native, int player, const CTown *town, std::map<ui32,CGHeroInstance *> &available, const CHeroClass *bannedClass = NULL) const;
|
||||
CGHeroInstance * pickHeroFor(bool native, int player, const CTown *town, bmap<ui32, ConstTransitivePtr<CGHeroInstance> > &available, const CHeroClass *bannedClass = NULL) const;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
@ -496,7 +497,7 @@ public:
|
||||
ui8 checkForStandardWin() const; //returns color of player that accomplished standard victory conditions or 255 if no winner
|
||||
bool checkForStandardLoss(ui8 player) const; //checks if given player lost the game
|
||||
void obtainPlayersStats(SThievesGuildInfo & tgi, int level); //fills tgi with info about other players that is available at given level of thieves' guild
|
||||
std::map<ui32,CGHeroInstance *> unusedHeroesFromPool(); //heroes pool without heroes that are available in taverns
|
||||
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > unusedHeroesFromPool(); //heroes pool without heroes that are available in taverns
|
||||
|
||||
bool isVisible(int3 pos, int player);
|
||||
bool isVisible(const CGObjectInstance *obj, int player);
|
||||
|
@ -266,7 +266,7 @@ DLL_EXPORT void RemoveObject::applyGs( CGameState *gs )
|
||||
if(obj->ID==HEROI_TYPE)
|
||||
{
|
||||
CGHeroInstance *h = static_cast<CGHeroInstance*>(obj);
|
||||
std::vector<CGHeroInstance*>::iterator nitr = std::find(gs->map->heroes.begin(), gs->map->heroes.end(),h);
|
||||
std::vector<ConstTransitivePtr<CGHeroInstance> >::iterator nitr = std::find(gs->map->heroes.begin(), gs->map->heroes.end(),h);
|
||||
gs->map->heroes.erase(nitr);
|
||||
int player = h->tempOwner;
|
||||
nitr = std::find(gs->getPlayer(player)->heroes.begin(), gs->getPlayer(player)->heroes.end(), h);
|
||||
|
13
lib/map.cpp
13
lib/map.cpp
@ -516,7 +516,7 @@ Mapa::~Mapa()
|
||||
}
|
||||
delete [] terrain;
|
||||
}
|
||||
for(std::list<CMapEvent*>::iterator i = events.begin(); i != events.end(); i++)
|
||||
for(std::list<ConstTransitivePtr<CMapEvent> >::iterator i = events.begin(); i != events.end(); i++)
|
||||
delete *i;
|
||||
}
|
||||
|
||||
@ -1287,6 +1287,15 @@ void Mapa::readDefInfo( const unsigned char * bufor, int &i)
|
||||
}
|
||||
}
|
||||
|
||||
class _HERO_SORTER
|
||||
{
|
||||
public:
|
||||
bool operator()(const ConstTransitivePtr<CGHeroInstance> & a, const ConstTransitivePtr<CGHeroInstance> & b)
|
||||
{
|
||||
return a->subID < b->subID;
|
||||
}
|
||||
};
|
||||
|
||||
void Mapa::readObjects( const unsigned char * bufor, int &i)
|
||||
{
|
||||
int howManyObjs = readNormalNr(bufor,i, 4); i+=4;
|
||||
@ -1934,7 +1943,7 @@ void Mapa::readObjects( const unsigned char * bufor, int &i)
|
||||
heroes.push_back(static_cast<CGHeroInstance*>(nobj));
|
||||
}
|
||||
|
||||
std::sort(heroes.begin(), heroes.end(), boost::bind(&CGHeroInstance::subID, _1) < boost::bind(&CGHeroInstance::subID, _2));
|
||||
std::sort(heroes.begin(), heroes.end(), _HERO_SORTER());
|
||||
}
|
||||
|
||||
void Mapa::readEvents( const unsigned char * bufor, int &i )
|
||||
|
14
lib/map.h
14
lib/map.h
@ -269,22 +269,22 @@ struct DLL_EXPORT Mapa : public CMapHeader
|
||||
TerrainTile*** terrain;
|
||||
std::vector<Rumor> rumors;
|
||||
std::vector<DisposedHero> disposedHeroes;
|
||||
std::vector<CGHeroInstance*> predefinedHeroes;
|
||||
std::vector<CGDefInfo *> defy; // list of .def files with definitions from .h3m (may be custom)
|
||||
std::vector<ConstTransitivePtr<CGHeroInstance> > predefinedHeroes;
|
||||
std::vector<ConstTransitivePtr<CGDefInfo> > defy; // list of .def files with definitions from .h3m (may be custom)
|
||||
std::vector<ui8> allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed
|
||||
std::vector<ui8> allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed
|
||||
std::vector<ui8> allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed
|
||||
std::list<CMapEvent*> events;
|
||||
std::list<ConstTransitivePtr<CMapEvent> > events;
|
||||
|
||||
int3 grailPos;
|
||||
int grailRadious;
|
||||
|
||||
std::vector< ConstTransitivePtr<CGObjectInstance> > objects;
|
||||
std::vector<CGHeroInstance*> heroes;
|
||||
std::vector<CGTownInstance*> towns;
|
||||
std::vector< ConstTransitivePtr<CGHeroInstance> > heroes;
|
||||
std::vector< ConstTransitivePtr<CGTownInstance> > towns;
|
||||
std::vector< ConstTransitivePtr<CArtifactInstance> > artInstances; //stores all artifacts
|
||||
std::map<ui16, CGCreature*> monsters;
|
||||
std::map<ui16, CGHeroInstance*> heroesToBeat;
|
||||
bmap<ui16, ConstTransitivePtr<CGCreature> > monsters;
|
||||
bmap<ui16, ConstTransitivePtr<CGHeroInstance> > heroesToBeat;
|
||||
|
||||
void initFromBytes( const unsigned char * bufor); //creates map from decompressed .h3m data
|
||||
|
||||
|
@ -933,7 +933,7 @@ void CGameHandler::setPortalDwelling(const CGTownInstance * town, bool forced=fa
|
||||
ssi.creatures = town->creatures;
|
||||
ssi.creatures[CREATURES_PER_TOWN].second.clear();//remove old one
|
||||
|
||||
const std::vector<CGDwelling *> &dwellings = gs->getPlayer(town->tempOwner)->dwellings;
|
||||
const std::vector<ConstTransitivePtr<CGDwelling> > &dwellings = gs->getPlayer(town->tempOwner)->dwellings;
|
||||
if (dwellings.empty())//no dwellings - just remove
|
||||
{
|
||||
sendAndApply(&ssi);
|
||||
@ -1008,7 +1008,7 @@ void CGameHandler::newTurn()
|
||||
else
|
||||
n.specialWeek = NewTurn::NO_ACTION; //don't remove bonuses
|
||||
|
||||
std::map<ui32,CGHeroInstance *> pool = gs->hpool.heroesPool;
|
||||
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > pool = gs->hpool.heroesPool;
|
||||
|
||||
for ( std::map<ui8, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
|
||||
{
|
||||
@ -1079,7 +1079,7 @@ void CGameHandler::newTurn()
|
||||
// townID, creatureID, amount
|
||||
std::map<si32, std::map<si32, si32> > newCreas;//creatures that needs to be added by town events
|
||||
|
||||
for(std::vector<CGTownInstance *>::iterator j = gs->map->towns.begin(); j!=gs->map->towns.end(); j++)//handle towns
|
||||
for(std::vector<ConstTransitivePtr<CGTownInstance> >::iterator j = gs->map->towns.begin(); j!=gs->map->towns.end(); j++)//handle towns
|
||||
{
|
||||
ui8 player = (*j)->tempOwner;
|
||||
if(gs->getDate(1)==7) //first day of week
|
||||
@ -1176,7 +1176,7 @@ void CGameHandler::newTurn()
|
||||
n2.day = gs->day;
|
||||
n2.resetBuilded = true;
|
||||
|
||||
for(std::vector<CGTownInstance *>::iterator j = gs->map->towns.begin(); j!=gs->map->towns.end(); j++)//handle towns
|
||||
for(std::vector<ConstTransitivePtr<CGTownInstance> >::iterator j = gs->map->towns.begin(); j!=gs->map->towns.end(); j++)//handle towns
|
||||
{
|
||||
SetAvailableCreatures sac;
|
||||
sac.tid = (**j).id;
|
||||
@ -3559,7 +3559,7 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, ui8 player)
|
||||
}
|
||||
|
||||
|
||||
CGHeroInstance *nh = p->availableHeroes[hid];
|
||||
const CGHeroInstance *nh = p->availableHeroes[hid];
|
||||
assert(nh);
|
||||
|
||||
HeroRecruited hr;
|
||||
@ -3570,7 +3570,7 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, ui8 player)
|
||||
sendAndApply(&hr);
|
||||
|
||||
|
||||
std::map<ui32,CGHeroInstance *> pool = gs->unusedHeroesFromPool();
|
||||
bmap<ui32, ConstTransitivePtr<CGHeroInstance> > pool = gs->unusedHeroesFromPool();
|
||||
|
||||
const CGHeroInstance *theOtherHero = p->availableHeroes[!hid];
|
||||
const CGHeroInstance *newHero = gs->hpool.pickHeroFor(false, player, getNativeTown(player), pool, theOtherHero->type->heroClass);
|
||||
@ -4700,8 +4700,8 @@ void CGameHandler::checkLossVictory( ui8 player )
|
||||
}
|
||||
else //player lost -> all his objects become unflagged (neutral)
|
||||
{
|
||||
std::vector<CGHeroInstance*> hlp = p->heroes;
|
||||
for (std::vector<CGHeroInstance*>::const_iterator i = hlp.begin(); i != hlp.end(); i++) //eliminate heroes
|
||||
std::vector<ConstTransitivePtr<CGHeroInstance> > hlp = p->heroes;
|
||||
for (std::vector<ConstTransitivePtr<CGHeroInstance> >::const_iterator i = hlp.begin(); i != hlp.end(); i++) //eliminate heroes
|
||||
removeObject((*i)->id);
|
||||
|
||||
for (std::vector<ConstTransitivePtr<CGObjectInstance> >::const_iterator i = gs->map->objects.begin(); i != gs->map->objects.end(); i++) //unflag objs
|
||||
|
Loading…
Reference in New Issue
Block a user