]> www.infradead.org Git - users/mchehab/andors-trail.git/commitdiff
Bugfix: reset spawns on maps that have not been visited recently. This will shrink...
authorOskar Wiksten <oskar.wiksten@gmail.com>
Tue, 7 Aug 2012 07:55:54 +0000 (09:55 +0200)
committerOskar Wiksten <oskar.wiksten@gmail.com>
Tue, 7 Aug 2012 07:55:54 +0000 (09:55 +0200)
AndorsTrail/src/com/gpl/rpg/AndorsTrail/Savegames.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/DebugInterface.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/Controller.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/GameRoundController.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java

index ea91a53dc78ebb1cdc8f21c22bb5a97a77bf1934..7516e44d38920bd3e702e2a9d9406a720444ffdc 100644 (file)
@@ -24,6 +24,7 @@ import android.os.Environment;
 import com.gpl.rpg.AndorsTrail.context.WorldContext;
 import com.gpl.rpg.AndorsTrail.controller.ActorStatsController;
 import com.gpl.rpg.AndorsTrail.controller.Constants;
+import com.gpl.rpg.AndorsTrail.controller.Controller;
 import com.gpl.rpg.AndorsTrail.controller.MovementController;
 import com.gpl.rpg.AndorsTrail.model.ModelContainer;
 import com.gpl.rpg.AndorsTrail.util.L;
@@ -110,7 +111,8 @@ public final class Savegames {
        world.model.writeToParcel(dest, flags);
        dest.close();
     }
-    public static int loadWorld(WorldContext world, InputStream inState) throws IOException {
+       
+       public static int loadWorld(WorldContext world, InputStream inState) throws IOException {
        DataInputStream src = new DataInputStream(inState);
        final FileHeader header = new FileHeader(src);
        if (header.fileversion > AndorsTrailApplication.CURRENT_VERSION) return LOAD_RESULT_FUTURE_VERSION;
@@ -119,12 +121,17 @@ public final class Savegames {
        world.model = new ModelContainer(src, world, header.fileversion);
        src.close();
        
-       ActorStatsController.recalculatePlayerCombatTraits(world.model.player);
-               MovementController.moveBlockedActors(world);
+       onWorldLoaded(world);
        
        return LOAD_RESULT_SUCCESS;
     }
     
+       private static void onWorldLoaded(WorldContext world) {
+               ActorStatsController.recalculatePlayerCombatTraits(world.model.player);
+               Controller.resetMaps(world, true, true);
+               MovementController.moveBlockedActors(world);
+       }
+       
        public static FileHeader quickload(Context androidContext, int slot) {
                try {
                        if (slot != SLOT_QUICKSAVE) {
index b3734576d966977bf6f3cd21558ee497bab925c0..21e57f6f7782941290d62fc9793f89ae957d3553 100644 (file)
@@ -120,7 +120,7 @@ public final class DebugInterface {
                                public void onClick(View arg0) {
                                for(PredefinedMap map : world.maps.predefinedMaps) {
                                        map.lastVisitTime = 1;
-                                       map.resetIfNotRecentlyVisited();
+                                       map.resetIfNotRecentlyVisited(true);
                                }
                                mainActivity.showToast("DEBUG: maps respawned", Toast.LENGTH_SHORT);
                                }
index e4dc66cd1b2b1d9e79fce5d5017782d409c683dc..3caefd6bc39a8f1d5e98580c8c1d2c725f9b7867 100644 (file)
@@ -85,9 +85,7 @@ public final class Controller {
                        player.spawnPlace = area.id;
                        player.spawnMap = world.model.currentMap.name;
                }
-               for (PredefinedMap m : world.maps.predefinedMaps) {
-               if (m.visited) m.spawnAll(world);
-        }
+               resetMaps(world, false, true);
        }
 
        public static void ui_playerRested(final Activity currentActivity, final ViewContext viewContext, MapObject area) {
@@ -102,10 +100,12 @@ public final class Controller {
                return false;
        }
 
-       public void resetMaps() {
+       public static void resetMaps(final WorldContext world, boolean excludeCurrentMap, boolean resetEvenIfMapIsAlreadyReset) {
                for (PredefinedMap m : world.maps.predefinedMaps) {
-               if (m == model.currentMap) continue;
-                       m.resetIfNotRecentlyVisited();
+                       if (excludeCurrentMap) {
+                               if (m == world.model.currentMap) continue;
+                       }
+                       m.resetIfNotRecentlyVisited(resetEvenIfMapIsAlreadyReset);
        }
        }
 
index df94d67b66c1276904faaeaef3e432d335c4b0fb..5f1c460f87243fab3c2daa38d546473f7420a1ce 100644 (file)
@@ -54,7 +54,7 @@ public final class GameRoundController implements TimedMessageTask.Callback {
     }
        
     private void onNewFullRound() {
-       view.controller.resetMaps();
+       Controller.resetMaps(world, true, false);
        view.actorStatsController.applyConditionsToMonsters(model.currentMap, true);
        view.actorStatsController.applyConditionsToPlayer(model.player, true);
     }
index 5a1a5bc1664bf28980da94e8cab2d4a0b78aca30..57ab6f7c359b9ff47c976bbcffd7ec53f45a2add 100644 (file)
@@ -159,7 +159,7 @@ public final class PredefinedMap {
                        spawnAllInArea(world, a, respawnUniqueMonsters);
                }
        }
-       public void spawnAllInArea(WorldContext world, MonsterSpawnArea area, boolean respawnUniqueMonsters) {
+       private void spawnAllInArea(WorldContext world, MonsterSpawnArea area, boolean respawnUniqueMonsters) {
                while (area.isSpawnable(respawnUniqueMonsters)) {
                        final boolean wasAbleToSpawn = spawnInArea(area, world, null);
                        if (!wasAbleToSpawn) break;
@@ -226,8 +226,10 @@ public final class PredefinedMap {
        public void updateLastVisitTime() {
                lastVisitTime = System.currentTimeMillis();
        }
-       public void resetIfNotRecentlyVisited() {
-               if (lastVisitTime == VISIT_RESET) return;
+       public void resetIfNotRecentlyVisited(boolean resetEvenIfMapIsAlreadyReset) {
+               if (!resetEvenIfMapIsAlreadyReset) {
+                       if (lastVisitTime == VISIT_RESET) return;
+               }
                if (isRecentlyVisited()) return;
                
                // We reset all non-unique spawn areas. This keeps the savegame file smaller, thus reducing load and save times. Also keeps the running memory usage slightly lower.