home
·
contact
·
privacy
projects
/
plomrogue
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Server: Limit iterations for map generation and object start placement.
[plomrogue]
/
src
/
server
/
map.c
diff --git
a/src/server/map.c
b/src/server/map.c
index 29beb1a03d5d0a6ebf1113d6ead1cd34763f2573..95d7e0ff4e96f875e17845e8a608c60a05307fbd 100644
(file)
--- a/
src/server/map.c
+++ b/
src/server/map.c
@@
-1,7
+1,8
@@
/* src/server/map.c */
#include "map.h"
/* src/server/map.c */
#include "map.h"
-#include <stdint.h> /* uint8_t, uint16_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() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* struct yx_uint8 */
#include "rrand.h" /* rrand() */
@@
-12,22
+13,25
@@
extern void init_map()
{
char * f_name = "init_map()";
extern void init_map()
{
char * f_name = "init_map()";
- uint
16
_t size = world.map.size.x * world.map.size.y;
+ uint
32
_t size = world.map.size.x * world.map.size.y;
world.map.cells = try_malloc(size, f_name);
world.map.cells = try_malloc(size, f_name);
- uint
8
_t y, x;
+ uint
16
_t y, x;
for (y = 0; y < world.map.size.y; y++)
{
for (x = 0;
x < world.map.size.x;
world.map.cells[(y * world.map.size.x) + x] = '~', x++);
}
for (y = 0; y < world.map.size.y; y++)
{
for (x = 0;
x < world.map.size.x;
world.map.cells[(y * world.map.size.x) + x] = '~', x++);
}
- world.map.cells[size / 2 + (world.map.size.x / 2)] = '.';
+ 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;
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;
{
y = rrand() % world.map.size.y;
x = rrand() % world.map.size.x;
- curpos =
y * world.map.size.x
+ 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])
if ('~' == world.map.cells[curpos]
&& ( ( curpos >= world.map.size.x
&& '.' == world.map.cells[curpos - world.map.size.x])
@@
-39,8
+43,8
@@
extern void init_map()
&& (curpos+1) % world.map.size.x != 0
&& '.' == world.map.cells[curpos+1])))
{
&& (curpos+1) % world.map.size.x != 0
&& '.' == world.map.cells[curpos+1])))
{
- if (
y == 0 || y == world.map.size.y - 1 || x == 0
- || x == world.map.size.x - 1)
+ if (
y == 0 || y == world.map.size.y - 1
+ || x ==
0 || x ==
world.map.size.x - 1)
{
break;
}
{
break;
}
@@
-54,10
+58,9
@@
extern void init_map()
extern uint8_t is_passable(struct yx_uint8 pos)
{
uint8_t passable = 0;
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])
);
+ passable = (
'.' == world.map.cells[(pos.y * world.map.size.x) + pos.x]
);
}
return passable;
}
}
return passable;
}