fix up some of the capturing duplication
This commit is contained in:
@@ -189,5 +189,17 @@ namespace OpenRA
|
||||
Destroyed = true;
|
||||
} );
|
||||
}
|
||||
|
||||
// todo: move elsewhere.
|
||||
public void ChangeOwner(Player newOwner)
|
||||
{
|
||||
World.AddFrameEndTask(w =>
|
||||
{
|
||||
// momentarily remove from world so the ownership queries don't get confused
|
||||
w.Remove(this);
|
||||
Owner = newOwner;
|
||||
w.Add(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,16 +85,8 @@ namespace OpenRA.Mods.Cnc
|
||||
|
||||
public void OnCapture (Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
if (dockedHarv == null)
|
||||
return;
|
||||
|
||||
dockedHarv.World.AddFrameEndTask(w =>
|
||||
{
|
||||
// momentarily remove from world so the ownership queries don't get confused
|
||||
w.Remove(dockedHarv);
|
||||
dockedHarv.Owner = captor.Owner;
|
||||
w.Add(dockedHarv);
|
||||
});
|
||||
if (dockedHarv != null)
|
||||
dockedHarv.ChangeOwner(newOwner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace OpenRA.Mods.RA.Activities
|
||||
if( !target.Trait<IOccupySpace>().OccupiedCells().Any( x => x == self.Location ) )
|
||||
return NextActivity;
|
||||
|
||||
// todo: clean this up
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
// momentarily remove from world so the ownership queries don't get confused
|
||||
|
||||
@@ -53,16 +53,8 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public void OnCapture (Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
if (dockedHarv == null)
|
||||
return;
|
||||
|
||||
dockedHarv.World.AddFrameEndTask(w =>
|
||||
{
|
||||
// momentarily remove from world so the ownership queries don't get confused
|
||||
w.Remove(dockedHarv);
|
||||
dockedHarv.Owner = captor.Owner;
|
||||
w.Add(dockedHarv);
|
||||
});
|
||||
if (dockedHarv != null)
|
||||
dockedHarv.ChangeOwner(newOwner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -137,11 +134,18 @@ namespace OpenRA.Mods.RA
|
||||
});
|
||||
}
|
||||
|
||||
static bool AreMutualAllies(Player a, Player b)
|
||||
{
|
||||
return a.Stances[b] == Stance.Ally &&
|
||||
b.Stances[a] == Stance.Ally;
|
||||
}
|
||||
|
||||
public static bool IsClear(Actor self, Player currentOwner, int range, Player originalOwner)
|
||||
{
|
||||
var unitsInRange = self.World.FindUnitsInCircle(self.CenterLocation, Game.CellSize * range);
|
||||
|
||||
return unitsInRange.Where(a => !a.Destroyed && a.IsInWorld && a != self && !a.Owner.NonCombatant && a.Owner != originalOwner).Where(a => a.Owner != currentOwner).All(a => (a.Owner.Stances[currentOwner] == Stance.Ally) && (currentOwner.Stances[a.Owner] == Stance.Ally));
|
||||
return unitsInRange.Where(a => !a.Destroyed && a.IsInWorld && a != self && !a.Owner.NonCombatant && a.Owner != originalOwner)
|
||||
.Where(a => a.Owner != currentOwner).All(a => AreMutualAllies(a.Owner, currentOwner));
|
||||
}
|
||||
|
||||
// TODO exclude other NeutralActor that arent permanent
|
||||
|
||||
Reference in New Issue
Block a user