Custom EventManagers in Revolution

Graceheart the Leopard

Resident Amur leopard
Joined
Sep 24, 2007
Messages
3,476
I've been playing around with the Revolution (well, actually, Wolfshanze Revolution) Mod, but to date most of my changes have been in XML. However, when I try and have a custom EventManager file, the game doesn't work properly (which I'm assuming is because of the BugEventManager file). Is there a way I can use a custom EventManager file while having a full Revolution experience?
 
Nobody? :(
 
BUG allows you to add as many event manager files as you want. You just have to register them with BUG and it will call your event handlers - the bug code calls each registered handler for each event that happens. Look in the Assets/Config folder to see how they are done for the existing things - the main file is the init.xml file which generally loads another .xml file for an add-in where it defines things like what python file holds your event handlers. There are 2 different ways to do it, essentially: you can either have each event handler be a stand alone function and define which function is called for an event in the XML file or you can put them all in a class like the regular event manager uses and give the class an __init__ function that registers your events when an instance of the class is made by BUG. If you only have a couple of event handlers, the first is probably easier.

You can also check out the BUG wiki here. The Modder's Corner has information about this sort of thing.
 
Hmmm... it doesn't seem to register the game. Here's the code I'm using in Python:

Code:
from CvPythonExtensions import *
import BugUtil

## Scientific Victory Start ##
		if CyGame().isVictoryValid(gc.getInfoTypeForString("VICTORY_SCIENTIFIC")):
			for iTeamX in xrange(gc.getMAX_CIV_TEAMS()):
				if not gc.getTeam(iTeamX).isAlive(): continue
				bVictory = self.doScientificVictoryCheck(iTeamX)
				if bVictory:
					CyGame().setWinner(iTeamX, gc.getInfoTypeForString("VICTORY_SCIENTIFIC"))

	def doScientificVictoryCheck(self, iTeam):
		iAlive = 0
		pTeam = gc.getTeam(iTeam)

		for iTech in range(gc.getNumTechInfos()):
			pTech = gc.getTechInfo(iTech)
			if (not pTech.isDisable() and not pTeam.isHasTech(iTech)):
				return False

		if pTeam.getBuildingClassCount(gc.getInfoTypeForString("BUILDINGCLASS_AI_ENTITY")) < pTeam.getNumCities():
			return False
		if pTeam.getBuildingClassCount(gc.getInfoTypeForString("BUILDINGCLASS_MIND_BANK")) < pTeam.getNumCities():
			return False
		return True
## Scientific Victory End ##

And here's the XML file:

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
    Scientific Victory
-->
<mod id="ScientificVictory" module="ScientificVictory">
    <event type="BeginPlayerTurn" function="doScientificVictoryCheck"/>
</mod>
 
The part before the function definition will be run exactly once when the file is first loaded.

If a function is not part of a class, it should not have the "self" argument.

I think the easiest fix is to have the Python adjusted a bit like so (not tested):
Code:
from CvPythonExtensions import *
import BugUtil

gc = CyGlobalContext()

## Scientific Victory ##		

def onBeginPlayerTurn(argsList):
	iGameTurn, iPlayer = argsList

	if CyGame().isVictoryValid(gc.getInfoTypeForString("VICTORY_SCIENTIFIC")):
		iTeam = gc.getPlayer(iPlayer).getTeam()
		if gc.getTeam(iTeam).isAlive():
			if doScientificVictoryCheck(iTeam):
				CyGame().setWinner(iTeam, gc.getInfoTypeForString("VICTORY_SCIENTIFIC"))

def doScientificVictoryCheck(iTeam):
	iAlive = 0
	pTeam = gc.getTeam(iTeam)

	for iTech in range(gc.getNumTechInfos()):
		pTech = gc.getTechInfo(iTech)
		if (not pTech.isDisable() and not pTeam.isHasTech(iTech)):
			return False

	if pTeam.getBuildingClassCount(gc.getInfoTypeForString("BUILDINGCLASS_AI_ENTITY")) < pTeam.getNumCities():
		return False
	if pTeam.getBuildingClassCount(gc.getInfoTypeForString("BUILDINGCLASS_MIND_BANK")) < pTeam.getNumCities():
		return False
	return True

Or something like that. I removed the loop over all teams, just going for a check of the team of the player who's turn is being processed, but I'm not sure how, or if, this would work on a simultaneous turns multiplayer game.

Make sure that this file is in the Python folder (not the config folder) and it is called ScientificVictory.py (to match the specified module="ScientificVictory").

Then in the XML set the function to call to be onBeginPlayerTurn.

With a little luck, and maybe some bugfixing, it should work.
 
Nope. XML's in the config folder, ScientificVictory.py is in the Python folder, and it still doesn't work. :(
 
Okay, it loads, but it doesn't seem to do anything when I try and test out the requirements (all techs researched and Mind Banks and AI Cores in every city). Here's the relevant part of the debug file:

Code:
18:47:28 DEBUG: BugConfig - loading mod file ScientificVictory
18:47:28 DEBUG: BugInit - loading mod ScientificVictory...
18:47:28 INFO : BugCore - creating uninitialized mod ScientificVictory
18:47:28 DEBUG: BugUtil - looking up ScientificVictory.onBeginPlayerTurn
load_module ScientificVictory

18:47:28 DEBUG: Timer - load mod [ScientificVictory] took 0 ms
 
If you have not changed it, it is not possible to win in the first 10 turns of the game. So if you are starting a new game and then using worldbuilder to add everything you need it still wont' let you win until 10 turns have happened.

(This is done via the isVictoryTest function near the beginning of the standard BtS CvGameUtils.py file.)
 
If you have not changed it, it is not possible to win in the first 10 turns of the game. So if you are starting a new game and then using worldbuilder to add everything you need it still wont' let you win until 10 turns have happened.

(This is done via the isVictoryTest function near the beginning of the standard BtS CvGameUtils.py file.)

Not true.
setWinner function ignores that check, so for python victories like this, it can be accomplished even on turn 0.

Do some simple test codes, like just add one line to add 10000 gold onBeginGameTurn, and see if the code actually ran.
 
Back
Top Bottom