1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-02 22:05:43 +02:00

better battle pathfinder and unit reversing

This commit is contained in:
mateuszb 2008-05-03 15:18:48 +00:00
parent 62952e3163
commit 33e3bf4849
3 changed files with 129 additions and 50 deletions

View File

@ -270,7 +270,7 @@ void CBattleInterface::show(SDL_Surface * to)
CSDL_Ext::update(); CSDL_Ext::update();
} }
bool CBattleInterface::reverseCreature(int number, int hex) bool CBattleInterface::reverseCreature(int number, int hex, bool wideTrick)
{ {
if(creAnims[number]==NULL) if(creAnims[number]==NULL)
return false; //there is no such creature return false; //there is no such creature
@ -285,7 +285,12 @@ bool CBattleInterface::reverseCreature(int number, int hex)
CStack curs = LOCPLINT->cb->battleGetStackByID(number); CStack curs = LOCPLINT->cb->battleGetStackByID(number);
std::pair <int, int> coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs.creature); std::pair <int, int> coords = CBattleHex::getXYUnitAnim(hex, creDir[number], curs.creature);
creAnims[number]->pos.x = coords.first; creAnims[number]->pos.x = coords.first;
creAnims[number]->pos.y = coords.second; //creAnims[number]->pos.y = coords.second;
if(wideTrick && curs.creature->isDoubleWide())
{
creAnims[number]->pos.x -= 44;
}
creAnims[number]->setType(7); creAnims[number]->setType(7);
for(int g=0; g<creAnims[number]->framesInGroup(7); ++g) for(int g=0; g<creAnims[number]->framesInGroup(7); ++g)
@ -364,6 +369,7 @@ void CBattleInterface::stackActivated(int number)
void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, bool endMoving) void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, bool endMoving)
{ {
//a few useful variables
int curStackPos = LOCPLINT->cb->battleGetPos(number); int curStackPos = LOCPLINT->cb->battleGetPos(number);
int steps = creAnims[number]->framesInGroup(0); int steps = creAnims[number]->framesInGroup(0);
int hexWbase = 44, hexHbase = 42; int hexWbase = 44, hexHbase = 42;
@ -377,6 +383,78 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo
} }
} }
int mutPos = CBattleHex::mutualPosition(curStackPos, destHex);
if(LOCPLINT->cb->battleGetCreature(number).isDoubleWide() &&
((creDir[number] && mutPos == 5) || (creDir[number] && mutPos == 0) || (creDir[number] && mutPos == 4))) //for special cases
{
switch(CBattleHex::mutualPosition(curStackPos, destHex)) //reverse unit if necessary
{
case 0:
if(creDir[number] == true)
reverseCreature(number, curStackPos, true);
break;
case 1:
if(creDir[number] == false)
reverseCreature(number, curStackPos, true);
break;
case 2:
if(creDir[number] == false)
reverseCreature(number, curStackPos, true);
break;
case 3:
if(creDir[number] == false)
reverseCreature(number, curStackPos, true);
break;
case 4:
if(creDir[number] == true)
reverseCreature(number, curStackPos, true);
break;
case 5:
if(creDir[number] == true)
reverseCreature(number, curStackPos, true);
break;
}
//moving instructions
creAnims[number]->setType(0);
for(int i=0; i<steps; ++i)
{
switch(CBattleHex::mutualPosition(curStackPos, destHex))
{
case 0:
creAnims[number]->pos.x -= hexWbase/(2*steps);
creAnims[number]->pos.y -= hexHbase/steps;
break;
case 1:
creAnims[number]->pos.x += hexWbase/(2*steps);
creAnims[number]->pos.y -= hexHbase/steps;
break;
case 2:
creAnims[number]->pos.x += hexWbase/steps;
break;
case 3:
creAnims[number]->pos.x += hexWbase/(2*steps);
creAnims[number]->pos.y += hexHbase/steps;
break;
case 4:
creAnims[number]->pos.x -= hexWbase/(2*steps);
creAnims[number]->pos.y += hexHbase/steps;
break;
case 5:
creAnims[number]->pos.x -= hexWbase/steps;
break;
}
show();
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
if( (LOCPLINT->cb->battleGetStackByID(number).owner == attackingHeroInstance->tempOwner ) != creDir[number])
{
reverseCreature(number, curStackPos, true);
}
}
else //normal move instructions
{
switch(CBattleHex::mutualPosition(curStackPos, destHex)) //reverse unit if necessary switch(CBattleHex::mutualPosition(curStackPos, destHex)) //reverse unit if necessary
{ {
case 0: case 0:
@ -436,8 +514,9 @@ void CBattleInterface::stackMoved(int number, int destHex, bool startMoving, boo
show(); show();
SDL_framerateDelay(LOCPLINT->mainFPSmng); SDL_framerateDelay(LOCPLINT->mainFPSmng);
} }
}
if(endMoving) //animation of starting move if(endMoving) //animation of ending move
{ {
for(int i=0; i<creAnims[number]->framesInGroup(21); ++i) for(int i=0; i<creAnims[number]->framesInGroup(21); ++i)
{ {

View File

@ -106,7 +106,7 @@ public:
void activate(); void activate();
void deactivate(); void deactivate();
void show(SDL_Surface * to = NULL); void show(SDL_Surface * to = NULL);
bool reverseCreature(int number, int hex); //reverses animation of given creature playing animation of reversing bool reverseCreature(int number, int hex, bool wideTrick = false); //reverses animation of given creature playing animation of reversing
//call-ins //call-ins
void newStack(CStack stack); //new stack appeared on battlefield void newStack(CStack stack); //new stack appeared on battlefield

View File

@ -295,7 +295,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
accessibility[k] = true; accessibility[k] = true;
for(int g=0; g<curB->stacks.size(); ++g) for(int g=0; g<curB->stacks.size(); ++g)
{ {
//if(curB->stacks[g]->owner == owner) //we don't want to lock enemy's positions if(curB->stacks[g]->owner == owner && curB->stacks[g]->ID != ID) //we don't want to lock enemy's positions and this units' position
{ {
accessibility[curB->stacks[g]->position] = false; accessibility[curB->stacks[g]->position] = false;
if(curB->stacks[g]->creature->isDoubleWide()) //if it's a double hex creature if(curB->stacks[g]->creature->isDoubleWide()) //if it's a double hex creature
@ -447,7 +447,7 @@ std::vector<int> CGameState::battleGetRange(int ID)
accessibility[k] = true; accessibility[k] = true;
for(int g=0; g<curB->stacks.size(); ++g) for(int g=0; g<curB->stacks.size(); ++g)
{ {
if(curB->stacks[g]->owner == owner) //we don't want to lock enemy's positions if(curB->stacks[g]->owner == owner && curB->stacks[g]->ID != ID) //we don't want to lock enemy's positions or current unit's position
{ {
accessibility[curB->stacks[g]->position] = false; accessibility[curB->stacks[g]->position] = false;
if(curB->stacks[g]->creature->isDoubleWide()) //if it's a double hex creature if(curB->stacks[g]->creature->isDoubleWide()) //if it's a double hex creature