using System;
namespace HPJ.Simulation.Map
{
public class AgentMap
{
///
/// Base map related to this map
///
public Map Base { get; protected set; }
///
/// Tile that descripe the agent ownership
///
public ushort[,] Tiles { get; protected set; }
///
/// Initializes the agent map based on the base map
///
///
public AgentMap(Map baseMap)
{
Base = baseMap;
Tiles = new ushort[baseMap.Settings.MapWidth, baseMap.Settings.MapHeight];
}
///
/// Disowns this tile so other agents can claim it or to know its availible
///
///
public void DisownTile(IntVector2 ownedTile, ushort ID)
{
if (ownedTile.x < 0 || ownedTile.y < 0 || ownedTile.x >= Base.Settings.MapWidth || ownedTile.y >= Base.Settings.MapHeight)
{
return;
}
if (Tiles[ownedTile.x, ownedTile.y] == ID)
{
Tiles[ownedTile.x, ownedTile.y] = 0;
}
}
///
/// Attempts to claim a tile for a specified ID
///
///
///
///
public bool ClaimTile(IntVector2 newTilePosition, ushort ID)
{
if (newTilePosition.x < 0 || newTilePosition.y < 0 || newTilePosition.x >= Base.Settings.MapWidth || newTilePosition.y >= Base.Settings.MapHeight)
{
return false;
}
if (Tiles[newTilePosition.x, newTilePosition.y] == 0)
{
Tiles[newTilePosition.x, newTilePosition.y] = ID;
return true;
}
return false;
}
internal bool IsBlocked(int x, int y, ushort CompareID)
{
return Tiles[x, y] != 0 && Tiles[x, y] != CompareID;
}
public bool ValidTileForAgent(ushort simNavigationAgentID, int x, int y)
{
if (Tiles[x, y] == 0 || Tiles[x, y] == simNavigationAgentID)
{
return true;
}
return false;
}
}
}