Skip to content

Commit

Permalink
Merge pull request #3145 from masakitenchi/RemoteBombardmentFix
Browse files Browse the repository at this point in the history
Fix Remote Bombardment Cannot Target Ambush Map
  • Loading branch information
N7Huntsman authored May 27, 2024
2 parents bde7ef3 + 9fea2e7 commit a348e5e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions Languages/English/Keyed/Keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<CE_ArtilleryTargetLabel>Attack world tile</CE_ArtilleryTargetLabel>
<CE_ArtilleryTargetDesc>Attack a world tile. If the selected tile contains a map, you can select the attack target within that map.</CE_ArtilleryTargetDesc>
<CE_ArtilleryTarget_AlreadyDestroyed>Selected target already destroyed</CE_ArtilleryTarget_AlreadyDestroyed>
<CE_ArtilleryTarget_MustTargetMark>Can only target artillery mark</CE_ArtilleryTarget_MustTargetMark>

<!-- Marking -->
<CE_MarkingUnavailableReason>Pawn cannot mark targets for artillery because they are on a map with no local artillery and they need a radio pack to communicate with the artillery crew.\n\nMarking targets is disabled when no artillery is available in local map and the pawn doesn't have access to long range radios.</CE_MarkingUnavailableReason>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
Expand Down Expand Up @@ -44,17 +44,14 @@ public override void ProcessInput(Event ev)
Log.Error("Command_ArtilleryTarget selected turrets collection is invalid");
return;
}
int tile = turret.Map.Tile;
int turretTile = turret.Map.Tile;
int radius = (int)turret.MaxWorldRange;
Find.WorldTargeter.BeginTargeting((targetInfo) =>
{
if (!targetInfo.HasWorldObject || targetInfo.Tile == tile || targetInfo.WorldObject.GetComponent<WorldObjects.HealthComp>() == null)
{
return false;
}
IEnumerable<Building_TurretGunCE> turrets = SelectedTurrets;
Map map = Find.World.worldObjects.MapParentAt(targetInfo.Tile)?.Map ?? null;
if (map != null)
// We only want player to target world object when there's no colonist in the map
if (map != null && map.mapPawns.AnyPawnBlockingMapRemoval)
{
IntVec3 selectedCell = IntVec3.Invalid;
Find.WorldTargeter.StopTargeting();
Expand All @@ -69,15 +66,24 @@ public override void ProcessInput(Event ev)
targetInfo.mapInt = map;
targetInfo.tileInt = map.Tile;
targetInfo.cellInt = target.cellInt;
targetInfo.thingInt = target.thingInt;
//targetInfo.thingInt = target.thingInt;
TryAttack(turrets, targetInfo, target);
}, highlightAction: (target) =>
{
GenDraw.DrawTargetHighlight(target);
}, targetValidator: (target) =>
{
RoofDef roof = map.roofGrid.RoofAt(target.Cell);
return roof == null || roof == RoofDefOf.RoofConstructed;
if ((roof == null || roof == RoofDefOf.RoofConstructed) &&
target.Cell.GetFirstThing<ArtilleryMarker>(map) != null)
{
return true;
}
else
{
Messages.Message("CE_ArtilleryTarget_MustTargetMark".Translate(), MessageTypeDefOf.RejectInput);
return false;
}
});
return false;
}
Expand Down Expand Up @@ -122,14 +128,14 @@ public override void ProcessInput(Event ev)
{
if (t.MaxWorldRange != radius)
{
GenDraw.DrawWorldRadiusRing(tile, (int)t.MaxWorldRange);
GenDraw.DrawWorldRadiusRing(turretTile, (int)t.MaxWorldRange);
}
}
}
GenDraw.DrawWorldRadiusRing(tile, radius);
GenDraw.DrawWorldRadiusRing(turretTile, radius);
}, extraLabelGetter: (targetInfo) =>
{
int distanceToTarget = Find.WorldGrid.TraversalDistanceBetween(tile, targetInfo.Tile, true);
int distanceToTarget = Find.WorldGrid.TraversalDistanceBetween(turretTile, targetInfo.Tile, true);
string distanceMessage = null;
if (others != null)
{
Expand Down Expand Up @@ -169,6 +175,15 @@ public override void ProcessInput(Event ev)
}
}
return distanceMessage + "\n" + "CE_ArtilleryTarget_ClickToOrderAttack".Translate() + extra;
}, canSelectTarget: (targetInfo) =>
{
if (!targetInfo.HasWorldObject || targetInfo.Tile == turretTile ||
(targetInfo.WorldObject as MapParent)?.Map == null &&
targetInfo.WorldObject.GetComponent<WorldObjects.HealthComp>() == null)
{
return false;
}
return true;
});
base.ProcessInput(ev);
}
Expand Down

0 comments on commit a348e5e

Please sign in to comment.