From 2710017049f3326959a7d08298a1b45022f1e070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Tue, 31 Mar 2009 20:47:53 +0000 Subject: [PATCH] * First Aid Tent won't get move * presumably fixed crash occurring sometimes on battle end * fixed problems when attacking with two-hex creature another two-hex creature, when tile before our destination was blocked * minor changes --- AI/GeniusAI/CGeniusAI.cpp | 2 +- AI/GeniusAI/CGeniusAI.h | 2 +- CGameInterface.h | 6 +-- CPlayerInterface.cpp | 16 +++---- CPlayerInterface.h | 8 ++-- client/NetPacksClient.cpp | 4 +- hch/CCreatureHandler.cpp | 3 +- lib/NetPacks.h | 5 ++- map.cpp | 9 ---- server/CGameHandler.cpp | 93 +++++---------------------------------- 10 files changed, 35 insertions(+), 113 deletions(-) diff --git a/AI/GeniusAI/CGeniusAI.cpp b/AI/GeniusAI/CGeniusAI.cpp index 00370c849..3a912aaae 100644 --- a/AI/GeniusAI/CGeniusAI.cpp +++ b/AI/GeniusAI/CGeniusAI.cpp @@ -136,7 +136,7 @@ void CGeniusAI::battleNewRound(int round) /** * */ -void CGeniusAI::battleStackMoved(int ID, int dest) +void CGeniusAI::battleStackMoved(int ID, int dest, int distance, bool end) { std::string message("\t\t\tCGeniusAI::battleStackMoved ID("); message += boost::lexical_cast(ID); diff --git a/AI/GeniusAI/CGeniusAI.h b/AI/GeniusAI/CGeniusAI.h index 4427070be..9fd005c8f 100644 --- a/AI/GeniusAI/CGeniusAI.h +++ b/AI/GeniusAI/CGeniusAI.h @@ -200,7 +200,7 @@ public: virtual void battleStacksAttacked(std::set & bsa); //called when stack receives damage (after battleAttack()) virtual void battleEnd(BattleResult *br); virtual void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - virtual void battleStackMoved(int ID, int dest); + virtual void battleStackMoved(int ID, int dest, int distance, bool end); virtual void battleSpellCasted(SpellCasted *sc); virtual void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right virtual void battlefieldPrepared(int battlefieldType, std::vector obstacles); //called when battlefield is prepared, prior the battle beginning diff --git a/CGameInterface.h b/CGameInterface.h index cf6759da9..ccd7981df 100644 --- a/CGameInterface.h +++ b/CGameInterface.h @@ -69,8 +69,8 @@ public: virtual void init(ICallback * CB){}; virtual void receivedResource(int type, int val){}; virtual void showInfoDialog(const std::string &text, const std::vector &components){}; - virtual void showSelDialog(std::string &text, const std::vector &components, ui32 askID){}; - virtual void showYesNoDialog(std::string &text, const std::vector &components, ui32 askID){}; + virtual void showSelDialog(const std::string &text, const std::vector &components, ui32 askID){}; + virtual void showYesNoDialog(const std::string &text, const std::vector &components, ui32 askID){}; virtual void tileHidden(const std::set &pos){}; virtual void tileRevealed(const std::set &pos){}; virtual void yourTurn(){}; @@ -87,7 +87,7 @@ public: virtual void battleStacksAttacked(std::set & bsa){}; //called when stack receives damage (after battleAttack()) virtual void battleEnd(BattleResult *br){}; virtual void battleNewRound(int round){}; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - virtual void battleStackMoved(int ID, int dest, int distance){}; + virtual void battleStackMoved(int ID, int dest, int distance, bool end){}; virtual void battleSpellCasted(SpellCasted *sc){}; virtual void battleStacksEffectsSet(SetStackEffect & sse){};//called when a specific effect is set to stacks virtual void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side){}; //called by engine when battle starts; side=0 - left, side=1 - right diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 115ac4e94..5b33b3678 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -2018,7 +2018,7 @@ void CPlayerInterface::receivedResource(int type, int val) castleInt->resdatabar->draw(); } -void CPlayerInterface::showSelDialog(std::string &text, const std::vector &components, ui32 askID) +void CPlayerInterface::showSelDialog(const std::string &text, const std::vector &components, ui32 askID) //void CPlayerInterface::showSelDialog(std::string text, std::vector & components, int askID) { boost::unique_lock un(*pim); @@ -2301,10 +2301,10 @@ void CPlayerInterface::battleResultQuited() LOCPLINT->showingDialog->setn(false); } -void CPlayerInterface::battleStackMoved(int ID, int dest, int distance) +void CPlayerInterface::battleStackMoved(int ID, int dest, int distance, bool end) { boost::unique_lock un(*pim); - battleInt->stackMoved(ID, dest, dest==curAction->destinationTile, distance); + battleInt->stackMoved(ID, dest, end, distance); } void CPlayerInterface::battleSpellCasted(SpellCasted *sc) { @@ -2391,7 +2391,7 @@ void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector std::vector > > pom; pom.push_back(std::pair >("IOKAY.DEF",0)); - CInfoWindow * temp = new CInfoWindow(text,playerID,32,components,pom); + CInfoWindow * temp = new CInfoWindow(text,playerID,36,components,pom); if(makingTurn && curint) { @@ -2409,7 +2409,7 @@ void CPlayerInterface::showInfoDialog(const std::string &text, const std::vector dialogs.push_back(temp); } } -void CPlayerInterface::showYesNoDialog(std::string &text, const std::vector & components, CFunctionList onYes, CFunctionList onNo, bool deactivateCur, bool DelComps) +void CPlayerInterface::showYesNoDialog(const std::string &text, const std::vector & components, CFunctionList onYes, CFunctionList onNo, bool deactivateCur, bool DelComps) { boost::unique_lock un(*pim); LOCPLINT->showingDialog->setn(true); @@ -2418,7 +2418,7 @@ void CPlayerInterface::showYesNoDialog(std::string &text, const std::vector > > pom; pom.push_back(std::pair >("IOKAY.DEF",0)); pom.push_back(std::pair >("ICANCEL.DEF",0)); - CInfoWindow * temp = new CInfoWindow(text,playerID,32,components,pom); + CInfoWindow * temp = new CInfoWindow(text,playerID,36,components,pom); temp->delComps = DelComps; for(int i=0;ibuttons[0]->callback += onYes.funcs[i]; @@ -2433,7 +2433,7 @@ void CPlayerInterface::showYesNoDialog(std::string &text, const std::vectorobjsToBlit.push_back(temp); } -void CPlayerInterface::showYesNoDialog( std::string &text, const std::vector &components, ui32 askID ) +void CPlayerInterface::showYesNoDialog(const std::string &text, const std::vector &components, ui32 askID ) { boost::unique_lock un(*pim); LOCPLINT->showingDialog->setn(false); @@ -2446,7 +2446,7 @@ void CPlayerInterface::showYesNoDialog( std::string &text, const std::vector >("IOKAY.DEF",0)); pom.push_back(std::pair >("ICANCEL.DEF",0)); - CInfoWindow * temp = new CInfoWindow(text,playerID,32,intComps,pom); + CInfoWindow * temp = new CInfoWindow(text,playerID,36,intComps,pom); temp->buttons[0]->callback += boost::bind(&IActivable::activate,curint); temp->buttons[1]->callback += boost::bind(&IActivable::activate,curint); temp->buttons[0]->callback += boost::bind(&CCallback::selectionMade,cb,0,askID); diff --git a/CPlayerInterface.h b/CPlayerInterface.h index b39c2120d..3eda80dd7 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -539,8 +539,8 @@ public: void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town); void receivedResource(int type, int val); void showInfoDialog(const std::string &text, const std::vector &components); - void showSelDialog(std::string &text, const std::vector &components, ui32 askID); - void showYesNoDialog(std::string &text, const std::vector &components, ui32 askID); + void showSelDialog(const std::string &text, const std::vector &components, ui32 askID); + void showYesNoDialog(const std::string &text, const std::vector &components, ui32 askID); void tileHidden(const std::set &pos); void tileRevealed(const std::set &pos); void yourTurn(); @@ -557,7 +557,7 @@ public: void battleEnd(BattleResult *br); //end of battle void battleResultQuited(); void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - void battleStackMoved(int ID, int dest, int distance); + void battleStackMoved(int ID, int dest, int distance, bool end); void battleSpellCasted(SpellCasted *sc); void battleStacksEffectsSet(SetStackEffect & sse); //called when a specific effect is set to stacks void battleStacksAttacked(std::set & bsa); @@ -581,7 +581,7 @@ public: int3 repairScreenPos(int3 pos); //returns position closest to pos we can center screen on void removeObjToBlit(IShowable* obj); void showInfoDialog(const std::string &text, const std::vector & components, bool deactivateCur=true); - void showYesNoDialog(std::string &text, const std::vector & components, CFunctionList onYes, CFunctionList onNo, bool deactivateCur, bool DelComps); //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close + void showYesNoDialog(const std::string &text, const std::vector & components, CFunctionList onYes, CFunctionList onNo, bool deactivateCur, bool DelComps); //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close bool moveHero(const CGHeroInstance *h, CPath * path); CPlayerInterface(int Player, int serial);//c-tor diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index d32e41997..ef4924a07 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -330,8 +330,8 @@ void BattleResult::applyFirstCl( CClient *cl ) void BattleStackMoved::applyFirstCl( CClient *cl ) { - INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStackMoved,stack,tile,distance); - INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStackMoved,stack,tile,distance); + INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side1,battleStackMoved,stack,tile,distance,ending); + INTERFACE_CALL_IF_PRESENT(GS(cl)->curB->side2,battleStackMoved,stack,tile,distance,ending); } void BattleStackAttacked::applyCl( CClient *cl ) diff --git a/hch/CCreatureHandler.cpp b/hch/CCreatureHandler.cpp index 3eda5f017..389b54759 100644 --- a/hch/CCreatureHandler.cpp +++ b/hch/CCreatureHandler.cpp @@ -464,8 +464,9 @@ void CCreatureHandler::loadCreatures() creatures[47].abilities += MULTI_HEAD_ATTACK; //cerberus - creatures[88].abilities += TWICE_ATTACK; //wolf raider + creatures[87].abilities += TWICE_ATTACK; //wolf raider + creatures[147].abilities += NOT_ACTIVE; //First Aid Tent //TODO: remove when support is added creatures[148].abilities += NOT_ACTIVE; //Ammo Cart } diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 3271f7c15..99aed46bc 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -647,13 +647,14 @@ struct BattleResult : public CPackForClient//3003 struct BattleStackMoved : public CPackForClient//3004 { - ui32 stack, tile, distance; + ui32 stack, tile; + ui8 ending, distance; BattleStackMoved(){type = 3004;}; void applyFirstCl(CClient *cl); void applyGs(CGameState *gs); template void serialize(Handler &h, const int version) { - h & stack & tile & distance; + h & stack & tile & ending & distance; } }; diff --git a/map.cpp b/map.cpp index feb65f212..52a6cdd58 100644 --- a/map.cpp +++ b/map.cpp @@ -1041,15 +1041,6 @@ void Mapa::readHeader( unsigned char * bufor, int &i) for (int zz=0; zzcreh->creatures[i->first].hitPoints * i->second; } } -//bool CGameState::checkFunc(int obid, std::string name) -//{ -// if (objscr.find(obid)!=objscr.end()) -// { -// if(objscr[obid].find(name)!=objscr[obid].end()) -// { -// return true; -// } -// } -// return false; -//} + PlayerStatus PlayerStatuses::operator[](ui8 player) { boost::unique_lock l(mx); @@ -205,15 +195,7 @@ void PlayerStatuses::removeQuery(ui8 player, ui32 id) } cv.notify_all(); } -//void CGameHandler::handleCPPObjS(std::map * mapa, CCPPObjectScript * script) -//{ -// std::vector tempv = script->yourObjects(); -// for (unsigned i=0;i void callWith(std::vector args, boost::function fun, ui32 which) { @@ -387,6 +369,7 @@ void CGameHandler::startBattle(CCreatureSet army1, CCreatureSet army2, int3 tile askInterfaceForMove: //ask interface and wait for answer + if(!battleResult.get()) { BattleSetActiveStack sas; sas.stack = next->ID; @@ -396,6 +379,11 @@ askInterfaceForMove: battleMadeAction.cond.wait(lock); battleMadeAction.data = false; } + else + { + break; + } + //we're after action, all results applied checkForBattleEnd(stacks); //check if this action ended the battle @@ -571,6 +559,7 @@ void CGameHandler::moveStack(int stack, int dest) sm.stack = curStack->ID; sm.tile = path.first[0]; sm.distance = path.second; + sm.ending = true; sendAndApply(&sm); } } @@ -584,6 +573,7 @@ void CGameHandler::moveStack(int stack, int dest) sm.stack = curStack->ID; sm.tile = path.first[v]; sm.distance = path.second; + sm.ending = v==tilesToMove; sendAndApply(&sm); } } @@ -610,32 +600,6 @@ void CGameHandler::init(StartInfo *si, int Seed) gs->init(si,map,Seed); tlog0 << "Gamestate initialized!" << std::endl; - /****************************LUA OBJECT SCRIPTS************************************************/ - //std::vector * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files - //for (int i=0; isize(); i++) - //{ - // try - // { - // std::vector * temp = CLuaHandler::functionList((*lf)[i]); - // CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]); - // CLuaCallback::registerFuncs(objs->is); - // //objs - // for (int j=0; jsize(); j++) - // { - // int obid ; //obj ID - // int dspos = (*temp)[j].find_first_of('_'); - // obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str()); - // std::string fname = (*temp)[j].substr(0,dspos); - // if (skrypty->find(obid)==skrypty->end()) - // skrypty->insert(std::pair >(obid,std::map())); - // (*skrypty)[obid].insert(std::pair(fname,objs)); - // } - // delete temp; - // }HANDLE_EXCEPTION - //} - - //delete lf; - for(std::map::iterator i = gs->players.begin(); i != gs->players.end(); i++) states.addPlayer(i->first); } @@ -768,42 +732,6 @@ void CGameHandler::run(bool resume) boost::thread(boost::bind(&CGameHandler::handleConnection,this,pom,boost::ref(**i))); } - /****************************SCRIPTS************************************************/ - //std::map > * skrypty = &objscr; //alias for easier access - /****************************C++ OBJECT SCRIPTS************************************************/ - //std::map scripts; - //CScriptCallback * csc = new CScriptCallback(); - //csc->gh = this; - //handleCPPObjS(&scripts,new CVisitableOPH(csc)); - //handleCPPObjS(&scripts,new CVisitableOPW(csc)); - //handleCPPObjS(&scripts,new CPickable(csc)); - //handleCPPObjS(&scripts,new CMines(csc)); - //handleCPPObjS(&scripts,new CTownScript(csc)); - //handleCPPObjS(&scripts,new CHeroScript(csc)); - //handleCPPObjS(&scripts,new CMonsterS(csc)); - //handleCPPObjS(&scripts,new CCreatureGen(csc)); - //handleCPPObjS(&scripts,new CTeleports(csc)); - - /****************************INITIALIZING OBJECT SCRIPTS************************************************/ - //std::string temps("newObject"); - //for (unsigned i=0; imap->objects.size(); i++) - //{ - //c++ scripts - //if (scripts.find(gs->map->objects[i]->ID) != scripts.end()) - //{ - // gs->map->objects[i]->state = scripts[gs->map->objects[i]->ID]; - // gs->map->objects[i]->state->newObject(gs->map->objects[i]->id); - //} - //else - //{ - // gs->map->objects[i]->state = NULL; - //} - - //// lua scripts - //if(checkFunc(map->objects[i]->ID,temps)) - // (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]); - //} - while (!end2) { if(!resume) @@ -1450,6 +1378,7 @@ void CGameHandler::ask( Query * sel, ui8 player, const CFunctionList void CGameHandler::sendToAllClients( CPackForClient * info ) { + tlog5 << "Sending to all clients a package of type " << typeid(*info).name() << std::endl; for(std::set::iterator i=conns.begin(); i!=conns.end();i++) { (*i)->wmx->lock();