Add a nearEnough field for RallyPoints (to be used as an argument for their AttackMove activities) so the Soviets don't get stuck on their rally point, and scatter the units a bit before they attack

This commit is contained in:
Scott_NZ
2012-09-15 18:55:13 +12:00
parent fd96d08ce8
commit 8fabf1504a
3 changed files with 17 additions and 13 deletions

View File

@@ -16,11 +16,11 @@ using OpenRA.FileFormats;
using OpenRA.Mods.RA.Activities; using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Air; using OpenRA.Mods.RA.Air;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Effects;
using OpenRA.Mods.RA.Move;
using OpenRA.Network; using OpenRA.Network;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Widgets; using OpenRA.Widgets;
using Gfx = OpenRA.Graphics;
using OpenRA.Mods.RA.Effects;
namespace OpenRA.Mods.RA.Missions namespace OpenRA.Mods.RA.Missions
{ {
@@ -237,17 +237,18 @@ namespace OpenRA.Mods.RA.Missions
void ManageSovietUnits() void ManageSovietUnits()
{ {
var idleSovietUnitsAtRP = ForcesNearLocation(sovietRallyPoint.CenterLocation, 3).Where(a => a.Owner == soviets && a.IsIdle); var idleSovietUnitsAtRP = ForcesNearLocation(sovietRallyPoint.CenterLocation, 3).Where(a => a.Owner == soviets && a.IsIdle && a.HasTrait<Mobile>());
if (idleSovietUnitsAtRP.Count() >= SovietGroupSize) if (idleSovietUnitsAtRP.Count() >= SovietGroupSize)
{ {
var firstIdleUnit = idleSovietUnitsAtRP.FirstOrDefault(); var firstUnit = idleSovietUnitsAtRP.FirstOrDefault();
if (firstIdleUnit != null) if (firstUnit != null)
{ {
var closestAlliedBuilding = ClosestAlliedBuilding(firstIdleUnit, 20); var closestAlliedBuilding = ClosestAlliedBuilding(firstUnit, 40);
if (closestAlliedBuilding != null) if (closestAlliedBuilding != null)
{ {
foreach (var unit in idleSovietUnitsAtRP) foreach (var unit in idleSovietUnitsAtRP)
{ {
unit.Trait<Mobile>().Nudge(unit, unit, true);
unit.QueueActivity(new AttackMove.AttackMoveActivity(unit, new Move.Move(closestAlliedBuilding.Location, 3))); unit.QueueActivity(new AttackMove.AttackMoveActivity(unit, new Move.Move(closestAlliedBuilding.Location, 3)));
} }
} }
@@ -267,15 +268,17 @@ namespace OpenRA.Mods.RA.Missions
Actor ClosestAlliedBuilding(Actor actor, int range) Actor ClosestAlliedBuilding(Actor actor, int range)
{ {
return BuildingsNearLocation(actor.CenterLocation, range) return BuildingsNearLocation(actor.CenterLocation, range)
.Where(a => a.Owner == allies2) .Where(a => a.Owner == allies2)
.OrderBy(a => (actor.Location - a.Location).LengthSquared) .OrderBy(a => (actor.Location - a.Location).LengthSquared)
.FirstOrDefault(); .FirstOrDefault();
} }
void InitializeSovietFactories() void InitializeSovietFactories()
{ {
sovietBarracks.Trait<RallyPoint>().rallyPoint = sovietRallyPoint.Location; var sbrp = sovietBarracks.Trait<RallyPoint>();
sovietWarFactory.Trait<RallyPoint>().rallyPoint = sovietRallyPoint.Location; var swrp = sovietWarFactory.Trait<RallyPoint>();
sbrp.rallyPoint = swrp.rallyPoint = sovietRallyPoint.Location;
sbrp.nearEnough = swrp.nearEnough = 3;
sovietBarracks.Trait<PrimaryBuilding>().SetPrimaryProducer(sovietBarracks, true); sovietBarracks.Trait<PrimaryBuilding>().SetPrimaryProducer(sovietBarracks, true);
sovietWarFactory.Trait<PrimaryBuilding>().SetPrimaryProducer(sovietWarFactory, true); sovietWarFactory.Trait<PrimaryBuilding>().SetPrimaryProducer(sovietWarFactory, true);
} }

View File

@@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA
if (mobile != null) if (mobile != null)
{ {
newUnit.QueueActivity(new AttackMove.AttackMoveActivity( newUnit.QueueActivity(new AttackMove.AttackMoveActivity(
newUnit, mobile.MoveTo(rp.rallyPoint, 1))); newUnit, mobile.MoveTo(rp.rallyPoint, rp.nearEnough)));
return rp.rallyPoint; return rp.rallyPoint;
} }

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
@@ -24,6 +24,7 @@ namespace OpenRA.Mods.RA
public class RallyPoint : IIssueOrder, IResolveOrder, ISync public class RallyPoint : IIssueOrder, IResolveOrder, ISync
{ {
[Sync] public CPos rallyPoint; [Sync] public CPos rallyPoint;
public int nearEnough = 1;
public RallyPoint(Actor self) public RallyPoint(Actor self)
{ {