1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-29 21:56:54 +02:00

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.
This commit is contained in:
Michał W. Urbańczyk 2009-11-28 01:42:08 +00:00
parent 82faf7538e
commit 7f97a56a28
8 changed files with 95 additions and 85 deletions

View File

@ -1028,31 +1028,31 @@ void CGeniusAI::yourTurn()
m_cb->waitTillRealize = true; m_cb->waitTillRealize = true;
static int seed = rand(); static int seed = rand();
srand(seed); srand(seed);
if (m_cb->getDate() == 1) { // if (m_cb->getDate() == 1) {
// startFirstTurn(); // // startFirstTurn();
//
// m_cb->endTurn(); // // m_cb->endTurn();
// return; // // return;
} // }
//////////////TODO: replace with updates. Also add suspected objects list.///////// // //////////////TODO: replace with updates. Also add suspected objects list./////////
knownVisitableObjects.clear(); // knownVisitableObjects.clear();
int3 pos = m_cb->getMapSize(); // int3 pos = m_cb->getMapSize();
for (int x = 0; x < pos.x; x++) { // for (int x = 0; x < pos.x; x++) {
for (int y = 0; y < pos.y; y++) { // for (int y = 0; y < pos.y; y++) {
for (int z = 0; z < pos.z; z++) // for (int z = 0; z < pos.z; z++)
tileRevealed(int3(x,y,z)); // tileRevealed(int3(x,y,z));
} // }
} // }
/////////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////////
//
reportResources(); // reportResources();
//
trueGameState = HypotheticalGameState(*this); // trueGameState = HypotheticalGameState(*this);
AIObjective * objective; // AIObjective * objective;
while ((objective = getBestObjective()) != NULL) // while ((objective = getBestObjective()) != NULL)
objective->fulfill(*this,trueGameState); // objective->fulfill(*this,trueGameState);
//
seed = rand(); // seed = rand();
m_cb->endTurn(); m_cb->endTurn();
m_cb->waitTillRealize = false; m_cb->waitTillRealize = false;
} }

View File

@ -1455,17 +1455,6 @@ void CBattleInterface::show(SDL_Surface * to)
SDL_SetClipRect(to, &buf); //restoring previous clip_rect 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 //prevents blitting outside this window
SDL_GetClipRect(to, &buf); SDL_GetClipRect(to, &buf);
SDL_SetClipRect(to, &pos); SDL_SetClipRect(to, &pos);
@ -1611,6 +1600,17 @@ void CBattleInterface::show(SDL_Surface * to)
blitAt(menu, pos.x, 556 + pos.y, to); blitAt(menu, pos.x, 556 + pos.y, to);
console->show(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 //showing window with result of battle
if(resWindow) if(resWindow)
{ {

View File

@ -20,7 +20,7 @@ typedef boost::int8_t si8; //signed int 8 bits (1 byte)
#define THC #define THC
#endif #endif
#define NAME_VER ("VCMI 0.74b") #define NAME_VER ("VCMI 0.74c")
extern std::string NAME; //full name extern std::string NAME; //full name
extern std::string NAME_AFFIX; //client / server extern std::string NAME_AFFIX; //client / server
#define CONSOLE_LOGGING_LEVEL 5 #define CONSOLE_LOGGING_LEVEL 5

View File

@ -246,16 +246,16 @@ CLoadFile::CLoadFile( const std::string &fname )
if(std::memcmp(buffer,"VCMI",4)) 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; delete sfile;
sfile = NULL; sfile = NULL;
return; return;
} }
*this >> myVersion; *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; delete sfile;
sfile = NULL; sfile = NULL;
} }

View File

@ -20,7 +20,7 @@
#include <boost/mpl/identity.hpp> #include <boost/mpl/identity.hpp>
#include <boost/type_traits/is_array.hpp> #include <boost/type_traits/is_array.hpp>
const ui32 version = 711; const ui32 version = 712;
class CConnection; class CConnection;
class CGObjectInstance; class CGObjectInstance;
class CGameState; class CGameState;

View File

@ -215,20 +215,20 @@ struct SetResource : public CPackForClient //102
h & player & resid & val; h & player & resid & val;
} }
}; };
struct SetResources : public CPackForClient //104 struct SetResources : public CPackForClient //104
{ {
SetResources(){res.resize(RESOURCE_QUANTITY);type = 104;}; SetResources(){res.resize(RESOURCE_QUANTITY);type = 104;};
void applyCl(CClient *cl); void applyCl(CClient *cl);
DLL_EXPORT void applyGs(CGameState *gs); DLL_EXPORT void applyGs(CGameState *gs);
ui8 player; ui8 player;
std::vector<si32> res; //res[resid] => res amount std::vector<si32> res; //res[resid] => res amount
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & player & res; h & player & res;
} }
}; };
struct SetPrimSkill : public CPackForClient //105 struct SetPrimSkill : public CPackForClient //105
{ {
@ -593,8 +593,9 @@ struct NewTurn : public CPackForClient //101
}; };
std::set<Hero> heroes; //updates movement and mana points std::set<Hero> heroes; //updates movement and mana points
std::vector<SetResources> res;//resource list //std::vector<SetResources> res;//resource list
std::vector<SetAvailableCreatures> cres;//resource list std::map<ui8, std::vector<si32> > res; //player ID => resource value[res_id]
std::vector<SetAvailableCreatures> cres;//creatures to be placed in towns
ui32 day; ui32 day;
bool resetBuilded; bool resetBuilded;

View File

@ -42,12 +42,12 @@ DLL_EXPORT void SetResource::applyGs( CGameState *gs )
gs->getPlayer(player)->resources[resid] = val; gs->getPlayer(player)->resources[resid] = val;
} }
DLL_EXPORT void SetResources::applyGs( CGameState *gs ) DLL_EXPORT void SetResources::applyGs( CGameState *gs )
{ {
assert(player < PLAYER_LIMIT); assert(player < PLAYER_LIMIT);
for(int i=0;i<res.size();i++) for(int i=0;i<res.size();i++)
gs->getPlayer(player)->resources[i] = res[i]; gs->getPlayer(player)->resources[i] = res[i];
} }
DLL_EXPORT void SetPrimSkill::applyGs( CGameState *gs ) DLL_EXPORT void SetPrimSkill::applyGs( CGameState *gs )
{ {
@ -546,8 +546,13 @@ DLL_EXPORT void NewTurn::applyGs( CGameState *gs )
hero->mana = h.mana; hero->mana = h.mana;
} }
BOOST_FOREACH(SetResources h, res) //give resources for(std::map<ui8, std::vector<si32> >::iterator i = res.begin(); i != res.end(); i++)
h.applyGs(gs); {
assert(i->first < PLAYER_LIMIT);
std::vector<si32> &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 BOOST_FOREACH(SetAvailableCreatures h, cres) //set available creatures in towns
h.applyGs(gs); h.applyGs(gs);
@ -748,7 +753,8 @@ DLL_EXPORT void StartAction::applyGs( CGameState *gs )
break; 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 ) DLL_EXPORT void SpellCast::applyGs( CGameState *gs )

View File

@ -801,10 +801,12 @@ void CGameHandler::newTurn()
sendAndApply(&sah); sendAndApply(&sah);
} }
if(i->first>=PLAYER_LIMIT) continue; if(i->first>=PLAYER_LIMIT) continue;
SetResources r;
r.player = i->first; n.res[i->first] = i->second.resources;
for(int j=0;j<RESOURCE_QUANTITY;j++) // SetResources r;
r.res[j] = i->second.resources[j]; // r.player = i->first;
// for(int j=0;j<RESOURCE_QUANTITY;j++)
// r.res[j] = i->second.resources[j];
BOOST_FOREACH(CGHeroInstance *h, (*i).second.heroes) BOOST_FOREACH(CGHeroInstance *h, (*i).second.heroes)
{ {
@ -827,25 +829,26 @@ void CGameHandler::newTurn()
switch(h->getSecSkillLevel(13)) //handle estates - give gold switch(h->getSecSkillLevel(13)) //handle estates - give gold
{ {
case 1: //basic case 1: //basic
r.res[6] += 125; n.res[i->first][6] += 125;
break; break;
case 2: //advanced case 2: //advanced
r.res[6] += 250; n.res[i->first][6] += 250;
break; break;
case 3: //expert case 3: //expert
r.res[6] += 500; n.res[i->first][6] += 500;
break; break;
} }
for(std::list<HeroBonus>::iterator i = h->bonuses.begin(); i != h->bonuses.end(); i++) for(std::list<HeroBonus>::iterator j = h->bonuses.begin(); j != h->bonuses.end(); j++)
if(i->type == HeroBonus::GENERATE_RESOURCE) if(j->type == HeroBonus::GENERATE_RESOURCE)
r.res[i->subtype] += i->val; n.res[i->first][j->subtype] += j->val;
} }
} }
n.res.push_back(r); //n.res.push_back(r);
} }
for(std::vector<CGTownInstance *>::iterator j = gs->map->towns.begin(); j!=gs->map->towns.end(); j++)//handle towns for(std::vector<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 if(gs->getDate(1)==7) //first day of week
{ {
SetAvailableCreatures sac; SetAvailableCreatures sac;
@ -862,24 +865,23 @@ void CGameHandler::newTurn()
} }
n.cres.push_back(sac); 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; ////SetResources r;
r.player = (**j).tempOwner; //r.player = (**j).tempOwner;
if(vstd::contains((**j).builtBuildings,15)) //there is resource silo if(vstd::contains((**j).builtBuildings,15)) //there is resource silo
{ {
if((**j).town->primaryRes == 127) //we'll give wood and ore if((**j).town->primaryRes == 127) //we'll give wood and ore
{ {
r.res[0] += 1; n.res[player][0] += 1;
r.res[2] += 1; n.res[player][2] += 1;
} }
else else
{ {
r.res[(**j).town->primaryRes] += 1; n.res[player][(**j).town->primaryRes] += 1;
} }
} }
r.res[6] += (**j).dailyIncome(); n.res[player][6] += (**j).dailyIncome();
n.res.push_back(r);
} }
} }
@ -2493,6 +2495,7 @@ bool CGameHandler::queryReply( ui32 qid, ui32 answer )
bool CGameHandler::makeBattleAction( BattleAction &ba ) bool CGameHandler::makeBattleAction( BattleAction &ba )
{ {
tlog1 << "\tMaking action of type " << ba.actionType << std::endl;
bool ok = true; bool ok = true;
switch(ba.actionType) switch(ba.actionType)
{ {