Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ public override bool StartCastChecks(Verb verb, LocalTargetInfo castTarg, LocalT
{
return false;
}
//TODO 1.5
//if (TryUseAOE(verb, castTarg, destTarg))
//{
//return false;
//}
if (TryUseAOE(verb, castTarg, destTarg))
{
return false;
}
return true;
}

Expand All @@ -152,30 +151,26 @@ public bool TryUseAOE(Verb verb, LocalTargetInfo castTarg, LocalTargetInfo destT
(TargetingPawns(castTarg.Thing, distance, out targetType) || TargetingTurrets(castTarg.Thing, distance, out targetType) || Rand.Chance(0.1f)))
{
// TODO add the ability to switch to EMP ammo or weapons
if (targetType == TargetType.Turret)
{
}
// if (targetType == TargetType.Turret)
// {
// }
if (CompInventory.TryFindRandomAOEWeapon(out ThingWithComps weapon, checkAmmo: true, predicate: (g) => g.def.Verbs?.Any(t => t.range >= distance + 3) ?? false))
{
lastOpportunisticSwitch = GenTicks.TicksGame;

var nextVerb = weapon.def.verbs.First(v => !v.IsMeleeAttack);
var targtPos = AI_Utility.FindAttackedClusterCenter(SelPawn, castTarg.Cell, weapon.def.verbs.Max(v => v.range), 4, (pos) =>
{
return GenSight.LineOfSight(SelPawn.Position, pos, Map, skipFirstCell: true);
});
var job = JobMaker.MakeJob(CE_JobDefOf.OpportunisticAttack, weapon, targtPos.IsValid ? targtPos : castTarg.Cell);
job.maxNumStaticAttacks = 1;
LocalTargetInfo targetInfo = castTarg.Thing;

SelPawn.jobs.StartJob(job, JobCondition.InterruptForced);
var job = JobMaker.MakeJob(CE_JobDefOf.OpportunisticAttack, weapon, targetInfo);
job.maxNumStaticAttacks = 1;
SelPawn.jobs.StartJob(job, JobCondition.InterruptForced, cancelBusyStances: false);
return true;
}
}
}
bool TargetingPawns(Thing thing, float distance, out TargetType targetType)
{
targetType = TargetType.None;
if (thing is Pawn pawn && (distance > 8 || SelPawn.HiddingBehindCover(pawn.positionInt)) && TargetIsSquad(pawn))
if (thing is Pawn pawn && distance > 8)
{
targetType = TargetType.Pawn;
return true;
Expand All @@ -185,7 +180,7 @@ bool TargetingPawns(Thing thing, float distance, out TargetType targetType)
bool TargetingTurrets(Thing thing, float distance, out TargetType targetType)
{
targetType = TargetType.None;
if (thing is Building_Turret && (distance > 8 || SelPawn.HiddingBehindCover(thing.positionInt)))
if (thing is Building_Turret && distance > 8)
{
targetType = TargetType.Turret;
return true;
Expand Down Expand Up @@ -261,6 +256,10 @@ private bool TargetIsSquad(Pawn pawn)
int hostiles = 0;
foreach (Pawn other in pawn.Position.PawnsInRange(pawn.Map, 4))
{
if (other == null)
{
continue;
}
if (other.Faction == null)
{
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static IEnumerable<Toil> AttackStatic(IJobDriver_Tactical driver, TargetI
if (target.HasThing)
{
Pawn pawn = target.Thing as Pawn;
if (target.Thing.Destroyed || (pawn != null && !startedIncapacitated && pawn.Downed) || (pawn != null && !(pawn.GetInvisibilityComp()?.ForcedVisible ?? false)))
if (target.Thing.Destroyed || (pawn != null && !startedIncapacitated && pawn.Downed) || (pawn != null && !(pawn.GetInvisibilityComp()?.ForcedVisible ?? true)))
{
driver.EndJobWith(JobCondition.Succeeded);
return;
Expand Down