- y = rrand() % world.map.size.y;
- x = rrand() % world.map.size.x;
- curpos = (y * world.map.size.x) + x;
- if ('~' == world.map.cells[curpos]
- && ( ( curpos >= world.map.size.x
- && '.' == world.map.cells[curpos - world.map.size.x])
- || ( curpos < world.map.size.x * (world.map.size.y-1)
- && '.' == world.map.cells[curpos + world.map.size.x])
- || ( curpos > 0 && curpos % world.map.size.x != 0
- && '.' == world.map.cells[curpos-1])
- || ( curpos < (world.map.size.x * world.map.size.y)
- && (curpos+1) % world.map.size.x != 0
- && '.' == world.map.cells[curpos+1])))
+ pos.y = rrand() % world.map.size.y;
+ pos.x = rrand() % world.map.size.x;
+ posi = (pos.y * world.map.size.x) + pos.x;
+ uint8_t ind = pos.y % 2;
+ uint8_t diag_west = pos.x + ind > 0;
+ uint8_t diag_east = pos.x + ind <= world.map.size.x - 1;
+ if ('~' == world.map.cells[posi]
+ && ( ( pos.y > 0 && diag_east
+ && '.' == world.map.cells[posi - world.map.size.x + ind])
+ || ( pos.x < world.map.size.x - 1
+ && '.' == world.map.cells[posi + 1])
+ || ( pos.y < world.map.size.y - 1 && diag_east
+ && '.' == world.map.cells[posi + world.map.size.x + ind])
+ || ( pos.y > 0 && diag_west
+ && '.' == world.map.cells[posi - world.map.size.x - !ind])
+ || ( pos.x > 0
+ && '.' == world.map.cells[posi - 1])
+ || ( pos.y < world.map.size.y - 1 && diag_west
+ && '.' == world.map.cells[posi + world.map.size.x - !ind])))