1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

* more support for attacking stacks for back by two hex stacks

* minor typo fixed
This commit is contained in:
mateuszb
2009-02-05 14:44:27 +00:00
parent e1d6ff54d7
commit 0070c93888
7 changed files with 78 additions and 26 deletions

View File

@ -638,7 +638,7 @@ BattleAction CBattleLogic::MakeDecision(int stackID)
} }
} }
std::vector<int> fields = m_cb->battleGetAvailableHexes(stackID); std::vector<int> fields = m_cb->battleGetAvailableHexes(stackID, false);
BattleAction ba; BattleAction ba;
ba.side = 1; ba.side = 1;
//ba.actionType = 6; // go and attack //ba.actionType = 6; // go and attack

View File

@ -1392,7 +1392,18 @@ void CBattleInterface::hexLclicked(int whichOne)
if(std::find(shadedHexes.begin(),shadedHexes.end(),whichOne)!=shadedHexes.end())// and it's in our range if(std::find(shadedHexes.begin(),shadedHexes.end(),whichOne)!=shadedHexes.end())// and it's in our range
{ {
CGI->curh->changeGraphic(1, 6); //cursor should be changed CGI->curh->changeGraphic(1, 6); //cursor should be changed
if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isDoubleWide())
{
std::vector<int> acc = LOCPLINT->cb->battleGetAvailableHexes(activeStack, false);
if(vstd::contains(acc, whichOne))
giveCommand(2,whichOne,activeStack); giveCommand(2,whichOne,activeStack);
else
giveCommand(2,whichOne + (LOCPLINT->cb->battleGetStackByID(activeStack)->attackerOwned ? 1 : -1),activeStack);
}
else
{
giveCommand(2,whichOne,activeStack);
}
} }
} }
else if(dest->owner != attackingHeroInstance->tempOwner else if(dest->owner != attackingHeroInstance->tempOwner
@ -1412,7 +1423,18 @@ void CBattleInterface::hexLclicked(int whichOne)
giveCommand(6,whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH-1 : BFIELD_WIDTH ),activeStack,whichOne); giveCommand(6,whichOne + ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH-1 : BFIELD_WIDTH ),activeStack,whichOne);
break; break;
case 8: case 8:
if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isDoubleWide() && !LOCPLINT->cb->battleGetStackByID(activeStack)->attackerOwned)
{
std::vector<int> acc = LOCPLINT->cb->battleGetAvailableHexes(activeStack, false);
if(vstd::contains(acc, whichOne))
giveCommand(6,whichOne - 1,activeStack,whichOne); giveCommand(6,whichOne - 1,activeStack,whichOne);
else
giveCommand(6,whichOne - 2,activeStack,whichOne);
}
else
{
giveCommand(6,whichOne - 1,activeStack,whichOne);
}
break; break;
case 9: case 9:
giveCommand(6,whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH+1 : BFIELD_WIDTH ),activeStack,whichOne); giveCommand(6,whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH+1 : BFIELD_WIDTH ),activeStack,whichOne);
@ -1421,7 +1443,18 @@ void CBattleInterface::hexLclicked(int whichOne)
giveCommand(6,whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH-1 ),activeStack,whichOne); giveCommand(6,whichOne - ( (whichOne/BFIELD_WIDTH)%2 ? BFIELD_WIDTH : BFIELD_WIDTH-1 ),activeStack,whichOne);
break; break;
case 11: case 11:
if(LOCPLINT->cb->battleGetStackByID(activeStack)->creature->isDoubleWide() && LOCPLINT->cb->battleGetStackByID(activeStack)->attackerOwned)
{
std::vector<int> acc = LOCPLINT->cb->battleGetAvailableHexes(activeStack, false);
if(vstd::contains(acc, whichOne))
giveCommand(6,whichOne + 1,activeStack,whichOne); giveCommand(6,whichOne + 1,activeStack,whichOne);
else
giveCommand(6,whichOne + 2,activeStack,whichOne);
}
else
{
giveCommand(6,whichOne + 1,activeStack,whichOne);
}
break; break;
} }
CGI->curh->changeGraphic(1, 6); //cursor should be changed CGI->curh->changeGraphic(1, 6); //cursor should be changed
@ -1974,7 +2007,7 @@ void CBattleInterface::attackingShowHelper()
void CBattleInterface::redrawBackgroundWithHexes(int activeStack) void CBattleInterface::redrawBackgroundWithHexes(int activeStack)
{ {
shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(activeStack); shadedHexes = LOCPLINT->cb->battleGetAvailableHexes(activeStack, true);
//preparating background graphic with hexes and shaded hexes //preparating background graphic with hexes and shaded hexes
blitAt(background, 0, 0, backgroundWithHexes); blitAt(background, 0, 0, backgroundWithHexes);

View File

@ -520,10 +520,10 @@ CCreature CCallback::battleGetCreature(int number)
#endif #endif
} }
std::vector<int> CCallback::battleGetAvailableHexes(int ID) std::vector<int> CCallback::battleGetAvailableHexes(int ID, bool addOccupiable)
{ {
boost::shared_lock<boost::shared_mutex> lock(*gs->mx); boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return gs->curB->getAccessibility(ID); return gs->curB->getAccessibility(ID, addOccupiable);
//return gs->battleGetRange(ID); //return gs->battleGetRange(ID);
} }

View File

@ -85,7 +85,7 @@ public:
virtual std::vector<CStack> battleGetStackQueue()=0; //returns vector of stack in order of their move sequence virtual std::vector<CStack> battleGetStackQueue()=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 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 bool battleMoveCreature(int ID, int dest)=0; //moves creature with id ID to dest if possible
virtual std::vector<int> battleGetAvailableHexes(int ID)=0; //reutrns numbers of hexes reachable by creature with id ID virtual std::vector<int> battleGetAvailableHexes(int ID, bool addOccupiable)=0; //reutrns 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 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 battleCanShoot(int ID, int dest)=0; //returns true if unit with id ID can shoot to dest
}; };
@ -172,7 +172,7 @@ public:
std::map<int, CStack> battleGetStacks(); //returns stacks on battlefield std::map<int, CStack> battleGetStacks(); //returns stacks on battlefield
std::vector<CStack> battleGetStackQueue(); //returns vector of stack in order of their move sequence std::vector<CStack> battleGetStackQueue(); //returns vector of stack in order of their move sequence
CCreature battleGetCreature(int number); //returns type of creature by given number of stack CCreature battleGetCreature(int number); //returns type of creature by given number of stack
std::vector<int> battleGetAvailableHexes(int ID); //reutrns numbers of hexes reachable by creature with id ID 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 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 battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest

View File

@ -186,12 +186,15 @@ void BattleInfo::getAccessibilityMap(bool *accessibility, int stackToOmmit)
} }
//TODO: obstacles //TODO: obstacles
} }
void BattleInfo::getAccessibilityMapForTwoHex(bool *accessibility, bool atackerSide, int stackToOmmit) //send pointer to at least 187 allocated bytes void BattleInfo::getAccessibilityMapForTwoHex(bool *accessibility, bool atackerSide, int stackToOmmit, bool addOccupiable) //send pointer to at least 187 allocated bytes
{ {
bool mac[BFIELD_SIZE]; bool mac[BFIELD_SIZE];
getAccessibilityMap(mac,stackToOmmit); getAccessibilityMap(mac,stackToOmmit);
memcpy(accessibility,mac,BFIELD_SIZE); memcpy(accessibility,mac,BFIELD_SIZE);
if(!addOccupiable)
{
for(int b=0; b<BFIELD_SIZE; ++b) for(int b=0; b<BFIELD_SIZE; ++b)
{ {
if( mac[b] && !(atackerSide ? mac[b-1] : mac[b+1])) if( mac[b] && !(atackerSide ? mac[b-1] : mac[b+1]))
@ -202,9 +205,10 @@ void BattleInfo::getAccessibilityMapForTwoHex(bool *accessibility, bool atackerS
//removing accessibility for side hexes //removing accessibility for side hexes
for(int v=0; v<BFIELD_SIZE; ++v) for(int v=0; v<BFIELD_SIZE; ++v)
if(atackerSide ? (v%17)==1 : (v%17)==15) if(atackerSide ? (v%BFIELD_WIDTH)==1 : (v%BFIELD_WIDTH)==(BFIELD_WIDTH - 2))
accessibility[v] = false; accessibility[v] = false;
} }
}
void BattleInfo::makeBFS(int start, bool*accessibility, int *predecessor, int *dists) //both pointers must point to the at least 187-elements int arrays void BattleInfo::makeBFS(int start, bool*accessibility, int *predecessor, int *dists) //both pointers must point to the at least 187-elements int arrays
{ {
//inits //inits
@ -234,13 +238,13 @@ void BattleInfo::makeBFS(int start, bool*accessibility, int *predecessor, int *d
} }
}; };
std::vector<int> BattleInfo::getAccessibility(int stackID) std::vector<int> BattleInfo::getAccessibility(int stackID, bool addOccupiable)
{ {
std::vector<int> ret; std::vector<int> ret;
bool ac[BFIELD_SIZE]; bool ac[BFIELD_SIZE];
CStack *s = getStack(stackID); CStack *s = getStack(stackID);
if(s->creature->isDoubleWide()) if(s->creature->isDoubleWide())
getAccessibilityMapForTwoHex(ac,s->attackerOwned,stackID); getAccessibilityMapForTwoHex(ac,s->attackerOwned,stackID,addOccupiable);
else else
getAccessibilityMap(ac,stackID); getAccessibilityMap(ac,stackID);

View File

@ -103,10 +103,10 @@ struct DLL_EXPORT BattleInfo
CStack * getStack(int stackID); CStack * getStack(int stackID);
CStack * getStackT(int tileID); CStack * getStackT(int tileID);
void getAccessibilityMap(bool *accessibility, int stackToOmmit=-1); //send pointer to at least 187 allocated bytes void getAccessibilityMap(bool *accessibility, int stackToOmmit=-1); //send pointer to at least 187 allocated bytes
void getAccessibilityMapForTwoHex(bool *accessibility, bool atackerSide, int stackToOmmit=-1); //send pointer to at least 187 allocated bytes void getAccessibilityMapForTwoHex(bool *accessibility, bool atackerSide, int stackToOmmit=-1, bool addOccupiable = false); //send pointer to at least 187 allocated bytes
void makeBFS(int start, bool*accessibility, int *predecessor, int *dists); //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result void makeBFS(int start, bool*accessibility, int *predecessor, int *dists); //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result
std::vector<int> getPath(int start, int dest, bool*accessibility); std::vector<int> getPath(int start, int dest, bool*accessibility);
std::vector<int> getAccessibility(int stackID); //returns vector of accessible tiles (taking into account the creature range) std::vector<int> getAccessibility(int stackID, bool addOccupiable); //returns vector of accessible tiles (taking into account the creature range)
bool isStackBlocked(int ID); //returns true if there is neighbouring enemy stack bool isStackBlocked(int ID); //returns true if there is neighbouring enemy stack
static signed char mutualPosition(int hex1, int hex2); //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left) static signed char mutualPosition(int hex1, int hex2); //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left)

View File

@ -1786,6 +1786,21 @@ void CGameHandler::moveStack(int stack, int dest)
else else
gs->curB->getAccessibilityMap(accessibility,curStack->ID); gs->curB->getAccessibilityMap(accessibility,curStack->ID);
//shifting destination (if we have double wide stack and we can occupy dest but not be exactly there)
if(!stackAtEnd && curStack->creature->isDoubleWide() && !accessibility[dest])
{
if(curStack->attackerOwned)
{
if(accessibility[dest+1])
dest+=1;
}
else
{
if(accessibility[dest-1])
dest-=1;
}
}
if((stackAtEnd && stackAtEnd!=curStack && stackAtEnd->alive()) || !accessibility[dest]) if((stackAtEnd && stackAtEnd!=curStack && stackAtEnd->alive()) || !accessibility[dest])
return; return;
@ -2181,7 +2196,7 @@ void CGameHandler::setupBattle( BattleInfo * curB, int3 tile, CCreatureSet &army
} }
if(hero2) if(hero2)
{ {
if(hero1->getArt(13)) //ballista if(hero2->getArt(13)) //ballista
{ {
stacks.push_back(new CStack(&VLC->creh->creatures[146], 1, hero2->tempOwner, stacks.size(), false, 255)); stacks.push_back(new CStack(&VLC->creh->creatures[146], 1, hero2->tempOwner, stacks.size(), false, 255));
stacks[stacks.size()-1]->position = 66; stacks[stacks.size()-1]->position = 66;