View Full Version : Map Script Compatibility with Mac Warlords


Grimvisage
Dec 27, 2006, 11:48 AM
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: (http://forums.civfanatics.com/showthread.php?t=151629) :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: (http://forums.civfanatics.com/showthread.php?t=151629) :( No options, generates grassland-only map.

Tectonics: (http://forums.civfanatics.com/showthread.php?t=149278) :( "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: (http://forums.civfanatics.com/showthread.php?t=152833) :) 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: (http://forums.civfanatics.com/showthread.php?t=184377) :) Seems to work perfectly! (not thoroughly playtested)

SmartMap: (http://forums.civfanatics.com/showthread.php?t=184377) :( No options in the Custom Game menu, generates grassland-only maps. Shame, too, because this script looks incredibly promising.

Fertile: (http://forums.civfanatics.com/showthread.php?t=155283) :) Works perfectly!

Fair Continents: (http://forums.civfanatics.com/showthread.php?t=153558) :( No options, grassland-only maps.


Snaky Pangaea and Grainy Pangaea: (http://forums.civfanatics.com/showthread.php?t=170024) :) and :) Both work perfectly! (And, IMHO, excellent map concepts!)

Chess: (http://forums.civfanatics.com/showthread.php?t=160090) :( No menu options, generates grassland-only maps.

Grid: (http://forums.civfanatics.com/showthread.php?t=154219) :) Menu options appear, but have odd names, e.g. "TXT_KEY_MAP_SCRIPT_OCEAN". Otherwise, works correctly. (not thoroughly playtested)

Life script: (http://forums.civfanatics.com/showthread.php?t=143946) :) Seems to work perfectly! (not thoroughly playtested)


Sansimap: (http://forums.civfanatics.com/showthread.php?t=143727) :) 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!

AlanH
Dec 27, 2006, 12:34 PM
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:


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\\Expl orer\\Shell Folders","Personal")
civFolder = os.path.basename(regRead(_winreg.HKEY_LOCAL_MACHIN E,"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


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.

Grimvisage
Dec 27, 2006, 01:44 PM
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?

AlanH
Dec 27, 2006, 02:10 PM
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.

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.

Grimvisage
Dec 27, 2006, 03:11 PM
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!

AlanH
Dec 27, 2006, 03:49 PM
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:

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

AlanH
Dec 27, 2006, 04:19 PM
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.

Grimvisage
Dec 27, 2006, 04:27 PM
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,


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*

AlanH
Dec 27, 2006, 07:10 PM
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.

Grimvisage
Dec 27, 2006, 07:51 PM
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?

AlanH
Dec 27, 2006, 09:01 PM
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:


# 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:


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.

Grimvisage
Dec 27, 2006, 09:45 PM
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?

AlanH
Dec 28, 2006, 05:55 AM
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.

Sto
Dec 28, 2006, 10:21 AM
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 !

AlanH
Dec 28, 2006, 10:24 AM
[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.

Sto
Dec 28, 2006, 11:10 AM
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 !

Grimvisage
Dec 28, 2006, 11:20 AM
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!

Sto
Dec 28, 2006, 11:30 AM
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 !

AlanH
Dec 28, 2006, 12:59 PM
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().

Sto
Dec 28, 2006, 01:07 PM
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 !

Sto
Jan 06, 2007, 02:01 PM
I've finished a version of the script that should be Mac compatible . Here (http://forums.civfanatics.com/showthread.php?t=151629)

If someone can tell me if that's work ( for single player and multiplayer with windows players also ?) , that would be great ! :)

Big thanks to AlanH for this adaptation !

Tcho !

AlanH
Jan 06, 2007, 04:36 PM
I just loaded the scripts up in Warlords for Mac and opened the Custom Game options for each. where the map options loaded up OK, I launched a game, but only with one set of options, so I didn't check that the different options are all operational.

Here are the results:

Archipelago: OK
Chess: OK
Continents: OK
Custom Continents: OK, but I got the following error when I hit Escape and Exit to Main Menu:

Traceback (most recent call last):

File "Sto_Custom_Continents_2_991", line 4008, in getCustomMapOptionDescAt

TypeError: list indices must be integers
ERR: Python function getCustomMapOptionDescAt failed, module Sto_Custom_Continents_2_991


Fractal Crash to Desktop. Python error log:

Traceback (most recent call last):

File "Sto_Fractal_2_991", line 3202, in getCustomMapOptionDescAt

TypeError: list indices must be integers
ERR: Python function getCustomMapOptionDescAt failed, module Sto_Fractal_2_991

Hub: OK
Lakes: OK
Pangaea: OK
Terra Crash to desktop. Python error log:

Traceback (most recent call last):

File "Sto_Terra_2_991", line 3626, in getCustomMapOptionDescAt

TypeError: list indices must be integers
ERR: Python function getCustomMapOptionDescAt failed, module Sto_Terra_2_991


I haven't investigated further. Please let me know if you need any more debugging data.

Sto
Jan 06, 2007, 04:50 PM
Thanks for all ... i don't undersstand yet what is the problem since i've tested every map and all seems to work with windows . I will check that soon to see is there is something in common or if this is simply a bug .

Tcho !

AlanH
Jan 06, 2007, 05:00 PM
It looks like a single problem to me. Presumably the first argument to the function getCustomMapOptionDescAt() is not being passed, or is invalid. Maybe Windows survives this and the Mac Python v2.3 fails.

I've just tried a retest with Fractal, and it didn't crash! So I'm afraid it appears to be intermittent.

Sto
Jan 06, 2007, 05:19 PM
this is all in :

ibutret=idbutton[iOption]


idbutton is recognized as a list so no problem with it . it seems that iOption is invalid .

Can you add this line in "def getNumCustomMapOptionValues(argsList)" :

[iOption] = argsList
print " iOption : "+repr(argsList)


and check when you have the bug ?


Edit : Very important detail : Something else, the errors occure only when you launch the map , during map generation ?? if yes , can you tell me what the previous function where i call "getNumCustomMapOptionValues"

... I've just check if this can be an encoding error ( thinking of that because not occur every time , but this seems not to make bug with all languages and windows ) .

Tcho !

edit : Sto_terra_2_991 is very close to the one you post in this thread ... just the test added between MAC / Windows

AlanH
Jan 06, 2007, 05:55 PM
The errors occur when I select the map type in the Custom Game options screen. But, as I said above, it's intermittent. I tried editing the Fractal map script to add your debug print line and it didn't fail. I selected another of your map types and it was still OK. I selected your Hub script, which was OK before, and it crashed with the same error.

I'm going to do some more testing, checking to see if it happens with standard scripts as well. If so, I may have to reinstall the software. I don't want to send you on a wild goose chase if it's my system that's corrupt.

Sto
Jan 06, 2007, 06:03 PM
If this occur when you select the map , arglist is send by civ IV ... so that's wreid . Do you select some option with the default <random> option ... but i don't think there is a diferrence with windows that's stupid !

I'm curious to know what iOption cause this problem .

Tcho!

AlanH
Jan 06, 2007, 06:37 PM
I tried about twenty or thirty selections of the various standard map scripts, and it didn't crash. I then tried the Sto scripts, and by switching between them a few times I was able to reproduce the crash.

I edited two of the scripts (Fractal and Continents) to add the debug print command as requested. I also deleted the Sto_Maps_DefaultMapOptions.cfg file, just in case this was corrupted, and then ran again. This time I switched between the two edited scripts, and it crashed after a few changes of script selection. The error was the same as above:


Traceback (most recent call last):

File "Sto_Fractal_2_991", line 3203, in getCustomMapOptionDescAt

TypeError: list indices must be integers
ERR: Python function getCustomMapOptionDescAt failed, module Sto_Fractal_2_991


Attached is the PythonDbg.log file from this run. It's too long to include inline the post.

I notice that it only gets as far as iOption = 59 in the last sequence. I think this is simply because the debug log was not flushed to disk before the crash. The crash report from the application gives the following stack trace indicating that the crash occurred in Python while it was writing error info out:


Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000000

Thread 0 Crashed:
0 <<00000000>> 0x00000000 0 + 0
1 org.python.python 0x97e1adf1 PySys_WriteStderr + 333
2 org.python.python 0x97dca6b7 PyDict_New + 1220
3 org.python.python 0x97dcaa88 PyDict_SetItem + 219
4 org.python.python 0x97dccb39 PyDict_SetItemString + 68
5 org.python.python 0x97e19780 PySys_SetObject + 90
6 org.python.python 0x97e17bd5 PyErr_PrintEx + 164
7 org.python.python 0x97e17e25 PyErr_Print + 18
8 com.aspyr.civ4warlords 0x0054fd04 FPythonMgr::CheckForPythonError() + 20
9 com.aspyr.civ4warlords 0x0055155a FPythonMgr::ICallFunction(_object*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, _object*, _object**) const + 132
10 com.aspyr.civ4warlords 0x00551688 FPythonMgr::ICallFunction(_object*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, _object*, FStringW*) const + 58
11 com.aspyr.civ4warlords 0x005519a7 FPythonMgr::CallFunction(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, _object*, FStringW*) const + 175
12 com.aspyr.civ4warlords 0x000ee4eb CyPythonMgr::callFunction(FStringA const&, FStringA const&, void*, FStringW*) + 177
13 com.aspyr.civ4warlords 0x00149669 CvStagingScreen::refreshCustomMapOptions() + 1061
14 com.aspyr.civ4warlords 0x0014890b CvStagingScreen::handleGameSettingsMessage(NetInit Info*) + 427
15 com.aspyr.civ4warlords 0x001485c5 CvStagingScreen::handleNetMessage(FNetMessage*) + 435
16 com.aspyr.civ4warlords 0x0014373b CvMenuManager::handleNetworkMessages() + 77
17 com.aspyr.civ4warlords 0x00143779 CvMenuManager::update() + 19
18 com.aspyr.civ4warlords 0x00144eea CvMenuManager::setupGame() + 1562
19 com.aspyr.civ4warlords 0x0006462f CvApp::InitGame() + 3045
20 com.aspyr.civ4warlords 0x0005f612 CvApp::Init(HINSTANCE__*, char const*) + 1814
21 com.aspyr.civ4warlords 0x000f185f WinMain + 33

Sto
Jan 06, 2007, 07:23 PM
Pfff ... i don't understand the second part . But with the log file , the map is well initializated at least one time . Perhaps should you make a test only with your terra_script to see if a problem occure , and remove the new maps . I've not change a lot of thing : only that :

if (sys.platform == 'darwin'):
import sets
def set(arg):
return sets.Set(arg)
else:
import _winreg


uncomment :

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


def civFilePath():
if (sys.platform == 'darwin'):
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 ""
else:
try:
userFolder = regRead(_winreg.HKEY_CURRENT_USER,"Software\\Microsoft\\Windows\\CurrentVersion\\Expl orer\\Shell Folders","Personal")
civFolder = os.path.basename(regRead(_winreg.HKEY_LOCAL_MACHIN E,"Software\\Firaxis Games\\Sid Meier's Civilization 4","INSTALLDIR"))
finalFolder = os.path.join(os.path.join(userFolder, "My Games"), civFolder)
return finalFolder
except:
return ""



If the old map work perfectly , i will make a second file like your terra_script to see if the problem occure from the multiple map . Else I will upload 2 version Mac / Windows

Tcho!

Sto
Jan 06, 2007, 07:30 PM
Here a second map script like your terra script . Exept the changes in the previous post and the changes into the afterGeneration() , there is nothing else ?

Tcho !

AlanH
Jan 06, 2007, 08:10 PM
I think this is a bug in Python. I can make it happen by changing selected map script using the version I had before, so it isn't anything to do with the way you have implemented the changes for the Mac.

Sto
Jan 06, 2007, 08:26 PM
Thanks for all :) . So i will let the map scripts like this , since i can't find the problem ... and you are surely a very good python programmer , so if you can't found what can cause the problem , i don't know what to rewrite . A little last question , did the bug occure one time when you start civ4 , and select a map ( with a previous sto map intialized ) ? ( i know it's impossible to test that , but perhaps you've noticed if the bug occure everytimes when you multiselect a map more than 2 times ) . if yes , i can post a note to explain that you must restart civ4 everytime you launch a map for Mac . If not , i will explain that there is a problem and that the scripts don't work all time .

A little more thing , if you play with these scripts and notice the same bug when generating the map , please tell me ... that could be a track , since i also call this function in beforeGeneration() .

Tcho !

Sto
Jan 06, 2007, 08:51 PM
A little idea . Perhaps you can have the iOption passed on value using :

sys.stdout.write(" iOption : "+repr(arglist)+"\n")

instead of print ?

In fact , when reading the log file again ... there is a big problem , you should not be able to read the map any one time because if you have tested "print repr(arglist)" :

there should be a list like : (0,0) ; (0,1) etc and there is (0,) ; (1,) ; (2,) ... i think about that because i was thinking to replace iOption with a global variable and notice that there is no iSelection ... more than wreid that you can get a map any one time .

Tcho !

AlanH
Jan 06, 2007, 09:04 PM
I'll maybe have a look at that, but I don't like the fact that it's intermittent. I feel that makes it a low level system error in the Python interpreter, not one that can be fixed in the application level code.

Yes, I think the problem has generally occurred after a Sto map has already been initialised. But it would be very inconvenient to have to quit each time you change the map script selection.

BTW I'm not really a Python programmer at all. :)

Sto
Jan 06, 2007, 09:10 PM
there should be a list like : (0,0) ; (0,1) etc and there is (0,) ; (1,) ; (2,) ... i think about that because i was thinking to replace iOption with a global variable and notice that there is no iSelection ... more than wreid that you can get a map any one time .

If fact , the log file stop at getNumCustomMapOptionValues() ... :blush:

Edit : i will let the scripts like this for the moment . But even if there is a low system error ( not of my understanding ) , i will try to rewrite the script using a global value to replace arglist .

Sto
Jan 06, 2007, 09:31 PM
Do you think that using a special encoding for the script may cause the problem ? I will also make a test file tomorrow removing all non english langages and :

# -*- coding: iso-8859-1 -*-


Tcho !

AlanH
Jan 06, 2007, 09:37 PM
I just tried a different experiment. I changed fdebug() to return False in the Sto_Fractal map, so that it would not output any debug text. I then switched between the Sto_Fractal map and the other standard map types. I was very careful to avoid selecting any other Sto script, although there are a couple of others in teh PublicMaps folder. After several menu changes the software crashed. And the PythonErr.log listing showed output from the Sto_Terra script. So it seems the Terra script is being called even if I don't select that script?

EDIT. Ignore that. I need to do the test again :blush:

Correction. The error still occurred in the Sto_Fractal script at the same place. I need to suppress the other print operations as well, I guess.

AlanH
Jan 06, 2007, 09:52 PM
I'm a bit confused about the indenting in your code. I thought Python needed consistent indenting, but I see some lines indented with four spaces and others with eight - for example:


def getNumCustomMapOptionValues(argsList):
global language
global listressmenu
global listunitsmenu
global listtechsmenu
global listtraitsmenu
idbutton=getidbutton()
[iOption] = argsList


Shouldn't all the lines after the function def line be at the same indentation level of eight spaces?

Also, there seem to be a mix of tabs and spaces for indentation. Does Python allow them to be mixed?

Sto
Jan 06, 2007, 11:06 PM
??? No , python don't accept space or different identation if i remember well with my hard beginning . But there is 2 tab = 8 space everywhere . I see no identation with 4 spaces :confused: . when i write code , i don't use tab but keybord shortcut to indent and unindent . And i think this may automaticaly cause a bug on initialization . Do you find some ? In the example , there is 8 spaces = 2 * tab .

edit : yes your right just in the last function there is four space identation . but that do not cause problem . i've seen other script (original with 8 or 16 space identation ) . But the mix of space and tab create a bug i think (not hidden).

Sto
Jan 07, 2007, 12:04 AM
Here a test file where i've removed all non ASCII character and coding . If you can test that after removing all other Sto_scripts ( the codec module is loaded if there is any other sto_scripts ) . This is the only thing i made that is not "" common "" , with a little hope ...

Tcho !

Edit : if this don't work , i will retabify all the script , but i'm almost sure that if there is mistake , that automaticaly create a bug .
Edit : i don't think that the debug tool might be in cause .because the error is clear : this is civ4 that call a bad value entry . So there must be something in initialization that create the bug ... nothing to do with debug !? ??

Sto
Jan 07, 2007, 05:42 AM
I let the file above . But in fact , there is still the problem ... i will recheck the script !

i think the problem can be cause by that -> this the two specific modules that are called when the script is initialized and i try to remove them :

load_module encodings.latin_1
load_module encodings.string_escape


I will check to see for what encodings.string_escape is made for ( i don't know :confused: ) ... i think that when i will achieve to remove , there should be no more problem .

Tcho !

AlanH
Jan 07, 2007, 05:43 AM
I tried the last version you posted. I put it in PublicMaps alone, with no other map scripts.

It crashes repeatably the fifth time I select it. I've repeated this three times, and a few more times trying different indentation methods. It always crashes on the fifth time I select Sto_Fractal_Test. In between the five Sto_Fractal_Test selections I select Archipelago.

Note that this is similar to my first test, when I went though the maps in turn, and it gave an error *after* the fourth map I tried, when I was going back to the main menu from the generated map, and then it crashed when I selected the fifth map script.

I have tried using all tabs and all spaces for indentation, and it made no difference.

The debug log still includes:

load_module encodings.latin_1

The fact that it fails predictably after five initialisations seems to indicate that there is either a memory leak problem in Python - it does its own garbage collection, so this should not be an application coding issue; or maybe some global variable is not being initialised properly, and after five runs it reaches an invalid value.

Sto
Jan 07, 2007, 05:48 AM
Ok , i will try to remove the encoding problem first -> then check all globals ( check if there are list or python bound function ) .

And i will post a file after i can reach that !

Tcho !

Sto
Jan 07, 2007, 07:16 AM
For "load_module encodings.latin_1" , i've understood that it's called when i get description of resources , etc for the menu listing ... i need probably to use unicode or something like that (i don't understand encoding problems) and that's a ton of work . that will not be ready soon . So i decide to force the import into the script instead of letting civ4 do it .

For "load_module encodings.string_escape" , it's called between two functions ( getNumCustomMapOptions() and getNumCustomMapOptionValues()) . And i don't understand what this module is made for ( i'm not very good in english , especially programming vocabulary . And i found no good french python documentation ) ... So i also decide to force the import into the script instead of letting civ4 do it .

So , i post a test file with all global values rewritten . That can be a good test to see if the problem comes from global values !?

Tcho !

AlanH
Jan 07, 2007, 08:44 AM
It still crashes the same after five cycles, swapping between the Sto_Fractal_Test map and the standard Archipelago map. I have no other maps installed.

encodings.latin_1 is not loaded now, but encodings.string_escape is still loaded.

Have you tried this same test on a PC?

Sto
Jan 07, 2007, 08:57 AM
I had not check it , because i was always test every map in a loop withoup any problems ... but now as you said, i've just made a test and get the same error after 20 switch ... So i'm terribly sorry to have borrowed you because there is the same bug with windows . :blush: :blush: :blush: :blush: :blush: :blush:

But I will rewrite all the scripts without description or another language . I can't do anything else . But i think the problem will still not be solved probably ... that must be something with memory allocation or size ( probably because i get the bug many times after you , and never get it before ).

Thanks for all , and i apologize for all this wasted time :blush:

Tcho !

AlanH
Jan 07, 2007, 09:21 AM
No problem. It's all good fun :). And if it takes four times as long to trigger the problem in Windows, then it may not be a real problem for PC users. Presumably no one has complained before.

It might be a good idea to work out how your text editor is mixing up the spaces and tabs, though. Just to eliminate any lingering doubt on that issue.

Sto
Jan 07, 2007, 09:27 AM
No , i've never got any feed back on this bug ( there is not a lot of player with my scripts ) ... I will still test a script without encoding , but i have no hope . I add a note to clarify this in the thread .

Thanks again , tcho ! :)

Sto
Jan 08, 2007, 11:34 AM
For infos , the problem is solved : there is no solution !

First , i try to understand why there is "load_module encodings.string_escape" . this is a special module that translate special character like "\n" and "\\" used into path strings . As i took the function to smart map , i try to get the bug without success with smart map. then remove all special character from my script and also get the bug .

Second , i test this file . I simply add that to the original fractal map :

def getNumCustomMapOptions():
return 90

def getCustomMapOptionName(argsList):
return unicode(CyTranslator().getText("TXT_KEY_MAP_SCRIPT_LANDMASS_TYPE", ()))

def getNumCustomMapOptionValues(argsList):
return 80

def getCustomMapOptionDescAt(argsList):
return unicode(CyTranslator().getText("TXT_KEY_MAP_SCRIPT_SNAKY_CONTINENTS", ()))

def getCustomMapOptionDefault(argsList):
return 40


And i get the bug , ( any other sto_script removed before ) ... So there is no ambiguity , civ4 is not made to load a map with many buttons and selections .

Tcho !

Edit : why didn't i begin by doing that :crazyeye:

AlanH
Jan 08, 2007, 03:37 PM
Well done :goodjob: I wonder what limit you're hitting in Civ4 with this level of complexity ... It might be worth asking Firaxis what the limits are.

Sto
Jan 09, 2007, 04:04 AM
It might be worth asking Firaxis what the limits are.

Thanks , Great idea :) , I'm curious to know the limit . I remember that the game crash if there is 100 buttons or more , but perhaps there is a way to remove the bug if i know the limit .

Do you know where to contact Firaxis for this kind of questions ? ( i've searched and hesistate to ask at <support> , this is the only thing i've found )

Tcho !

AlanH
Jan 09, 2007, 04:24 AM
You could try a PM to Sirian (Bob Thomas) (http://forums.civfanatics.com/member.php?u=8083). He is with Firaxis and wrote a lot of the original map scripts. He also wrote the map reference (http://forums.civfanatics.com/showthread.php?t=134226) in the C&C forum.

Sto
Jan 09, 2007, 04:27 AM
Thanks , i'll do that now ! :)

Sto
Jan 10, 2007, 08:30 AM
For infos , Sirian can't help ... So i tried to get the limit of the number of button and selection you can have -> there is no limit . Whatever the number of buttons you have , they should be saved somewhere (or because of an incrementation ) , after a number of time you load a script with any number of buttons the game crash . I get the bug with smartmap ( 15 buttons , after selecting it about 140 times ) . By making many tests , it seems to have a limit of the number of buttons you can load by launch of civ IV ( looks like : (nbButtons^0.8) * const ) .

Tcho !

Edit : replace nbButtons^1.2 by nbButtons^0.8

Edit : It seems that waiting between selection change the max number of time you can select a script ... but i get the bug even after waiting 10 min between two selection .

gidds
Mar 07, 2007, 09:29 AM
[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.

Just downloades and tried the thingy, works well as far as I can see, and boy, will this change experience of playing the game (finally). And yeah, I completely overlooked these (as the reason why reacting now). And AlanH....U did it again...(oops).

Maybe make this one a sticky so that people can find it easier?

Sto
Mar 09, 2007, 08:13 AM
All changes made by AlanH for Mac compatibility has been included in these scripts (http://forums.civfanatics.com/showthread.php?t=151629) . there is most of public maps generator in customized .

Tcho ! :)

gidds
Mar 09, 2007, 08:51 AM
All changes made by AlanH for Mac compatibility has been included in these scripts (http://forums.civfanatics.com/showthread.php?t=151629) . there is most of public maps generator in customized .

Tcho ! :)

Merci beaucoup!

:D :D

Nercury
Aug 05, 2007, 07:56 PM
PlanetGenerator now should be compatible with mac too: http://forums.civfanatics.com/showthread.php?t=180995

However, it will not remember your settings.

AlanH
Aug 06, 2007, 06:21 AM
Well done ... thanks for supporting the Civ-underdogs :)

I had a look at the script, and I *think* the modified version I've attached here ought to work on both Mac and Windows, including saving settings. I have only changed the Windows registry stuff a little, so I don't think it should be broken, but I can't test it as I don't have Civ4 for Windows. If it works, this will remove the need to maintain two versions.

Nercury
Aug 06, 2007, 12:46 PM
Great, I will install Civ4 in Vista and will check that out too (I am worried about the way Vista user profiles differ from XP). I also had somewhere 0.45 version with working oasis support, but haven't released it yet, so I am hoping to dig that out too :).

Also, I think a have made quite efficient engine here for writing map scripts, so if anyone is interested on building something new on top of it, I can help with documentation.

AlanH
Aug 06, 2007, 02:35 PM
Apologies. I should have named it a distinct version to avoid your number sequence, as you will no doubt have a real 0.45 in due course.

My changes were simply to make the Windows user directory path code conditional, depending on the sys.platform value, and to provide a Mac version. Then I used os.path.join() to define the settings file path name, removing the dreaded backslashes. So this ought to provide a Mac version of your map scripts engine as well.

Nercury
Aug 06, 2007, 03:02 PM
No problem, I can make it 0.46 easily.

So, if I understand it properly from code, you have made it to remember settings on mac too?

By the way, what "._Planet_Generator_0_45.py" file does? I found it in archive.

AlanH
Aug 06, 2007, 03:23 PM
So, if I understand it properly from code, you have made it to remember settings on mac too?

I haven't tested it thoroughly, but all I did was to fix the two lines that define the settings file path code to create a valid file in the user's Civ4 or Warlords directory. It creates a file containing what look like settings, and I guess it would read it back.


By the way, what "._Planet_Generator_0_45.py" file does? I found it in archive
I think it contains Mac OS X metadata - file creator and type information. You should be able to ignore it. I must remember to use a compressor that I can tell not to do that.

Nercury
Aug 06, 2007, 04:37 PM
Well then, it would be nice if someone using mac could test it, just to make sure. All what is needed is to start custom game with at least one of the settings changed, and then check if script remembers them.

Thank you for help.

AlanH
Aug 06, 2007, 06:27 PM
I've done that, and it worked. I changed all the settings away from defaults, started a game, quit, then relaunched. The settings were all as I left them.

Nercury
Aug 06, 2007, 11:52 PM
I merged my new version with your version, also added some code to handle crude jungle/desert transition better. Version now is 0.47, it's here: http://forums.civfanatics.com/showthread.php?t=180995

AlanH
Aug 07, 2007, 04:20 AM
That version still works OK on my Mac. :goodjob:

I notice the version string in the script is '0.46', so the settings file name is 'planet_generator_0_46.cfg'.

Nercury
Aug 07, 2007, 07:43 AM
Yeah, I ussually don't change file name if it is compatible with previous version.