Newbie Modding Question

Lplate

Esus (Allegedly)
Joined
Feb 8, 2011
Messages
578
Location
Ireland
Hi,

I'm trying to start off learning to mod by doing a relatively simple one.

Initial idea is dwarven siblings. Essentially, low level hero units that are available to several civilisations based on events. My problem is that I want the siblings to preferentially target each other in any combat where they are present in the stacks. I thought that UnitClassTargets, UnitCombatTargets, UnitClassDefenders or UnitCombatDefenders would be the way to make it happen but can't get it to work.
Any suggestions??

The other part of my mod would be "Adepts of the Age" - weak adepts with an affinity for the mana types from the different schools: Alteration, etc. As these are supposed to be the best students of their classes, I want them to automatically upgrade to Channelling II when they have the right amount of experience.
How to you link events to levels gained? Can this be done just through XML? Is the neater solution to simply have the adepts upgradable to "Mage of the Age" who has Channelling II when the right tech is researched?

thanks,
Lplate
 
My problem is that I want the siblings to preferentially target each other in any combat where they are present in the stacks.

As far as I know, all targetting is handled in the DLL

I thought that UnitClassTargets, UnitCombatTargets, UnitClassDefenders or UnitCombatDefenders would be the way to make it happen but can't get it to work.

These tags are not used by the DLL at all. I expect they were part of a system that was never implemented. Or made available for modders to adapt. Either way, those tags are useless unless someone creates code for them.

Is the neater solution to simply have the adepts upgradable to "Mage of the Age" who has Channelling II when the right tech is researched?

That's probably the easiest method, and it matches how regular adepts upgrade.
 
Either way, those tags are useless unless someone creates code for them.

MoM seems to use UnitCombatTarget. (The Luonnotar vs. Disciple units.) One of the other modmods might use some of the tags, too.
 
Thanks for the feedback.
 
As far as I know, all targetting is handled in the DLL



These tags are not used by the DLL at all. I expect they were part of a system that was never implemented. Or made available for modders to adapt. Either way, those tags are useless unless someone creates code for them.



That's probably the easiest method, and it matches how regular adepts upgrade.

Are you sure of that? I use the tags in my modmod, and they seem to work fine.

UnitCombatTargets is used in vanilla BtS, by a unique unit that targets mounted units.

Note that Firaxis did not intend for the targeting mechanism to work in cities, only out in the field.






For the other issue, it is very easy in base FfH too if you don't mind using a little python in a way that most programmers consider bad form: make a spell that handles all its effects in its prereqs. The spell itself won't show up, as the prereq never tells it that it can never be cast, but the prereq code is called every time the unit is selected or moved and allows for some very powerful passive effects that don't require any special player action or knowledge. I find this trick too powerful not to use my my modmod.

Code:
in CIV4SpellInfos.xml add:
        <SpellInfo>
            <Type>SPELL_MAGE_OF_AGE</Type>
            <Description>TXT_KEY_NO_PLAYER_WILL_EVER_READ_THIS</Description>
            <Civilopedia>TXT_KEY_SPELL_PLACEHOLDER_PEDIA</Civilopedia>
            <UnitPrereq>UNIT_ADEPT_OF_AGE</UnitPrereq>
            <TechPrereq>TECH_ALTERATION</TechPrereq>
            <bAllowAI>1</bAllowAI>
            <iCasterMinLevel>4</iCasterMinLevel>
            <bIgnoreHasCasted>1</bIgnoreHasCasted>
            <bAbility>1</bAbility>
            <PyRequirement>effectMageOfAge(pCaster)</PyRequirement>
            <Effect>EFFECT_SPELL1</Effect>
            <Sound>AS3D_SPELL_TRAIN</Sound>
            <bGraphicalOnly>1</bGraphicalOnly>
            <Button>Art/Interface/Buttons/Units/Adept.dds</Button>
        </SpellInfo>


In CVSpellInterface.py add either this:

def effectMageOfAge(pCaster):
	if not pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING2')):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING2'), True)
	return False


or this:


def effectMageOfAge(pCaster):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_MAGE_OF_AGE'), pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
	newUnit.convert(pCaster)
	return False

The second python option still requires that you add a new unit, but it runs more efficiently as the python is never called again for the same unit once it has done its job. The code is simple enough that the first way probably wouldn't cause noticeable lag unless every civ spammed nothing but those units though.


If you omit the bIgnoreHasCasted it would only be called if the unit had not cast a spell yet that turn. If you omit bAbility, then the Illian worldspell would prevent the upgrade. The code does not run constantly, so once you level up a unit you'll either have to click it again or move it to have the effect. You could also get rid of the xml level prereq and add an experience prereq in python if you prefer the free channeling promotion to be gained before the user spends the xp.



You know, if you want to emphasize the specialization of the adepts of the age, it might be better to give them higher levels of the appropriate spell spheres automatically instead of channeling promotions.
 
Are you sure of that? I use the tags in my modmod, and they seem to work fine.

After a second look, I have to agree that you are correct. There is some code regarding those tags in the DLL that's kind of buried. It seems to only be referenced in the isTargetOf() function, which I've never looked at before, so I don't really know how those tags are supposed to work.
 
For the other issue, it is very easy in base FfH too if you don't mind using a little python in a way that most programmers consider bad form: make a spell that handles all its effects in its prereqs. The spell itself won't show up, as the prereq never tells it that it can never be cast, but the prereq code is called every time the unit is selected or moved and allows for some very powerful passive effects that don't require any special player action or knowledge. I find this trick too powerful not to use my my modmod.

I know this isn't the point of the thread, but this is a tip I'll have to remember.
 
Hi,

I've managed to create the fratricidal dwarves:). The xml code I used to get them to single each other out for combat was:

Spoiler :
<UnitClassTargets>
<UnitClassTarget>
<UnitClassTargetType>UNITCLASS_SIBLING</UnitClassTargetType>
<bUnitClassTarget>1</bUnitClassTarget>
</UnitClassTarget>
</UnitClassTargets>
<UnitCombatTargets>
</UnitCombatTargets>
<UnitClassDefenders>
<UnitClassDefender>
<UnitClassDefenderType>UNITCLASS_SIBLING</UnitClassDefenderType>
<bUnitClassDefender>1</bUnitClassDefender>
</UnitClassDefender>
</UnitClassDefenders>



Lplate
 
Works fine. I sent one sibling against a stack with everything from Auric Ascended down and it was still his brother who faced off against him.

Lplate
 
Back
Top Bottom