Building granting promotion to specific units

Rob (R8XFT)

Ancient Briton
Retired Moderator
Joined
Aug 11, 2002
Messages
10,871
Location
Leeds (UK)
In Anno Domini, I have three different chariot units; the main two come out with "Chariotry" - one being the normal ranged unit, the other is a melee unit. I would like to have a chariot maker building available with "Chariotry" also - but giving a bonus to these specific units (and none other). Is there any way of doing this?
 
Can't you create your promotion in such a way so that it is only applicable on the one unit it's meant to be given to, then have that building hand it out via some flavor of free promotion?
 
I don't know about XML, but Lua-wise, if you use Machiavelli's Unit Created snippet or whoward's DLL (it has a GameEvents for that), checking on creation the unit's plot you can get the city and check for the Building, adding the Chariotry-related Promotion directly to the unit! :D
Sounds complex, but I'll look into it, thanks!

Can't you create your promotion in such a way so that it is only applicable on the one unit it's meant to be given to, then have that building hand it out via some flavor of free promotion?
That's what I'm thinking: the question is how?
 
If using Machiavelli's, this should suffice:
Code:
function ChariotryPromotion(playerID, unitID)
	local pPlayer = Players[playerID]
	local pUnit = pPlayer:GetUnitByID(unitID)
	local pPlot = pUnit:GetPlot()
	local pCity = pPlot:GetPlotCity()
	if pPlot:IsCity() and pCity:IsHasBuilding(GameInfoTypes["BUILDING_CHARIOTRY"]) and pUnit:GetUnitType() == GameInfoTypes["UNIT_CHARIOT_TYPE_II"] then
		pUnit:SetHasPromotion(GameInfoTypes["PROMOTION_CHARIOTRY"], true)
	end
end
LuaEvents.SerialEventUnitCreatedGood.Add(ChariotryPromotion)

Using whoward's:
Code:
function ChariotryPromotion(iPlayer, iUnit, iUnitType, iPlotX, iPlotY)
	local pPlayer = Players[iPlayer]
	local pUnit = pPlayer:GetUnitByID(iUnit)
	local pPlot = Map.GetPlot(iPlotX, iPlotY) -- or local pPlot = pUnit:GetPlot()
	local pCity = pPlot:GetPlotCity()
	if pPlot:IsCity() and pCity:IsHasBuilding(GameInfoTypes["BUILDING_CHARIOTRY"]) and pUnit:GetUnitType() == GameInfoTypes["UNIT_CHARIOT_TYPE_II"] then
		pUnit:SetHasPromotion(GameInfoTypes["PROMOTION_CHARIOTRY"], true)
	end
end
GameEvents.UnitCreated.Add(ChariotryPromotion)

Basically the same thing, so, the choice is yours. :D
 
Brilliant - thank-you!! I've been thinking about it and I might just assign regularly available promotions to the chariotry units - but I am presuming that the promotions will only be given automatically to chariots build in cities where a chariot maker already exists. Is that correct?
 
Can't you create your promotion in such a way so that it is only applicable on the one unit it's meant to be given to, then have that building hand it out via some flavor of free promotion?
Unfortunately the way both <FreePromotion> and <TrainedFreePromotion> work is controlled not so much by the building as by the way the promotion works. Any unit that can accept the promotion is given the promotion. The way that the promotions system works is it will be based generally on UnitCombatType and not on the individual unit (<UnitPromotions_UnitCombats>). Promotions that are tied within the Units & Promotions systems to individual units within a class or within a UnitCombatType are given the promotion immediately upon creation regardless of where or how they are created or what buildings are present in the city where the unit was built (<Unit_FreePromotions>). There's no table within the promotions system so far as I know of that specifies a specific unit is allowed a promotion but don't also give the unit the promotion whenever the unit is created.

And for others looking at this thread in some unknowable future:
  1. <FreePromotion> should be used with world or national wonders because it gives a specified promotion to all units everywhere on the game map for the empire that constructs the building. This gifting-out of the promotion is instantaneous with the completion of the building, and continues in it's effect throughout the rest of the game. As I mentioned above, each individual unit has to be the correct sort for the promotion in question, so you can't in this way for example give a navy-unit-only promotion to land units.
  2. <TrainedFreePromotion> only affects units created in the same city where the building or wonder is built, and only those units that are built or purchased in the city after the building is completed. As I mentioned above, each individual unit has to be the correct sort for the promotion in question, so you can't in this way for example give a navy-unit-only promotion to land units.
 
Yeah, I was thinking of TrainedFreePromotion, but it was late, so I wasn't able to look into the code.

That would work well if his units are of their own unique combat class, though. However, I'm not sure what's involved in creating a new combat class entirely.
 
However, I'm not sure what's involved in creating a new combat class entirely.
I think that may be the brick wall in waiting for you to bang your head against. I'm not sure what all would be required either to get it to work.
 
IIRC you can easily create a new combat class, but no animations play for units assigned to that class
 
IIRC you can easily create a new combat class, but no animations play for units assigned to that class
For mods that don't use later eras, however, you can recycle existing ones. I use UNITCOMBAT_GUN for horse-mounted archers and UNITCOMBAT_ARMOR for elephant-mounted units. That lets me keep all UnitCombats "clean" so I can use them for promotion assignments.
 
Top Bottom