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

* stack at the limit of unit's range can now be attacked

* range of unit is now properly displayed
* battle log is scrolled down when new event occurs
* dead stacks don't lock hexes
* living units on hexes with corpses are properly displayed
* dead units cannot be attacked now
This commit is contained in:
mateuszb 2008-06-11 10:27:30 +00:00
parent 4f0ce359f6
commit c13f596d1d
3 changed files with 72 additions and 24 deletions

View File

@ -239,37 +239,42 @@ void CBattleInterface::show(SDL_Surface * to)
defendingHero->show(to);
//showing units //a lot of work...
int stackByHex[187];
for(int b=0; b<187; ++b)
stackByHex[b] = -1;
std::vector<int> stackByHex[187];
//double loop because dead stacks should be printed first
for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
{
stackByHex[j->second.position] = j->second.ID;
if(!j->second.alive)
stackByHex[j->second.position].push_back(j->second.ID);
}
for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
{
if(j->second.alive)
stackByHex[j->second.position].push_back(j->second.ID);
}
attackingShowHelper(); // handle attack animation
for(int b=0; b<187; ++b)
{
if(stackByHex[b]!=-1)
for(int v=0; v<stackByHex[b].size(); ++v)
{
creAnims[stackByHex[b]]->nextFrame(to, creAnims[stackByHex[b]]->pos.x, creAnims[stackByHex[b]]->pos.y, creDir[stackByHex[b]], (animCount%2==0 || creAnims[stackByHex[b]]->getType()!=2) && stacks[stackByHex[b]].alive, stackByHex[b]==activeStack); //increment always when moving, never if stack died
creAnims[stackByHex[b][v]]->nextFrame(to, creAnims[stackByHex[b][v]]->pos.x, creAnims[stackByHex[b][v]]->pos.y, creDir[stackByHex[b][v]], (animCount%2==0 || creAnims[stackByHex[b][v]]->getType()!=2) && stacks[stackByHex[b][v]].alive, stackByHex[b][v]==activeStack); //increment always when moving, never if stack died
//printing amount
if(stacks[stackByHex[b]].amount > 0) //don't print if stack is not alive
if(stacks[stackByHex[b][v]].amount > 0) //don't print if stack is not alive
{
if(stacks[stackByHex[b]].attackerOwned)
if(stacks[stackByHex[b][v]].attackerOwned)
{
CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackByHex[b]]->pos.x + 220, creAnims[stackByHex[b]]->pos.y + 260));
CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackByHex[b][v]]->pos.x + 220, creAnims[stackByHex[b][v]]->pos.y + 260));
std::stringstream ss;
ss<<stacks[stackByHex[b]].amount;
CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackByHex[b]]->pos.x + 220 + 14, creAnims[stackByHex[b]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
ss<<stacks[stackByHex[b][v]].amount;
CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackByHex[b][v]]->pos.x + 220 + 14, creAnims[stackByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
}
else
{
CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackByHex[b]]->pos.x + 202, creAnims[stackByHex[b]]->pos.y + 260));
CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackByHex[b][v]]->pos.x + 202, creAnims[stackByHex[b][v]]->pos.y + 260));
std::stringstream ss;
ss<<stacks[stackByHex[b]].amount;
CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackByHex[b]]->pos.x + 202 + 14, creAnims[stackByHex[b]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
ss<<stacks[stackByHex[b][v]].amount;
CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackByHex[b][v]]->pos.x + 202 + 14, creAnims[stackByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
}
}
}
@ -1112,12 +1117,11 @@ bool CBattleConsole::addText(std::string text)
{
texts.push_back( text.substr(firstInToken, i-firstInToken) );
firstInToken = i+1;
lastShown++;
}
}
texts.push_back( text.substr(firstInToken, text.size()) );
lastShown++;
lastShown = texts.size()-1;
return true;
}

View File

@ -35,7 +35,7 @@ public:
bool hovered, strictHovered;
CBattleInterface * myInterface; //interface that owns me
static std::pair<int, int> getXYUnitAnim(int hexNum, bool attacker, CCreature * creature); //returns (x, y) of left top corner of animation
static signed char mutualPosition(int hex1, int hex2); //returns info about mutual position of given hexes (-1 - they 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)
//for user interactions
void hover (bool on);
void activate();

View File

@ -4,6 +4,7 @@
#include <algorithm>
#include "SDL_Thread.h"
#include "SDL_Extensions.h"
#include "CBattleInterface.h" //for CBattleHex
#include <queue>
@ -283,9 +284,12 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
|| (curB->stacks[g]->creature->isDoubleWide() && curB->stacks[g]->attackerOwned && curB->stacks[g]->position-1 == dest)
|| (curB->stacks[g]->creature->isDoubleWide() && !curB->stacks[g]->attackerOwned && curB->stacks[g]->position+1 == dest))
{
stackAtEnd = true;
numberOfStackAtEnd = g;
break;
if(curB->stacks[g]->alive)
{
stackAtEnd = true;
numberOfStackAtEnd = g;
break;
}
}
}
@ -307,7 +311,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
accessibility[k] = true;
for(int g=0; g<curB->stacks.size(); ++g)
{
if(curB->stacks[g]->ID != ID) //we don't want to lock enemy's positions and this units' position
if(curB->stacks[g]->ID != ID && curB->stacks[g]->alive) //we don't want to lock enemy's positions and this units' position
{
accessibility[curB->stacks[g]->position] = false;
if(curB->stacks[g]->creature->isDoubleWide()) //if it's a double hex creature
@ -402,7 +406,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
}
}
//following the Path
if(dists[dest] > curStack->creature->speed)
if(dists[dest] > curStack->creature->speed && !(stackAtEnd && dists[dest] == curStack->creature->speed+1)) //we can attack a stack if we can go to adjacent hex
return false;
std::vector<int> path;
int curElem = dest;
@ -544,7 +548,7 @@ std::vector<int> CGameState::battleGetRange(int ID)
accessibility[k] = true;
for(int g=0; g<curB->stacks.size(); ++g)
{
if(curB->stacks[g]->ID != ID) //we don't want to lock current unit's position
if(curB->stacks[g]->ID != ID && curB->stacks[g]->alive) //we don't want to lock current unit's position
{
accessibility[curB->stacks[g]->position] = false;
if(curB->stacks[g]->creature->isDoubleWide()) //if it's a double hex creature
@ -637,6 +641,46 @@ std::vector<int> CGameState::battleGetRange(int ID)
ret.push_back(i);
}
}
return ret;
std::vector<int> additionals;
//adding enemies' positions
for(int c=0; c<curB->stacks.size(); ++c)
{
if(curB->stacks[c]->alive && curB->stacks[c]->owner != owner)
{
for(int g=0; g<ret.size(); ++g)
{
if(CBattleHex::mutualPosition(ret[g], curB->stacks[c]->position) != -1)
{
additionals.push_back(curB->stacks[c]->position);
}
if(curB->stacks[c]->creature->isDoubleWide() && curB->stacks[c]->attackerOwned && CBattleHex::mutualPosition(ret[g], curB->stacks[c]->position-1) != -1)
{
additionals.push_back(curB->stacks[c]->position-1);
}
if(curB->stacks[c]->creature->isDoubleWide() && !curB->stacks[c]->attackerOwned && CBattleHex::mutualPosition(ret[g], curB->stacks[c]->position+1) != -1)
{
additionals.push_back(curB->stacks[c]->position+1);
}
}
}
}
for(int g=0; g<additionals.size(); ++g)
{
ret.push_back(additionals[g]);
}
std::sort(ret.begin(), ret.end());
std::vector<int>::iterator nend = std::unique(ret.begin(), ret.end());
std::vector<int> ret2;
for(std::vector<int>::iterator it = ret.begin(); it != nend; ++it)
{
ret2.push_back(*it);
}
return ret2;
}