Step three in implementing sandworms

Removed/fixed comments

Code style fixes

Fixed AttackWander, addressed style nits

Fix Travis crash
This commit is contained in:
penev92
2014-11-03 00:14:53 +02:00
parent 1057f8ff3b
commit c4efd269d4
16 changed files with 154 additions and 203 deletions

View File

@@ -14,6 +14,7 @@ using System.Drawing;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Move;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
@@ -25,7 +26,8 @@ namespace OpenRA.Mods.RA
public readonly string Cursor = "attack";
public readonly string OutsideRangeCursor = "attackoutsiderange";
[Desc("Does the attack type requires the attacker to enter the target's cell?")]
[Desc("Does the attack type require the attacker to enter the target's cell?")]
public readonly bool AttackRequiresEnteringCell = false;
public abstract object Create(ActorInitializer init);
@@ -61,6 +63,9 @@ namespace OpenRA.Mods.RA
if (!self.IsInWorld)
return false;
if (!HasAnyValidWeapons(target))
return false;
// Building is under construction or is being sold
if (building.Value != null && !building.Value.BuildComplete)
return false;
@@ -137,7 +142,18 @@ namespace OpenRA.Mods.RA
public abstract Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove);
public bool HasAnyValidWeapons(Target t) { return Armaments.Any(a => a.Weapon.IsValidAgainst(t, self.World, self)); }
public bool HasAnyValidWeapons(Target t)
{
if (Info.AttackRequiresEnteringCell)
{
var positionable = self.TraitOrDefault<IPositionable>();
if (positionable == null || !positionable.CanEnterCell(t.Actor.Location, null, false))
return false;
}
return Armaments.Any(a => a.Weapon.IsValidAgainst(t, self.World, self));
}
public WRange GetMaximumRange()
{
return Armaments.Select(a => a.Weapon.Range).Append(WRange.Zero).Max();

View File

@@ -17,14 +17,20 @@ namespace OpenRA.Mods.RA
"This conflicts with player orders and should only be added to animal creeps.")]
class AttackWanderInfo : ITraitInfo
{
public readonly int MoveRadius = 4;
readonly public int WanderMoveRadius = 10;
[Desc("Number of ticks to wait until decreasing the effective move radius.")]
public readonly int MoveReductionRadiusScale = 5;
public object Create(ActorInitializer init) { return new AttackWander(init.self, this); }
}
class AttackWander : INotifyIdle
{
int ticksIdle;
int effectiveMoveRadius;
readonly AttackWanderInfo Info;
public AttackWander(Actor self, AttackWanderInfo info)
{
Info = info;
@@ -32,9 +38,22 @@ namespace OpenRA.Mods.RA
public void TickIdle(Actor self)
{
var target = self.CenterPosition + new WVec(0, -1024*Info.MoveRadius, 0).Rotate(WRot.FromFacing(self.World.SharedRandom.Next(255)));
// TODO: This needs to be looked into again. The bigger MoveRadius is, the bigger chance that the selected coordinates will be invalid.
self.Trait<AttackMove>().ResolveOrder(self, new Order("AttackMove", self, false) { TargetLocation = self.World.Map.CellContaining(target) });
var target = self.CenterPosition + new WVec(0, -1024 * effectiveMoveRadius, 0).Rotate(WRot.FromFacing(self.World.SharedRandom.Next(255)));
var targetCell = self.World.Map.CellContaining(target);
if (!self.World.Map.Contains(targetCell))
{
// If MoveRadius is too big there might not be a valid cell to order the attack to (if actor is on a small island and can't leave)
if (++ticksIdle % Info.MoveReductionRadiusScale == 0)
effectiveMoveRadius--;
return; // We'll be back the next tick; better to sit idle for a few seconds than prolongue this tick indefinitely with a loop
}
self.Trait<AttackMove>().ResolveOrder(self, new Order("AttackMove", self, false) { TargetLocation = targetCell });
ticksIdle = 0;
effectiveMoveRadius = Info.WanderMoveRadius;
}
}
}

View File

@@ -10,7 +10,6 @@
using System.Drawing;
using System.Linq;
using OpenRA.Mods.RA.Move;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
@@ -164,15 +163,12 @@ namespace OpenRA.Mods.RA
nextScanTime = self.World.SharedRandom.Next(info.MinimumScanTimeInterval, info.MaximumScanTimeInterval);
var inRange = self.World.FindActorsInCircle(self.CenterPosition, range);
var mobile = self.TraitOrDefault<Mobile>();
return inRange
.Where(a =>
a.AppearsHostileTo(self) &&
!a.HasTrait<AutoTargetIgnore>() &&
attack.HasAnyValidWeapons(Target.FromActor(a)) &&
self.Owner.Shroud.IsTargetable(a) &&
(!attack.Info.AttackRequiresEnteringCell || (mobile != null && mobile.MovementSpeedForCell(self, a.Location) != 0))
)
a.AppearsHostileTo(self) &&
!a.HasTrait<AutoTargetIgnore>() &&
attack.HasAnyValidWeapons(Target.FromActor(a)) &&
self.Owner.Shroud.IsTargetable(a))
.ClosestTo(self);
}
}