move Building et al into Mods/

This commit is contained in:
Bob
2010-11-04 17:26:56 +13:00
committed by Chris Forbes
parent fdfa1ddf97
commit 480c5edd75
60 changed files with 322 additions and 285 deletions

View File

@@ -145,6 +145,10 @@
<Project>{0DFB103F-2962-400F-8C6D-E2C28CCBA633}</Project>
<Name>OpenRA.Game</Name>
</ProjectReference>
<ProjectReference Include="..\OpenRA.Mods.RA\OpenRA.Mods.RA.csproj">
<Project>{4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E}</Project>
<Name>OpenRA.Mods.RA</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="OpenRA.Editor.Icon.ico" />

View File

@@ -8,10 +8,12 @@
*/
#endregion
using System;
using System.Drawing;
using System.Drawing.Imaging;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Mods.RA.Buildings;
namespace OpenRA.Editor
{

View File

@@ -79,7 +79,6 @@
<Compile Include="Group.cs" />
<Compile Include="Orders\GenericSelectTarget.cs" />
<Compile Include="Server\ProtocolVersion.cs" />
<Compile Include="Traits\BaseBuilding.cs" />
<Compile Include="Traits\LintAttributes.cs" />
<Compile Include="Traits\Player\PlayerResources.cs" />
<Compile Include="Traits\World\Shroud.cs" />
@@ -116,12 +115,10 @@
<Compile Include="Sound.cs" />
<Compile Include="Support\PerfHistory.cs" />
<Compile Include="Sync.cs" />
<Compile Include="Traits\CustomSellValue.cs" />
<Compile Include="Traits\World\SpatialBins.cs" />
<Compile Include="Traits\World\Country.cs" />
<Compile Include="Actor.cs" />
<Compile Include="Cursor.cs" />
<Compile Include="GameRules\Footprint.cs" />
<Compile Include="GameRules\Rules.cs" />
<Compile Include="Graphics\Animation.cs" />
<Compile Include="Game.cs" />
@@ -130,7 +127,6 @@
<Compile Include="Graphics\LineRenderer.cs" />
<Compile Include="Graphics\WorldRenderer.cs" />
<Compile Include="Traits\Activities\Idle.cs" />
<Compile Include="Traits\Activities\Sell.cs" />
<Compile Include="Orders\IOrderGenerator.cs" />
<Compile Include="Player.cs" />
<Compile Include="Graphics\Sheet.cs" />
@@ -146,8 +142,6 @@
<Compile Include="Graphics\SpriteRenderer.cs" />
<Compile Include="Graphics\SpriteSheetBuilder.cs" />
<Compile Include="Graphics\TerrainRenderer.cs" />
<Compile Include="Traits\Building.cs" />
<Compile Include="Traits\World\BuildingInfluence.cs" />
<Compile Include="Traits\World\PlayerColorPalette.cs" />
<Compile Include="Traits\World\ResourceLayer.cs" />
<Compile Include="Traits\World\ResourceType.cs" />
@@ -161,12 +155,10 @@
<Compile Include="Graphics\Util.cs" />
<Compile Include="Graphics\Viewport.cs" />
<Compile Include="Orders\UnitOrderGenerator.cs" />
<Compile Include="Widgets\WorldTooltipWidget.cs" />
<Compile Include="World.cs" />
<Compile Include="WorldUtils.cs" />
<Compile Include="Traits\Player\EvaAlerts.cs" />
<Compile Include="Traits\World\ScreenShaker.cs" />
<Compile Include="Traits\LineBuild.cs" />
<Compile Include="Widgets\WidgetLoader.cs" />
<Compile Include="Widgets\ButtonWidget.cs" />
<Compile Include="Widgets\Widget.cs" />
@@ -200,8 +192,6 @@
<Compile Include="Traits\ActorStance.cs" />
<Compile Include="Traits\Armor.cs" />
<Compile Include="Graphics\CursorProvider.cs" />
<Compile Include="Traits\Player\TechTree.cs" />
<Compile Include="Traits\Player\PowerManager.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
@@ -220,13 +210,12 @@
<Compile Include="Network\SyncReport.cs" />
<Compile Include="Server\IServerExtension.cs" />
<Compile Include="Server\NullServerExtension.cs" />
<Compile Include="Traits\BaseBuilding.cs" />
<Compile Include="Traits\ValidateOrder.cs" />
<Compile Include="Traits\Scale.cs" />
<Compile Include="TraitDictionary.cs" />
<Compile Include="Traits\Activities\CancelableActivity.cs" />
<Compile Include="Traits\SharesCell.cs" />
<Compile Include="Traits\Valued.cs" />
<Compile Include="Traits\World\BibLayer.cs" />
<Compile Include="Widgets\Delegates\DeveloperModeDelegate.cs" />
<Compile Include="Widgets\ScrollingTextWidget.cs" />
</ItemGroup>

View File

@@ -8,6 +8,8 @@
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Traits
{
/* tag trait for "bases": mcv/fact */

View File

@@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRA.Traits
{
public class ValuedInfo : TraitInfo<Valued>
{
public readonly int Cost = 0;
}
public class TooltipInfo : TraitInfo<Tooltip>
{
public readonly string Description = "";
public readonly string Name = "";
public readonly string Icon = null;
public readonly string[] AlternateName = { };
}
public class Valued { }
public class Tooltip { }
}

View File

@@ -71,7 +71,7 @@ namespace OpenRA.Traits
for (int y = map.YOffset; y < map.YOffset + map.Height; y++)
{
// Todo: Valid terrain should be specified in the resource
if (!w.IsCellBuildable(new int2(x,y), false))
if (!AllowOreAt(new int2(x,y)))
continue;
content[x, y].type = resourceTypes.FirstOrDefault(
@@ -89,6 +89,14 @@ namespace OpenRA.Traits
}
}
bool AllowOreAt( int2 a )
{
if( !world.Map.IsInMap( a.X, a.Y ) ) return false;
if( !world.GetTerrainInfo( a ).Buildable ) return false;
if( world.WorldActor.Trait<UnitInfluence>().AnyUnitsAt( a ) ) return false;
return true;
}
Sprite[] ChooseContent(ResourceType t)
{
return t.info.Sprites[world.SharedRandom.Next(t.info.Sprites.Length)];

View File

@@ -12,9 +12,6 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.GameRules;
using OpenRA.Traits;
namespace OpenRA.Traits
{
@@ -121,13 +118,6 @@ namespace OpenRA.Traits
}
public static IEnumerable<int2> GetVisOrigins(Actor a)
{
if (a.Info.Traits.Contains<BuildingInfo>())
{
var bi = a.Info.Traits.Get<BuildingInfo>();
return Footprint.Tiles(a.Info.Name, bi, a.Location);
}
else
{
var ios = a.TraitOrDefault<IOccupySpace>();
if (ios != null)
@@ -138,7 +128,6 @@ namespace OpenRA.Traits
return new[] { (1f / Game.CellSize * a.CenterLocation).ToInt2() };
}
}
void RemoveActor(Actor a)
{

View File

@@ -11,7 +11,6 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Graphics;
using OpenRA.Traits;
@@ -58,68 +57,5 @@ namespace OpenRA
foreach( var c in cells )
( c.Value ? buildOk : buildBlocked ).DrawAt( wr, Game.CellSize * c.Key, "terrain" );
}
public void DrawBuildingGrid( WorldRenderer wr, World world, string name, BuildingInfo bi )
{
var position = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2();
var topLeft = position - Footprint.AdjustForBuildingSize( bi );
var cells = new Dictionary<int2, bool>();
// Linebuild for walls.
// Assumes a 1x1 footprint; weird things will happen for other footprints
if (Rules.Info[name].Traits.Contains<LineBuildInfo>())
{
foreach( var t in LineBuildUtils.GetLineBuildCells( world, topLeft, name, bi ) )
cells.Add( t, world.IsCloseEnoughToBase( world.LocalPlayer, name, bi, t ) );
}
else
{
var res = world.WorldActor.Trait<ResourceLayer>();
var isCloseEnough = world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, topLeft);
foreach (var t in Footprint.Tiles(name, bi, topLeft))
cells.Add( t, isCloseEnough && world.IsCellBuildable(t, bi.WaterBound) && res.GetResource(t) == null );
}
DrawGrid( wr, cells );
}
}
public static class LineBuildUtils
{
public static IEnumerable<int2> GetLineBuildCells(World world, int2 location, string name, BuildingInfo bi)
{
int range = Rules.Info[name].Traits.Get<LineBuildInfo>().Range;
var topLeft = location; // 1x1 assumption!
if (world.IsCellBuildable(topLeft, bi.WaterBound))
yield return topLeft;
// Start at place location, search outwards
// TODO: First make it work, then make it nice
var vecs = new[] { new int2(1, 0), new int2(0, 1), new int2(-1, 0), new int2(0, -1) };
int[] dirs = { 0, 0, 0, 0 };
for (int d = 0; d < 4; d++)
{
for (int i = 1; i < range; i++)
{
if (dirs[d] != 0)
continue;
int2 cell = topLeft + i * vecs[d];
if (world.IsCellBuildable(cell, bi.WaterBound))
continue; // Cell is empty; continue search
// Cell contains an actor. Is it the type we want?
if (world.Queries.WithTrait<LineBuild>().Any(a => (a.Actor.Info.Name == name && a.Actor.Location.X == cell.X && a.Actor.Location.Y == cell.Y)))
dirs[d] = i; // Cell contains actor of correct type
else
dirs[d] = -1; // Cell is blocked by another actor type
}
// Place intermediate-line sections
if (dirs[d] > 0)
for (int i = 1; i < dirs[d]; i++)
yield return topLeft + i * vecs[d];
}
}
}
}

View File

@@ -12,9 +12,9 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Orders;
using OpenRA.Traits;
using OpenRA.Graphics;
namespace OpenRA.Widgets
{

View File

@@ -8,7 +8,6 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
@@ -21,22 +20,6 @@ namespace OpenRA
{
public static class WorldUtils
{
public static bool IsCellBuildable(this World world, int2 a, bool waterBound)
{
return world.IsCellBuildable(a, waterBound, null);
}
public static bool IsCellBuildable(this World world, int2 a, bool waterBound, Actor toIgnore)
{
if (world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(a) != null) return false;
if (world.WorldActor.Trait<UnitInfluence>().GetUnitsAt(a).Any(b => b != toIgnore)) return false;
if (waterBound)
return world.Map.IsInMap(a.X,a.Y) && GetTerrainInfo(world,a).IsWater;
return world.Map.IsInMap(a.X, a.Y) && world.GetTerrainInfo(a).Buildable;
}
public static IEnumerable<Actor> FindUnitsAtMouse(this World world, int2 mouseLocation)
{
var loc = mouseLocation + Game.viewport.Location;
@@ -93,14 +76,6 @@ namespace OpenRA
return world.TileSet.Terrain[world.GetTerrainType(cell)];
}
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore)
{
var res = world.WorldActor.Trait<ResourceLayer>();
return Footprint.Tiles(name, building, topLeft).All(
t => world.Map.IsInMap(t.X, t.Y) && res.GetResource(t) == null &&
world.IsCellBuildable(t, building.WaterBound, toIgnore));
}
public static bool IsVisible(this Actor a, Player byPlayer) /* must never be relied on in synced code! */
{
if (byPlayer == null) return true; // Observer
@@ -117,34 +92,7 @@ namespace OpenRA
return true;
}
public static bool IsCloseEnoughToBase(this World world, Player p, string buildingName, BuildingInfo bi, int2 topLeft)
{
var buildingMaxBounds = bi.Dimensions;
if( Rules.Info[ buildingName ].Traits.Contains<BibInfo>() )
buildingMaxBounds.Y += 1;
var scanStart = world.ClampToWorld( topLeft - new int2( bi.Adjacent, bi.Adjacent ) );
var scanEnd = world.ClampToWorld( topLeft + buildingMaxBounds + new int2( bi.Adjacent, bi.Adjacent ) );
var nearnessCandidates = new List<int2>();
for( int y = scanStart.Y ; y < scanEnd.Y ; y++ )
{
for( int x = scanStart.X ; x < scanEnd.X ; x++ )
{
var at = world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt( new int2( x, y ) );
if( at != null && at.Owner.Stances[ p ] == Stance.Ally && at.Info.Traits.Get<BuildingInfo>().BaseNormal )
nearnessCandidates.Add( new int2( x, y ) );
}
}
var buildingTiles = Footprint.Tiles( buildingName, bi, topLeft ).ToList();
return nearnessCandidates
.Any( a => buildingTiles
.Any( b => Math.Abs( a.X - b.X ) <= bi.Adjacent
&& Math.Abs( a.Y - b.Y ) <= bi.Adjacent ) );
}
static int2 ClampToWorld( this World world, int2 xy )
public static int2 ClampToWorld( this World world, int2 xy )
{
return int2.Min(world.Map.BottomRight, int2.Max(world.Map.TopLeft, xy));
}

View File

@@ -8,12 +8,10 @@
*/
#endregion
using System;
using System.Linq;
using System.Collections.Generic;
using OpenRA.Traits;
using OpenRA.Mods.RA.Render;
using OpenRA.FileFormats;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Activities
{

View File

@@ -8,6 +8,7 @@
*/
#endregion
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA

View File

@@ -9,10 +9,11 @@
#endregion
using System;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
using System.Linq;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Move;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{

View File

@@ -14,8 +14,9 @@ using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Traits
namespace OpenRA.Mods.RA.Buildings
{
class BibLayerInfo : ITraitInfo
{
@@ -88,6 +89,6 @@ namespace OpenRA.Traits
}
}
class BibInfo : TraitInfo<Bib> { }
public class BibInfo : TraitInfo<Bib> { }
public class Bib { }
}

View File

@@ -10,13 +10,11 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Effects;
using OpenRA.GameRules;
using OpenRA.Traits.Activities;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Traits
namespace OpenRA.Mods.RA.Buildings
{
public class BuildingInfo : ITraitInfo
{
@@ -36,6 +34,56 @@ namespace OpenRA.Traits
public readonly string DestroyedSound = "kaboom22.aud";
public object Create(ActorInitializer init) { return new Building(init); }
public bool IsCloseEnoughToBase(World world, Player p, string buildingName, int2 topLeft)
{
var buildingMaxBounds = Dimensions;
if( Rules.Info[ buildingName ].Traits.Contains<BibInfo>() )
buildingMaxBounds.Y += 1;
var scanStart = world.ClampToWorld( topLeft - new int2( Adjacent, Adjacent ) );
var scanEnd = world.ClampToWorld( topLeft + buildingMaxBounds + new int2( Adjacent, Adjacent ) );
var nearnessCandidates = new List<int2>();
for( int y = scanStart.Y ; y < scanEnd.Y ; y++ )
{
for( int x = scanStart.X ; x < scanEnd.X ; x++ )
{
var at = world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt( new int2( x, y ) );
if( at != null && at.Owner.Stances[ p ] == Stance.Ally && at.Info.Traits.Get<BuildingInfo>().BaseNormal )
nearnessCandidates.Add( new int2( x, y ) );
}
}
var buildingTiles = FootprintUtils.Tiles( buildingName, this, topLeft ).ToList();
return nearnessCandidates
.Any( a => buildingTiles
.Any( b => Math.Abs( a.X - b.X ) <= Adjacent
&& Math.Abs( a.Y - b.Y ) <= Adjacent ) );
}
public void DrawBuildingGrid( WorldRenderer wr, World world, string name )
{
var position = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2();
var topLeft = position - FootprintUtils.AdjustForBuildingSize( this );
var cells = new Dictionary<int2, bool>();
// Linebuild for walls.
// Assumes a 1x1 footprint; weird things will happen for other footprints
if (Rules.Info[name].Traits.Contains<LineBuildInfo>())
{
foreach( var t in BuildingUtils.GetLineBuildCells( world, topLeft, name, this ) )
cells.Add( t, IsCloseEnoughToBase( world, world.LocalPlayer, name, t ) );
}
else
{
var res = world.WorldActor.Trait<ResourceLayer>();
var isCloseEnough = IsCloseEnoughToBase(world, world.LocalPlayer, name, topLeft);
foreach (var t in FootprintUtils.Tiles(name, this, topLeft))
cells.Add( t, isCloseEnough && world.IsCellBuildable(t, WaterBound) && res.GetResource(t) == null );
}
wr.uiOverlay.DrawGrid( wr, cells );
}
}
public class Building : INotifyDamage, IResolveOrder, IOccupySpace
@@ -98,7 +146,7 @@ namespace OpenRA.Traits
public IEnumerable<int2> OccupiedCells()
{
return Footprint.UnpathableTiles( self.Info.Name, Info, TopLeft );
return FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft );
}
}
}

View File

@@ -8,11 +8,9 @@
*/
#endregion
using OpenRA.FileFormats;
using OpenRA.GameRules;
using System;
using OpenRA.Traits;
namespace OpenRA.Traits
namespace OpenRA.Mods.RA.Buildings
{
public class BuildingInfluenceInfo : ITraitInfo
{
@@ -40,7 +38,7 @@ namespace OpenRA.Traits
void ChangeInfluence( Actor a, Building building, bool isAdd )
{
foreach( var u in Footprint.Tiles( a.Info.Name, a.Info.Traits.Get<BuildingInfo>(), a.Location ) )
foreach( var u in FootprintUtils.Tiles( a.Info.Name, a.Info.Traits.Get<BuildingInfo>(), a.Location ) )
if( map.IsInMap( u ) )
influence[ u.X, u.Y ] = isAdd ? a : null;
}

View File

@@ -10,7 +10,7 @@
using OpenRA.Traits;
namespace OpenRA.Mods.RA
namespace OpenRA.Mods.RA.Buildings
{
public class CanPowerDownInfo : ITraitInfo
{

View File

@@ -8,7 +8,9 @@
*/
#endregion
namespace OpenRA.Traits
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Buildings
{
// allow a nonstandard sell/repair value to avoid
// buy-sell exploits like c&c's PROC.

View File

@@ -11,11 +11,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.GameRules
namespace OpenRA.Mods.RA.Buildings
{
public static class Footprint
public static class FootprintUtils
{
public static IEnumerable<int2> Tiles( string name, BuildingInfo buildingInfo, int2 topLeft )
{

View File

@@ -8,7 +8,9 @@
*/
#endregion
namespace OpenRA.Traits
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Buildings
{
public class LineBuildInfo : TraitInfo<LineBuild>
{

View File

@@ -8,12 +8,10 @@
*/
#endregion
using System;
using System.Linq;
using System.Collections.Generic;
using OpenRA.FileFormats;
using OpenRA.Traits;
namespace OpenRA.Traits
namespace OpenRA.Mods.RA.Buildings
{
public class PowerManagerInfo : ITraitInfo
{

View File

@@ -12,7 +12,7 @@ using System;
using OpenRA.Mods.RA.Effects;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
namespace OpenRA.Mods.RA.Buildings
{
public class RepairableBuildingInfo : ITraitInfo, ITraitPrerequisite<HealthInfo>
{

View File

@@ -10,7 +10,7 @@
using OpenRA.Traits;
namespace OpenRA.Mods.RA
namespace OpenRA.Mods.RA.Buildings
{
class RequiresPowerInfo : ITraitInfo
{

View File

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

View File

@@ -11,8 +11,9 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Traits;
namespace OpenRA.Traits
namespace OpenRA.Mods.RA.Buildings
{
public class TechTreeInfo : ITraitInfo
{

View File

@@ -0,0 +1,80 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 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 LICENSE.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Buildings
{
public static class BuildingUtils
{
public static bool IsCellBuildable(this World world, int2 a, bool waterBound)
{
return world.IsCellBuildable(a, waterBound, null);
}
public static bool IsCellBuildable(this World world, int2 a, bool waterBound, Actor toIgnore)
{
if (world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(a) != null) return false;
if (world.WorldActor.Trait<UnitInfluence>().GetUnitsAt(a).Any(b => b != toIgnore)) return false;
if (waterBound)
return world.Map.IsInMap(a.X,a.Y) && world.GetTerrainInfo(a).IsWater;
return world.Map.IsInMap(a.X, a.Y) && world.GetTerrainInfo(a).Buildable;
}
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore)
{
var res = world.WorldActor.Trait<ResourceLayer>();
return FootprintUtils.Tiles(name, building, topLeft).All(
t => world.Map.IsInMap(t.X, t.Y) && res.GetResource(t) == null &&
world.IsCellBuildable(t, building.WaterBound, toIgnore));
}
public static IEnumerable<int2> GetLineBuildCells(World world, int2 location, string name, BuildingInfo bi)
{
int range = Rules.Info[name].Traits.Get<LineBuildInfo>().Range;
var topLeft = location; // 1x1 assumption!
if (world.IsCellBuildable(topLeft, bi.WaterBound))
yield return topLeft;
// Start at place location, search outwards
// TODO: First make it work, then make it nice
var vecs = new[] { new int2(1, 0), new int2(0, 1), new int2(-1, 0), new int2(0, -1) };
int[] dirs = { 0, 0, 0, 0 };
for (int d = 0; d < 4; d++)
{
for (int i = 1; i < range; i++)
{
if (dirs[d] != 0)
continue;
int2 cell = topLeft + i * vecs[d];
if (world.IsCellBuildable(cell, bi.WaterBound))
continue; // Cell is empty; continue search
// Cell contains an actor. Is it the type we want?
if (world.Queries.WithTrait<LineBuild>().Any(a => (a.Actor.Info.Name == name && a.Actor.Location.X == cell.X && a.Actor.Location.Y == cell.Y)))
dirs[d] = i; // Cell contains actor of correct type
else
dirs[d] = -1; // Cell is blocked by another actor type
}
// Place intermediate-line sections
if (dirs[d] > 0)
for (int i = 1; i < dirs[d]; i++)
yield return topLeft + i * vecs[d];
}
}
}
}

View File

@@ -11,7 +11,7 @@
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
namespace OpenRA.Mods.RA.Buildings
{
public class WallInfo : ITraitInfo, ITraitPrerequisite<BuildingInfo>
{

View File

@@ -8,15 +8,14 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Effects;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Move;
namespace OpenRA.Mods.RA
{

View File

@@ -11,9 +11,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
using OpenRA.FileFormats;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{

View File

@@ -11,8 +11,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
using OpenRA.FileFormats;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{

View File

@@ -11,6 +11,7 @@
using System.Collections.Generic;
using OpenRA.Effects;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Effects

View File

@@ -8,11 +8,10 @@
*/
#endregion
using System;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Traits;
using OpenRA.FileFormats;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
@@ -39,7 +38,7 @@ namespace OpenRA.Mods.RA
var health = self.TraitOrDefault<Health>();
var hpFraction = (health == null) ? 1f : health.HPFraction;
var dudesValue = (int)(hpFraction * info.ValueFraction * cost);
var eligibleLocations = Footprint.Tiles(self).ToList();
var eligibleLocations = FootprintUtils.Tiles(self).ToList();
var actorTypes = info.ActorTypes.Select(a => new { Name = a, Cost = Rules.Info[a].Traits.Get<ValuedInfo>().Cost }).ToArray();
while (eligibleLocations.Count > 0 && actorTypes.Any(a => a.Cost <= dudesValue))

View File

@@ -8,13 +8,13 @@
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Effects;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Orders;
using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{

View File

@@ -12,9 +12,9 @@ using System.Collections.Generic;
using System.Drawing;
using OpenRA.Effects;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
namespace OpenRA.Mods.RA
{

View File

@@ -11,10 +11,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Network;
using OpenRA.FileFormats;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
using XRandom = OpenRA.Thirdparty.Random;
using OpenRA.FileFormats;
//TODO:
@@ -176,7 +176,7 @@ namespace OpenRA.Mods.RA
for (var k = 0; k < MaxBaseDistance; k++)
foreach (var t in world.FindTilesInCircle(baseCenter, k))
if (world.CanPlaceBuilding(item.Item, bi, t, null))
if (world.IsCloseEnoughToBase(p, item.Item, bi, t))
if (bi.IsCloseEnoughToBase(world, p, item.Item, t))
return t;
return null; // i don't know where to put it.

View File

@@ -10,13 +10,13 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Effects;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using System.Drawing;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{

View File

@@ -83,6 +83,17 @@
<Compile Include="AttackBase.cs" />
<Compile Include="AttackMove.cs" />
<Compile Include="Buildable.cs" />
<Compile Include="Buildings\BibLayer.cs" />
<Compile Include="Buildings\Building.cs" />
<Compile Include="Buildings\BuildingInfluence.cs" />
<Compile Include="Buildings\CustomSellValue.cs" />
<Compile Include="Buildings\FootprintUtils.cs" />
<Compile Include="Buildings\LineBuild.cs" />
<Compile Include="Buildings\PowerManager.cs" />
<Compile Include="Buildings\Sell.cs" />
<Compile Include="Buildings\TechTree.cs" />
<Compile Include="Buildings\Util.cs" />
<Compile Include="Valued.cs" />
<Compile Include="Combat.cs" />
<Compile Include="Player\SurrenderOnDisconnect.cs" />
<Compile Include="Crates\CloakCrateAction.cs" />
@@ -126,7 +137,7 @@
<Compile Include="Render\RenderBuildingTurreted.cs" />
<Compile Include="Render\RenderUnit.cs" />
<Compile Include="Render\RenderUnitTurreted.cs" />
<Compile Include="RepairableBuilding.cs" />
<Compile Include="Buildings\RepairableBuilding.cs" />
<Compile Include="ReservableProduction.cs" />
<Compile Include="SupportPowers\AirstrikePower.cs" />
<Compile Include="AttackFrontal.cs" />
@@ -143,7 +154,7 @@
<Compile Include="BridgeLayer.cs" />
<Compile Include="Burns.cs" />
<Compile Include="C4Demolition.cs" />
<Compile Include="CanPowerDown.cs" />
<Compile Include="Buildings\CanPowerDown.cs" />
<Compile Include="Cargo.cs" />
<Compile Include="CarpetBomb.cs" />
<Compile Include="Crates\LevelUpCrateAction.cs" />
@@ -202,7 +213,7 @@
<Compile Include="Render\RenderUnitSpinner.cs" />
<Compile Include="Repairable.cs" />
<Compile Include="RepairsUnits.cs" />
<Compile Include="RequiresPower.cs" />
<Compile Include="Buildings\RequiresPower.cs" />
<Compile Include="Mine.cs" />
<Compile Include="Minelayer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -229,7 +240,7 @@
<Compile Include="TraitsInterfaces.cs" />
<Compile Include="DefaultShellmapScript.cs" />
<Compile Include="Turreted.cs" />
<Compile Include="Wall.cs" />
<Compile Include="Buildings\Wall.cs" />
<Compile Include="WaterPaletteRotation.cs" />
<Compile Include="Weapon.cs" />
<Compile Include="Widgets\BuildPaletteWidget.cs" />
@@ -240,6 +251,7 @@
<Compile Include="Widgets\PowerBinWidget.cs" />
<Compile Include="Widgets\RadarBinWidget.cs" />
<Compile Include="Widgets\SpecialPowerBinWidget.cs" />
<Compile Include="Widgets\WorldTooltipWidget.cs" />
<Compile Include="WithMuzzleFlash.cs" />
<Compile Include="WithShadow.cs" />
<Compile Include="NukePaletteEffect.cs" />

View File

@@ -10,8 +10,8 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Orders
@@ -44,9 +44,9 @@ namespace OpenRA.Mods.RA.Orders
{
if (mi.Button == MouseButton.Left)
{
var topLeft = xy - Footprint.AdjustForBuildingSize( BuildingInfo );
var topLeft = xy - FootprintUtils.AdjustForBuildingSize( BuildingInfo );
if (!world.CanPlaceBuilding( Building, BuildingInfo, topLeft, null)
|| !world.IsCloseEnoughToBase(Producer.Owner, Building, BuildingInfo, topLeft))
|| !BuildingInfo.IsCloseEnoughToBase(world, Producer.Owner, Building, topLeft))
{
var eva = world.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
Sound.Play(eva.BuildingCannotPlaceAudio);
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA.Orders
public void RenderBeforeWorld( WorldRenderer wr, World world )
{
wr.uiOverlay.DrawBuildingGrid( wr, world, Building, BuildingInfo );
BuildingInfo.DrawBuildingGrid( wr, world, Building );
}
public string GetCursor(World world, int2 xy, MouseInput mi) { return "default"; }

View File

@@ -11,6 +11,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Buildings;
namespace OpenRA.Mods.RA.Orders
{

View File

@@ -11,6 +11,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Orders

View File

@@ -11,6 +11,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Orders

View File

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

View File

@@ -14,8 +14,9 @@ using System.Drawing;
using System.Linq;
using OpenRA.Effects;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{

View File

@@ -10,6 +10,7 @@
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA

View File

@@ -11,6 +11,7 @@
using System.Linq;
using OpenRA.Effects;
using OpenRA.FileFormats;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
@@ -45,7 +46,7 @@ namespace OpenRA.Mods.RA
if (order.OrderString == "LineBuild")
{
bool playSounds = true;
foreach (var t in LineBuildUtils.GetLineBuildCells(w, order.TargetLocation, order.TargetString, buildingInfo))
foreach (var t in BuildingUtils.GetLineBuildCells(w, order.TargetLocation, order.TargetString, buildingInfo))
{
var building = w.CreateActor(order.TargetString, new TypeDictionary
{

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA

View File

@@ -9,11 +9,11 @@
#endregion
using System;
using OpenRA.Mods.RA.Effects;
using OpenRA.Traits;
using OpenRA.GameRules;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Effects;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
@@ -87,10 +87,10 @@ namespace OpenRA.Mods.RA.Render
return;
if (e.DamageState == DamageState.Dead)
foreach (var t in Footprint.UnpathableTiles( self.Info.Name, self.Info.Traits.Get<BuildingInfo>(), self.Location ))
foreach (var t in FootprintUtils.UnpathableTiles( self.Info.Name, self.Info.Traits.Get<BuildingInfo>(), self.Location ))
{
var cell = t; // required: c# fails at bindings
self.World.AddFrameEndTask(w => w.Add(new Explosion(w, Util.CenterOfCell(cell), "building", false, 0)));
self.World.AddFrameEndTask(w => w.Add(new Explosion(w, Traits.Util.CenterOfCell(cell), "building", false, 0)));
}
else if (e.DamageState >= DamageState.Heavy && e.PreviousDamageState < DamageState.Heavy)
{

View File

@@ -8,6 +8,7 @@
*/
#endregion
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render

View File

@@ -9,6 +9,7 @@
#endregion
using System.Linq;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render

View File

@@ -8,15 +8,15 @@
*/
#endregion
using System.Linq;
using OpenRA.Mods.RA.Activities;
using OpenRA.Effects;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using System.Drawing;
using System.Collections.Generic;
using OpenRA.Mods.RA.Orders;
using System.Drawing;
using System.Linq;
using OpenRA.Effects;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.RA
});
self.CancelActivity();
self.QueueActivity(mobile.MoveTo(Util.CellContaining(order.TargetActor.CenterLocation), order.TargetActor));
self.QueueActivity(mobile.MoveTo(Traits.Util.CellContaining(order.TargetActor.CenterLocation), order.TargetActor));
self.QueueActivity(new Rearm());
self.QueueActivity(new Repair(order.TargetActor));

View File

@@ -8,14 +8,14 @@
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using System.Drawing;
using System.Collections.Generic;
using OpenRA.Mods.RA.Orders;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{

View File

@@ -11,6 +11,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Render;
using OpenRA.Traits;

View File

@@ -9,6 +9,7 @@
#endregion
using System.Linq;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits;
namespace OpenRA.Mods.RA

View File

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

View File

@@ -8,12 +8,11 @@
*/
#endregion
using OpenRA.Mods.RA.Activities;
using OpenRA.Traits;
using OpenRA.Traits.Activities;
using OpenRA.GameRules;
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
{

30
OpenRA.Mods.RA/Valued.cs Executable file
View File

@@ -0,0 +1,30 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 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 LICENSE.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public class ValuedInfo : TraitInfo<Valued>
{
public readonly int Cost = 0;
}
public class TooltipInfo : TraitInfo<Tooltip>
{
public readonly string Description = "";
public readonly string Name = "";
public readonly string Icon = null;
public readonly string[] AlternateName = { };
}
public class Valued { }
public class Tooltip { }
}

View File

@@ -14,6 +14,7 @@ using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
using OpenRA.Widgets;

View File

@@ -11,7 +11,7 @@
using System;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Traits;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets

View File

@@ -12,9 +12,9 @@ using System;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Widgets
namespace OpenRA.Mods.RA.Widgets
{
public class WorldTooltipWidget : Widget
{

View File

@@ -10,7 +10,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using OpenRA;
using OpenRA.FileFormats;
@@ -43,10 +42,10 @@ namespace RALint
Rules.LoadRules(Game.modData.Manifest, new Map());
// all the @something names which actually EXIST.
var psuedoPrereqs = Rules.Info.Values.Select(a => a.Traits.GetOrDefault<TooltipInfo>()).Where(b => b != null)
.Select(b => b.AlternateName).Where(n => n != null).SelectMany(a => a).Select(a => a.ToLowerInvariant()).Distinct();
//var psuedoPrereqs = Rules.Info.Values.Select(a => a.Traits.GetOrDefault<TooltipInfo>()).Where(b => b != null)
// .Select(b => b.AlternateName).Where(n => n != null).SelectMany(a => a).Select(a => a.ToLowerInvariant()).Distinct();
ValidPrereqs = Rules.Info.Keys.Concat(psuedoPrereqs).ToDictionary(a => a, a => 0);
//ValidPrereqs = Rules.Info.Keys.Concat(psuedoPrereqs).ToDictionary(a => a, a => 0);
foreach (var actorInfo in Rules.Info)
foreach (var traitInfo in actorInfo.Value.Traits.WithInterface<ITraitInfo>())