Michał W. Urbańczyk 15 gadi atpakaļ
vecāks
revīzija
e677cd5b07

+ 2 - 2
AI/GeniusAI/BattleLogic.cpp

@@ -641,7 +641,7 @@ BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID)
  */
 list<int> 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<int> creatures;
 
@@ -658,7 +658,7 @@ list<int> 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);
 				}

+ 3 - 59
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 <ui16 N> bool isType(CPack *pack)
 {
 	return pack->getType() == N;
@@ -500,12 +494,6 @@ std::vector<CObstacleInstance> CCallback::battleGetAllObstacles()
 		return std::vector<CObstacleInstance>();
 }
 
-int CCallback::battleGetStack(int pos, bool onlyAlive)
-{
-	boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
-	return gs->battleGetStack(pos, onlyAlive);
-}
-
 const CStack* CCallback::battleGetStackByID(int ID, bool onlyAlive)
 {
 	boost::shared_lock<boost::shared_mutex> 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<boost::shared_mutex> 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<const CStack *> &out, int howMany )
 	gs->curB->getStackQueue(out, howMany);
 }
 
-CCreature CCallback::battleGetCreature(int number)
-{
-	boost::shared_lock<boost::shared_mutex> lock(*gs->mx); //TODO use me?
-	if(!gs->curB)
-	{
-		tlog2<<"battleGetCreature called when there is no battle!"<<std::endl;
-	}
-	for(size_t h=0; h<gs->curB->stacks.size(); ++h)
-	{
-		if(gs->curB->stacks[h]->ID == number) //creature found
-			return *(gs->curB->stacks[h]->getCreature());
-	}
-#ifndef __GNUC__
-	throw new std::exception("Cannot find the creature");
-#else
-	throw new std::exception();
-#endif
-}
-
 std::vector<int> CCallback::battleGetAvailableHexes(int ID, bool addOccupiable)
 {
 	boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
@@ -599,22 +569,6 @@ std::vector<int> CCallback::battleGetAvailableHexes(int ID, bool addOccupiable)
 	//return gs->battleGetRange(ID);
 }
 
-bool CCallback::battleIsStackMine(int ID)
-{
-	boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
-	if(!gs->curB)
-	{
-		tlog2<<"battleIsStackMine called when there is no battle!"<<std::endl;
-		return false;
-	}
-	for(size_t h=0; h<gs->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<boost::shared_mutex> 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;

+ 0 - 21
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<CObstacleInstance> 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::vector<const CStack*> battleGetStacks()=0; //returns stacks on battlefield
 	virtual void getStackQueue( std::vector<const CStack *> &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<int> 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<ui32, ui32> 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 <min dmg, max dmg>
 	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<CObstacleInstance> 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::vector<const CStack*> battleGetStacks(); //returns stacks on battlefield
 	void getStackQueue( std::vector<const CStack *> &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<int> 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<ui32, ui32> 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 <min dmg, max dmg>
 	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

+ 0 - 8
CGameInterface.h

@@ -5,7 +5,6 @@
 #include <vector>
 #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 <typename Serializer> class CISer;
 template <typename Serializer> class COSer;
 
-class CObstacle
-{
-	int ID;
-	int position;
-	//TODO: add some kind of the blockmap
-};
-
 class CGameInterface
 {
 public:

+ 1 - 0
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

+ 7 - 6
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"
@@ -3588,7 +3589,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())
 		{
@@ -3617,14 +3618,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));
 		}
 	}
 }

+ 1 - 0
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"

+ 1 - 0
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"

+ 1 - 0
client/Client.cpp

@@ -1,3 +1,4 @@
+#include "../hch/CMusicHandler.h"
 #include "../hch/CCampaignHandler.h"
 #include "../CCallback.h"
 #include "../CConsoleHandler.h"