help creating new victory condition

kaysea

Chieftain
Joined
Oct 22, 2005
Messages
12
I'm learning python and am kinda lost trying to create a new victory condition. Basically what I want to do is create a victory condition for Fell From Heaven where once all the civs aligned to a certain alignment (good, evil, neutral) are defeated the game is over. For example; say your a good civ and all the evil and neutral civs are defeated, then you win.

I've read all the python tut. on this site but am lost on how to start it.

where do you insert your code?
How would you structure it?

I'm at a complete loss ... can anyone guide me in the right direction?
 
You could place a check for this condition in a BeginPlayerTurn event handler. This event is fired for every player as they begin their turn. For humans, this happens when they hit the end turn button. I don't know how to acquire a player's alignment in FfH, but this is the general structure of the code:

Code:
def onBeginPlayerTurn(self, argsList):
    iGameTurn, iPlayer = argsList
    if iPlayer == gc.getGame().getActivePlayer():
        iAlignment = gc.getPlayer(iPlayer).[B]getAlighment()[/B]
        for iLoopPlayer in range(GC.getMAX_PLAYERS()):
            if iLoopPlayer != iPlayer:
                player = gc.getPlayer(iLoopPlayer)
                if player.isAlive() and not player.isBarbarian() and not player.isMinorCiv() and player.[B]getAlignment()[/B] != iAlignment:
                    break
        else:
            # all living players have same alignment
            [B]<trigger victory condition>[/B]

BTW, "else" on a "for" loop runs if the loop goes through all values--doesn't exit due to a "break".
 
emperorfool said:
<trigger victory condition>

I am also interested in this, but does anybody have more details on the quoted part? File civ4victoryinfos.xml seems related, but it seems you have to add a new enumerated type value in the sdk to add a brand new condition. Can anybody give or point to a step by step instruction?
 
I am also interested in this, but does anybody have more details on the quoted part? File civ4victoryinfos.xml seems related, but it seems you have to add a new enumerated type value in the sdk to add a brand new condition. Can anybody give or point to a step by step instruction?

I may be wrong, but I believe no SDK modifications are necessary to add a new victory condition.
 
No, not really.
You can just add another time victory to the VictoryInfos.xml and then let it trigger via python (look at this middle east trading mod, which comes with civ4).

@kaysea:
First you'll need to have the API, where all the commands are mentioned.
Then the first question here: Do you have basic programming skills? Do you know, what a loop, what a list and what an if statement is? If yes: Fine. If not: Will still work somehow.

The game related python files are the CvEventManager and the CvGameUtils.py, you should look at them.

Looking at EFs code, i would suggest instead letting it trigger after onCityAcquired/onCityRazed/onCityAcquiredAndKept, because this normally the reason for the destruction of a civ, and would be more performant.
 
Thanks for the pointer to "Crossroads of the World". This is probably what I need. Although this may seem like a thread hijack, I think the OP will need this information also. As far as I can tell, CotW has changed two python files and one xml file for the commerce victory condition. Did I miss any?

In python/screens/CvVictoryScreen.py, they have commented out the score victory section and added a section which starts:
Code:
if (victory.getTextKey() == "TXT_KEY_VICTORY_COMMERCE"):
This is kind of a hack, but that is fine. This code prints the data for the victory screen so you can see how each civ is doing. The vanilla victory conditions don't give the exact score of each player, but only yourself and the leader; still, this is close enough.

In python/CvCrossroadsEvents.py in the onEndGameTurn event, there is a check to see if any player's gold total is greater than the threshold. In this case CyGame().setWinner is called, passing in the hard-coded number of the commerce victory condition.

In xml/gameinfo/civ4victoryinfos.xml the VICTORY_COMMERCE section is added, which is straightforward.

Unless I missed something, this is probably enough to add the victory condition. I will try this for a terraforming victory in Dune Wars, and if I find any missing steps I will update here.
 
Back
Top Bottom