| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#include <stdio.h> |
| 19 |
#include <string.h> |
| 20 |
#include "imagelib.h" |
| 21 |
#include "table.h" |
| 22 |
#include "taipeilib.h" |
| 23 |
|
| 24 |
unsigned char grid[GRID_SX][GRID_SY][GRID_SZ]; |
| 25 |
|
| 26 |
char *filename; |
| 27 |
int layer; |
| 28 |
|
| 29 |
void |
| 30 |
load(int complain) |
| 31 |
{ |
| 32 |
int x, y, z; |
| 33 |
FILE *f; |
| 34 |
if (!filename) return; |
| 35 |
f = fopen(filename, "r"); |
| 36 |
if (!f) |
| 37 |
{ |
| 38 |
if (complain) |
| 39 |
perror(filename); |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
memset(grid, 0, sizeof(grid)); |
| 44 |
layer = 0; |
| 45 |
while (fscanf(f, "%d%*[^0-9-]", &x) > 0) |
| 46 |
{ |
| 47 |
if (x == 127) |
| 48 |
break; |
| 49 |
if (x <= 0) |
| 50 |
{ |
| 51 |
x = -x; |
| 52 |
fscanf(f, "%d%*[^0-9-]%d%*[^0-9-]", &y, &z); |
| 53 |
if (layer < z) |
| 54 |
layer = z; |
| 55 |
} |
| 56 |
grid[x][y][z] = 1; |
| 57 |
} |
| 58 |
|
| 59 |
invalidate(0, 0, table_width, table_height); |
| 60 |
} |
| 61 |
|
| 62 |
void |
| 63 |
invalidate_tile(int x, int y, int z) |
| 64 |
{ |
| 65 |
invalidate(gx2x(x, z), gy2y(y, z), TILE_SX, TILE_SY); |
| 66 |
} |
| 67 |
|
| 68 |
static void |
| 69 |
tile_synth2(image *rv) |
| 70 |
{ |
| 71 |
image *img; |
| 72 |
int x, y, which; |
| 73 |
int bx, by, bw, bh; |
| 74 |
int xo, yo, dx, dy; |
| 75 |
int tw, th, txo, tyo; |
| 76 |
image_list *list = rv->list; |
| 77 |
int width = rv->width; |
| 78 |
int height = rv->height; |
| 79 |
|
| 80 |
img = get_image("taipei-tiles", width*6, height*9, 0); |
| 81 |
|
| 82 |
switch (img->width) |
| 83 |
{ |
| 84 |
case 243: |
| 85 |
bx = 5; by = 5; bw = 39; bh = 39; |
| 86 |
xo = 50; yo = 6; dx = 36; dy = 36; |
| 87 |
tw = 34; th = 34; txo = 4; tyo = 1; |
| 88 |
break; |
| 89 |
} |
| 90 |
|
| 91 |
which = list->synth_flags; |
| 92 |
|
| 93 |
x = (which/10 - 2) * dx + xo; |
| 94 |
y = (which%10 - 1) * dy + yo; |
| 95 |
|
| 96 |
put_image (img, bx, by, bw, bh, rv, -bx, -by, 0); |
| 97 |
put_mask (img, bx, by, bw, bh, rv, -bx, -by, 0); |
| 98 |
if (which) |
| 99 |
put_image (img, x, y, tw, th, rv, txo-x, tyo-y, 0); |
| 100 |
} |
| 101 |
|
| 102 |
static image * |
| 103 |
tile_synth(image_list *list, int type, int width, int height) |
| 104 |
{ |
| 105 |
image *rv, *img; |
| 106 |
int bw, bh; |
| 107 |
|
| 108 |
for (rv = list->subimage[type]; rv; rv=rv->next) |
| 109 |
if (rv->width == width && rv->height == height) |
| 110 |
return rv; |
| 111 |
|
| 112 |
img = get_image("taipei-tiles", width*6, height*9, 0); |
| 113 |
|
| 114 |
switch (img->width) |
| 115 |
{ |
| 116 |
case 243: |
| 117 |
bw = 39; bh = 39; |
| 118 |
break; |
| 119 |
} |
| 120 |
|
| 121 |
rv = alloc_synth_image(list, bw, bh, type); |
| 122 |
rv->synth_func = tile_synth2; |
| 123 |
return rv; |
| 124 |
} |
| 125 |
|
| 126 |
image_list tile_images[] = { |
| 127 |
{ "bl", 1, 1, {0,0,0}, 0, tile_synth, 0 }, |
| 128 |
|
| 129 |
{ "n1", 1, 1, {0,0,0}, 0, tile_synth, 21 }, |
| 130 |
{ "n2", 1, 1, {0,0,0}, 0, tile_synth, 22 }, |
| 131 |
{ "n3", 1, 1, {0,0,0}, 0, tile_synth, 23 }, |
| 132 |
{ "n4", 1, 1, {0,0,0}, 0, tile_synth, 24 }, |
| 133 |
{ "n5", 1, 1, {0,0,0}, 0, tile_synth, 25 }, |
| 134 |
{ "n6", 1, 1, {0,0,0}, 0, tile_synth, 26 }, |
| 135 |
{ "n7", 1, 1, {0,0,0}, 0, tile_synth, 27 }, |
| 136 |
{ "n8", 1, 1, {0,0,0}, 0, tile_synth, 28 }, |
| 137 |
{ "n9", 1, 1, {0,0,0}, 0, tile_synth, 29 }, |
| 138 |
|
| 139 |
{ "p1", 1, 1, {0,0,0}, 0, tile_synth, 31 }, |
| 140 |
{ "p2", 1, 1, {0,0,0}, 0, tile_synth, 32 }, |
| 141 |
{ "p3", 1, 1, {0,0,0}, 0, tile_synth, 33 }, |
| 142 |
{ "p4", 1, 1, {0,0,0}, 0, tile_synth, 34 }, |
| 143 |
{ "p5", 1, 1, {0,0,0}, 0, tile_synth, 35 }, |
| 144 |
{ "p6", 1, 1, {0,0,0}, 0, tile_synth, 36 }, |
| 145 |
{ "p7", 1, 1, {0,0,0}, 0, tile_synth, 37 }, |
| 146 |
{ "p8", 1, 1, {0,0,0}, 0, tile_synth, 38 }, |
| 147 |
{ "p9", 1, 1, {0,0,0}, 0, tile_synth, 39 }, |
| 148 |
|
| 149 |
{ "b1", 1, 1, {0,0,0}, 0, tile_synth, 41 }, |
| 150 |
{ "b2", 1, 1, {0,0,0}, 0, tile_synth, 42 }, |
| 151 |
{ "b3", 1, 1, {0,0,0}, 0, tile_synth, 43 }, |
| 152 |
{ "b4", 1, 1, {0,0,0}, 0, tile_synth, 44 }, |
| 153 |
{ "b5", 1, 1, {0,0,0}, 0, tile_synth, 45 }, |
| 154 |
{ "b6", 1, 1, {0,0,0}, 0, tile_synth, 46 }, |
| 155 |
{ "b7", 1, 1, {0,0,0}, 0, tile_synth, 47 }, |
| 156 |
{ "b8", 1, 1, {0,0,0}, 0, tile_synth, 48 }, |
| 157 |
{ "b9", 1, 1, {0,0,0}, 0, tile_synth, 49 }, |
| 158 |
|
| 159 |
{ "xj", 1, 1, {0,0,0}, 0, tile_synth, 51 }, |
| 160 |
{ "xa", 1, 1, {0,0,0}, 0, tile_synth, 52 }, |
| 161 |
{ "xx", 1, 1, {0,0,0}, 0, tile_synth, 53 }, |
| 162 |
|
| 163 |
{ "cr", 1, 1, {0,0,0}, 0, tile_synth, 56 }, |
| 164 |
{ "cg", 1, 1, {0,0,0}, 0, tile_synth, 57 }, |
| 165 |
{ "cb", 1, 1, {0,0,0}, 0, tile_synth, 58 }, |
| 166 |
{ "ck", 1, 1, {0,0,0}, 0, tile_synth, 59 }, |
| 167 |
|
| 168 |
{ "sh", 1, 1, {0,0,0}, 0, tile_synth, 61 }, |
| 169 |
{ "sd", 1, 1, {0,0,0}, 0, tile_synth, 62 }, |
| 170 |
{ "sc", 1, 1, {0,0,0}, 0, tile_synth, 63 }, |
| 171 |
{ "ss", 1, 1, {0,0,0}, 0, tile_synth, 64 }, |
| 172 |
|
| 173 |
{ "du", 1, 1, {0,0,0}, 0, tile_synth, 66 }, |
| 174 |
{ "dd", 1, 1, {0,0,0}, 0, tile_synth, 67 }, |
| 175 |
{ "dl", 1, 1, {0,0,0}, 0, tile_synth, 68 }, |
| 176 |
{ "dr", 1, 1, {0,0,0}, 0, tile_synth, 69 }, |
| 177 |
{ 0 } |
| 178 |
}; |
| 179 |
|