Categorygithub.com/samuelyuan/Civ5MapViewer
modulepackage
0.0.0-20241114011112-3a690da5dc69
Repository: https://github.com/samuelyuan/civ5mapviewer.git
Documentation: pkg.go.dev

# README

Civ5MapViewer

Table of Contents

Introduction

This project is the GUI version of Civ5MapImage. It is supposed to be an open-source lightweight map viewer.

Most custom maps designed for Civ 5 will usually provide screenshots of the map, but they will either only show a portion of the map in the game or a zoomed out image which shows all of the cities but not the terrain. This program is designed to provide you a detailed view of the entire map in one single image.

You have the option of generating a physical map or a political map. The physical map focuses on generating the terrain, while the political map shows the civilization boundaries and major cities.

earth

Features

  • Supported map file formats for importing: .civ5map, .json
  • Export .civ5map maps to json
  • Save a screenshot of the map as an image using "Save Image As"
  • After loading the map, click on any hex to get all the properties of the hex

Examples

europe europe europe
europe world earth 1900
earth 1936 earth 1939 earth 1942
earth 2014 huge 1 earth 2014 huge 2 earth 2022
mongol india stalingrad

File format

This file format covers .civ5map files, which stores the map data. All data is stored in little endian.

Header

TypeSizeDescription
uint81 byteScenarioVersion (The leftmost 4 bits are for scenario. The rightmost 4 bits are for version, which is set to 12 for newer files.)
uint324 bytesMap width
uint324 bytesMap height
uint81 byteNumber of players
uint8[4]4 bytesSettings (hasWorldWrap, hasRandomResources, hasRandomGoodies)
uint324 bytesTerrainDataSize (Length of terrain list)
uint324 bytesFeatureTerrainDataSize (Length of feature terrain list)
uint324 bytesFeatureWonderDataSize (Length of feature wonder list)
uint324 bytesResourceDataSize (Length of resource list)
uint324 bytesModDataSize
uint324 bytesMapNameLength
uint324 bytesMapDescriptionLength

Following the header, is a list of strings whose size is determined in the header. Each string list will have a zero byte to split items.

Geography list data

TypeSizeDescription
String listTerrainDataSize bytesTerrain (e.g. TERRAIN_GRASS)
String listFeatureTerrainDataSize bytesFeature terrain (e.g. FEATURE_ICE)
String listFeatureWonderDataSize bytesFeature wonders(e.g. FEATURE_CRATER, FEATURE_FUJI)
String listResourceDataSize bytesResources (e.g. RESOURCE_IRON)
StringModDataSize bytesmodData
StringMapNameLength bytesMap name
StringMapDescriptionLength bytesMap description
uint324 bytesWorldSizeLength (Only if version >= 11)
StringWorldSizeLength bytesWorldSize (Only if version >= 11)

Map geography

The map data is inverted, which means that the bottommost row rendered on the screen is stored on the top row of the array and the topmost row rendered on the screen is stored on the last row of the array.

TypeSizeDescription
MapTile[Height][Width](Height * Width * 8) bytesMap geography

Map tile data

The size of this struct is 8 bytes.

TypeSizeDescription
uint81 byteTerrainType (index in terrain list)
uint81 byteResourceType (index in resource list, 0xFF if none)
uint81 byteFeatureTerrainType (index in feature terrain list, 0xFF if none)
uint81 byteRiverData (The low 3 bits means the tile border has a river. Only 3 edges needs to be marked per tile. 4 (>>2) is southwest edge, 2 (>>1) is southeast edge, 1 (>>0) is eastern edge)
uint81 byteElevation (0 = flat, 1 = hills, 2 = mountain)
uint81 byteContinent (0 = none, 1 = Americas, 2 = Asia, 3 = Africa, 4 = Europe)
uint81 byteFeatureWonderType (index in feature wonder list, 0xFF if none)
uint81 byteResourceAmount

Game description header

TypeSizeDescription
byte[68]68 bytesUnknown, seems related to GameSpeed
uint324 bytesMaxTurns
byte[4]4 bytesUnknown
uint324 bytesStartYear
uint81 bytePlayerCount (Number of playable civs)
uint81 byteCityStateCount
uint81 byteTeamCount (should be the sum of PlayerCount and CityStateCount)
byte1 byteUnknown
uint324 bytesImprovementDataSize
uint324 bytesUnitTypeDataSize
uint324 bytesTechTypeDataSize
uint324 bytesPolicyTypeDataSize
uint324 bytesBuildingTypeDataSize
uint324 bytesPromotionTypeDataSize
uint324 bytesUnitDataSize
uint324 bytesUnitNameDataSize
uint324 bytesCityDataSize
uint324 bytesVictoryDataSize (Only if version >= 11)
uint324 bytesGameOptionDataSize (Only if version >= 11)

Game description data

TypeSizeDescription
String listImprovementDataSize bytesImprovements (e.g. IMPROVEMENT_FARM)
String listUnitTypeDataSize bytesUnit types (e.g. UNIT_SETTLER)
String listTechTypeDataSize bytesTech types (e.g. TECH_AGRICULTURE)
String listPolicyTypeDataSize bytesPolicy types (e.g. POLICY_LIBERTY)
String listBuildingTypeDataSize bytesBuilding types (e.g. BUILDING_STADIUM)
String listPromotionTypeDataSize bytesPromotion types (e.g. PROMOTION_DRILL_1)
Unit data arrayUnitDataSize bytesUnit data
Unit name arrayUnitNameDataSize bytesUnit names
City arrayCityDataSize bytesCity information
String listVictoryDataSize bytesVictory types (e.g. VICTORY_CULTURAL)
String listGameOptionDataSize bytesGame options (e.g. GAMEOPTION_NO_CITY_RAZING)

Unit data format

In version 11, the sizeof this struct is 48 bytes.

In version 12, the sizeof this struct is 84 bytes.

TypeSizeDescription
byte[2]2 bytesUnknown
uint162 bytesIndex to custom unit name data
uint324 bytesExperience
uint324 bytesHealth (100% health is 100000)
uint8 (version 11) or uint32 (version 12)1 byte for version 11, 4 bytes for version 12Unit type
uint81 byteOwner
uint81 byteFacing direction
uint81 byteStatus (The low 3 bits are used. 4 (>>2) is garrisoned, 2 (>>1) is embarked, 1 (>>0) is fortified)
byte1 byteUnknown (Only for version 12)
byte[]32 bytes for version 11, 64 bytes for version 12Promotion data

City format

In version 11, the sizeof this struct is 104 bytes.

In version 12, the sizeof this struct is 136 bytes.

TypeSizeDescription
byte[64]64 bytesCity name
uint81 byteOwner
uint81 byteSettings
uint162 bytesPopulation
uint324 bytesHealth (100% health is 100000)
byte[]32 bytes for version 11, 64 bytes for version 12Building data

Unknown block

There is a section between the city data and team data that doesn't seem to be used anywhere, except for padding. The sizeof this block is unknown, but this block size increases as the number of civs increases.

TypeSizeDescription
byte[]Unknown bytesThis block doesn't seem to correspond to anything in the game

Team format

The sizeof this struct is 64 bytes. The team name is usually the default value, e.g. Team 1.

TypeSizeDescription
byte[64]64 bytesTeam name

Player format

The sizeof this struct is 436 bytes.

TypeSizeDescription
byte[32]32 bytesPolicies
byte[64]64 bytesLeader name (override leader name)
byte[64]64 bytesCiv name (override civ name)
byte[64]64 bytesCiv type (default civ name)
byte[64]64 bytesTeam color
byte[64]64 bytesEra
byte[64]64 bytesHandicap
uint324 bytesCulture
uint324 bytesGold
uint324 bytesStart position X
uint324 bytesStart position Y
uint81 byteTeam
uint81 bytePlayable
byte[2]2 bytesUnknown

Map tile improvement properties

This block is always placed at the end of a file.

TypeSizeDescription
MapTileImprovement[Height][Width](Height * Width * 8) bytes2D array of map tile improvements

Map tile improvement data

The size of this struct is 8 bytes.

TypeSizeDescription
uint162 bytesCity id (0xFFFF if none)
uint162 bytesUnit id (0xFFFF if none)
uint81 byteOwner
uint81 byteImprovement
uint81 byteRouteType (0 = road, 1 = railroad, 0xFF = none)
uint81 byteRouteOwner