LeeS
Imperator
Here is the portion of the code that will add +1 population to the player's capital every time an enemy combat unit is killed by the player within the player's territory:
You'll have to change CIVILIZATION_RUSSIA to the correct name for your civ. I tested using Russia and killed off a Barb in my territory: everything seemed to work properly.
The unit 'killing' event requires that:
Spoiler :
Code:
local iRequiredCivilizationID = GameInfoTypes.CIVILIZATION_RUSSIA
local tRequiredPlayerID = { ["NONE"] = " no player has been identified as the civilization" }
for PlayerID = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
if Players[PlayerID]:GetCivilizationType() == iRequiredCivilizationID then
if tRequiredPlayerID["NONE"] then
tRequiredPlayerID = {}
end
tRequiredPlayerID[PlayerID] = PlayerID
end
end
function EnemyKilledInPlayerTerritory(iOwner, iUnit, iUnitType, iX, iY, bDelay, iKiller)
local iRequiredPlayerID = "NONE"
if tRequiredPlayerID[iKiller] then
iRequiredPlayerID = tRequiredPlayerID[iKiller]
else
return
end
if bDelay then
if iKiller ~= iOwner then
local pPlot = Map.GetPlot(iX, iY)
if pPlot:GetOwner() == iRequiredPlayerID then
local pKilledUnit = Players[iOwner]:GetUnitByID(iUnit)
if pKilledUnit:IsCombatUnit() then
local pPlayer = Players[iRequiredPlayerID]
local pUnitOwner = Players[iOwner]
if Teams[pPlayer:GetTeam()]:IsAtWar(pUnitOwner:GetTeam()) then
local pCapitalCity = pPlayer:GetCapitalCity()
pCapitalCity:ChangePopulation(1, true)
end
end
end
end
end
end
GameEvents.UnitPrekill.Add(EnemyKilledInPlayerTerritory)
The unit 'killing' event requires that:
- The killed unit has to be a combat unit. UnitPreKill fires for anything: Workers, Great People, Combat Units, Missionaries, etc. Thus the requirement for a combat unit.
- The killer has to be your civ. So if an ally kills an enemy in your territory nothing will happen. Otherwise the logic of the code is too much a
and after a couple aborted attempts to think it through....
- The two players actually have to be at war. (Barbs are always seen as being at war with 'regular' players). This extra requirement is an insurance policy against any 'oddball' conditions introduced by other mods, such as attrition systems or what have you.
I'm not certain why the dynamic policy system would be needed. CapitalUnhappinessMod is a table that's already defined in XML; it's used in the Monarchy policy, under the Tradition branch.
- CapitalUnhappinessMod is a column within table Policies.
- While any dummy policy can include the column with a value specification, such as:
Code:
<CapitalUnhappinessMod>-10</CapitalUnhappinessMod>
- Or you need ten different policies each with an increased setting for <CapitalUnhappinessMod>: one would for example have "-10", the next "-20", the next "-30", etc. And then you have to swap-out the policy with the lower setting for the policy with the next higher setting. Essentially this is what the Dynamic Policy System will do.
- It really depends on what you want