Skip to content

Commit c40b8b6

Browse files
committed
Merge branch 'master' of https://github.com/SupSuper/OpenXcom
2 parents 23bd77d + db432dc commit c40b8b6

3 files changed

Lines changed: 28 additions & 18 deletions

File tree

src/Battlescape/BattlescapeGenerator.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,20 +1609,25 @@ bool BattlescapeGenerator::placeUnitNearFriend(BattleUnit *unit)
16091609
{
16101610
return false;
16111611
}
1612-
Position entryPoint = Position(-1, -1, -1);
1613-
int tries = 100;
1614-
while (entryPoint == Position(-1, -1, -1) && tries)
1612+
for (int i = 0; i != 10; ++i)
16151613
{
1616-
BattleUnit* k = _save->getUnits()->at(RNG::generate(0, _save->getUnits()->size()-1));
1617-
if (k->getFaction() == unit->getFaction() && k->getPosition() != Position(-1, -1, -1) && k->getArmor()->getSize() >= unit->getArmor()->getSize())
1614+
Position entryPoint = Position(-1, -1, -1);
1615+
int tries = 100;
1616+
bool largeUnit = false;
1617+
while (entryPoint == Position(-1, -1, -1) && tries)
16181618
{
1619-
entryPoint = k->getPosition();
1619+
BattleUnit* k = _save->getUnits()->at(RNG::generate(0, _save->getUnits()->size()-1));
1620+
if (k->getFaction() == unit->getFaction() && k->getPosition() != Position(-1, -1, -1) && k->getArmor()->getSize() >= unit->getArmor()->getSize())
1621+
{
1622+
entryPoint = k->getPosition();
1623+
largeUnit = (k->getArmor()->getSize() != 1);
1624+
}
1625+
--tries;
1626+
}
1627+
if (tries && _save->placeUnitNearPosition(unit, entryPoint, largeUnit))
1628+
{
1629+
return true;
16201630
}
1621-
--tries;
1622-
}
1623-
if (tries && _save->placeUnitNearPosition(unit, entryPoint))
1624-
{
1625-
return true;
16261631
}
16271632
return false;
16281633
}

src/Savegame/SavedBattleGame.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,9 @@ void SavedBattleGame::reviveUnconsciousUnits()
14331433
}
14341434
if ((*i)->getStatus() == STATUS_UNCONSCIOUS && (*i)->getStunlevel() < (*i)->getHealth() && (*i)->getHealth() > 0)
14351435
{
1436-
if (placeUnitNearPosition((*i), originalPosition))
1436+
Tile *targetTile = getTile(originalPosition);
1437+
bool largeUnit = targetTile && targetTile->getUnit() && targetTile->getUnit() != *i && targetTile->getUnit()->getArmor()->getSize() != 1;
1438+
if (placeUnitNearPosition((*i), originalPosition, largeUnit))
14371439
{
14381440
// recover from unconscious
14391441
(*i)->turn(false); // makes the unit stand up again
@@ -1673,19 +1675,22 @@ int SavedBattleGame::getMoraleModifier(BattleUnit* unit)
16731675
* @param entryPoint The position around which to attempt to place the unit.
16741676
* @return True if the unit was successfully placed.
16751677
*/
1676-
bool SavedBattleGame::placeUnitNearPosition(BattleUnit *unit, Position entryPoint)
1678+
bool SavedBattleGame::placeUnitNearPosition(BattleUnit *unit, Position entryPoint, bool largeFriend)
16771679
{
16781680
if (setUnitPosition(unit, entryPoint))
16791681
{
16801682
return true;
16811683
}
1682-
1684+
1685+
int me = 0 - unit->getArmor()->getSize();
1686+
int you = largeFriend ? 2 : 1;
1687+
int xArray[8] = {0, you, you, you, 0, me, me, me};
1688+
int yArray[8] = {me, me, 0, you, you, you, 0, me};
16831689
for (int dir = 0; dir <= 7; ++dir)
16841690
{
1685-
Position offset;
1686-
getPathfinding()->directionToVector(dir, &offset);
1691+
Position offset = Position (xArray[dir], yArray[dir], 0);
16871692
Tile *t = getTile(entryPoint + offset);
1688-
if (t && !getPathfinding()->isBlocked(getTile(entryPoint), t, dir, 0)
1693+
if (t && !getPathfinding()->isBlocked(getTile(entryPoint + (offset / 2)), t, dir, 0)
16891694
&& setUnitPosition(unit, entryPoint + offset))
16901695
{
16911696
return true;

src/Savegame/SavedBattleGame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class SavedBattleGame
226226
/// Checks whether a particular faction has eyes on *unit (whether any unit on that faction sees *unit).
227227
bool eyesOnTarget(UnitFaction faction, BattleUnit* unit);
228228
/// Attempts to place a unit on or near entryPoint.
229-
bool placeUnitNearPosition(BattleUnit *unit, Position entryPoint);
229+
bool placeUnitNearPosition(BattleUnit *unit, Position entryPoint, bool largeFriend);
230230
/// Resets the turn counter.
231231
void resetTurnCounter();
232232
/// Resets the visibility of all tiles on the map.

0 commit comments

Comments
 (0)