// public ResourceTile GetNearestResourceTile (IVec2 Pos, ResourceType type) { ResourceTile nearestTile = null; int nearestDistance = int.MaxValue; foreach (MapObject mo in entities) { if (mo is ResourceTile) { ResourceTile rt = mo as ResourceTile; if (rt.m_resource == type) { int distance = Pos.manhatttanDistance(rt.m_MapPos); if (distance < nearestDistance){ nearestDistance = distance; nearestTile = rt; } } } } return nearestTile; }
public Building GetNearestBuilding (IVec2 Pos, BuildingType type) { Building nearestBuilding = null; int nearestDistance = int.MaxValue; foreach (MapObject mo in entities) { if (mo is Building) { Building b = mo as Building; if (b.m_buildingtype == type) { int distance = Pos.manhatttanDistance(b.m_MapPos); if (distance < nearestDistance){ nearestDistance = distance; nearestBuilding = b; } } } } return nearestBuilding; }
public Building GetNearestBuilding (IVec2 Pos, BuildingType type) { Building nearestBuilding = null; int nearestDistance = int.MaxValue; foreach (Building b in Buildings) { if (b.m_buildingtype == type) { int distance = Pos.manhatttanDistance(b.m_MapPos); if (distance < nearestDistance){ nearestDistance = distance; nearestBuilding = b; } } } return nearestBuilding; }