This commit is contained in:
2025-09-22 20:45:29 +08:00
parent 4c1cc31983
commit bb5e555acc
4 changed files with 23 additions and 23 deletions

Binary file not shown.

View File

@@ -51,6 +51,7 @@
</li> </li>
<li Class="CompProperties_Forbiddable"/> <li Class="CompProperties_Forbiddable"/>
<li Class="CompProperties_Breakdownable"/> <li Class="CompProperties_Breakdownable"/>
<li Class="ArachnaeSwarm.CompProperties_ForceTargetable" />
</comps> </comps>
<building> <building>
<turretGunDef>CatastropheMissile_Weapon</turretGunDef> <turretGunDef>CatastropheMissile_Weapon</turretGunDef>

View File

@@ -31,20 +31,13 @@ namespace ArachnaeSwarm
public override void ExposeData() public override void ExposeData()
{ {
base.ExposeData(); base.ExposeData();
// We no longer save/load longTarget here. It is only set by player action. Scribe_TargetInfo.Look(ref this.longTarget, "longTarget");
// Scribe_TargetInfo.Look(ref this.longTarget, "longTarget"); // REMOVED
} }
protected override void Tick() protected override void Tick()
{ {
// --- Attack Priority Logic --- // --- Attack Priority Logic (Remote Target has higher priority) ---
// Prio 1: Forced Local Target. Let the base class handle it. // Prio 1: Remote Target
if (this.forcedTarget.IsValid)
{
base.Tick();
return;
}
// Prio 2: Remote Target
if (this.longTarget.IsValid) if (this.longTarget.IsValid)
{ {
if (base.Active && this.burstCooldownTicksLeft <= 0 && CanFireGlobal(out _)) if (base.Active && this.burstCooldownTicksLeft <= 0 && CanFireGlobal(out _))
@@ -58,10 +51,15 @@ namespace ArachnaeSwarm
this.top.TurretTopTick(); this.top.TurretTopTick();
} }
} }
// Prio 3: No manual target, fall back to base auto-targeting. // Prio 2: Forced Local Target (Only if no remote target)
else if (this.forcedTarget.IsValid)
{
base.Tick(); // Let base class handle it
}
// Prio 3: Auto Target (if no manual targets)
else else
{ {
base.Tick(); base.Tick(); // Let base class handle it
} }
} }
@@ -78,7 +76,7 @@ namespace ArachnaeSwarm
public override IEnumerable<Gizmo> GetGizmos() public override IEnumerable<Gizmo> GetGizmos()
{ {
// Yield base gizmos first, which includes "Set forced target" // Yield base gizmos first, which includes "Set forced target" and other standard buttons.
foreach (var g in base.GetGizmos()) foreach (var g in base.GetGizmos())
{ {
yield return g; yield return g;
@@ -97,7 +95,7 @@ namespace ArachnaeSwarm
{ {
fireGlobal.Disable(reason); fireGlobal.Disable(reason);
} }
// Disable if a local forced target is already set // Global Strike button is disabled if a forced target is already set, to ensure mutual exclusivity.
if (this.forcedTarget.IsValid) if (this.forcedTarget.IsValid)
{ {
fireGlobal.Disable("LocalTargetForced".Translate()); fireGlobal.Disable("LocalTargetForced".Translate());
@@ -134,11 +132,12 @@ namespace ArachnaeSwarm
missile.Projectile = DefDatabase<ThingDef>.GetNamed("Projectile_CatastropheMissile"); missile.Projectile = DefDatabase<ThingDef>.GetNamed("Projectile_CatastropheMissile");
Find.WorldObjects.Add(missile); Find.WorldObjects.Add(missile);
if (CellFinder.TryFindRandomEdgeCellWith(c => this.Map.reachability.CanReach(this.Position, c, PathEndMode.OnCell, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly)), this.Map, 0f, out IntVec3 edgeCell)) // Rimatomics style: dummy projectile flies off-map in the direction the turret is facing.
{ Vector3 shellDirection = Vector3.forward.RotatedBy(this.top.CurRotation);
Projectile_CruiseMissile dummy = (Projectile_CruiseMissile)GenSpawn.Spawn(DefDatabase<ThingDef>.GetNamed("Projectile_CatastropheMissile_Fake"), this.Position, this.Map); IntVec3 outcell = (this.DrawPos + shellDirection * 500f).ToIntVec3();
dummy?.Launch(this, this.DrawPos, new LocalTargetInfo(edgeCell), new LocalTargetInfo(edgeCell), ProjectileHitFlags.None);
} Projectile_CruiseMissile dummy = (Projectile_CruiseMissile)GenSpawn.Spawn(DefDatabase<ThingDef>.GetNamed("Projectile_CatastropheMissile_Fake"), this.Position, this.Map);
dummy?.Launch(this, this.DrawPos, new LocalTargetInfo(outcell), new LocalTargetInfo(outcell), ProjectileHitFlags.None);
var refuelableComp = this.TryGetComp<CompRefuelable>(); var refuelableComp = this.TryGetComp<CompRefuelable>();
if(refuelableComp != null) if(refuelableComp != null)
@@ -154,7 +153,7 @@ namespace ArachnaeSwarm
private bool CanFireGlobal(out string reason) private bool CanFireGlobal(out string reason)
{ {
var refuelableComp = this.TryGetComp<CompRefuelable>(); var refuelableComp = this.TryGetComp<CompRefuelable>();
if (refuelableComp != null && !refuelableComp.HasFuel) if (refuelableComp != null && !this.refuelableComp.HasFuel)
{ {
reason = "NoFuel".Translate().CapitalizeFirst(); reason = "NoFuel".Translate().CapitalizeFirst();
return false; return false;
@@ -189,7 +188,6 @@ namespace ArachnaeSwarm
return false; return false;
} }
// Allow targeting Pawns and Buildings on the world map
if (target.WorldObject is MapParent mapParent && mapParent.HasMap) if (target.WorldObject is MapParent mapParent && mapParent.HasMap)
{ {
var originalMap = this.Map; var originalMap = this.Map;
@@ -215,6 +213,7 @@ namespace ArachnaeSwarm
{ {
this.longTarget = new GlobalTargetInfo(localTarget.Cell, mapParent.Map); this.longTarget = new GlobalTargetInfo(localTarget.Cell, mapParent.Map);
} }
this.forcedTarget = LocalTargetInfo.Invalid; // Clear local target when setting remote
}, },
null, onFinished, FireMissionTex, true); null, onFinished, FireMissionTex, true);

View File

@@ -60,8 +60,8 @@ namespace ArachnaeSwarm
Map targetMap = Current.Game.FindMap(this.destinationTile); Map targetMap = Current.Game.FindMap(this.destinationTile);
if (targetMap != null) if (targetMap != null)
{ {
// Find a random entry point at the edge of the target map // Find a random entry point at the north edge of the target map
IntVec3 entryCell = CellFinder.RandomEdgeCell(targetMap); IntVec3 entryCell = CellFinder.RandomEdgeCell(Rot4.North, targetMap);
// Spawn the final projectile (the cruise missile) at the entry point // Spawn the final projectile (the cruise missile) at the entry point
Projectile_CruiseMissile missile = (Projectile_CruiseMissile)GenSpawn.Spawn(this.Projectile, entryCell, targetMap, WipeMode.Vanish); Projectile_CruiseMissile missile = (Projectile_CruiseMissile)GenSpawn.Spawn(this.Projectile, entryCell, targetMap, WipeMode.Vanish);