2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * getbit.c: Replaces old bitmap code
29 * Known contributors to this file:
36 #include "prototypes.h"
41 * the bit offsets for each bit pattern based on the efficiency of
51 #define bitoff(x, y) x, y
53 static int bitmap0[] = {
54 bitoff(-1, -1), bitoff(1, -1),
55 bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0),
56 bitoff(-1, 1), bitoff(1, 1),
60 static int bitmap1[] = {
62 bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1), bitoff(3, -1),
63 bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0),
64 bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1), bitoff(3, 1),
69 static int bitmap2[] = {
70 bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2),
71 bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1), bitoff(3, -1),
72 bitoff(-4, 0), bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0), bitoff(4, 0),
73 bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1), bitoff(3, 1),
74 bitoff(-2, 2), bitoff(0, 2), bitoff(2, 2),
78 static int bitmap3[] = {
79 bitoff(-1, -3), bitoff(1, -3),
80 bitoff(-4, -2), bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2), bitoff(4,
82 bitoff(-5, -1), bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1),
83 bitoff(3, -1), bitoff(5, -1),
84 bitoff(-4, 0), bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0), bitoff(4, 0),
85 bitoff(-5, 1), bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1),
86 bitoff(3, 1), bitoff(5, 1),
87 bitoff(-4, 2), bitoff(-2, 2), bitoff(0, 2), bitoff(2, 2), bitoff(4, 2),
88 bitoff(-1, 3), bitoff(1, 3),
92 static int bitmap4[] = {
93 bitoff(-3, -3), bitoff(-1, -3), bitoff(1, -3), bitoff(3, -3),
94 bitoff(-4, -2), bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2), bitoff(4,
96 bitoff(-5, -1), bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1),
97 bitoff(3, -1), bitoff(5, -1),
98 bitoff(-6, 0), bitoff(-4, 0), bitoff(-2, 0), bitoff(0, 0), bitoff(2,
100 bitoff(4, 0), bitoff(6, 0),
101 bitoff(-5, 1), bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1),
102 bitoff(3, 1), bitoff(5, 1),
103 bitoff(-4, 2), bitoff(-2, 2), bitoff(0, 2), bitoff(2, 2), bitoff(4, 2),
104 bitoff(-3, 3), bitoff(-1, 3), bitoff(1, 3), bitoff(3, 3),
108 static int *bitmaps[5] = {
117 emp_getbit(int x, int y, unsigned char *bitmap)
119 int id = sctoff(x, y);
122 return bitmap[id >> 3] & bit(id & 07);
126 emp_setbit(int x, int y, unsigned char *bitmap)
128 int id = sctoff(x, y);
131 bitmap[id >> 3] |= bit(id & 07);
135 emp_setbitmap(int x, int y, unsigned char *bitmap, int *bitmaps)
141 for (mp = bitmaps; *mp != 9999;) {
145 bitmap[id >> 3] |= bit(id & 07);
150 bitinit2(struct nstr_sect *np, unsigned char *bitmap, int country)
155 while (nxtsct(np, §)) {
156 if (sect.sct_own != country)
158 eff = sect.sct_effic / 20;
161 emp_setbitmap(np->x, np->y, bitmap, bitmaps[eff]);