Generalize RallyPointInfo.Offset to support arbitrary length paths.

This commit is contained in:
Paul Chote
2020-02-09 15:30:14 +00:00
committed by abcdefg30
parent 9dc4ea8541
commit b2f0ac15e8
16 changed files with 80 additions and 25 deletions

View File

@@ -187,7 +187,7 @@ namespace OpenRA.Mods.Common.Activities
{
if (wasRepaired || isHostInvalid || (!stayOnResupplier && aircraft.Info.TakeOffOnResupply))
{
if (self.CurrentActivity.NextActivity == null && rp != null)
if (self.CurrentActivity.NextActivity == null && rp != null && rp.Path.Count > 0)
foreach (var cell in rp.Path)
QueueChild(move.MoveTo(cell, 1, ignoreActor: repairableNear != null ? null : host.Actor, targetLineColor: Color.Green));
else
@@ -208,7 +208,7 @@ namespace OpenRA.Mods.Common.Activities
// If there's a next activity and we're not RepairableNear, first leave host if the next activity is not a Move.
if (self.CurrentActivity.NextActivity == null)
{
if (rp != null)
if (rp != null && rp.Path.Count > 0)
foreach (var cell in rp.Path)
QueueChild(move.MoveTo(cell, 1, repairableNear != null ? null : host.Actor, true));
else if (repairableNear == null)

View File

@@ -73,6 +73,9 @@ namespace OpenRA.Mods.Common.Effects
foreach (var c in cachedLocations)
targetLineNodes.Add(world.Map.CenterOfCell(c));
if (targetLineNodes.Count == 0)
return;
var exitPos = building.CenterPosition;
// Find closest exit

View File

@@ -79,8 +79,21 @@ namespace OpenRA.Mods.Common.Scripting
[Desc("Query or set a factory's rally point.")]
public CPos RallyPoint
{
get { return rp.Path.Last(); }
set { rp.Path = new List<CPos> { value }; }
get
{
if (rp.Path.Count > 0)
return rp.Path.Last();
var exit = Self.FirstExitOrDefault();
if (exit != null)
return Self.Location + exit.Info.ExitCell;
return Self.Location;
}
set
{
rp.Path = new List<CPos> { value };
}
}
}

View File

@@ -228,8 +228,10 @@ namespace OpenRA.Mods.Common.Traits
{
foreach (var rp in world.ActorsWithTrait<RallyPoint>())
{
if (rp.Actor.Owner == player &&
!IsRallyPointValid(rp.Trait.Path[0], rp.Actor.Info.TraitInfoOrDefault<BuildingInfo>()))
if (rp.Actor.Owner != player)
continue;
if (rp.Trait.Path.Count == 0 || !IsRallyPointValid(rp.Trait.Path[0], rp.Actor.Info.TraitInfoOrDefault<BuildingInfo>()))
{
bot.QueueOrder(new Order("SetRallyPoint", rp.Actor, Target.FromCell(world, ChooseRallyLocationNear(rp.Actor)), false)
{

View File

@@ -39,7 +39,8 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Custom palette is a player palette BaseName")]
public readonly bool IsPlayerPalette = true;
public readonly CVec Offset = new CVec(1, 3);
[Desc("A list of 0 or more offsets defining the initial rally point path.")]
public readonly CVec[] Path = { new CVec(1, 3) };
public object Create(ActorInitializer init) { return new RallyPoint(init.Self, this); }
}
@@ -57,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits
public void ResetPath(Actor self)
{
Path = new List<CPos> { self.Location + Info.Offset };
Path = Info.Path.Select(p => self.Location + p).ToList();
}
public RallyPoint(Actor self, RallyPointInfo info)

View File

@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits
initialFacing = delta.Yaw.Facing;
}
exitLocations = rp.Value != null ? rp.Value.Path : new List<CPos> { exit };
exitLocations = rp.Value != null && rp.Value.Path.Count > 0 ? rp.Value.Path : new List<CPos> { exit };
td.Add(new LocationInit(exit));
td.Add(new CenterPositionInit(spawn));

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits
var aircraftInfo = producee.TraitInfoOrDefault<AircraftInfo>();
var mobileInfo = producee.TraitInfoOrDefault<MobileInfo>();
var destinations = rp != null ? rp.Path : new List<CPos> { self.Location };
var destinations = rp != null && rp.Path.Count > 0 ? rp.Path : new List<CPos> { self.Location };
var location = spawnLocation;
if (!location.HasValue)

View File

@@ -123,7 +123,7 @@ namespace OpenRA.Mods.Common.Traits
var initialFacing = exitinfo.Facing < 0 ? (to - spawn).Yaw.Facing : exitinfo.Facing;
exitLocations = rp.Value != null ? rp.Value.Path : new List<CPos> { exit };
exitLocations = rp.Value != null && rp.Value.Path.Count > 0 ? rp.Value.Path : new List<CPos> { exit };
td.Add(new LocationInit(exit));
td.Add(new CenterPositionInit(spawn));

View File

@@ -0,0 +1,35 @@
#region Copyright & License Information
/*
* Copyright 2007-2020 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
namespace OpenRA.Mods.Common.UpdateRules.Rules
{
class RenameRallyPointPath : UpdateRule
{
public override string Name { get { return "Renamed RallyPoint Offset to Path"; } }
public override string Description
{
get
{
return "The RallyPoint Offset property has been renamed to Path and now accepts multiple (or no) values.";
}
}
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
{
foreach (var rp in actorNode.ChildrenMatching("RallyPoint"))
rp.RenameChildrenMatching("Offset", "Path");
yield break;
}
}
}

View File

@@ -98,6 +98,7 @@ namespace OpenRA.Mods.Common.UpdateRules
new ReformatChromeProvider(),
new RenameSpins(),
new CreateScreenShakeWarhead(),
new RenameRallyPointPath(),
})
};