1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

* fixed bug 257

* minor changes
This commit is contained in:
mateuszb 2011-02-09 15:19:53 +00:00
parent 454beba90c
commit 8b8d06ac64
6 changed files with 40 additions and 38 deletions

View File

@ -94,13 +94,19 @@ void CBattleAnimation::endAnim()
bool CBattleAnimation::isEarliest(bool perStackConcurrency)
{
int lowestMoveID = owner->animIDhelper + 5;
CBattleStackAnimation * thAnim = dynamic_cast<CBattleStackAnimation *>(this);
CSpellEffectAnim * thSen = dynamic_cast<CSpellEffectAnim *>(this);
for(std::list<std::pair<CBattleAnimation *, bool> >::iterator it = owner->pendingAnims.begin(); it != owner->pendingAnims.end(); ++it)
{
CBattleStackAnimation * stAnim = dynamic_cast<CBattleStackAnimation *>(it->first);
CBattleStackAnimation * thAnim = dynamic_cast<CBattleStackAnimation *>(this);
CSpellEffectAnim * sen = dynamic_cast<CSpellEffectAnim *>(it->first);
if(perStackConcurrency && stAnim && thAnim && stAnim->stack->ID != thAnim->stack->ID)
continue;
if(sen && thSen && perStackConcurrency)
continue;
CReverseAnim * revAnim = dynamic_cast<CReverseAnim *>(stAnim);
if(revAnim && thAnim && stAnim && stAnim->stack->ID == thAnim->stack->ID && revAnim->priority)
@ -109,7 +115,7 @@ bool CBattleAnimation::isEarliest(bool perStackConcurrency)
if(it->first)
amin(lowestMoveID, it->first->ID);
}
return ID == lowestMoveID;
return ID == lowestMoveID || lowestMoveID == (owner->animIDhelper + 5);
}
CBattleAnimation::CBattleAnimation(CBattleInterface * _owner)
@ -146,7 +152,7 @@ CDummyAnim::CDummyAnim(CBattleInterface * _owner, int howManyFrames) : CBattleAn
//effect animation
bool CSpellEffectAnim::init()
{
if(!isEarliest(false))
if(!isEarliest(true))
return false;
if(effect == 12) //armageddon
@ -1534,10 +1540,10 @@ void CBattleInterface::show(SDL_Surface * to)
//preparing obstacles to be shown
std::vector<CObstacleInstance> obstacles = curInt->cb->battleGetAllObstacles();
std::multimap<int, int> hexToObstacle;
std::multimap<THex, int> hexToObstacle;
for(int b=0; b<obstacles.size(); ++b)
{
int position = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getMaxBlocked(obstacles[b].pos);
THex position = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getMaxBlocked(obstacles[b].pos);
hexToObstacle.insert(std::make_pair(position, b));
}
@ -1622,10 +1628,10 @@ void CBattleInterface::show(SDL_Surface * to)
}
//showing obstacles
std::pair<std::multimap<int, int>::const_iterator, std::multimap<int, int>::const_iterator> obstRange =
std::pair<std::multimap<THex, int>::const_iterator, std::multimap<THex, int>::const_iterator> obstRange =
hexToObstacle.equal_range(b);
for(std::multimap<int, int>::const_iterator it = obstRange.first; it != obstRange.second; ++it)
for(std::multimap<THex, int>::const_iterator it = obstRange.first; it != obstRange.second; ++it)
{
CObstacleInstance & curOb = obstacles[it->second];
std::pair<si16, si16> shift = CGI->heroh->obstacles.find(curOb.ID)->second.posShift;
@ -2297,7 +2303,7 @@ void CBattleInterface::newRound(int number)
}
void CBattleInterface::giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional)
void CBattleInterface::giveCommand(ui8 action, THex tile, ui32 stack, si32 additional)
{
if(!curInt->cb->battleGetStackByID(stack) && action != 1 && action != 4 && action != 5)
{
@ -2325,7 +2331,7 @@ void CBattleInterface::giveCommand(ui8 action, ui16 tile, ui32 stack, si32 addit
givenCommand->setn(ba);
}
bool CBattleInterface::isTileAttackable(const int & number) const
bool CBattleInterface::isTileAttackable(const THex & number) const
{
for(size_t b=0; b<shadedHexes.size(); ++b)
{
@ -2335,20 +2341,20 @@ bool CBattleInterface::isTileAttackable(const int & number) const
return false;
}
bool CBattleInterface::blockedByObstacle(int hex) const
bool CBattleInterface::blockedByObstacle(THex hex) const
{
std::vector<CObstacleInstance> obstacles = curInt->cb->battleGetAllObstacles();
std::set<int> coveredHexes;
std::set<THex> coveredHexes;
for(int b = 0; b < obstacles.size(); ++b)
{
std::vector<int> blocked = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getBlocked(obstacles[b].pos);
std::vector<THex> blocked = CGI->heroh->obstacles.find(obstacles[b].ID)->second.getBlocked(obstacles[b].pos);
for(int w = 0; w < blocked.size(); ++w)
coveredHexes.insert(blocked[w]);
}
return vstd::contains(coveredHexes, hex);
}
bool CBattleInterface::isCatapultAttackable(int hex) const
bool CBattleInterface::isCatapultAttackable(THex hex) const
{
if(!siegeH)
return false;
@ -3614,12 +3620,12 @@ void CBattleHex::mouseMoved(const SDL_MouseMotionEvent &sEvent)
if(hovered && strictHovered) //print attacked creature to console
{
if(myInterface->console->alterTxt.size() == 0 && myInterface->curInt->cb->battleGetStackByPos(myNumber) != NULL &&
myInterface->curInt->cb->battleGetStackByPos(myNumber)->owner != myInterface->curInt->playerID &&
myInterface->curInt->cb->battleGetStackByPos(myNumber)->alive())
const CStack * attackedStack = myInterface->curInt->cb->battleGetStackByPos(myNumber);
if(myInterface->console->alterTxt.size() == 0 &&attackedStack != NULL &&
attackedStack->owner != myInterface->curInt->playerID &&
attackedStack->alive())
{
char tabh[160];
const CStack * attackedStack = myInterface->curInt->cb->battleGetStackByPos(myNumber);
const std::string & attackedName = attackedStack->count == 1 ? attackedStack->getCreature()->nameSing : attackedStack->getCreature()->namePl;
sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str());
myInterface->console->alterTxt = std::string(tabh);

View File

@ -413,10 +413,10 @@ private:
std::list<SProjectileInfo> projectiles; //projectiles flying on battlefield
void projectileShowHelper(SDL_Surface * to); //prints projectiles present on the battlefield
void giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional=-1);
bool isTileAttackable(const int & number) const; //returns true if tile 'number' is neighboring any tile from active stack's range or is one of these tiles
bool blockedByObstacle(int hex) const;
bool isCatapultAttackable(int hex) const; //returns true if given tile can be attacked by catapult
void giveCommand(ui8 action, THex tile, ui32 stack, si32 additional=-1);
bool isTileAttackable(const THex & number) const; //returns true if tile 'number' is neighboring any tile from active stack's range or is one of these tiles
bool blockedByObstacle(THex hex) const;
bool isCatapultAttackable(THex hex) const; //returns true if given tile can be attacked by catapult
std::list<SBattleEffect> battleEffects; //different animations to display on the screen like spell effects

View File

@ -158,7 +158,7 @@ void BattleInfo::getAccessibilityMap(bool *accessibility, bool twoHex, bool atta
//obstacles
for(unsigned int b=0; b<obstacles.size(); ++b)
{
std::vector<int> blocked = VLC->heroh->obstacles[obstacles[b].ID].getBlocked(obstacles[b].pos);
std::vector<THex> blocked = VLC->heroh->obstacles[obstacles[b].ID].getBlocked(obstacles[b].pos);
for(unsigned int c=0; c<blocked.size(); ++c)
{
if(blocked[c] >=0 && blocked[c] < BFIELD_SIZE)
@ -1465,7 +1465,7 @@ BattleInfo * BattleInfo::setupBattle( int3 tile, int terrain, int terType, const
coi.uniqueID = curB->obstacles.size();
coi.ID = possibleObstacles[rand()%possibleObstacles.size()];
coi.pos = rand()%BFIELD_SIZE;
std::vector<int> block = VLC->heroh->obstacles[coi.ID].getBlocked(coi.pos);
std::vector<THex> block = VLC->heroh->obstacles[coi.ID].getBlocked(coi.pos);
bool badObstacle = false;
for(int b=0; b<block.size(); ++b)
{

View File

@ -93,9 +93,9 @@ int CObstacleInfo::getHeight() const
return ret;
}
std::vector<int> CObstacleInfo::getBlocked(int hex) const
std::vector<THex> CObstacleInfo::getBlocked(THex hex) const
{
std::vector<int> ret;
std::vector<THex> ret;
int cur = hex; //currently browsed hex
int curBeg = hex; //beginning of current line
for(int h=0; h<blockmap.size(); ++h)
@ -107,16 +107,12 @@ std::vector<int> CObstacleInfo::getBlocked(int hex) const
++cur;
break;
case 'L':
if((cur/17)%2 == 0)
cur = curBeg + BFIELD_WIDTH;
if((cur/BFIELD_WIDTH)%2 == 1)
{
cur = curBeg + 17;
curBeg = cur;
}
else
{
cur = curBeg + 16;
curBeg = cur;
cur--;
}
curBeg = cur;
break;
case 'N':
++cur;
@ -126,9 +122,9 @@ std::vector<int> CObstacleInfo::getBlocked(int hex) const
return ret;
}
int CObstacleInfo::getMaxBlocked(int hex) const
THex CObstacleInfo::getMaxBlocked(THex hex) const
{
std::vector<int> blocked = getBlocked(hex);
std::vector<THex> blocked = getBlocked(hex);
return *std::max_element(blocked.begin(), blocked.end());
}

View File

@ -98,8 +98,8 @@ struct DLL_EXPORT CObstacleInfo
std::pair<si16, si16> posShift; //shift of obstacle's position in the battlefield <x shift, y shift>, eg. if it's <-1, 2> obstacle will be printed one pixel to the left and two to the bottom
int getWidth() const; //returns width of obstacle in hexes
int getHeight() const; //returns height of obstacle in hexes
std::vector<int> getBlocked(int hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex'
int getMaxBlocked(int hex) const; //returns maximal hex (max number) covered by this obstacle
std::vector<THex> getBlocked(THex hex) const; //returns vector of hexes blocked by obstacle when it's placed on hex 'hex'
THex getMaxBlocked(THex hex) const; //returns maximal hex (max number) covered by this obstacle
template <typename Handler> void serialize(Handler &h, const int version)
{
h & ID & defName & blockmap & allowedTerrains & posShift;

View File

@ -3715,7 +3715,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, int destinatio
ObstaclesRemoved obr;
for(int g=0; g<gs->curB->obstacles.size(); ++g)
{
std::vector<int> blockedHexes = VLC->heroh->obstacles[gs->curB->obstacles[g].ID].getBlocked(gs->curB->obstacles[g].pos);
std::vector<THex> blockedHexes = VLC->heroh->obstacles[gs->curB->obstacles[g].ID].getBlocked(gs->curB->obstacles[g].pos);
if(vstd::contains(blockedHexes, destination)) //this obstacle covers given hex
{