1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-05 00:49:09 +02:00

Several fixes for Whirlpool and stack removal.

Sea Captain's Hat is also supported.
This commit is contained in:
DjWarmonger
2010-06-25 08:19:39 +00:00
parent e2fd2bbe04
commit 08da1692cf
2 changed files with 20 additions and 14 deletions

View File

@ -2869,7 +2869,9 @@ void CGTeleport::onHeroVisit( const CGHeroInstance * h ) const
if (!h->hasBonusOfType(Bonus::WHIRLPOOL_PROTECTION)) if (!h->hasBonusOfType(Bonus::WHIRLPOOL_PROTECTION))
{ {
CCreatureSet army = h->getArmy(); CCreatureSet army = h->getArmy();
int targetstack = army.Slots().size()-1; if (army.Slots().size() > 1 || army.Slots().begin()->second.count > 1)
{ //we can't remove last unit
int targetstack = army.Slots().begin()->first; //slot numbers may vary
for(TSlots::const_reverse_iterator i = army.Slots().rbegin(); i != army.Slots().rend(); i++) for(TSlots::const_reverse_iterator i = army.Slots().rbegin(); i != army.Slots().rend(); i++)
{ {
if (army.getPower(targetstack) > army.getPower(i->first)) if (army.getPower(targetstack) > army.getPower(i->first))
@ -2879,9 +2881,9 @@ void CGTeleport::onHeroVisit( const CGHeroInstance * h ) const
} }
CCreatureSet ourArmy; CCreatureSet ourArmy;
ourArmy.addStack (targetstack, army.getStack(targetstack)); ourArmy.addStack (targetstack, army.getStack(targetstack));
TQuantity tq = (TQuantity)((double)(ourArmy.getAmount(targetstack))*0.3); TQuantity tq = (double)(ourArmy.getAmount(targetstack))*0.5;
if (tq) //casualties > 0 amax (tq, 1);
{
ourArmy.setStackCount (targetstack, tq); ourArmy.setStackCount (targetstack, tq);
InfoWindow iw; InfoWindow iw;
iw.player = h->tempOwner; iw.player = h->tempOwner;
@ -2928,6 +2930,9 @@ void CGTeleport::onHeroVisit( const CGHeroInstance * h ) const
tlog2 << "Cannot find exit... (obj at " << pos << ") :( \n"; tlog2 << "Cannot find exit... (obj at " << pos << ") :( \n";
return; return;
} }
if (ID == 111)
cb->moveHero (h->id,CGHeroInstance::convertPosition(cb->getObj(destinationid)->pos,true) + (h->pos - pos) - int3(1,0,0), true);
else
cb->moveHero (h->id,CGHeroInstance::convertPosition(cb->getObj(destinationid)->pos,true) - getVisitableOffset(), true); cb->moveHero (h->id,CGHeroInstance::convertPosition(cb->getObj(destinationid)->pos,true) - getVisitableOffset(), true);
} }

View File

@ -1893,14 +1893,15 @@ void CGameHandler::takeCreatures (int objid, TSlots creatures) //probably we cou
return; return;
const CArmedInstance* obj = static_cast<const CArmedInstance*>(getObj(objid)); const CArmedInstance* obj = static_cast<const CArmedInstance*>(getObj(objid));
CCreatureSet newArmy = obj->getArmy(); CCreatureSet newArmy = obj->getArmy();
while (creatures.size() > 0) while (creatures.size())
{ {
int slot = newArmy.getSlotFor(creatures.begin()->second.type->idNumber); int slot = newArmy.getSlotFor(creatures.begin()->second.type->idNumber);
if (slot < 0) if (slot < 0)
break; break;
newArmy.slots[slot].type = creatures.begin()->second.type; newArmy.slots[slot].type = creatures.begin()->second.type;
newArmy.slots[slot].count -= creatures.begin()->second.count; newArmy.slots[slot].count -= creatures.begin()->second.count;
if (newArmy.getStack(slot).count < 1)
newArmy.eraseStack(slot);
creatures.erase (creatures.begin()); creatures.erase (creatures.begin());
} }
SetGarrisons sg; SetGarrisons sg;