1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

better support for two-hex stacks

This commit is contained in:
mateuszb 2008-04-19 17:10:57 +00:00
parent 06f278717c
commit f9a4c2a5fd
4 changed files with 60 additions and 2 deletions

View File

@ -8,6 +8,7 @@
#include "hch\CDefHandler.h"
#include "CCallback.h"
#include "CGameState.h"
#include "hch\CGeneralTextHandler.h"
#include <queue>
#include <sstream>
@ -463,6 +464,11 @@ void CBattleInterface::stackAttacking(int ID, int dest)
{
}
void CBattleInterface::newRound(int number)
{
console->addText(CGI->generaltexth->allTexts[412]);
}
void CBattleInterface::hexLclicked(int whichOne)
{
if((whichOne%17)!=0 && (whichOne%17)!=16) //if player is trying to attack enemey unit or move creature stack

View File

@ -114,6 +114,6 @@ public:
void stackActivated(int number); //active stack has been changed
void stackMoved(int number, int destHex, bool startMoving, bool endMoving); //stack with id number moved to destHex
void stackAttacking(int ID, int dest); //called when stack with id ID is attacking something on hex dest
void turnEnded(); //caled when current unit cannot get new orders
void newRound(int number); //caled when round is ended; number is the number of round
void hexLclicked(int whichOne); //hex only call-in
};

View File

@ -183,9 +183,14 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
//SDL_Thread * eventh = SDL_CreateThread(battleEventThread, NULL);
while(true) //do zwyciestwa jednej ze stron
while(true) //till the end of the battle ;]
{
bool battleEnd = false;
//tell players about next round
for(int v=0; v<CGI->playerint.size(); ++v)
CGI->playerint[v]->battleNewRound(curB->round);
//stack loop
for(int i=0;i<stacks.size();i++)
{
curB->activeStack = i;
@ -239,6 +244,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
}
if(battleEnd)
break;
curB->round++;
SDL_Delay(50);
}
@ -301,6 +307,23 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
}
}
}
if(curStack->creature->isDoubleWide()) //locking positions unreachable by two-hex creatures
{
bool mac[187];
for(int b=0; b<187; ++b)
{
//
// && ( ? (curStack->attackerOwned ? accessibility[curNext-1] : accessibility[curNext+1]) : true )
mac[b] = accessibility[b];
if( accessibility[b] && !(curStack->attackerOwned ? accessibility[b-1] : accessibility[b+1]))
{
mac[b] = false;
}
}
mac[curStack->attackerOwned ? curStack->position+1 : curStack->position-1]=true;
for(int v=0; v<187; ++v)
accessibility[v] = mac[v];
}
int predecessor[187]; //for getting the Path
for(int b=0; b<187; ++b)
predecessor[b] = -1;
@ -391,6 +414,17 @@ std::vector<int> CGameState::battleGetRange(int ID)
int initialPlace=-1; //position of unit
int radius=-1; //range of unit
unsigned char owner = -1; //owner of unit
//selecting stack
CStack * curStack = NULL;
for(int y=0; y<curB->stacks.size(); ++y)
{
if(curB->stacks[y]->ID == ID)
{
curStack = curB->stacks[y];
break;
}
}
for(int g=0; g<curB->stacks.size(); ++g)
{
if(curB->stacks[g]->ID == ID)
@ -420,6 +454,23 @@ std::vector<int> CGameState::battleGetRange(int ID)
}
}
if(curStack->creature->isDoubleWide()) //locking positions unreachable by two-hex creatures
{
bool mac[187];
for(int b=0; b<187; ++b)
{
//
// && ( ? (curStack->attackerOwned ? accessibility[curNext-1] : accessibility[curNext+1]) : true )
mac[b] = accessibility[b];
if( accessibility[b] && !(curStack->attackerOwned ? accessibility[b-1] : accessibility[b+1]))
{
mac[b] = false;
}
}
mac[curStack->attackerOwned ? curStack->position+1 : curStack->position-1]=true;
for(int v=0; v<187; ++v)
accessibility[v] = mac[v];
}
int dists[187]; //calculated distances
std::queue<int> hexq; //bfs queue

View File

@ -1967,6 +1967,7 @@ void CPlayerInterface::battlefieldPrepared(int battlefieldType, std::vector<CObs
void CPlayerInterface::battleNewRound(int round) //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
{
dynamic_cast<CBattleInterface*>(curint)->newRound(round);
}
void CPlayerInterface::actionStarted(BattleAction action)//occurs BEFORE every action taken by any stack or by the hero