tidy in OreRefinery, Harvester, CncLobbyLogic, ScaredyCat

This commit is contained in:
Chris Forbes
2011-10-29 17:39:58 +13:00
parent 268f06caf0
commit 9279161de6
29 changed files with 128 additions and 165 deletions

View File

@@ -221,7 +221,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var font = Game.Renderer.Fonts[nameLabel.Font];
var nameSize = font.Measure(from);
var time = System.DateTime.Now;
var time = DateTime.Now;
timeLabel.GetText = () => "{0:D2}:{1:D2}".F(time.Hour, time.Minute);
nameLabel.GetColor = () => c;
@@ -233,11 +233,12 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
// Hack around our hacky wordwrap behavior: need to resize the widget to fit the text
text = WidgetUtils.WrapText(text, textLabel.Bounds.Width, font);
textLabel.GetText = () => text;
var oldHeight = textLabel.Bounds.Height;
textLabel.Bounds.Height = font.Measure(text).Y;
var dh = textLabel.Bounds.Height - oldHeight;
var dh = font.Measure(text).Y - textLabel.Bounds.Height;
if (dh > 0)
{
textLabel.Bounds.Height += dh;
template.Bounds.Height += dh;
}
chatPanel.AddChild(template);
chatPanel.ScrollToBottom();

View File

@@ -34,28 +34,19 @@ namespace OpenRA.Mods.RA
{
Dictionary<ResourceTypeInfo, int> contents = new Dictionary<ResourceTypeInfo, int>();
[Sync]
public Actor LinkedProc = null;
[Sync] public Actor LinkedProc = null;
[Sync] int currentUnloadTicks;
public int2? LastHarvestedCell = null;
[Sync]
public int ContentValue { get { return contents.Sum(c => c.Key.ValuePerUnit*c.Value); } }
[Sync]
int currentUnloadTicks;
[Sync] public int ContentValue { get { return contents.Sum(c => c.Key.ValuePerUnit*c.Value); } }
readonly HarvesterInfo Info;
public Harvester(Actor self, HarvesterInfo info)
{
Info = info;
self.QueueActivity( new CallFunc( () => ChooseNewProc(self, null)));
}
public void ChooseNewProc(Actor self, Actor ignore)
{
LinkedProc = ClosestProc(self, ignore);
}
public void ChooseNewProc(Actor self, Actor ignore) { LinkedProc = ClosestProc(self, ignore); }
public void ContinueHarvesting(Actor self)
{
@@ -78,7 +69,9 @@ namespace OpenRA.Mods.RA
PathSearch.FromPoints(self.World, mi, self.Owner,
refs.Select(r => r.Actor.Location + r.Trait.DeliverOffset),
self.Location, false));
path.Reverse();
if (path.Count != 0)
return refs.Where(x => x.Actor.Location + x.Trait.DeliverOffset == path[0])
.Select(a => a.Actor).FirstOrDefault();
@@ -182,10 +175,8 @@ namespace OpenRA.Mods.RA
public void UnlinkProc(Actor self, Actor proc)
{
if (LinkedProc != proc)
return;
ChooseNewProc(self, proc);
if (LinkedProc == proc)
ChooseNewProc(self, proc);
}
PipType GetPipAt(int i)
@@ -218,8 +209,9 @@ namespace OpenRA.Mods.RA
class HarvestOrderTargeter : IOrderTargeter
{
public string OrderID { get { return "Harvest";}}
public string OrderID { get { return "Harvest"; } }
public int OrderPriority { get { return 10; } }
public bool IsQueued { get; protected set; }
public bool CanTargetActor(Actor self, Actor target, bool forceAttack, bool forceQueued, ref string cursor)
{
@@ -241,7 +233,6 @@ namespace OpenRA.Mods.RA
return true;
}
public bool IsQueued { get; protected set; }
}
}
}

View File

@@ -363,6 +363,7 @@
<Compile Include="Widgets\Logic\DownloadPackagesLogic.cs" />
<Compile Include="AI\BaseBuilder.cs" />
<Compile Include="AI\HackyAI.cs" />
<Compile Include="Render\RenderInfantryPanic.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -19,9 +19,7 @@ namespace OpenRA.Mods.RA
{
public class OreRefineryInfo : ITraitInfo
{
public readonly int PipCount = 0;
public readonly PipType PipColor = PipType.Red;
public readonly int2 DockOffset = new int2 (1, 2);
public readonly int2 DockOffset = new int2(1, 2);
public readonly bool ShowTicks = true;
public readonly int TickLifetime = 30;
@@ -40,20 +38,14 @@ namespace OpenRA.Mods.RA
int currentDisplayTick = 0;
int currentDisplayValue = 0;
[Sync]
public int Ore = 0;
[Sync]
Actor dockedHarv = null;
[Sync]
bool preventDock = false;
[Sync] public int Ore = 0;
[Sync] Actor dockedHarv = null;
[Sync] bool preventDock = false;
public bool AllowDocking { get { return !preventDock; } }
public int2 DeliverOffset { get { return Info.DockOffset; } }
public virtual Activity DockSequence(Actor harv, Actor self)
{
return new RAHarvesterDockSequence(harv, self);
}
public virtual Activity DockSequence(Actor harv, Actor self) { return new RAHarvesterDockSequence(harv, self); }
public OreRefinery(Actor self, OreRefineryInfo info)
{
@@ -69,10 +61,7 @@ namespace OpenRA.Mods.RA
.Where(a => a.Trait.LinkedProc == self);
}
public bool CanGiveOre(int amount)
{
return PlayerResources.CanGiveOre(amount);
}
public bool CanGiveOre(int amount) { return PlayerResources.CanGiveOre(amount); }
public void GiveOre(int amount)
{

View File

@@ -8,10 +8,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.RA

View File

@@ -10,8 +10,8 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{

View File

@@ -10,7 +10,6 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Network;

View File

@@ -22,15 +22,13 @@ namespace OpenRA.Mods.RA
public class RadarColorFromTerrain : IRadarColorModifier
{
Color c;
public RadarColorFromTerrain(Actor self, string terrain)
{
c = self.World.TileSet.Terrain[terrain].Color;
}
public bool VisibleOnRadar(Actor self) { return true; }
public Color RadarColorOverride(Actor self)
{
return c;
}
public Color RadarColorOverride(Actor self) { return c; }
}
}

View File

@@ -9,10 +9,8 @@
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
using OpenRA.Mods.RA.Effects;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
@@ -25,8 +23,7 @@ namespace OpenRA.Mods.RA
public class RallyPoint : IIssueOrder, IResolveOrder, ISync
{
[Sync]
public int2 rallyPoint;
[Sync] public int2 rallyPoint;
public RallyPoint(Actor self)
{

View File

@@ -22,8 +22,7 @@ namespace OpenRA.Mods.RA
public class Reloads : ITick
{
[Sync]
int remainingTicks;
[Sync] int remainingTicks;
ReloadsInfo Info;
LimitedAmmo la;

View File

@@ -0,0 +1,56 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* 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. For more information,
* see COPYING.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
class RenderInfantryPanicInfo : RenderInfantryInfo, Requires<ScaredyCatInfo>
{
public override object Create(ActorInitializer init) { return new RenderInfantryPanic(init.self, this); }
}
class RenderInfantryPanic : RenderInfantry
{
readonly ScaredyCat sc;
bool wasPanic;
public RenderInfantryPanic(Actor self, RenderInfantryPanicInfo info)
: base(self, info)
{
sc = self.Trait<ScaredyCat>();
}
protected override string NormalizeInfantrySequence(Actor self, string baseSequence)
{
var prefix = sc != null && sc.Panicked ? "panic-" : "";
if (anim.HasSequence(prefix + baseSequence))
return prefix + baseSequence;
else
return baseSequence;
}
protected override bool AllowIdleAnimation(Actor self)
{
return base.AllowIdleAnimation(self) && !sc.Panicked;
}
public override void Tick (Actor self)
{
if (wasPanic != sc.Panicked)
dirty = true;
wasPanic = sc.Panicked;
base.Tick(self);
}
}
}

View File

@@ -9,7 +9,6 @@
#endregion
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;

View File

@@ -11,7 +11,6 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Effects;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Move;

View File

@@ -21,8 +21,7 @@ namespace OpenRA.Mods.RA
{
class RepairableNearInfo : ITraitInfo, Requires<HealthInfo>
{
[ActorReference]
public readonly string[] Buildings = { "spen", "syrd" };
[ActorReference] public readonly string[] Buildings = { "spen", "syrd" };
public object Create( ActorInitializer init ) { return new RepairableNear( init.self ); }
}

View File

@@ -9,8 +9,8 @@
#endregion
using System;
using OpenRA.Traits;
using OpenRA.Mods.RA.Air;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{

View File

@@ -9,7 +9,6 @@
#endregion
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
@@ -25,64 +24,17 @@ namespace OpenRA.Mods.RA
{
readonly ScaredyCatInfo Info;
public bool Panicked = false;
public ScaredyCat(Actor self, ScaredyCatInfo info)
{
Info = info;
}
public ScaredyCat(Actor self, ScaredyCatInfo info) { Info = info; }
public void TickIdle(Actor self)
{
if (!Panicked)
return;
if (!Panicked) return;
var target = Util.SubPxVector[self.World.SharedRandom.Next(255)]* Info.MoveRadius / 1024 + self.Location;
self.Trait<Mobile>().ResolveOrder(self, new Order("Move", self, false) { TargetLocation = target });
}
public void Damaged(Actor self, AttackInfo e)
{
Panicked = true;
}
}
class RenderInfantryPanicInfo : RenderInfantryInfo, Requires<ScaredyCatInfo>
{
public override object Create(ActorInitializer init) { return new RenderInfantryPanic(init.self, this); }
}
class RenderInfantryPanic : RenderInfantry
{
readonly ScaredyCat sc;
bool wasPanic;
public RenderInfantryPanic(Actor self, RenderInfantryPanicInfo info)
: base(self, info)
{
sc = self.Trait<ScaredyCat>();
}
protected override string NormalizeInfantrySequence(Actor self, string baseSequence)
{
var prefix = sc != null && sc.Panicked ? "panic-" : "";
if (anim.HasSequence(prefix + baseSequence))
return prefix + baseSequence;
else
return baseSequence;
}
protected override bool AllowIdleAnimation(Actor self)
{
return base.AllowIdleAnimation(self) && !sc.Panicked;
}
public override void Tick (Actor self)
{
if (wasPanic != sc.Panicked)
dirty = true;
wasPanic = sc.Panicked;
base.Tick(self);
}
public void Damaged(Actor self, AttackInfo e) { Panicked = true; }
}
}

View File

@@ -8,12 +8,9 @@
*/
#endregion
using System;
using System.Collections.Generic;
using OpenRA.Orders;
using OpenRA.Traits;
using OpenRA.Mods.RA.Render;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
@@ -25,6 +22,7 @@ namespace OpenRA.Mods.RA
class Sellable : IResolveOrder
{
bool selling = false;
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString == "Sell" && !selling)

View File

@@ -10,8 +10,8 @@
using System.Drawing;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
@@ -25,10 +25,8 @@ namespace OpenRA.Mods.RA
class ShroudPalette : IPalette
{
readonly ShroudPaletteInfo info;
public ShroudPalette( ShroudPaletteInfo info )
{
this.info = info;
}
public ShroudPalette( ShroudPaletteInfo info ) { this.info = info; }
public void InitPalette( WorldRenderer wr )
{

View File

@@ -9,8 +9,8 @@
#endregion
using OpenRA.GameRules;
using OpenRA.Traits;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{

View File

@@ -18,19 +18,19 @@ namespace OpenRA.Mods.RA
class TargetableBuildingInfo : ITraitInfo, Requires<BuildingInfo>
{
public readonly string[] TargetTypes = { };
public object Create( ActorInitializer init ) { return new TargetableBuilding( this ); }
}
class TargetableBuilding : ITargetable
{
readonly TargetableBuildingInfo info;
public TargetableBuilding( TargetableBuildingInfo info )
{
this.info = info;
}
public TargetableBuilding( TargetableBuildingInfo info ) { this.info = info; }
public string[] TargetTypes { get { return info.TargetTypes; } }
public bool TargetableBy(Actor self, Actor byActor) { return true; }
public IEnumerable<int2> TargetableCells( Actor self )
{
return self.Trait<Building>().OccupiedCells().Select(c => c.First);

View File

@@ -16,6 +16,7 @@ namespace OpenRA.Mods.RA
public class TargetableSubmarineInfo : TargetableUnitInfo, Requires<CloakInfo>
{
public readonly string[] CloakedTargetTypes = {};
public override object Create( ActorInitializer init ) { return new TargetableSubmarine(init.self, this); }
}
@@ -26,8 +27,8 @@ namespace OpenRA.Mods.RA
public override string[] TargetTypes
{
get { return (Cloak.Cloaked) ? info.CloakedTargetTypes
: info.TargetTypes;}
get { return Cloak.Cloaked ? info.CloakedTargetTypes
: info.TargetTypes;}
}
}
}

View File

@@ -8,10 +8,8 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRA.Traits;
namespace OpenRA.Mods.RA

View File

@@ -8,19 +8,16 @@
*/
#endregion
using System.Collections.Generic;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class TransformOnCaptureInfo : ITraitInfo
{
[ActorReference]
public readonly string IntoActor = null;
[ActorReference] public readonly string IntoActor = null;
public readonly int ForceHealthPercentage = 0;
public virtual object Create(ActorInitializer init) { return new TransformOnCapture(this); }
}
@@ -28,14 +25,14 @@ namespace OpenRA.Mods.RA
{
TransformOnCaptureInfo Info;
public TransformOnCapture(TransformOnCaptureInfo info)
{
Info = info;
}
public TransformOnCapture(TransformOnCaptureInfo info) { Info = info; }
public void OnCapture (Actor self, Actor captor, Player oldOwner, Player newOwner)
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{
self.QueueActivity(new Transform(self, Info.IntoActor) {ForceHealthPercentage = Info.ForceHealthPercentage, Facing = self.Trait<IFacing>().Facing});
self.QueueActivity(new Transform(self, Info.IntoActor) {
ForceHealthPercentage = Info.ForceHealthPercentage,
Facing = self.Trait<IFacing>().Facing
});
}
}
}

View File

@@ -10,8 +10,6 @@
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Render;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;

View File

@@ -12,15 +12,14 @@ using System.Collections.Generic;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class TransformsInfo : ITraitInfo
{
[ActorReference]
public readonly string IntoActor = null;
[ActorReference] public readonly string IntoActor = null;
public readonly int2 Offset = int2.Zero;
public readonly int Facing = 96;
public readonly string[] TransformSounds = {};

View File

@@ -45,13 +45,13 @@ namespace OpenRA.Mods.RA
facing = init.self.TraitOrDefault<IFacing>();
}
public void Tick( Actor self )
public void Tick(Actor self)
{
var df = desiredFacing ?? ( facing != null ? facing.Facing : turretFacing );
turretFacing = Util.TickFacing(turretFacing, df, info.ROT);
}
public bool FaceTarget( Actor self, Target target )
public bool FaceTarget(Actor self, Target target)
{
desiredFacing = Util.GetFacing( target.CenterLocation - self.CenterLocation, turretFacing );
return turretFacing == desiredFacing;

View File

@@ -17,16 +17,16 @@ namespace OpenRA.Mods.RA
public readonly int Cost = 0;
}
public class Valued { }
public class TooltipInfo : ITraitInfo
{
public readonly string Description = "";
public readonly string Name = "";
public readonly string Icon = null;
public virtual object Create (ActorInitializer init) { return new Tooltip(init.self, this); }
}
public class Valued { }
public virtual object Create(ActorInitializer init) { return new Tooltip(init.self, this); }
}
public class Tooltip : IToolTip
{
@@ -34,12 +34,10 @@ namespace OpenRA.Mods.RA
TooltipInfo Info;
public string Name() { return Info.Name; }
public Player Owner() { return self.Owner; }
public Stance Stance() { return self.World.LocalPlayer.Stances[self.Owner]; }
public Tooltip( Actor self, TooltipInfo info )
public Tooltip(Actor self, TooltipInfo info)
{
this.self = self;
Info = info;

View File

@@ -16,6 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class WaterPaletteRotationInfo : TraitInfo<WaterPaletteRotation> {}
class WaterPaletteRotation : ITick, IPaletteModifier
{
float t = 0;

View File

@@ -110,15 +110,14 @@ namespace OpenRA.Mods.RA
if (limitedAmmo != null && !limitedAmmo.HasAmmo())
return;
if( !Combat.IsInRange( self.CenterLocation, Info.Range, target ) )
return;
if( Combat.IsInRange( self.CenterLocation, Info.MinRange, target ) )
return;
if (!Combat.IsInRange(self.CenterLocation, Info.Range, target)) return;
if (Combat.IsInRange(self.CenterLocation, Info.MinRange, target)) return;
if (!IsValidAgainst(self.World, target)) return;
var barrel = Barrels[Burst % Barrels.Length];
var destMove = target.IsActor ? target.Actor.TraitOrDefault<IMove>() : null;
var turreted = self.TraitOrDefault<Turreted>();
var args = new ProjectileArgs
{
@@ -134,7 +133,7 @@ namespace OpenRA.Mods.RA
destAltitude = destMove != null ? destMove.Altitude : 0,
facing = barrel.Facing +
(self.HasTrait<Turreted>() ? self.Trait<Turreted>().turretFacing :
(turreted != null ? turreted.turretFacing :
facing != null ? facing.Facing : Util.GetFacing(target.CenterLocation - self.CenterLocation, 0)),
firepowerModifier = self.TraitsImplementing<IFirepowerModifier>()