Map Script Compatibility with Mac Warlords

Grimvisage

Chieftain
Joined
Dec 23, 2006
Messages
12
Location
High Point, NC
Hey everyone,

New player and poster here. Just got the game for Christmas and have been trying it out with some friends, but already we've noticed that many (if not most) of the map scripts on the forums here act in some very unexpected and unfriendly ways when run on Macs. I thought that I would post a list of the ones I've tested here along with comments on their success. Also, if anybody has any other information, please feel free to add it.

NOTE: These scripts have not been tested in multiplayer cross-platform games, i.e. PCs running unpatched Warlords in multiplayer games with a Mac player connected. The one exception is the "Full of Resources" script, which is linked below, and which my cousins, brother, and I (with one of their PCs hosting for my MacBook Pro) have playtested for several hours now and thoroughly enjoyed (apart from what seemed like unusually large numbers of animals and barbarians).


Full of Resources: :D :( In the Custom Game menu, when any of the scripts are selected, none of the extra options appear in the list. When run, the scripts generate grassland-only maps. However, if a PC running version 2.00 Warlords hosts the script and a Mac player connects, it works almost perfectly. My only concern was some "graphics blips" where my screen turned funky multi-colors for a split second, then reverted to normal. Eventually, this caused my computer to freeze and crash, but I reconnected successfully. So far, this is my absolute favorite script, with just a couple of minor complaints.

Planet Generator: :( No options, generates grassland-only map.

Tectonics: :( "Landmass type" and "Aridity level" options appear correctly. Using default settings on Large, creates very unusual and mostly unplayable maps, typically with too much water and strange land combinations, such as one large continent with several smaller ones on the very edges of the map. I'm not sure if this is the intended result, since I don't have a PC to test it, but it's not Mac-friendly.

Random Map Script v5 final: :) Seems to work correctly, but not a script I'd ever play. Generates mostly Pangaea or two continent maps with rather inorganic terrain and resource placement. Perhaps that's different on PCs.

Earth2: :) Seems to work perfectly! (not thoroughly playtested)

SmartMap: :( No options in the Custom Game menu, generates grassland-only maps. Shame, too, because this script looks incredibly promising.

Fertile: :) Works perfectly!

Fair Continents: :( No options, grassland-only maps.


Snaky Pangaea and Grainy Pangaea:
:) and :) Both work perfectly! (And, IMHO, excellent map concepts!)

Chess: :( No menu options, generates grassland-only maps.

Grid: :) Menu options appear, but have odd names, e.g. "TXT_KEY_MAP_SCRIPT_OCEAN". Otherwise, works correctly. (not thoroughly playtested)

Life script: :) Seems to work perfectly! (not thoroughly playtested)


Sansimap:
:) Seems to work perfectly! (not thoroughly playtested)


I hope this post is helpful for somebody. :-D And I urge, plead with modders and script writers to keep Macs in mind. I get the feeling that many of the newer scripts don't work because they've been altered for compatibility with Warlords 2.08 for the PCs, so I may just have to wait until Aspyr gets their act together. *frustrated sigh* Comments welcome. Ja mata ne!
 
I just had a quick look at PublicMaps from Planet Generator, and the problem there is that it uses Python to read the Windows registry to identify the path to your ~/Documents/Civ4 folder. This fails on a Mac, of course.

This is a common problem with mods developed for Windows, and there is probably no standard way to fix it. It may well affect some of the other mods you are having trouble with.

For example, in Sto_Archipelago_2_99.py:

change:

Code:
def regRead(registry, path, field):
    pathKey = _winreg.OpenKey(registry, path)
    try:
        fieldValue = _winreg.QueryValueEx(pathKey, field)
        return fieldValue[0]
    finally:
        pathKey.Close()

def civFilePath():
	try:
		userFolder = regRead(_winreg.HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders","Personal")
		civFolder = os.path.basename(regRead(_winreg.HKEY_LOCAL_MACHINE,"Software\\Firaxis Games\\Sid Meier's Civilization 4","INSTALLDIR"))
		finalFolder =  os.path.join(os.path.join(userFolder, "My Games"), civFolder)
		return finalFolder
	except:
		return ""

to

Code:
def civFilePath():
	try:
		userFolder = os.path.join(os.environ['HOME'], "Documents")
		civFolder = "Civilization IV"
		if (os.path.basename(os.getcwd()) == "Warlords"):
			civFolder = "Civilization IV Warlords"
		finalFolder = os.path.join(userFolder, civFolder)
		return finalFolder
	except:
		return ""

PS. I haven't tested the above, and it may not be the only reason for these scripts to fail.
 
I really appreciate your taking the time to look into this. :) Unfortunately, the change you suggested only causes the game to lock up during the Initialization phase of launching the map. I'm completely ignorant about scripting, so I'm afraid I'm not much help. As far as I know, my programs are in the default paths, so if the code is pointing to those directories, that's not the only bug in the script. Very puzzling. I have verified that the same winReg code is present in other scripts that failed, but inserting the suggested code also produces the same lock-ups at Initializing. Can anybody else shed some light on this?
 
I'm working on it. It doesn't lock up here - it just doesn't appear as a map option at the moment.

OK. I found the hidden problems in the Spoiler tag in Sto's thread. These maps are designed to be run in conjunction with a mod that handles a lot of the options and functions that are called.

Sto said:
ou must play a MOD with The Lopez 's Scriptable Trait component

Unfortunately, the Lopez Scriptable Trait mods use a custom DLL, and the Mac versions of Civ4 and Warlords cannot handle custom DLLs until/unless Aspyr give us a Mac SDK that we can use to compile them, and a new Mac version that can handle it.

[EDIT]
However, if you comment out the line: "import _winreg", and comment out or delete all the stuff at the beginning that assumes there's a scriptable trait mod, then the map script loads and runs, as far as I can tell.

Tectonics looks OK to me. I think the odd maps are just the way it is.
 
Alright, well, I have discovered that if I wait about 5 minutes, the map will finally generate, but it's a grassland-only. Maybe it's something in the earlier edit of the file path. Could my path be invalid for what the code is pointing to? The Warlords application is in Applications/Civilization IV/Warlords. Also, none of my friends have the Lopez mod, and they have been able to run the script just fine. That makes me think that the mod may only be necessary for the "traits" options, as the top section indicates. Does the code call for a search of the mod's presence and then an "if not, don't show xyz pulldown menus"? That would let us know better whether it's really the Lopez lines that are causing the fuss.

[EDIT]
However, if you comment out the line: "import _winreg", and comment out or delete all the stuff at the beginning that assumes there's a scriptable trait mod, then the map script loads and runs, as far as I can tell.

I'm not exactly sure what parts you mean... I just went ahead and backed up the script again and tried deleting all of the lines mentioning the Lopez mod as well as the winreg line. Unfortunately, that still did not allow the script to load acceptably (though it did eventually load), nor did it return the proper options menus in the Custom Game screen, which is what's really important for this script. I'm not exactly sure what I'm doing, hahaha. :-D Well, I'll keep messing around, I guess. Thanks for your help!
 
OK, here's one I've debugged properly (I think).

Attached is a copy of the archipelago script that I placed in ~/Documents/Civilization IV Warlords/PublicMaps/. It produces a Custom Game options screen of enormous proportions with lots of menus whose functions I can only guess and wonder at. Let me know if this does what you want.

If it works, you should be able to transcribe the changes I made into the other map scripts. There are three sections that are changed from the original:

1. Line 294 - commented out:
# import _winreg

2. Line 303 - insert the following:
Code:
if (sys.platform == 'darwin'):
	import sets
	def set(arg):
		return sets.Set(arg)
Note that Python requires the consistent use of tabs to indent the lines of code precisely as shown above.

3. End of file, as defined in my previous post, modify the last two 'def's to replace the Windows registry calls
 

Attachments

  • Sto_Archipelago_2_99.py.zip
    41.4 KB · Views: 173
Hmm. Still getting an error during map creation. It produces a map, but I suspect some parameters will not be taken into account. Working on it ...

[Update] It uses a Python 2.4 function that is not available in Python 2.3. I'll have to see if there's a way to work around it.
 
Awesome! You are a lifesaver, man. The archipelago map works perfectly. :-D However, I had some trouble converting the Terra map script. The options still would not appear in the menu after making your corrections. After comparing the two versions, I noticed that Archipelago had two more lines of code after 303 where you told me to insert the 'darwin' bit. Namely,

Code:
def getDescription():
	return 'Sto_Archipelago_2_99'

I pasted that into the Terra script at the same place and replaced it with the correct name. Then, voila! The menu options appeared! Only one problem, though... the scroll bar doesn't go down far enough to reveal all of the dropdown menus. So, there are several more options to change, but I can't scroll down far enough to see them. Is there a way to fix that? The map still loads just fine, but it'd be nice to have access to those other options. Thanks again!

[EDIT]
I restarted the program and selected the Terra map again, and the scroll bar went all the way down. Problem solved. *shrug*
 
Here's a modified version of the Sto_Archipelago_2_99 script that doesn't generate any Python errors. I had to change the tile sorting routines, as they were using Python 2.4 functions, and the current OS X Python is version 2.3. I *think* the changes I've made will do what was intended, but you would have to check it out in practice. The older sort routines will be slower, though, so please be patient when building big maps.

I imagine the same or similar problems exist in the other scripts as well.

I've renamed the file, as recommended by the originator.
 

Attachments

  • Sto_Archipelago_Mac_2_99.py.zip
    41.6 KB · Views: 156
Ok, that sounds good. I haven't gotten any Python errors so far, but it's good to know I have the backup. If I want to transfer your changes to the other scripts in the set, how do I go about doing that?
 
You won't see these Python errors unless you enable error logging. It just fails when it runs the final stage of map generation, so some stuff about resource distribution and so on may not be done properly.

I just had a look at the Terra script. The exact same changes are all that's strictly required as far as I can tell. I've run it, error-free, but I'm no expert, so I don't know if it's doing what it's supposed to.

The extra changes are in the afterGeneration(): function:

at line 1341 in the Archipelago script , 1491 in the Terra script, comment out the itemgetter() calls and insert three functions in their place, to look like:

Code:
#        getcount0=operator.itemgetter(0)
#        getcount1=operator.itemgetter(1)
#        getcount2=operator.itemgetter(2)
        def cmp0(x,y):
                return cmp(x[0],y[0])
        def cmp1(x,y):
                return cmp(x[1],y[1])
        def cmp2(x,y):
                return cmp(x[2],y[2])

Then at line 1388 in archipelago, 1538 in Terra, change all the sorted() calls to sort() calls, as follows:

Code:
                                if buffbonusexttp!=[]:
                                        if hill and Flatlands :
                                                buffbonusexttp=[(item[0],item[1],(item[2]+1)%2,item[3]) for item in buffbonusexttp]
                                                buffbonusexttp.sort(cmp2)
                                                if not featured:
                                                        buffbonusexttp.sort(cmp0)
                                                        buffbonusexttp.sort(cmp1)
                                                else:
                                                        buff1=[item for item in buffbonusexttp if item[1]==0]
                                                        buff2=[item for item in buffbonusexttp if not item in buff1]
                                                        if buff1!=[]:buff1.sort(cmp0)
                                                        if buff2!=[]:buff2.sort(cmp0)
                                                        buffbonusexttp=buff2+buff1
                                        elif hill:
                                                if not featured:
                                                        buffbonusexttp.sort(cmp0)
                                                        buffbonusexttp.sort(cmp1)
                                                else:
                                                        buff1=[item for item in buffbonusexttp if item[1]==0]
                                                        buff2=[item for item in buffbonusexttp if not item in buff1]
                                                        if buff1!=[]:buff1.sort(cmp0)
                                                        if buff2!=[]:buff2.sort(cmp0)
                                                        buffbonusexttp=buff2+buff1
                                                buffhilltp=[item for item in buffbonusexttp if item[2]==1]
                                                buffnohilltp=[item for item in buffbonusexttp if not item in buffhilltp]
                                                buffbonusexttp=buffhilltp+buffnohilltp
                                        else:
                                                if not featured:
                                                        buffbonusexttp.sort(cmp0)
                                                        buffbonusexttp.sort(cmp1)
                                                else:
                                                        buff1=[item for item in buffbonusexttp if item[1]==0]
                                                        buff2=[item for item in buffbonusexttp if not item in buff1]
                                                        if buff1!=[]:buff1.sort(cmp0)
                                                        if buff2!=[]:buff2.sort(cmp0)
                                                        buffbonusexttp=buff2+buff1
                                                buffbonusexttp.sort(cmp2)
                                        buffbonusext=[item[3] for item in buffbonusexttp]
                                        bbonusextend[i]=[list(bonusplacs[i][0]),list(buffbonusext)]
With luck, the same changes may get the rest of those scripts running. The best tool to use is BBEdit, which can show you all the differences between two files. And you need to enable Python error logging and check the PythonErr.log file in Civ4 Warlords/Logs/ each time you try a change. It should be empty.

You may want to change the file name as recommended in the file, and then you need to change the same string where it appears in the text.
 
Thank you, thank you. :) That will help a lot. One final, minor question will probably put this thread to rest. As I've been playing some maps using the revised scripts, particularly Huge Terra maps, I've noticed that the barbarians are exceptionally numerous and animals still spawn in unusually large numbers, despite the settings for that being set to the lowest or none. Is raging barbarians automatically set with these map scripts? The only thing that stops them is checking the "No Barbarians" box. Can I edit this somewhere in the script?
 
I recommend you discuss that with the script originator.

It's possible that the changes I've made are incorrect, of course, in which case I apologise :blush:, but it would surprise me if they specifically affected barbs.
 
Thanks :) , for all this work !

I will try to make a compatible version of the scripts for MAC and post a test file here .

Actually , i search a way to know if you're running a MAC or Windows version . I will surely try with a "Try: Exept:" .

I will change the part with operator . ( I was about to rewrite the script all with operator :lol: )

For the trait part , there is no problem if you don't play with a mod with The Lopez Scriptable trait : the script test it before adding the options for changing the traits .


Tcho !
 
[PS] Here is the Terra script I modded. It works without Python errors.

It's just possible that the barbs and animals are controlled from the modded CvGameCoreDLL file. If that is the case then this aspect of the maps will fail on a Mac.
 

Attachments

  • Sto_Terra_Mac_2_99.py.zip
    41.9 KB · Views: 182
For the barbarian part , i reply into the "full of resources" thread

In fact , i don't touch anything into barbarian settings ... the default "raging" setting has nothing to do with the map scripts .
With the scripts , you have the choice of addind barbarian cities and animals at the beginning of the game . But i don't change the Civ IV barbarian settings . They are just added .
The percent of barbarian cities is just : "the number of city placed"/"the number of maximum cities possible to place , according with some settings"
The percent of animals is the percent of avaible land ( excluding city radius and starting location ) where to place an animal .

For info , the dll you can download into the "full of resources" thread is just a compilation of The Lopez's Scriptable Trait and no more . It's just made for players that do not play with MOD or SDK MOD . There is no other addition .

Tcho !
 
Thanks, man. Much appreciated. I thought I edited the Terra script as you indicated, but it made my computer crash again (but the menu options did show up!). So, I was in the process of trying to figure out where I messed up when I saw your post, haha. As for the barbarian issue, we have been hosting the original script on a PC for many games, now, with the same issue. I don't think that the platform is the issue. I hoped it was a blip in the script that somehow disabled the safety, so to speak, in the core game files, but since neither you nor Sto can find anything wrong in there, we may just be SOL. I think we've agreed to turn off the barbarians completely next game. For one thing, we've never seen so many animals immediately after starting, at least not on Noble or Warlord difficulty. For another, it's just too much trouble for each player to hunt down barbarian cities near his captial (two, in my case) that keep pumping out archers and axemen on turn 80 on Warlord difficulty, then spawning yet another city 10 turns later. (I exaggerate, but not a lot.) Even the AI civs seemed to be suffering. And on the script options, we turned barbarian cities to "none" and animals to "2%". All we know is something's got to be off. Well, I'm off to do some playtesting and get some lunch.

Ja mata ne!
 
Thanks, man. Much appreciated. I thought I edited the Terra script as you indicated, but it made my computer crash again (but the menu options did show up!). So, I was in the process of trying to figure out where I messed up when I saw your post, haha. As for the barbarian issue, we have been hosting the original script on a PC for many games, now, with the same issue. I don't think that the platform is the issue. I hoped it was a blip in the script that somehow disabled the safety, so to speak, in the core game files, but since neither you nor Sto can find anything wrong in there, we may just be SOL. I think we've agreed to turn off the barbarians completely next game. For one thing, we've never seen so many animals immediately after starting, at least not on Noble or Warlord difficulty. For another, it's just too much trouble for each player to hunt down barbarian cities near his captial (two, in my case) that keep pumping out archers and axemen on turn 80 on Warlord difficulty, then spawning yet another city 10 turns later. (I exaggerate, but not a lot.) Even the AI civs seemed to be suffering. And on the script options, we turned barbarian cities to "none" and animals to "2%". All we know is something's got to be off. Well, I'm off to do some playtesting and get some lunch.

Ja mata ne!


For the barbarian part ... you have the option to add many barbarians at the beginning of the game . But , even if i've added some few starting units for AI_Players , you should add some additionnal defensive units , a copper and bronze working for all players . In fact , it's up to you to find a good gameplay (as i can't evaluate this in function of the MOD and map you play ) . I will add a note into the thread to clarify this . :)

Tcho !
 
Thanks :) , for all this work !
Thanks for picking it up :)

I will try to make a compatible version of the scripts for MAC and post a test file here .

Actually , i search a way to know if you're running a MAC or Windows version . I will surely try with a "Try: Exept:" .

You can use "if sys.platform == 'darwin':" as a test for Mac OS X. I used that in one place to deal with the set() problem.

Note that there is a new version of Mac OS X coming early next year, and I expect it is very likely to include Python 2.4. So it may be better to test for the existence of the 2.4 functions explicitly, rather than just looking for OS X, then the 2.4 code will be used as soon as OS X has it.

I will change the part with operator . ( I was about to rewrite the script all with operator :lol: )
operator is defined in Python 2.3, but not operator.itemgetter().
 
You can use "if sys.platform == 'darwin':" as a test for Mac OS X. I used that in one place to deal with the set() problem.

Note that there is a new version of Mac OS X coming early next year, and I expect it is very likely to include Python 2.4. So it may be better to test for the existence of the 2.4 functions explicitly, rather than just looking for OS X, then the 2.4 code will be used as soon as OS X has it.

operator is defined in Python 2.3, but not operator.itemgetter().


Thanks for all ! I think i will be able to post a Mac compatible version soon with your code . Just one or two little things else to upgrade .

Tcho !
 
Top Bottom