[Freeciv-Dev] check_map_pos() function?
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
I know it's not quite what we talked about, but how about something like
this to implement check_map_pos?
The advantage of making it an inline function rather than a macro is
that it can be easily used in places a generic macro could not (like
map_inx). I don't think we want to have a different check in map_inx if
at all possible.
jason Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.96
diff -u -r1.96 map.h
--- common/map.h 2001/10/09 16:26:46 1.96
+++ common/map.h 2001/10/14 04:58:28
@@ -13,6 +13,9 @@
#ifndef FC__MAP_H
#define FC__MAP_H
+#include <assert.h>
+
+#include "log.h"
#include "player.h"
#include "terrain.h"
#include "unit.h"
@@ -234,6 +237,23 @@
int is_normal_map_pos(int x, int y);
int normalize_map_pos(int *x, int *y);
void nearest_real_pos(int *x, int *y);
+
+static inline void check_map_pos(int *x, int *y)
+{
+#ifdef DEBUG
+ assert(is_normal_map_pos(*x, *y));
+#else
+ /* When we're pretty sure things work it'll be worthwhile to remove this
+ code. Until then, something like this is safest. */
+ if (!is_normal_map_pos(*x, *y)) {
+ freelog(LOG_ERROR, "Bad coordinates (%d, %d) passed to check_map_pos.",
*x, *y);
+ if (!normalize_map_pos(x, y)) {
+ nearest_real_pos(x, y);
+ freelog(LOG_FATAL, "Unreal coordinates 'fixed' to (%d, %d).", *x, *y);
+ }
+ }
+#endif
+}
void rand_neighbour(int x0, int y0, int *x, int *y);
- [Freeciv-Dev] check_map_pos() function?,
Jason Dorje Short <=
|
|