From: Christian Heller <c.heller@plomlompom.de>
Date: Wed, 5 Feb 2014 23:02:16 +0000 (+0100)
Subject: Eliminated some potential problems for alternative game map sizes.
X-Git-Tag: tce~840
X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/static/day?a=commitdiff_plain;h=cdb90723dd636591bcfa98ebb165cf74a0cdeec7;p=plomrogue
Eliminated some potential problems for alternative game map sizes.
---
diff --git a/src/client/windows.c b/src/client/windows.c
index b0734dc..674e6ad 100644
--- a/src/client/windows.c
+++ b/src/client/windows.c
@@ -551,8 +551,8 @@ static void suspend_win(struct Win * w)
-extern uint16_t center_offset(uint16_t position, uint16_t mapsize,
- uint16_t frame_size)
+extern uint16_t center_offset(uint16_t position, uint32_t mapsize,
+ uint32_t frame_size)
{
uint16_t offset = 0;
if (mapsize > frame_size)
diff --git a/src/client/windows.h b/src/client/windows.h
index 92a35a1..872fe13 100644
--- a/src/client/windows.h
+++ b/src/client/windows.h
@@ -25,7 +25,7 @@
#define WINDOWS_H
#include <ncurses.h> /* WINDOW, chtype */
-#include <stdint.h> /* uint8_t, int16_t, uint16_t */
+#include <stdint.h> /* uint8_t, int16_t, uint16_t, uint32_t */
#include "../common/yx_uint16.h" /* yx_uint16 struct */
#include "keybindings.h" /* struct KeyBindingDB */
@@ -66,7 +66,7 @@ struct Win
/* Return yx offset to focus map of "mapsize" on "position" in "frame_size". */
extern uint16_t center_offset(uint16_t position,
- uint16_t mapsize, uint16_t frame_size);
+ uint32_t mapsize, uint32_t frame_size);
/* Get Win of "id". */
extern struct Win * get_win_by_id(char id);
diff --git a/src/server/ai.c b/src/server/ai.c
index 50c5031..c25c277 100644
--- a/src/server/ai.c
+++ b/src/server/ai.c
@@ -44,7 +44,7 @@ static char get_dir_to_nearest_enemy(struct MapObj * mo_origin);
static void get_neighbor_scores(uint32_t * score_map, uint16_t pos_i,
uint32_t max_score, uint32_t * neighbors)
{
- uint16_t map_size = world.map.size.y * world.map.size.x;
+ uint32_t map_size = world.map.size.y * world.map.size.x;
uint8_t i_dir;
for (i_dir = 0; i_dir < N_DIRS; neighbors[i_dir] = max_score, i_dir++);
uint8_t open_north = pos_i >= world.map.size.x;
@@ -90,7 +90,7 @@ static void get_neighbor_scores(uint32_t * score_map, uint16_t pos_i,
static void dijkstra_map(uint32_t * score_map, uint32_t max_score)
{
uint32_t i_scans, neighbors[N_DIRS], min_neighbor_o, min_neighbor_d;
- uint16_t map_size = world.map.size.y * world.map.size.x;
+ uint32_t map_size = world.map.size.y * world.map.size.x;
uint16_t pos;
uint8_t scores_still_changing = 1;
uint8_t i_dirs;
@@ -138,7 +138,7 @@ static char get_dir_to_nearest_enemy(struct MapObj * mo_origin)
* not "mo_origin", with movement only possible in the directions of "dir".
* (Actors' own cells start with a distance of 0 towards themselves.)
*/
- uint16_t map_size = world.map.size.y * world.map.size.x;
+ uint32_t map_size = world.map.size.y * world.map.size.x;
uint32_t max_score = UINT32_MAX - (world.map.dist_diagonal + 1);
uint32_t score_map[map_size];
uint32_t i;
diff --git a/src/server/io.c b/src/server/io.c
index a516d81..2507d3b 100644
--- a/src/server/io.c
+++ b/src/server/io.c
@@ -5,7 +5,7 @@
#include <fcntl.h> /* open(), O_RDONLY, O_NONBLOCK */
#include <limits.h> /* PIPE_BUF */
#include <stddef.h> /* size_t, NULL */
-#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
+#include <stdint.h> /* uint8_t, uint32_t */
#include <stdio.h> /* define FILE, sprintf() */
#include <stdlib.h> /* free() */
#include <string.h> /* strlen(), memset(), memcpy() */
@@ -183,7 +183,7 @@ static void write_inventory(struct MapObj * player, FILE * file)
static void write_map(FILE * file)
{
char * f_name = "write_map()";
- uint16_t map_size = world.map.size.y * world.map.size.x;
+ uint32_t map_size = world.map.size.y * world.map.size.x;
char visible_map[map_size];
memcpy(visible_map, world.map.cells, map_size);
struct MapObj * o;
diff --git a/src/server/map.c b/src/server/map.c
index 29beb1a..9b0f294 100644
--- a/src/server/map.c
+++ b/src/server/map.c
@@ -1,7 +1,7 @@
/* src/server/map.c */
#include "map.h"
-#include <stdint.h> /* uint8_t, uint16_t */
+#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* struct yx_uint8 */
#include "rrand.h" /* rrand() */
@@ -12,7 +12,7 @@
extern void init_map()
{
char * f_name = "init_map()";
- uint16_t size = world.map.size.x * world.map.size.y;
+ 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++)
@@ -21,13 +21,14 @@ extern void init_map()
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;
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])
@@ -39,8 +40,8 @@ extern void init_map()
&& (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;
}
@@ -57,7 +58,7 @@ extern uint8_t is_passable(struct yx_uint8 pos)
if ( 0 <= pos.x && pos.x < world.map.size.x
&& 0 <= pos.y && 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;
}