Adding UnitCommands like Contribute to Wonder to a new unit

anansethespider

Warlord
Joined
Oct 27, 2016
Messages
288
I want to make a unit called Slave that all civs have access to that can contribute to both wonders and districts. I've tried a few iterations of code and here's where I'm at now:

<?xml version="1.0" encoding="utf-8"?>
<GameInfo>
<Types>
<Row Type="UNIT_SLAVE" Kind="KIND_UNIT"/>
</Types>
<UnitReplaces>
</UnitReplaces>
<UnitAiInfos>
<Row UnitType="UNIT_SLAVE" AiType="UNITAI_BUILD"/>
<Row UnitType="UNIT_SLAVE" AiType="UNITTYPE_CIVILIAN"/>
</UnitAiInfos>
<Tags>
</Tags>
<TypeTags>
</TypeTags>
<Units>
<Row UnitType="UNIT_SLAVE" BaseMoves="2" Cost="50" AdvisorType="ADVISOR_GENERIC" BaseSightRange="2" ZoneOfControl="false" Domain="DOMAIN_LAND" FormationClass="FORMATION_CLASS_CIVILIAN" Name="LOC_UNIT_SLAVE_NAME" Description="LOC_UNIT_SLAVE_DESCRIPTION" CanCapture="False" PurchaseYield="YIELD_GOLD" BuildCharges="5"/>
</Units>
<Improvement_ValidBuildUnits>
<Row ImprovementType="IMPROVEMENT_FARM" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_MINE" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_QUARRY" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_FISHING_BOATS" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_PASTURE" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_PLANTATION" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_CAMP" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_LUMBER_MILL" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_OIL_WELL" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_OFFSHORE_OIL_RIG" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_BEACH_RESORT" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_FORT" UnitType="UNIT_MILITARY_ENGINEER"/>
<Row ImprovementType="IMPROVEMENT_AIRSTRIP" UnitType="UNIT_MILITARY_ENGINEER"/>
<Row ImprovementType="IMPROVEMENT_MISSILE_SILO" UnitType="UNIT_MILITARY_ENGINEER"/>
<!--Unique Improvements -->
<Row ImprovementType="IMPROVEMENT_CHATEAU" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_COLOSSAL_HEAD" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_GREAT_WALL" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_KURGAN" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_MISSION" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_ROMAN_FORT" UnitType="UNIT_ROMAN_LEGION"/>
<Row ImprovementType="IMPROVEMENT_SPHINX" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_STEPWELL" UnitType="UNIT_SLAVE"/>
<Row ImprovementType="IMPROVEMENT_ZIGGURAT" UnitType="UNIT_SLAVE"/>
</Improvement_ValidBuildUnits>
<UnitUpgrades>
</UnitUpgrades>
<Modifiers>

<Row>
<ModifierId>SLAVE_WONDER_PERCENT</ModifierId>
<ModifierType>MODIFIER_PLAYER_ADJUST_UNIT_WONDER_PERCENT</ModifierType>
</Row>
<Row>
<ModifierId>SLAVE_DISTRICT_PERCENT</ModifierId>
<ModifierType>MODIFIER_PLAYER_ADJUST_UNIT_DISTRICT_PERCENT</ModifierType>
</Row>
</Modifiers>
<ModifierArguments>
<Row>
<ModifierId>SLAVE_DISTRICT_PERCENT</ModifierId>
<Name>Amount</Name>
<Value>20</Value>
</Row>
<Row>
<ModifierId>SLAVE_WONDER_PERCENT</ModifierId>
<Name>Amount</Name>
<Value>10</Value>
</Row>
</ModifierArguments>
<RequirementSets>
<Row>
<RequirementSetId>UNIT_IS_SLAVE_REQUIREMENTS</RequirementSetId>
<RequirementSetType>REQUIREMENTSET_TEST_ALL</RequirementSetType>
</Row>
</RequirementSets>
<RequirementSetRequirements>
<Row>
<RequirementSetId>UNIT_IS_SLAVE_REQUIREMENTS</RequirementSetId>
<RequirementId>REQUIRES_UNIT_IS_SLAVE</RequirementId>
</Row>
</RequirementSetRequirements>
<Requirements>
<Row>
<RequirementId>REQUIRES_UNIT_IS_SLAVE</RequirementId>
<RequirementType>REQUIREMENT_UNIT_TYPE_MATCHES</RequirementType>
</Row>
</Requirements>
<RequirementArguments>
<Row>
<RequirementId>REQUIRES_UNIT_IS_SLAVE</RequirementId>
<Name>UnitType</Name>
<Value>UNIT_SLAVE</Value>
</Row>
</RequirementArguments>
</GameInfo>




Note that this establishes a requirementset and a modifier, but doesn't attach either of them to anything. I've tried numerous ways of attaching, from Civics to Traits and nothing seems to work. Anyone see what I'm doing wrong?
 
I don't think there is anyway to make this work as the game currently exists.

In the DynamicModifiers table, MODIFIER_PLAYER_ADJUST_UNIT_WONDER_PERCENT has a scope of COLLECTION_OWNER, meaning it applies at the highest level of a Player (that is, not to individual units). So what your code is currently saying is "If this Player is a Slave unit..." which is never true.

The only use I can find for MODIFIER_PLAYER_ADJUST_UNIT_WONDER_PERCENT is to give Qin a bonus to builders. The ModifierArguments for his ability allows you to set a percent, but not a unit. That means the ability is most likely hard-coded to Builders. If you could change it, the most likely way to do it would be to have a ModifierArgument with a Name like "UnitType." Because there isn't one, I don't think its possible to give another unit this ability.
 
It looks to me like isau is right. The closest thing I could find was a UnitCommand for Wonder production. Can you just duplicate the builder unit, change the name, and add it as a unit ability?
 
You can't parse out the Wonder Production ability. EVERY unit with Build Charges gets it, even if it can't build anything else. Same with forests. As soon as you give ANY unit build charges, AND you have the right Modifier/Ability to contribute to a Wonder (or to a District, for that matter - I think it's because both are essentially districts), that unit will have the ability to plant forests and contribute production to wonders/districts. I've tested this quite extensively, e.g. by giving build charges to the missionary unit.

There is no way way to parse out any of the UnitCommands because the underlying elements are not exposed to XML in any meaningful way. We only get descriptions and a few meaningless conditions. It's hardcoded, as far as I can tell. In Lua, that's another matter. There are a few promising functions and events, but even in LUA it is probably not within our reach at the moment.

So, to answer your question, yes you can create a unit and give it build charges. But the modifier/effect comes from COLLECTION_OWNER level (as far as I remember), and all of that civ's units with build charges would get the ability. So, no.

OH, and, yeah... ANY unit with build charges can also do remove_feature and remove_improvement and harvest_resource.
 
Back
Top Bottom