- char * f_name = "init_map()";
- uint32_t size = world.map.size.x * world.map.size.y;
- world.map.cells = try_malloc(size, f_name);
- uint8_t y, x;
- for (y = 0; y < world.map.size.y; y++)
+ static uint32_t i = 0;
+ char * err = "Map generation reached iteration limit. Change map size?";
+ if (init)
+ {
+ i = 0;
+ return 0;
+ }
+ i++;
+ exit_err(256 * UINT16_MAX == i, err);
+ return 1;
+}
+
+
+
+static uint8_t is_neighbor(struct yx_uint8 pos, char type)
+{
+ uint8_t ind = pos.y % 2;
+ uint8_t diag_west = pos.x + ind > 0;
+ uint8_t diag_east = pos.x + ind <= world.map.length - 1;
+ uint16_t pos_i = (pos.y * world.map.length) + pos.x;
+ if ( ( pos.y > 0 && diag_east
+ && type == world.map.cells[pos_i - world.map.length + ind])
+ || ( pos.x < world.map.length - 1
+ && type == world.map.cells[pos_i + 1])
+ || ( pos.y < world.map.length - 1 && diag_east
+ && type == world.map.cells[pos_i + world.map.length + ind])
+ || ( pos.y > 0 && diag_west
+ && type == world.map.cells[pos_i - world.map.length - !ind])
+ || ( pos.x > 0
+ && type == world.map.cells[pos_i - 1])
+ || ( pos.y < world.map.length - 1 && diag_west
+ && type == world.map.cells[pos_i + world.map.length - !ind]))
+ {
+ return 1;
+ }
+ return 0;
+}
+
+
+
+static void make_sea()
+{
+ uint16_t y, x;
+ for (y = 0; y < world.map.length; y++)