Hello.
Currently i am trying to figure out how i am gonna calculate vision range of my units in 2d tile based map.
The issue is my map goes up to 100x100 in size, and i need access of variable in one of tiles for AI logic.
For example:
o = player;
x = sight range
n = tile out of sight range
In case x = 1
Amount of tiles in sight = 4
n n n n n
n n x n n
n x o x n
n n x n n
n n n n n
In case x = 2
Amount of tiles in sight = 12
n n x n n
n x x x n
x x o x x
n x x x n
n n x n n
In case x = 3
Amount of tiles in sight = 24
n n n x n n n
n n x x x n n
n x x x x x n
x x x o x x x
n x x x x x n
n n x x x n n
n n n x n n n
What do i do for calculation?
I need to loop each tile and check its type, i also need to figure out the tile that is closest,
How would i access the tiles from a vector that are filed like this?
I have a position in vector, and sight range.
vector<Tile> tileList; //10x10 map vector array...
int unitsVecPos = 25;//units position in vector array
int sightRange = 3;//range of tiles unit can see from its origin
//Check if there is a grass tile in the sight range of unit
Questions:
1: How to calculate amount of tiles i need to loop in case of x sight range?
2: Any idea on algorithm for accessing the tiles when looping for sight range?
Example:
for(int i = 0; i < amountOfTilesToLoop; i++)
{
if(tileList[tileIDStart + i].type == GrassType)//I the tileIDStart + i is totally wrong but :(
{
if(ThisTileIsCloserThenLastMatchingTile == true)
//Tell AI there is food here
}
}