Quick Modding Questions Thread

Is the code that adds the leader unit to a unit's art when joined by a great general available for modding? If so, how exactly?

I'm currently considering stuff like removing explicit Anti-Tank and SAM Infantry units, as they would be (or already are) more appropriately represented by promotions. In that case, it would be cool to have one member of the unit change to the existing Anti-Tank or SAM Infantry art when the promotion is assigned.
 
Is the code that adds the leader unit to a unit's art when joined by a great general available for modding? If so, how exactly?

I'm currently considering stuff like removing explicit Anti-Tank and SAM Infantry units, as they would be (or already are) more appropriately represented by promotions. In that case, it would be cool to have one member of the unit change to the existing Anti-Tank or SAM Infantry art when the promotion is assigned.
There are two ways you can go.

First one is duplicating the warlord unit and promotion. The problem here is that the warlord birth mechanic does not differ between units having a non-NONE entry in the <LeaderPromotion> tag, means that each time a warlord should be born, there is a chance that your new unit will be born instead. I think Lemon Merchant fixed that for her BAT mod though.

The other way to add a leader to a unit is through python using the 'setLeaderUnitType' command. I am doing so in my Beastmaster mod, the code line looks like this:
Code:
unit.setLeaderUnitType(gc.getInfoTypeForString("UNIT_BEASTMASTER"))
This is of course only graphics, you will have to add a fitting promotion separately.

With both methods you have the restriction that a unit can only have one leader at the same time, means that if you have a unit with a warlord attached and attach a SAM unit to it, it will replace the warlord.

If you want to replace one of the three unit members with a different model, you will have to go through the dll as far as I know. I think the Dune mod does something like that with promotions.

Edit: There is another alternative to make promotions change the appearance of a unit I played around with here.
 
That's a lot of options to try, thank you! I am not adverse to modifying the DLL for this. Let's see what I can make happen here.
 
Hi All:king:,

I'm currently making a scenario for Rise of Mankind - A New Dawn and looking for someone who can help me to modify a 3D mesh of an existing leaderhead. (Just minor changes needed and all other leaderheads of the scenario are OK.)
I have contacted the creator, but he hasn't answered (despite he was active several times after I wrote private message to him) so I don't want to pester him/anyone.

I tried to manage this with various 3D animator softwares like Blender or Python, even with Nifscope too, but I found myself in massive trouble and confusion after several days because my 3D modelling experience is none and there is a lot of compatibility or (maybe) patch/version/OS :)confused:) issues - whatever it may be - so please don't leave me with some links of 3D tutorials.
My part is graphic design, can change or modify unit or leadehead skins, backgrounds, flags, map design, etc. but 3D - unfortunately no way. (...and fortunately doesn't needed so far.:lol:)
So after the modification of the mesh (only!), the graphics like skin and clothes I can manage.

And of course, the scenario included this leaderhead will be shared in this forum.
:)

For further infos please contact me in private.


Kind regards,
ProjectM
 
Is there a way to view the files inside a .fpk without unpacking them? I'd only need the name of a file.
 
Where are the functions which draw minimaps (both the main one in the bottom right and the one in military advisor) located? I searched through both dll code and python code but I was not able to find anything.

I am interested in slightly changing how map centering works, i.e. changing the center point to something else than map center.
 
Possibly a stupid question. How does the coordinate system in C4 work, especially as regards to Python coding? That is, say I have a tile at iX, iY. Are the surrounding 8 tiles ([iX-1 to iX+1],[iY-1 to iY+1])? If so, why do I see lots of things that loop from iX-1 to iX+2, for example, when doing things to neighboring plots? If not, uh, what are the surrounding 8 tiles' coordinates?
 
In Python, when you do a loop using "for index in range(number)", the loop will stop when index reaches the value number, so the last iteration will use (number - 1). So for example, when you do a loop like:

Code:
for i in range (CyMap().numPlots()):

i will go from zero to (CyMap().numPlots() - 1), which is the last position for which the following code would be valid:

Code:
CyMap().plotByIndex(i)

Looping like this is very useful because the plots are internally an array with CyMap().numPlots() numbered from zero to (CyMap().numPlots() - 1).

In the double for loops you mentioned, the case is the same.

Code:
for iiX in range(iX-1, iX+2, 1):
   for iiY in range(iY-1, iY+2, 1):

In this example the first for loop will be executed in iterations from iX - 1 to iX + 1, increasing the value of iiX in 1 each time. When iiX reaches iX+2, the for loop will stop without running for that value. Therefore, the loop will run for the 8 tiles surrounding (iiX, iiY), and for the center tile too.
 
Ah, ok, so it's due to the way Python does for loops. I figured that was one of the possibilities, but wasn't sure and was too lazy to go look it up myself. Thanks!
 
Code:
for iiX in range(iX-1, iX+2, 1):
   for iiY in range(iY-1, iY+2, 1):
There is a function to do this:
Code:
for i in range(8):
    plot = CvUtil.plotDirection(x, y, i)
x,y is the center plot. 8 is NUM_DIRECTION_TYPES (which I can't remember offhand what is called in python, but it's always 8)

The main difference compared to Terkhen's loops is that CvUtil.plotDirection is aware of map size. It is able to warp around the map if you happen to pick a plot on the edge, which will happen eventually on the normal maps where east/west are connected. Not true. plotXY actually accounts for map warp as well.

Remember that plot can be NULL!!! This will happen if the center plot is on the edge of the map and the map doesn't warp around. Polar regions can do this. Assuming plot to be valid when it's NULL will crash in C++, but I'm not sure what will happen in python. It won't do what you expect it to do, that's for sure.
 
Last edited:
Oh, damn, I forgot to account for map edges/wraps. That said, looking at the Volcano event in base BtS there appears to be a function that loops around coordinates:
Code:
loopPlot = plotXY(kTriggeredData.iPlotX, kTriggeredData.iPlotY, iDX, iDY)
           if not loopPlot.isNone():
Presumably it takes coordinates that are outside the map and either loops them or returns a null that can then be used to filter things.
 
I checked plotXY and it calls CvMap:: plotINLINE(), which calls coordRange(). The last actually takes map warps into account (something I wasn't actually aware of). This means both approaches should work. There is one tiny difference though and that is CvUtil.plotDirection loops 8 plots while the nested loops loops 9 plots. In other words the question is if you want to include the center plot in the loop.

Copying a piece of code from vanilla seems like a good approach. A fully patched vanilla has very few bugs, which makes it a good example on how to avoid bugs.
 
Thanks for all your help! All this just to try to make Caveman2Cosmos' recurrent volcano eruptions do what I want them to do... fingers crossed!
There is a function to do this:
Code:
for i in range(8):
    plot = CvUtil.plotDirection(x, y, i)
x,y is the center plot. 8 is NUM_DIRECTION_TYPES (which I can't remember offhand what is called in python, but it's always 8)
Oh, for the record, what you want is
Code:
for i in range(8):
    plot = CvUtil.plotDirection(x, y, DirectionTypes(i))
 
Last edited:
Hello as I began the project of creating some custom interfaces the need of evolving flags seemed more relevant than ever. I have already seen flags changing by era but I want more precise things like flags changing if you are communist or "fascist" (it's nation + police state but never really made clear in the game). I suppose the best way to do that would be python but I don't know if it's doable.
My real question: if it's doable, as it been made? How could it be made?
 
Looks like flags are controlled by CvPlayer::getFlagDecal(). In other words you need to mod CvPlayer.cpp, which is in the DLL file.

The function returns the string for each flag and you need to make it return the string suiting for the flag you want to display. This means you need to add code to check civics and alter the returned string accordingly. Alternatively you can set the flag with CvInitCore::setFlagDecal(PlayerTypes eID, const CvWString & szFlagDecal), though I don't think that one is exposed to python either.

You also need to mark all flags dirty when changing civic.

I haven't actually tested this because I never had the need to change flags, but looking at the code and considering how unit art and similar matches eras, it would appear this would be the solution to your question.
 
Thank you for your very quick reply, sadly this is (as I feared) one step above my current skills but I still have hope that one day I will match the russian flag with the red star in the communist interface....
 
Top Bottom