move RallyPoint lookup into a Lazy

This commit is contained in:
Matthias Mailänder
2014-05-28 10:51:53 +02:00
parent 4c50757b18
commit c1f8a8e315

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.Mods.RA.Move;
@@ -41,13 +42,13 @@ namespace OpenRA.Mods.RA
public class Production
{
RallyPoint rp;
Lazy<RallyPoint> rp;
public ProductionInfo Info;
public Production(ProductionInfo info, Actor self)
{
Info = info;
rp = self.TraitOrDefault<RallyPoint>();
rp = Exts.Lazy(() => self.TraitOrDefault<RallyPoint>());
}
public void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo)
@@ -82,15 +83,15 @@ namespace OpenRA.Mods.RA
CPos MoveToRallyPoint(Actor self, Actor newUnit, CPos exitLocation)
{
if (rp == null)
if (self.IsDead() || rp.Value == null)
return exitLocation;
var move = newUnit.TraitOrDefault<IMove>();
if (move != null)
{
newUnit.QueueActivity(new AttackMove.AttackMoveActivity(
newUnit, move.MoveTo(rp.rallyPoint, rp.nearEnough)));
return rp.rallyPoint;
newUnit, move.MoveTo(rp.Value.rallyPoint, rp.Value.nearEnough)));
return rp.Value.rallyPoint;
}
return exitLocation;