Skip to content

Commit

Permalink
Fixes for new style rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
MustaphaTR committed Nov 25, 2023
1 parent dc26003 commit 3b52918
Show file tree
Hide file tree
Showing 26 changed files with 101 additions and 102 deletions.
114 changes: 57 additions & 57 deletions OpenRA.Mods.AS/Activities/EnterGarrison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,74 +120,74 @@ public override bool Tick(Actor self)
switch (lastState)
{
case EnterState.Approaching:
{
// NOTE: We can safely cancel in this case because we know the
// actor has finished any in-progress move activities
if (IsCanceling)
return true;

// Lost track of the target
if (useLastVisibleTarget && lastVisibleTarget.Type == TargetType.Invalid)
return true;

// We are not next to the target - lets fix that
if (target.Type != TargetType.Invalid && !move.CanEnterTargetNow(self, target))
{
// NOTE: We can safely cancel in this case because we know the
// actor has finished any in-progress move activities
if (IsCanceling)
return true;

// Lost track of the target
if (useLastVisibleTarget && lastVisibleTarget.Type == TargetType.Invalid)
return true;

// We are not next to the target - lets fix that
if (target.Type != TargetType.Invalid && !move.CanEnterTargetNow(self, target))
{
// Target lines are managed by this trait, so we do not pass targetLineColor
var initialTargetPosition = (useLastVisibleTarget ? lastVisibleTarget : target).CenterPosition;
QueueChild(move.MoveToTarget(self, target, initialTargetPosition));
return false;
}

// We are next to where we thought the target should be, but it isn't here
// There's not much more we can do here
if (useLastVisibleTarget || target.Type != TargetType.Actor)
return true;

// Are we ready to move into the target?
if (TryStartEnter(self, target.Actor))
{
lastState = EnterState.Entering;
QueueChild(move.MoveIntoTarget(self, target));
return false;
}

// Subclasses can cancel the activity during TryStartEnter
// Return immediately to avoid an extra tick's delay
if (IsCanceling)
return true;

// Target lines are managed by this trait, so we do not pass targetLineColor
var initialTargetPosition = (useLastVisibleTarget ? lastVisibleTarget : target).CenterPosition;
QueueChild(move.MoveToTarget(self, target, initialTargetPosition));
return false;
}

case EnterState.Entering:
// We are next to where we thought the target should be, but it isn't here
// There's not much more we can do here
if (useLastVisibleTarget || target.Type != TargetType.Actor)
return true;

// Are we ready to move into the target?
if (TryStartEnter(self, target.Actor))
{
// Re-acquire the target after change owner has happened.
if (target.Type == TargetType.Invalid)
target = Target.FromActor(target.Actor);

// Check that we reached the requested position
var targetPos = target.Positions.ClosestToWithPathFrom(self);
if (!IsCanceling && self.CenterPosition == targetPos && target.Type == TargetType.Actor)
OnEnterComplete(self, target.Actor);
else
{
// Need to move again as we have re-aquired a target
QueueChild(move.MoveToTarget(self, target, targetPos));
lastState = EnterState.Approaching;
return false;
}

lastState = EnterState.Exiting;
lastState = EnterState.Entering;
QueueChild(move.MoveIntoTarget(self, target));
return false;
}

case EnterState.Exiting:
// Subclasses can cancel the activity during TryStartEnter
// Return immediately to avoid an extra tick's delay
if (IsCanceling)
return true;

return false;
}

case EnterState.Entering:
{
// Re-acquire the target after change owner has happened.
if (target.Type == TargetType.Invalid)
target = Target.FromActor(target.Actor);

// Check that we reached the requested position
var targetPos = target.Positions.ClosestToWithPathFrom(self);
if (!IsCanceling && self.CenterPosition == targetPos && target.Type == TargetType.Actor)
OnEnterComplete(self, target.Actor);
else
{
QueueChild(move.ReturnToCell(self));
lastState = EnterState.Finished;
// Need to move again as we have re-aquired a target
QueueChild(move.MoveToTarget(self, target, targetPos));
lastState = EnterState.Approaching;
return false;
}

lastState = EnterState.Exiting;
return false;
}

case EnterState.Exiting:
{
QueueChild(move.ReturnToCell(self));
lastState = EnterState.Finished;
return false;
}
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.AS/Activities/UnloadSharedCargo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public override bool Tick(Actor self)
if (cargo.CanUnload())
{
foreach (var inu in notifiers)
inu.Unloading(self);
inu.Unloading(self);

var actor = cargo.Peek();
var spawn = self.CenterPosition;
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.AS/Effects/AirstrikePowerASEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ void IEffect.Tick(World world)

if (!enteredRange && planes.Any(p => (p.OccupiesSpace.CenterPosition - pos).Length < info.BeaconDistanceOffset.Length))
{
OnEnterRange();
enteredRange = true;
OnEnterRange();
enteredRange = true;
}

if (!planes.Any() || (enteredRange && planes.All(p => (p.OccupiesSpace.CenterPosition - pos).Length > info.BeaconDistanceOffset.Length)))
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.AS/Traits/ActorStatValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ public string CalculateMobSpawner()
if (!mobSpawnerMaster.IsTraitDisabled)
{
total += mobSpawnerMaster.Info.Actors.Length;
spawned += mobSpawnerMaster.SlaveEntries.Where(s => s.IsValid).Count();
spawned += mobSpawnerMaster.SlaveEntries.Count(s => s.IsValid);
}
}

Expand All @@ -633,7 +633,7 @@ public string CalculateDroneSpawner()
if (!droneSpawnerMaster.IsTraitDisabled)
{
total += droneSpawnerMaster.Info.Actors.Length;
spawned += droneSpawnerMaster.SlaveEntries.Where(s => s.IsValid).Count();
spawned += droneSpawnerMaster.SlaveEntries.Count(s => s.IsValid);
}
}

Expand Down
6 changes: 3 additions & 3 deletions OpenRA.Mods.AS/Traits/BotModules/SendUnitToAttackBotModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2023 The OpenRA Developers (see AUTHORS)
* Copyright (c) The OpenRA Developers and Contributors
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
Expand Down Expand Up @@ -308,10 +308,10 @@ void AttackTicks(IBot bot)
switch (targetDistance)
{
case TargetDistance.Closest:
targets = targets.OrderBy(a => (a.CenterPosition - attackActors.First().CenterPosition).HorizontalLengthSquared);
targets = targets.OrderBy(a => (a.CenterPosition - attackActors[0].CenterPosition).HorizontalLengthSquared);
break;
case TargetDistance.Furthest:
targets = targets.OrderByDescending(a => (a.CenterPosition - attackActors.First().CenterPosition).HorizontalLengthSquared);
targets = targets.OrderByDescending(a => (a.CenterPosition - attackActors[0].CenterPosition).HorizontalLengthSquared);
break;
case TargetDistance.Random:
targets = targets.Shuffle(world.LocalRandom);
Expand Down
14 changes: 7 additions & 7 deletions OpenRA.Mods.AS/Traits/ChronoResourceDelivery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ void ITick.Tick(Actor self)
ticksTillCheck--;
}

public void MovingToResources(Actor self, CPos targetCell) { Reset(); }

public void MovingToDock(Actor self, Actor hostActor, IDockHost host)
void INotifyDockClientMoving.MovingToDock(Actor self, Actor hostActor, IDockHost host)
{
var deliverypos = self.World.Map.CellContaining(host.DockPosition);

Expand All @@ -93,11 +91,13 @@ public void MovingToDock(Actor self, Actor hostActor, IDockHost host)
destination = deliverypos;
}

public void MovementCancelled(Actor self) { Reset(); }
void INotifyDockClientMoving.MovementCancelled(Actor self) { Reset(); }

void INotifyHarvestAction.MovingToResources(Actor self, CPos targetCell) { Reset(); }

void INotifyHarvestAction.MovementCancelled(Actor self) { Reset(); }

public void Harvested(Actor self, string resourceType) { }
public void Docked() { }
public void Undocked() { }
void INotifyHarvestAction.Harvested(Actor self, string resourceType) { }

void TeleportIfPossible(Actor self)
{
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.AS/Traits/Garrisonable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ void INotifyKilled.Killed(Actor self, AttackInfo e)
positionable.SetPosition(garrisoner, self.Location);

if (!inAir && positionable.CanEnterCell(self.Location, self, BlockedByActor.None))
{
{
self.World.AddFrameEndTask(w => w.Add(garrisoner));
var nbms = garrisoner.TraitsImplementing<INotifyBlockingMove>();
foreach (var nbm in nbms)
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.AS/Traits/GivesProximityBounty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class GivesProximityBountyInfo : ConditionalTraitInfo
public readonly PlayerRelationship ValidRelationships = PlayerRelationship.Neutral | PlayerRelationship.Enemy;

[Desc("DeathTypes for which a bounty should be granted.",
"Use an empty list (the default) to allow all DeathTypes.")]
"Use an empty list (the default) to allow all DeathTypes.")]
public readonly BitSet<DamageType> DeathTypes = default;

[Desc("Bounty types for the ProximityBounty traits which a bounty should be granted.",
"Use an empty list (the default) to allow all of them.")]
"Use an empty list (the default) to allow all of them.")]
public readonly BitSet<ProximityBountyType> BountyTypes = default;

public override object Create(ActorInitializer init) { return new GivesProximityBounty(this); }
Expand Down
8 changes: 4 additions & 4 deletions OpenRA.Mods.AS/Traits/Infectable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ void INotifyDamage.Damaged(Actor self, AttackInfo e)
}

void INotifyKilled.Killed(Actor self, AttackInfo e)
{
if (Infector != null)
{
{
if (Infector != null)
{
var kill = !Infector.Item3.SurviveHostDamageTypes.Overlaps(e.Damage.DamageTypes);
RemoveInfector(self, kill, e);
}
}
}

void ITick.Tick(Actor self)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.AS/Traits/MissileSpawnerMaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel ba

// Queue attack order, too.
// invalidate the slave entry so that slave will regen.
self.World.AddFrameEndTask(w => se.Actor = null);
self.World.AddFrameEndTask(w => se.Actor = null);

// Set clock so that regen happens.
if (respawnTicks <= 0) // Don't interrupt an already running timer!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override object Create(ActorInitializer init)
}
}

class HealthPercentageFirepowerMultiplier : ConditionalTrait<HealthPercentageFirepowerMultiplierInfo>, IFirepowerModifier
class HealthPercentageFirepowerMultiplier : ConditionalTrait<HealthPercentageFirepowerMultiplierInfo>, IFirepowerModifier
{
readonly Health health;

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.AS/Traits/ProximityBounty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ProximityBountyInfo : ConditionalTraitInfo
public readonly WDist Range;

[Desc("The maximum vertical range above terrain within bounty gets collected.",
"Ignored if 0 (actors are upgraded regardless of vertical distance).")]
"Ignored if 0 (actors are upgraded regardless of vertical distance).")]
public readonly WDist MaximumVerticalOffset = WDist.Zero;

[Desc("What killer diplomatic stances gathers bounty.")]
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.AS/Traits/RangedGpsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)
}

void INotifyKilled.Killed(Actor self, AttackInfo e)
{
{
if (!IsTraitDisabled)
TraitDisabled(self);
}

void INotifyActorDisposing.Disposing(Actor self)
{
{
if (!IsTraitDisabled)
TraitDisabled(self);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.AS/Traits/Render/WithVoxelHelicopterBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace OpenRA.Mods.AS.Traits
{
[Desc("Render an animated voxel based upon the voxel being inair.")]
public class WithVoxelHelicopterBodyInfo : ConditionalTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>
public class WithVoxelHelicopterBodyInfo : ConditionalTraitInfo, IRenderActorPreviewVoxelsInfo, Requires<RenderVoxelsInfo>
{
public readonly string Sequence = "idle";

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.AS/Traits/Sound/WithCargoSounds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class WithCargoSoundsInfo : ConditionalTraitInfo
public class WithCargoSounds : ConditionalTrait<WithCargoSoundsInfo>, INotifyPassengerEntered, INotifyPassengerExited
{
public WithCargoSounds(Actor self, WithCargoSoundsInfo info)
: base(info) { }
: base(info) { }

void INotifyPassengerEntered.OnPassengerEntered(Actor self, Actor passenger)
{
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.AS/Warheads/BackFireShrapnelWarhead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class BackFireShrapnelWarhead : WarheadAS, IRulesetLoaded<WeaponInfo>
public void RulesetLoaded(Ruleset rules, WeaponInfo info)
{
if (!rules.Weapons.TryGetValue(Weapon.ToLowerInvariant(), out weapon))
throw new YamlException($"Weapons Ruleset does not contain an entry '{Weapon.ToLowerInvariant()}'");
throw new YamlException($"Weapons Ruleset does not contain an entry '{Weapon.ToLowerInvariant()}'");
}

public override void DoImpact(in Target target, WarheadArgs args)
Expand Down Expand Up @@ -77,7 +77,7 @@ public override void DoImpact(in Target target, WarheadArgs args)
{
var projectile = pargs.Weapon.Projectile.Create(pargs);
if (projectile != null)
firedBy.World.AddFrameEndTask(w => w.Add(projectile));
firedBy.World.AddFrameEndTask(w => w.Add(projectile));

if (pargs.Weapon.Report != null && pargs.Weapon.Report.Length > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void ITick.Tick(Actor self)
}

if (BeforeTeleportTicks > 0)
{
{
if (--BeforeTeleportTicks == 0)
Teleport(self, targetLocation, duration, killCargo, chronosphere);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Cnc/Traits/DisguisingTurreted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public DisguisingTurreted(ActorInitializer init, DisguisingTurretedInfo info)
: base(init, info)
{
disguise = init.Self.Trait<Disguise>();
intendedTurretOffset = disguise.TurretOffsets.First();
intendedTurretOffset = disguise.TurretOffsets[0];
}

protected override void Tick(Actor self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ public bool IsProducing(string actorType)
if (triggers.HasAnyCallbacksFor(Trigger.OnProduction))
return true;

return queues.Where(q => GetBuildableInfo(actorType, q.Info.Type) != null)
.Any(q => q.AllQueued().Any());
return queues.Any(q => GetBuildableInfo(actorType, q.Info.Type) != null && q.AllQueued().Any());
}

BuildableInfo GetBuildableInfo(string actorType, string queue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ List<MiniYamlNode> IGameSaveTraitData.IssueTraitData(Actor self)

return new List<MiniYamlNode>()
{
new("Squads", "", Squads.Select(s => new MiniYamlNode("Squad", s.Serialize())).ToList()),
new("Squads", "", Squads.ConvertAll(s => new MiniYamlNode("Squad", s.Serialize()))),
new("InitialBaseCenter", FieldSaver.FormatValue(initialBaseCenter)),
new("UnitsHangingAroundTheBase", FieldSaver.FormatValue(unitsHangingAroundTheBase
.Where(u => !UnitCannotBeOrdered(u.Actor))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void Tick(Squad owner)
return;
}

if (AttackOrFleeFuzzy.Default.CanAttack(owner.Units.Select(u => u.Actor).ToList(), enemyUnits))
if (AttackOrFleeFuzzy.Default.CanAttack(owner.Units.ConvertAll(u => u.Actor), enemyUnits))
owner.FuzzyStateMachine.ChangeState(owner, new GroundUnitsAttackMoveState(), false);
else
Retreat(owner, flee: true, rearm: true, repair: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Tick(Squad owner)
return;
}

if (AttackOrFleeFuzzy.Default.CanAttack(owner.Units.Select(u => u.Actor).ToList(), enemyUnits))
if (AttackOrFleeFuzzy.Default.CanAttack(owner.Units.ConvertAll(u => u.Actor), enemyUnits))
{
// We have gathered sufficient units. Attack the nearest enemy unit.
owner.BaseLocation = RandomBuildingLocation(owner);
Expand Down
Loading

0 comments on commit 3b52918

Please sign in to comment.