From ad48681d91d8d7b656e2d5d8326f6a7a305265a9 Mon Sep 17 00:00:00 2001 From: mateuszb Date: Wed, 8 Dec 2010 20:17:05 +0000 Subject: [PATCH] * cleanup --- AI/GeniusAI/BattleLogic.cpp | 4 +-- CCallback.cpp | 62 ++--------------------------------- CCallback.h | 21 ------------ CGameInterface.h | 8 ----- client/AdventureMapButton.cpp | 1 + client/CBattleInterface.cpp | 13 ++++---- client/CKingdomInterface.cpp | 1 + client/CPlayerInterface.cpp | 1 + client/Client.cpp | 1 + 9 files changed, 16 insertions(+), 96 deletions(-) diff --git a/AI/GeniusAI/BattleLogic.cpp b/AI/GeniusAI/BattleLogic.cpp index be7c00672..2ba13ff07 100644 --- a/AI/GeniusAI/BattleLogic.cpp +++ b/AI/GeniusAI/BattleLogic.cpp @@ -641,7 +641,7 @@ BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID) */ list CBattleLogic::PerformBerserkAttack(int stackID, int &additionalInfo) { - CCreature c = m_cb->battleGetCreature(stackID); + const CStack * c = m_cb->battleGetStackByID(stackID); // attack to make biggest damage list creatures; @@ -658,7 +658,7 @@ list CBattleLogic::PerformBerserkAttack(int stackID, int &additionalInfo) } for (creature_stat::const_iterator it2 = m_statDistance.begin(); it2 != m_statDistance.end(); ++it2) { - if (it2->first == it->first && it2->second - 1 <= c.valOfBonuses(Bonus::STACKS_SPEED)) + if (it2->first == it->first && it2->second - 1 <= c->getCreature()->valOfBonuses(Bonus::STACKS_SPEED)) { creatures.push_front(it->first); } diff --git a/CCallback.cpp b/CCallback.cpp index 69a5d9261..42a99c281 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -1,5 +1,6 @@ #include "stdafx.h" #include "CCallback.h" +#include "hch/CCreatureHandler.h" #include "client/CGameInfo.h" #include "lib/CGameState.h" #include "client/CPlayerInterface.h" @@ -35,13 +36,6 @@ * */ - -HeroMoveDetails::HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho) - :src(Src),dst(Dst),ho(Ho) -{ - owner = ho->getOwner(); -}; - template bool isType(CPack *pack) { return pack->getType() == N; @@ -500,12 +494,6 @@ std::vector CCallback::battleGetAllObstacles() return std::vector(); } -int CCallback::battleGetStack(int pos, bool onlyAlive) -{ - boost::shared_lock lock(*gs->mx); - return gs->battleGetStack(pos, onlyAlive); -} - const CStack* CCallback::battleGetStackByID(int ID, bool onlyAlive) { boost::shared_lock lock(*gs->mx); @@ -515,6 +503,7 @@ const CStack* CCallback::battleGetStackByID(int ID, bool onlyAlive) int CCallback::battleMakeAction(BattleAction* action) { + assert(action->actionType == BattleAction::HERO_SPELL); MakeCustomAction mca(*action); sendRequest(&mca); return 0; @@ -523,7 +512,7 @@ int CCallback::battleMakeAction(BattleAction* action) const CStack* CCallback::battleGetStackByPos(int pos, bool onlyAlive) { boost::shared_lock lock(*gs->mx); - return battleGetStackByID(battleGetStack(pos, onlyAlive), onlyAlive); + return battleGetStackByID(gs->battleGetStack(pos, onlyAlive), onlyAlive); } int CCallback::battleGetPos(int stack) @@ -568,25 +557,6 @@ void CCallback::getStackQueue( std::vector &out, int howMany ) gs->curB->getStackQueue(out, howMany); } -CCreature CCallback::battleGetCreature(int number) -{ - boost::shared_lock lock(*gs->mx); //TODO use me? - if(!gs->curB) - { - tlog2<<"battleGetCreature called when there is no battle!"<curB->stacks.size(); ++h) - { - if(gs->curB->stacks[h]->ID == number) //creature found - return *(gs->curB->stacks[h]->type); - } -#ifndef __GNUC__ - throw new std::exception("Cannot find the creature"); -#else - throw new std::exception(); -#endif -} - std::vector CCallback::battleGetAvailableHexes(int ID, bool addOccupiable) { boost::shared_lock lock(*gs->mx); @@ -599,22 +569,6 @@ std::vector CCallback::battleGetAvailableHexes(int ID, bool addOccupiable) //return gs->battleGetRange(ID); } -bool CCallback::battleIsStackMine(int ID) -{ - boost::shared_lock lock(*gs->mx); - if(!gs->curB) - { - tlog2<<"battleIsStackMine called when there is no battle!"<curB->stacks.size(); ++h) - { - if(gs->curB->stacks[h]->ID == ID) //creature found - return gs->curB->stacks[h]->owner == player; - } - return false; -} - bool CCallback::battleCanShoot(int ID, int dest) { boost::shared_lock lock(*gs->mx); @@ -941,16 +895,6 @@ void CCallback::dig( const CGObjectInstance *hero ) sendRequest(&dwh); } -si8 CCallback::battleGetStackMorale( int stackID ) -{ - return gs->curB->getStack(stackID)->MoraleVal(); -} - -si8 CCallback::battleGetStackLuck( int stackID ) -{ - return gs->curB->getStack(stackID)->LuckVal(); -} - void CCallback::castSpell(const CGHeroInstance *hero, int spellID, const int3 &pos) { CastAdvSpell cas; diff --git a/CCallback.h b/CCallback.h index 4acb47932..96b499093 100644 --- a/CCallback.h +++ b/CCallback.h @@ -161,17 +161,13 @@ public: virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield virtual std::vector battleGetAllObstacles()=0; //returns all obstacles on the battlefield - virtual int battleGetStack(int pos, bool onlyAlive)=0; //returns ID of stack on the tile virtual const CStack * battleGetStackByID(int ID, bool onlyAlive = true)=0; //returns stack info by given ID virtual const CStack * battleGetStackByPos(int pos, bool onlyAlive = true)=0; //returns stack info by given pos virtual int battleGetPos(int stack)=0; //returns position (tile ID) of stack virtual int battleMakeAction(BattleAction* action)=0;//for casting spells by hero - DO NOT use it for moving active stack virtual std::map battleGetStacks()=0; //returns stacks on battlefield virtual void getStackQueue( std::vector &out, int howMany )=0; //returns vector of stack in order of their move sequence - virtual CCreature battleGetCreature(int number)=0; //returns type of creature by given number of stack - //virtual bool battleMoveCreature(int ID, int dest)=0; //moves creature with id ID to dest if possible virtual std::vector battleGetAvailableHexes(int ID, bool addOccupiable)=0; //returns numbers of hexes reachable by creature with id ID - virtual bool battleIsStackMine(int ID)=0; //returns true if stack with id ID belongs to caller virtual bool battleCanShoot(int ID, int dest)=0; //returns true if unit with id ID can shoot to dest virtual bool battleCanCastSpell()=0; //returns true, if caller can cast a spell virtual bool battleCanFlee()=0; //returns true if caller can flee from the battle @@ -181,22 +177,10 @@ public: virtual std::pair battleEstimateDamage(int attackerID, int defenderID)=0; //estimates damage dealt by attacker to defender; it may be not precise especially when stack has randomly working bonuses; returns pair virtual ui8 battleGetSiegeLevel()=0; //returns 0 when there is no siege, 1 if fort, 2 is citadel, 3 is castle virtual const CGHeroInstance * battleGetFightingHero(ui8 side) const =0; //returns hero corresponding to given side (0 - attacker, 1 - defender) - virtual si8 battleGetStackMorale(int stackID) =0; //returns morale of given stack - virtual si8 battleGetStackLuck(int stackID) =0; //returns luck of given stack virtual si8 battleHasDistancePenalty(int stackID, int destHex) =0; //checks if given stack has distance penalty virtual si8 battleHasWallPenalty(int stackID, int destHex) =0; //checks if given stack has wall penalty }; -struct HeroMoveDetails -{ - HeroMoveDetails(){}; - HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho); - int3 src, dst; //source and destination points - CGHeroInstance * ho; //object instance of this hero - int owner, style; //style: 0 - normal move, 1 - teleport, 2 - instant jump - bool successful; -}; - class CCallback : public ICallback { private: @@ -292,16 +276,13 @@ public: int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship int battleGetObstaclesAtTile(int tile); //returns bitfield std::vector battleGetAllObstacles(); //returns all obstacles on the battlefield - int battleGetStack(int pos, bool onlyAlive = true); //returns ID of stack on the tile const CStack * battleGetStackByID(int ID, bool onlyAlive = true); //returns stack info by given ID const CStack * battleGetStackByPos(int pos, bool onlyAlive = true); //returns stack info by given pos int battleGetPos(int stack); //returns position (tile ID) of stack int battleMakeAction(BattleAction* action);//for casting spells by hero - DO NOT use it for moving active stack std::map battleGetStacks(); //returns stacks on battlefield void getStackQueue( std::vector &out, int howMany ); //returns vector of stack in order of their move sequence - CCreature battleGetCreature(int number); //returns type of creature by given number of stack std::vector battleGetAvailableHexes(int ID, bool addOccupiable); //reutrns numbers of hexes reachable by creature with id ID - bool battleIsStackMine(int ID); //returns true if stack with id ID belongs to caller bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest bool battleCanCastSpell(); //returns true, if caller can cast a spell bool battleCanFlee(); //returns true if caller can flee from the battle @@ -311,8 +292,6 @@ public: std::pair battleEstimateDamage(int attackerID, int defenderID); //estimates damage dealt by attacker to defender; it may be not precise especially when stack has randomly working bonuses; returns pair ui8 battleGetSiegeLevel(); //returns 0 when there is no siege, 1 if fort, 2 is citadel, 3 is castle const CGHeroInstance * battleGetFightingHero(ui8 side) const; //returns hero corresponding ot given side (0 - attacker, 1 - defender) - si8 battleGetStackMorale(int stackID); //returns morale of given stack - si8 battleGetStackLuck(int stackID); //returns luck of given stack si8 battleHasDistancePenalty(int stackID, int destHex); //checks if given stack has distance penalty si8 battleHasWallPenalty(int stackID, int destHex); //checks if given stack has wall penalty si8 battleCanTeleportTo(int stackID, int destHex, int telportLevel); //checks if teleportation of given stack to given position can take place diff --git a/CGameInterface.h b/CGameInterface.h index 71c8ad08a..efdae3c19 100644 --- a/CGameInterface.h +++ b/CGameInterface.h @@ -5,7 +5,6 @@ #include #include "lib/BattleAction.h" #include "client/FunctionList.h" -#include "hch/CMusicHandler.h" /* * CGameInterface.h, part of VCMI engine @@ -48,13 +47,6 @@ class CSaveFile; template class CISer; template class COSer; -class CObstacle -{ - int ID; - int position; - //TODO: add some kind of the blockmap -}; - class CGameInterface { public: diff --git a/client/AdventureMapButton.cpp b/client/AdventureMapButton.cpp index 17aacccd8..c727a8570 100644 --- a/client/AdventureMapButton.cpp +++ b/client/AdventureMapButton.cpp @@ -12,6 +12,7 @@ #include "CBattleInterface.h" #include "CPlayerInterface.h" #include "CMessage.h" +#include "../hch/CMusicHandler.h" /* * AdventureMapButton.cpp, part of VCMI engine diff --git a/client/CBattleInterface.cpp b/client/CBattleInterface.cpp index a5e9dbf91..d5fe48a8d 100644 --- a/client/CBattleInterface.cpp +++ b/client/CBattleInterface.cpp @@ -9,6 +9,7 @@ #include "../hch/CHeroHandler.h" #include "../hch/CDefHandler.h" #include "../hch/CSpellHandler.h" +#include "../hch/CMusicHandler.h" #include "CMessage.h" #include "CCursorHandler.h" #include "../CCallback.h" @@ -3585,7 +3586,7 @@ void CBattleHex::mouseMoved(const SDL_MouseMotionEvent &sEvent) if(hovered && strictHovered) //print attacked creature to console { - if(myInterface->console->alterTxt.size() == 0 && myInterface->curInt->cb->battleGetStack(myNumber) != -1 && + if(myInterface->console->alterTxt.size() == 0 && myInterface->curInt->cb->battleGetStackByID(myNumber) != NULL && myInterface->curInt->cb->battleGetStackByPos(myNumber)->owner != myInterface->curInt->playerID && myInterface->curInt->cb->battleGetStackByPos(myNumber)->alive()) { @@ -3614,14 +3615,14 @@ void CBattleHex::clickLeft(tribool down, bool previousState) void CBattleHex::clickRight(tribool down, bool previousState) { - int stID = myInterface->curInt->cb->battleGetStack(myNumber); //id of stack being on this tile - if(hovered && strictHovered && stID!=-1) + const CStack * myst = myInterface->curInt->cb->battleGetStackByPos(myNumber); //stack info + if(hovered && strictHovered && myst!=NULL) { - const CStack & myst = *myInterface->curInt->cb->battleGetStackByID(stID); //stack info - if(!myst.alive()) return; + + if(!myst->alive()) return; if(down) { - GH.pushInt(new CCreInfoWindow(myst)); + GH.pushInt(new CCreInfoWindow(*myst)); } } } diff --git a/client/CKingdomInterface.cpp b/client/CKingdomInterface.cpp index c8d4f43ce..cf73e64ad 100644 --- a/client/CKingdomInterface.cpp +++ b/client/CKingdomInterface.cpp @@ -17,6 +17,7 @@ #include "../hch/CGeneralTextHandler.h" #include "../hch/CObjectHandler.h" #include "../hch/CTownHandler.h" +#include "../hch/CCreatureHandler.h" #include "../hch/CHeroHandler.h" #include "../lib/map.h" #include "../lib/NetPacks.h" diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 21abb37d6..4d018cfaf 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -25,6 +25,7 @@ #include "../lib/Connection.h" #include "../hch/CSpellHandler.h" #include "../hch/CTownHandler.h" +#include "../hch/CMusicHandler.h" #include "../lib/CondSh.h" #include "../lib/NetPacks.h" #include "../lib/map.h" diff --git a/client/Client.cpp b/client/Client.cpp index 7fdd19bcc..a4e9f8dc8 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -1,3 +1,4 @@ +#include "../hch/CMusicHandler.h" #include "../hch/CCampaignHandler.h" #include "../CCallback.h" #include "../CConsoleHandler.h"