move Mobile et al into Mods/

This commit is contained in:
Bob
2010-10-22 11:31:13 +13:00
parent 6513bd5fe0
commit 0d9cf63dd2
34 changed files with 68 additions and 42 deletions

View File

@@ -106,7 +106,6 @@
<Compile Include="Network\Connection.cs" />
<Compile Include="Network\OrderIO.cs" />
<Compile Include="Network\OrderManager.cs" />
<Compile Include="PathSearch.cs" />
<Compile Include="Selection.cs" />
<Compile Include="Server\Connection.cs" />
<Compile Include="Server\Exts.cs" />
@@ -136,7 +135,6 @@
<Compile Include="Orders\IOrderGenerator.cs" />
<Compile Include="Player.cs" />
<Compile Include="Graphics\Sheet.cs" />
<Compile Include="PathFinder.cs" />
<Compile Include="Graphics\Sequence.cs" />
<Compile Include="Network\Order.cs" />
<Compile Include="Graphics\SequenceProvider.cs" />
@@ -151,7 +149,6 @@
<Compile Include="Graphics\SpriteRenderer.cs" />
<Compile Include="Graphics\SpriteSheetBuilder.cs" />
<Compile Include="Graphics\TerrainRenderer.cs" />
<Compile Include="Traits\Activities\Move.cs" />
<Compile Include="Traits\Activities\Turn.cs" />
<Compile Include="Traits\Building.cs" />
<Compile Include="Traits\World\BuildingInfluence.cs" />
@@ -159,7 +156,6 @@
<Compile Include="Traits\World\ResourceLayer.cs" />
<Compile Include="Traits\World\ResourceType.cs" />
<Compile Include="Traits\Selectable.cs" />
<Compile Include="Traits\Mobile.cs" />
<Compile Include="Traits\Render\RenderSimple.cs" />
<Compile Include="Traits\TraitsInterfaces.cs" />
<Compile Include="Traits\World\UnitInfluence.cs" />
@@ -202,7 +198,6 @@
<Compile Include="Traits\RevealsShroud.cs" />
<Compile Include="Traits\Targetable.cs" />
<Compile Include="Traits\Health.cs" />
<Compile Include="Traits\Activities\Drag.cs" />
<Compile Include="Widgets\VqaPlayerWidget.cs" />
<Compile Include="Widgets\Delegates\VideoPlayerDelegate.cs" />
<Compile Include="GameRules\Settings.cs" />

View File

@@ -90,7 +90,7 @@ namespace OpenRA.Support
}
}
class PerfSample : IDisposable
public class PerfSample : IDisposable
{
readonly Stopwatch sw = new Stopwatch();
readonly string Item;

View File

@@ -129,9 +129,9 @@ namespace OpenRA.Traits
}
else
{
var mobile = a.TraitOrDefault<Mobile>();
if (mobile != null)
return new[] { mobile.fromCell, mobile.toCell };
var ios = a.TraitOrDefault<IOccupySpace>();
if (ios != null)
return ios.OccupiedCells();
else
return new[] { (1f / Game.CellSize * a.CenterLocation).ToInt2() };
}

View File

@@ -28,6 +28,8 @@ namespace OpenRA
List<IEffect> effects = new List<IEffect>();
Queue<Action<World>> frameEndActions = new Queue<Action<World>>();
public int FrameNumber { get { return orderManager.LocalFrameNumber; } }
internal readonly OrderManager orderManager;
public Session LobbyInfo { get { return orderManager.LobbyInfo; } }
@@ -49,7 +51,6 @@ namespace OpenRA
}
public readonly Actor WorldActor;
public readonly PathFinder PathFinder;
public readonly Map Map;
public readonly TileSet TileSet;
@@ -109,8 +110,6 @@ namespace OpenRA
if (!p.Stances.ContainsKey(q))
p.Stances[q] = Stance.Neutral;
PathFinder = new PathFinder(this);
Sound.SoundVolumeModifier = 1.0f;
foreach (var wlh in WorldActor.TraitsImplementing<IWorldLoaded>())
wlh.WorldLoaded(this);

View File

@@ -18,6 +18,7 @@ using OpenRA;
using OpenRA.Mods.RA.Activities;
using System;
using OpenRA.Mods.RA;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.Cnc
{

View File

@@ -14,6 +14,7 @@ using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.Cnc
{

View File

@@ -11,6 +11,7 @@
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Activities
{

View File

@@ -11,6 +11,7 @@
using System.Collections.Generic;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Activities
{

View File

@@ -13,6 +13,7 @@ using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Activities
{

View File

@@ -10,6 +10,7 @@
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Activities
{

View File

@@ -12,6 +12,7 @@ using System.Linq;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Activities
{
@@ -67,7 +68,7 @@ namespace OpenRA.Mods.RA.Activities
self.QueueActivity(mobile.MoveTo(
() =>
{
return self.World.PathFinder.FindPath(PathSearch.Search(self.World, mobileInfo, true)
return self.World.WorldActor.Trait<PathFinder>().FindPath(PathSearch.Search(self.World, mobileInfo, true)
.WithHeuristic(loc => (res.GetResource(loc) != null && harv.Resources.Contains( res.GetResource(loc).info.Name )) ? 0 : 1)
.FromPoint(self.Location));
}));

View File

@@ -12,6 +12,7 @@ using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Activities
{

View File

@@ -11,6 +11,7 @@
using System.Linq;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Activities
{

View File

@@ -13,6 +13,7 @@ using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Activities
{
@@ -45,7 +46,7 @@ namespace OpenRA.Mods.RA.Activities
ps1.heuristic = PathSearch.DefaultEstimator( mobile.toCell );
var ps2 = PathSearch.FromPoint( self.World, mobile.Info, mobile.toCell, target.Location, true );
var ret = self.World.PathFinder.FindBidiPath( ps1, ps2 );
var ret = self.World.WorldActor.Trait<PathFinder>().FindBidiPath( ps1, ps2 );
if( ret.Count > 0 )
ret.RemoveAt( 0 );
return Util.SequenceActivities( mobile.MoveTo( () => ret ), this );

View File

@@ -13,6 +13,7 @@ using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using System.Drawing;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Activities
{

View File

@@ -11,6 +11,7 @@
using System.Drawing;
using OpenRA.Effects;
using OpenRA.Traits;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA
{

View File

@@ -12,6 +12,7 @@ using System;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
using System.Linq;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA
{

View File

@@ -16,6 +16,7 @@ using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA
{

View File

@@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Crates
{

View File

@@ -16,6 +16,7 @@ using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Orders;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA
{
@@ -65,7 +66,7 @@ namespace OpenRA.Mods.RA
.Where(x => x != ignore && x.HasTrait<IAcceptOre>())
.ToList();
var mi = self.Info.Traits.Get<MobileInfo>();
var path = self.World.PathFinder.FindPath(PathSearch.FromPoints(self.World, mi,
var path = self.World.WorldActor.Trait<PathFinder>().FindPath(PathSearch.FromPoints(self.World, mi,
refs.Select(r => r.Location + r.Trait<IAcceptOre>().DeliverOffset),
self.Location,
false));

View File

@@ -9,8 +9,9 @@
#endregion
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Traits.Activities
namespace OpenRA.Mods.RA.Move
{
public class Drag : IActivity
{

View File

@@ -17,8 +17,9 @@ using OpenRA.Traits.Activities;
using OpenRA.FileFormats;
using System.Diagnostics;
using OpenRA.Orders;
using OpenRA.Traits;
namespace OpenRA.Traits
namespace OpenRA.Mods.RA.Move
{
public class MobileInfo : ITraitInfo
{
@@ -180,7 +181,7 @@ namespace OpenRA.Traits
if( !order.Queued ) self.CancelActivity();
self.QueueActivity(new Activities.Move(currentLocation, 8));
self.QueueActivity(new Move(currentLocation, 8));
if (self.Owner == self.World.LocalPlayer)
self.World.AddFrameEndTask(w =>

View File

@@ -12,8 +12,10 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Traits.Activities
namespace OpenRA.Mods.RA.Move
{
class Move : CancelableActivity
{
@@ -28,7 +30,7 @@ namespace OpenRA.Traits.Activities
public Move( int2 destination )
{
this.getPath = (self,mobile) =>
self.World.PathFinder.FindPath(
self.World.WorldActor.Trait<PathFinder>().FindPath(
PathSearch.FromPoint( self.World, mobile.Info, mobile.toCell, destination, false )
.WithoutLaneBias());
this.destination = destination;
@@ -37,7 +39,7 @@ namespace OpenRA.Traits.Activities
public Move( int2 destination, int nearEnough )
{
this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPath( mobile.toCell, destination, self );
this.getPath = (self,mobile) => self.World.WorldActor.Trait<PathFinder>().FindUnitPath( mobile.toCell, destination, self );
this.destination = destination;
this.nearEnough = nearEnough;
}
@@ -45,9 +47,9 @@ namespace OpenRA.Traits.Activities
public Move(int2 destination, Actor ignoreBuilding)
{
this.getPath = (self,mobile) =>
self.World.PathFinder.FindPath(
self.World.WorldActor.Trait<PathFinder>().FindPath(
PathSearch.FromPoint( self.World, mobile.Info, mobile.toCell, destination, false )
.WithCustomBlocker( self.World.PathFinder.AvoidUnitsNear( mobile.toCell, 4, self ))
.WithCustomBlocker( self.World.WorldActor.Trait<PathFinder>().AvoidUnitsNear( mobile.toCell, 4, self ))
.WithIgnoredBuilding( ignoreBuilding ));
this.destination = destination;
@@ -57,7 +59,7 @@ namespace OpenRA.Traits.Activities
public Move( Actor target, int range )
{
this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPathToRange(
this.getPath = (self,mobile) => self.World.WorldActor.Trait<PathFinder>().FindUnitPathToRange(
mobile.toCell, target.Location,
range, self );
this.destination = null;
@@ -66,7 +68,7 @@ namespace OpenRA.Traits.Activities
public Move(Target target, int range)
{
this.getPath = (self,mobile) => self.World.PathFinder.FindUnitPathToRange(
this.getPath = (self,mobile) => self.World.WorldActor.Trait<PathFinder>().FindUnitPathToRange(
mobile.toCell, Util.CellContaining(target.CenterLocation),
range, self);
this.destination = null;

View File

@@ -15,16 +15,17 @@ using System.Linq;
using OpenRA.Support;
using OpenRA.Traits;
namespace OpenRA
namespace OpenRA.Mods.RA.Move
{
public class PathFinderInfo : ITraitInfo
{
public object Create( ActorInitializer init ) { return new PathFinder( init.world ); }
}
public class PathFinder
{
readonly World world;
public PathFinder( World world )
{
this.world = world;
}
public PathFinder( World world ) { this.world = world; }
class CachedPath
{
@@ -45,8 +46,8 @@ namespace OpenRA
var cached = CachedPaths.FirstOrDefault(p => p.from == from && p.to == target && p.actor == self);
if (cached != null)
{
Log.Write("debug", "Actor {0} asked for a path from {1} tick(s) ago", self.ActorID, Game.LocalTick - cached.tick);
cached.tick = Game.LocalTick;
Log.Write("debug", "Actor {0} asked for a path from {1} tick(s) ago", self.ActorID, world.FrameNumber - cached.tick);
cached.tick = world.FrameNumber;
return new List<int2>(cached.result);
}
@@ -61,8 +62,8 @@ namespace OpenRA
CheckSanePath2(pb, from, target);
CachedPaths.RemoveAll(p => Game.LocalTick - p.tick > MaxPathAge);
CachedPaths.Add(new CachedPath { from = from, to = target, actor = self, result = pb, tick = Game.LocalTick });
CachedPaths.RemoveAll(p => world.FrameNumber - p.tick > MaxPathAge);
CachedPaths.Add(new CachedPath { from = from, to = target, actor = self, result = pb, tick = world.FrameNumber });
return new List<int2>(pb);
}
}
@@ -98,8 +99,6 @@ namespace OpenRA
while (!search.queue.Empty)
{
var p = search.Expand( world );
PerfHistory.Increment("nodes_expanded", .01);
if (search.heuristic(p) == 0)
return MakePath(search.cellInfo, p);
}

View File

@@ -13,7 +13,7 @@ using System.Collections.Generic;
using OpenRA.FileFormats;
using OpenRA.Traits;
namespace OpenRA
namespace OpenRA.Mods.RA.Move
{
public class PathSearch
{

View File

@@ -97,6 +97,11 @@
<Compile Include="FallsToEarth.cs" />
<Compile Include="CashTrickler.cs" />
<Compile Include="LimitedAmmo.cs" />
<Compile Include="Move\Drag.cs" />
<Compile Include="Move\Mobile.cs" />
<Compile Include="Move\Move.cs" />
<Compile Include="Move\PathFinder.cs" />
<Compile Include="Move\PathSearch.cs" />
<Compile Include="MPStartLocations.cs" />
<Compile Include="Orders\DeployOrderTargeter.cs" />
<Compile Include="Orders\EnterBuildingOrderTargeter.cs" />

View File

@@ -13,6 +13,7 @@ using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using System.Drawing;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA
{

View File

@@ -16,6 +16,7 @@ using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA
{

View File

@@ -12,6 +12,7 @@ using System.Drawing;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA
{

View File

@@ -12,6 +12,7 @@ using OpenRA.Mods.RA.Effects;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA.Render
{

View File

@@ -16,6 +16,7 @@ using OpenRA.Traits.Activities;
using System.Drawing;
using System.Collections.Generic;
using OpenRA.Mods.RA.Orders;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA
{

View File

@@ -15,6 +15,7 @@ using OpenRA.Traits.Activities;
using System.Drawing;
using System.Collections.Generic;
using OpenRA.Mods.RA.Orders;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA
{

View File

@@ -178,6 +178,7 @@ World:
Maximum: 3
SpawnInterval: 120
WaterChance: 0
PathFinder:
CRATE:
Tooltip:

View File

@@ -218,6 +218,7 @@ World:
SpatialBins:
BinSize: 4
Shroud:
PathFinder:
MINP:
Mine: