How to create new Python file and call it from within SDK?

sirkris

Chieftain
Joined
Dec 16, 2005
Messages
57
I need to have the game open a remote URL at a certain point in the code, but of course C doesn't have any native functions to handle that. I tried putting in an include for MFC so I could use OpenURL, but it was just too incompatible with the existing src on link during make.

So instead I'd like to just have the URL opened from within a Python script, which is insultingly easy in comparison. However, I have no idea how to call a Python script from within the SRC to do that. I could create the file, but how do I get it to execute?


Thanks!
 
hum, you could use a generic event. The code for the unit statistics looks like this.

Code:
    CyUnit* pyUnit1 = new CyUnit(this);
    CyUnit* pyUnit2 = new CyUnit(pDefender);
    CyArgsList pyArgs;
    pyArgs.add(gDLL->getPythonIFace()->makePythonObject(pyUnit1));
    pyArgs.add(gDLL->getPythonIFace()->makePythonObject(pyUnit2));
    pyArgs.add(min(iDamage, (airCombatLimit() - pDefender->getDamage())));
    gDLL->getEventReporterIFace()->genericEvent("airStrikeHit", pyArgs.makeFunctionArgs());

Of course, you have to place it so that it only gets called when you want it.

then you have to add the event to the eventhandlermap in your CvEventManager or CvCustomEventManager:

Code:
			'airStrikeHit'				: self.onAirStrikeHit,

And finally, you do whatever you want in python.

Code:
	def onAirStrikeHit(self, argsList):

		genericArgs = argsList[0][0]
		attackerUnit = genericArgs[0]
		defenderUnit = genericArgs[1]
		iDamage = genericArgs[2]


Maybe there is a more elegant way, but at least it should work :)
 
Back
Top Bottom