AnotherPacifist
Deity
- Joined
- Sep 21, 2007
- Messages
- 4,878
Shame on me, but I still haven't tried it yet. But for Russia's UP, have you taken into account barbs and independents (which may not necessarily show up as war "officially")?
Actually, I realized that there's no way to check if you are at war with someone without looping through every civ and checking them independantly, so there goes that suggestion.Shame on me, but I still haven't tried it yet. But for Russia's UP, have you taken into account barbs and independents (which may not necessarily show up as war "officially")?
The slowness is still felt in the normal RFC though, but at least from what I've noticed, my changes helped.Update!
I found more files that could use this optimization. I've also done a couple other small things that I'm not going to try to explain.Again, this is for BTS only, other version will come soon, don't worry.
![]()

import pickle
import cPickle as pickle


#Vikings
(( "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", ),
( "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", ),
( "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "Narvik", "Hammerfest", "Hammerfest", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", "-1", ),
Here's what I turned that section into:11: { 28: {47: 'Fort Casimir', 48: 'Fort Kristina'},
29: {47: 'Älfsborg', 48: 'Uppland', 49: 'Torne'},
30: { 47: 'Fort Christina',
48: 'Nya Korsholm',
49: 'Norumbega',
50: 'Norumbega'},
31: {49: 'Norumbega', 50: 'Norumbega'},
32: {37: 'Sankt Thomas', 55: 'Markland', 56: 'Markland'},
33: {56: 'Markland'},
Plus, I don't know how much Python you know, so I don't have a good starting point.
These things probably won't actually help with teaching you how to mod, but these things are good practices when trying to make a fast and efficient mod. For example, why store every plot when you can only store the ones needed? Also, the links I scattered around the post are great references; this is a great Python tutorial (that's where I learned it).
If you have any questions, or you want me to start you out with a "modding tutorial" or something, feel free to PM me. I've had a lot of free time lately. 
Oh, I did? My bad, yes you may change it.on the AI wars you have changed the grid like you showed, but left it with "import pickle" rather than "import cpickle as pickle" like the other files, is this deliberate or can I change it?
That was me.Somebody suggested using dictionaries before, I forget why it wasn't implemented. Maybe Rhye concluded it wouldn't make that much of a difference.
Yeah he didn't think it was worth the work. Although I personally think it's much easier to maintain (just add the coordinates)...but maybe that's just me.Good, I'm glad.Thanks Musicfreak, that was a very helpful tutorial as I prefer to implement changes myself rather than download them. I currently have very little python knowledge but I completely understood your tutorial.
Thanks.
I was afraid you wouldn't understand any of it, if you just started learning Python, but I'm glad it made sense.Thanks! About marshal...I've tried using it, but I get an EOF error every time...don't know why, but I'm guessing it has something to do with Rhye's change in the way script data is saved. The problem is, if I change it back, I also get an EOF error.Great stuff, musicfreak!
Very informative thread: pickle vs. cPickle (vs. marshal?), tuple vs. dictionairy
I need to figure out what's causing it.Thanks! About marshal...I've tried using it, but I get an EOF error every time...don't know why, but I'm guessing it has something to do with Rhye's change in the way script data is saved. The problem is, if I change it back, I also get an EOF error.I need to figure out what's causing it.
It crashes IDLE but you shouldn't have any problem opening it in a normal text editor.Absolutely amazing work man!![]()
Extra bonus: I can now finally load the CityNameManager, it was too big to load it without a crash.
I've attached some more cPickle files, the game runs even faster now.
All those files are included in my attachment...check the first post.Absolutely amazing work man!![]()
Extra bonus: I can now finally load the CityNameManager, it was too big to load it without a crash.
I've attached some more cPickle files, the game runs even faster now.

Well I think the reason for it is Rhye's change to the way Civ stores script data. The original DLL uses the ReadString and WriteString functions, which should (theoretically) work without problems (although it doesn't seem to play well with RFC). Rhye changed it to a loop that first reads an integer (the size of the string), and then loops through once for every character and uses Read() to read in every character, one at a time. He commented the block as "bugfix", although I'm thinking that's the cause of the bug. However, like I said, when I change it back to how it is in the original DLL (using ReadString), it gives an EOF error no matter what the Python code actually does...I'm not an expert, but usually you get an EOF error when using a wrong loop direction:
while not EOF
take next record
do something
instead of:
do something
take next record
while not EOF
I've encountered this problem a lot over the years in web-scripting. About still having the same error when changing it back: maybe you have to do a fresh restart (clear cache?) of civ, otherwise you get old errors. It's something I noticed when changing Python, while keeping the game open.
For me it took ages to load in any editor with syntax highlighting, and I have a pretty decent computer. I imagine that on a slower one it would just hang. Notepad works fine but I have to have syntax highlighting.It crashes IDLE but you shouldn't have any problem opening it in a normal text editor.
