Categorygithub.com/samuelyuan/Civ5MapImage
repositorypackage
0.0.0-20241007050250-983c103b3b39
Repository: https://github.com/samuelyuan/civ5mapimage.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

Civ5MapImage

Table of Contents

Introduction

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. This program will convert a Civ 5 map with the file extension .Civ5Map to a PNG image.

Command-Line Usage

The input filename can either be a .civ5map or .json file. To start using this application, you can use any of the map files in the maps/ folder or you can load a .civ5map in your game directory.

If you generated the map image and want to modify the map, you can export the .civ5map as a .json by providing an output filename with the file extension .json and reuse the exported json as the input filename.

./Civ5MapImage.exe -input=[input filename] -mode=[drawing mode (optional)] -output=[output filename (default is output.png)]

Generate Physical Map Image

The default map mode is physical, which shows the different types of terrain.

./Civ5MapImage.exe -input=earth.Civ5Map -output=earth.png
earth

Generate Political Map Image

To generate a political map with the civilization and city state borders, you must pass in -mode=political to specify the drawing mode.

./Civ5MapImage.exe -input=maps/europe1939.json -mode=political -output=europe1939.png
europe

Generate Replay

To generate a replay, you will need to provide the base map and the replay file of a game.

./Civ5MapImage.exe -mode=replay -input=[map filename] -replay=[replay filename]  -output=[gif filename]

Convert .civ5map to .json

Set -mode=exportjson and output to have a filename ending in .json. No image will be generated.

./Civ5MapImage.exe -mode=exportjson -input=earth.Civ5Map -output=earth.json

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

Map 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

Replay File Format

The replay files store a list of civilizations, events, and datasets for different statistics like gold per turn.

TypeSizeDescription
byte[4]4 bytesGame name
uint324 bytesunknownBlock1
varstringvar bytesGame version
varstringvar bytesGame build
uint324 bytesCurrent turn number
byte[1]1 bytesunknownBlock2
varstringvar bytesPlayer civ
varstringvar bytesDifficulty
varstringvar bytesEra start
varstringvar bytesEra end
varstringvar bytesGame speed
varstringvar bytesWorld size
varstringvar bytesMap filename

DLC Array Element

Array size is uint32 followed by list of elements.

TypeSizeDescription
byte[16]16 bytesdlcId
byte[4]4 bytesdlcEnabled
varstringvar bytesdlcName

Mods Array Element

Array size is uint32 followed by list of elements.

TypeSizeDescription
varstringvar bytesmodId
byte[4]4 bytesmodVersion
varstringvar bytesmodName

Header Continued

TypeSizeDescription
varstringvar bytesCiv name
varstringvar bytesLeader name
varstringvar bytesPlayer color
byte[8]8 bytesunknownBlock5
varstringvar bytesmapFilename2

Unknown Block

TypeSizeDescription
uint324 bytesunknownVersion
byte[]7 bytes if unknownVersion is 2, 9 bytes for all other valuesUnknown array
uint324 bytesunknownCount
uint32[](unknownCount + 1) bytesUnknown array
uint81 byteUnknown

Header Continued

TypeSizeDescription
uint324 bytesStart turn
int324 bytesStart year
uint324 bytesEnd turn
varstringvar bytesEnd year
uint324 byteszeroStartYear
uint324 byteszeroEndYear

Civ Names

The civ names are stored in an array.

Array size is uint32.

Array element format

TypeSizeDescription
uint32[4]4*4 bytesUnknown
varstringvar bytesLeader name
varstringvar bytesCiv long name
varstringvar bytesCiv name
varstringvar bytesCiv demonym

Civ Dataset Names

Array size is uint32.

Array element format

TypeSizeDescription
varstringvar bytesDataset name

Civ Dataset Values

This is a 3D array. The first level is divided by civilization and the second level is divided by category. To get a list of dataset values, you have to call datasetValues[civIndex][datasetNameIndex]. Each dataset value is represented by a Turn and Value pair.

Replay Events

The number of events is a uint32.

Replay Event format

TypeSizeDescription
uint324 bytesTurn
uint324 bytesType id
uint324 bytesNumber tiles
tile arraynumTIles * 4 bytesTile array, which contains uint16 for x and uint16 for y
uint324 bytesCivilization Id
varstringvarstring bytesEvent text

Tiles

Tile data contains information about the physical map.

TypeSizeDescription
uint324 bytesunknownVariable1
uint324 bytesunknownVariable2
uint81 byteElevation id
uint81 byteType id
uint81 byteFeature id
uint81 byteunknownVariable3

Save File Format

Most of the save file is compressed and the header begins with 0x789C, which is a ZLIB header.