BobTheTerrible
Just Another Bob
I'm trying to make a small script where rather than all spawning at 4000 BC, civs will spawn at a random time within the first 15 or so turns. This is the first script I'm trying to do with python and I really have no idea how to make this work, I know what steps I have to go through but I don't know how to put this into python. I've read the tutorial for python modding, but I still can't understand how I need to go about doing this. Here's the pseudo-code I have (mostly written by jdog from the revolution mod, my comments in italics, his after #):
I'm also going to need to know how to call the script to run at at the game start, and make sure that the player doesn't lose the game right at the beginning until he's spawned. If someone could help me along here, hopefully by putting it into real python code and explaining what each bit does, I would greatly appreciate it.
Code:
from CvPythonExtensions import * [i](I can't locate this file on my computer
so I have no idea what I'm being told to import here)[/i]
#(These set up useful shortcuts to commonly used classes) [i](again, not really sure what these do)[/i]
gc = CyGlobalContext()
game = CyGame()
#(This will keep record of player info)[i]I'm assuming this is the list to add/remove
players from once they've spawned[/i]
playerInfoList = list()
register Events : [i] this is just defining the events I'll need?[/i]
add GameStart event handler
add BeginGameTurn event handler
onGameStart: [i]not sure exactly why I need this, either[/i]
global playerInfoList #(so that you can write to this global variable and use it in other functions)
game.setAIAutoPlay( 15 ) [i]autoplay is a feature of the mod I am modding.
It allows AI to take control of the player for a set number of turns... now that I think of it,
I probably don't need this bit in there...[/i]
for each player:
record player id number
record x,y location of settler
remove the player's units
assign player random integer(1-15)
onBeginGameTurn:
for each player in recorded list :
if turn == random integer for player:
if that x/y location has a barbarian unit/animal
remove that unit
spawn settler/warrior at recorded location
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)
I'm also going to need to know how to call the script to run at at the game start, and make sure that the player doesn't lose the game right at the beginning until he's spawned. If someone could help me along here, hopefully by putting it into real python code and explaining what each bit does, I would greatly appreciate it.