Mod Component Requests Thread

By the way, there is a third way here, and it is the basic landscape that is transformed (a peak into water; or a hill into it). Using an event, as far as I understood.
https://forums.civfanatics.com/resources/planetbuster.11673/

"For modders:
I've added the planetbuster-unitclass and unit at the end of the unitclassinfos.xml and unitinfos.xml
In the CvEventManager.py i've added with tsentom's help this: " And so on
 
Technically, these are actually not different :).
The pioneer tank triggers the improvement-built event, changing the underlying terrain.
The planet buster rocket triggers the nuke explosion event, changing the underlying terrain.

The issue is now why the worker cannot build an improvement :think:.
 
TERRAIN_PEAK does not really matter. It is <bWater>1</bWater> by default, which at one point I hypothesized might have to do with the AI land units recognizing it as impossible, but I recall correctly changing it to <bWater>0</bWater> did nothing. Deleting the terrain type entirely did nothing either.

If you want to be able to use any improvement builds on peaks you will need to modify CvGameUtils.py



I just tested this code in my modmod to see if I could change peaks to hills via building a route instead of an improvement, and I found it works just fine.

Spoiler :

Assets\python\CvEventManager.py
Code:
    def onRouteBuilt(self, argsList):
        'Route Built'
        iRoute, iX, iY = argsList
     
        pPlot = CyMap().plot(iX, iY)
        if iRoute == gc.getInfoTypeForString('ROUTE_MOUNTAIN_PASS'):
            pPlot.setRouteType(-1)
            if pPlot.isPeak():
                pPlot.setPlotType(PlotTypes.PLOT_HILLS, True, True)
     
        if (not self.__LOG_IMPROVEMENT):
            return
        CvUtil.pyPrint('Route %s was built at %d, %d'
            %(gc.getRouteInfo(iRoute).getDescription(), iX, iY))

Assets\XML\Misc\CIV4RouteInfos.xml
Code:
        <RouteInfo>
            <Type>ROUTE_MOUNTAIN_PASS</Type>
            <Description>TXT_KEY_ROUTE_MOUNTAIN_PASS</Description>
            <iValue>3</iValue>
            <iAdvancedStartCost>-1</iAdvancedStartCost>
            <iAdvancedStartCostIncrease>0</iAdvancedStartCostIncrease>
            <iMovement>-1</iMovement>
            <iFlatMovement>-1</iFlatMovement>
            <BonusType>NONE</BonusType>
            <PrereqOrBonuses/>
            <Yields/>
            <TechMovementChanges/>
            <Button>Art/Interface/Buttons/BaseTerrain/Hill.dds</Button>
        </RouteInfo>
Assets\XML\Units\CIV4BuildInfos.xml
Code:
    <BuildInfos>
        <BuildInfo>
            <Type>BUILD_MOUNTAIN_PASS</Type>
            <Description>TXT_KEY_BUILD_MOUNTAIN_PASS</Description>
            <Help/>
            <PrereqTech></PrereqTech>
            <iTime>200</iTime>
            <iCost>0</iCost>
            <bKill>0</bKill>
            <ImprovementType/>
            <RouteType>ROUTE_MOUNTAIN_PASS</RouteType>
            <EntityEvent>ENTITY_EVENT_SHOVEL</EntityEvent>
            <FeatureStructs/>
            <HotKey>KB_R</HotKey>
            <bAltDown>0</bAltDown>
            <bShiftDown>0</bShiftDown>
            <bCtrlDown>0</bCtrlDown>
            <iHotKeyPriority>0</iHotKeyPriority>
            <Button>Art/Interface/Buttons/BaseTerrain/Hill.dds</Button>
        </BuildInfo>
Assets\XML\Units\CIV4UnitInfos.xml
Code:
        <UnitInfo>
            <Class>UNITCLASS_WORKER</Class>
            <Type>UNIT_MUD_GOLEM</Type>
            <Combat>NONE</Combat>
            <Domain>DOMAIN_LAND</Domain>
            <DefaultUnitAI>UNITAI_WORKER</DefaultUnitAI>
            <Description>TXT_KEY_UNIT_MUD_GOLEM</Description>
            <Civilopedia>TXT_KEY_UNIT_MUD_GOLEM_PEDIA</Civilopedia>
            <Strategy>TXT_KEY_UNIT_MUD_GOLEM_STRATEGY</Strategy>
            <Advisor>ADVISOR_ECONOMY</Advisor>
            <bCanMoveImpassable>1</bCanMoveImpassable>
            <bIgnoreTerrainCost>1</bIgnoreTerrainCost>
            <bMechanized>1</bMechanized>
            <UnitAIs>
                <UnitAI>
                    <UnitAIType>UNITAI_WORKER</UnitAIType>
                    <bUnitAI>1</bUnitAI>
                </UnitAI>
            </UnitAIs>
            <Builds>
                <Build>
                    <BuildType>BUILD_MOUNTAIN_PASS</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_ROAD</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_RAILROAD</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_FARM</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_MINE</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_WORKSHOP</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_LUMBERMILL</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_WINDMILL</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_PLANTATION</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_QUARRY</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_PASTURE</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_CAMP</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_WINERY</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_COTTAGE</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_FORT</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_REMOVE_JUNGLE</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_REMOVE_FOREST</BuildType>
                    <bBuild>1</bBuild>
                </Build>
                <Build>
                    <BuildType>BUILD_GRAVEYARD</BuildType>
                    <bBuild>1</bBuild>
                </Build>
            </Builds>
            <iCost>100</iCost>
            <iMoves>3</iMoves>
            <iWorkRate>250</iWorkRate>
            <iXPValueAttack>8</iXPValueAttack>
            <iXPValueDefense>4</iXPValueDefense>
            <UnitMeshGroups>
            <iGroupSize>1</iGroupSize>
            <fMaxSpeed>1.75</fMaxSpeed>
            <fPadTime>1</fPadTime>
            <iMeleeWaveSize>1</iMeleeWaveSize>
            <iRangedWaveSize>0</iRangedWaveSize>
                <UnitMeshGroup>
                    <iRequired>1</iRequired>
                    <EarlyArtDefineTag>ART_DEF_UNIT_MUD_GOLEM</EarlyArtDefineTag>
                </UnitMeshGroup>
            </UnitMeshGroups>
            <FormationType>FORMATION_TYPE_DEFAULT</FormationType>
            <HotKey/>
            <FreePromotions>
                <FreePromotion>
                    <PromotionType>PROMOTION_GOLEM</PromotionType>
                    <bFreePromotion>1</bFreePromotion>
                </FreePromotion>
            </FreePromotions>
            <bDisableUpgradeTo>1</bDisableUpgradeTo>
            <bNeverObsolete>1</bNeverObsolete>
            <iCombatDefense>3</iCombatDefense>
            <iTier>1</iTier>
        </UnitInfo>

However, if you want to block this route from being built on tiles other than peaks then you would need to use CvGameUtils.py anyway, in which case you could just as easily permit the building of an improvement.

Things would be easier if you just wanted your Pioneer Tank (or any worker that could move impassible) to build normal roads or railroads and to make any peak with that route through it to become a peak.


I remember from some of my earliest FfH2 modding attempts many years ago that the AI had a lot of trouble understanding units that could build improvements but not built routes. That might only be if they can build improvements that can connect resources though.

Still, I feel like a route is a more natural choice than an improvement, especially since you can reduce micromanagement by using the Route To Mode (Alt+R) to make it clear a path between the unit's current location and an arbitrary endpoint instead of needing to manually move the unit and issue improvement building orders one tile at a time.
 
Last edited:
The advantage with improvements is that you can make the AI kinda understand what it's happening.
e.g. the CREATE_HILL improvement gives -1 food, +1 production, which are exactly the stats the hill will have at the end.
The AI will not understand the other impacts, but I think on average you normally don't change the improvements that much anway.

Since this seems to work: @hrochland do you need help with adapting this?
(I think I can make these changes to the CvGameUtils.py...)
 
Thank you, everyone. You guys are awesome. I'm looking forward to the weekend to try it out.

CvGameutils from my mod
 

Attachments

  • CvGameUtils.rar
    6.2 KB · Views: 31
Last edited:
Okay, try the attached file with changes.

Please make sure that you have the Python errors activated, because I cannot test it, and therefore do not know if I made any errors :blush:.
 

Attachments

  • CvGameUtils.zip
    6.4 KB · Views: 32
If I'm lucky enough to see professionals in the thread, then I'll try. Platy has a mod component that changes the resource model to something between civ5 and civ 6. That is, one copy of resources is not enough for the endless production of units, a copy is needed for each unit. At the same time, resources accumulate. However, you cannot specify the consumption of multiple copies of the same resource.
https://forums.civfanatics.com/thre...sant-posh-python.497337/page-44#post-12851573
https://forums.civfanatics.com/resources/manufactured-resources.21936/ - the actual code

"Certain Resources produce X New Resources Per Y Turns.
These new resources can then be set as requirements for units or whatever.
Units consume 1 copy of these resources when built."

"D) Currently, it is all set to consume just 1 copy of each resource when unit built.
1) Unit Created however, does not consume because that requires onUnitCreated callback, you can shift it there if you like
2) If you want to define more copies per unit, such as 3 Bananas per Monkey, then that requires (i) cannotTrain callback (ii) Long list of units and consumables, which means can be done but I am lazy to do so :D"

The problem is that the metal consumption of the knight and the militia differed dozens of times. Then there were battleships weighing 2,000,000 knight armor:D. Or 2000 medium tanks (a dozen German divisions). In general, it is impossible to build a normal military-economic model based on the current code. At the same time, it was very large differences in the cost of maintenance and resource intensity of "units" that determined the structure of armies in reality.
However, while I figure out programming, civ 4 will move into the field of archaeology.
Is there a good Samaritan who can help me? At least explaining what the author meant? I am tormented by the idea that by combining components already available on the forum or in mods, you can create realistic and interesting game mechanics. Perhaps it's not just me she's secretly tormenting.
 
Last edited:
For #2 The base is that platyping was simply to lazy to make a long list.
e.g. if you think about everyhting what needs iron... let's say swordsman 1 iron, pikeman 1 iron, maceman 1 iron, knight 1 iron, ironclad 3 iron, tank 5 iron, bomber 5 iron, etc. the list goes on. He was simply to lazy for that.
You can do it, but it's a bit busy work.

For #1, there is a difference between building a unit, and creating a unit, as far as I remember. The latter includes upgraded units (so in this example here, I guess upgrading a warrior to a swordsman would not consume iron), gifted units, units from goody huts, etc.
So right now in this mod only building a unit consumes a resource, but not if you get them in another way.
 
Oh, no, sorry, from the technical point of view, you can't modify this in the XML.
That needs some python code, although also there making the list to specify which unit does need how much is probably the most annoying.
I might be able to plug that in (not sure, as said above, my civ-related knowledge there is getting rusty), but you'd need to provide me the list first.
 
but you'd need to provide me the list first.

Thanks a lot again. Hmm. The list even looks big beforehand and will expand at the same time. Including at the expense of new resources. It would be nice to just get the code for an arbitrary unit (the same spearman) with N copies of the resource. In the future I will use it as a template. If, of course, each unit needs a specific code outside of XML.
 
Great, I will be very grateful. This is really one of the very few key points of mod, I can do without the rest or add later.
 
Thanks a lot again. Hmm. The list even looks big beforehand and will expand at the same time. Including at the expense of new resources. It would be nice to just get the code for an arbitrary unit (the same spearman) with N copies of the resource. In the future I will use it as a template. If, of course, each unit needs a specific code outside of XML.

No, that shouldn't be necessary.
I'll try to have a look at it over the weekend. If you don't hear back from my latest Sunday evening, then ping me.

I'm afraid that I don't understand parts of the code, and I can't test anything, since I don't have Civ4 anymore.
-> I'm sorry, can't make these changes :(.
 
I'm sorry, but maybe I got something wrong somewhere, the thing about turning a peak into a hill just doesn't work for me.

I was still wondering if you don't have BUGmod in your mode. I don't have it and I don't know if it's not a mistake ..
 
Top Bottom