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