• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

Dom Pedro's Mod Helper for Python Modders

I was in the process of merging this with another component and I noticed two other commented blocks (specifically titled PoliticsMod and Factions). I wasn't sure if these needed to be included or not for the PythonDLL to work (I wasn't sure if they were a type of precourser to the PythonDLL as some of the PythonDLL blocks end with PoliticsMod End).

Yeah, that was because I merged some of the python-related stuff from some other mod components I have in the works into the PythonDLL stuff. It's needed.
 
Very interesting... this is something I have always wanted and was going to attempt to do. This may fit into a little experimental project of mine that, if it works, I wanna release. We'll see what happens. :D Thanks for another sweeeeeet MOD COMP.
 
I will use it for my next project but I am already 1500+ lines into the current project, and the current project is based on an sdk which is heavily modified by others. So it would be difficult to merge.
 
This is actually what I needed so I'm going to merge it into my mod to help me use python more, if you don't mind. :)
Is this for 3.19? It would help merging but actually doesn't matter. And have you changed anything in the python API? Sorry if that's stupid question. ;)
 
I have started merging your mod component into my mod. However I have found something you have added but it's commented out. :confused: Is this intented or just a mistake? Here is the code part:
Spoiler :
int CvUnit::maxCombatStr(const CvPlot* pPlot, const CvUnit* pAttacker, CombatDetails* pCombatDetails) const
{
int iCombat;

FAssertMsg((pPlot == NULL) || (pPlot->getTerrainType() != NO_TERRAIN), "(pPlot == NULL) || (pPlot->getTerrainType() is not expected to be equal with NO_TERRAIN)");

// handle our new special case
const CvPlot* pAttackedPlot = NULL;
bool bAttackingUnknownDefender = false;
if (pAttacker == this)
{
bAttackingUnknownDefender = true;
pAttackedPlot = pPlot;

// reset these values, we will fiddle with them below
pPlot = NULL;
pAttacker = NULL;
}
// otherwise, attack plot is the plot of us (the defender)
else if (pAttacker != NULL)
{
pAttackedPlot = plot();
}

if (pCombatDetails != NULL)
{
pCombatDetails->iExtraCombatPercent = 0;
pCombatDetails->iAnimalCombatModifierTA = 0;
pCombatDetails->iAIAnimalCombatModifierTA = 0;
pCombatDetails->iAnimalCombatModifierAA = 0;
pCombatDetails->iAIAnimalCombatModifierAA = 0;
pCombatDetails->iBarbarianCombatModifierTB = 0;
pCombatDetails->iAIBarbarianCombatModifierTB = 0;
pCombatDetails->iBarbarianCombatModifierAB = 0;
pCombatDetails->iAIBarbarianCombatModifierAB = 0;
pCombatDetails->iPlotDefenseModifier = 0;
pCombatDetails->iFortifyModifier = 0;
pCombatDetails->iCityDefenseModifier = 0;
pCombatDetails->iHillsAttackModifier = 0;
pCombatDetails->iHillsDefenseModifier = 0;
pCombatDetails->iFeatureAttackModifier = 0;
pCombatDetails->iFeatureDefenseModifier = 0;
pCombatDetails->iTerrainAttackModifier = 0;
pCombatDetails->iTerrainDefenseModifier = 0;
pCombatDetails->iCityAttackModifier = 0;
pCombatDetails->iDomainDefenseModifier = 0;
pCombatDetails->iCityBarbarianDefenseModifier = 0;
pCombatDetails->iClassDefenseModifier = 0;
pCombatDetails->iClassAttackModifier = 0;
pCombatDetails->iCombatModifierA = 0;
pCombatDetails->iCombatModifierT = 0;
pCombatDetails->iDomainModifierA = 0;
pCombatDetails->iDomainModifierT = 0;
pCombatDetails->iAnimalCombatModifierA = 0;
pCombatDetails->iAnimalCombatModifierT = 0;
pCombatDetails->iRiverAttackModifier = 0;
pCombatDetails->iAmphibAttackModifier = 0;
pCombatDetails->iKamikazeModifier = 0;
pCombatDetails->iModifierTotal = 0;
pCombatDetails->iBaseCombatStr = 0;
pCombatDetails->iCombat = 0;
pCombatDetails->iMaxCombatStr = 0;
pCombatDetails->iCurrHitPoints = 0;
pCombatDetails->iMaxHitPoints = 0;
pCombatDetails->iCurrCombatStr = 0;
pCombatDetails->eOwner = getOwnerINLINE();
pCombatDetails->eVisualOwner = getVisualOwner();
pCombatDetails->sUnitName = getName().GetCString();
}

if (baseCombatStr() == 0)
{
return 0;
}

int iModifier = 0;
int iExtraModifier;

iExtraModifier = getExtraCombatPercent();
iModifier += iExtraModifier;

/*** PYTHONDLL 07/20/09 by DPII START ***
if (getNumPythonCombatModifiers() > 0)
{
for (int i = 0; i < getNumPythonCombatModifiers(); i++)
{
CyUnit* pyUnit = new CyUnit((CvUnit*)this);
CyArgsList argsList;
argsList.add(gDLL->getPythonIFace()->makePythonObject(pyUnit)); // pass in city class
CyUnit* pyAttacker = new CyUnit((CvUnit*)pAttacker);
argsList.add(gDLL->getPythonIFace()->makePythonObject(pyAttacker));
long lResult=0;
gDLL->getPythonIFace()->callFunction(PYPythonDLLModule, getPythonScript(i), argsList.makeFunctionArgs(), &lResult);
delete pyUnit; // python fxn must not hold on to this pointer
delete pyAttacker;
}
}
/*** PYTHONDLL END ***/


if (pCombatDetails != NULL)
{
pCombatDetails->iExtraCombatPercent = iExtraModifier;
}...
EDIT: I don't find any differences between the original CyGame.cpp and CyGame.h files and your CyGame.cpp and CyGame.h files. I even used WinMerge. So why they are in C++ files?

EDIT2: There are no differences in CyGameInterFace.cpp either.

EDIT3: Nor in CvGame.h. Also do you have something to tell about this comment
//DPII Add code here to display help for Builds
in CvDLLWidgetData.cpp?
 
I merged Mod Helper into my mod, but when building a solution it threw in some errors:
1>CvDLLWidgetData.cpp
1>CvDLLWidgetData.cpp(2891) : error C2027: use of undefined type 'CvActionButtonInfo'
1> d:\CvGameCoreDLL\CvGlobals.h(45) : see declaration of 'CvActionButtonInfo'
1>CvDLLWidgetData.cpp(2891) : error C2228: left of '.getHelp' must have class/struct/union type
1>NMAKE : fatal error U1077: '"C:/Program Files/Microsoft Visual C++ Toolkit 2003/bin/cl.exe"' : return code '0x2'
1>Stop.
1>Project : error PRJ0019: A tool returned an error code from "Performing Makefile project actions"
1>Build log was saved at "file://d:\CvGameCoreDLL\Final_Release\BuildLog.htm"
1>CvGameCoreDLL - 4 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
:confused: I'm sure I added everything that should. Please someone help me!

EDIT: There were 44 files in the C++ folder. 4 of them didn't have any changes so I have edited 40 files. The total of comments witch had DPII in was 322, and that much I have in the current DLL. I even downloaded again it from the data base to see if mine was older version. I still don't see why it shows up errors. Are you sure this is the code you used in your DLL? And what about that commented out part in CvUnit.cpp or your comment in CvDLLWidgetData.cpp? I really would like to use this.
 
I actually found the error. (I don't believe it myself either. :) ) Anyway the problem was that there has been added a CvActionButtonInfo class in both CvInfos.h and CvInfos.cpp. So they were without any comments so I missed them. I think you should add these comments. ;)
I'm going to see what I can do to the xml next week...
 
Dom Pedro,
These things you made look great. I want to use them ASAP but I have some questions:

1) I want to use your Maintenance Modifiers mod, and your Religion mod, and your Tech Research mod, and your mod helper, but I'm not sure if they're compatible with one another, since some of the files I'm supposed to replace are the same in more than one mod...

2) About the helper mod, can you give a description of the variables passed in argsList for each XML call to python? In the pdf you give examples for some functions called from some of the XML files, but not for all of them. Maybe there's something obvious I'm supposed to know, but right now I would have to guess what will be stored in argsList[0] when defining a function at Civ4CorporationsInfos.xml, for example...

3) In all of these mods you provided xml files, but I suppose the only really necessary ones are each of the *Schema.xml, right?


Thanks
 
Back
Top Bottom