@@ -327,10 +327,18 @@ public static bool CanEnterTile(this MapUnit unit, Tile tile, bool allowCombat)
327327 return true ;
328328 }
329329
330- public static void move ( this MapUnit unit , TileDirection dir , bool wait = false )
330+ /// <summary>
331+ /// Moves the unit in the given direction
332+ /// </summary>
333+ /// <param name="unit"></param>
334+ /// <param name="dir">Which direction to move, e.g. northeast, west, etc.</param>
335+ /// <param name="wait">Whether the method should wait to return until animations complete</param>
336+ /// <returns>True if the unit is alive after the movement, false otherwise</returns>
337+ /// <exception cref="Exception"></exception>
338+ public static bool move ( this MapUnit unit , TileDirection dir , bool wait = false )
331339 {
332340 ( int dx , int dy ) = dir . toCoordDiff ( ) ;
333- var newLoc = EngineStorage . gameData . map . tileAt ( dx + unit . location . xCoordinate , dy + unit . location . yCoordinate ) ;
341+ Tile newLoc = EngineStorage . gameData . map . tileAt ( dx + unit . location . xCoordinate , dy + unit . location . yCoordinate ) ;
334342 if ( ( newLoc != Tile . NONE ) && unit . CanEnterTile ( newLoc , true ) && ( unit . movementPoints . canMove ) ) {
335343 unit . facingDirection = dir ;
336344 unit . wake ( ) ;
@@ -342,27 +350,31 @@ public static void move(this MapUnit unit, TileDirection dir, bool wait = false)
342350 CombatResult combatResult = unit . fight ( defender ) ;
343351 // If we were killed then of course there's nothing more to do. If the combat couldn't happen for whatever
344352 // reason, just give up on trying to move.
345- if ( combatResult == CombatResult . AttackerKilled || combatResult == CombatResult . Impossible )
346- return ;
353+ if ( combatResult == CombatResult . AttackerKilled ) {
354+ return false ;
355+ }
356+ if ( combatResult == CombatResult . Impossible ) {
357+ return true ;
358+ }
347359
348360 // If the enemy was defeated, check if there is another enemy on the tile. If so we can't complete the move
349361 // but still pay one movement point for the combat.
350362 else if ( combatResult == CombatResult . DefenderKilled || combatResult == CombatResult . DefenderRetreated ) {
351363 if ( ! unit . CanEnterTile ( newLoc , false ) ) {
352364 unit . movementPoints . onUnitMove ( 1 ) ;
353- return ;
365+ return true ;
354366 }
355367
356368 // Similarly if we retreated, pay one MP for the combat but don't move.
357369 } else if ( combatResult == CombatResult . AttackerRetreated ) {
358370 unit . movementPoints . onUnitMove ( 1 ) ;
359- return ;
371+ return true ;
360372 }
361373 } else if ( unit . unitType . bombard > 0 ) {
362374 unit . bombard ( newLoc ) ;
363- return ;
375+ return true ;
364376 } else {
365- return ;
377+ return true ;
366378 }
367379 }
368380
@@ -375,6 +387,7 @@ public static void move(this MapUnit unit, TileDirection dir, bool wait = false)
375387 unit . movementPoints . onUnitMove ( movementCost ) ;
376388 unit . animate ( MapUnit . AnimatedAction . RUN , wait ) ;
377389 }
390+ return true ;
378391 }
379392
380393 public static float getMovementCost ( Tile from , TileDirection dir , Tile newLocation ) {
0 commit comments