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

	<!-- === Tools === -->
	<Operation Class="PatchOperationReplace">
		<xpath>
			Defs/ThingDef[
			defName ="VWE_Gun_ChargePistol" or
			defName="VWE_Gun_ChargeSMG"]/tools
		</xpath>
		<value>
			<tools>
				<li Class="CombatExtended.ToolCE">
					<label>grip</label>
					<capacities>
						<li>Blunt</li>
					</capacities>
					<power>2</power>
					<cooldownTime>1.54</cooldownTime>
					<chanceFactor>1.5</chanceFactor>
					<armorPenetrationBlunt>0.555</armorPenetrationBlunt>
					<linkedBodyPartsGroup>Grip</linkedBodyPartsGroup>
				</li>
				<li Class="CombatExtended.ToolCE">
					<label>muzzle</label>
					<capacities>
						<li>Poke</li>
					</capacities>
					<power>2</power>
					<cooldownTime>1.54</cooldownTime>
					<armorPenetrationBlunt>0.555</armorPenetrationBlunt>
					<linkedBodyPartsGroup>Muzzle</linkedBodyPartsGroup>
				</li>
			</tools>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>
			Defs/ThingDef[
			defName="VWE_Gun_ChargeShotgun" or
			defName="VWE_Gun_ChargeSniperRifle" or
			defName="VWE_Gun_ChargeLMG" or
			defName="VWE_Gun_ChargeMinigun"
			]/tools
		</xpath>
		<value>
			<tools>
				<li Class="CombatExtended.ToolCE">
					<label>stock</label>
					<capacities>
						<li>Blunt</li>
					</capacities>
					<power>8</power>
					<cooldownTime>1.55</cooldownTime>
					<chanceFactor>1.5</chanceFactor>
					<armorPenetrationBlunt>2.755</armorPenetrationBlunt>
					<linkedBodyPartsGroup>Stock</linkedBodyPartsGroup>
				</li>
				<li Class="CombatExtended.ToolCE">
					<label>barrel</label>
					<capacities>
						<li>Blunt</li>
					</capacities>
					<power>5</power>
					<cooldownTime>2.02</cooldownTime>
					<armorPenetrationBlunt>1.630</armorPenetrationBlunt>
					<linkedBodyPartsGroup>Barrel</linkedBodyPartsGroup>
				</li>
				<li Class="CombatExtended.ToolCE">
					<label>muzzle</label>
					<capacities>
						<li>Poke</li>
					</capacities>
					<power>8</power>
					<cooldownTime>1.55</cooldownTime>
					<armorPenetrationBlunt>2.755</armorPenetrationBlunt>
					<linkedBodyPartsGroup>Muzzle</linkedBodyPartsGroup>
				</li>
			</tools>
		</value>
	</Operation>

	<Operation Class="PatchOperationReplace">
		<xpath>Defs/ThingDef[defName="VWE_Gun_ChargeRocketLauncher"]/tools</xpath>
		<value>
			<tools>
				<li Class="CombatExtended.ToolCE">
					<label>barrel</label>
					<capacities>
						<li>Blunt</li>
					</capacities>
					<power>10</power>
					<cooldownTime>2.44</cooldownTime>
					<armorPenetrationBlunt>3.5</armorPenetrationBlunt>
					<linkedBodyPartsGroup>Barrel</linkedBodyPartsGroup>
				</li>
			</tools>
		</value>
	</Operation>

	<!-- === Charge Pistol, based on the P-6 from Combat Extended Guns === -->
	<Operation Class="CombatExtended.PatchOperationMakeGunCECompatible">
		<defName>VWE_Gun_ChargePistol</defName>
		<statBases>
			<WorkToMake>16500</WorkToMake>
			<Mass>0.9</Mass>
			<Bulk>2.0</Bulk>
			<SwayFactor>0.97</SwayFactor>
			<ShotSpread>0.15</ShotSpread>
			<SightsEfficiency>0.8</SightsEfficiency>
			<RangedWeapon_Cooldown>0.36</RangedWeapon_Cooldown>
		</statBases>
		<costList>
			<Steel>20</Steel>
			<Plasteel>20</Plasteel>
			<Chemfuel>5</Chemfuel>
			<ComponentIndustrial>2</ComponentIndustrial>
			<ComponentSpacer>1</ComponentSpacer>
		</costList>
		<Properties>
			<recoilAmount>2.33</recoilAmount>
			<verbClass>CombatExtended.Verb_ShootCE</verbClass>
			<hasStandardCommand>True</hasStandardCommand>
			<defaultProjectile>Bullet_6x18mmCharged</defaultProjectile>
			<burstShotCount>3</burstShotCount>
			<ticksBetweenBurstShots>5</ticksBetweenBurstShots>
			<warmupTime>0.5</warmupTime>
			<range>16</range>
			<soundCast>VWE_Shot_ChargePistol</soundCast>
			<soundCastTail>GunTail_Light</soundCastTail>
			<muzzleFlashScale>9</muzzleFlashScale>
		</Properties>
		<AmmoUser>
			<magazineSize>15</magazineSize>
			<reloadTime>4</reloadTime>
			<ammoSet>AmmoSet_6x18mmCharged</ammoSet>
		</AmmoUser>
		<FireModes>
			<aiAimMode>Snapshot</aiAimMode>
			<aiUseBurstMode>True</aiUseBurstMode>
			<aimedBurstShotCount>2</aimedBurstShotCount>
		</FireModes>
		<weaponTags>
			<li>CE_Sidearm</li>
			<li>CE_OneHandedWeapon</li>
		</weaponTags>
	</Operation>

	<!-- === Charge SMG, based on the S-6 from Combat Extended Guns === -->
	<Operation Class="CombatExtended.PatchOperationMakeGunCECompatible">
		<defName>VWE_Gun_ChargeSMG</defName>
		<statBases>
			<WorkToMake>56000</WorkToMake>
			<Mass>2.80</Mass>
			<Bulk>5.00</Bulk>
			<SwayFactor>0.75</SwayFactor>
			<ShotSpread>0.12</ShotSpread>
			<SightsEfficiency>1.1</SightsEfficiency>
			<RangedWeapon_Cooldown>0.36</RangedWeapon_Cooldown>
		</statBases>
		<costList>
			<Steel>30</Steel>
			<Plasteel>20</Plasteel>
			<Chemfuel>10</Chemfuel>
			<ComponentIndustrial>4</ComponentIndustrial>
			<ComponentSpacer>1</ComponentSpacer>
		</costList>
		<Properties>
			<recoilAmount>1.40</recoilAmount>
			<verbClass>CombatExtended.Verb_ShootCE</verbClass>
			<hasStandardCommand>True</hasStandardCommand>
			<defaultProjectile>Bullet_6x18mmCharged</defaultProjectile>
			<burstShotCount>6</burstShotCount>
			<ticksBetweenBurstShots>4</ticksBetweenBurstShots>
			<warmupTime>0.5</warmupTime>
			<range>31</range>
			<soundCast>VWE_Shot_ChargeSMG</soundCast>
			<soundCastTail>GunTail_Medium</soundCastTail>
			<muzzleFlashScale>9</muzzleFlashScale>
		</Properties>
		<AmmoUser>
			<magazineSize>40</magazineSize>
			<reloadTime>4</reloadTime>
			<ammoSet>AmmoSet_6x18mmCharged</ammoSet>
		</AmmoUser>
		<FireModes>
			<aiAimMode>Snapshot</aiAimMode>
			<aiUseBurstMode>True</aiUseBurstMode>
			<aimedBurstShotCount>3</aimedBurstShotCount>
		</FireModes>
		<weaponTags>
			<li>SpacerGun</li>
			<li>CE_SMG</li>
			<li>CE_AI_BROOM</li>
		</weaponTags>
	</Operation>

	<!-- === Charge Shotgun, based on the S-12 from Combat Extended Guns === -->
	<Operation Class="CombatExtended.PatchOperationMakeGunCECompatible">
		<defName>VWE_Gun_ChargeShotgun</defName>
		<statBases>
			<WorkToMake>38000</WorkToMake>
			<Mass>4.0</Mass>
			<Bulk>8.5</Bulk>
			<SwayFactor>1.25</SwayFactor>
			<ShotSpread>0.14</ShotSpread>
			<SightsEfficiency>1.1</SightsEfficiency>
			<RangedWeapon_Cooldown>0.36</RangedWeapon_Cooldown>
		</statBases>
		<costList>
			<Steel>50</Steel>
			<Plasteel>25</Plasteel>
			<Chemfuel>10</Chemfuel>
			<ComponentIndustrial>2</ComponentIndustrial>
			<ComponentSpacer>1</ComponentSpacer>
		</costList>
		<Properties>
			<recoilAmount>2.68</recoilAmount>
			<verbClass>CombatExtended.Verb_ShootCE</verbClass>
			<hasStandardCommand>True</hasStandardCommand>
			<defaultProjectile>Bullet_12GaugeCharged</defaultProjectile>
			<warmupTime>0.5</warmupTime>
			<range>20</range>
			<soundCast>VWE_Shot_ChargeShotgun</soundCast>
			<soundCastTail>GunTail_Heavy</soundCastTail>
			<muzzleFlashScale>9</muzzleFlashScale>
		</Properties>
		<AmmoUser>
			<magazineSize>12</magazineSize>
			<reloadTime>0.85</reloadTime>
			<reloadOneAtATime>true</reloadOneAtATime>
			<ammoSet>AmmoSet_12GaugeCharged</ammoSet>
		</AmmoUser>
		<FireModes>
			<aiAimMode>Snapshot</aiAimMode>
		</FireModes>
		<weaponTags>
			<li>CE_AI_BROOM</li>
			<li>CE_AI_AssaultWeapon</li>
		</weaponTags>
	</Operation>

	<!-- === Charge Sniper Rifle, based on the R-8 from Combat Extended Guns === -->
	<Operation Class="CombatExtended.PatchOperationMakeGunCECompatible">
		<defName>VWE_Gun_ChargeSniperRifle</defName>
		<statBases>
			<WorkToMake>50500</WorkToMake>
			<Mass>7.0</Mass>
			<Bulk>14.0</Bulk>
			<SwayFactor>1.47</SwayFactor>
			<ShotSpread>0.03</ShotSpread>
			<SightsEfficiency>2.6</SightsEfficiency>
			<RangedWeapon_Cooldown>0.56</RangedWeapon_Cooldown>
			<NightVisionEfficiency_Weapon>0.4</NightVisionEfficiency_Weapon>
		</statBases>
		<costList>
			<Steel>70</Steel>
			<Plasteel>35</Plasteel>
			<Chemfuel>15</Chemfuel>
			<ComponentIndustrial>5</ComponentIndustrial>
			<ComponentSpacer>1</ComponentSpacer>
		</costList>
		<Properties>
			<recoilAmount>1.82</recoilAmount>
			<verbClass>CombatExtended.Verb_ShootCE</verbClass>
			<hasStandardCommand>True</hasStandardCommand>
			<defaultProjectile>Bullet_8x50mmCharged</defaultProjectile>
			<warmupTime>1.6</warmupTime>
			<range>86</range>
			<soundCast>VWE_Shot_ChargeSniperRifle</soundCast>
			<soundCastTail>GunTail_Medium</soundCastTail>
			<muzzleFlashScale>11</muzzleFlashScale>
			<!-- This weapon previously had a three-shot burst in the base mod. However, with the 'remake' of VWE, this was removed and the gun's description explicitly states it fires a single charged slug. We can thus remove this three-shot ability -->
		</Properties>
		<AmmoUser>
			<magazineSize>10</magazineSize>
			<reloadTime>4</reloadTime>
			<ammoSet>AmmoSet_8x50mmCharged</ammoSet>
		</AmmoUser>
		<FireModes>
			<aiAimMode>AimedShot</aiAimMode>
		</FireModes>
		<weaponTags>
			<li>CE_AI_SR</li>
			<li>Bipod_DMR</li>
		</weaponTags>
		<AllowWithRunAndGun>false</AllowWithRunAndGun>
	</Operation>

	<!-- === Charge Blaster, based on the L-8 from Combat Extended Guns === -->
	<Operation Class="CombatExtended.PatchOperationMakeGunCECompatible">
		<defName>VWE_Gun_ChargeLMG</defName>
		<statBases>
			<WorkToMake>56000</WorkToMake>
			<Mass>7.0</Mass>
			<Bulk>14.00</Bulk>
			<SwayFactor>1.26</SwayFactor>
			<ShotSpread>0.05</ShotSpread>
			<SightsEfficiency>1.1</SightsEfficiency>
			<RangedWeapon_Cooldown>0.56</RangedWeapon_Cooldown>
		</statBases>
		<costList>
			<Steel>80</Steel>
			<Plasteel>40</Plasteel>
			<Chemfuel>15</Chemfuel>
			<ComponentIndustrial>5</ComponentIndustrial>
			<ComponentSpacer>1</ComponentSpacer>
		</costList>
		<Properties>
			<recoilAmount>1.40</recoilAmount>
			<verbClass>CombatExtended.Verb_ShootCE</verbClass>
			<hasStandardCommand>True</hasStandardCommand>
			<defaultProjectile>Bullet_8x35mmCharged</defaultProjectile>
			<burstShotCount>10</burstShotCount>
			<ticksBetweenBurstShots>5</ticksBetweenBurstShots>
			<warmupTime>1.25</warmupTime>
			<range>50</range>
			<soundCast>Shot_ChargeBlaster</soundCast>
			<soundCastTail>GunTail_Medium</soundCastTail>
			<muzzleFlashScale>9</muzzleFlashScale>
			<targetParams>
				<canTargetLocations>True</canTargetLocations>
			</targetParams>
		</Properties>
		<AmmoUser>
			<magazineSize>100</magazineSize>
			<reloadTime>7.8</reloadTime>
			<ammoSet>AmmoSet_8x35mmCharged</ammoSet>
		</AmmoUser>
		<FireModes>
			<aiAimMode>SuppressFire</aiAimMode>
			<aiUseBurstMode>False</aiUseBurstMode>
			<aimedBurstShotCount>5</aimedBurstShotCount>
		</FireModes>
		<weaponTags>
			<li>CE_MachineGun</li>
			<li>CE_AI_LMG</li>
			<li>AdvancedGun</li>
			<li>SpacerGun</li>
			<li>Bipod_LMG</li>
		</weaponTags>
		<AllowWithRunAndGun>false</AllowWithRunAndGun>
	</Operation>

	<!-- === Heavy Charge Blaster, very roughly based on the regular minigun as it's a charged minigun === -->
	<Operation Class="CombatExtended.PatchOperationMakeGunCECompatible">
		<defName>VWE_Gun_ChargeMinigun</defName>
		<statBases>
			<WorkToMake>100000</WorkToMake>
			<Mass>24.0</Mass>
			<Bulk>14.0</Bulk>
			<SwayFactor>2.20</SwayFactor>
			<ShotSpread>0.06</ShotSpread>
			<SightsEfficiency>1.1</SightsEfficiency>
			<RangedWeapon_Cooldown>0.80</RangedWeapon_Cooldown>
		</statBases>
		<costList>
			<Steel>120</Steel>
			<Plasteel>50</Plasteel>
			<Chemfuel>20</Chemfuel>
			<ComponentIndustrial>6</ComponentIndustrial>
			<ComponentSpacer>2</ComponentSpacer>
		</costList>
		<Properties>
			<recoilAmount>1.80</recoilAmount>
			<verbClass>CombatExtended.Verb_ShootCE</verbClass>
			<hasStandardCommand>True</hasStandardCommand>
			<defaultProjectile>Bullet_8x35mmCharged</defaultProjectile>
			<burstShotCount>40</burstShotCount>
			<ticksBetweenBurstShots>2</ticksBetweenBurstShots>
			<warmupTime>2.2</warmupTime>
			<range>62</range>
			<soundCast>VWE_Shot_ChargeMinigun</soundCast>
			<soundCastTail>GunTail_Heavy</soundCastTail>
			<muzzleFlashScale>12</muzzleFlashScale>
			<targetParams>
				<canTargetLocations>True</canTargetLocations>
			</targetParams>
		</Properties>
		<AmmoUser>
			<magazineSize>240</magazineSize>
			<reloadTime>9.2</reloadTime>
			<ammoSet>AmmoSet_8x35mmCharged</ammoSet>
		</AmmoUser>
		<FireModes>
			<aiAimMode>AimedShot</aiAimMode>
			<aiUseBurstMode>True</aiUseBurstMode>
			<aimedBurstShotCount>20</aimedBurstShotCount>
		</FireModes>
		<weaponTags>
			<li>CE_AI_Suppressive</li>
		</weaponTags>
		<AllowWithRunAndGun>false</AllowWithRunAndGun>
	</Operation>

	<!-- === Charge Missile Launcher === -->
	<Operation Class="CombatExtended.PatchOperationMakeGunCECompatible">
		<defName>VWE_Gun_ChargeRocketLauncher</defName>
		<statBases>
			<WorkToMake>88000</WorkToMake>
			<Mass>24.0</Mass>
			<Bulk>15.65</Bulk>
			<SwayFactor>3.24</SwayFactor>
			<ShotSpread>0.01</ShotSpread>
			<SightsEfficiency>2.5</SightsEfficiency>
			<RangedWeapon_Cooldown>1.9</RangedWeapon_Cooldown>
		</statBases>
		<costList>
			<Steel>30</Steel>
			<Plasteel>60</Plasteel>
			<ComponentIndustrial>4</ComponentIndustrial>
			<ComponentSpacer>1</ComponentSpacer>
		</costList>
		<Properties>
			<verbClass>CombatExtended.Verb_ShootMortarCE</verbClass>
			<hasStandardCommand>True</hasStandardCommand>
			<defaultProjectile>Bullet_AntiGrainRocket</defaultProjectile>
			<warmupTime>2</warmupTime>
			<range>62</range>
			<soundCast>InfernoCannon_Fire</soundCast>
			<soundCastTail>GunTail_Heavy</soundCastTail>
			<muzzleFlashScale>14</muzzleFlashScale>
			<onlyManualCast>True</onlyManualCast>
			<circularError>1</circularError>
			<indirectFirePenalty>0.2</indirectFirePenalty>
			<targetParams>
				<canTargetLocations>true</canTargetLocations>
			</targetParams>
		</Properties>
		<AmmoUser>
			<magazineSize>1</magazineSize>
			<reloadTime>5.6</reloadTime>
			<ammoSet>AmmoSet_ChargedRockets</ammoSet>
		</AmmoUser>
		<FireModes>
			<aiAimMode>AimedShot</aiAimMode>
		</FireModes>
		<weaponTags>
			<li>GunHeavy</li>
			<li>CE_AI_AOE</li>
		</weaponTags>
		<AllowWithRunAndGun>false</AllowWithRunAndGun>
	</Operation>
	
	<Operation Class="PatchOperationAdd">
		<xpath>Defs/ThingDef[defName="VWE_Gun_ChargeRocketLauncher"]/comps</xpath>
		<value>
			<li Class="CombatExtended.CompProperties_Charges">
				<chargeSpeeds>
					<li>50</li>
					<li>70</li>
					<li>90</li>
					<li>120</li>	
					<li>150</li>		
				</chargeSpeeds>
			</li>
		</value>
	</Operation>

	<!-- For some reason, the Combat Extended gun compatibility patch cannot properly remove the VEF.Weapons.Verb_Shoot_FlyOverhead verb from this weapon, so we have to do this -->
	
	<Operation Class="PatchOperationConditional">
		<xpath>Defs/ThingDef[defName="VWE_Gun_ChargeRocketLauncher"]/verbs/li[verbClass="VEF.Weapons.Verb_Shoot_FlyOverhead"]</xpath>
		<match Class="PatchOperationRemove">
			<xpath>Defs/ThingDef[defName="VWE_Gun_ChargeRocketLauncher"]/verbs/li[verbClass="VEF.Weapons.Verb_Shoot_FlyOverhead"]</xpath>
		</match>
	</Operation>
	
</Patch>