Skip to content

Instantly share code, notes, and snippets.

@lulebe
Last active January 2, 2018 19:19
Show Gist options
  • Select an option

  • Save lulebe/39b9791d108b499dcf2b1c8b14ecb915 to your computer and use it in GitHub Desktop.

Select an option

Save lulebe/39b9791d108b499dcf2b1c8b14ecb915 to your computer and use it in GitHub Desktop.
Kreuzzüge Gamedata structure

Kreuzzüge gamedata structure proposal

Faction = enum {CRUSADERS, SARACEN}
GameType = enum {SINGLEPLAYER, MULTIPLAYER_LOCAL, MULTIPLAYER_REMOTE}
UnitType = enum {GUARD, ARCHER, SHIP...}

The actual enum order for Units will be provided later, but will be ordered by how units are listed within each recruiting building, in the following order: Foot, Horse, Artillery, Ship, Air. So the Guard will have ID 1 and the Bird the highest ID. All enums are serialized to Integers starting with Index 1, to avoid null-check issues in javascript because 0 == false there.

{
  type: GameType, //see above
  map: Integer, //mapId
  playerA: {
    faction: Faction, //see above
    money: Integer,
    units: [Unit], //see below
    buildings: [Integer] //describes index in map fields array, see below
  },
  playerB: {}, //same as playerA
  turn: Integer
}


Unit = {
  type: UnitType, //see above
  hp: Integer,
  food: Integer,
  ammo: Integer
}

Maps will have fields as one-dimensional Array from left to right, top to bottom like you would read a book. That means that buildings and units only need one Int to store their position, instead of a [x,y] data structure.

simple example

{
  type: 2,
  map: 1,
  playerA: {
    faction: 1,
    money: 95,
    units: [{type: 4, hp: 6, food: 1, ammo: 3}],
    buildings: [13, 24, 36]
  },
  playerB: {
    faction: 2,
    money: 162,
    units: [{type: 3, hp: 4, food: 2, ammo: -1}],
    buildings: [19, 38, 49]
  },
  turn: 13
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment