@@ -174,14 +174,6 @@ export class TransportShipExecution implements Execution {
174174    } 
175175    this . lastMove  =  ticks ; 
176176
177-     if  ( this . boat . retreating ( ) )  { 
178-       this . dst  =  this . src ! ;  // src is guaranteed to be set at this point 
179- 
180-       if  ( this . boat . targetTile ( )  !==  this . dst )  { 
181-         this . boat . setTargetTile ( this . dst ) ; 
182-       } 
183-     } 
184- 
185177    // Team member can conquer disconnected player and gets their ships 
186178    // captureUnit has changed the owner of the unit, now update attacker 
187179    if  ( 
@@ -191,6 +183,34 @@ export class TransportShipExecution implements Execution {
191183    )  { 
192184      this . attacker  =  this . boat . owner ( ) ; 
193185      this . originalOwner  =  this . boat . owner ( ) ;  // for when this owner disconnects too 
186+ 
187+       // Ensure retreat source is valid for the new owner, may be same port 
188+       const  newSrc  =  this . attacker . canBuild ( UnitType . TransportShip ,  this . dst ) ; 
189+       if  ( newSrc  ===  false )  { 
190+         console . warn ( 
191+           `TransportShipExecution: Failed to find valid src for new attacker` , 
192+         ) ; 
193+       }  else  if  ( this . mg . owner ( this . src ! )  !==  this . attacker )  { 
194+         this . src  =  newSrc ; 
195+       } 
196+     } 
197+ 
198+     if  ( this . boat . retreating ( ) )  { 
199+       if  ( this . src  ===  null )  { 
200+         console . warn ( 
201+           `TransportShipExecution: retreating but no src found for new attacker` , 
202+         ) ; 
203+         this . attacker . addTroops ( this . boat . troops ( ) ) ; 
204+         this . boat . delete ( false ) ; 
205+         this . active  =  false ; 
206+         return ; 
207+       }  else  { 
208+         this . dst  =  this . src ; 
209+ 
210+         if  ( this . boat . targetTile ( )  !==  this . dst )  { 
211+           this . boat . setTargetTile ( this . dst ) ; 
212+         } 
213+       } 
194214    } 
195215
196216    const  result  =  this . pathFinder . nextTile ( this . boat . tile ( ) ,  this . dst ) ; 
0 commit comments