mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
* bugfixes and refactorings
This commit is contained in:
parent
0a9c46d88f
commit
4f30bde636
@ -968,7 +968,7 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed)
|
|||||||
int3 hpos = map->players[i].posOfMainTown;
|
int3 hpos = map->players[i].posOfMainTown;
|
||||||
hpos.x+=1;// hpos.y+=1;
|
hpos.x+=1;// hpos.y+=1;
|
||||||
int j;
|
int j;
|
||||||
for(unsigned j=0; j<scenarioOps->playerInfos.size(); j++)
|
for(j=0; j<scenarioOps->playerInfos.size(); j++) //don't add unsigned here - we are refering to the variable above
|
||||||
if(scenarioOps->playerInfos[j].color == i)
|
if(scenarioOps->playerInfos[j].color == i)
|
||||||
break;
|
break;
|
||||||
if(j == scenarioOps->playerInfos.size())
|
if(j == scenarioOps->playerInfos.size())
|
||||||
@ -1949,6 +1949,63 @@ void BattleInfo::calculateCasualties( std::set<std::pair<ui32,si32> > *casualtie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::set<CStack*> BattleInfo::getAttackedCreatures(const CSpell * s, const CGHeroInstance * caster, int destinationTile)
|
||||||
|
{
|
||||||
|
std::set<ui16> attackedHexes = s->rangeInHexes(destinationTile, caster->getSpellSchoolLevel(s));
|
||||||
|
std::set<CStack*> attackedCres; /*std::set to exclude multiple occurences of two hex creatures*/
|
||||||
|
if(s->id == 24 || s->id == 25 || s->id == 26) //death ripple, destroy undead and armageddon
|
||||||
|
{
|
||||||
|
for(int it=0; it<stacks.size(); ++it)
|
||||||
|
{
|
||||||
|
if((s->id == 24 && !stacks[it]->creature->isUndead()) //death ripple
|
||||||
|
|| (s->id == 25 && stacks[it]->creature->isUndead()) //destroy undead
|
||||||
|
|| (s->id == 26) //armageddon
|
||||||
|
)
|
||||||
|
{
|
||||||
|
attackedCres.insert(stacks[it]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(VLC->spellh->spells[s->id].attributes.find("CREATURE_TARGET_2") != std::string::npos) //spell to be cast on a specific creature but massive on expert
|
||||||
|
{
|
||||||
|
if(caster->getSpellSchoolLevel(s) < 3) /*not expert */
|
||||||
|
{
|
||||||
|
CStack * st = getStackT(destinationTile);
|
||||||
|
if(st)
|
||||||
|
attackedCres.insert(st);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for(int it=0; it<stacks.size(); ++it)
|
||||||
|
{
|
||||||
|
/*if it's non negative spell and our unit or non positive spell and hostile unit */
|
||||||
|
if((VLC->spellh->spells[s->id].positiveness >= 0 && stacks[it]->owner == caster->tempOwner)
|
||||||
|
||(VLC->spellh->spells[s->id].positiveness <= 0 && stacks[it]->owner != caster->tempOwner )
|
||||||
|
)
|
||||||
|
{
|
||||||
|
attackedCres.insert(stacks[it]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} //if(caster->getSpellSchoolLevel(s) < 3)
|
||||||
|
}
|
||||||
|
else if(VLC->spellh->spells[s->id].attributes.find("CREATURE_TARGET") != std::string::npos) //spell to be cast on one specific creature
|
||||||
|
{
|
||||||
|
CStack * st = getStackT(destinationTile);
|
||||||
|
if(st)
|
||||||
|
attackedCres.insert(st);
|
||||||
|
}
|
||||||
|
else //custom range from attackedHexes
|
||||||
|
{
|
||||||
|
for(std::set<ui16>::iterator it = attackedHexes.begin(); it != attackedHexes.end(); ++it)
|
||||||
|
{
|
||||||
|
CStack * st = getStackT(*it);
|
||||||
|
if(st)
|
||||||
|
attackedCres.insert(st);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return attackedCres;
|
||||||
|
}
|
||||||
|
|
||||||
CStack * BattleInfo::getNextStack()
|
CStack * BattleInfo::getNextStack()
|
||||||
{
|
{
|
||||||
CStack *current = getStack(activeStack);
|
CStack *current = getStack(activeStack);
|
||||||
|
@ -46,6 +46,7 @@ class CPathfinder;
|
|||||||
struct SetObjectProperty;
|
struct SetObjectProperty;
|
||||||
struct MetaString;
|
struct MetaString;
|
||||||
struct CPack;
|
struct CPack;
|
||||||
|
class CSpell;
|
||||||
|
|
||||||
|
|
||||||
std::string DLL_EXPORT toString(MetaString &ms);
|
std::string DLL_EXPORT toString(MetaString &ms);
|
||||||
@ -137,6 +138,7 @@ struct DLL_EXPORT BattleInfo
|
|||||||
static std::vector<int> neighbouringTiles(int hex);
|
static std::vector<int> neighbouringTiles(int hex);
|
||||||
static int calculateDmg(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting); //TODO: add additional conditions and require necessary data
|
static int calculateDmg(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting); //TODO: add additional conditions and require necessary data
|
||||||
void calculateCasualties(std::set<std::pair<ui32,si32> > *casualties);
|
void calculateCasualties(std::set<std::pair<ui32,si32> > *casualties);
|
||||||
|
std::set<CStack*> getAttackedCreatures(const CSpell * s, const CGHeroInstance * caster, int destinationTile); //calculates stack affected by given spell
|
||||||
};
|
};
|
||||||
|
|
||||||
class DLL_EXPORT CStack
|
class DLL_EXPORT CStack
|
||||||
|
@ -4440,7 +4440,7 @@ CSystemOptionsWindow::CSystemOptionsWindow(const SDL_Rect &pos, CPlayerInterface
|
|||||||
musicVolume = new CHighlightableButtonsGroup(0, true);
|
musicVolume = new CHighlightableButtonsGroup(0, true);
|
||||||
for(int i=1; i<=10; ++i)
|
for(int i=1; i<=10; ++i)
|
||||||
{
|
{
|
||||||
musicVolume->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[359+i].first),CGI->generaltexth->zelp[359+i].second, "syslb.def", 188 + 19*(i-1), 415, i*10);
|
musicVolume->addButton(boost::assign::map_list_of(0,CGI->generaltexth->zelp[325+i].first),CGI->generaltexth->zelp[325+i].second, "syslb.def", 188 + 19*(i-1), 415, i*10);
|
||||||
}
|
}
|
||||||
musicVolume->select(CGI->audioh->getMusicVolume(), 1);
|
musicVolume->select(CGI->audioh->getMusicVolume(), 1);
|
||||||
musicVolume->onChange = boost::bind(&CAudioHandler::setMusicVolume, CGI->audioh, _1);
|
musicVolume->onChange = boost::bind(&CAudioHandler::setMusicVolume, CGI->audioh, _1);
|
||||||
|
@ -2409,60 +2409,9 @@ bool CGameHandler::makeCustomAction( BattleAction &ba )
|
|||||||
sc.tile = ba.destinationTile;
|
sc.tile = ba.destinationTile;
|
||||||
sendAndApply(&sc);
|
sendAndApply(&sc);
|
||||||
|
|
||||||
//calculating affected creatures for all spells ///////////////////
|
//calculating affected creatures for all spells
|
||||||
std::set<ui16> attackedHexes = s->rangeInHexes(ba.destinationTile, h->getSpellSchoolLevel(s));
|
std::set<CStack*> attackedCres = gs->curB->getAttackedCreatures(s, h, ba.destinationTile);
|
||||||
std::set<CStack*> attackedCres; /*std::set to exclude multiple occurences of two hex creatures*/
|
|
||||||
if(ba.additionalInfo == 24 || ba.additionalInfo == 25 || ba.additionalInfo == 26) //death ripple, destroy undead and armageddon
|
|
||||||
{
|
|
||||||
for(int it=0; it<gs->curB->stacks.size(); ++it)
|
|
||||||
{
|
|
||||||
if((ba.additionalInfo == 24 && !gs->curB->stacks[it]->creature->isUndead()) //death ripple
|
|
||||||
|| (ba.additionalInfo == 25 && gs->curB->stacks[it]->creature->isUndead()) //destroy undead
|
|
||||||
|| (ba.additionalInfo == 26) //armageddon
|
|
||||||
)
|
|
||||||
{
|
|
||||||
attackedCres.insert(gs->curB->stacks[it]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(VLC->spellh->spells[ba.additionalInfo].attributes.find("CREATURE_TARGET_2") != std::string::npos) //spell to be cast on a specific creature but massive on expert
|
|
||||||
{
|
|
||||||
if(h->getSpellSchoolLevel(s) < 3) /*not expert */
|
|
||||||
{
|
|
||||||
CStack * st = gs->curB->getStackT(ba.destinationTile);
|
|
||||||
if(st)
|
|
||||||
attackedCres.insert(st);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for(int it=0; it<gs->curB->stacks.size(); ++it)
|
|
||||||
{
|
|
||||||
/*if it's non negative spell and our unit or non positive spell and hostile unit */
|
|
||||||
if((VLC->spellh->spells[ba.additionalInfo].positiveness >= 0 && gs->curB->stacks[it]->owner == h->tempOwner)
|
|
||||||
||(VLC->spellh->spells[ba.additionalInfo].positiveness <= 0 && gs->curB->stacks[it]->owner != h->tempOwner )
|
|
||||||
)
|
|
||||||
{
|
|
||||||
attackedCres.insert(gs->curB->stacks[it]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} //if(h->getSpellSchoolLevel(s) < 3)
|
|
||||||
}
|
|
||||||
else if(VLC->spellh->spells[ba.additionalInfo].attributes.find("CREATURE_TARGET") != std::string::npos) //spell to be cast on one specific creature
|
|
||||||
{
|
|
||||||
CStack * st = gs->curB->getStackT(ba.destinationTile);
|
|
||||||
if(st)
|
|
||||||
attackedCres.insert(st);
|
|
||||||
}
|
|
||||||
else //custom range from attackedHexes
|
|
||||||
{
|
|
||||||
for(std::set<ui16>::iterator it = attackedHexes.begin(); it != attackedHexes.end(); ++it)
|
|
||||||
{
|
|
||||||
CStack * st = gs->curB->getStackT(*it);
|
|
||||||
if(st)
|
|
||||||
attackedCres.insert(st);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//affected creatures calculated
|
|
||||||
//applying effects
|
//applying effects
|
||||||
switch(ba.additionalInfo) //spell id
|
switch(ba.additionalInfo) //spell id
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user