--First define ability:
INSERT INTO Tags (Tag, Vocabulary) VALUES ('CLASS_TIRAMOD_GRANT_ABILITY', 'ABILITY_CLASS');
INSERT INTO Types (Type, Kind) VALUES ('ABILITY_TIRAMOD_GRANT_SOME_ABILITY', 'KIND_ABILITY');
INSERT INTO TypeTags (Type, Tag) VALUES ('ABILITY_TIRAMOD_GRANT_SOME_ABILITY', 'CLASS_TIRAMOD_GRANT_ABILITY');
INSERT INTO UnitAbilities (UnitAbilityType, Name, Description) VALUES ('ABILITY_TIRAMOD_GRANT_SOME_ABILITY', 'LOC_ABILITY_TIRAMOD_GRANT_SOME_ABILITY_NAME', 'LOC_ABILITY_TIRAMOD_GRANT_SOME_ABILITY_DESCRIPTION');
INSERT INTO UnitAbilityModifiers (UnitAbilityType, ModifierId) VALUES ('ABILITY_TIRAMOD_GRANT_SOME_ABILITY', 'TIRAMOD_SOME_MODIFIER');
INSERT INTO Modifiers (ModifierId, ModifierType, Permanent, SubjectRequirementSetId) VALUES ('TIRAMOD_SOME_MODIFIER', 'MODIFIER_ALL_UNITS_GRANT_ABILITY', 1, 'TIRAMOD_ON_SAME_PLOT_REQUIREMENTS');
INSERT INTO ModifierArguments (ModifierId, Name, Value) VALUES ('TIRAMOD_SOME_MODIFIER', 'AbilityType', 'ABILITY_GREAT_GENERAL_MOVEMENT');
INSERT INTO RequirementSetRequirements (RequirementSetId, RequirementId) VALUES ('TIRAMOD_ON_SAME_PLOT_REQUIREMENTS', 'TIRAMOD_ADJACENT_UNIT_REQUIREMENT');
INSERT INTO RequirementSets (RequirementSetId, RequirementSetType) VALUES ('TIRAMOD_ON_SAME_PLOT_REQUIREMENTS', 'REQUIREMENTSET_TEST_ALL');
INSERT INTO Requirements (RequirementId, RequirementType) VALUES ('TIRAMOD_ADJACENT_UNIT_REQUIREMENT', 'REQUIREMENT_PLOT_ADJACENT_TO_OWNER');
INSERT INTO RequirementArguments (RequirementId, Name, Value) VALUES ('TIRAMOD_ADJACENT_UNIT_REQUIREMENT', 'MinDistance', 0);
INSERT INTO RequirementArguments (RequirementId, Name, Value) VALUES ('TIRAMOD_ADJACENT_UNIT_REQUIREMENT', 'MaxDistance', 0);
--Now define new unit:
INSERT INTO Types (Type, Kind) VALUES ('UNIT_TIRAMOD_DUMMY_SUPPORT', 'KIND_UNIT');
INSERT INTO TypeTags (Type, Tag) VALUES ('UNIT_TIRAMOD_DUMMY_SUPPORT', 'CLASS_TIRAMOD_GRANT_ABILITY');
INSERT INTO Units (UnitType, Name, Description, BaseSightRange, BaseMoves, Domain, FormationClass, Cost) VALUES ('UNIT_TIRAMOD_DUMMY_SUPPORT', 'LOC_UNIT_TIRAMOD_DUMMY_SUPPORT_NAME', 'LOC_UNIT_TIRAMOD_DUMMY_SUPPORT_DESCRIPTION', 3, 2, 'DOMAIN_LAND', 'FORMATION_CLASS_CIVILIAN', 10 );
local iPlayerID = 0
local iX, iY = 5, 18
local pUnit = UnitManager.InitUnit(iPlayerID , "UNIT_TIRAMOD_DUMMY_SUPPORT", iX, iY)
UnitManager.Kill(pUnit, false)
My only problem is that it would be very cumbersome to write the SQL code for each existing ability in the game. So now I wonder, whether it is possible to create the SQL rows automatically for each ability using something like a while loop in SQL.
-- Add a Culture Bomb to every wonder
INSERT INTO Modifiers
(ModifierID, ModifierType, RunOnce, Permanent, OwnerRequirementSetId, SubjectRequirementSetId)
SELECT 'QUO_WONDER_CULTURE_BOMB_' || BuildingType, 'MODIFIER_PLAYER_ADD_CULTURE_BOMB_TRIGGER', 0, 0, NULL, NULL
FROM Buildings WHERE Buildings.IsWonder=1 ;
INSERT INTO ModifierArguments
(ModifierID, Name, Type, Value, Extra, SecondExtra)
SELECT 'QUO_WONDER_CULTURE_BOMB_' || BuildingType, 'BuildingType', 'ARGTYPE_IDENTITY', BuildingType, NULL, NULL
FROM Buildings WHERE Buildings.IsWonder=1 ;
-- Only apply the modifiers if the culture bomb ability is enabled in MyOptions
INSERT INTO TraitModifiers
(TraitType, ModifierID)
SELECT 'TRAIT_LEADER_MAJOR_CIV', 'QUO_WONDER_CULTURE_BOMB_' || BuildingType
FROM Buildings WHERE Buildings.IsWonder=1 AND (SELECT tblquoOptions.Value FROM tblQuoOptions WHERE tblQuoOptions.OptionID='QUO_OPTION_CAN_WONDERS_CULTURE_BOMB') >0 ;
--Hook modifiers to abilities:
INSERT INTO UnitAbilityModifiers (UnitAbilityType, ModifierId)
SELECT 'ABILITY_ZZZ_TIRAMOD_GRANT_' || Type,
'TIRAMOD_GRANT_' || Type || '_MODIFIER'
FROM Types WHERE Types.Kind='KIND_ABILITY' ;
INSERT INTO Modifiers (ModifierId, ModifierType, Permanent, SubjectRequirementSetId)
SELECT 'TIRAMOD_GRANT_' || Type || '_MODIFIER',
'MODIFIER_ALL_UNITS_GRANT_ABILITY',
1,
'TIRAMOD_ON_SAME_PLOT_REQUIREMENTS'
FROM Types WHERE Types.Kind='KIND_ABILITY' ;
INSERT INTO ModifierArguments (ModifierId, Name, Value)
SELECT 'TIRAMOD_GRANT_' || Type || '_MODIFIER',
'AbilityType',
Type
FROM Types WHERE Types.Kind='KIND_ABILITY' ;
--Define Requirements:
INSERT INTO RequirementSetRequirements (RequirementSetId, RequirementId)
VALUES ('TIRAMOD_ON_SAME_PLOT_REQUIREMENTS',
'TIRAMOD_ADJACENT_UNIT_REQUIREMENT');
INSERT INTO RequirementSets (RequirementSetId, RequirementSetType)
VALUES ('TIRAMOD_ON_SAME_PLOT_REQUIREMENTS',
'REQUIREMENTSET_TEST_ALL');
INSERT INTO Requirements (RequirementId, RequirementType)
VALUES ('TIRAMOD_ADJACENT_UNIT_REQUIREMENT',
'REQUIREMENT_PLOT_ADJACENT_TO_OWNER');
INSERT INTO RequirementArguments (RequirementId, Name, Value)
VALUES ('TIRAMOD_ADJACENT_UNIT_REQUIREMENT',
'MinDistance',
0);
INSERT INTO RequirementArguments (RequirementId, Name, Value)
VALUES ('TIRAMOD_ADJACENT_UNIT_REQUIREMENT',
'MaxDistance',
0);
--Now define new units:
INSERT INTO Types (Type, Kind)
SELECT 'UNIT_ZZZ_TIRAMOD_DUMMY_UNIT_GRANT_' || Type,
'KIND_UNIT'
FROM Types WHERE Types.Kind='KIND_ABILITY' ;
INSERT INTO TypeTags (Type, Tag)
SELECT 'UNIT_ZZZ_TIRAMOD_DUMMY_UNIT_GRANT_' || Type,
'CLASS_TIRAMOD_GRANT_' || Type
FROM Types WHERE Types.Kind='KIND_ABILITY' ;
INSERT INTO Units (UnitType, Name, Description, BaseSightRange, BaseMoves, Domain, FormationClass, Cost, EnabledByReligion)
SELECT 'UNIT_ZZZ_TIRAMOD_DUMMY_UNIT_GRANT_' || Type,
'LOC_' || 'UNIT_ZZZ_TIRAMOD_DUMMY_UNIT_GRANT_' || Type || '_NAME',
'LOC_' || 'UNIT_ZZZ_TIRAMOD_DUMMY_UNIT_GRANT_' || Type || '_DESCRIPTION',
3,
2,
'DOMAIN_LAND',
'FORMATION_CLASS_CIVILIAN',
10,
1
FROM Types WHERE Types.Kind='KIND_ABILITY' ;
--At last populate ability rows:
INSERT INTO Tags (Tag, Vocabulary)
SELECT 'CLASS_TIRAMOD_GRANT_' || Type,
'ABILITY_CLASS'
FROM Types WHERE Types.Kind='KIND_ABILITY' ;
INSERT INTO TypeTags (Type, Tag)
SELECT 'ABILITY_ZZZ_TIRAMOD_GRANT_' || Type,
'CLASS_TIRAMOD_GRANT_' || Type
FROM Types WHERE Types.Kind='KIND_ABILITY' ;
INSERT INTO UnitAbilities (UnitAbilityType, Name, Description)
SELECT 'ABILITY_ZZZ_TIRAMOD_GRANT_' || Type,
'LOC_ABILITY_ZZZ_TIRAMOD_GRANT_' || Type || '_NAME',
'LOC_ABILITY_ZZZ_TIRAMOD_GRANT_' || Type || '_DESCRIPTION'
FROM Types WHERE Types.Kind='KIND_ABILITY' ;
--we define the new abilities at last to make sure they do not interfer with the previous lines "FROM Types WHERE Types.Kind='KIND_ABILITY' ;"
INSERT INTO Types (Type, Kind)
SELECT 'ABILITY_ZZZ_TIRAMOD_GRANT_' || Type,
'KIND_ABILITY'
FROM Types WHERE Types.Kind='KIND_ABILITY' ;
<UpdateDatabase id="UnitsTest">
<Properties>
<LoadOrder>9999</LoadOrder> <!-- high load order -->
</Properties>
<Items>
<File>Units.sql</File>
</Items>
</UpdateDatabase>
function GrantAbilityToUnit( pTargetUnit, sAbilityType )
local iPlayerID = pTargetUnit:GetOwner()
local iX, iY = pTargetUnit:GetX(), pTargetUnit:GetY()
local sFoundString = string.match(sAbilityType, "ABILITY_ZZZ_TIRAMOD_GRANT_")
local sUnit = "UNIT_ZZZ_TIRAMOD_DUMMY_UNIT_GRANT_" .. sAbilityType
if( iX and iY and sAbilityType and not sFoundString ) then
local pUnit = UnitManager.InitUnit(iPlayerID , sUnit, iX, iY)
UnitManager.Kill(pUnit, false)
end
end