This post is mostly for Arkiruthis/Mrthingy, but if the rest of you want to read it, feel free!
All of the map data for Powermonger is contained in the MAPDATA.DAT file. This file is 65,268 bytes long and contains 196 Powermonger maps. It’s broken down into:
* One header that is 196 bytes long. It’s possible this header was going to flag certain maps as being certain types, but since all of the entries are zeroes it probably wasn’t used.
* One hundred and ninety-six map files that are each 332 bytes long.
While I have not figured out everything each byte in a map file represents, I’ve figured out a lot. Here’s the map file for the third level (I picked this one because it’s more interesting than the first two). I’ve grouped the bytes into groups of four because…well, you’ll see.
First off, here’s a cleaned-up version of how the minimap for the third level looks:
The first 40 lines (160 bytes) contain data I haven’t identified yet, but I can say that most of these lines are exactly the same in all files.
0 10 0 32 0 250 0 0 0 10 0 15 0 7 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 0 48 0 250 0 4 0 10 0 20 0 7 0 2 0 0 0 0 0 6 0 0 0 0 0 0 0 0 0 0 0 15 0 32 0 250 0 8 0 10 0 20 0 7 0 2 3 0 208 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 32 1 14 0 1 0 10 0 15 0 7 0 2 3 212 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 32 1 24 0 2 0 10 0 10 0 7 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Now things get interesting. The first three bytes of line 41 contain the values that are passed into the terrain generation algorithm. Altering them alters the terrain of the map. The last byte is apparently passed into the forest-creating algorithm, since changing it changes the forests without changing the underlying terrain.
2 97 18 0
The first byte on line 42 (in this case, 0) is also apparently fed into the forest algorithm.
The second byte on line 42 (in this case, 6) appears to set the upper Z limit – raising and lowering this value makes the terrain hillier or flatter without altering the shape of the terrain on the map.
The fourth byte (32) is an X-coordinate offset. It won’t change the shape of the terrain, but it will move the entire terrain mass left or right on the map. The terrain mass will wrap around if necessary.
0 6 0 32
The second byte on line 43 (48) is, you guessed it, the Y offset. It will move the entire terrain mass up or down on the map, wrapping around as necessary.
The fourth byte on line 43 (3) is apparently a terrain smoothing factor. Setting this value low causes the terrain to get very jagged; setting it high causes the terrain to smooth out until there’s nothing left.
0 48 0 3
Now we can FINALLY stop guessing, because from line 44 until the end of the file, each four-byte group encodes one “object” that is dropped on top of the terrain after generation. The four bytes represent the X-coordinate, Y-coordinate, team of the object and finally the object type. The X and Y coordinates correspond perfectly to what pixel that object is in on the minimap (which is why I was able to figure these out).
The player’s team is team 1; all higher numbers refer to computer-controlled teams. Unfortunately I do not know what all the codes mean yet because I haven’t been able to access maps that use those objects. Here are the object codes I do know:
1 – Road Endpoint
2 – Tiny Village
3 – Medium Village
5 – Large Village
16 – Tower
17 – Road Segment
You will always see a “1 16” pair (a tower belonging to Player 1) in the list. This designates where the player starts.
52 24 1 16 - Tower belonging to Team 1 at 52, 24 14 65 2 16 - Tower belonging to Team 2 at 14, 65 17 41 3 3 - Medium village belonging to Team 3 at 17, 41 41 66 3 3 - Medium village belonging to Team 3 at 41, 66 44 99 2 5 - Large village belonging to Team 2 at 44, 99 35 78 3 3 - Medium village belonging to Team 3 at 35, 78 54 77 3 3 - Medium village belonging to Team 3 at 54, 77 8 77 3 3 - Medium village belonging to Team 3 at 8, 77 41 66 1 17 - Road segment belonging to Team 1 54 77 1 17 - Road segment belonging to Team 1 55 91 1 17 - Road segment belonging to Team 1 44 95 1 17 - Road segment belonging to Team 1 37 90 1 17 - Road segment belonging to Team 1 35 78 1 1 - Road segment belonging to Team 1 35 85 1 17 - Road segment belonging to Team 1 26 94 1 17 - Road segment belonging to Team 1 22 94 1 17 - Road segment belonging to Team 1 19 86 1 17 - Road segment belonging to Team 1 16 75 1 17 - Road segment belonging to Team 1 11 72 1 17 - Road segment belonging to Team 1 8 77 1 1 - Road segment belonging to Team 1 48 40 3 3 - Medium village belonging to Team 3 at 48, 40 26 52 3 3 - Medium village belonging to Team 3 at 26, 52 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Notes:
Yes, the road segments belong to team 1 (the players’ team). I’m not sure why.
You can easily beat any Powermonger map by finding the data for that map in MAPDATA.DAT and changing all the villages to belong to team 1. Next time you load that map you’ll be instantly declared the winner.
When the terrain generator drops these objects on the map, it creates terrain underneath them if there isn’t already some.
And finally, here is the source for the program that can scan the original MAPDATA.DAT and split out the map files.
And now as a special bonus! These are some notes I took about how the village simulation in Powermonger works. They are kind of rough, so I present them as-is 🙂
Notes on Powermonger:
Powermonger allows the two triangles in a cell to be different terrain types. Thus, you can have half be beach and the other water, half be farmland and the other mountain, etc.
Speaking of farmland, it’s not marked on the map, but all the clear, flat tiles (or half-tiles) around a village is considered farmland.
By the same token, all the water that is at least one square from a beach is considered “fishable”.
While there are only two official “jobs” (farmer and fisher) there appear to be five things a walker can do in Powermonger:
Gather food from a farm (this REQUIRES the job “Farmer”).
Gather food from the ocean (this REQUIRES the job “Fisher”).
Gather wood (no specific job required).
Bring a sheep back to the village center (no specific job required).
Defend themselves when attacked (no specific job required).
(Units also make things, but since that is all handled internally there is absolutely no way to tell what unit made what and why or how they chose to make that particular thing.)
Farming and fishing cannot happen during the winter. Walkers usually gather wood or make things in the winter. If a walker has no supported job, he simply stands in the center of the town.
Hard to tell how often units “eat”, but it appears they consume 2 food every time they do.
When walkers encounter sheep (which is pretty random, since the sheep walk around randomly and the walker must get near the sheep in the course of doing another job), they bring the sheep back to the center of town. It APPEARS that as long as the sheep is near the center of town, the village gets a constant low food income. But the sheep will continue to wander off, and thus will have to be brought back again.
Towns cannot die off. Ever. If you take all the walkers from a village and the last walker is about to starve, then five men from your army will leave your army, become walkers, and rejoin the village.
Fantastic stuff. Only unfortunate thing is that the 3 bytes that seed the landscape generator require a random number generator that was presumably written into Powermonger. I imagine the standard C libraries on Amiga, ST, PC etc. implemented their own methods so the only way to keep the maps looking the same between formats was to utilise their own random number generator that gave the same results for a seed regardless of which format it was running on.
I can see why they implemented the X and Y offsets. The generation algorithm is similar to mine in that when the random ‘walk’ hits the edge of the map, it starts again on the other side. They could offset the map so that the main terrain areas were in the middle of the map.
Yeah, the first 2 bytes is the seed number, the 3rd byte seems to be the ‘length’ of the random walk around the landscape. At 01 it’s very short, at FF it pretty much fills the map.
Oh, I’ve uploaded the terrain algorithm if you’re interested:
http://arkiruthis.blogspot.com/2008/06/powermonger-terrain-algorithm.html
Ah, reverse engineering, the third most fun thing you can do with a computer.. (or so). Just too bad it’s more or less illegal in many parts of the world these days.
I once went through a bunch of old DOS games and figured out some graphics formats. I think the game was mean streets – it has some cutscenes done as animations; the animation compression format was actually quite much fun to figure out =)
I wish somebody would bring PowerMonger to the iPhone. I loved that old game but it was not very friendly towards any of the hardware that came out afterwards.