fix: random neighbour field technically doesnt allow coordinates outside the map
This commit is contained in:
parent
23cceb9622
commit
4eb61a8f48
@ -710,18 +710,23 @@ public class GameLogic {
|
||||
return options;
|
||||
}
|
||||
|
||||
ArrayList<IntVector2> allOptions = new ArrayList<>();
|
||||
for(IntVector2 dir: IntVector2.CardinalDirections) {
|
||||
IntVector2 pos = start.copy().add(dir);
|
||||
if(pos.getX() < 0 || pos.getX() >= state.mapSize.getX() || pos.getY() < 0 || pos.getY() >= state.mapSize.getY()) {
|
||||
continue;
|
||||
}
|
||||
if(state.entities.findByPosition(pos).size() == 0) {
|
||||
allOptions.add(pos);
|
||||
if(state.entities.findByPosition(pos).isEmpty()) {
|
||||
options.add(pos);
|
||||
}
|
||||
}
|
||||
|
||||
if(options.size() == 0) {
|
||||
return getFreeNeighbour(state, start.copy().add(IntVector2.CardinalDirections[rand.nextInt(IntVector2.CardinalDirections.length)]));
|
||||
if(options.isEmpty()) {
|
||||
if(allOptions.isEmpty()) {
|
||||
return allOptions;
|
||||
}
|
||||
return getFreeNeighbour(state, start.copy().add(allOptions.get(rand.nextInt(allOptions.size()))));
|
||||
}else {
|
||||
return options;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user