2021-04-29 17:15:29 +00:00
|
|
|
package uulm.teamname.marvelous.gamelibrary.gamelogic;
|
|
|
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
2021-05-01 17:47:19 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.*;
|
2021-04-29 17:15:29 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.Tuple;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** Represents the state of a game instance. */
|
2021-04-29 17:15:29 +00:00
|
|
|
class GameState {
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The size of the map */
|
2021-04-29 17:15:29 +00:00
|
|
|
public final IntVector2 mapSize;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The list of {@link Entity}s inside the game */
|
2021-05-01 17:47:19 +00:00
|
|
|
public final EntityManager entities = new EntityManager();
|
2021-04-29 17:15:29 +00:00
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The total amount of full turn cycles that occurred */
|
2021-04-29 17:15:29 +00:00
|
|
|
public int roundNumber = 0;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The turn order of every character */
|
2021-04-30 19:48:28 +00:00
|
|
|
public ArrayList<EntityID> turnOrder = new ArrayList<>();
|
2021-04-29 17:15:29 +00:00
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The total amount of turns that occurred */
|
2021-04-29 17:15:29 +00:00
|
|
|
public int turnNumber = 0;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The {@link EntityID} of the active character */
|
2021-04-30 19:48:28 +00:00
|
|
|
public EntityID activeCharacter = null;
|
2021-04-29 17:15:29 +00:00
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** Whether or not the game was won */
|
2021-04-29 17:15:29 +00:00
|
|
|
public boolean won = false;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The global cooldown of every infinity stone */
|
2021-05-01 17:47:19 +00:00
|
|
|
public final StoneCooldownManager stoneCooldown = new StoneCooldownManager();
|
2021-04-29 17:15:29 +00:00
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The store of the {@link WinCondition} data for every win condition for each player */
|
|
|
|
public final HashMap<Tuple<ParticipantType, WinCondition>, Integer> winConditions = new HashMap<>();
|
2021-04-29 17:15:29 +00:00
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/**
|
|
|
|
* Constructs a new {@link GameState}.
|
|
|
|
* @param mapSize The size of the map
|
2021-04-29 17:15:29 +00:00
|
|
|
*/
|
|
|
|
public GameState(IntVector2 mapSize) {
|
|
|
|
this.mapSize = mapSize;
|
|
|
|
}
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/**
|
2021-04-30 19:48:28 +00:00
|
|
|
* Clones the state into a new {@link GameState} object. This is slow.
|
2021-04-30 18:54:34 +00:00
|
|
|
* @return The cloned game state
|
2021-04-29 17:15:29 +00:00
|
|
|
*/
|
|
|
|
public GameState snapshot() {
|
2021-04-30 19:48:28 +00:00
|
|
|
GameState clone = new GameState(this.mapSize);
|
|
|
|
|
2021-05-01 17:47:19 +00:00
|
|
|
clone.entities.cloneFrom(entities);
|
2021-04-30 19:48:28 +00:00
|
|
|
|
|
|
|
clone.roundNumber = roundNumber;
|
|
|
|
|
|
|
|
clone.turnOrder = new ArrayList<>();
|
|
|
|
for(EntityID id: turnOrder) {
|
|
|
|
clone.turnOrder.add(id.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
clone.turnNumber = turnNumber;
|
|
|
|
|
|
|
|
clone.activeCharacter = activeCharacter != null ? activeCharacter.clone() : null;
|
|
|
|
|
|
|
|
clone.won = won;
|
|
|
|
|
2021-05-01 17:47:19 +00:00
|
|
|
clone.stoneCooldown.cloneFrom(stoneCooldown);
|
2021-04-30 19:48:28 +00:00
|
|
|
|
|
|
|
for(Tuple<ParticipantType, WinCondition> condition: winConditions.keySet()) {
|
|
|
|
clone.winConditions.put(condition, winConditions.get(condition));
|
|
|
|
}
|
|
|
|
|
|
|
|
return clone;
|
2021-04-29 17:15:29 +00:00
|
|
|
}
|
2021-05-18 12:14:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Restores the state rom the given {@link GameState}. This is slow.
|
|
|
|
* @param state The state to restore from
|
|
|
|
*/
|
|
|
|
public void restore(GameState state) {
|
|
|
|
mapSize.set(state.mapSize);
|
|
|
|
|
|
|
|
entities.cloneFrom(state.entities);
|
|
|
|
|
|
|
|
roundNumber = state.roundNumber;
|
|
|
|
|
|
|
|
turnOrder = new ArrayList<>();
|
|
|
|
for(EntityID id: state.turnOrder) {
|
|
|
|
turnOrder.add(id.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
turnNumber = state.turnNumber;
|
|
|
|
|
|
|
|
activeCharacter = state.activeCharacter != null ? state.activeCharacter.clone() : null;
|
|
|
|
|
|
|
|
won = state.won;
|
|
|
|
|
|
|
|
stoneCooldown.cloneFrom(state.stoneCooldown);
|
|
|
|
|
|
|
|
for(Tuple<ParticipantType, WinCondition> condition: state.winConditions.keySet()) {
|
|
|
|
winConditions.put(condition, state.winConditions.get(condition));
|
|
|
|
}
|
|
|
|
}
|
2021-04-29 17:15:29 +00:00
|
|
|
}
|