Can anyone help me out a bit?

BobTheTerrible

Just Another Bob
Joined
Jan 5, 2003
Messages
927
Location
Middle of Nowhere
I'm trying to make a mod for my personal enjoyment for Revolutions, and I was wondering if you guys would help me out. I've tried to read all the stickies for answers but I can't seem to find anything I'm looking for. I have a couple easy modifications I want to make of the Revolutions mod, but I have no idea how to implement any of them. I don't want to pm jdog directly because I know he's busy, so I was wondering if any of you could help me with this. I posted it in the creation and customization forum but it doesn't seem to be getting any responses.

EDIT: may have answered first question

EDIT: Big question now is how exactly through python I can:
A) retain starting locations generated through the map
B) remove the civs while recording their start locations
C) run auto-play and intermittently respawn a civ in its respective start location until player has been spawned, at which case stop auto-play but keep spawning civs until all the original civs have been spawned.


Sorry for being a noob. I'd appreciate any help you guys could give. I'm willing to do these modifications myself, I just have no idea where to look and how to change things.
 
The initial civ placement code is not something I've looked at, for figuring out how to make changes like that you might need to talk to modders who've been tweaking map scripts like SevenSpirits or Thedrin ... check out the MapScript part of Creation & Customization.

There are quite a few problems people are working on with initial civ placement, as something seems to have changed in BTS causing excessively forested starts to be much more common.

Anyway, as for automatically launching autoplay to have a couple civs and barbs start pre-4000 ... you might try having all the civs spawn pre-4000 to make use of the existing initial placement code, then going through the list of civs and selectively killing some off so you can start them up again ... :crazyeye: In total psuedo code it could work like this (indentation indicates conditional execution/inner part of loop as in Python):

Code:
on event GameStart:
    set autoplay to 100

on event begin game turn:
    if( turn == 47 or whatever corresponds to 4000bc) :
        for each player :
            bDoKill = True
            if capital has a couple floodplains nearby
                bDoKill = False
            elif capital is holy city
                bDoKill = False

            if( bDoKill ) :
               record x,y location of capital
               player.killCities()
               player.killUnits()
               spawn settler and starting unit at x,y
        

        change human player to one of the players who was killed

This won't erase any tech researched or tiles exposed during the pre-time, to do that you'd replace the killing lines with:

Code:
player.setNewPlayerAlive(False)
game.addPlayerNoTurn( previous civ's details )
player.setNewPlayerAlive(True)

This has the downside that it will generate the "so-and-so has been destroyed" messages, but will wipe the slate completely clean for the newly new civs.

I'd recommend creating a new Python file for this and follow examples from my code for registering the two event handling functions.
 
Hey jdog thanks for your help, I really appreciate it.

Anyway, as for automatically launching autoplay to have a couple civs and barbs start pre-4000 ... you might try having all the civs spawn pre-4000 to make use of the existing initial placement code, then going through the list of civs and selectively killing some off so you can start them up again ... :crazyeye:

What I was originally thinking was something like (keep in mind I have little knowledge of coding):

Add X# of extra turns to the game, before 4,000 BC (obviously not done via this script)
Spawn a civ or two
run autoplay for X turns, until it hits 4,000 BC
switch off autoplay
Spawn the rest of the civs as per normal

So I guess, is there any way to have two rounds of generating civs, or can it no generate starting positions once the game has begun?
 
It's definitely possible to place settlers etc on the map for new civs at any time, but I don't know how it decides where to place them initially so I can't really help with that. It should be possible ... and you'd probably still want to use the general setup I described above, but create a bunch of new civs instead of killing some off in the second function.
 
OK so I've been trying to read up on python, I've gone through a lot of the tutorial that someone posted but I'm still trying to understand some parts of it, as well as the logistics of how these things work.

If I wanted to make a script to tell the game to:
A) retain starting locations generated through the map
B) remove the civs while recording their start locations
C) run auto-play (for, say 15 turns) and intermittently respawn a civ in its respective start location until player has been spawned, at which case stop auto-play but keep spawning civs until all the original civs have been spawned.

Then I'd start off by creating a new python file (not modifying an existing one) and telling it? (again in pseudo code):

Code:
import (lots of other files that I'm not even aware need to be imported)
import (more files that I don't even know about)


autoplay = 1

on event GameStart:
     for each player:
          record x,y location of settler
          remove the player
          assign player random integer(1-15)
   

on event Begin Game Turn:
     if turn = 1 and random integer for a player is 1:
           spawn that player at recorded x,y value
     if turn = 2 and random integer for a player is 2:
           spawn that player at recorded x,y value
     etc
     if player is spawned:
           autoplay = 0

Would it look something like that?

I also need to know where I'd put such a script and how I'd make sure it starts at the game start. Would I have to put in another script to open this one when the game starts?

This is the first time I've tried to write anything in python or any programming language for that matter, so if you guys would help me out it would be greatly appreciated.
 
Pretty good start, a few small changes ...

Code:
from CvPythonExtensions import *

(These set up useful shortcuts to commonly used classes)
gc = CyGlobalContext()
game = CyGame()

(This will keep record of player info)
playerInfoList = list()

register Events :
     add GameStart event handler
     add BeginGameTurn event handler

on event GameStart:
     global playerInfoList (so that you can write to this global variable and use it in other functions)

     game.setAIAutoPlay( 15 )

     for each player:
          record player id number
          record x,y location of settler
          remove the player's units
          assign player random integer(1-15)
   

on event Begin Game Turn:
     for each player in recorded list :
         if turn == random integer for player:
              spawn that player at recorded x,y value

              if game.getActivePlayer() == player id :
                  game.setAIAutoPlay( 0 )

              remove player info from list (not strictly necessary, but might as well so it isn't checked unnecessarily later)

The register events function is what will register the other two functions with the CustomEventManager so that they will be called when those events occur, it should be called inside of either RevolutionInit.py or CvCustomEventManager.py in a similar way to how RevUtils function is called.

I'm only mostly sure that the GameStart function is what you want, as I don't exactly know when that fires with respect to unit placement ... if it doesn't work, you could just shift that loop to inside of a conditional on gameTurn == 0.

Good luck!
 
Thanks again for all your help jdog. One last quick question for now. How do I make sure the script runs when the game starts? I'm assuming there's some other python script somewhere that I'd have to tell to run myscript.py when the game begins?
 
Top Bottom