Creating new python event?

Joined
Jan 21, 2006
Messages
737
I just tried to create two new python events using the SDK. But every time I start a map with the modified CvGameCoreDLL, I get a crash to desktop.

Here's what I did:

In CvDLLEventReporterIFace.h, I added the lines

Code:
	virtual void combatBegin(CvUnit* pAttacker, CvUnit* pDefender, int idefenderOdds) = 0;
	virtual void combatHit(CvUnit* pAttacker, CvUnit* pDefender, int iIsAttacker, int iDamage) = 0;

I also changed some other files (CvEventManager.py, CvUnit.cpp), but I removed those changes again to verify that it is indeed these two lines that lead to the crash.

Now to the question: Did I miss another file that I have to edit to make it work? Is there an error in my code? Is it even possible to add new python events?
 
You changed the header file. You also have to add the functions to the .cpp file. Even empty functions should be ok but they have to be there. Of course, I haven't looked at the SDK that much yet so I'm just making a general statement about C++.

Roger Bacon
 
Unfortunately I cannot find where the existing event methods are... just do a search for cityDoTurn. There is a virutal definition for it but no actual implementation of in the source code...
 
CvDLL*Iface.h seem to define interfaces for accessing functions in the exe. Therefore you can't edit the interface or the definition of any of those functions.
 
Hmpf. Well, it's not that bad because new events can still be created using genericEvents. I already successfully tested it, but I haven't been able to add CvUnit objects to the argsList, which is rather important.

Hm, I'll try a workaround using the Unit ID and Owner until I find a more suitable solution.
 
You need to add CyUnits to the argslist in a special way - this example is from CvCity.can train:
Code:
	CyCity* pyCity = new CyCity(this);
	CyArgsList argsList;
	argsList.add(gDLL->getPythonIFace()->makePythonObject(pyCity));	// pass in city class
	argsList.add(eUnit);
	argsList.add(bContinue);
	argsList.add(bTestVisible);
	long lResult=0;
	gDLL->getPythonIFace()->callFunction(PYGameModule, "canTrain", argsList.makeFunctionArgs(), &lResult);
	delete pyCity;	// python fxn must not hold on to this pointer

Here its CyCity/CvCity and callFunction, but you would do the same sort of thing for CyUnit/CvUnit and genericEvent.
 
Thanks for your help. I already tried copying one of these examples once, but it didn't work, so I looked for another way. Seems like this is the best/only way though, it probably just didn't work because of some mistake I made. Anyway, I now succeeded in implementing it. Yay! :)
 
Back
Top Bottom