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

Reading Civ5Replay files (update: HTML export!)

Discussion in 'Civ5 - Strategy & Tips' started by dannythefool, Oct 4, 2010.

  1. dannythefool

    dannythefool King

    Jul 15, 2009
    EDIT: Update 5 from October 25. Improves compatibility with map files and replays that start on a later turn than 0. Added an "alpha" button that switches between three levels of transparency for the borders.

    There's now a public web service provided by flexd. If you don't want to go through all the steps below, head over to http://civ5.flexd.net/ and give it a try. Note that background maps aren't supported yet. Get the details from this post.

    Old screenshot from update 2:

    Script features with changes from this update in bold:

    • See the leader and civ names, the difficulty level, map size and type, advanced game options, enabled victory types (only shown if at least one was disabled), and how the game ended. Please let me know if bad data is displayed for any of these.
    • Scrollable list of events as recorded by the game with turn count and text.
    • Use map data from a Civ5Map file as background. Rivers are now displayed, too. You can create files in this format from within the game. Load a save game from which you want to visualize the replay, then open the save dialog again. At the bottom, slightly to the left, there is a "Save as Map" button. Unfortunately, replay files don't seem to contain map data, so for now, this is the only way.
    • Animated map of tiles changing ownership, including city locations. Now you can pick how transparent the territory borders are rendered. Cities have name tags. Contiguous regions of empires are now rendered as such, and their inside is rendered slightly transparently if a map backdrop is being used.
    • Manually step through the history of your empire.
    • Score histogram, see how the players' scores developed during the game.
    • The script guesses the civ based on the first city each civ founds and uses the same colours as the game if possible (only works with English and French replays - unrecognized civs are still black&white unfortunately).
    • The display width of the HTML can be set on the command line.

    • BotYann has provided a French translation and replay files. Thanks! See instructions below on how to run the script in French mode. If it doesn't work, it's 100% my fault!
    • Collin G. has provided some HTML enhancements and replay files. Thanks!
    • player1 fanatic suggested a usability change, thanks!
    • blind biker suggested a usability change, thanks!

    The examples have been updated too and they all have rivers now. You will need Safari, Chrome or Firefox, and I'm told that Opera also works; IE doesn't work yet since it doesn't support the HTML5 canvas element and probably one or two other things I'm doing:
    Scroll down for instructions on how to get and run the script that generates these.

    Fat Disclaimer!

    This is still based on a lot of guesswork, and I really think the replay files are half broken like other parts of the game after looking at them, but I get satisfactory results from all 14 replay files that I have. If you have a replay file that doesn't work, please send it to me! My e-mail address is in the script.

    The same goes for localized replays. My native language isn't English, but I play Civ V in English so I only have English replays. To make this script work with localized replays, I need examples to experiment with! Several guesses the script makes depend on the localized event descriptions.

    • All the textual descriptions are created by the game. They have lots of errors, like the leader name being used in place of the civ name, civ name missing after liberating a civ, research pacts showing as TXT_KEY_MISC_PLAYERS_SIGN_RESEARCH_AGREEMENT instead of real English, random punctuation and so on. I can't really fix those, you'll have to live with them.
    • There appears to be no good way to distinguish between a tile losing ownership because a city was razed, and a tile reverting to a city state because a city state was liberated. The script makes several guesses based on what contiguous region a reverting tile belongs to, what it belonged to previously, advanced game options, and so on, in order to be able to make razed cities disappear while keeping captured ones on the map. If you have a replay file where this produces the wrong outcome, please send it to me, my address is in the script.
    • The script is not really user friendly right now. If nobody beats me to it I may or may not make this into a web service at some point.
    • The javascript code is not completely optimized yet.
    • HTML files can turn out quite large.

    I'm sorry that this isn't very user friendly yet. If you want, you can follow these steps to run the script on your own system:
    • Get my replay export script here: http://discordia.erinye.com/civ5replay/civ5replay.py
    • If you don't have python, download version 2.x (not 3!) here, then install it: http://python.org/
    • Replay files for your completed games are in your user directory, inside "Documents\My Games\Sid Meier's Civilization 5\Replays"
    • Copy the replay file you want to view to the same place where you put civ5replay.py (or remember the full path)
    • Optional: If you want the terrain to show, you need to export a map using Civilization V. Load a save from any turn from the game you want to replay, then open the save dialog again. Click the "Save as Map" button and pick a name you can remember. Maps end up in the "Maps" directory in the same location where the "Replays" directory is located. Copy the map file to the same place where you put the script if you want.
    • Open CMD, and type "cd " plus the path where you put civ5replay.py, e.g. your downloads folder
    • Type "python civ5replay.py -H replay.html " plus the name of the replay file (or full path if you didn't copy it here)
    • Optional: If you have a Civ5Map file matching the replay, you can add " -m " plus the path to the map file (if you copied it to the same location where the script is, this is just the file name) and the script will include the map as a backdrop.
    • Optional: If your replay file is in French, add " -l fr" to the command line. I don't know if this is working, I don't have any French replays! If it isn't working, by all means please send me a replay file I can test this on :)
    • Optional: You can set the width of the canvas element if you want. Add " -w 1600" to make it 1600 pixels wide, etc.
    • If all is well, the script will spam you with a list of events as recorded in the replay while it is processing them, it'll eventually finish and write an html file
    • If an error happens, please let me know. There's a lot of guesswork involved in this and I'm pretty sure that it won't work for every replay yet, that would just be too strange...
    • Open the resulting replay.html file in Safari, Chrome or Firefox
  2. alcaras

    alcaras Warlord

    Dec 27, 2005
    Awesome find!

    I sorely miss the post-game replay from Civ4, so it's nice to know that it'll be possible to recreate it.

    e: This looks awesome! Thank you.
  3. jpinard

    jpinard Martian

    Jan 18, 2002
    Enceladus, Saturn
    They should hire you to put this in if they can't be bothered to finish it themselves. This is one of the most disappointing things about the current game. Being unceremoniously dumped to a crappy end-screen. My last game it didn't even tell me why I'd won.
  4. dannythefool

    dannythefool King

    Jul 15, 2009
    Yeah, I was missing the replay too...

    But there definitely is some hope. I have a basic HTML canvas based animation of the tiles flipping culture working now, still need to look at the map itself though. The replay files just look like they didn't manage to finish the feature, with all the errors in the text, and I'm not sure yet how I'm supposed to distinguish a razed city from one that was captured by a city state...

    Btw., the replay includes when you load a game so think twice before you reload :p

    I'll upload a new version of the script once the HTML export is useful enough.
  5. Dariush

    Dariush Chieftain

    Sep 17, 2010
    The finish was the most dissapointing finish I've ever seen. I enjoied the ending of Ice Climber on NES more...:mad:
  6. gunter

    gunter King

    Oct 16, 2002
    It's a shame that forumers had to find by themselves the way to open replay files and as shown that's not an immediate task. BTW my compliments Danny.

    If the first real patch won't allow to easily read replays we are pretty much obliged to camp within Firaxis building and dressed like Brute attack John Shafer :)
  7. dannythefool

    dannythefool King

    Jul 15, 2009
    So the bad news is that the actual map data (ocean, land, and so on) is nowhere to be found in the replay file. Showing land and ocean will have to wait until I can look at the save game format.

    The good news is that the blob of data I hadn't examined before contains data for histograms! Four different ones, apparently. I'm not sure what they are, but I'm reasonably certain that one of them is the score of each civ, so I can now draw a histogram for that.

    I've updated the initial post in this thread with some examples of the HTML export and instructions on where to get the new version of my script.
  8. pim42

    pim42 Chieftain

    Oct 5, 2010
    I'm a lurker who registered just so I could tell you this is awesome. I look forward to seeing where this goes.

    I have (limited) experience programming with Python and using it to generate graphs. Maybe I can help you some. First though, I'll run your tool against my replays and let you know how it goes.
  9. Ayt

    Ayt Warlord

    Nov 15, 2005
    It is sad you had to make this but I'm very glad that you did.
  10. CaptainBinky

    CaptainBinky Warlord

    May 12, 2010
    Wooo! Nice one, works great! :D
  11. Boojumhunter

    Boojumhunter Chieftain

    Mar 6, 2002
    Brampton, Ont
    +10 Internet points for you. Amazing.
  12. Peptis

    Peptis Chieftain

    Sep 20, 2010
    I just wanted to let you know that it works in Opera as well. And thanks, nice work on the replay.
  13. kaltorak

    kaltorak Emperor

    Jul 7, 2009
    wow, this rocks, gj!
  14. lemmy101

    lemmy101 Emperor

    Apr 10, 2006
  15. gunter

    gunter King

    Oct 16, 2002
    Any official comments on that ?

    I am sure that Danny / everybody deserve an official opinion on what will be done on the next patch
  16. -Rodri-

    -Rodri- Chieftain

    Aug 8, 2006
    Excelent work. Congrats. Firaxis should be ashamed.
  17. Magikthighs

    Magikthighs Chieftain

    Oct 6, 2010
    I can't believe this was omitted from the release!

    Nice work on trying to get this sorted :goodjob:
  18. dtolman

    dtolman Chieftain

    Jul 3, 2002
    With this in, I now believe I am playing Civ, and not some generic strategy game!

    Thank you!

    2KGames should be ashamed that this simple but important features was not in the game to begin with!
  19. Mahi

    Mahi Prince

    Apr 24, 2010
    Props to you man! Deepest respect from here :goodjob:

    This should be made a sticky IMO. Did the second best thing. Made a link in my signature if you don't mind.
  20. gunter

    gunter King

    Oct 16, 2002
    Yes, this thread must be stickied, polls should suface every day claiming for replays to be back, otherwise we'll riot !

Share This Page