00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <config.h>
00035
00036 #include "optlist.h"
00037 #include "prototypes.h"
00038 #include "sect.h"
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #define bitoff(x, y) x, y
00053
00054 static int bitmap0[] = {
00055 bitoff(-1, -1), bitoff(1, -1),
00056 bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0),
00057 bitoff(-1, 1), bitoff(1, 1),
00058 bitoff(9999, 9999),
00059 };
00060
00061 static int bitmap1[] = {
00062 bitoff(0, -2),
00063 bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1), bitoff(3, -1),
00064 bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0),
00065 bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1), bitoff(3, 1),
00066 bitoff(0, 2),
00067 bitoff(9999, 9999),
00068 };
00069
00070 static int bitmap2[] = {
00071 bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2),
00072 bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1), bitoff(3, -1),
00073 bitoff(-4, 0), bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0), bitoff(4, 0),
00074 bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1), bitoff(3, 1),
00075 bitoff(-2, 2), bitoff(0, 2), bitoff(2, 2),
00076 bitoff(9999, 9999),
00077 };
00078
00079 static int bitmap3[] = {
00080 bitoff(-1, -3), bitoff(1, -3),
00081 bitoff(-4, -2), bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2), bitoff(4,
00082 -2),
00083 bitoff(-5, -1), bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1),
00084 bitoff(3, -1), bitoff(5, -1),
00085 bitoff(-4, 0), bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0), bitoff(4, 0),
00086 bitoff(-5, 1), bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1),
00087 bitoff(3, 1), bitoff(5, 1),
00088 bitoff(-4, 2), bitoff(-2, 2), bitoff(0, 2), bitoff(2, 2), bitoff(4, 2),
00089 bitoff(-1, 3), bitoff(1, 3),
00090 bitoff(9999, 9999),
00091 };
00092
00093 static int bitmap4[] = {
00094 bitoff(-3, -3), bitoff(-1, -3), bitoff(1, -3), bitoff(3, -3),
00095 bitoff(-4, -2), bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2), bitoff(4,
00096 -2),
00097 bitoff(-5, -1), bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1),
00098 bitoff(3, -1), bitoff(5, -1),
00099 bitoff(-6, 0), bitoff(-4, 0), bitoff(-2, 0), bitoff(0, 0), bitoff(2,
00100 0),
00101 bitoff(4, 0), bitoff(6, 0),
00102 bitoff(-5, 1), bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1),
00103 bitoff(3, 1), bitoff(5, 1),
00104 bitoff(-4, 2), bitoff(-2, 2), bitoff(0, 2), bitoff(2, 2), bitoff(4, 2),
00105 bitoff(-3, 3), bitoff(-1, 3), bitoff(1, 3), bitoff(3, 3),
00106 bitoff(9999, 9999),
00107 };
00108
00109 static int *bitmaps[5] = {
00110 bitmap0,
00111 bitmap1,
00112 bitmap2,
00113 bitmap3,
00114 bitmap4,
00115 };
00116
00117 #define GCFx(x) ((x + WORLD_X) % WORLD_X)
00118 #define GCFy(y) ((y + WORLD_Y) % WORLD_Y)
00119
00120 int
00121 emp_getbit(int x, int y, unsigned char *bitmap)
00122 {
00123 int id;
00124
00125 id = (GCFy(y)) * WORLD_X / 2 + GCFx(x) / 2;
00126 return bitmap[id / 8] & bit(id & 07);
00127 }
00128
00129 void
00130 emp_setbit(int x, int y, unsigned char *bitmap)
00131 {
00132 int id;
00133
00134 id = (GCFy(y)) * WORLD_X / 2 + GCFx(x) / 2;
00135 bitmap[id / 8] |= bit(id & 07);
00136 }
00137
00138 static void
00139 emp_setbitmap(int x, int y, unsigned char *bitmap, int *bitmaps)
00140 {
00141 int *mp;
00142 int id;
00143 int dx, dy;
00144
00145 for (mp = bitmaps; *mp != 9999;) {
00146 dx = x + *mp++;
00147 dy = y + *mp++;
00148 id = (GCFy(dy)) * WORLD_X / 2 + GCFx(dx) / 2;
00149 bitmap[id / 8] |= bit(id & 07);
00150 }
00151 }
00152
00153 void
00154 bitinit2(struct nstr_sect *np, unsigned char *bitmap, int country)
00155 {
00156 struct sctstr sect;
00157 int eff;
00158
00159 while (nxtsct(np, §)) {
00160 if (sect.sct_own != country)
00161 continue;
00162 eff = sect.sct_effic / 20;
00163 if (eff > 4)
00164 eff = 4;
00165 emp_setbitmap(np->x, np->y, bitmap, bitmaps[eff]);
00166 }
00167 snxtsct_rewind(np);
00168 }