NEW_GAME_RANDOM_PLACEMENT.md 3.0 KB

New Game Random Team Placement

Overview

This feature ensures that when starting a new game, the TeamMarker is always randomly placed in a town/village, regardless of whether there are saved positions for the current map seed. The load functionality continues to work as before, preserving the player's saved team position.

How It Works

New Game Flow

  1. Player clicks "New Game" on title screen
  2. GameStateManager.StartNewGame() is called
  3. The isNewGame flag is set to true
  4. When the map scene loads, SimpleTeamPlacement checks this flag
  5. If isNewGame is true, saved positions are ignored and team is randomly placed
  6. After placement, the isNewGame flag is cleared
  7. The new random position is saved for future loads

Load Game Flow

  1. Player clicks "Load Game" on title screen
  2. GameStateManager.LoadGame() is called
  3. The isNewGame flag is set to false
  4. When the map scene loads, SimpleTeamPlacement loads the saved position
  5. Team is placed at the previously saved location

Key Features

Random Placement Even for Same Seeds

  • Even if a new game uses the same seed as a previous game, the team will be randomly placed
  • This ensures true randomness for new games while preserving saved positions for loads

Exploration System Support

  • The feature works with both regular map mode and exploration system
  • In exploration mode, new games will randomly select from available settlements
  • Load games in exploration mode will use the saved position

Debug Information

  • Enhanced debug logs show whether placement is for a new game or loaded game
  • Clear distinction in console output for troubleshooting

Testing

Manual Testing

  1. Start a new game → Team should be randomly placed
  2. Save the game and load it → Team should be at same position
  3. Start another new game with same seed → Team should be at different random position
  4. Load the saved game again → Team should be at original saved position

Context Menu Testing

Right-click on SimpleTeamPlacement in Inspector and use:

  • "Force New Game Random Placement" - Simulates new game behavior
  • "Randomly Place Team" - Normal random placement
  • "Show Marker Info" - Shows current team position details

Technical Details

Modified Files

  • GameStateManager.cs: Added isNewGame flag and related methods
  • SimpleTeamPlacement.cs: Added new game detection logic

Key Methods

  • GameStateManager.IsNewGameForceRandom(): Checks if random placement should be forced
  • GameStateManager.ClearNewGameFlag(): Clears flag after initial placement
  • SimpleTeamPlacement.WaitAndPlaceTeam(): Main placement logic with new game detection

PlayerPrefs Impact

  • Saved positions are still stored with map seed keys
  • New games overwrite saved positions for their seed
  • Load games continue to read from saved positions

Backward Compatibility

  • Existing save games continue to work exactly as before
  • No changes to save/load data structures
  • Feature is transparent to existing gameplay mechanics