This tutorial is a step by step to add a new unit in the game, it won't covert the creation of a new unit model, there are other tutorials about that.
It assumes that you know how to create a basic mod, and understand the meaning of "OnModActivated"
It applies for Civilization and G+K post patch .674, since that patch you don't have (and in fact can't) to replace Civ5ArtDefines_UnitMembers.xml and Civ5ArtDefines_Units.xml. The only file related to units which is still not loaded to the Database (and so have to be replaced in a mod using the VFS property) is unitformations.xml. But unless you want to change the default formations, you won't need it.
Note that previous version of the tutorials made a bad use of double-quote in the SQL code, see here why you shouldn't use them and please refer to the now corrected code.
The exception for using double-quote is when a SQL keyword is used as a table of column name, as it is the case with "Index" column in ArtDefine_UnitMemberCombats table (see code in step 4)
Pre-required : Right click your mod project in the Solution explorer windows, select "properties", go in the "Mod Info" panel, and check the "Reload Unit System" in the "Systems" section.
step 1 : For the tutorial, we're taking the example of the biplan from this danrell's units pack, supposing that we want to add a WW1 era fighter to civ5 vanilla.
Here are the files requested by this unit model:
EarlyFighter_Generic_gloss.dds
EarlyFighter_Generic.gr2
EarlyFighter_Generic.fxsxml
EarlyFighter_Generic.dds
All this files must be copied in your project and have the VFS property set to "true". I'll suggest you to organize your project using folders and subfolders if you have to put many files in it, the VFS will not care for the relative path.
Danrell also provide the blend file and a jpg screenshot, those are not needed in your mod, but the blend is a must for those who want to edit the model itself, go and thanks him again for his work
step 2 : create a new sql file in your project (right click the project name or one of it's subfolder in the Solution Explorer windows, select "Add", "New Item..." and Game Rules (SQL)
Rename it, or keep the original Game Rules1.sql. You don't need to set the VFS to true for that file, but you have to add an UpdateDatabase entry for it.
step 3 : For that right click your mod project in the Solution explorer windows, select "properties", go in the "Action" panel, click "Add...", select "OnModActivated" as event, "UpdateDatabase" as Action, and point File to your newly created SQL file.
As this is a step by step mod, I won't detailed the SQL commands used here, just follow the steps and all will goes well (I hope )
An XML tutorial may be more user friendly, but I really found the SQL method more efficient.
step 4 : Now open the sql file and add the following code to it :
In red the reference for the new unit, in blue the reference of the unit we use as a template for the new one.
This code define the visual effects for the new unit. I use a "template" unit for reference, so I don't have to manually set each entry, but have the SQL code copy them from the "template" unit (here the normal fighter) and only change those that are needed.
Using a template is much faster, but you have to be sure that no other mods will delete the unit you're using as a template. Mods compatibility depend of the loading order and can sometimes be assured using associations, but that's another subject.
You can still use SQL to add new entries without duplicating another unit's entry using this syntax:
Horem has posted a complete SQL template here.
but you may find it easier to use XML in that case, see the second post for an example from whoward69.
step 5 : Below is the code for the new unit statistics, add it after in the sql file :
That code will copy all the entry of the vanilla civ5 fighter in new entry for our new units. In red the changes that are made:
UNIT_BIPLAN is the type of your new unit
Biplan is the in game name
(25) the ranged attack value
(250) the construction cost
(5) the range
ART_DEF_UNIT_BIPLAN refer to the <Type> of step 4
Fell free to tweak other values, thinking of the requested tech for example...
This should be enough for most your new units to work properly, danrell's units may require an extra step
extra step : copy the "Common" folder from danrell's pack in your project folder, and set the VFS property to true for all it's files. Needed especially for his tanks and ships.
edit : finally converted to post-patch .674 method.
It assumes that you know how to create a basic mod, and understand the meaning of "OnModActivated"
It applies for Civilization and G+K post patch .674, since that patch you don't have (and in fact can't) to replace Civ5ArtDefines_UnitMembers.xml and Civ5ArtDefines_Units.xml. The only file related to units which is still not loaded to the Database (and so have to be replaced in a mod using the VFS property) is unitformations.xml. But unless you want to change the default formations, you won't need it.
Note that previous version of the tutorials made a bad use of double-quote in the SQL code, see here why you shouldn't use them and please refer to the now corrected code.
The exception for using double-quote is when a SQL keyword is used as a table of column name, as it is the case with "Index" column in ArtDefine_UnitMemberCombats table (see code in step 4)
Pre-required : Right click your mod project in the Solution explorer windows, select "properties", go in the "Mod Info" panel, and check the "Reload Unit System" in the "Systems" section.
step 1 : For the tutorial, we're taking the example of the biplan from this danrell's units pack, supposing that we want to add a WW1 era fighter to civ5 vanilla.
Here are the files requested by this unit model:
EarlyFighter_Generic_gloss.dds
EarlyFighter_Generic.gr2
EarlyFighter_Generic.fxsxml
EarlyFighter_Generic.dds
All this files must be copied in your project and have the VFS property set to "true". I'll suggest you to organize your project using folders and subfolders if you have to put many files in it, the VFS will not care for the relative path.
Danrell also provide the blend file and a jpg screenshot, those are not needed in your mod, but the blend is a must for those who want to edit the model itself, go and thanks him again for his work
step 2 : create a new sql file in your project (right click the project name or one of it's subfolder in the Solution Explorer windows, select "Add", "New Item..." and Game Rules (SQL)
Rename it, or keep the original Game Rules1.sql. You don't need to set the VFS to true for that file, but you have to add an UpdateDatabase entry for it.
step 3 : For that right click your mod project in the Solution explorer windows, select "properties", go in the "Action" panel, click "Add...", select "OnModActivated" as event, "UpdateDatabase" as Action, and point File to your newly created SQL file.
As this is a step by step mod, I won't detailed the SQL commands used here, just follow the steps and all will goes well (I hope )
An XML tutorial may be more user friendly, but I really found the SQL method more efficient.
step 4 : Now open the sql file and add the following code to it :
Code:
INSERT INTO ArtDefine_UnitInfos (Type,DamageStates,Formation)
SELECT ([COLOR="Red"]'ART_DEF_UNIT_BIPLAN'[/COLOR]), DamageStates, Formation
FROM ArtDefine_UnitInfos WHERE (Type = [COLOR=Blue]'ART_DEF_UNIT_FIGHTER'[/COLOR]);
INSERT INTO ArtDefine_UnitInfoMemberInfos (UnitInfoType,UnitMemberInfoType,NumMembers)
SELECT ([COLOR="Red"]'ART_DEF_UNIT_BIPLAN'[/COLOR]), ([COLOR="Red"]'ART_DEF_UNIT_MEMBER_BIPLAN'[/COLOR]), NumMembers
FROM ArtDefine_UnitInfoMemberInfos WHERE (UnitInfoType = [COLOR=Blue]'ART_DEF_UNIT_FIGHTER'[/COLOR]);
INSERT INTO ArtDefine_UnitMemberCombats (UnitMemberType, EnableActions, DisableActions, MoveRadius, ShortMoveRadius, ChargeRadius, AttackRadius, RangedAttackRadius, MoveRate, ShortMoveRate, TurnRateMin, TurnRateMax, TurnFacingRateMin, TurnFacingRateMax, RollRateMin, RollRateMax, PitchRateMin, PitchRateMax, LOSRadiusScale, TargetRadius, TargetHeight, HasShortRangedAttack, HasLongRangedAttack, HasLeftRightAttack, HasStationaryMelee, HasStationaryRangedAttack, HasRefaceAfterCombat, ReformBeforeCombat, HasIndependentWeaponFacing, HasOpponentTracking, HasCollisionAttack, AttackAltitude, AltitudeDecelerationDistance, OnlyTurnInMovementActions, RushAttackFormation)
SELECT ([COLOR="Red"]'ART_DEF_UNIT_MEMBER_BIPLAN'[/COLOR]), EnableActions, DisableActions, MoveRadius, ShortMoveRadius, ChargeRadius, AttackRadius, RangedAttackRadius, MoveRate, ShortMoveRate, TurnRateMin, TurnRateMax, TurnFacingRateMin, TurnFacingRateMax, RollRateMin, RollRateMax, PitchRateMin, PitchRateMax, LOSRadiusScale, TargetRadius, TargetHeight, HasShortRangedAttack, HasLongRangedAttack, HasLeftRightAttack, HasStationaryMelee, HasStationaryRangedAttack, HasRefaceAfterCombat, ReformBeforeCombat, HasIndependentWeaponFacing, HasOpponentTracking, HasCollisionAttack, AttackAltitude, AltitudeDecelerationDistance, OnlyTurnInMovementActions, RushAttackFormation
FROM ArtDefine_UnitMemberCombats WHERE (UnitMemberType = [COLOR=Blue]'ART_DEF_UNIT_MEMBER_FIGHTER'[/COLOR]);
INSERT INTO ArtDefine_UnitMemberCombatWeapons (UnitMemberType, "Index", SubIndex, ID, VisKillStrengthMin, VisKillStrengthMax, ProjectileSpeed, ProjectileTurnRateMin, ProjectileTurnRateMax, HitEffect, HitEffectScale, HitRadius, ProjectileChildEffectScale, AreaDamageDelay, ContinuousFire, WaitForEffectCompletion, TargetGround, IsDropped, WeaponTypeTag, WeaponTypeSoundOverrideTag)
SELECT ([COLOR="Red"]'ART_DEF_UNIT_MEMBER_BIPLAN'[/COLOR]), "Index", SubIndex, ID, VisKillStrengthMin, VisKillStrengthMax, ProjectileSpeed, ProjectileTurnRateMin, ProjectileTurnRateMax, HitEffect, HitEffectScale, HitRadius, ProjectileChildEffectScale, AreaDamageDelay, ContinuousFire, WaitForEffectCompletion, TargetGround, IsDropped, WeaponTypeTag, WeaponTypeSoundOverrideTag
FROM ArtDefine_UnitMemberCombatWeapons WHERE (UnitMemberType = [COLOR=Blue]'ART_DEF_UNIT_MEMBER_FIGHTER'[/COLOR]);
INSERT INTO ArtDefine_UnitMemberInfos (Type, Scale, ZOffset, Domain, Model, MaterialTypeTag, MaterialTypeSoundOverrideTag)
SELECT ([COLOR="Red"]'ART_DEF_UNIT_MEMBER_BIPLAN'[/COLOR]), Scale, ZOffset, Domain, ([COLOR="Red"]'EarlyFighter_Generic.fxsxml'[/COLOR]), MaterialTypeTag, MaterialTypeSoundOverrideTag
FROM ArtDefine_UnitMemberInfos WHERE (Type = [COLOR=Blue]'ART_DEF_UNIT_MEMBER_FIGHTER'[/COLOR]);
INSERT INTO ArtDefine_StrategicView (StrategicViewType, TileType, Asset )
SELECT ([COLOR="Red"]'ART_DEF_UNIT_BIPLAN'[/COLOR]), TileType, Asset
FROM ArtDefine_StrategicView WHERE (StrategicViewType = [COLOR=Blue]'ART_DEF_UNIT_FIGHTER'[/COLOR]);
In red the reference for the new unit, in blue the reference of the unit we use as a template for the new one.
This code define the visual effects for the new unit. I use a "template" unit for reference, so I don't have to manually set each entry, but have the SQL code copy them from the "template" unit (here the normal fighter) and only change those that are needed.
Using a template is much faster, but you have to be sure that no other mods will delete the unit you're using as a template. Mods compatibility depend of the loading order and can sometimes be assured using associations, but that's another subject.
You can still use SQL to add new entries without duplicating another unit's entry using this syntax:
Code:
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...);
Horem has posted a complete SQL template here.
but you may find it easier to use XML in that case, see the second post for an example from whoward69.
step 5 : Below is the code for the new unit statistics, add it after in the sql file :
Code:
INSERT INTO UnitClasses (Type, Description, MaxGlobalInstances, MaxTeamInstances, MaxPlayerInstances, InstanceCostModifier, DefaultUnit )
SELECT ([COLOR="Red"]'UNITCLASS_BIPLAN'[/COLOR]), Description, MaxGlobalInstances, MaxTeamInstances, MaxPlayerInstances, InstanceCostModifier, ([COLOR="Red"]'UNIT_BIPLAN'[/COLOR])
FROM UnitClasses WHERE (Type = [COLOR="blue"]'UNITCLASS_FIGHTER'[/COLOR]);
INSERT INTO Units (Type, Description, Civilopedia, Strategy, Help, Requirements, Combat, RangedCombat, Cost, Moves, Immobile, Range, BaseSightRange, Class, Special, Capture, CombatClass, Domain, CivilianAttackPriority, DefaultUnitAI, Food, NoBadGoodies, RivalTerritory, MilitarySupport, MilitaryProduction, Pillage, Found, FoundAbroad, CultureBombRadius, GoldenAgeTurns, IgnoreBuildingDefense, PrereqResources, Mechanized, Suicide, CaptureWhileEmbarked, PrereqTech, ObsoleteTech, GoodyHutUpgradeUnitClass, HurryCostModifier, AdvancedStartCost, MinAreaSize, AirUnitCap, NukeDamageLevel, WorkRate, NumFreeTechs, RushBuilding, BaseHurry, HurryMultiplier, BaseGold, NumGoldPerEra, SpreadReligion, CombatLimit, RangeAttackOnlyInDomain, RangeAttackIgnoreLOS, RangedCombatLimit, XPValueAttack, XPValueDefense, SpecialCargo, DomainCargo, Conscription, ExtraMaintenanceCost, NoMaintenance, Unhappiness, UnitArtInfo, UnitArtInfoCulturalVariation, UnitArtInfoEraVariation, ProjectPrereq, SpaceshipProject, LeaderPromotion, LeaderExperience, DontShowYields, ShowInPedia, MoveRate, UnitFlagIconOffset, PortraitIndex, IconAtlas, UnitFlagAtlas)
SELECT [COLOR="red"]('UNIT_BIPLAN')[/COLOR], [COLOR="red"]('Biplan')[/COLOR], Civilopedia, Strategy, Help, Requirements,
Combat, [COLOR="red"](25)[/COLOR], [COLOR="red"](250)[/COLOR], Moves, Immobile, [COLOR="red"](5)[/COLOR], BaseSightRange, [COLOR="red"]('UNITCLASS_BIPLAN')[/COLOR], Special, Capture, CombatClass, Domain, CivilianAttackPriority, DefaultUnitAI, Food, NoBadGoodies, RivalTerritory, MilitarySupport, MilitaryProduction, Pillage, Found, FoundAbroad, CultureBombRadius, GoldenAgeTurns, IgnoreBuildingDefense, PrereqResources, Mechanized, Suicide, CaptureWhileEmbarked, PrereqTech, ObsoleteTech, GoodyHutUpgradeUnitClass, HurryCostModifier, AdvancedStartCost, MinAreaSize, AirUnitCap, NukeDamageLevel, WorkRate, NumFreeTechs, RushBuilding, BaseHurry, HurryMultiplier, BaseGold, NumGoldPerEra, SpreadReligion, CombatLimit, RangeAttackOnlyInDomain, RangeAttackIgnoreLOS, RangedCombatLimit, XPValueAttack, XPValueDefense, SpecialCargo, DomainCargo, Conscription, ExtraMaintenanceCost, NoMaintenance, Unhappiness,
[COLOR="red"]('ART_DEF_UNIT_BIPLAN')[/COLOR], UnitArtInfoCulturalVariation, UnitArtInfoEraVariation, ProjectPrereq, SpaceshipProject, LeaderPromotion, LeaderExperience, DontShowYields, ShowInPedia, MoveRate,
UnitFlagIconOffset, PortraitIndex, IconAtlas, UnitFlagAtlas
FROM Units WHERE (Type = [COLOR="blue"]'UNIT_FIGHTER'[/COLOR]);
INSERT INTO Unit_AITypes (UnitType, UnitAIType)
SELECT [COLOR="red"]('UNIT_BIPLAN')[/COLOR], UnitAIType
FROM Unit_AITypes WHERE (UnitType = [COLOR="blue"]'UNIT_FIGHTER'[/COLOR]);
INSERT INTO Unit_ClassUpgrades (UnitType, UnitClassType)
SELECT [COLOR="red"]('UNIT_BIPLAN')[/COLOR], UnitClassType
FROM Unit_ClassUpgrades WHERE (UnitType = [COLOR="blue"]'UNIT_FIGHTER'[/COLOR]);
INSERT INTO Unit_Flavors (UnitType, FlavorType, Flavor)
SELECT [COLOR="red"]('UNIT_BIPLAN')[/COLOR], FlavorType, Flavor
FROM Unit_Flavors WHERE (UnitType = [COLOR="blue"]'UNIT_FIGHTER'[/COLOR]);
INSERT INTO Unit_FreePromotions (UnitType, PromotionType)
SELECT [COLOR="red"]('UNIT_BIPLAN')[/COLOR], PromotionType
FROM Unit_FreePromotions WHERE (UnitType = [COLOR="blue"]'UNIT_FIGHTER'[/COLOR]);
INSERT INTO Unit_ResourceQuantityRequirements (UnitType, ResourceType, Cost)
SELECT [COLOR="red"]('UNIT_BIPLAN')[/COLOR], ResourceType, Cost
FROM Unit_ResourceQuantityRequirements WHERE (UnitType = [COLOR="Blue"]'UNIT_FIGHTER'[/COLOR]);
That code will copy all the entry of the vanilla civ5 fighter in new entry for our new units. In red the changes that are made:
UNIT_BIPLAN is the type of your new unit
Biplan is the in game name
(25) the ranged attack value
(250) the construction cost
(5) the range
ART_DEF_UNIT_BIPLAN refer to the <Type> of step 4
Fell free to tweak other values, thinking of the requested tech for example...
This should be enough for most your new units to work properly, danrell's units may require an extra step
extra step : copy the "Common" folder from danrell's pack in your project folder, and set the VFS property to true for all it's files. Needed especially for his tanks and ships.
edit : finally converted to post-patch .674 method.