]> git.pond.sub.org Git - empserver/blobdiff - include/xy.h
Fix XNORM() and YNORM()
[empserver] / include / xy.h
index 81ec32dd255e60ef9f81e08af497968809adffb5..574c1b679fb6a06bbb01bcd9387b430f264ab244 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *     Steve McClure, 1998
  */
 
-#ifndef _XY_H_
-#define _XY_H_
+#ifndef XY_H
+#define XY_H
 
-#include "sect.h"
-#include "nat.h"
+#include "types.h"
 
-/* Used to calculate an offset into an array.  Used for
-   dynamically sizing the world. */
-#define XYOFFSET(x, y) ((y * WORLD_X) + x)
+/* Return the number of sectors in the world */
+#define WORLD_SZ() (WORLD_X * WORLD_Y / 2)
 
-#define XNORM(x) (((x)<0) ? ((WORLD_X-(-(x)%WORLD_X))%WORLD_X) : ((x)%WORLD_X))
-#define YNORM(y) (((y)<0) ? ((WORLD_Y-(-(y)%WORLD_Y))%WORLD_Y) : ((y)%WORLD_Y))
+/* Fast version of sctoff() for normalized arguments */
+#define XYOFFSET(x, y) (((y) * WORLD_X + (x)) / 2)
+
+#define XNORM(x) \
+    (((x) < 0) ? (WORLD_X - 1 - ((-(x) - 1) % WORLD_X)) : ((x) % WORLD_X))
+#define YNORM(y) \
+    (((y) < 0) ? (WORLD_Y - 1 - ((-(y) - 1) % WORLD_Y)) : ((y) % WORLD_Y))
 
 struct range {
-       coord lx;       /* low-range x,y */
-       coord ly;
-       coord hx;       /* high-range x,y */
-       coord hy;
-       int width;      /* range width, height */
-       int height;
+    coord lx;                  /* low-range x,y */
+    coord ly;
+    coord hx;                  /* high-range x,y */
+    coord hy;
+    int width;                 /* range width, height */
+    int height;
 };
 
-extern s_char *xyfmt();
-extern s_char *xyas(coord x, coord y, natid country);
-extern s_char *ownxy(struct sctstr *sp);
-extern coord   xrel(struct natstr *np, coord absx);
-extern coord   yrel(struct natstr *np, coord absy);
-extern void xyrelrange(struct natstr *np, struct range *src,struct range *dst);
-extern void xyabsrange(struct natstr *np, struct range *src,struct range *dst);
-extern void inputxy(coord *xp, coord *yp, natid cn);
+extern char *xyas(coord x, coord y, natid country);
+extern char *ownxy(struct sctstr *sp);
+extern coord xrel(struct natstr *np, coord absx);
+extern coord yrel(struct natstr *np, coord absy);
+extern void xyrelrange(struct natstr *np, struct range *src,
+                      struct range *dst);
+extern void xyabsrange(struct natstr *np, struct range *src,
+                      struct range *dst);
+extern coord strtox(char *str, char **end);
+extern coord strtoy(char *str, char **end);
 extern coord xabs(struct natstr *np, coord relx);
 extern coord yabs(struct natstr *np, coord rely);
-extern coord xnorm(register coord x);
-extern coord ynorm(register coord y);
+extern coord xnorm(coord x);
+extern coord ynorm(coord y);
 extern int xyinrange(coord x, coord y, struct range *rp);
 
-#endif /* _XY_H_ */
-
+#endif