Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Assemblies/CombatExtended.dll
Binary file not shown.
8 changes: 8 additions & 0 deletions Languages/English/Keyed/FloatMenu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<LanguageData>
<CE_NoAmmoAvailable>no viable ammo found nearby</CE_NoAmmoAvailable>
<CE_TurretFull>turret magazine is fully loaded</CE_TurretFull>
<CE_TurretNonAllied>turret belongs to a hostile faction</CE_TurretNonAllied>
<CE_TurretAlreadyReloading>already reloading turret</CE_TurretAlreadyReloading>
<CE_TurretIsBurning>turret is on fire</CE_TurretIsBurning>
</LanguageData>
9 changes: 9 additions & 0 deletions Patches/Core/ThinkTreeDefs/Humanlike.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@
</value>
</Operation>

<!-- =========== Add turret reloading to mechanoids ===========-->
<Operation Class="PatchOperationAdd">
<xpath>Defs/DutyDef[defName="Defend"]/thinkNode/subNodes</xpath>
<value>
<li Class="CombatExtended.JobGiver_DefenderReloadTurret"/>
</value>
<order>Prepend</order>
</Operation>

<!--<Operation Class="PatchOperationAttributeSet">
<xpath>Defs/ThinkTreeDef[defName="HumanlikeConstant"]/thinkRoot/subNodes/li[@Class="ThinkNode_ConditionalCanDoConstantThinkTreeJobNow"]/subNodes/li[@Class="JobGiver_ConfigurableHostilityResponse"]</xpath>
<attribute>Class</attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
<MaxHitPoints>100</MaxHitPoints>
<Flammability>0</Flammability>
</statBases>
<building>
<building>
<buildingTags>
<li>MechClusterMember</li>
</buildingTags>
</building>
<graphicData>
<texPath>Things/Building/Mech/MechDropBeacon</texPath> <!-- Perhaps add a custom texture? -->
<texPath>Things/Building/Mech/MechDropBeacon</texPath> <!-- Perhaps add a custom texture? -->
<graphicClass>Graphic_Single</graphicClass>
<drawSize>(1,1)</drawSize>
<shadowData>
Expand All @@ -36,9 +36,9 @@
<dormantStateLabelKey>DormantCompInactive</dormantStateLabelKey>
</li>
<li Class="CompProperties_WakeUpDormant"/>
<li Class="CombatExtended.CompProperties_AmmoResupplyOnWakeup">
<li Class="CombatExtended.CompProperties_AmmoResupplyOnWakeup">
<dropInPods>True</dropInPods>
</li>
</li>
</comps>
</ThingDef>

Expand Down
4 changes: 3 additions & 1 deletion Source/CombatExtended/CombatExtended.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@
<Compile Include="CombatExtended\Enums\LoadoutCountType.cs" />
<Compile Include="CombatExtended\ExplosionCE.cs" />
<Compile Include="CombatExtended\GenExplosionCE.cs" />
<Compile Include="CombatExtended\GenClosestAmmo.cs" />
<Compile Include="CombatExtended\Graphic_StackCountRanged.cs" />
<Compile Include="CombatExtended\Graphic_Smoke.cs" />
<Compile Include="CombatExtended\Jobs\JobDriver_Hunt.cs" />
Expand All @@ -419,16 +418,19 @@
<Compile Include="CombatExtended\Jobs\JobDriver_WaitKnockdown.cs" />
<Compile Include="CombatExtended\Jobs\JobGiver_CheckReload.cs" />
<Compile Include="CombatExtended\Jobs\JobGiver_ConfigurableHostilityResponse.cs" />
<Compile Include="CombatExtended\Jobs\JobGiver_DefenderReloadTurret.cs" />
<Compile Include="CombatExtended\Jobs\JobGiver_ManTurretsNearPointCE.cs" />
<Compile Include="CombatExtended\Jobs\JobGiver_ManTurretsNearSelfCE.cs" />
<Compile Include="CombatExtended\Jobs\JobGiver_ReactToSuppression.cs" />
<Compile Include="CombatExtended\Jobs\JobGiver_TakeAndEquip.cs" />
<Compile Include="CombatExtended\Jobs\Utils\JobGiverUtils_Reload.cs" />
<Compile Include="CombatExtended\LetterTracker.cs" />
<Compile Include="CombatExtended\Loadouts\HoldRecord.cs" />
<Compile Include="CombatExtended\Loadouts\PawnColumnWorker_MassBulkBars.cs" />
<Compile Include="CombatExtended\Loadouts\Tracker.cs" />
<Compile Include="CombatExtended\Loadouts\PawnColumnWorker_Loadout.cs" />
<Compile Include="CombatExtended\Loadouts\Utility_HoldTracker.cs" />
<Compile Include="CombatExtended\LoggerUtils\CELogger.cs" />
<Compile Include="CombatExtended\MentalState_ShellShock.cs" />
<Compile Include="CombatExtended\MentalState_CombatFrenzy.cs" />
<Compile Include="CombatExtended\ParryTracker.cs" />
Expand Down
35 changes: 25 additions & 10 deletions Source/CombatExtended/CombatExtended/Comps/CompAmmoUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public Pawn Wielder
return CompEquippable.PrimaryVerb.CasterPawn;
}
}
public bool IsEquippedGun => Wielder != null;
public Pawn Holder
{
get
Expand Down Expand Up @@ -110,14 +111,28 @@ public bool HasAmmo
return CompInventory != null && CompInventory.ammoList.Any(x => Props.ammoSet.ammoTypes.Any(a => a.ammo == x.def));
}
}
public bool HasMagazine { get { return Props.magazineSize > 0; } }
public bool HasMagazine => Props.magazineSize > 0;
public AmmoDef CurrentAmmo
{
get
{
return UseAmmo ? currentAmmoInt : null;
}
}

public bool EmptyMagazine => HasMagazine && CurMagCount == 0;
public int MissingToFullMagazine
{
get
{
if (!HasMagazine) { return 0; }
if (SelectedAmmo == CurrentAmmo) { return Props.magazineSize - CurMagCount; }
return Props.magazineSize;
}
}

public bool FullMagazine => HasMagazine && SelectedAmmo == CurrentAmmo && CurMagCount >= Props.magazineSize;

public ThingDef CurAmmoProjectile => Props.ammoSet?.ammoTypes?.FirstOrDefault(x => x.ammo == CurrentAmmo)?.projectile ?? parent.def.Verbs.FirstOrDefault().defaultProjectile;
public CompInventory CompInventory
{
Expand All @@ -130,7 +145,7 @@ private IntVec3 Position
{
get
{
if (Wielder != null) return Wielder.Position;
if (IsEquippedGun) return Wielder.Position;
else if (turret != null) return turret.Position;
else if (Holder != null) return Holder.Position;
else return parent.Position;
Expand Down Expand Up @@ -171,7 +186,7 @@ public override void Initialize(CompProperties vprops)
{
base.Initialize(vprops);

//spawnUnloaded checks have all been moved to methods calling ResetAmmoCount.
//spawnUnloaded checks have all been moved to methods calling ResetAmmoCount.
//curMagCountInt = Props.spawnUnloaded && UseAmmo ? 0 : Props.magazineSize;

// Initialize ammo with default if none is set
Expand Down Expand Up @@ -244,7 +259,7 @@ public bool TryReduceAmmoCount(int ammoConsumedPerShot = 1)
{
ammoConsumedPerShot = (ammoConsumedPerShot > 0) ? ammoConsumedPerShot : 1;

if (Wielder == null && turret == null)
if (!IsEquippedGun && turret == null)
{
Log.Error(parent.ToString() + " tried reducing its ammo count without a wielder");
}
Expand Down Expand Up @@ -307,7 +322,7 @@ public void TryStartReload()
}
return;
}
if (Wielder == null && turret == null)
if (!IsEquippedGun && turret == null)
return;

// secondary branch for if we ended up being called up by a turret somehow...
Expand All @@ -326,7 +341,7 @@ public void TryStartReload()
TryUnload();

// Check for ammo
if (Wielder != null && !HasAmmo)
if (IsEquippedGun && !HasAmmo)
{
DoOutOfAmmoAction();
return;
Expand All @@ -340,7 +355,7 @@ public void TryStartReload()
}

// Issue reload job
if (Wielder != null)
if (IsEquippedGun)
{
Job reloadJob = TryMakeReloadJob();
if (reloadJob == null)
Expand Down Expand Up @@ -427,7 +442,7 @@ private void DoOutOfAmmoAction()
{
MoteMaker.ThrowText(Position.ToVector3Shifted(), Find.CurrentMap, "CE_OutOfAmmo".Translate() + "!");
}
if (Wielder != null && CompInventory != null && (Wielder.CurJob == null || Wielder.CurJob.def != JobDefOf.Hunt)) CompInventory.SwitchToNextViableWeapon();
if (IsEquippedGun && CompInventory != null && (Wielder.CurJob == null || Wielder.CurJob.def != JobDefOf.Hunt)) CompInventory.SwitchToNextViableWeapon();
}

public void LoadAmmo(Thing ammo = null)
Expand Down Expand Up @@ -552,10 +567,10 @@ public override IEnumerable<Gizmo> CompGetGizmosExtra()
GizmoAmmoStatus ammoStatusGizmo = new GizmoAmmoStatus { compAmmo = this };
yield return ammoStatusGizmo;

if ((Wielder != null && Wielder.Faction == Faction.OfPlayer) || (turret != null && turret.Faction == Faction.OfPlayer && (turret.MannableComp != null || UseAmmo)))
if ((IsEquippedGun && Wielder.Faction == Faction.OfPlayer) || (turret != null && turret.Faction == Faction.OfPlayer && (turret.MannableComp != null || UseAmmo)))
{
Action action = null;
if (Wielder != null) action = TryStartReload;
if (IsEquippedGun) action = TryStartReload;
else if (turret?.MannableComp != null) action = turret.TryForceReload;

// Check for teaching opportunities
Expand Down
163 changes: 0 additions & 163 deletions Source/CombatExtended/CombatExtended/GenClosestAmmo.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using CombatExtended.CombatExtended.LoggerUtils;
using RimWorld;
using UnityEngine;
using Verse;
Expand Down Expand Up @@ -33,7 +34,22 @@ private CompAmmoUser compReloader

public override bool TryMakePreToilReservations(bool errorOnFailed)
{
return pawn.Reserve(TargetA, job) && (ammo == null || pawn.Reserve(TargetB, job, Mathf.Max(1, TargetThingB.stackCount - job.count), job.count));
if (!pawn.Reserve(TargetA, job))
{
CELogger.Message("Combat Extended: Could not reserve turret for reloading job.");
return false;
}
if (ammo == null)
{
CELogger.Message("Combat Extended: Ammo is null");
return false;
}
if (!pawn.Reserve(TargetB, job, Mathf.Max(1, TargetThingB.stackCount - job.count), job.count)) {
CELogger.Message("Combat Extended: Could not reserve " + Mathf.Max(1, TargetThingB.stackCount - job.count) + " of ammo.");
return false;
}
CELogger.Message("Combat Extended: Managed to reserve everything successfully.");
return true;
}

public override string GetReport()
Expand Down
Loading