fix up some of the capturing duplication

This commit is contained in:
Chris Forbes
2010-12-23 14:25:39 +13:00
parent e8a85db309
commit 3149f3efa2
5 changed files with 27 additions and 26 deletions

View File

@@ -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);
});
}
}
}

View File

@@ -84,17 +84,9 @@ 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);
}
}
}

View File

@@ -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

View File

@@ -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);
}
}
}

View File

@@ -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