mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Fixed #1585 - destroyed war machines will be removed from hero's equipment.
This commit is contained in:
@@ -387,36 +387,45 @@ void CArtHandler::loadGrowingArt(CGrowingArtifact * art, const JsonNode & node)
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: use bimap
|
||||
ArtifactID CArtHandler::creatureToMachineID(CreatureID id)
|
||||
{
|
||||
int dif = 142;
|
||||
switch (id)
|
||||
{
|
||||
case 147:
|
||||
dif--;
|
||||
case CreatureID::CATAPULT: //Catapult
|
||||
return ArtifactID::CATAPULT;
|
||||
break;
|
||||
case 148:
|
||||
dif++;
|
||||
case CreatureID::BALLISTA: //Ballista
|
||||
return ArtifactID::BALLISTA;
|
||||
break;
|
||||
case CreatureID::FIRST_AID_TENT: //First Aid tent
|
||||
return ArtifactID::FIRST_AID_TENT;
|
||||
break;
|
||||
case CreatureID::AMMO_CART: //Ammo cart
|
||||
return ArtifactID::AMMO_CART;
|
||||
break;
|
||||
}
|
||||
dif = -dif;
|
||||
return ArtifactID(id+dif);
|
||||
return ArtifactID::NONE; //this creature is not artifact
|
||||
}
|
||||
|
||||
CreatureID CArtHandler::machineIDToCreature(ArtifactID id)
|
||||
{
|
||||
int dif = 142;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case 6:
|
||||
dif--;
|
||||
case ArtifactID::CATAPULT:
|
||||
return CreatureID::CATAPULT;
|
||||
break;
|
||||
case 5:
|
||||
dif++;
|
||||
case ArtifactID::BALLISTA:
|
||||
return CreatureID::BALLISTA;
|
||||
break;
|
||||
case ArtifactID::FIRST_AID_TENT:
|
||||
return CreatureID::FIRST_AID_TENT;
|
||||
break;
|
||||
case ArtifactID::AMMO_CART:
|
||||
return CreatureID::AMMO_CART;
|
||||
break;
|
||||
}
|
||||
return CreatureID(id + dif);
|
||||
return CreatureID::NONE; //this artifact is not a creature
|
||||
}
|
||||
|
||||
ArtifactID CArtHandler::getRandomArt(int flags)
|
||||
|
@@ -618,7 +618,8 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance *hero1, const CGHer
|
||||
sendAndApply(&cs);
|
||||
}
|
||||
|
||||
cab1.takeFromArmy(this); cab2.takeFromArmy(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)
|
||||
@@ -6353,11 +6354,24 @@ CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance *army, BattleI
|
||||
{
|
||||
if(vstd::contains(st->state, EBattleStackState::SUMMONED)) //don't take into account summoned stacks
|
||||
continue;
|
||||
if (st->owner != color) //remove only our stacks
|
||||
continue;
|
||||
|
||||
//FIXME: this info is also used in BattleInfo::calculateCasualties, refactor
|
||||
st->count = std::max (0, st->count - st->resurrected);
|
||||
|
||||
if(st->owner==color && !army->slotEmpty(st->slot) && st->count < army->getStackCount(st->slot))
|
||||
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)
|
||||
{
|
||||
auto hero = dynamic_cast<const CGHeroInstance*> (army);
|
||||
if (hero)
|
||||
removedWarMachines.push_back (ArtifactLocation(hero, hero->getArtPos(warMachine, true)));
|
||||
}
|
||||
}
|
||||
|
||||
if(!army->slotEmpty(st->slot) && st->count < army->getStackCount(st->slot))
|
||||
{
|
||||
StackLocation sl(army, st->slot);
|
||||
if(st->alive())
|
||||
@@ -6387,6 +6401,10 @@ void CasualtiesAfterBattle::takeFromArmy(CGameHandler *gh)
|
||||
else
|
||||
gh->eraseStack(ncount.first, true);
|
||||
}
|
||||
for (auto al : removedWarMachines)
|
||||
{
|
||||
gh->removeArtifact(al);
|
||||
}
|
||||
if (heroWithDeadCommander != ObjectInstanceID())
|
||||
{
|
||||
SetCommanderProperty scp;
|
||||
|
@@ -71,6 +71,7 @@ struct CasualtiesAfterBattle
|
||||
typedef std::pair<StackLocation, int> TStackAndItsNewCount;
|
||||
enum {ERASE = -1};
|
||||
std::vector<TStackAndItsNewCount> newStackCounts;
|
||||
std::vector<ArtifactLocation> removedWarMachines;
|
||||
ObjectInstanceID heroWithDeadCommander; //TODO: unify stack loactions
|
||||
|
||||
CasualtiesAfterBattle(const CArmedInstance *army, BattleInfo *bat);
|
||||
|
Reference in New Issue
Block a user