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) bool CBattleAnimation::isEarliest(bool perStackConcurrency)
{ {
int lowestMoveID = owner->animIDhelper + 5; 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) 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 * 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) if(perStackConcurrency && stAnim && thAnim && stAnim->stack->ID != thAnim->stack->ID)
continue; continue;
if(sen && thSen && perStackConcurrency)
continue;
CReverseAnim * revAnim = dynamic_cast<CReverseAnim *>(stAnim); CReverseAnim * revAnim = dynamic_cast<CReverseAnim *>(stAnim);
if(revAnim && thAnim && stAnim && stAnim->stack->ID == thAnim->stack->ID && revAnim->priority) if(revAnim && thAnim && stAnim && stAnim->stack->ID == thAnim->stack->ID && revAnim->priority)
@ -109,7 +115,7 @@ bool CBattleAnimation::isEarliest(bool perStackConcurrency)
if(it->first) if(it->first)
amin(lowestMoveID, it->first->ID); amin(lowestMoveID, it->first->ID);
} }
return ID == lowestMoveID; return ID == lowestMoveID || lowestMoveID == (owner->animIDhelper + 5);
} }
CBattleAnimation::CBattleAnimation(CBattleInterface * _owner) CBattleAnimation::CBattleAnimation(CBattleInterface * _owner)
@ -146,7 +152,7 @@ CDummyAnim::CDummyAnim(CBattleInterface * _owner, int howManyFrames) : CBattleAn
//effect animation //effect animation
bool CSpellEffectAnim::init() bool CSpellEffectAnim::init()
{ {
if(!isEarliest(false)) if(!isEarliest(true))
return false; return false;
if(effect == 12) //armageddon if(effect == 12) //armageddon
@ -1534,10 +1540,10 @@ void CBattleInterface::show(SDL_Surface * to)
//preparing obstacles to be shown //preparing obstacles to be shown
std::vector<CObstacleInstance> obstacles = curInt->cb->battleGetAllObstacles(); 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) 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)); hexToObstacle.insert(std::make_pair(position, b));
} }
@ -1622,10 +1628,10 @@ void CBattleInterface::show(SDL_Surface * to)
} }
//showing obstacles //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); 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]; CObstacleInstance & curOb = obstacles[it->second];
std::pair<si16, si16> shift = CGI->heroh->obstacles.find(curOb.ID)->second.posShift; 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) 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); 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) for(size_t b=0; b<shadedHexes.size(); ++b)
{ {
@ -2335,20 +2341,20 @@ bool CBattleInterface::isTileAttackable(const int & number) const
return false; return false;
} }
bool CBattleInterface::blockedByObstacle(int hex) const bool CBattleInterface::blockedByObstacle(THex hex) const
{ {
std::vector<CObstacleInstance> obstacles = curInt->cb->battleGetAllObstacles(); std::vector<CObstacleInstance> obstacles = curInt->cb->battleGetAllObstacles();
std::set<int> coveredHexes; std::set<THex> coveredHexes;
for(int b = 0; b < obstacles.size(); ++b) 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) for(int w = 0; w < blocked.size(); ++w)
coveredHexes.insert(blocked[w]); coveredHexes.insert(blocked[w]);
} }
return vstd::contains(coveredHexes, hex); return vstd::contains(coveredHexes, hex);
} }
bool CBattleInterface::isCatapultAttackable(int hex) const bool CBattleInterface::isCatapultAttackable(THex hex) const
{ {
if(!siegeH) if(!siegeH)
return false; return false;
@ -3614,12 +3620,12 @@ void CBattleHex::mouseMoved(const SDL_MouseMotionEvent &sEvent)
if(hovered && strictHovered) //print attacked creature to console if(hovered && strictHovered) //print attacked creature to console
{ {
if(myInterface->console->alterTxt.size() == 0 && myInterface->curInt->cb->battleGetStackByPos(myNumber) != NULL && const CStack * attackedStack = myInterface->curInt->cb->battleGetStackByPos(myNumber);
myInterface->curInt->cb->battleGetStackByPos(myNumber)->owner != myInterface->curInt->playerID && if(myInterface->console->alterTxt.size() == 0 &&attackedStack != NULL &&
myInterface->curInt->cb->battleGetStackByPos(myNumber)->alive()) attackedStack->owner != myInterface->curInt->playerID &&
attackedStack->alive())
{ {
char tabh[160]; char tabh[160];
const CStack * attackedStack = myInterface->curInt->cb->battleGetStackByPos(myNumber);
const std::string & attackedName = attackedStack->count == 1 ? attackedStack->getCreature()->nameSing : attackedStack->getCreature()->namePl; const std::string & attackedName = attackedStack->count == 1 ? attackedStack->getCreature()->nameSing : attackedStack->getCreature()->namePl;
sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str()); sprintf(tabh, CGI->generaltexth->allTexts[220].c_str(), attackedName.c_str());
myInterface->console->alterTxt = std::string(tabh); myInterface->console->alterTxt = std::string(tabh);

View File

@ -413,10 +413,10 @@ private:
std::list<SProjectileInfo> projectiles; //projectiles flying on battlefield std::list<SProjectileInfo> projectiles; //projectiles flying on battlefield
void projectileShowHelper(SDL_Surface * to); //prints projectiles present on the battlefield void projectileShowHelper(SDL_Surface * to); //prints projectiles present on the battlefield
void giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional=-1); void giveCommand(ui8 action, THex 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 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(int hex) const; bool blockedByObstacle(THex hex) const;
bool isCatapultAttackable(int hex) const; //returns true if given tile can be attacked by catapult 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 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 //obstacles
for(unsigned int b=0; b<obstacles.size(); ++b) 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) for(unsigned int c=0; c<blocked.size(); ++c)
{ {
if(blocked[c] >=0 && blocked[c] < BFIELD_SIZE) 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.uniqueID = curB->obstacles.size();
coi.ID = possibleObstacles[rand()%possibleObstacles.size()]; coi.ID = possibleObstacles[rand()%possibleObstacles.size()];
coi.pos = rand()%BFIELD_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; bool badObstacle = false;
for(int b=0; b<block.size(); ++b) for(int b=0; b<block.size(); ++b)
{ {

View File

@ -93,9 +93,9 @@ int CObstacleInfo::getHeight() const
return ret; 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 cur = hex; //currently browsed hex
int curBeg = hex; //beginning of current line int curBeg = hex; //beginning of current line
for(int h=0; h<blockmap.size(); ++h) for(int h=0; h<blockmap.size(); ++h)
@ -107,16 +107,12 @@ std::vector<int> CObstacleInfo::getBlocked(int hex) const
++cur; ++cur;
break; break;
case 'L': case 'L':
if((cur/17)%2 == 0) cur = curBeg + BFIELD_WIDTH;
if((cur/BFIELD_WIDTH)%2 == 1)
{ {
cur = curBeg + 17; cur--;
curBeg = cur;
}
else
{
cur = curBeg + 16;
curBeg = cur;
} }
curBeg = cur;
break; break;
case 'N': case 'N':
++cur; ++cur;
@ -126,9 +122,9 @@ std::vector<int> CObstacleInfo::getBlocked(int hex) const
return ret; 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()); 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 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 getWidth() const; //returns width of obstacle in hexes
int getHeight() const; //returns height 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' std::vector<THex> getBlocked(THex 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 THex getMaxBlocked(THex hex) const; //returns maximal hex (max number) covered by this obstacle
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & ID & defName & blockmap & allowedTerrains & posShift; h & ID & defName & blockmap & allowedTerrains & posShift;

View File

@ -3715,7 +3715,7 @@ void CGameHandler::handleSpellCasting( int spellID, int spellLvl, int destinatio
ObstaclesRemoved obr; ObstaclesRemoved obr;
for(int g=0; g<gs->curB->obstacles.size(); ++g) 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 if(vstd::contains(blockedHexes, destination)) //this obstacle covers given hex
{ {