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