From e560bba808fa90731e9f5d1c2f4453bef5ea7f9f Mon Sep 17 00:00:00 2001 From: Oskar Wiksten Date: Thu, 27 Jun 2013 20:24:42 +0200 Subject: [PATCH] Bugfix: Store all visited maps in savegame * Required for keeping the "lastSeenLayoutHash" between savegames. --- AndorsTrail/AndroidManifest.xml | 2 +- .../AndorsTrail/AndorsTrailApplication.java | 2 +- .../controller/MovementController.java | 1 + .../AndorsTrail/model/map/MapCollection.java | 3 +- .../AndorsTrail/model/map/PredefinedMap.java | 102 ++++++++++-------- 5 files changed, 60 insertions(+), 50 deletions(-) diff --git a/AndorsTrail/AndroidManifest.xml b/AndorsTrail/AndroidManifest.xml index 726352be8..5ed2ce960 100644 --- a/AndorsTrail/AndroidManifest.xml +++ b/AndorsTrail/AndroidManifest.xml @@ -3,7 +3,7 @@ diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java index bd2072d53..de62b908c 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java @@ -18,7 +18,7 @@ public final class AndorsTrailApplication extends Application { public static final boolean DEVELOPMENT_VALIDATEDATA = true; public static final boolean DEVELOPMENT_DEBUGMESSAGES = true; public static final boolean DEVELOPMENT_INCOMPATIBLE_SAVEGAMES = DEVELOPMENT_DEBUGRESOURCES || DEVELOPMENT_DEBUGBUTTONS; - public static final int CURRENT_VERSION = DEVELOPMENT_INCOMPATIBLE_SAVEGAMES ? 999 : 36; + public static final int CURRENT_VERSION = DEVELOPMENT_INCOMPATIBLE_SAVEGAMES ? 999 : 37; public static final String CURRENT_VERSION_DISPLAY = "0.7.0dev"; private final AndorsTrailPreferences preferences = new AndorsTrailPreferences(); diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java index c335cce29..316fff49e 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java @@ -102,6 +102,7 @@ public final class MovementController implements TimedMessageTask.Callback { } controllers.mapController.applyCurrentMapReplacements(res, false); newMap.visited = true; + newMap.updateLastVisitTime(); moveBlockedActors(newMap, model.currentTileMap); refreshMonsterAggressiveness(newMap, model.player); controllers.effectController.updateSplatters(newMap); diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapCollection.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapCollection.java index ded0dcba7..1e3090122 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapCollection.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapCollection.java @@ -83,9 +83,8 @@ public final class MapCollection { } private static boolean shouldSaveMap(WorldContext world, PredefinedMap map) { + if (map.visited) return true; if (map == world.model.currentMap) return true; - if (!map.visited) return false; - if (map.hasPersistentData()) return true; return false; } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java index d3e322d6f..ca5035d2b 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java @@ -180,44 +180,52 @@ public final class PredefinedMap { // ====== PARCELABLE =================================================================== public void readFromParcel(DataInputStream src, WorldContext world, ControllerContext controllers, int fileversion) throws IOException { - final int loadedSpawnAreas = src.readInt(); - for(int i = 0; i < loadedSpawnAreas; ++i) { - if (AndorsTrailApplication.DEVELOPMENT_VALIDATEDATA) { - if (i >= this.spawnAreas.length) { - L.log("WARNING: Trying to load monsters in map " + this.name + " for spawn #" + i + ". This will totally fail."); + boolean shouldLoadPersistentData = true; + if (fileversion >= 37) shouldLoadPersistentData = src.readBoolean(); + + int loadedSpawnAreas = 0; + if (shouldLoadPersistentData) { + loadedSpawnAreas = src.readInt(); + for(int i = 0; i < loadedSpawnAreas; ++i) { + if (AndorsTrailApplication.DEVELOPMENT_VALIDATEDATA) { + if (i >= this.spawnAreas.length) { + L.log("WARNING: Trying to load monsters in map " + this.name + " for spawn #" + i + ". This will totally fail."); + } + } + this.spawnAreas[i].readFromParcel(src, world, fileversion); + } + + groundBags.clear(); + if (fileversion <= 5) return; + + final int size2 = src.readInt(); + for(int i = 0; i < size2; ++i) { + groundBags.add(new Loot(src, world, fileversion)); + } + + if (fileversion <= 11) return; + + if (fileversion < 37) visited = src.readBoolean(); + + if (fileversion <= 15) { + if (visited) { + lastVisitTime = System.currentTimeMillis(); + createAllContainerLoot(); + } + return; + } + lastVisitTime = src.readLong(); + + if (visited) { + if (fileversion > 30 && fileversion < 36) { + /*int lastVisitVersion = */src.readInt(); } } - this.spawnAreas[i].readFromParcel(src, world, fileversion); - } - - groundBags.clear(); - if (fileversion <= 5) return; - - final int size2 = src.readInt(); - for(int i = 0; i < size2; ++i) { - groundBags.add(new Loot(src, world, fileversion)); } + if (fileversion >= 37) visited = true; - if (fileversion <= 11) return; - visited = src.readBoolean(); - - - if (fileversion <= 15) { - if (visited) { - lastVisitTime = System.currentTimeMillis(); - createAllContainerLoot(); - } - return; - } - lastVisitTime = src.readLong(); - - if (visited) { - if (fileversion > 30 && fileversion < 36) { - /*int lastVisitVersion = */src.readInt(); - } - if (fileversion < 36) lastSeenLayoutHash = ""; - else lastSeenLayoutHash = src.readUTF(); - } + if (fileversion < 36) lastSeenLayoutHash = ""; + else lastSeenLayoutHash = src.readUTF(); for(int i = loadedSpawnAreas; i < spawnAreas.length; ++i) { MonsterSpawnArea area = this.spawnAreas[i]; @@ -227,18 +235,20 @@ public final class PredefinedMap { } public void writeToParcel(DataOutputStream dest, int flags) throws IOException { - dest.writeInt(spawnAreas.length); - for(MonsterSpawnArea a : spawnAreas) { - a.writeToParcel(dest, flags); - } - dest.writeInt(groundBags.size()); - for(Loot l : groundBags) { - l.writeToParcel(dest, flags); - } - dest.writeBoolean(visited); - dest.writeLong(lastVisitTime); - if (visited) { - dest.writeUTF(lastSeenLayoutHash); + if (hasPersistentData()) { + dest.writeBoolean(true); + dest.writeInt(spawnAreas.length); + for(MonsterSpawnArea a : spawnAreas) { + a.writeToParcel(dest, flags); + } + dest.writeInt(groundBags.size()); + for(Loot l : groundBags) { + l.writeToParcel(dest, flags); + } + dest.writeLong(lastVisitTime); + } else { + dest.writeBoolean(false); } + dest.writeUTF(lastSeenLayoutHash); } }