Skip to content

Serialization Design

Rhys Fuller edited this page Apr 28, 2022 · 8 revisions

File Format

  • File will be in binary.
  • File will begin with the string "Civilization209" to prove that it is a proper save file of the game.
  • File will then have an integer representing the current score of the game.
  • File will then have a character representing the current season of the game.
  • File will then have a character representing the current difficulty of the game.
  • File will then have an integer representing the number of player cities left.
  • File will then have a double representing the game speed.
  • File will then have an integer X representing the number of items in the Entity List.
  • Following that, there will be X sections representing X entities.
    • The first item of the section is the string type of the entity, either "City", "Troop", or "Projectile". Weather has special cases.
    • Cities will have the following format:
      • File will have two doubles representing the location coordinate.
      • File will have an integer representing the turn count.
      • File will have an integer representing the current population of the city.
      • File will have a char representing the nationality of the city, where 'P' is player, 'E' is enemy, and 'N' is neutral.
      • File will have a boolean representing whether the city is currently selected or not.
      • File will have a char representing the CityType of the city, where 's' is standard, 'F' is fast, and 'S' is strong.
    • Troops will have the following format:
      • File will have two doubles representing the location coordinate.
      • File will have an integer representing the turn count.
      • File will have a double representing the speed of the troop.
      • File will have a double representing the heading of the troop.
      • File will have an integer representing the health of the troop.
      • File will have a char representing the nationality of the troop, where 'P' is player, 'E' is enemy, and 'N' is neutral.
      • File will have a char representing the destination type of the troop, where 'i' is city and 'o' is coordinate.
      • File will have a char representing the CityType of the troop, where 's' is standard, 'F' is fast, and 'S' is strong.
      • File will have two doubles representing the destination coordinate.
    • Weather entities will have the following format:
      • As opposed to all other types, weather name is either "L" representing lightning, "B" representing blizzard, or "F" representing flood.
      • File will have two doubles representing the location coordinate.
      • File will have an integer representing the turn count.
      • File will have a double representing the speed of the weather entity.
      • File will have a double representing the heading of the weather entity.
    • Projectile entities will have the following format:
      • File will have two doubles representing the location coordinate.
      • File will have an integer representing the turn count.
      • File will have a double representing the speed of the projectile.
      • File will have a double representing the heading of the projectile.
      • File will have two doubles representing the destination coordinate of the projectile.
      • File will have an integer representing the damage of the projectile.

Sample File

(Text representation of binary)

Civilization209
400
W
E
3
.5
4
City|43.2|23.4|5|21|P|true|s|
Troop|80.2|46.2|3|100.0|100.0|2|P|i|s|39.0|42.0|
Projectile|70.4|46.2|1|80.2|46.2|1.3|180.0|2|
L|300.2|267.4|0|1000.0|1000.0|

Links to Relevant Code

Serialization Unit Tests

Game Load Function

Game Save Function

City Load Function

City Save Function

Troop Load Function

Troop Save Function

Projectile Load Function

Projectile Save Function

Weather Load Function

Weather Save Function

Design Review

  • 2022-4-8 at 11:45 AM
  • Reviewer: Emily Bronkema
  • Suggestion: Fix the spelling of the Nationality Enum, "nuetral" to "neutral." Suggestion has been implemented.
Clone this wiki locally