mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
A few upgrades and bugfixes in battles
This commit is contained in:
parent
d5a5a04811
commit
500f55cd52
@ -289,45 +289,52 @@ void CBattleInterface::stackMoved(int number, int destHex)
|
|||||||
|
|
||||||
void CBattleInterface::showRange(SDL_Surface * to, int initialPlace, int radius)
|
void CBattleInterface::showRange(SDL_Surface * to, int initialPlace, int radius)
|
||||||
{
|
{
|
||||||
int dists[187]; //calculated distances
|
int * dists = new int[187]; //calculated distances
|
||||||
std::queue<int> hexq; //bfs queue
|
std::queue<int> hexq; //bfs queue
|
||||||
hexq.push(initialPlace);
|
hexq.push(initialPlace);
|
||||||
for(int g=0; g<187; ++g)
|
for(int g=0; g<187; ++g)
|
||||||
dists[g] = 100000000;
|
dists[g] = 100000000;
|
||||||
dists[initialPlace] = 0;
|
dists[initialPlace] = 0;
|
||||||
|
int curNext = -1; //for bfs loop only (helper var)
|
||||||
while(!hexq.empty()) //bfs loop
|
while(!hexq.empty()) //bfs loop
|
||||||
{
|
{
|
||||||
int curHex = hexq.front();
|
int curHex = hexq.front();
|
||||||
hexq.pop();
|
hexq.pop();
|
||||||
if((curHex - 18 > 0) && bfield[curHex-18].accesible && (dists[curHex] + 1 < dists[curHex-18]) && (curHex-18)%17!=0 && (curHex-18)%17!=16) //top left
|
curNext = curHex - ( (curHex/17)%2 ? 17 : 18 );
|
||||||
|
if((curNext > 0) && bfield[curNext].accesible && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //top left
|
||||||
{
|
{
|
||||||
hexq.push(curHex - 18);
|
hexq.push(curNext);
|
||||||
dists[curHex-18] = dists[curHex] + 1;
|
dists[curNext] = dists[curHex] + 1;
|
||||||
}
|
}
|
||||||
if((curHex - 17 > 0) && bfield[curHex-17].accesible && (dists[curHex] + 1 < dists[curHex-17]) && (curHex-17)%17!=0 && (curHex-17)%17!=16) //top right
|
curNext = curHex - ( (curHex/17)%2 ? 16 : 17 );
|
||||||
|
if((curNext > 0) && bfield[curNext].accesible && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //top right
|
||||||
{
|
{
|
||||||
hexq.push(curHex - 17);
|
hexq.push(curNext);
|
||||||
dists[curHex-17] = dists[curHex] + 1;
|
dists[curNext] = dists[curHex] + 1;
|
||||||
}
|
}
|
||||||
if((curHex - 1 > 0) && bfield[curHex-1].accesible && (dists[curHex] + 1 < dists[curHex-1]) && (curHex-1)%17!=0 && (curHex-1)%17!=16) //left
|
curNext = curHex - 1;
|
||||||
|
if((curNext > 0) && bfield[curNext].accesible && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //left
|
||||||
{
|
{
|
||||||
hexq.push(curHex - 1);
|
hexq.push(curNext);
|
||||||
dists[curHex-1] = dists[curHex] + 1;
|
dists[curNext] = dists[curHex] + 1;
|
||||||
}
|
}
|
||||||
if((curHex + 1 < 187) && bfield[curHex+1].accesible && (dists[curHex] + 1 < dists[curHex+1]) && (curHex+1)%17!=0 && (curHex+1)%17!=16) //right
|
curNext = curHex + 1;
|
||||||
|
if((curNext < 187) && bfield[curNext].accesible && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //right
|
||||||
{
|
{
|
||||||
hexq.push(curHex + 1);
|
hexq.push(curNext);
|
||||||
dists[curHex+1] = dists[curHex] + 1;
|
dists[curNext] = dists[curHex] + 1;
|
||||||
}
|
}
|
||||||
if((curHex + 17 < 187) && bfield[curHex+17].accesible && (dists[curHex] + 1 < dists[curHex+17]) && (curHex+17)%17!=0 && (curHex+17)%17!=16) //bottom left
|
curNext = curHex + ( (curHex/17)%2 ? 16 : 17 );
|
||||||
|
if((curNext < 187) && bfield[curNext].accesible && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //bottom left
|
||||||
{
|
{
|
||||||
hexq.push(curHex + 17);
|
hexq.push(curNext);
|
||||||
dists[curHex+17] = dists[curHex] + 1;
|
dists[curNext] = dists[curHex] + 1;
|
||||||
}
|
}
|
||||||
if((curHex + 18 < 187) && bfield[curHex+18].accesible && (dists[curHex] + 1 < dists[curHex+18]) && (curHex+18)%17!=0 && (curHex+18)%17!=16) //bottom right
|
curNext = curHex + ( (curHex/17)%2 ? 17 : 18 );
|
||||||
|
if((curNext < 187) && bfield[curNext].accesible && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //bottom right
|
||||||
{
|
{
|
||||||
hexq.push(curHex + 18);
|
hexq.push(curNext);
|
||||||
dists[curHex+18] = dists[curHex] + 1;
|
dists[curNext] = dists[curHex] + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(int i=0; i<187; ++i)
|
for(int i=0; i<187; ++i)
|
||||||
@ -423,12 +430,14 @@ void CBattleHex::activate()
|
|||||||
{
|
{
|
||||||
Hoverable::activate();
|
Hoverable::activate();
|
||||||
MotionInterested::activate();
|
MotionInterested::activate();
|
||||||
|
ClickableL::activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBattleHex::deactivate()
|
void CBattleHex::deactivate()
|
||||||
{
|
{
|
||||||
Hoverable::deactivate();
|
Hoverable::deactivate();
|
||||||
MotionInterested::deactivate();
|
MotionInterested::deactivate();
|
||||||
|
ClickableL::deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBattleHex::hover(bool on)
|
void CBattleHex::hover(bool on)
|
||||||
@ -455,3 +464,7 @@ void CBattleHex::mouseMoved(SDL_MouseMotionEvent &sEvent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CBattleHex::clickLeft(boost::logic::tribool down)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
@ -22,7 +22,7 @@ public:
|
|||||||
~CBattleHero(); //d-tor
|
~CBattleHero(); //d-tor
|
||||||
};
|
};
|
||||||
|
|
||||||
class CBattleHex : public Hoverable, public MotionInterested
|
class CBattleHex : public Hoverable, public MotionInterested, public ClickableL
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
unsigned int myNumber;
|
unsigned int myNumber;
|
||||||
@ -35,6 +35,7 @@ public:
|
|||||||
void activate();
|
void activate();
|
||||||
void deactivate();
|
void deactivate();
|
||||||
void mouseMoved (SDL_MouseMotionEvent & sEvent);
|
void mouseMoved (SDL_MouseMotionEvent & sEvent);
|
||||||
|
void clickLeft(boost::logic::tribool down);
|
||||||
CBattleHex();
|
CBattleHex();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -552,7 +552,11 @@ std::map<int, CStack> CCallback::battleGetStacks()
|
|||||||
|
|
||||||
CCreature CCallback::battleGetCreature(int number)
|
CCreature CCallback::battleGetCreature(int number)
|
||||||
{
|
{
|
||||||
return *(CGI->state->curB->stacks[number]->creature);
|
for(int h=0; h<CGI->state->curB->stacks.size(); ++h)
|
||||||
|
{
|
||||||
|
if(CGI->state->curB->stacks[h]->ID == number) //creature found
|
||||||
|
return *(CGI->state->curB->stacks[h]->creature);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCallback::battleMoveCreature(int ID, int dest)
|
bool CCallback::battleMoveCreature(int ID, int dest)
|
||||||
|
@ -228,45 +228,52 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
|
|||||||
for(int g=0; g<187; ++g)
|
for(int g=0; g<187; ++g)
|
||||||
dists[g] = 100000000;
|
dists[g] = 100000000;
|
||||||
dists[hexq.front()] = 0;
|
dists[hexq.front()] = 0;
|
||||||
|
int curNext = -1; //for bfs loop only (helper var)
|
||||||
while(!hexq.empty()) //bfs loop
|
while(!hexq.empty()) //bfs loop
|
||||||
{
|
{
|
||||||
int curHex = hexq.front();
|
int curHex = hexq.front();
|
||||||
hexq.pop();
|
hexq.pop();
|
||||||
if((curHex - 18 > 0) && accessibility[curHex-18] && (dists[curHex] + 1 < dists[curHex-18]) && (curHex-18)%17!=0 && (curHex-18)%17!=16) //top left
|
curNext = curHex - ( (curHex/17)%2 ? 17 : 18 );
|
||||||
|
if((curNext > 0) && accessibility[curNext] && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //top left
|
||||||
{
|
{
|
||||||
hexq.push(curHex - 18);
|
hexq.push(curNext);
|
||||||
dists[curHex-18] = dists[curHex] + 1;
|
dists[curNext] = dists[curHex] + 1;
|
||||||
predecessor[curHex-18] = curHex;
|
predecessor[curNext] = curHex;
|
||||||
}
|
}
|
||||||
if((curHex - 17 > 0) && accessibility[curHex-17] && (dists[curHex] + 1 < dists[curHex-17]) && (curHex-17)%17!=0 && (curHex-17)%17!=16) //top right
|
curNext = curHex - ( (curHex/17)%2 ? 16 : 17 );
|
||||||
|
if((curNext > 0) && accessibility[curNext] && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //top right
|
||||||
{
|
{
|
||||||
hexq.push(curHex - 17);
|
hexq.push(curNext);
|
||||||
dists[curHex-17] = dists[curHex] + 1;
|
dists[curNext] = dists[curHex] + 1;
|
||||||
predecessor[curHex-17] = curHex;
|
predecessor[curNext] = curHex;
|
||||||
}
|
}
|
||||||
if((curHex - 1 > 0) && accessibility[curHex-1] && (dists[curHex] + 1 < dists[curHex-1]) && (curHex-1)%17!=0 && (curHex-1)%17!=16) //left
|
curNext = curHex - 1;
|
||||||
|
if((curNext > 0) && accessibility[curNext] && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //left
|
||||||
{
|
{
|
||||||
hexq.push(curHex - 1);
|
hexq.push(curNext);
|
||||||
dists[curHex-1] = dists[curHex] + 1;
|
dists[curNext] = dists[curHex] + 1;
|
||||||
predecessor[curHex-1] = curHex;
|
predecessor[curNext] = curHex;
|
||||||
}
|
}
|
||||||
if((curHex + 1 < 187) && accessibility[curHex+1] && (dists[curHex] + 1 < dists[curHex+1]) && (curHex+1)%17!=0 && (curHex+1)%17!=16) //right
|
curNext = curHex + 1;
|
||||||
|
if((curNext < 187) && accessibility[curNext] && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //right
|
||||||
{
|
{
|
||||||
hexq.push(curHex + 1);
|
hexq.push(curNext);
|
||||||
dists[curHex+1] = dists[curHex] + 1;
|
dists[curNext] = dists[curHex] + 1;
|
||||||
predecessor[curHex+1] = curHex;
|
predecessor[curNext] = curHex;
|
||||||
}
|
}
|
||||||
if((curHex + 17 < 187) && accessibility[curHex+17] && (dists[curHex] + 1 < dists[curHex+17]) && (curHex+17)%17!=0 && (curHex+17)%17!=16) //bottom left
|
curNext = curHex + ( (curHex/17)%2 ? 16 : 17 );
|
||||||
|
if((curNext < 187) && accessibility[curNext] && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //bottom left
|
||||||
{
|
{
|
||||||
hexq.push(curHex + 17);
|
hexq.push(curNext);
|
||||||
dists[curHex+17] = dists[curHex] + 1;
|
dists[curNext] = dists[curHex] + 1;
|
||||||
predecessor[curHex+17] = curHex;
|
predecessor[curNext] = curHex;
|
||||||
}
|
}
|
||||||
if((curHex + 18 < 187) && accessibility[curHex+18] && (dists[curHex] + 1 < dists[curHex+18]) && (curHex+18)%17!=0 && (curHex+18)%17!=16) //bottom right
|
curNext = curHex + ( (curHex/17)%2 ? 17 : 18 );
|
||||||
|
if((curNext < 187) && accessibility[curNext] && (dists[curHex] + 1 < dists[curNext]) && (curNext)%17!=0 && (curNext)%17!=16) //bottom right
|
||||||
{
|
{
|
||||||
hexq.push(curHex + 18);
|
hexq.push(curNext);
|
||||||
dists[curHex+18] = dists[curHex] + 1;
|
dists[curNext] = dists[curHex] + 1;
|
||||||
predecessor[curHex+18] = curHex;
|
predecessor[curNext] = curHex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//following the Path
|
//following the Path
|
||||||
|
@ -1900,7 +1900,7 @@ void CPlayerInterface::actionFinished(Action action)//occurs AFTER every action
|
|||||||
void CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
|
void CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
|
||||||
{
|
{
|
||||||
unsigned char showCount = 0;
|
unsigned char showCount = 0;
|
||||||
((CBattleInterface*)curint)->stackActivated(stackID);
|
dynamic_cast<CBattleInterface*>(curint)->stackActivated(stackID);
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
++showCount;
|
++showCount;
|
||||||
|
Loading…
Reference in New Issue
Block a user