Requesting following features

Well I'm basically working on stuff relating to Civs dying/respawning right now. I'm gonna try to get all of that squared away during the day tomorrow. I must not forget to wipe out those place-holder units in no-man-land on game start, so that I can disable all setPlayerAlive callbacks on the first turn only (when the game realizes that the rebel players have no cities/units).

What was the "error" you reported from not including those units, by the way? :confused:

Did you ever update the WBS? Because I would like to test the code with the starting location coordinates in place. (Otherwise I'll just add the Rome tile coordinates as the Roman starting location and see if Rome indeed becomes the capital, despite not being the first city to flip.)

If I get the time, I'll also revisit the earlier discussion on the senate missions to see if I can't provide you with a sample Mission class. The rest of the Senate module (or whatever) could then be written by you based on discussion in this or another thread.

How is testing Rebellions going? Are the settings I added as constants enough or do we need to tweak something in the actual code also? I'd like you to be able to do these things yourself anyway, but before I let go of this project altogether we should probably try to work together on the module.
 
I did change the start coordinates and posted them here didn't it?

I am going to do more rebels testing tommorrow!

It is not an error as such but more of a perminant fixture... the units will spawn on their own as they can't be instantly killed... I tried and it didn't work... (I cant remember the exact problem...)

so either your kill off units on the first turn or asaf's adding an alive function...

what about diplo reset? Also is there anything else we needed to do?

I should really get 2.1 sorted ready for tweaking :p But I will get there in time!
 
I did change the start coordinates and posted them here didn't it?
You did? In that case it must just have slipped my mind. I'll look back and see if I can spot it... (If it was bundled up with some other files you could just post it alone.)

I am going to do more rebels testing tommorrow!
I trust that you got what you needed in terms of debugging messages, not?

It is not an error as such but more of a perminant fixture... the units will spawn on their own as they can't be instantly killed... I tried and it didn't work... (I cant remember the exact problem...)
I noticed that you've added starting coordinates for the rebel civs... Why exactly is this? :confused: Could this in fact be the problem?

so either your kill off units on the first turn or asaf's adding an alive function...
I'll actually try to kill the units off before the first turn. How that works well know tomorrow... :p

what about diplo reset? Also is there anything else we needed to do?
This is just the thing I need to verify, but thus long the diplo reset seems to be working. (All I had to do was enable it as intended in the event manager.) But you will have to test everything in actual play-testing once I'm done.
 
if no start coords are set then I beleive it would spawn where ever which we dont want, however I could always try the coordinates of -1, -1... would that work to kill it?

I have what I need debugging wise!

did we decide not to remove the death messages in the end? I'm a little confused today :D
 
did we decide not to remove the death messages in the end? I'm a little confused today :D
I think we should - and if Asaf can diable them in the SDK that would be really convenient for the likes of you or me. :D
 
Yeah, this is also something I'm currently testing. In fact, I'll get to it momentarily and be back with a full report during the day.
 
Ok, I think I got rid of those death-messages by deleting the units on game start. It might not be necessary to edit the SDK after all. :goodjob:

And that means that we don't have to add our own messages either.
 
ok so when you send me the code what will I have?

today i will test my altered calculations for the rebellions
 
It depends. Did you successfully disable the default death messages? In that case I need to include some Python triggered ones...
 
Ok, the attachment includes a new CustomFeatures module with these added/updated features:
  • rebel players are not allowed to raze cities conquered from their former major players, and vice versa
  • rebel players get all previous diplomatic deals canceled on spawn and war is declared on the corresponding major player, while all other states of war are ended
  • a destroyed major player will flip its rebel counterpart if one is present at that time-of-death, city garrisons depending on Techs and a reformed army (according to the rebel units scheme) headed by a Great General are spawned, a Golden Age starts and a end-of-civil-war message is displayed
  • a custom death message is displayed whenever a major player dies - but not when it dies at the hands of a rebel player (see above)
Add this code into CvEventManager:
Code:
	def onGameStart(self, argsList):
		'Called at the start of the game'

		initiateCustomPython()
		[B]Custom.initRebels()[/B]
		Rebellion.setup()
Code:
	def onEndGameTurn(self, argsList):
		'Called at the end of the end of each turn'
		iGameTurn = argsList[0]

		[B]Custom.flipRebelCiv()[/B]
Code:
	def onSetPlayerAlive(self, argsList):
		'Set Player Alive Event'
		iPlayerID = argsList[0]
		bNewValue = argsList[1]
		CvUtil.pyPrint("Player %d's alive status set to: %d" %(iPlayerID, int(bNewValue)))

[B]		if not gc.getGame().isFinalInitialized(): return
		Custom.manageRebels(iPlayerID, bNewValue)[/B]
Code:
def initiateCustomPython():
	if gc.getGame().isFinalInitialized():
		global Powers, Rebellion, Custom, CC
		import Powers, Rebellion, CustomFeatures as Custom, CatapultConstruction as CC
		if not Rebellion.getGlobalScriptDict():
			Rebellion.setup()
		CC.load()
		from CvGameUtils import CvGameUtils
		CvGameUtils.powers = Powers
		[B]CvGameUtils.custom = Custom[/B]
		Custom.gameTurn()
And in CvGameUtils:
Code:
	def canRazeCity(self,argsList):
		iRazingPlayer, pCity = argsList
		[B]return self.custom.rebelRaze(*argsList)[/B]
(It will of course not work if I missed one. In such an event just give me the exception and I'll get back to you with what is missing. Because its all working at my end.)

Note that I added eNums and helper functions directly in the module. You should probably move those the their respective modules, but this is entirely your responsibility. I added comment lines to remind you however. (One import statement should also be moved to Helpers. See line comment.)
 

Attachments

what about catapult construction can we do anything with that yet?
 
Ok, exception...?
Traceback (most recent call last):

File "CvEventInterface", line 23, in onEvent

File "CvEventManager", line 187, in handleEvent

File "CvEventManager", line 335, in onGameStart

File "CvEventManager", line 1153, in initiateCustomPython

File "<string>", line 52, in load_module

File "Powers", line 3, in ?

File "<string>", line 52, in load_module

File "Helpers", line 7, in ?

File "<string>", line 52, in load_module

File "Rebellion", line 58, in ?

NameError: name 'getRandNum' is not defined Edit: getSorenRandNum?

accompanied by this:
Traceback (most recent call last):

File "CvEventInterface", line 23, in onEvent

File "CvEventManager", line 187, in handleEvent

File "CvEventManager", line 318, in onPreSave

NameError: global name 'Rebellion' is not defined Edit: no clue?
ERR: Python function onEvent failed, module CvEventInterface

whats this about? I see no problem just thinking about it...

Edit: while these exceptions are being fixed I was thinking of setting up some diverting code for the affected code using the:
try:
except "add in name"Error:

and when an exception appears the code is diverted and a message is posted in debug which says a "add in name" error has occured
and then I am also looking for a way to have the exception displayed aswell... how does that sound? because that makes it possible for testing to continue!
 
Zip and post your copy of the concerned files: CvEventManager, Rebellion and Helpers. Because your files are clearly not matching mine, but its not entirely clear how exactly. Most likely you lack the getRandNum() function in helpers, which is causing all this mayhem. But the odd thing is that this is happening now.

Well, we'll sort it out.
 
ok I posted here! dont forget to see the edit to above post regarding try and except (I have been reading the textbook by the way and that's where I got too... which brings me to the spoiler)

Spoiler :

I was experimenting with dictionaries today and made this inventory list thing (where you add items to it and how much, delete items etc) like a shop would use to keep track of products... Anyway the dictionaries worked out fine by themselves but when the code ends the data added is deleted :mad: So I thought that if I save the dictionary into a file made each time the program is run (and the dictionary updtaed from the file) it would work... I used IO for this and made a file and tried to add shopping to it (by using shopping which has the program running before so it would look like this in view dictionary: {'apples':3}) it failed and gave me a TypeError (or something) so I used str(inventory) to convert to string and it worked. so I tried to update shopping by reading the file and saying shopping = readfunction (actually is something) and the dictionary could not be updated because it was given a string :rolleyes: So... I used dict(shopping) to convert back and this happened:
ValueError: dictionary update sequence element #0 has length 1; 2 is required
here is code
Spoiler :

Code:
from Dictionaries import *
def program():
    exception()

    f = open("test.py","w")

    f.write(str(shopping))
    f.close()

program()
fo = open("test.py", "r")
read = fo.read()
shopping = read
print shopping
print type(shopping)
exception()
dict(shopping)
print type(shopping)
that is a little complicated at the moment... :rolleyes: just wait for this :D
Code:
def add(x, n, y):
    y[x] = n
def delete(x, y):
    del y[x]
def show(y):
    print y
def change(x, n, y):
    y[x] = n
def new():
    print ""
def menu():
    print "welcome to Dictionaries.py!"
    new()
    print "These are your options:"
    new()
    print "1) Shopping List"
    print "2) Phone Book"
    print "3) Address Book"
    print "4) Quit"
    new()
def submenu(n, x, y = ""):
    print "What would you like to do in", n,"?"
    new()
    print "These are your options:"
    new()
    print "1) View", n
    print "2) Add", x
    print "3) Delete", x
    print "4) Change", x, y
    print "5) Exit", n
    new()
def selection():
    return input("Please select your option: ")
def error():
    print "Invalid Option!"
def program():
    loop = 1
    loop2 = 1
    menu()
    while loop == 1:
        loop2 = 1
        option = selection()
        if option == 1:
            submenu("Shopping List", "Item", "Amount")
            while loop2 == 1:
                choice = selection()
                if choice == 1:
                    show(shopping)
                elif choice == 2:
                    add(input("What is the name of the item?(add within ''): "), input("How much of the item do you have?: "), shopping)
                elif choice == 3:
                    delete(input("What is the name of the item you wish to delete?(add within '', case sensitive!): "), shopping)
                elif choice == 4:
                    change(input("What is the name of the item?(add within ''): "), input("New amount: "), shopping)
                elif choice == 5:
                    print "Returning to main menu!"
                    menu()
                    loop2 = 0
                else:
                    error()
        elif option == 2:
            submenu("Phone Book", "Number")
            while loop2 == 1:
                choice = selection()
                if choice == 1:
                    show(phone)
                elif choice == 2:
                    add(input("Enter person's name(add within ''): "), input("Enter Number (add within '' for numbers starting with 0: "), phone)
                elif choice == 3:
                    delete(input("Who's number would you like to delete?(add within '', case sensitive!): "), phone)
                elif choice == 4:
                    change(input("Enter person's name?(add within ''): "), input("New Number: "), phone)
                elif choice == 5:
                    print "Returning to main menu!"
                    menu()
                    loop2 = 0
                else:
                    error()
        elif option == 3:
            submenu("Address Book", "Address")
            while loop2 == 1:
                choice = selection()
                if choice == 1:
                    show(address)
                elif choice == 2:
                    add(input("Enter person's name(add within ''): "), input("Enter Address: "), address)
                elif choice == 3:
                    delete(input("Who's address would you like to delete?(add within '', case sensitive!): "), address)
                elif choice == 4:
                    change(input("Enter person's name?(add within ''): "), input("New Address: "), address)
                elif choice == 5:
                    print "Returning to main menu!"
                    menu()
                    loop2 = 0
                else:
                    error()
        elif option == 4:
            print "Thanks for using dictionaries.py!"
            loop = 0
        else:
            error()
def exception():
    try:
        program()
    except NameError:
        print "You must use the option number!"
        print "Returning to main menu!"
        exception()
    except SyntaxError:
        print "You must use the option number!"
        print "Returning to main menu!"
        exception()

shopping = {}
phone = {}
address = {}

as you can see the code is run through exception to stop Name and Syntax Errors :D (this is a nice little loop aswell, once you make the mistake it tells you off and then runs itself!) this includes 2 other dictionaires aswell but they are not dealing dealt with yet!"

could you explain what the error is on about and what I am doing wrong?
 

Attachments

You don't need to do your own file IO, you can save data into various objects in the game via their script data. This gets the data into the regular saved game file. The game itself, each player, each city, each plot, and each unit have script data fields.

When saving an object, don't use str(). That just make a human readable description of the object and to convert it back you'd need to write your own parser. What you want is the Python pickle object (I'd suggest using the cPickle module instead of the pickle module, since it is a lot faster) and its pickle.dumps and pickle.loads methods which encode an object as a string and decode a string into an object. This does a process known in general as "serialization", also called "pickling" in Python for obvious reasons, which is converting an object to a string in a specific format that can be reversed to produce an effectively identical object. You can see how this is done in Final Frontier (Plus or not) in the saveSystemsToPlots and loadSystemsFromPlots functions. It uses the plot script data to store the star system data and the game object's script data to store the tutorial data. (The beta merge of FFP with BUG changes it some since BUG itself stores data on the game object, but it's storage mechanism allows you to add data to it's stored data so FFPBUG adds the tutorial data to the BUG data storage system. So this point of this parenthetical remark is that if you are using BUG you can just use the BugData module.)

The general form for saving a dictionary would be something like this...
In the onPreSave event handler do:
Code:
CyGame().setScriptData(pickle.dumps(MyDictionary))
and in the onLoadGame event handler do:
Code:
MyDictionary = pickle.loads(CyGame().getScriptData())
 
Ok, regarding the exception. It seems to be a stupid import mess-up so you should just leave that import statement in CustomFeatures and keep those helper function at the bottom of the same module. We could rewrite all 3 modules and be able to move those functions but it requires testing and I doubt its worth the effort. (You could move the eNums though.)

I haven't looked at the catapult construction bug yet. And I'll have to get back to you about the other code you posted. And I'll try to have a look at the previous discussion on the Senate Missions.

About what God-Emperor said, this of course only applies to CivIV Python modding. And this sort of thing is already available to you via the DataStorage module.
 
ahh but it isn't for civ 4 modding :(

I will try move the helpers back again and get back to you!
 
Back
Top Bottom