<?xml version="1.0" encoding="utf-8"?>
<Patch>

	<Operation Class="PatchOperationRemove">
		<xpath>Defs/ThingDef[defName="VFES_Turret_Ballista" or defName="VFES_Turret_Artillery"]/comps/li[@Class="CompProperties_Refuelable"]</xpath>
	</Operation>
	
	<Operation Class="PatchOperationRemove">
		<xpath>Defs/ThingDef[defName="VFES_Turret_AutomatedMortar"]/comps/li[@Class="VEF.Buildings.CompProperties_Refuelable_DualFuel"]</xpath>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[
			defName="VFES_Turret_Artillery" or
			defName="VFES_Turret_Catapult" or
			defName="VFES_Turret_Ballista"
			]/thingClass</xpath>
		<value>
			<thingClass>CombatExtended.Building_TurretGunCE</thingClass>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VFES_Turret_Ballista"]/fillPercent </xpath>
		<value>
			<fillPercent>0.85</fillPercent>
		</value>
	</Operation>

	<!-- ========== Ballista - Weapon ========== -->
	<Operation Class="CombatExtended.PatchOperationMakeGunCECompatible">
		<defName>VFES_Gun_BallistaTurret</defName>
		<statBases>
			<SightsEfficiency>1</SightsEfficiency>
			<ShotSpread>1</ShotSpread>
			<SwayFactor>1</SwayFactor>
			<Bulk>4.00</Bulk>
			<RangedWeapon_Cooldown>2</RangedWeapon_Cooldown>
		</statBases>
		<Properties>
			<verbClass>CombatExtended.Verb_ShootCE</verbClass>
			<hasStandardCommand>true</hasStandardCommand>
			<defaultProjectile>Pilum_Fired</defaultProjectile>
			<warmupTime>1.4</warmupTime>
			<range>44</range>
			<soundCast>VFES_Shot_Ballista</soundCast>
			<soundCastTail>GunTail_Heavy</soundCastTail>
			<recoilPattern>Mounted</recoilPattern>
		</Properties>
		<AmmoUser>
			<magazineSize>1</magazineSize>
			<reloadTime>8</reloadTime>
			<ammoSet>AmmoSet_Javelins</ammoSet>
		</AmmoUser>
		<FireModes>
			<aiAimMode>AimedShot</aiAimMode>
			<noSnapshot>true</noSnapshot>
			<noSingleShot>false</noSingleShot>
		</FireModes>
	</Operation>

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="VFES_Gun_BallistaTurret"]/weaponTags</xpath>
		<value>
			<li>TurretGun</li>
		</value>
	</Operation>

	<!-- ========== Catapult - Base ========== -->
	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="VFES_Turret_Catapult"]/building</xpath>
		<value>
			<spawnedConceptLearnOpportunity>CE_MortarDirectFire</spawnedConceptLearnOpportunity>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VFES_Turret_Catapult"]/building/turretBurstWarmupTime</xpath>
		<value>
			<turretBurstWarmupTime>1</turretBurstWarmupTime>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VFES_Turret_Catapult"]/building/turretBurstCooldownTime</xpath>
		<value>
			<turretBurstCooldownTime>1</turretBurstCooldownTime>
		</value>
	</Operation>

	<Operation Class="PatchOperationRemove">
		<xpath>Defs/ThingDef[defName="VFES_Turret_Catapult"]/inspectorTabs</xpath>
	</Operation>

	<!-- ========== Catapult - Weapon ========== -->
	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="VFES_Artillery_Catapult"]/statBases</xpath>
		<value>
			<SightsEfficiency>0.5</SightsEfficiency>
		</value>
	</Operation>

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="VFES_Artillery_Catapult"]/comps</xpath>
		<value>
			<li Class="CombatExtended.CompProperties_Charges">
				<chargeSpeeds>
					<li>15</li>
					<li>30</li>
					<li>35</li>
					<li>45</li>
				</chargeSpeeds>
			</li>
			<li Class="CombatExtended.CompProperties_AmmoUser">
				<magazineSize>1</magazineSize>
				<reloadTime>12</reloadTime>
				<ammoSet>AmmoSet_Catapult</ammoSet>
			</li>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VFES_Artillery_Catapult"]/verbs</xpath>
		<value>
			<verbs>
				<li Class="CombatExtended.VerbPropertiesCE">
					<verbClass>CombatExtended.Verb_ShootMortarCE</verbClass>
					<forceNormalTimeSpeed>false</forceNormalTimeSpeed>
					<hasStandardCommand>true</hasStandardCommand>
					<defaultProjectile>Projectile_CatapultBullet_Boulder</defaultProjectile>
					<warmupTime>4</warmupTime>
					<minRange>22</minRange>
					<range>72</range>
					<burstShotCount>1</burstShotCount>
					<soundCast>Bow_Recurve</soundCast>
					<muzzleFlashScale>0</muzzleFlashScale>
					<indirectFirePenalty>0.2</indirectFirePenalty>
					<targetParams>
						<canTargetLocations>true</canTargetLocations>
					</targetParams>
				</li>
			</verbs>
		</value>
	</Operation>

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="VFES_Artillery_Catapult"]/weaponTags</xpath>
		<value>
			<li>TurretGun</li>
		</value>
	</Operation>

	<!-- ========== Artillery - Base ========== -->

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="VFES_Turret_Artillery"]/statBases</xpath>
		<value>
			<Mass>5500</Mass>
		</value>
	</Operation>

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="VFES_Turret_Artillery"]/building</xpath>
		<value>
			<spawnedConceptLearnOpportunity>CE_MortarDirectFire</spawnedConceptLearnOpportunity>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VFES_Turret_Artillery"]/building/turretBurstWarmupTime</xpath>
		<value>
			<turretBurstWarmupTime>1</turretBurstWarmupTime>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VFES_Turret_Artillery"]/building/turretBurstCooldownTime</xpath>
		<value>
			<turretBurstCooldownTime>1</turretBurstCooldownTime>
		</value>
	</Operation>

	<Operation Class="PatchOperationRemove">
		<xpath>Defs/ThingDef[defName="VFES_Turret_Artillery"]/comps/li[@Class="VFESecurity.CompProperties_WorldArtillery"]</xpath>
	</Operation>

	<!-- ========== Artillery - Weapon ========== -->

	<Operation Class="PatchOperationConditional">
		<xpath>Defs/ThingDef[defName="VFES_Artillery_ArtilleryGun"]/statBases</xpath>
		<nomatch Class="PatchOperationAdd">
			<xpath>Defs/ThingDef[defName="VFES_Artillery_ArtilleryGun"]</xpath>
			<value>
				<statBases />
			</value>
		</nomatch>
	</Operation>

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="VFES_Artillery_ArtilleryGun"]/statBases</xpath>
		<value>
			<SightsEfficiency>0.5</SightsEfficiency>
		</value>
	</Operation>

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="VFES_Artillery_ArtilleryGun"]/comps</xpath>
		<value>
			<li Class="CombatExtended.CompProperties_Charges">
				<chargeSpeeds>
					<li>30</li>
					<li>50</li>
					<li>70</li>
					<li>90</li>
				</chargeSpeeds>
			</li>
			<li Class="CombatExtended.CompProperties_AmmoUser">
				<magazineSize>1</magazineSize>
				<reloadTime>12</reloadTime>
				<ammoSet>AmmoSet_155mmHowitzerShell</ammoSet>
			</li>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VFES_Artillery_ArtilleryGun"]/verbs</xpath>
		<value>
			<verbs>
				<li Class="CombatExtended.VerbPropertiesCE">
					<verbClass>CombatExtended.Verb_ShootMortarCE</verbClass>
					<forceNormalTimeSpeed>false</forceNormalTimeSpeed>
					<hasStandardCommand>true</hasStandardCommand>
					<defaultProjectile>Bullet_155mmHowitzerShell_HE</defaultProjectile>
					<warmupTime>4</warmupTime>
					<minRange>40</minRange>
					<range>1000</range>
					<burstShotCount>1</burstShotCount>
					<soundCast>VFES_Shot_Artillery</soundCast>
					<muzzleFlashScale>20</muzzleFlashScale>
					<indirectFirePenalty>0.2</indirectFirePenalty>
					<targetParams>
						<canTargetLocations>true</canTargetLocations>
					</targetParams>
				</li>
			</verbs>
		</value>
	</Operation>
	
	<!-- ========== Auto-mortar - Base ========== -->
	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VFES_Turret_AutomatedMortar"]/thingClass</xpath>
		<value>
			<thingClass>CombatExtended.Building_TurretGunCE</thingClass>
		</value>
	</Operation>

	<Operation Class="PatchOperationRemove">
		<xpath>Defs/ThingDef[defName="VFES_Turret_AutomatedMortar"]/comps/li[@Class="CompProperties_Stunnable"]/affectedDamageDefs/li[.="Stun"]</xpath>
	</Operation>
	
	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VFES_Turret_AutomatedMortar"]/statBases/MaxHitPoints</xpath>
		<value>
			<MaxHitPoints>250</MaxHitPoints>
		</value>
	</Operation>

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="VFES_Turret_AutomatedMortar"]/statBases</xpath>
		<value>
			<AimingAccuracy>0.25</AimingAccuracy>
			<NightVisionEfficiency>0.6</NightVisionEfficiency>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VFES_Turret_AutomatedMortar"]/statBases/ShootingAccuracyTurret</xpath>
		<value>
			<ShootingAccuracyTurret>0.5</ShootingAccuracyTurret>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VFES_Turret_AutomatedMortar"]/fillPercent</xpath>
		<value>
			<fillPercent>0.85</fillPercent>
		</value>
	</Operation>

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="VFES_Turret_AutomatedMortar"]/comps</xpath>
		<value>
			<li Class="CombatExtended.CompProperties_Fragments">
				<fragments>
					<Fragment_Large>5</Fragment_Large>
					<Fragment_Small>20</Fragment_Small>
				</fragments>
			</li>
		</value>
	</Operation>
	
	<!-- ========== Auto-mortar - Weapon ========== -->
	<Operation Class="PatchOperationConditional">
		<xpath>Defs/ThingDef[defName="Gun_AutomatedMortar"]/statBases</xpath>
		<nomatch Class="PatchOperationAdd">
			<xpath>Defs/ThingDef[defName="Gun_AutomatedMortar"]</xpath>
			<value>
				<statBases>
					<SightsEfficiency>0.5</SightsEfficiency>
				</statBases>
			</value>
		</nomatch>
		<match Class="PatchOperationAdd">
			<xpath>Defs/ThingDef[defName="Gun_AutomatedMortar"]/statBases</xpath>
			<value>
				<SightsEfficiency>0.5</SightsEfficiency>
			</value>
		</match>
	</Operation>

	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="Gun_AutomatedMortar"]</xpath>
		<value>
			<comps>
				<li Class="CombatExtended.CompProperties_Charges">
					<chargeSpeeds>
						<li>30</li>
						<li>50</li>
						<li>70</li>
						<li>90</li>
					</chargeSpeeds>
				</li>
				<li Class="CombatExtended.CompProperties_AmmoUser">
					<magazineSize>6</magazineSize>
					<reloadTime>3.6</reloadTime>
					<reloadOneAtATime>true</reloadOneAtATime>
					<ammoSet>AmmoSet_81mmMortarShell</ammoSet>
				</li>
			</comps>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="Gun_AutomatedMortar"]/verbs</xpath>
		<value>
			<verbs>
				<li Class="CombatExtended.VerbPropertiesCE">
					<verbClass>CombatExtended.Verb_ShootMortarCE</verbClass>
					<forceNormalTimeSpeed>false</forceNormalTimeSpeed>
					<hasStandardCommand>true</hasStandardCommand>
					<defaultProjectile>Bullet_81mmMortarShell_HE</defaultProjectile>
					<!-- Longer warmup than a mortar, to stay true to the mod's balance -->
					<warmupTime>12.5</warmupTime>
					<minRange>32</minRange>
					<range>700</range>
					<burstShotCount>1</burstShotCount>
					<soundCast>Mortar_LaunchA</soundCast>
					<muzzleFlashScale>16</muzzleFlashScale>
					<circularError>3</circularError>
					<indirectFirePenalty>0.4</indirectFirePenalty>
					<targetParams>
						<canTargetLocations>true</canTargetLocations>
					</targetParams>
				</li>
			</verbs>
		</value>
	</Operation>

</Patch>