Civilization II Saved Game Loader for GIMP

To learn more about GIMP internals and GTK application programming I converted a simple PPM application I wrote to be a GIMP plugin. The plugin is capable of loading saved games generated by Civilization II from Microprose and the maps generated by its map editor.

I've updated the source to work with versions of GIMP from this century. Last tested with gimp-2.4 (which is pretty impressive considering it was written in 1997 for gimp 1.x or earlier!) Download the source now!

Status

This is the 0.8 release. Since this was more of a learning experience than a practical application, I probably won't do any furthur development. I will gladly incorporate fixes and enhancements made by users who are still fanatical enough about Civ2 to want a fully functional plugin. If you want to take over maintenance of this plugin please contact me with some evidence that you will actually enhance the program (i.e. diffs to implement some features!).

If Ultimate Civ2 ever comes out it will add multiplayer support to Civ2, at which point I might actually want to finish this program. That is if I'm not too busy playing Age of Empires.

The latest version will always be at http://www.ben.com/GIMP/CIV2/ as civ2.tar.gz.

Operation

When installed the plugin makes itself the default loader for files ending in .SAV. If you select a saved game you will get the CIV2 plugin automatically. If you want to load a map (which usually uses the .MP extension) you'll have to select the CIV2 filetype by hand. After loading the game or map, the plugin will present you with some options:

The grayed checkboxes are not optional because the code doesn't exist to implement them, but it was more interesting to learn how to desensitize GTK widgets than to just remove the checkboxes.

The imagemaps must be the GIFs that come with CIV2 or compatible imagemaps (from official or unofficial mod paks). The original GIF imagemaps contain special information encoded in the palette so it is not possible to use arbitrary images. The plugin also assumes that the union of all the image palettes is small enough to generate an indexed image as output. If you don't have them try getting a mod pack from a CIV2 site. I won't ship them with the plugin: I don't want the legal hassle. The code will try to find these images in some common locations using a simple search path, including looking at /cdrom and /cd for the game CDROM.

After loading the four imagemaps and rendering the selected components, you'll be presented with an immense image (frequently 3000x1000 or larger) with several layers:

The texture images are closed when the rendering is complete. If the plugin crashes for some reason (e.g. a corrupted save file) you may be left with those images loaded. The GIMP does not provide a way for you to create views of these images but you can access them from the layers menu.

The resulting image can be flattened and saved as a GIF with no additional manipulation. Here's a detail from one saved game, showing some French and American cities and their supporting units (the unit shields are all red because there's no code to change the color as the shield is copied, see below):

Shortcomings

The rendering engine doesn't use the "dither" tile at all to merge adjacent tiles, so they are blockier than they are in the game. It's not clear how to use this tile to get the same results as the game.

The saved game loader just reads large arrays of carefully constructed structures with bitfields to describe object attributes. This has several problems: the loader is probably byte-order dependant, the structure layout may be compiler (gcc) dependant, and it is probably not the method used by the civ2 game programmers (so it's difficult to see patterns in the layout of the datastructures).

The following information isn't extracted from a saved game file or the algorithm for synthesizing the information is unknown:

General TODO

There are a few things I have left undone. I intended to get to these before releasing but if I waited you'd never see this:

Enhancements

Of course it would be nice to fix all the flaws, but it would also be fun to create some new features that don't exist in the game:
Ben Jackson ben@ben.com