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: Move common config file reading stuff into read_config_file().
[plomrogue]
/
src
/
server
/
map.c
diff --git
a/src/server/map.c
b/src/server/map.c
index f46b03e99fc30c1227c1e91636e418039d7fe895..0edd955c4265419f7f09d19d14e10c1066384a62 100644
(file)
--- a/
src/server/map.c
+++ b/
src/server/map.c
@@
-2,9
+2,8
@@
#include "map.h"
#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
#include "map.h"
#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
-#include "../common/map.h" /* struct Map */
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/try_malloc.h" /* try_malloc() */
-#include "../common/yx_uint
16.h" /* struct yx_uint16
*/
+#include "../common/yx_uint
8.h" /* struct yx_uint8
*/
#include "rrand.h" /* rrand() */
#include "world.h" /* global world */
#include "rrand.h" /* rrand() */
#include "world.h" /* global world */
@@
-13,8
+12,6
@@
extern void init_map()
{
char * f_name = "init_map()";
extern void init_map()
{
char * f_name = "init_map()";
- world.map.size.x = 64;
- world.map.size.y = 64;
uint32_t size = world.map.size.x * world.map.size.y;
world.map.cells = try_malloc(size, f_name);
uint16_t y, x;
uint32_t size = world.map.size.x * world.map.size.y;
world.map.cells = try_malloc(size, f_name);
uint16_t y, x;
@@
-24,13
+21,14
@@
extern void init_map()
x < world.map.size.x;
world.map.cells[(y * world.map.size.x) + x] = '~', x++);
}
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)] = '.';
- uint32_t curpos;
+ 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)
{
y = rrand() % world.map.size.y;
x = rrand() % world.map.size.x;
while (1)
{
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])
@@
-42,8
+40,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,13
+52,12
@@
extern void init_map()
-extern uint8_t is_passable(struct yx_uint
16
pos)
+extern uint8_t is_passable(struct yx_uint
8
pos)
{
uint8_t passable = 0;
{
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;
}