Some initial hacks towards multiple-infantry-per-cell. Make the pathfinder smart enough to do what we need, and remove a *lot* of stupid duplication. Needs more work.
This commit is contained in:
@@ -76,15 +76,9 @@ namespace OpenRA.Mods.RA.Activities
|
||||
self.QueueActivity(new Move(
|
||||
() =>
|
||||
{
|
||||
var search = new PathSearch(self.World)
|
||||
{
|
||||
heuristic = loc => (res.GetResource(loc) != null
|
||||
&& harv.Resources.Contains( res.GetResource(loc).info.Name )) ? 0 : 1,
|
||||
umt = UnitMovementType.Wheel,
|
||||
checkForBlocked = true
|
||||
};
|
||||
search.AddInitialCell(self.World, self.Location);
|
||||
return self.World.PathFinder.FindPath(search);
|
||||
return self.World.PathFinder.FindPath(PathSearch.Search(self, UnitMovementType.Wheel, true)
|
||||
.WithHeuristic(loc => (res.GetResource(loc) != null && harv.Resources.Contains( res.GetResource(loc).info.Name )) ? 0 : 1)
|
||||
.FromPoint(self.Location));
|
||||
}));
|
||||
self.QueueActivity(new Harvest());
|
||||
}
|
||||
|
||||
@@ -38,8 +38,9 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if (unit.Altitude == 0)
|
||||
return NextActivity;
|
||||
|
||||
if (requireSpace && !self.World.IsPathableCell(self.Location, UnitMovementType.Foot))
|
||||
return this; // fail to land if no space
|
||||
// Todo: check if we can land here
|
||||
//if (requireSpace && !self.World.IsPathableCell(self.Location, UnitMovementType.Foot))
|
||||
// return this; // fail to land if no space
|
||||
|
||||
--unit.Altitude;
|
||||
return this;
|
||||
|
||||
@@ -30,17 +30,18 @@ namespace OpenRA.Mods.RA.Activities
|
||||
public IActivity NextActivity { get; set; }
|
||||
bool isCanceled;
|
||||
|
||||
int2? ChooseExitTile(Actor self)
|
||||
int2? ChooseExitTile(Actor self, Actor cargo)
|
||||
{
|
||||
// is anyone still hogging this tile?
|
||||
if (self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(self.Location).Count() > 1)
|
||||
return null;
|
||||
|
||||
var mobile = cargo.traits.Get<Mobile>();
|
||||
|
||||
for (var i = -1; i < 2; i++)
|
||||
for (var j = -1; j < 2; j++)
|
||||
if ((i != 0 || j != 0) &&
|
||||
self.World.IsPathableCell(self.Location + new int2(i, j),
|
||||
UnitMovementType.Foot))
|
||||
mobile.CanEnterCell(self.Location + new int2(i, j)))
|
||||
return self.Location + new int2(i, j);
|
||||
|
||||
return null;
|
||||
@@ -68,7 +69,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if (ru != null)
|
||||
ru.PlayCustomAnimation(self, "unload", null);
|
||||
|
||||
var exitTile = ChooseExitTile(self);
|
||||
var exitTile = ChooseExitTile(self, cargo.Peek(self));
|
||||
if (exitTile == null)
|
||||
return this;
|
||||
|
||||
|
||||
@@ -70,6 +70,11 @@ namespace OpenRA.Mods.RA
|
||||
return cargo.Count == 0;
|
||||
}
|
||||
|
||||
public Actor Peek(Actor self)
|
||||
{
|
||||
return cargo[0];
|
||||
}
|
||||
|
||||
public Actor Unload(Actor self)
|
||||
{
|
||||
var a = cargo[0];
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
@@ -65,23 +66,30 @@ namespace OpenRA.Mods.RA
|
||||
for (var n = 0; n < threshold; n++ )
|
||||
{
|
||||
var p = self.World.ChooseRandomCell(self.World.SharedRandom);
|
||||
if (self.World.IsPathableCell(p, inWater ? UnitMovementType.Float : UnitMovementType.Wheel))
|
||||
{
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
var crate = new Actor(w, "crate", new int2(0, 0), w.WorldActor.Owner);
|
||||
crates.Add(crate);
|
||||
|
||||
// Don't drop on any actors
|
||||
if (self.World.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(p) != null) continue;
|
||||
if (self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(p).Any()) continue;
|
||||
|
||||
var startPos = w.ChooseRandomEdgeCell();
|
||||
var plane = w.CreateActor("BADR", startPos, w.WorldActor.Owner);
|
||||
plane.traits.Get<Unit>().Facing = Util.GetFacing(p - startPos, 0);
|
||||
plane.CancelActivity();
|
||||
plane.QueueActivity(new FlyCircle(p));
|
||||
plane.traits.Get<ParaDrop>().SetLZ(p, null, inWater);
|
||||
plane.traits.Get<Cargo>().Load(plane, crate);
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Don't drop on unpathable cells
|
||||
if (!(self.World.Map.IsInMap(p.X, p.Y) &&
|
||||
Rules.TerrainTypes[self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[p.X, p.Y])]
|
||||
.GetCost(inWater ? UnitMovementType.Float : UnitMovementType.Wheel) < float.PositiveInfinity)) continue;
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
var crate = new Actor(w, "crate", new int2(0, 0), w.WorldActor.Owner);
|
||||
crates.Add(crate);
|
||||
|
||||
var startPos = w.ChooseRandomEdgeCell();
|
||||
var plane = w.CreateActor("BADR", startPos, w.WorldActor.Owner);
|
||||
plane.traits.Get<Unit>().Facing = Util.GetFacing(p - startPos, 0);
|
||||
plane.CancelActivity();
|
||||
plane.QueueActivity(new FlyCircle(p));
|
||||
plane.traits.Get<ParaDrop>().SetLZ(p, null);
|
||||
plane.traits.Get<Cargo>().Load(plane, crate);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,23 +68,18 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
var mobile = self.traits.Get<Mobile>();
|
||||
|
||||
var search = new PathSearch(self.World)
|
||||
{
|
||||
heuristic = PathSearch.DefaultEstimator(self.Location),
|
||||
umt = mobile.GetMovementType(),
|
||||
checkForBlocked = false,
|
||||
};
|
||||
var refineries = self.World.Queries.OwnedBy[self.Owner]
|
||||
var refs = self.World.Queries.OwnedBy[self.Owner]
|
||||
.Where(x => x != ignore && x.traits.Contains<IAcceptOre>())
|
||||
.ToList();
|
||||
|
||||
foreach (var r in refineries)
|
||||
search.AddInitialCell(self.World, r.Location + r.traits.Get<IAcceptOre>().DeliverOffset);
|
||||
|
||||
var path = self.World.PathFinder.FindPath(search);
|
||||
|
||||
var path = self.World.PathFinder.FindPath(PathSearch.FromPoints(self,
|
||||
refs.Select(r => r.Location + r.traits.Get<IAcceptOre>().DeliverOffset),
|
||||
self.Location,
|
||||
mobile.GetMovementType(),
|
||||
false));
|
||||
path.Reverse();
|
||||
if (path.Count != 0)
|
||||
return refineries.FirstOrDefault(x => x.Location + x.traits.Get<IAcceptOre>().DeliverOffset == path[0]);
|
||||
return refs.FirstOrDefault(x => x.Location + x.traits.Get<IAcceptOre>().DeliverOffset == path[0]);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -37,13 +37,11 @@ namespace OpenRA.Mods.RA
|
||||
readonly List<int2> droppedAt = new List<int2>();
|
||||
int2 lz;
|
||||
Actor flare;
|
||||
bool waterDrop;
|
||||
|
||||
public void SetLZ( int2 lz, Actor flare, bool waterDrop )
|
||||
public void SetLZ( int2 lz, Actor flare )
|
||||
{
|
||||
this.lz = lz;
|
||||
this.flare = flare;
|
||||
this.waterDrop = waterDrop;
|
||||
droppedAt.Clear();
|
||||
}
|
||||
|
||||
@@ -79,7 +77,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
bool IsSuitableCell(Actor self, int2 p)
|
||||
{
|
||||
return self.World.IsPathableCell(p, waterDrop ? UnitMovementType.Float : UnitMovementType.Wheel);
|
||||
return self.traits.Get<Mobile>().CanEnterCell(p);
|
||||
}
|
||||
|
||||
void FinishedDropping(Actor self)
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
a.CancelActivity();
|
||||
a.QueueActivity(new FlyCircle(p));
|
||||
a.traits.Get<ParaDrop>().SetLZ(p, flare, false);
|
||||
a.traits.Get<ParaDrop>().SetLZ(p, flare);
|
||||
|
||||
var cargo = a.traits.Get<Cargo>();
|
||||
foreach (var i in items)
|
||||
|
||||
Reference in New Issue
Block a user