1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

The Civilization III Save Format

Discussion in 'Civ3 - Tutorials, Reference, & Guides' started by Sirp, Mar 21, 2003.

  1. Sirp

    Sirp Emperor

    Joined:
    Nov 19, 2001
    Messages:
    1,746
    Location:
    Texas
    I'm not sure if this is the appropriate forum to post this in, but I figure it is the most appropriate.

    I haven't seen any concise documentation on the save format in Civilization III. I've done a briefish investigation myself, and I post the results of what I've found. I hope that others will also post anything they know below too. The information is as at Play the World 1.14f

    ---

    The autosaves are uncompressed, but normal saves are compressed by default. You have to decompress saves to get them in the correct format. I'm not sure how they're compressed though. It's probably something standard like ZLib.

    Numbers in the file are generally stored as 4-byte integers, with the lowest value byte coming first. UINT_MAX (i.e. 0xFFFFFFFF) is generally used to represent 'null' values.

    The save file is a database which contains a series of records. There are different types of records. Each record begins with the name of its record type. This is followed by a 4-byte integer which is the length of the record's data (does not include the name or this integer itself).

    The records generally either describe the rules the game is played under - the improvements that can be built, units that can be built, how much they cost etc etc: everything that can be set in the editor - I call these 'rules records', and actual game state data - the map, where units are located on the map, where cities are, etc etc. I call these 'game data records'.

    Since almost everything in the rules can be edited in the editor, the game data records are what I'm most interested in.

    The following are the known records in the game:

    BLDGN - rules - the state of buildings
    CNSL
    CONT
    CTZN
    CULT - rules - culture
    DIFF - rules - difficulty settings
    ERAS
    EXPR
    FAXXT
    GAME
    GOOD
    GOVT - rules - government types
    HIST - histogram (?)
    ICBM
    LEAD - gamedata - general information about a civilization
    PALV
    PEER
    RACE - rules - the races available to play
    RPLS
    RPLT
    RULE
    TECHR - rules - the technologies available
    TERR - rules - terrain
    TFRM
    TILE - gamedata - a single tile on the map
    UNIT - gamedata - a single unit
    WRLD
    WSIZ - world size (?)

    I have found a little about the formats of some of the more interesting records, as follows:

    LEAD section:

    This section documents information about each civilization. The first LEAD section in the file is for barbarians, and the second one is for the player's civilization. Further ones after that are for each AI civilization.

    I guess that "LEAD" stands for "leader", but I'm not sure. The known format is as follows:

    bytes 0-3: id of the civilization. i.e. if '0' this means the civilization uses the first RACE record, if '1' it uses the second RACE record and so forth.
    bytes 12-15: the capital city. UINT_MAX means none. It seems however that a palace may also need to be in the city for it to count as the capital.
    bytes 36-43: two integers which seem to be encrypted values determining how much gold the civilization has. It seems that changing these numbers so that they sum to the same amount will not affect one's gold balance.
    bytes 216-219: beakers put into researching the current technology
    bytes 220-223: technology being researched. (UINT_MAX means none). I'm guessing the index into TECHR of what is currently being researched.
    bytes 388-391: luxury rate (0-10)
    bytes 392-395: science rate (0-10)
    bytes 3740-?: a series of 4 byte values, each of which can assume only the values 0 or 1. Each one corresponds to another civilization, and determines if contact has been established yet. Note though that whether the 'D' for diplomacy button is available is determined elsewhere, so changing this when one has contact with no-one will still not allow entry into diplomacy.

    CITY section: this section stories information about a city. The records seem to be in a varying format depending on how long they are. In particular, a 148 byte city field seems to also store the city name and be in a slightly different format to what's listed here, although I'm not sure why the city name isn't already stored. The following is known:

    0-3: the co-ordinates of the city, as two short integers (two bytes each). Changing these is not sufficient to change the location of the city.
    4-7: the LEAD-index of the owner of the city (changing this alone will not be sufficient to change ownership of the city however).
    12-15: whether the city name should be displayed with dropshadows.
    28-31: food stored
    32-35: shields stored
    40-47: ID of what is currently being built. First integer is the id of the item being built, second integer is the type: 1 - building, 2 - unit
    56-59: The cultural influence of the city, but changing doesn't seem to influence anything.

    UNIT section:

    0-3: The unit ID. It appears that each unit gets a unique id across the entire game.
    4-7: x-co-ordinate
    8-11: y-co-ordinate. Note that co-ordinates are in half tiles. To move a unit to the right one space, add 2 to its x-co. To move it to the up-right one space, add 1 to its x-co and 1 to its y-co. Otherwise it'll end up (!!) between tiles.
    12-15: x-co-ordinate that the unit was on last turn. (why this needs to be recorded is unknown)
    16-19: y-co-ordinate that the unit was on last turn.
    20-23: the id of the civilization that the unit belongs to. This is the index into LEAD of the owner
    24-27: the nationality of the unit. This is the civilization id - so an index into RACE, not an index into LEAD.
    28-31: unknown
    32-35: the type of unit. I.e. whether a worker, warrior, archer etc.
    36-39: the rank of the unit. 0 = conscript, 1 = regular, etc.
    40-43: unknown
    44-47: the number of hits of damage the unit has taken. i.e. 0 = undamaged.
    48-51: the number of thirds of point of movement the unit has moved this turn
    52-55: unknown
    56-59: (for workers) the type of action the worker is performing. UINT_MAX = none. 0 = mine. 1 = irrigate. 2 = build fort
    60-63: unknown
    64-67: unknown
    68-71: whether the unit is fortified. (or in other states perhaps?)

    TILE section: I'm still investigating this section. The records seem to be highly variant in size, and are really confusing me....

    If anyone else wants to post what they know about the save format, please go ahead!

    -Sirp.
     
  2. pdescobar

    pdescobar Moo, baby. Moo.

    Joined:
    Nov 30, 2002
    Messages:
    1,364
    Location:
    CFC or playing DyP
    This forum is for actual utility programs. I would guess the Tutorial/Reference forum is probably the best place for this, but I'm not really sure; when in doubt, it can go to the main C&C. Anyhow, take a look at the following Apolyton post which outlines the BIC format as of vanilla 1.29f; the save and BIC formats should be quite similar since both contain the rules in-use and the BIC can hold a custom map, cities, units, etc:
    http://apolyton.net/forums/showthread.php?s=&threadid=48062
     
  3. MarkC1

    MarkC1 Warlord

    Joined:
    Nov 22, 2002
    Messages:
    242
    Location:
    Texas
    Great Info Sirp :goodjob:
     
  4. MarkC1

    MarkC1 Warlord

    Joined:
    Nov 22, 2002
    Messages:
    242
    Location:
    Texas
    "32-35: the type of unit. I.e. whether a worker, warrior, archer etc."
    I don't think this is the right position or maybe i am using a different version

    also do you have any clues as to the values for the units?
     
  5. MarkC1

    MarkC1 Warlord

    Joined:
    Nov 22, 2002
    Messages:
    242
    Location:
    Texas
    Great Info Sirp :goodjob:
     
  6. MarkC1

    MarkC1 Warlord

    Joined:
    Nov 22, 2002
    Messages:
    242
    Location:
    Texas
    I got this data for some of the units

    Settler = 0
    Worker = 1
    Scout = 2
    Explorer = 3
    Marine = 4
    Parachute = 5
    Warrior = 6
    Horseman = 11
    IV = 18
    Tank = 19
    MechIV = 20
    MA = 21
     
  7. Adrain

    Adrain Chieftain

    Joined:
    May 3, 2004
    Messages:
    80
    Gender:
    Male
    Location:
    UK
    Gr8 work Sirp.
    Thx for the info I used in the table below - I hope I've added something helpful.
    I'm interested in anything you have on TILEs.

    MarkC1,
    If you haven't found out through other means, the code items (where a number refers to an item from a list) refer to lists which are mostly found in the rules section.
    This can be found by editing 'Civ3Mod.Bic' using the 'Civ3Edit.Exe' program. Select Rules\Edit Rules... from the menus and choose the tab you need. The number refers to the position the item is found in the list (0 based) so beware - the first item is referred to as 0.
    EG. The 'UNIT' Settler is referred to as 0; The 'TFRM' (Terra-Form or worker job) Mine is referred to as 0.

    Hope this helps.

    The following table is based on data provided originally by Sirp and added to by others (Thx).
    It's maybe laid out differently (and in Hex) but I hope it's readable.
    It is tabulated so may look better in non-proportional font (EG Courier New).
    I use vanilla Civ3 v1.29f - No PTW or Conquests.
    Code:
    Actual Units (UNIT)
    strSearch:         UNIT{A1}{01}{00}{00} - Length including this = 01A9 (425)
    lngID              0000:    Individual Unit ID
    lngX:              0004:    X Position (sum of X & Y must be even)
    lngY:              0008:    Y Position (sum of X & Y must be even)
    lngPrevX:          000C:    Previous X Position
    lngPrevY:          0010:    Previous Y Position
    lngLeader:         0014:    00=Barbarian; 01=Player (See LEAD - Leader table)
    lngNationality:    0018:    (See RACE table)
    lng:               001C:    Unknown
    lngUnitCode:       0020:    (See PRTO table)
    lngRank:           0024:    (See EXPR - Experience table)
    bln:               0028:    0010 0000 (20) = Leader created
    lngHits:           002C:    Hits taken
    lngMovement:       0030:    Movement points x 3
    lngJobTurns:       0034:    2 per turn if native - only 1 if foreign
    lngWorkerJob:      0038:    (See TFRM - Terra-Form table)
    lng:               003C:    Unknown
    lng:               0040:    Unknown
    lngState:          0044:    Fortified?
    -Adrain.
     
    Last edited: Jul 19, 2019
  8. Adrain

    Adrain Chieftain

    Joined:
    May 3, 2004
    Messages:
    80
    Gender:
    Male
    Location:
    UK
    The following tables are based on data provided originally by Sirp and added to by others (Thx).
    It's maybe laid out differently (and in Hex) but I hope it's readable.
    It is tabulated so may look better reformatted in non-proportional font (EG Courier New).
    I use vanilla Civ3 v1.29f - No PTW or Conquests.
    Beware, some of the data is unknown so not all fields follow on directly from the previous ones.
    Some of this info is overwritten by the prog on load so is essentially R/O.
    Also, the CITY data layout gets a bit messy as there are a number of CITY entries - each of a different length - which seem to follow on from each other for the same city.
    Code:
    Actual Cities (CITY) type A
    strSearch(08):    CITY{88}{00}{00}{00} - Length including this = 0090 (144)
    lngID             0000:    Individual City ID
    intX:             0004:    X Position (sum of X & Y must be even)
    intY:             0006:    Y Position (sum of X & Y must be even)
    chrLeader:        0008:    00=Barbarian; 01=Player (See LEAD - Leader table)
    lngMaint:         000C:    Maintenance cost per go
    lngFood:          0020:    Food stored
    lngShields:       0024:    Shields accumulated
    lngBuild:         002C:    See table given below (lngBuildType)
    lngBuildType:     0030:    01=BLDG table; 02=PRTO table (see lngBuild)
    lngInfluence:     003C:    Cultural influence range
    lngContent:       0040:    Causes of Contentment (Content Faces)
    lngHappy:         0044:    Causes of Happiness (Happy Faces)
    Code:
    Actual Cities (CITY) type B
    strSearch(08):    CITY{10}{00}{00}{00} - Length including this = 0018 (24)
    Code:
    Actual Cities (CITY) type C
    strSearch(08):    CITY{24}{00}{00}{00} - Length including this = 002C (44)
    Code:
    Actual Cities (CITY) type D
    strSearch(08):    CITY{9C}{00}{00}{00} - Length including this = 00A4 (164)
    Code:
    Actual Cities (CITY) type E
    strSearch(08):    CITY{94}{00}{00}{00} - Length including this = 009C (156)
    strName(10):      0000:    Name of city
    Code:
    City Population (POPD)
    strSearch(08):    POPD{08}{00}{00}{00} - Length including this = 0010 (16)
    lngSpec:          0000:    No of Specialists
    lngPop:           0004:    Total no of Citizens
    and for each citizen:
    Code:
    Citizen (CTZN)
    strSearch(08):    CTZN{2C}{01}{00}{00} - Length including this = 0134 (308)
    strDesc(??):      0002:    Description (modified by happiness in game)
    lngLeader:        0120:    Nationality 00=Barbarian; 01=Player (See LEAD - Leader table)
    lngOwner:         0124:    Owner Nationality (As lngLeader if foreign otherwise FFFFFFFF)
    lngRef:           0128:    Some reference which is zero if the citizen is a member of the owner civ.
    I don't know what it refers to as yet.
    NB. I haven't tested the safety of changing all these values.

    -Adrain.
     
    Last edited: Jul 19, 2019
  9. Rufus T. Firefly

    Rufus T. Firefly Rufus is coming in town!

    Joined:
    Jun 17, 2003
    Messages:
    1,905
    Location:
    Freedonian North pole base
    Oh, only a wrong post :(
     
  10. Adrain

    Adrain Chieftain

    Joined:
    May 3, 2004
    Messages:
    80
    Gender:
    Male
    Location:
    UK

    Just to add
    lng???: 0128: Some reference which is zero if the citizen is a member of the owner civ.
    I don't know what it refers to as yet.

    -Adrain.

    PS. Previous post updated now (it didn't allow me to edit the earlier one 'till after I'd added this)
     
  11. Adrain

    Adrain Chieftain

    Joined:
    May 3, 2004
    Messages:
    80
    Gender:
    Male
    Location:
    UK
    TILE section:
    Tiles are listed in Left-to-Right WITHIN Top-to-Bottom order.
    IE.
    0,0 0,2 0,4 ... 1,1 1,3 1,5 ... 2,0 2,2 2,4 ... until last tile of map.

    Actual Tiles (TILE) type A
    strSearch(08): TILE{1C}{00}{00}{00} - Length including this = 0024 (36)
    chrImps: 0010: Improvement flags: bit0=Road, bit1=Rail, bit2=Mine, bit3=Irrigation, bit4=Fortress, bit5=Goody hut, bit6=Pollution & bit7=Barbarian encampment.
    or
    0000 0001 = Road
    0000 0010 = Rail
    etc.
    intCity: 0016: Id of City or {FF}{FF} if none

    Actual Tiles (TILE) type B
    strSearch(08): TILE{7C}{00}{00}{00} - Length including this = 0084 (132)
    lngVisibileTo: 0000: Bits indicating which civs can see tile. bit0 (val=1) indicates barbarians; other bits in order of turns (where AI civs come after any human players so single player is bit1 (val=2)).
    lngVisibleNow: 0004: This says which civs can see it now (brighter on map).
    intCity: 0014: Id of City or {FF}{FF} if none

    I don't know why the City ID appears twice but I suspect that one of them refers to the tile the city is actually on and the other refers to all the tiles the city can work.
     
  12. wotan321

    wotan321 Emperor

    Joined:
    Oct 25, 2001
    Messages:
    1,220
    Location:
    NC, USA
    Any info on where "locked alliances" and "Locked war" info is kept in the .sav file?

    Thanks.
     
  13. Adrain

    Adrain Chieftain

    Joined:
    May 3, 2004
    Messages:
    80
    Gender:
    Male
    Location:
    UK
    I don't think I have anything on either of those.
    I'm not sure I've even come across the concepts.
    What are they?
     
  14. Dianthus

    Dianthus Small but hardy

    Joined:
    Mar 26, 2003
    Messages:
    5,814
    Location:
    Woking, UK
    They are new to [c3c]. They allow a scenario designed to force a player to have an unbreakable alliance with another player, or an never ending war with another player.
     
  15. wotan321

    wotan321 Emperor

    Joined:
    Oct 25, 2001
    Messages:
    1,220
    Location:
    NC, USA
    I have seen over at Apolyton boards the listing of the .bix/.biq files format, and there is a section where the individual civs have recorded which of the 1-4 alliance groups they belong to, and to which other groups they are in locked war with. But its not that simple either.

    I have noticed that Firaxis creates a "locked" alliance or war by simply giving the MPP or war a duration of thousands of turns, as opposed to the usual MPP or war term of 20 turns. But where in the .sav game is that info? Is there more to it than that?
     
  16. weezer

    weezer Chieftain

    Joined:
    Apr 21, 2003
    Messages:
    22
    What compression was used in the game file?

    EDIT: I managed to decompress it. Where can I find the Game info data(difficulty, version, hours played, turns, data, if already won.. etc..)?
     
  17. Adrain

    Adrain Chieftain

    Joined:
    May 3, 2004
    Messages:
    80
    Gender:
    Male
    Location:
    UK
    If you go through this thread you will find everything that has been posted so far about the save game file specifically.

    The link pdescobar posted above (http://apolyton.net/forums/showthread.php?s=&threadid=48062) is a veritable mine of info about the configuration file, much of which is incorporated into the save game file.
    Incidentally, I think it also details compression info but it's really very big so you may need to search a while. If not there, then it is certainly somewhere linkable from there and posted by Gramphos.

    Not all questions are answered but many are - so happy hunting.
     
  18. jimmywfl

    jimmywfl Chieftain

    Joined:
    Oct 10, 2009
    Messages:
    47
    Location:
    Vienna, Austria
    This link is no longer working
     
  19. Quintillus

    Quintillus Archiving Civ3 Content Supporter

    Joined:
    Mar 17, 2007
    Messages:
    6,354
    Location:
    Columbus
    It isn't, due to breaking when Apolyton upgraded from vBulletin 2 to vBulletin 5 several years ago. However, this link (https://apolyton.net/forum/civiliza...i/122361-civilization-iii-bix-biq-file-format) is the new link to the same thread. I should also note that while it looks like the section links in that thread should work (and they did back in the day), they no longer do. But you can still scroll and search by section name.

    I highly recommend that thread for info on the Civ3 scenario format; it has been my top reference while writing a Civ3 editor. I'd estimate 98% of my scenario format info came from that thread, 1% from various other sources or corrections, and 1% from original research.
     
  20. jimmywfl

    jimmywfl Chieftain

    Joined:
    Oct 10, 2009
    Messages:
    47
    Location:
    Vienna, Austria
    Thanks. What is the difference between the creation files format and the .sav format?
     

Share This Page