public Tile GetTargetTile(ActuatorItemData callingActuator)
{
var targetPos = ((RemoteTarget)callingActuator.ActionLocation).Position.Position.ToAbsolutePosition(CurrentMap);
Tile targetTile = null;
if (TilesPositions.TryGetValue(targetPos, out targetTile))
return targetTile;
else
{
//try find tile in raw data, and than actuator, add it to Tiles Positions
var virtualTileData = CurrentMap[targetPos.X, targetPos.Y];
if (virtualTileData.Actuators.Any()) //virtual tile will be proccessed at the and so any checking shouldnt be necessary
{
var newTile = new LogicTile(targetPos.ToGridVector3(CurrentLevel));
newTile.Gates = virtualTileData.Actuators.Where(x => x.ActuatorType == 5).Select(y => InitLogicGates(y, newTile)).ToArray(); //recurse
newTile.Counters = virtualTileData.Actuators.Where(x => x.ActuatorType == 6).Select(y => InitCounters(y, newTile)).ToArray(); //recurse
TilesPositions.Add(targetPos, targetTile = newTile); //subitems will be processed
}
else if (virtualTileData.TextTags.Any())
{
var textTag = virtualTileData.TextTags.Single();
textTag.HasTargetingActuator = true;
targetTile = TilesPositions[textTag.GetParentPosition(targetPos)];
if (textTag.Processed)
targetTile.SubItems.Single(x => x is TextTag).AcceptMessages = true;
}
return targetTile; //TODO (if null) think out what to do
//Acutor at the begining references wall near by with tag only ... what to do ?
}
}