/* src/server/map.c */
#include "map.h"
-#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
+#include <stdint.h> /* uint8_t, uint16_t, uint32_t, UINT16_MAX */
+#include "../common/rexit.h" /* exit_err() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* struct yx_uint8 */
#include "rrand.h" /* rrand() */
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;
+ uint16_t y, x;
for (y = 0; y < world.map.size.y; y++)
{
for (x = 0;
uint8_t add_half_width = !(world.map.size.y % 2) * (world.map.size.x / 2);
world.map.cells[(size / 2) + add_half_width] = '.';
uint16_t curpos;
- while (1)
+ char * err = "Map generation reached iteration limit. Change map size?";
+ uint32_t i;
+ for (i = 0; ; i++, exit_err(256 * UINT16_MAX == i, err))
{
y = rrand() % world.map.size.y;
x = rrand() % world.map.size.x;
extern uint8_t is_passable(struct yx_uint8 pos)
{
uint8_t passable = 0;
- if ( 0 <= pos.x && pos.x < world.map.size.x
- && 0 <= pos.y && pos.y < world.map.size.y)
+ if (pos.x < world.map.size.x && pos.y < world.map.size.y)
{
passable = ('.' == world.map.cells[(pos.y * world.map.size.x) + pos.x]);
}