Przeglądaj źródła

[programming challenge] Added battleGetDistancesFromHex as a fixed variant of battleGetDistances (that uses its second argument — hex).

Michał W. Urbańczyk 14 lat temu
rodzic
commit
e337eb681d
2 zmienionych plików z 11 dodań i 4 usunięć
  1. 7 3
      lib/IGameCallback.cpp
  2. 4 1
      lib/IGameCallback.h

+ 7 - 3
lib/IGameCallback.cpp

@@ -55,6 +55,11 @@ si8 CBattleInfoCallback::battleCanTeleportTo(const CStack * stack, THex destHex,
 }
 
 std::vector<int> CBattleInfoCallback::battleGetDistances(const CStack * stack, THex hex /*= THex::INVALID*/, THex * predecessors /*= NULL*/)
+{
+	return battleGetDistancesFromHex(stack, stack->position, predecessors);
+}
+
+std::vector<int> CBattleInfoCallback::battleGetDistancesFromHex(const CStack * stack, THex hex /*= THex::INVALID*/, THex * predecessors /*= NULL*/)
 {
 	if(!hex.isValid())
 		hex = stack->position;
@@ -65,7 +70,7 @@ std::vector<int> CBattleInfoCallback::battleGetDistances(const CStack * stack, T
 	gs->curB->getAccessibilityMap(ac, stack->doubleWide(), stack->attackerOwned, false, occupyable, stack->hasBonusOfType(Bonus::FLYING), stack);
 	THex pr[BFIELD_SIZE];
 	int dist[BFIELD_SIZE];
-	gs->curB->makeBFS(stack->position, ac, pr, dist, stack->doubleWide(), stack->attackerOwned, stack->hasBonusOfType(Bonus::FLYING), false);
+	gs->curB->makeBFS(hex, ac, pr, dist, stack->doubleWide(), stack->attackerOwned, stack->hasBonusOfType(Bonus::FLYING), false);
 
 	for(int i=0; i<BFIELD_SIZE; ++i)
 	{
@@ -82,6 +87,7 @@ std::vector<int> CBattleInfoCallback::battleGetDistances(const CStack * stack, T
 
 	return ret;
 }
+
 std::set<THex> CBattleInfoCallback::battleGetAttackedHexes(const CStack* attacker, THex destinationTile, THex attackerPos  /*= THex::INVALID*/)
 {
 	if(!gs->curB)
@@ -370,8 +376,6 @@ const CGHeroInstance * CBattleInfoCallback::battleGetFightingHero(ui8 side) cons
 	return gs->curB->heroes[side];
 }
 
-
-
 CGameState *const CPrivilagedInfoCallback::gameState ()
 { 
 	return gs;

+ 4 - 1
lib/IGameCallback.h

@@ -120,9 +120,12 @@ public:
 ///	 returns numbers of hexes reachable by creature with id ID
 	std::vector<THex> battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector<THex> * attackable = NULL); 
 
-///	 returns vector of distances to [dest hex number]
+///	 returns vector of distances to [dest hex number]; WARNING: second argument is ignored
 	std::vector<int> battleGetDistances(const CStack * stack, THex hex = THex::INVALID, THex * predecessors = NULL); 
 
+	///	 returns vector of distances to [dest hex number]
+	std::vector<int> battleGetDistancesFromHex(const CStack * stack, THex hex = THex::INVALID, THex * predecessors = NULL); 
+
 	std::set<THex> battleGetAttackedHexes(const CStack* attacker, THex destinationTile, THex attackerPos = THex::INVALID);
 ///	 returns true if unit with id ID can shoot to dest
 	bool battleCanShoot(const CStack * stack, THex dest);