mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Several fixes for Whirlpool and stack removal.
Sea Captain's Hat is also supported.
This commit is contained in:
		| @@ -2869,19 +2869,21 @@ void CGTeleport::onHeroVisit( const CGHeroInstance * h ) const | ||||
| 				if (!h->hasBonusOfType(Bonus::WHIRLPOOL_PROTECTION)) | ||||
| 				{ | ||||
| 					CCreatureSet army = h->getArmy(); | ||||
| 					int targetstack = army.Slots().size()-1; | ||||
| 					for(TSlots::const_reverse_iterator i = army.Slots().rbegin(); i != army.Slots().rend(); i++) | ||||
| 					{ | ||||
| 						if (army.getPower(targetstack) > army.getPower(i->first)) | ||||
| 					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++) | ||||
| 						{ | ||||
| 							targetstack = (i->first); | ||||
| 							if (army.getPower(targetstack) > army.getPower(i->first)) | ||||
| 							{ | ||||
| 								targetstack = (i->first); | ||||
| 							} | ||||
| 						} | ||||
| 					} | ||||
| 					CCreatureSet ourArmy; | ||||
| 					ourArmy.addStack (targetstack, army.getStack(targetstack)); | ||||
| 					TQuantity tq = (TQuantity)((double)(ourArmy.getAmount(targetstack))*0.3); | ||||
| 					if (tq) //casualties > 0 | ||||
| 					{ | ||||
| 						CCreatureSet ourArmy; | ||||
| 						ourArmy.addStack (targetstack, army.getStack(targetstack)); | ||||
| 						TQuantity tq = (double)(ourArmy.getAmount(targetstack))*0.5; | ||||
| 						amax (tq, 1); | ||||
|  | ||||
| 						ourArmy.setStackCount (targetstack, tq); | ||||
| 						InfoWindow iw; | ||||
| 						iw.player = h->tempOwner; | ||||
| @@ -2928,7 +2930,10 @@ void CGTeleport::onHeroVisit( const CGHeroInstance * h ) const | ||||
| 		tlog2 << "Cannot find exit... (obj at " << pos << ") :( \n"; | ||||
| 		return; | ||||
| 	} | ||||
| 	cb->moveHero (h->id,CGHeroInstance::convertPosition(cb->getObj(destinationid)->pos,true) - getVisitableOffset(), true); | ||||
| 	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); | ||||
| } | ||||
|  | ||||
| void CGTeleport::initObj() | ||||
|   | ||||
| @@ -1893,14 +1893,15 @@ void CGameHandler::takeCreatures (int objid, TSlots creatures) //probably we cou | ||||
| 		return; | ||||
| 	const CArmedInstance* obj = static_cast<const CArmedInstance*>(getObj(objid)); | ||||
| 	CCreatureSet newArmy = obj->getArmy(); | ||||
| 	while (creatures.size() > 0) | ||||
| 	while (creatures.size()) | ||||
| 	{ | ||||
| 		int slot = newArmy.getSlotFor(creatures.begin()->second.type->idNumber); | ||||
| 		if (slot < 0) | ||||
| 			break; | ||||
|  | ||||
| 		newArmy.slots[slot].type = creatures.begin()->second.type; | ||||
| 		newArmy.slots[slot].count -= creatures.begin()->second.count; | ||||
| 		if (newArmy.getStack(slot).count < 1) | ||||
| 			newArmy.eraseStack(slot); | ||||
| 		creatures.erase (creatures.begin()); | ||||
| 	} | ||||
| 	SetGarrisons sg; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user