mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-17 00:07:41 +02:00
Revert "Merge pull request #124 from vcmi/issue/1372"
This reverts commitda01af319b
, reversing changes made to8b6b4e2e0b
.
This commit is contained in:
@ -651,8 +651,8 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance *hero1, const CGHer
|
||||
sendAndApply(&cs);
|
||||
}
|
||||
|
||||
cab1.updateArmy(this);
|
||||
cab2.updateArmy(this); //take casualties after battle is deleted
|
||||
cab1.takeFromArmy(this);
|
||||
cab2.takeFromArmy(this); //take casualties after battle is deleted
|
||||
|
||||
//if one hero has lost we will erase him
|
||||
if(battleResult.data->winner!=0 && hero1)
|
||||
@ -3848,16 +3848,18 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
|
||||
//TODO: From Strategija:
|
||||
//Summon Demon is a level 2 spell.
|
||||
{
|
||||
StartAction start_action(ba);
|
||||
sendAndApply(&start_action);
|
||||
|
||||
const CStack *summoner = gs->curB->battleGetStackByID(ba.stackNumber),
|
||||
*destStack = gs->curB->battleGetStackByPos(ba.destinationTile, false);
|
||||
|
||||
CreatureID summonedType(summoner->getBonusLocalFirst(Selector::type(Bonus::DAEMON_SUMMONING))->subtype);//in case summoner can summon more than one type of monsters... scream!
|
||||
BattleStackAdded bsa;
|
||||
bsa.attacker = summoner->attackerOwned;
|
||||
|
||||
bsa.creID = summonedType;
|
||||
bsa.creID = CreatureID(summoner->getBonusLocalFirst(Selector::type(Bonus::DAEMON_SUMMONING))->subtype); //in case summoner can summon more than one type of monsters... scream!
|
||||
ui64 risedHp = summoner->count * summoner->valOfBonuses(Bonus::DAEMON_SUMMONING, bsa.creID.toEnum());
|
||||
ui64 targetHealth = destStack->getCreature()->MaxHealth() * destStack->baseAmount;//todo: ignore AGE effect
|
||||
ui64 targetHealth = destStack->getCreature()->MaxHealth() * destStack->baseAmount;
|
||||
|
||||
ui64 canRiseHp = std::min(targetHealth, risedHp);
|
||||
ui32 canRiseAmount = canRiseHp / VLC->creh->creatures.at(bsa.creID)->MaxHealth();
|
||||
@ -3869,9 +3871,6 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
|
||||
|
||||
if (bsa.amount) //there's rare possibility single creature cannot rise desired type
|
||||
{
|
||||
StartAction start_action(ba);
|
||||
sendAndApply(&start_action);
|
||||
|
||||
BattleStacksRemoved bsr; //remove body
|
||||
bsr.stackIDs.insert(destStack->ID);
|
||||
sendAndApply(&bsr);
|
||||
@ -3883,9 +3882,9 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
|
||||
ssp.val = -1;
|
||||
ssp.absolute = false;
|
||||
sendAndApply(&ssp);
|
||||
|
||||
sendAndApply(&end_action);
|
||||
}
|
||||
|
||||
sendAndApply(&end_action);
|
||||
break;
|
||||
}
|
||||
case Battle::MONSTER_SPELL:
|
||||
@ -5805,52 +5804,13 @@ void CGameHandler::duelFinished()
|
||||
return;
|
||||
}
|
||||
|
||||
CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance * _army, BattleInfo *bat):
|
||||
army(_army)
|
||||
CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance *army, BattleInfo *bat)
|
||||
{
|
||||
heroWithDeadCommander = ObjectInstanceID();
|
||||
|
||||
PlayerColor color = army->tempOwner;
|
||||
if(color == PlayerColor::UNFLAGGABLE)
|
||||
color = PlayerColor::NEUTRAL;
|
||||
|
||||
auto killStack = [&, this](const SlotID slot, const CStackInstance * instance)
|
||||
{
|
||||
StackLocation sl(army, slot);
|
||||
newStackCounts.push_back(TStackAndItsNewCount(sl, 0));
|
||||
if(nullptr == instance)
|
||||
return;
|
||||
auto c = dynamic_cast <const CCommanderInstance *>(instance);
|
||||
if (c) //switch commander status to dead
|
||||
{
|
||||
auto h = dynamic_cast <const CGHeroInstance *>(army);
|
||||
if (h && h->commander == c)
|
||||
heroWithDeadCommander = army->id; //TODO: unify commander handling
|
||||
}
|
||||
};
|
||||
|
||||
//1. Find removed stacks.
|
||||
for(const auto & slotInfo : army->stacks)
|
||||
{
|
||||
const SlotID slot = slotInfo.first;
|
||||
const CStackInstance * instance = slotInfo.second;
|
||||
|
||||
if(nullptr != instance)//just in case
|
||||
{
|
||||
bool found = false;
|
||||
for(const CStack * sta : bat->stacks)
|
||||
{
|
||||
if(sta->base == instance)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//stack in this slot was removed == it is dead
|
||||
if(!found)
|
||||
killStack(slot, instance);
|
||||
}
|
||||
}
|
||||
|
||||
for(CStack *st : bat->stacks)
|
||||
{
|
||||
@ -5862,7 +5822,7 @@ CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance * _army, Battl
|
||||
//FIXME: this info is also used in BattleInfo::calculateCasualties, refactor
|
||||
st->count = std::max (0, st->count - st->resurrected);
|
||||
|
||||
if (!st->count && !st->base) //we can imagine stacks of war machines that are not spawned by artifacts?
|
||||
if (!st->count && !st->base) //we can imagine stacks of war mahcines that are not spawned by artifacts?
|
||||
{
|
||||
auto warMachine = VLC->arth->creatureToMachineID(st->type->idNumber);
|
||||
if (warMachine != ArtifactID::NONE)
|
||||
@ -5872,32 +5832,29 @@ CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance * _army, Battl
|
||||
removedWarMachines.push_back (ArtifactLocation(hero, hero->getArtPos(warMachine, true)));
|
||||
}
|
||||
}
|
||||
|
||||
if(army->slotEmpty(st->slot))
|
||||
|
||||
if(!army->slotEmpty(st->slot) && st->count < army->getStackCount(st->slot))
|
||||
{
|
||||
if(st->slot == SlotID::SUMMONED_SLOT_PLACEHOLDER && !vstd::contains(st->state, EBattleStackState::SUMMONED) && st->alive() && st->count > 0)
|
||||
{
|
||||
//this stack was permanently summoned
|
||||
const CreatureID summonedType = st->type->idNumber;
|
||||
summoned[summonedType] += st->count;
|
||||
}
|
||||
StackLocation sl(army, st->slot);
|
||||
if(st->alive())
|
||||
newStackCounts.push_back(std::pair<StackLocation, int>(sl, st->count));
|
||||
else
|
||||
newStackCounts.push_back(std::pair<StackLocation, int>(sl, 0));
|
||||
}
|
||||
else
|
||||
if (st->base && !st->count)
|
||||
{
|
||||
if(st->count == 0 || !st->alive())
|
||||
auto c = dynamic_cast <const CCommanderInstance *>(st->base);
|
||||
if (c) //switch commander status to dead
|
||||
{
|
||||
killStack(st->slot, st->base);
|
||||
}
|
||||
else if(st->count < army->getStackCount(st->slot))
|
||||
{
|
||||
StackLocation sl(army, st->slot);
|
||||
newStackCounts.push_back(TStackAndItsNewCount(sl, st->count));
|
||||
auto h = dynamic_cast <const CGHeroInstance *>(army);
|
||||
if (h && h->commander == c)
|
||||
heroWithDeadCommander = army->id; //TODO: unify commander handling
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CasualtiesAfterBattle::updateArmy(CGameHandler *gh)
|
||||
void CasualtiesAfterBattle::takeFromArmy(CGameHandler *gh)
|
||||
{
|
||||
for(TStackAndItsNewCount &ncount : newStackCounts)
|
||||
{
|
||||
@ -5906,21 +5863,6 @@ void CasualtiesAfterBattle::updateArmy(CGameHandler *gh)
|
||||
else
|
||||
gh->eraseStack(ncount.first, true);
|
||||
}
|
||||
for(auto summoned_iter : summoned)
|
||||
{
|
||||
SlotID slot = army->getSlotFor(summoned_iter.first);
|
||||
if(slot.validSlot())
|
||||
{
|
||||
StackLocation location(army, slot);
|
||||
gh->addToSlot(location, summoned_iter.first.toCreature(), summoned_iter.second);
|
||||
}
|
||||
else
|
||||
{
|
||||
//even if it will be possible to summon anything permanently it should be checked for free slot
|
||||
//necromancy is handled separately
|
||||
gh->complain("No free slot to put summoned creature");
|
||||
}
|
||||
}
|
||||
for (auto al : removedWarMachines)
|
||||
{
|
||||
gh->removeArtifact(al);
|
||||
|
Reference in New Issue
Block a user