Barbarian Unit Capture!

Protagonist

Warlord
Joined
Mar 10, 2014
Messages
175
I was thinking I'd like to build a mod where the Barbarians can capture units. Basically, whenever they defeat a unit of yours, there's an X% chance that that unit joins their side rather than die.

Basically, it turns the Barbarians into a zombie horde.

Anyone have an idea how this could be done?
 
Give the Barbarian Units this promotion:
<Row>
<Type>PROMOTION_BITE</Type>
<Description>TXT_KEY_PROMOTION_BITE</Description>
<Help>TXT_KEY_PROMOTION_BITE_HELP</Help>
<Sound>AS2D_IF_LEVELUP</Sound>
<CannotBeChosen>true</CannotBeChosen>
<CaptureDefeatedEnemy>true</CaptureDefeatedEnemy>
<PortraitIndex>2</PortraitIndex>
<IconAtlas>PROMOTION_ATLAS</IconAtlas>
<PediaType>PEDIA_ATTRIBUTE</PediaType>
<PediaEntry>TXT_KEY_PROMOTION_BITE</PediaEntry>
</Row>
 
Or this very similar bit:
Spoiler :
Code:
<GameData>
	<UnitPromotions>
		<Row>
			<Type>PROMOTION_CAPTURE</Type>
			<Description>TXT_KEY_PROMOTION_CAPTURE</Description>
			<Help>TXT_KEY_PROMOTION_CAPTURE_HELP</Help>
			<Sound>AS2D_IF_LEVELUP</Sound>
			<CannotBeChosen>true</CannotBeChosen>
			<CaptureDefeatedEnemy>true</CaptureDefeatedEnemy>
			<PortraitIndex>6</PortraitIndex>
			<IconAtlas>KRIS_SWORDSMAN_PROMOTION_ATLAS</IconAtlas>
			<PediaType>PEDIA_ATTRIBUTE</PediaType>
			<PediaEntry>TXT_KEY_PROMOTION_CAPTURE</PediaEntry>
		</Row>
	</UnitPromotions>
	<Language_en_US>
		<!-- PROMOTION_CAPTURE -->

		<Row Tag="TXT_KEY_PROMOTION_CAPTURE">
			<Text>Capture</Text>
		</Row>
		<Row Tag="TXT_KEY_PROMOTION_CAPTURE_HELP">
			<Text>Defeated enemy units join your side</Text>
		</Row>
		<Update>
			<Where Tag="TXT_KEY_EUPANEL_CAPTURE_CHANCE" />
			<Set Text="[COLOR_CYAN]Capture Chance if Defeated: {1_Percent}%[ENDCOLOR]" />
		</Update>
	</Language_en_US>
	<Unit_FreePromotions>
		<Row>
			<UnitType>UNIT_BARBARIAN_SPEARMAN</UnitType>
			<PromotionType>PROMOTION_CAPTURE</PromotionType>
		</Row>
		<Row>
			<UnitType>UNIT_BARBARIAN_SWORDSMAN</UnitType>
			<PromotionType>PROMOTION_CAPTURE</PromotionType>
		</Row>
		<Row>
			<UnitType>UNIT_BARBARIAN_ARCHER</UnitType>
			<PromotionType>PROMOTION_CAPTURE</PromotionType>
		</Row>
		<Row>
			<UnitType>UNIT_BARBARIAN_HORSEMAN</UnitType>
			<PromotionType>PROMOTION_CAPTURE</PromotionType>
		</Row>
		<Row>
			<UnitType>UNIT_BARBARIAN_AXMAN</UnitType>
			<PromotionType>PROMOTION_CAPTURE</PromotionType>
		</Row>
		<Row>
			<UnitType>UNIT_BARBARIAN_WARRIOR</UnitType>
			<PromotionType>PROMOTION_CAPTURE</PromotionType>
		</Row>
	</Unit_FreePromotions>
</GameData>
Though it won't cover the "standard" units the barbarians can use.
 
Is there a way to make the promotion only capture certain units? For example, could you make it capture a tank unit but not infantry?
No, not directly. It could be done, but would require a fair amount of lua mechanics because barbarians are allowed to have infantry, so it would be necessary to figure out a method to tell the difference between a naturally-occuring Barb Infantry unit and a "captured" Barb Infantry unit.

In lua there's a Unit:GetOriginalOwner() but I am pretty sure it will not apply since I am pretty sure when a unit is "captured" the original unit is destroyed and a new unit is created in its place. So the Unit:GetOriginalOwner() would give you the Barb "Civ" in all cases, I think.

The same issue would apply for any unit that the Barbs are allowed to spawn "naturally".

[edit]It would probably be more direct and easy to simply create an lua program that always looks at whether the Barbs have killed off an enemy unit, and if so, which unit type was the one killed. If it is the desired unit(s), then spawn a new barbarian unit of the type just killed. That would be a relatively straightforward piece of lua code.
 
...By giving the promotion to all the civ's units, yes... which doesn't alleviate the problem.

If you're planning to make a zombie horde, though, wouldn't it make more sense for them to be able to capture infantry rather than tanks? :hmm:
 
...By giving the promotion to all the civ's units, yes... which doesn't alleviate the problem.

If you're planning to make a zombie horde, though, wouldn't it make more sense for them to be able to capture infantry rather than tanks? :hmm:
Two different people are asking similar but not identical questions
 
Would it be possible to just make it an ability of the faction itself?
Hmmm...UA are tied to the leader trait. I'd have to double-check whether the barbarians even have a leader in the usual sense.


But the promotion could be given via lua any time a barbarian unit was spawned. But it would require adding Machiavelli24's Unit Created Good system into the mod. I don't have the link to Machiavelli's thread handy.
 
I'm pretty sure the Barbarians have a leader (there was a screenshot in the funny screenshots thread involving trying to do diplomacy with the barbarians, which have no real diplo screen), but I'll check too.
EDIT: Well... there doesn't seem to be an XML file for a barbarian leader, no. This will be hard to prove expect by delving into the source code.

As for Machiavelli: Steam download for Unit Created Event ; Mod Maker Snippet Thread
 
The Barbarians' leader is called 'Barbarian of Barbarians.' I've seen several screenshots where they captured a city state and were thus in the running diplomatically.
 
Sorry to bump this thread. This is not a question specifically for a leader ability or for barbarians, but does concern the <CaptureDefeatedEnemy> in the UnitPromotions xml file. If I wanted to make an promotion for an infantry unit to be able to capture mechanical (artillery or tank) unit but not other infantry units (or other figure units), is that possible. I've played around w/ XML only, and can't figure a way out. I tried the <Capture> function for the Units.xml file, which apparently only applies to non-military units (it's the function that tells a settler to be captured and turned into a worker). I also looked through to see if there was a function that would preclude a unit capture, but can't find that either.

Just wondering if anyone has ever tried this for lua or another form of mod. It would help greatly as I'm trying to make the German stormtrooper units in my WW1 mod able to capture tanks but not other infantry units.

Thanks!
-Smitty
 
Top Bottom