mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-02-23 15:38:29 +01:00
Bugfix: reset spawns on maps that have not been visited recently. This will shrink the savegame size to about a fifth of the previous sizes.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user