From 7f97a56a28b920a6f0bd8f7d3f65f0056db616e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 28 Nov 2009 01:42:08 +0000 Subject: [PATCH] Fixed crash on casting spell. Fixed giving resources from towns. Version set to 0.74c. Incremented save format version. Disabled adventure AI. Will be released as dev build. --- AI/GeniusAI/CGeniusAI.cpp | 50 ++++++++++++++++++------------------- client/CBattleInterface.cpp | 22 ++++++++-------- global.h | 2 +- lib/Connection.cpp | 6 ++--- lib/Connection.h | 2 +- lib/NetPacks.h | 33 ++++++++++++------------ lib/NetPacksLib.cpp | 24 +++++++++++------- server/CGameHandler.cpp | 41 ++++++++++++++++-------------- 8 files changed, 95 insertions(+), 85 deletions(-) diff --git a/AI/GeniusAI/CGeniusAI.cpp b/AI/GeniusAI/CGeniusAI.cpp index fdacacd8c..ea146e863 100644 --- a/AI/GeniusAI/CGeniusAI.cpp +++ b/AI/GeniusAI/CGeniusAI.cpp @@ -1028,31 +1028,31 @@ void CGeniusAI::yourTurn() m_cb->waitTillRealize = true; static int seed = rand(); srand(seed); - if (m_cb->getDate() == 1) { - // startFirstTurn(); - - // m_cb->endTurn(); - // return; - } - //////////////TODO: replace with updates. Also add suspected objects list.///////// - knownVisitableObjects.clear(); - int3 pos = m_cb->getMapSize(); - for (int x = 0; x < pos.x; x++) { - for (int y = 0; y < pos.y; y++) { - for (int z = 0; z < pos.z; z++) - tileRevealed(int3(x,y,z)); - } - } - /////////////////////////////////////////////////////////////////////////////////// - - reportResources(); - - trueGameState = HypotheticalGameState(*this); - AIObjective * objective; - while ((objective = getBestObjective()) != NULL) - objective->fulfill(*this,trueGameState); - - seed = rand(); +// if (m_cb->getDate() == 1) { +// // startFirstTurn(); +// +// // m_cb->endTurn(); +// // return; +// } +// //////////////TODO: replace with updates. Also add suspected objects list.///////// +// knownVisitableObjects.clear(); +// int3 pos = m_cb->getMapSize(); +// for (int x = 0; x < pos.x; x++) { +// for (int y = 0; y < pos.y; y++) { +// for (int z = 0; z < pos.z; z++) +// tileRevealed(int3(x,y,z)); +// } +// } +// /////////////////////////////////////////////////////////////////////////////////// +// +// reportResources(); +// +// trueGameState = HypotheticalGameState(*this); +// AIObjective * objective; +// while ((objective = getBestObjective()) != NULL) +// objective->fulfill(*this,trueGameState); +// +// seed = rand(); m_cb->endTurn(); m_cb->waitTillRealize = false; } diff --git a/client/CBattleInterface.cpp b/client/CBattleInterface.cpp index 4e59fda77..8e29af477 100644 --- a/client/CBattleInterface.cpp +++ b/client/CBattleInterface.cpp @@ -1455,17 +1455,6 @@ void CBattleInterface::show(SDL_Surface * to) SDL_SetClipRect(to, &buf); //restoring previous clip_rect - //showing buttons - bOptions->show(to); - bSurrender->show(to); - bFlee->show(to); - bAutofight->show(to); - bSpell->show(to); - bWait->show(to); - bDefence->show(to); - bConsoleUp->show(to); - bConsoleDown->show(to); - //prevents blitting outside this window SDL_GetClipRect(to, &buf); SDL_SetClipRect(to, &pos); @@ -1611,6 +1600,17 @@ void CBattleInterface::show(SDL_Surface * to) blitAt(menu, pos.x, 556 + pos.y, to); console->show(to); + //showing buttons + bOptions->show(to); + bSurrender->show(to); + bFlee->show(to); + bAutofight->show(to); + bSpell->show(to); + bWait->show(to); + bDefence->show(to); + bConsoleUp->show(to); + bConsoleDown->show(to); + //showing window with result of battle if(resWindow) { diff --git a/global.h b/global.h index ee3bce556..91e3bd90d 100644 --- a/global.h +++ b/global.h @@ -20,7 +20,7 @@ typedef boost::int8_t si8; //signed int 8 bits (1 byte) #define THC #endif -#define NAME_VER ("VCMI 0.74b") +#define NAME_VER ("VCMI 0.74c") extern std::string NAME; //full name extern std::string NAME_AFFIX; //client / server #define CONSOLE_LOGGING_LEVEL 5 diff --git a/lib/Connection.cpp b/lib/Connection.cpp index fecad0482..7305789ff 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -246,16 +246,16 @@ CLoadFile::CLoadFile( const std::string &fname ) if(std::memcmp(buffer,"VCMI",4)) { - tlog1 << "Error: wrong save format! (file " << fname << " )\n"; + tlog1 << "Error: not a VCMI save! (file " << fname << " )\n"; delete sfile; sfile = NULL; return; } *this >> myVersion; - if(myVersion > version || myVersion < 110) + if(myVersion != version) { - tlog1 << "Wrong save format! (file " << fname << " )\n"; + tlog1 << "Error: Not supported save format! (file " << fname << " )\n"; delete sfile; sfile = NULL; } diff --git a/lib/Connection.h b/lib/Connection.h index 77c7429f7..e1217366e 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -20,7 +20,7 @@ #include #include -const ui32 version = 711; +const ui32 version = 712; class CConnection; class CGObjectInstance; class CGameState; diff --git a/lib/NetPacks.h b/lib/NetPacks.h index acec1ba9d..a5d06c0f3 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -215,20 +215,20 @@ struct SetResource : public CPackForClient //102 h & player & resid & val; } }; -struct SetResources : public CPackForClient //104 -{ - SetResources(){res.resize(RESOURCE_QUANTITY);type = 104;}; - void applyCl(CClient *cl); - DLL_EXPORT void applyGs(CGameState *gs); - - ui8 player; - std::vector res; //res[resid] => res amount - - template void serialize(Handler &h, const int version) - { - h & player & res; - } -}; + struct SetResources : public CPackForClient //104 + { + SetResources(){res.resize(RESOURCE_QUANTITY);type = 104;}; + void applyCl(CClient *cl); + DLL_EXPORT void applyGs(CGameState *gs); + + ui8 player; + std::vector res; //res[resid] => res amount + + template void serialize(Handler &h, const int version) + { + h & player & res; + } + }; struct SetPrimSkill : public CPackForClient //105 { @@ -593,8 +593,9 @@ struct NewTurn : public CPackForClient //101 }; std::set heroes; //updates movement and mana points - std::vector res;//resource list - std::vector cres;//resource list + //std::vector res;//resource list + std::map > res; //player ID => resource value[res_id] + std::vector cres;//creatures to be placed in towns ui32 day; bool resetBuilded; diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index e03a30d27..3e50f133a 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -42,12 +42,12 @@ DLL_EXPORT void SetResource::applyGs( CGameState *gs ) gs->getPlayer(player)->resources[resid] = val; } -DLL_EXPORT void SetResources::applyGs( CGameState *gs ) -{ - assert(player < PLAYER_LIMIT); - for(int i=0;igetPlayer(player)->resources[i] = res[i]; -} + DLL_EXPORT void SetResources::applyGs( CGameState *gs ) + { + assert(player < PLAYER_LIMIT); + for(int i=0;igetPlayer(player)->resources[i] = res[i]; + } DLL_EXPORT void SetPrimSkill::applyGs( CGameState *gs ) { @@ -546,8 +546,13 @@ DLL_EXPORT void NewTurn::applyGs( CGameState *gs ) hero->mana = h.mana; } - BOOST_FOREACH(SetResources h, res) //give resources - h.applyGs(gs); + for(std::map >::iterator i = res.begin(); i != res.end(); i++) + { + assert(i->first < PLAYER_LIMIT); + std::vector &playerRes = gs->getPlayer(i->first)->resources; + for(int j = 0; j < i->second.size(); j++) + playerRes[j] = i->second[j]; + } BOOST_FOREACH(SetAvailableCreatures h, cres) //set available creatures in towns h.applyGs(gs); @@ -748,7 +753,8 @@ DLL_EXPORT void StartAction::applyGs( CGameState *gs ) break; } - st->state -= WAITING; //if stack was waiting it has made move, so it won't be "waiting" anymore (if the action was WAIT, then we have returned) + if(st) + st->state -= WAITING; //if stack was waiting it has made move, so it won't be "waiting" anymore (if the action was WAIT, then we have returned) } DLL_EXPORT void SpellCast::applyGs( CGameState *gs ) diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 857121478..d2f8ada8f 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -801,10 +801,12 @@ void CGameHandler::newTurn() sendAndApply(&sah); } if(i->first>=PLAYER_LIMIT) continue; - SetResources r; - r.player = i->first; - for(int j=0;jsecond.resources[j]; + + n.res[i->first] = i->second.resources; +// SetResources r; +// r.player = i->first; +// for(int j=0;jsecond.resources[j]; BOOST_FOREACH(CGHeroInstance *h, (*i).second.heroes) { @@ -827,25 +829,26 @@ void CGameHandler::newTurn() switch(h->getSecSkillLevel(13)) //handle estates - give gold { case 1: //basic - r.res[6] += 125; + n.res[i->first][6] += 125; break; case 2: //advanced - r.res[6] += 250; + n.res[i->first][6] += 250; break; case 3: //expert - r.res[6] += 500; + n.res[i->first][6] += 500; break; } - for(std::list::iterator i = h->bonuses.begin(); i != h->bonuses.end(); i++) - if(i->type == HeroBonus::GENERATE_RESOURCE) - r.res[i->subtype] += i->val; + for(std::list::iterator j = h->bonuses.begin(); j != h->bonuses.end(); j++) + if(j->type == HeroBonus::GENERATE_RESOURCE) + n.res[i->first][j->subtype] += j->val; } } - n.res.push_back(r); + //n.res.push_back(r); } for(std::vector::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 { SetAvailableCreatures sac; @@ -862,24 +865,23 @@ void CGameHandler::newTurn() } n.cres.push_back(sac); } - if(gs->day && (*j)->tempOwner < PLAYER_LIMIT)//not the first day and town not neutral + if(gs->day && player < PLAYER_LIMIT)//not the first day and town not neutral { - SetResources r; - r.player = (**j).tempOwner; + ////SetResources r; + //r.player = (**j).tempOwner; if(vstd::contains((**j).builtBuildings,15)) //there is resource silo { if((**j).town->primaryRes == 127) //we'll give wood and ore { - r.res[0] += 1; - r.res[2] += 1; + n.res[player][0] += 1; + n.res[player][2] += 1; } else { - r.res[(**j).town->primaryRes] += 1; + n.res[player][(**j).town->primaryRes] += 1; } } - r.res[6] += (**j).dailyIncome(); - n.res.push_back(r); + n.res[player][6] += (**j).dailyIncome(); } } @@ -2493,6 +2495,7 @@ bool CGameHandler::queryReply( ui32 qid, ui32 answer ) bool CGameHandler::makeBattleAction( BattleAction &ba ) { + tlog1 << "\tMaking action of type " << ba.actionType << std::endl; bool ok = true; switch(ba.actionType) {