Added LineBuildNode trait to filter which structure(s) a LineBuild actor can be attached to.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2014 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,
|
||||
@@ -18,6 +18,9 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
[Desc("The maximum allowed length of the line.")]
|
||||
public readonly int Range = 5;
|
||||
|
||||
[Desc("LineBuildNode 'Types' to attach to.")]
|
||||
public readonly string[] NodeTypes = { "wall" };
|
||||
}
|
||||
|
||||
public class LineBuild {}
|
||||
|
||||
24
OpenRA.Mods.RA/Buildings/LineBuildNode.cs
Normal file
24
OpenRA.Mods.RA/Buildings/LineBuildNode.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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.FileFormats;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
{
|
||||
[Desc("LineBuild actors attach to LineBuildNodes.")]
|
||||
public class LineBuildNodeInfo : TraitInfo<LineBuildNode>
|
||||
{
|
||||
[Desc("This actor is of LineBuild 'NodeType'...")]
|
||||
public readonly string[] Types = { "wall" };
|
||||
}
|
||||
|
||||
public class LineBuildNode {}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
|
||||
public static IEnumerable<CPos> GetLineBuildCells(World world, CPos location, string name, BuildingInfo bi)
|
||||
{
|
||||
int range = Rules.Info[name].Traits.Get<LineBuildInfo>().Range;
|
||||
var lbi = Rules.Info[name].Traits.Get<LineBuildInfo>();
|
||||
var topLeft = location; // 1x1 assumption!
|
||||
|
||||
if (world.IsCellBuildable(topLeft, bi))
|
||||
@@ -54,17 +54,21 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
int[] dirs = { 0, 0, 0, 0 };
|
||||
for (int d = 0; d < 4; d++)
|
||||
{
|
||||
for (int i = 1; i < range; i++)
|
||||
for (int i = 1; i < lbi.Range; i++)
|
||||
{
|
||||
if (dirs[d] != 0)
|
||||
continue;
|
||||
|
||||
CPos cell = topLeft + i * vecs[d];
|
||||
var cell = topLeft + i * vecs[d];
|
||||
if (world.IsCellBuildable(cell, bi))
|
||||
continue; // Cell is empty; continue search
|
||||
|
||||
// Cell contains an actor. Is it the type we want?
|
||||
if (world.ActorsWithTrait<LineBuild>().Any(a => (a.Actor.Info.Name == name && a.Actor.Location.X == cell.X && a.Actor.Location.Y == cell.Y)))
|
||||
if (world.ActorsWithTrait<LineBuildNode>().Any(a =>
|
||||
(
|
||||
a.Actor.Location == cell &&
|
||||
a.Actor.Info.Traits.Get<LineBuildNodeInfo>().Types.Intersect(lbi.NodeTypes).Any()
|
||||
)))
|
||||
dirs[d] = i; // Cell contains actor of correct type
|
||||
else
|
||||
dirs[d] = -1; // Cell is blocked by another actor type
|
||||
|
||||
@@ -490,6 +490,7 @@
|
||||
<Compile Include="Orders\BeaconOrderGenerator.cs" />
|
||||
<Compile Include="Widgets\LogicKeyListenerWidget.cs" />
|
||||
<Compile Include="Widgets\Logic\ControlGroupLogic.cs" />
|
||||
<Compile Include="Buildings\LineBuildNode.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
Reference in New Issue
Block a user