CivWin Editing

nova10

Chieftain
Joined
May 16, 2003
Messages
43
Location
Canada
It appears that after all this time, it may soon become possible to edit any part of Civilization for Windows for beneficial uses. So far I have made slow progress in some areas but good progress in other areas. I'll start with the files for CivWin (ignoring the obvious):

civ.prf - This holds the window locations,width and height for the main civ screen, the map window and the status window. The second to last byte are the options you set under "File-Options". I'm not sure what the last byte does. This file does not need to be modified.

All 5 .rsc files - These hold pretty much all the text you see in the game. They also hold all the graphics seen in the game. It would appear that unit information (Attack Power, Defense Power, #Moves and cost) are not in these files. Most likely in the civ.exe file. I currently do not know how to view or even extract the graphics in these files at this time :crazyeye:

The .Sav File - Ah yes, the save file for CivWin. This file is the equiv of CivDos .map and .sve put together (Hope you all knew that one ;) ). This file is compressed. While uncompressing it is easy, re-compressing it has been quite a thorn in my side. This file is my current main priority (with getting the re-compression fully operational being on the top of the list). I have found where some stuff are located in the file, and the file still holds many undiscovered keys :scan:
 
It appears that after all this time, it may soon become possible to edit any part of Civilization for Windows for beneficial uses. So far I have made slow progress in some areas but good progress in other areas. I'll start with the files for CivWin (ignoring the obvious):

civ.prf - This holds the window locations,width and height for the main civ screen, the map window and the status window. The second to last byte are the options you set under "File-Options". I'm not sure what the last byte does. This file does not need to be modified.

All 5 .rsc files - These hold pretty much all the text you see in the game. They also hold all the graphics seen in the game. It would appear that unit information (Attack Power, Defense Power, #Moves and cost) are not in these files. Most likely in the civ.exe file. I currently do not know how to view or even extract the graphics in these files at this time :crazyeye:

The .Sav File - Ah yes, the save file for CivWin. This file is the equiv of CivDos .map and .sve put together (Hope you all knew that one ;) ). This file is compressed. While uncompressing it is easy, re-compressing it has been quite a thorn in my side. This file is my current main priority (with getting the re-compression fully operational being on the top of the list). I have found where some stuff are located in the file, and the file still holds many undiscovered keys :scan:

I have been able to decipher a some of the .sav file, and have been able to modify unit types. It is not 100%. It works early in the game, and becomes less reliable as more turns are played. Examples of what I can do. I can change a militia into a settler, or even a mech infantry or cruiser. It allows for very fast colonization and exploration of the world. By about 0 ad the editing of the units becomes unreliable.

What I really want to be able to do is modify the map. I am very interested in getting a copy of this program that unpacks the map.
 
I found a post by Honza.Havlicek where he posted the C++ code that decompressed and recompressed the Civwin .sav file. Much thanks to him I now have a prototype Map Editor for CivWin.

I can make all squares visible, and have hacked how to modify the terrain types and perform improvements including roads, mining, irrigation, railroads and fortresses.
 
I have been watching this forum for a long time looking for a way to edit the CivWin map. The answer to all who asked has always been, "Use the Dos version of CIV".

Now there is an editor. You can just cursor around the map and press keys to edit the terrain. You can create roads and railroads, irrigate and mine.

Here is a screen shot.


The program is written in VB.Net. I would be happy to provide the source code and/or exe to anyone who wants it.

The .ex extension is for "expanded". The .sav file must be decompressed for editing, and then recompressed on save.
 
This is a request to Dack for information if he is willing to share it.

Perusing through the thread on your Terraform program I see that you have discovered many rules about the squares, cities and units.

The windows version appears to have the same data per square as the dos version. I have found 16 + 1 bytes per square just as you found in the dos version.

I have identified the following information about the 16 bytes. I was hoping you could shed some more light on these. Especially the bytes that allow the computer player to build cities. I am close. I got a computer player to build one city, but he won't build a second. Maybe the island I built for him was too small. I will experiment some more.

First block of 4 bytes
Type of terrain
Who owns the square - also seems to double at start of game with whether a city can be built
Who is occupying the square - set by civ number plus a bit showing that a unit occupies the square
an unknown byte

Second block of 4 bytes
The continent number
The byte that shows whether a city can be built - as you stated it appears to be a bit + a number
unknown
unknown

Third block
The improvement if it is visible to the human player
The improvement state of the square - city, road, mined, irrigated
unknown
unknown

Fourth block
The advanced improvement - pollution, railroad, fortified. if visible to the human player
The advanced improvement
unknown
unknown

I have figured out a lot about the windows .sav file. Just a few more bits to figure out.

Any information you are willing to shared will be appreciated.

The list of what I have figured out is too much for one post. At this time I can do almost anything to the game. If I can figure out how to create land the computer will use I will be done. I might even tackle drawing a pretty map. I have figured out the special resources.
 
... Especially the bytes that allow the computer player to build cities. I am close. I got a computer player to build one city, but he won't build a second. Maybe the island I built for him was too small. I will experiment some more. ...
I’ll start off by quoting myself:
The games countries only build on plains, grassland or river squares. They do this by checking a value “City build value”. I have not come up with an exact matching value for every square, but something close. So as to not upset the configuration of a game that may be saved with only minor changes. TerraForm marks the squares that a user has changed and at the SAVE function it re-evaluates the value only for the squares that change. (Also for the 20 squares that are effected if this falls in the range of a city).

I have never been able to reproduce perfectly the value that CIV DOS stores in the “City build value”. There seems to be a four bit value, the high order bit is set if it is a plains, grassland or river square. The remaining three bits are assigned a value from zero to seven. In numerous attempts in weighting the value of the twenty squares that surround a square (the area of a city zone of control) I have never came up with an exact formula. I assume that games countries check this value to determine if they should build there. As stated TerraForm only changes the values of the squares that have there terrain changed or fall in the zone of control.
My experience is that the game becomes seriously disturbed if mountains, deserts, swamps and the other types of terrain squares are marked with a “City build value”. I had hoped to use the map.pic modification tool that someone had worked on to see if I could come up with a more exacting formula of how these values are derived.
 
Thanks for the reply and being willing to discuss this. I have figured out a lot, but still have questions. There are values in the .sav file that I don't undertand. I very much appreciate your help so I can avoid doing things to the map that cause problems down the road. My first attempts at moving units and cities caused major issues in CivWin. GP Faults, etc.

Based on your description above I have also tried to weight the surrounding squares and I came up with a formula that uses the potential food, trade and resources. It comes up with numbers similar to the initial values, but not the same. I built my formula from 1 to 7 instead of 0 to 7. I am going to adjust it to go from 0 to 7.

I didn't find it necessary to keep track of which squares are modified. Rather I look at the "city build value" byte and the byte that marks who "owns" the square. If they are both 0, then I mark the plains or grassland as buildable with my ranking. If the square is not plains or grassland and is marked as buildable and the two bytes are equal, then I assume that the square was modified and set both bytes to 0. I think this is equivalent to what you are doing by keeping track of the changed squares. I am not sure it is 100% safe, but it has worked so far. Keeping track of the changed squares is probably safer.

I created an entire world using my map editor. I set everything to ocean and started over. This way all the squares were marked with my formula instead of the default. The computer player actually did better than usual. By 1000 BC there were only 2 computer civs and they had 15 and 21 cities each. So I have made an option to rank all the squares using my formula instead of the default, and so far it looks like it makes a better, stronger, computer player. I don't know if my rankings had anything to do with it, or if my mixture of land types was exceptionally rich.

I am in the middle of testing another game where I used my formula to mark the city build values for all the squares and I have incredibly strong Mongols and Zulus early in the game. All the civilizations are building lots of cities. I didn't modify much terrain. Just split my continent off, and joined a few of the smaller ones together.

One of the things I really like about this is that I can view from time to time what the computer civs are doing. I always hated that I had to wait until I could build bombers to be able to spy on the computer players.

I have found in my third and fourth block I had the first two bytes reversed.

Altogether I have figured out 9 of the 16 bytes of data for each square. Have you figured out any of the other bytes? Do my descriptions match what you have found in the DOS file?

In the CivWin file the bytes are stored by column, then row. 320 bytes per row * 50 rows. Then another 320 bytes per row * 50 rows, repeated 4 times. The 4000 bytes for which squares are visible are stored by row, then column. 50 bytes per column * 80 rows. Is this the same as in the DOS version?
 
I created a 4 player game using a map of Europe that I found here. A mapOut.txt

I am starting as the Egyptians. I had to move a couple cities because I wasn't player number 1. Every city I move gets destroyed by Barbarians on the second turn. I can't figure out what I am doing wrong.

Edit - I found the problem. The city location is stored in two places.
 
Finding out cool things every day. Located the data that defines the unit types.

Today I made flying amphibious settlers who can move 3 squares at a time without regards to terrain type. They still found cities and build roads.

I am curious to see if I can make diplomats into some kind of commando unit.
 
I have started drawing using the actual graphics from the game and am at the "square" look. I have figured out drawing the rivers, roads and railroads.

I am looking at the images for the shoreline, and am having trouble understanding when to use what to draw the rounded shorelines. If Dack has any insite on this I would appreciate it.
 
... I have figured out drawing the rivers...
I am looking at the images for the shoreline, and am having trouble understanding when to use what to draw the rounded shorelines...

If you have the rivers displayed as they appear in the game use the same algorithm for the oceans. As there are 16 different river patterns there are also 16 ocean patterns (32 if you count the ones with fish resource). Make 16 ocean images each one with a unique shoreline pattern. Look at each ocean square, is there land next to it N S E and W. Assign each of the four map directions a value (1,2,4,8). Add them up giving a value from 0 to 15. Zero being an ocean with no shoreline, one being an ocean with land to the north and so on. Use the result as an index into an array of the 16 ocean images.
 
In the CivWin the images are all in one block 1472x400.

I figured the oceans were the same as the rivers but looking at the only images for the ocean they just don't look right. There is a block of all the images for the various land types. Desert at the top down to jungle at the bottom. This block is 16 squares wide. Then a blank row and then the ocean.

The first 7 for the ocean look reasonable, then there are 4 that look like 4 blue paw prints, another blank one and then three that look more like rivers. Then there are 6 more that look like shore lines underneath the images for the wonders.

I take it that you do the same thing for hills and mountains? That's why the 16 square wide block?

Also there are what look like two identical sets of rivers.

Does this sound like the DOS image?

Edit: Just tried this for hils and mountains. Looks good. But I have not located the right 16 images for the shoreline.

I can't find the shoreline in the image, so I just screen scraped them from the game. Didn't get all of them exact, but close enough for the scope of this project.
 
I have looked at the shorelines a little closer. They are more complicated than the rivers, hills, mountains and other land forms. They also look at the corners.
 
I have looked at the shorelines a little closer. They are more complicated than the rivers, hills, mountains and other land forms. They also look at the corners.

Quotes from MountainMn10 in red
I take it that you do the same thing for hills and mountains?
I haven’t coded the hills and mountains as seen in the game. In TerraForm each hill or mountain stands alone.

That's why the 16 square wide block?
CIV DOS presents each square in 16 by 16 pixels. I was unaware of the program PIC.EXE, so in my early effort I captured images from the game its self.

Does this sound like the DOS image?
TerraForm images are mostly captured from the game or manufactured approximations. If I remember correctly the shoreline on the ocean squares are my own approximation.

…but close enough for the scope of this project
I don’t think anyone would nitpick if your representation is not exact.
 
Did I get this right? The editor is already working? All these years of waiting - I can't believe it!

How can I get it?
 
http://www.dynacomsoftware.com/CivWin/CivCracker.zip

There is no installation kit. It is just an .exe. Copy it to a directory and create a shortcut.
There is no documentation. If you try menu items before opening a saved game you may crash the program.
The about box lists all the Civ Fanatic's members who helped me develop this. Many (most) of them are unaware of their contribution.

Dot Net Framework 2.0 is required. You can download it using Windows Update.
 
It works! I have just changed some of these useless mountains to plains, grassland and hills. Some grassland squares became the type without shield, some the one with a shield.
Then I changed an ocean square to a plain square, and it has a hut on it.
Thx a lot!
 
One thing to watch for is if you leave it in Draw Land mode and you start clicking on units or cities it changes the land under them.

You can right click on a square for more options. I need to make the right click not "Draw Land".

I am happy someone else is still interested in Civ Win.
 
MountainMn10
http://www.dynacomsoftware.com/CivWin/CivCracker.zip

There is no installation kit. It is just an .exe. Copy it to a directory and create a shortcut.
...
Dot Net Framework 2.0 is required. You can download it using Windows Update.

Unfortunately, it does not work on desired comp, at least from USB flash drive.
(the CiwWin is also there, I do not want to leave any file on that machine, nor have any permission to install there anything)

I got this mesage:

Application Error
The application failed to initialize properly (0x0000135)
Click OK to terminate the application

There no Net Framework 2.0 right? How I can verify that?
A second computer on which I would like use this is without a network connection and there's also definitely not Net Framework 2.0
Of course, I deal with how to get it yourself, but maybe you've got a good and ready solution?
 
Bump!

After going through some of my old saved games and noticing that in one of them I'm controlling an AI civilization, I've been searching around for ways to replicate that.
That's how I found about CivCracker - what a great program you got there, MountainMn10!

Unfortunately, so far I'm still unable to replicate that civilization "switch", because either I'm dumb or CivCracker doesn't have that feature...
In any case, do any of you know how to switch sides in CivWin?
 
Top Bottom