******************** Finally Flatmap support ********************
SLIC Code for making flatmap-support for CtP1 possible.
Made by Wouter Snijders a.k.a. Locutus (locutus-of-borg@hetnet.nl)
Date: May/June 2000, last update: June 28, 2000



*** Important notes ***

You can e-mail me with any questions, problems, suggestions, remarks, etc, you may have at locutus-of-borg@hetnet.nl, or you can find me at the forums of the Apolyton Civilization Site (http://apolyton.net). I use the handle Locutus there (Duh!)

Many thanks go to Don Blevens (aka Skorpion59), Darryl Marcinkoski (aka Gemini), Paul van den Belt (aka Paul) and Wes Whitaker (aka WesW) for their support and ideas. If it wasn't for Don, I would probably never have even started looking for a workaround for flatmap-support (and he helped me a lot in all stages of development) and Gemini was the one who pointed me in the right direction for the final solution. Paul and Wes helped me in setting up versions for CD's mod and Medieval Pack 3 respectively.

The parts of this file marked with '(for those interested)' aren't really necessary to read, but I urge you to read the rest of this file.

In writing this readme I tried to make it as understandable as possible for a large audience, even for people who aren't too familiar with CtP and modmaking. So if you find that this documentation is too simple and you feel patronized, that's just because others may have a tougher time understanding this all then you have. I'm sorry if this bothers you.

Feel free to use, distribute and/or change this code as you please, but please mention my efforts if you distribute this code (or an edited version of it) to others.
I am in no way associated with Activision or any other company that is involved with Civilization: Call to Power. Should this code in any way damage your computer or your game, I am not responsible. It is advisable to make back-ups of your files before installing or using this mod.



*** How to get flat-map support to work ***

In short, this mod works by creating two rows of invincible units (out of frustration Don Blevens and I started calling them BBBs, Big Black Blobs - because that's what they look like ;) ) where the map-edge should be, making travelling over the map-edge impossible. Also, in the beginning of the game the terrain around this map-edge is terraformed in such a way that the terrain under the BBBs is dead and the transition between the surrounding terrain and the dead tiles goes smoothly. Futhermore, starting locations for civs on the actual map-edge are moved a litte so they are right next to it. For more details see below (under the section 'How does this code work?').
You can get flat-map support to work with the most popular mods of CtP by simply unzipping the appropriate zip-file for a certain version in the standard CTP-folder (by default C:\Program Files\Activision\Civilization - Call to Power\). With the Apolyton Pack version you will be asked if you wish to overwrite packlist.txt, answer yes to this. This mod will normally only work if at least the following programs are installed (it *may* work with less programs but keep in mind that I didn't design it for it and I wouldn't put my money on it; normally it *will* work with more programs installed (e.g. CtP Modpicker) but again, I didn't design it for it):

- Civilization: Call to Power itself (Duh!)
- Patch v1.2 for C:CtP
- Hack v1.21 (the No-CD hack should work as well but I didn't actually test this)
- the appropriate mod(s) for your version(s) of flat-map support. There's also a version for the original game files, that doesn't need any mods.

When I wrote this file, flat-map support was available in the following versions (all can be downloaded at Apolyton, though FM4MP3 probably not seperately but only as part of Medieval Pack 3 itself):

- FM4Orig.zip	for the original game files, so with no mods installed
- FM4MP3(.zip)	for Wes's Medieval Pack v3, included within the Pack itself
- FM4AP.zip	for use with the Apolyton Pack
- FMCustom.zip	custom version, for your own or unsupported mods/scenarios
- FM4CD.zip	for use with CD's mod v4.22 (+ graphics add-on, you need that installed as well or else use the custom-version of flat-map support)

To install this feature on mods/scenarios that are not supported, you must follow the instructions off the section of this document titled 'How mod-makers should use this'.
To play a game you must start a new game/hotseat game from within the game and then open the scenario screen (Click on the 'Select Scenario' button). Select the correct scenario by double clicking on the scenario pack you want and then the correct scenario (Single clicking and pressing OK works too). This will not work with old savegames, you must start a new game to get this to work once it is installed.
If you safe a flat-map game (or any scenario/mod game that doesn't overwrite the original game files) and you want to play with it again, it would be wise to first start a new game with the same mod/scenario/mod-combo, so the scenario-files are loaded and then load the actual savegame you want to play on (via options -> load game from within the new game). Loading your savegame directly may cause the game to crash, either while loading it or during play. I never noticed this myself but then again, my system crashes so often I wouldn't notice it if there was a pattern ;) But whether it helps or not, it is a good and not too time-comsuming precaution to prevent crashes so I always use this method myself and I can only advise you to do the same.

There's a theoretical chance that the game tries to relocate a starting location for a civ that had it's starting location on the map-edge but can't find a suitable starting location within a few tiles of the original location. If this happens the game will either freeze or crash, but the chances of this happening are extremely small and so far I haven't been heard of anyone who experienced it (I haven't experienced it myself either). This can only happen if a starting location is at an extremely small island or on a chokepoint of a continent. But if it happens, just restart your computer and start a new game, that should solve the problem (I can't imagine that it would happen twice in a row).



*** How mod-makers should use this (for those interested) ***

You can incorporate flat-map support in your own mods/scenarios easily, or add it to mod(-combinations) that are not supported by default. To do this you first need to download and unzip the scenario version of flat-map support (it will create a scen0001 folder under the [CTP_folder]\scenarios\ and put the files in there). Once you have done this there are three options: you install flat-map suport over an exissting mod in the scenario structure, as an addition to the 'regular' game of that mod (i.e. no flat-map support). Secondly, you can install it over a mod that uses the original game folders instead of scenario folders (though flat-map support itself *will* need scenario folders), again as an addition to the original game or to a mod that was installed over the original files. Finally, you can install it over a scenario/map, as a replacement of the 'regular' game.
 
The first method is that you have a mod that is installed in the folder [CTP_folder]\scenarios\[mod_name] and that has in this folder two subfolders, 'english' (or some other language name) and 'default', in which the modified files for this mod are contained. This setup allows you to get flat-map support for a mod or mod-combination without overwriting the standard files of this mod. If you don't have the default and english folders as subdirs of [mod_name] but as subfolders of [mod_name]\scenarioxxxx (in which xxxx is a number between 0000 and 9999) you can still get flat-map support but it will overwrite the standard mod-files and you can only use flat-map support (and not the 'regular' game) until you manually remove it again. This can be avoided by copying the entire contents of the scenxxxx folder into a scenyyyy folder in which yyyy is a different number between 0000 and 9999.
To accomplish this you should copy the scen0001 folder of the scenario-version into your own [CTP_folder]\scenarios\[mod_name] folder. You may need to rename it if the scen0001 folder already exists. In this case rename it 'scenxxxx' then, in which xxxx is a number between 0000 and 9999 using a number that isn't used already. Now open the packlist.txt file and add one to the number on the bottom of the file. If you want to you can now open the scenario.txt file in the scen0001 folder (or whatever you called it) and change the text so that it gives a description of the mod (the first line of the file will be the title of the mod, the rest a description). 
Now you need to make the actual changes. For this, copy the files units.txt and spriteID.txt from the [CTP_folder]\scenarios\[mod_name]\default\gamedata folder to the [CTP_folder]\scenarios\[mod_name]\scen0001\default\gamedata folder and the file gl_str.txt from the folder [CTP_folder]\scenarios\[mod_name]\english\gamedata to the folder [CTP_folder]\scenarios\[mod_name]\scen0001\english\gamedata (if you don't use the default names you'll have to replace scen0001 and/or english with whatever names you *do* use). If these files are not present in the default and english folders of the mod, you should copy the files from the original game folders ([CTP_folder]\ctp_data\[english and default]\gamedata). Now past the text from the additions-files (units.additions.txt, spriteID.addtions.txt and gl_str.additions.txt) into the 'original' files of the same name. Make sure you also add one to the numbers on top of units.txt and spriteID.txt.
If you're not familiar with changing the text-files, add the units.txt additions right above the last line of the files ("### ALL UNITS DONE ###"), add the additions of spriteID.txt at the bottom of the file and with gl_str.txt, make the additions at the bottom of the list with units (a list of UNIT_xxx with xxx being unit-names halfway down the file). If you *are* familiar with editing the text-files, you'll be able to jugde for yourself what the best place is to put the additions. 
Now you can delete the addition-files if you want to (though it won't change a thing if you don't). Also, you can replace the scenicon.tga file with your own file, but that's not really necessary either. That's it, you should now have flat-map support on random maps for this mod. You can now start a game with or without flat-map support by going into the scenario-selection screen when setting up your game and selecting the correct scenario.

The second opton is if your mod isn't in an scenario folder but overwrote the original game files. In that case you should make all the above changes in a new scenario folder that contains nothing else than the described scen0001 folder (in this case it would make more sense to rename it scen0000) and a packicon.tga (e.g. a copy of scenicon.tga, but this file is optional, you can leave it out if you want to, the game will use a standard icon in that case) and packlist.txt (which contains as first line a title for the scenario, as second line a description and as third line a number for the number of scenarios in this pack (1 in this case). This scenario folder should be placed in the [CTP_folder]\scenarios folder. 
Note that you don't necessarilly need to use the scen0000 folder, you can also place the default and english folders directly under the main scenario folder (e.g. instead of using [CTP_folder]\scenarios\Flatmap\scen0000\[default and english] you can also use [CTP_folder]\scenarios\Flatmap\[default and english]). Keep in mind that the other files in the scen0000 folder are still needed, just the two folders can be moved. Of course it's also possible (though normally not smart) to install flat-map support directly over the original game files but keep in mind that you can't play on a 'regular' map as long as flat-map is installed (not without using a scenario). Should you decide to edit the original game files you should be very carefull and make sure you have back-ups of all your files.

The third option is that you don't want to have flat-map on a mod with random maps, but that you want it to replace the random maps by a custom map. Normally this is only the case with scenarios (which normally have only one map) or loose maps, whether they come 'stand-alone' or as part of a mod. In this case, locate the default and english (again, if you use a different language replace 'english' with the language you use) folders within the scenario structure (this could be under either [CTP_folder]\scenarios\[scen_name] or [CTP_folder]\scenarios\[scen_name]\scenxxxx with xxxx a number between 0000 and 9999, depending on where the scenario-maker choose to put the files). Now add the the gu93.spr file of the scen0001 folder of the scenario-version of flat-map support to the appropriate folder (..\default\graphics\sprites) in your own scenario folder and add the scenario.slc file to the appropriate folder as well (..\default\gamedata). If either of the files already exists in the scenario structure, simply rename the (new) files. Gu93.spr can be renamed guxxx.spr with xxx any not already existing number between 0 and 200. Make sure you also change the number behind SPRITE_BBB in spriteID.additions.txt in the scen0001 folder to match this number. If you rename scenario.slc (to any name you want, as long as the extension remains slc - it might be wise to not make the name itself longer than 8 characters since I don't know if CtP and/or SLIC supports longer names) make sure to add the line "#import newname.slc" to script.slc in which newname is of course your new name. (If script.slc isn't present in the scenario folder structure, copy it from the original game folders - note that this is only needed if you give a SLIC file any other name then scenario.slc). Once you did this you can paste the text from the additions files into the files in you scenario structure (as described above). 
To make flat-map support work on a custom map/scenario instead of on random maps you'll need to have a savegame in your scenario folder (it should be in the scenxxxx folder). Because of this you may want to remove the second trigger in the scenario.slc file because it might otherwise delete part of your map. To find out if this deletion happens and is annoying, just try it out to see if this is so. If this is the case, you can remove the second trigger.
If you delete the second trigger though, you'll have to make sure yourself no civs have a starting location on the map-edge and that the BBBs are placed on the proper positions of the map and that the terrain is terraformed properly as well. To remove the second trigger find the part of this file that says '////////// Random Map trigger //////////' and delete everything from there to the line '// The last line of the file may not be a comment or the game will crash'. You must make sure the last line of the file is not a comment (i.e. starts with '//'), so don't delete the last line itself.

If you have any problems you with any of this you can always contact me or post in the forums. Note that this setup for flat-maps isn't the only one. If you want a scenario with a circular, triangular, diamond-shaped or any other shape of map, this can be accomplished in the same fashion as this file. I don't plan on making this myself unless there turns out to be a great demand for it, but you're of course free to try it yourself. Should you not succeed in this because your knowledge of SLIC is limited or you simply find it to challenging to get exactly the right units placed in the right spot (this can be a real pain, believe me), I'm willing to help you out with it, so don't hesitate to contact me (posting in the forums is less usefull here since - at least for now - I'm the only one with experience in this area and others will have just as much trouble as you have).



*** History (for those interested) ***

When Activision brought out Civilization: Call to Power they didn't supply it with flatmap support. They rushed out the game and the result was a only half-finished game with a lot of bugs and many features that were supposed to be implemented but taken out at the last moment (or at least that's what most people claim, I don't think Activision ever officially confirmed this - fact is, a lot was wrong with the game when it shipped). Flatmap-support was one of those features. A lot has improved with the patches that were brought out but flat-map support still didn't work. (The Activision people promissed us they'd fix it in CtP2 but at the moment of writing the release for part 2 was still at least several months away.) A lot of people tried to get it working anyway after the game release but failed to do so.
Don Blevens was still trying to get it working when he and I were part of a SLIC group that was going to bring out a SLIC-mod among other things (it might still some day, at least if I can help it). I mentioned I wanted to have a look at flatmap-support as well for the mod to see if that was possible to accomplish this through SLIC. Don initially dismissed it but he sent me the stuff he'd been working with to see if I had some new ideas. This stuff was not SLIC related at all and after working with it for a while I thought that it might have potential but only after a lot of frustrating experimenting and I wanted to try through SLIC anyway.
Initially I booked a lot of succes but it took many months of on and off experimenting with the code to get close to a finished solution that was nice but not ideal. Then Gemini got involved in SLIC for his WWII scenario and after asking for help in the forum we got into a discussion to solve his problems and then he found a solution to his own problem by finding out how an undocumented function worked. This function proved very useful for me as well and I threw out the solution I already had for flatmap-support and wrote a whole new version. This is the code you're looking at right now, it only took me about two weeks to finish it and to get it working in scenarios as well as on random maps. After a short period of public beta-ing without significant problems (I only increased the defensive values of the BBBs to make it less likely for the AI to try to attack the BBBs) it was officially released on Apolyton CS.



*** How does this code work? (for those interested) ***

I think it is very important that any kind of programming code should be documented in such a way that others can understand it and possibly learn from it, in fact, I think that is even more important than the code itself. For this reason I always try to document my code as thoroughly as possible. If there is anything unclear about the code or it's explanation (it was tough to find out how to get it to work, but it is even tougher to explain to others what it does) and you would like to understand it, feel free to email me or visit the Apolyton forums. Note that I added some comments to the actual code itself as well.

What this code does, is to check every time a player starts its turn, except the first year (at least in case of a random map, in a scenario this might be different) if there are units at all locations that form the edge of the map. If this is not the case, it will create two Big Black Blob units (BBBs) at the edge of the map. I choose for two because one unit will have a bigger shield, which is IMHO ugly and more aren't really needed (though it will now be possible for barbarians to cross the mapedge; should you want to prevent this, you should change the code so that nine units get created).
Since these units cannot be attacked they will normally never die. However, a nuclear explosion near the edge of the map *can* kill the BBBs and that's why the trigger that check if the units are still there is executed every turn. Elaborate testing showed it to be difficult to have the units replaced as soon as a nuclear strike occurs (i.e. the game will crash). My theory is that, when you want to replace the units as soon as they die, two different game-events want to access the unit-objects and manipulate them, which is something the game-engine isn't equiped to do. Hence there is a conflict and the game will crash. Of course, that's just my theory...
Because there BBBs aren't replaced as soon as possible, it is possible for units to sneak trough to the other side of the map in the meantime. The chance of this happening is minimal, since the mapedge isn't really suitable to have cities right next to them and as far as I can see it isn't really likely that a lot of Nukes will be unleashed on units right next to the mapedge (the nukes would have only a limited range of destruction then). And even if it does happen, a unit with a high movement-factor would have to be near the hole in the egde and yet far enough away to still be out of range of the Nuke. Also, AI-players rarely or never use Nukes and humans will realize that moving through a gap in the mapedge will be very unrealistic, and if they choose to do it anyway, it's their own mistake that the game lost it's realism.
The trigger that works during the first gameturn is different from the other trigger (that works always except the first turn) in that it also terraforms the terrain underneath and, if needed, around the BBBs. It will make all the terrain under the BBBs dead, so that the AI won't settle near the mapedge because it thinks it can collect the resources on that terrain later on in the game (when the BBBs have moved away, which they of course never do) and because it marks the edge of the map better when the fog of war is over them. Also, in sea the surrounding terrain will have to be terraformed as well because if one square is land and the square right next to it is deep ocean or something like that the results won't look pretty (you can try this out in cheat-mode if you don't know what I mean. So a elaborate system of terraforming has been set up to prevent the aera around the mapedge from looking ugly. This system isn't 100% bulletproof, occasionally a ugly square can appear but this isn't so ugly that it becomes unacceptable. If you look very closely, you may even see more, very subtle errors, but even the map-generator of Activision can't prevent this so you I most certainly can't either.
The trigger that works in the first turn only also has a section that moves units that are on the mapegde as well (under normal circumstances these are starting locations). It will move these units to a random locations up to four tiles away from the original location (if this isn't possible because the starting location is on a tiny island or chokepoint that is swallowed by the mapedge, the game will get in an infinite loop and probably crash, but the chance of this happening is so small I couldn't get it to happen yet, no matter how hard I tried). I choose for no more than four squares because else it'd be hard to predict where the unit would end up, it could be very near to a opponent. Also, the chance still getting a good starting location are largest near the original location, the further away you go, the larger the chance you'd end up in a large and barren desert, mountain range or polar region.

If you ever want to work with maps in CtP you might want to know that the coordinate-system in CtP works slightly unusual, the width (here x) is measured along the horizontal axis (this is pretty normal) but the height (here y) is measured along the diagonal axis, so it looks like this (on a 24x48 map):

      /\    /\    /\    /\    /\    (upper number is x, lower number is y)
     /  \  /  \  /  \  /  \  /  \
    / 23 \/  0 \/  1 \/  2 \/  3 \
    \  0 /\  0 /\  0 /\  0 /\  0 /\
     \  /  \  /  \  /  \  /  \  /  \
      \/ 23 \/  0 \/  1 \/  2 \/  3 \
      /\  1 /\  1 /\  1 /\  1 /\  1 /
     /  \  /  \  /  \  /  \  /  \  /
    / 22 \/ 23 \/  0 \/  1 \/  2 \/
    \  2 /\  2 /\  2 /\  2 /\  2 /
     \  /  \  /  \  /  \  /  \  /
      \/ 22 \/ 23 \/  0 \/    \/
       \  3 /\  3 /\  3 /
        \  /  \  /  \  /
         \/ 22 \/    \/
          \  4 /
           \  /
            \/
            .
            .
            .
      /\    /\    /\
     /  \  /  \  /  \
    /  1 \/  2 \/  3 \
   /\ 44 /\ 44 /\ 44 /\
  /  \  /  \  /  \  /  \
 /  0 \/  1 \/  2 \/  3 \
 \ 45 /\ 45 /\ 45 /\ 45 /
  \  /  \  /  \  /  \  /
   \/  0 \/  1 \/  2 \/
   /\ 46 /\ 46 /\ 46 /\
  /  \  /  \  /  \  /  \
 / 23 \/  0 \/  1 \/  2 \
 \ 47 /\ 47 /\ 47 /\ 47 /
  \  /  \  /  \  /  \  /
   \/    \/    \/    \/



Enjoy your games!

Wouter Snijders (aka Locutus)
locutus-of-borg@hetnet.nl