fix dumb crash in cnc

This commit is contained in:
Chris Forbes
2010-03-06 16:34:56 +13:00
parent 3a6746f405
commit 5ae3f2c814
2 changed files with 6 additions and 2 deletions

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Traits
public void Tick(Actor self) public void Tick(Actor self)
{ {
if (isOpen && !self.World.WorldActor.traits.Get<UnitInfluence>() if (isOpen && !self.World.WorldActor.traits.Get<UnitInfluence>()
.GetUnitsAt(((1/24f) * self.CenterLocation).ToInt2()).Any()) .GetUnitsAt(((1f/Game.CellSize) * self.CenterLocation).ToInt2()).Any())
{ {
isOpen = false; isOpen = false;
roof.PlayBackwardsThen(GetPrefix(self) + "build-top", () => roof.Play(GetPrefix(self) + "idle-top")); roof.PlayBackwardsThen(GetPrefix(self) + "build-top", () => roof.Play(GetPrefix(self) + "idle-top"));

View File

@@ -22,6 +22,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using OpenRA.FileFormats;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
@@ -33,10 +34,12 @@ namespace OpenRA.Traits
public class UnitInfluence : ITick public class UnitInfluence : ITick
{ {
List<Actor>[,] influence; List<Actor>[,] influence;
Map map;
public UnitInfluence( Actor self ) public UnitInfluence( Actor self )
{ {
int size = self.World.Map.MapSize; map = self.World.Map;
var size = self.World.Map.MapSize;
influence = new List<Actor>[size, size]; influence = new List<Actor>[size, size];
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++) for (int j = 0; j < size; j++)
@@ -90,6 +93,7 @@ namespace OpenRA.Traits
public IEnumerable<Actor> GetUnitsAt( int2 a ) public IEnumerable<Actor> GetUnitsAt( int2 a )
{ {
if (!map.IsInMap(a)) return null;
return influence[ a.X, a.Y ]; return influence[ a.X, a.Y ];
} }