Thunderbrd
C2C War Dog
I experimented a bit with direct interactions with the Python DLL.
As a result it is now possible to code outcome effects in Python and include that code right in the XML for the outcome (now means when someone next checks in the compiled DLL).
An example:
Anything that you could do in a Python module is allowed within that tag (so you could import other modules and similar). PythonName can be anything. It is only used for code error messages in PythonErr. Ignore any "traceback" it claims if your PythonName appears there.Code:<Outcome> <OutcomeType>OUTCOME_BEAR_POWER</OutcomeType> <iChance>5</iChance> <PythonName>BearWithMeModule</PythonName> <Python> def isPossible(unit, plot): return unit.isHuman() def doOutcome(unit, plot, eDefPlayer, eDefUnitType): unit.changeExperience100(1000, -1, False, False, False) def getDisplay(unit, plot): return u"Bear POWER" def getAIValue(unit, plot): return 1 </Python> </Outcome>
The four functions need exactly that signature but you can leave any of them out (so if you leave out isPossible, because you don't want to alter when the outcome is possible, then that is ok).
If isPossible(unit, plot) returns false, then this outcome is not possible for the given unit on the given plot.
doOutcome(unit, plot, eDefPlayer, eDefUnitType) is executed when the outcome is triggered with a given unit. If it is a kill outcome, then eDefPlayer is the player to whom the killed unit belonged and eDefUnitType is the type of the killed unit. The plot is given so the function signature is similar to the others but is currently always the plot of the given unit.
getDisplay(unit, plot) can return a string that is displayed in the result brackets of the help text for that outcome (like when you mouse over an action outcome).
getAIValue(unit, plot) allows you to give an estimate of the value of the Python effect to the AI (like when it tries to decide what to do with a subdued animal).
Forgive my ignorance of the inner workings of the current (or pre-this-change) functioning of the Outcome Mechanism but I have a few questions that may come across as shamefully lacking understanding here.
1) So this enables us to basically program the outcome variables (with python language) right into the xml of the unit, unitcombat, etc itself?
2) What then is the need for referring to a python module at all? What further python will be necessary - it seems to me the whole process can be encapsulated here.
3) How do you compile the 'chances' of an outcome?
4) Is this purely useful in combat results at the moment? Or does it have other potential effects?
5) To what info types do this <Outcome> tag apply to?
6) If a unit is getting an <Outcome> ability from it's base unit info, a combat class, and a promotion, do they in any way seamlessly tally up somehow?
Sorry... again - I'm shamefully confused still on what Outcomes are and how they work (to an extent.) And I'm just trying to get this cleared up for myself.