2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * getbit.c: Replaces old bitmap code
30 * Known contributors to this file:
37 #include "prototypes.h"
42 * the bit offsets for each bit pattern based on the efficiency of
52 #define bitoff(x, y) x, y
54 static int bitmap0[] = {
55 bitoff(-1, -1), bitoff(1, -1),
56 bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0),
57 bitoff(-1, 1), bitoff(1, 1),
61 static int bitmap1[] = {
63 bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1), bitoff(3, -1),
64 bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0),
65 bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1), bitoff(3, 1),
70 static int bitmap2[] = {
71 bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2),
72 bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1), bitoff(3, -1),
73 bitoff(-4, 0), bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0), bitoff(4, 0),
74 bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1), bitoff(3, 1),
75 bitoff(-2, 2), bitoff(0, 2), bitoff(2, 2),
79 static int bitmap3[] = {
80 bitoff(-1, -3), bitoff(1, -3),
81 bitoff(-4, -2), bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2), bitoff(4,
83 bitoff(-5, -1), bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1),
84 bitoff(3, -1), bitoff(5, -1),
85 bitoff(-4, 0), bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0), bitoff(4, 0),
86 bitoff(-5, 1), bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1),
87 bitoff(3, 1), bitoff(5, 1),
88 bitoff(-4, 2), bitoff(-2, 2), bitoff(0, 2), bitoff(2, 2), bitoff(4, 2),
89 bitoff(-1, 3), bitoff(1, 3),
93 static int bitmap4[] = {
94 bitoff(-3, -3), bitoff(-1, -3), bitoff(1, -3), bitoff(3, -3),
95 bitoff(-4, -2), bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2), bitoff(4,
97 bitoff(-5, -1), bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1),
98 bitoff(3, -1), bitoff(5, -1),
99 bitoff(-6, 0), bitoff(-4, 0), bitoff(-2, 0), bitoff(0, 0), bitoff(2,
101 bitoff(4, 0), bitoff(6, 0),
102 bitoff(-5, 1), bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1),
103 bitoff(3, 1), bitoff(5, 1),
104 bitoff(-4, 2), bitoff(-2, 2), bitoff(0, 2), bitoff(2, 2), bitoff(4, 2),
105 bitoff(-3, 3), bitoff(-1, 3), bitoff(1, 3), bitoff(3, 3),
109 static int *bitmaps[5] = {
118 emp_getbit(int x, int y, unsigned char *bitmap)
120 int id = sctoff(x, y);
123 return bitmap[id >> 3] & bit(id & 07);
127 emp_setbit(int x, int y, unsigned char *bitmap)
129 int id = sctoff(x, y);
132 bitmap[id >> 3] |= bit(id & 07);
136 emp_setbitmap(int x, int y, unsigned char *bitmap, int *bitmaps)
142 for (mp = bitmaps; *mp != 9999;) {
146 bitmap[id >> 3] |= bit(id & 07);
151 bitinit2(struct nstr_sect *np, unsigned char *bitmap, int country)
156 while (nxtsct(np, §)) {
157 if (sect.sct_own != country)
159 eff = sect.sct_effic / 20;
162 emp_setbitmap(np->x, np->y, bitmap, bitmaps[eff]);