]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/getbit.c
Update copyright notice
[empserver] / src / lib / subs / getbit.c
index ce4994a429289e811673c8d5b71d0902b986188d..dcd7191dbcdcdfb86e12e788bb41e74de18ec128 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-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *
  *  ---
  *
- *  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.
  *
  *  ---
  *
  *  getbit.c: Replaces old bitmap code
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1989
  */
 
-#include "misc.h"
-#include "player.h"
-#include "xy.h"
-#include "nsc.h"
-#include "sect.h"
-#include "nat.h"
-#include "prototypes.h"
-#include "optlist.h"
-
-#define GCFx(x) ((x + WORLD_X) % WORLD_X)
-#define GCFy(y) ((y + WORLD_Y) % WORLD_Y)
-
-int
-emp_getbit(int x, int y, u_char *bitmap)
-{
-    int id;
-
-    id = (GCFy(y)) * WORLD_X / 2 + GCFx(x) / 2;
-    return bitmap[id / 8] & bit(id & 07);
-}
-
-void
-emp_setbit(int x, int y, u_char *bitmap)
-{
-    register int id;
-
-    id = (GCFy(y)) * WORLD_X / 2 + GCFx(x) / 2;
-    bitmap[id / 8] |= bit(id & 07);
-}
+#include <config.h>
 
-void
-emp_setbitmap(register int x, register int y, register u_char *bitmap,
-             int *bitmaps)
-{
-    register int *mp;
-    register int id;
-    register int dx, dy;
-
-    for (mp = bitmaps; *mp != 9999;) {
-       dx = x + *mp++;
-       dy = y + *mp++;
-       id = (GCFy(dy)) * WORLD_X / 2 + GCFx(dx) / 2;
-       bitmap[id / 8] |= bit(id & 07);
-    }
-}
-
-
-/*
- * if we're not player->god, we have to set up the bitmaps
- * correctly for the owned sectors.  If we are player->god,
- * forego all this (expensive) nonsense!
- */
-void
-emp_bitinit(struct nstr_sect *np, u_char *bitmap)
-{
-    extern int *bitmaps[];
-    struct sctstr sect;
-    int eff;
-
-    while (nxtsct(np, &sect)) {
-       if (!player->owner)
-           continue;
-       eff = sect.sct_effic / 20;
-       if (eff > 4)
-           eff = 4;
-       emp_setbitmap(np->x, np->y, bitmap, bitmaps[eff]);
-    }
-    snxtsct_rewind(np);
-}
+#include "optlist.h"
+#include "prototypes.h"
+#include "sect.h"
 
 /*
  *
@@ -115,14 +51,14 @@ emp_bitinit(struct nstr_sect *np, u_char *bitmap)
 
 #define bitoff(x, y) x, y
 
-int bitmap0[] = {
+static int bitmap0[] = {
     bitoff(-1, -1), bitoff(1, -1),
     bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0),
     bitoff(-1, 1), bitoff(1, 1),
     bitoff(9999, 9999),
 };
 
-int bitmap1[] = {
+static int bitmap1[] = {
     bitoff(0, -2),
     bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1), bitoff(3, -1),
     bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0),
@@ -131,7 +67,7 @@ int bitmap1[] = {
     bitoff(9999, 9999),
 };
 
-int bitmap2[] = {
+static int bitmap2[] = {
     bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2),
     bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1), bitoff(3, -1),
     bitoff(-4, 0), bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0), bitoff(4, 0),
@@ -140,7 +76,7 @@ int bitmap2[] = {
     bitoff(9999, 9999),
 };
 
-int bitmap3[] = {
+static int bitmap3[] = {
     bitoff(-1, -3), bitoff(1, -3),
     bitoff(-4, -2), bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2), bitoff(4,
                                                                         -2),
@@ -154,7 +90,7 @@ int bitmap3[] = {
     bitoff(9999, 9999),
 };
 
-int bitmap4[] = {
+static int bitmap4[] = {
     bitoff(-3, -3), bitoff(-1, -3), bitoff(1, -3), bitoff(3, -3),
     bitoff(-4, -2), bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2), bitoff(4,
                                                                         -2),
@@ -170,10 +106,60 @@ int bitmap4[] = {
     bitoff(9999, 9999),
 };
 
-int *bitmaps[5] = {
+static int *bitmaps[5] = {
     bitmap0,
     bitmap1,
     bitmap2,
     bitmap3,
     bitmap4,
 };
+
+int
+emp_getbit(int x, int y, unsigned char *bitmap)
+{
+    int id = sctoff(x, y);
+    if (id < 0)
+       return 0;
+    return bitmap[id >> 3] & bit(id & 07);
+}
+
+void
+emp_setbit(int x, int y, unsigned char *bitmap)
+{
+    int id = sctoff(x, y);
+    if (id < 0)
+       return;
+    bitmap[id >> 3] |= bit(id & 07);
+}
+
+static void
+emp_setbitmap(int x, int y, unsigned char *bitmap, int *bitmaps)
+{
+    int *mp;
+    int id;
+    int dx, dy;
+
+    for (mp = bitmaps; *mp != 9999;) {
+       dx = x + *mp++;
+       dy = y + *mp++;
+       id = sctoff(dx, dy);
+       bitmap[id >> 3] |= bit(id & 07);
+    }
+}
+
+void
+bitinit2(struct nstr_sect *np, unsigned char *bitmap, int country)
+{
+    struct sctstr sect;
+    int eff;
+
+    while (nxtsct(np, &sect)) {
+       if (sect.sct_own != country)
+           continue;
+       eff = sect.sct_effic / 20;
+       if (eff > 4)
+           eff = 4;
+       emp_setbitmap(np->x, np->y, bitmap, bitmaps[eff]);
+    }
+    snxtsct_rewind(np);
+}