@@ -104,7 +104,9 @@ public void setBlocking(final List<WalkPosition> blockedAreas) {
104104 public List <Area > getBlockedAreas () {
105105 final List <Area > blockedAreas = new ArrayList <>();
106106 for (final WalkPosition w : this .blockedAreas ) {
107- blockedAreas .add (getMap ().getArea (w ));
107+ if (getMap ().getArea (w ) != null ) {
108+ blockedAreas .add (getMap ().getArea (w ));
109+ }
108110 }
109111 return blockedAreas ;
110112 }
@@ -200,21 +202,23 @@ private void removeFromTiles() {
200202 }
201203 } else {
202204 Neutral prevStacked = tile .getNeutral ();
203- while (! prevStacked .getNextStacked (). equals ( this )) {
205+ while (prevStacked != null && ! this . equals ( prevStacked .getNextStacked ())) {
204206 prevStacked = prevStacked .getNextStacked ();
205207 }
206- if (!((NeutralImpl ) prevStacked ).isSameUnitTypeAs (this )) {
207- // bwem_assert(pPrevStacked->Type() == Type());
208- throw new IllegalStateException ();
209- } else if (!(prevStacked .getTopLeft ().equals (getTopLeft ()))) {
210- // bwem_assert(pPrevStacked->topLeft() == topLeft());
211- throw new IllegalStateException ();
212- } else if (!(dx == 0 && dy == 0 )) {
208+ if (!(dx == 0 && dy == 0 )) {
213209 // bwem_assert((dx == 0) && (dy == 0));
214210 throw new IllegalStateException ();
215211 }
216-
217- ((NeutralImpl ) prevStacked ).nextStacked = nextStacked ;
212+ if (prevStacked != null ) {
213+ if (!((NeutralImpl ) prevStacked ).isSameUnitTypeAs (this )) {
214+ // bwem_assert(pPrevStacked->Type() == Type());
215+ throw new IllegalStateException ();
216+ } else if (!(prevStacked .getTopLeft ().equals (getTopLeft ()))) {
217+ // bwem_assert(pPrevStacked->topLeft() == topLeft());
218+ throw new IllegalStateException ();
219+ }
220+ ((NeutralImpl ) prevStacked ).nextStacked = nextStacked ;
221+ }
218222 this .nextStacked = null ;
219223 return ;
220224 }
0 commit comments