1 /* The Ace of Penguins - tplib.c
2    Copyright (C) 1998, 2001 DJ Delorie
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
17 
18 #include <stdio.h>
19 #include <string.h>
20 #include "imagelib.h"
21 #include "taipeilib.h"
22 #include "cards.h"
23 
24 unsigned char grid[GRID_SX][GRID_SY][GRID_SZ];
25 
26 char *filename;
27 int layer;
28 
29 extern int table_width, table_height;
30 
31 void
load(int complain)32 load(int complain)
33 {
34   int x, y, z;
35   FILE *f;
36   if (!filename) return;
37   f = fopen(filename, "r");
38   if (!f)
39   {
40     if (complain)
41       perror(filename);
42     return;
43   }
44 
45   memset(grid, 0, sizeof(grid));
46   layer = 0;
47   while (fscanf(f, "%d%*[^0-9-]", &x) > 0)
48   {
49     if (x == 127)
50       break;
51     if (x <= 0)
52     {
53       x = -x;
54       fscanf(f, "%d%*[^0-9-]%d%*[^0-9-]", &y, &z);
55       if (layer < z)
56 	layer = z;
57     }
58     grid[x][y][z] = 1;
59   }
60 
61   invalidate(0, 0, table_width, table_height);
62 }
63 
64 void
invalidate_tile(int x,int y,int z)65 invalidate_tile(int x, int y, int z)
66 {
67   invalidate(gx2x(x, z), gy2y(y, z), TILE_SX, TILE_SY);
68 }
69 
70 static void
tile_synth2(image * rv)71 tile_synth2(image *rv)
72 {
73   image *img;
74   int x, y, which;
75   int bx, by, bw, bh;
76   int xo, yo, dx, dy;
77   int tw, th, txo, tyo;
78   image_list *list = rv->list;
79   int width = rv->width;
80   int height = rv->height;
81 
82   img = get_image("taipei-tiles", width*6, height*9, 0);
83 
84   switch (img->width)
85     {
86     case 243:
87       bx = 5; by = 5; bw = 39; bh = 39;
88       xo = 50; yo = 6; dx = 36; dy = 36;
89       tw = 34; th = 34; txo = 4; tyo = 1;
90       break;
91     }
92 
93   which = list->synth_flags;
94 
95   x = (which/10 - 2) * dx + xo;
96   y = (which%10 - 1) * dy + yo;
97 
98   put_image (img, bx, by, bw, bh, rv, -bx, -by, 0);
99   put_mask  (img, bx, by, bw, bh, rv, -bx, -by, 0);
100   if (which)
101     put_image (img, x, y, tw, th, rv, txo-x, tyo-y, 0);
102 }
103 
104 static image *
tile_synth(image_list * list,int type,int width,int height)105 tile_synth(image_list *list, int type, int width, int height)
106 {
107   image *rv, *img;
108   int bw, bh;
109 
110   for (rv = list->subimage[type]; rv; rv=rv->next)
111     if (rv->width == width && rv->height == height)
112       return rv;
113 
114   img = get_image("taipei-tiles", width*6, height*9, 0);
115 
116   switch (img->width)
117     {
118     case 243:
119       bw = 39; bh = 39;
120       break;
121     }
122 
123   rv = alloc_synth_image(list, bw, bh, type);
124   rv->synth_func = tile_synth2;
125   return rv;
126 }
127 
128 image_list tile_images[] = {
129   { "bl", 1, 1, {0,0,0}, 0, tile_synth, 0 },
130 
131   { "n1", 1, 1, {0,0,0}, 0, tile_synth, 21 },
132   { "n2", 1, 1, {0,0,0}, 0, tile_synth, 22 },
133   { "n3", 1, 1, {0,0,0}, 0, tile_synth, 23 },
134   { "n4", 1, 1, {0,0,0}, 0, tile_synth, 24 },
135   { "n5", 1, 1, {0,0,0}, 0, tile_synth, 25 },
136   { "n6", 1, 1, {0,0,0}, 0, tile_synth, 26 },
137   { "n7", 1, 1, {0,0,0}, 0, tile_synth, 27 },
138   { "n8", 1, 1, {0,0,0}, 0, tile_synth, 28 },
139   { "n9", 1, 1, {0,0,0}, 0, tile_synth, 29 },
140 
141   { "p1", 1, 1, {0,0,0}, 0, tile_synth, 31 },
142   { "p2", 1, 1, {0,0,0}, 0, tile_synth, 32 },
143   { "p3", 1, 1, {0,0,0}, 0, tile_synth, 33 },
144   { "p4", 1, 1, {0,0,0}, 0, tile_synth, 34 },
145   { "p5", 1, 1, {0,0,0}, 0, tile_synth, 35 },
146   { "p6", 1, 1, {0,0,0}, 0, tile_synth, 36 },
147   { "p7", 1, 1, {0,0,0}, 0, tile_synth, 37 },
148   { "p8", 1, 1, {0,0,0}, 0, tile_synth, 38 },
149   { "p9", 1, 1, {0,0,0}, 0, tile_synth, 39 },
150 
151   { "b1", 1, 1, {0,0,0}, 0, tile_synth, 41 },
152   { "b2", 1, 1, {0,0,0}, 0, tile_synth, 42 },
153   { "b3", 1, 1, {0,0,0}, 0, tile_synth, 43 },
154   { "b4", 1, 1, {0,0,0}, 0, tile_synth, 44 },
155   { "b5", 1, 1, {0,0,0}, 0, tile_synth, 45 },
156   { "b6", 1, 1, {0,0,0}, 0, tile_synth, 46 },
157   { "b7", 1, 1, {0,0,0}, 0, tile_synth, 47 },
158   { "b8", 1, 1, {0,0,0}, 0, tile_synth, 48 },
159   { "b9", 1, 1, {0,0,0}, 0, tile_synth, 49 },
160 
161   { "xj", 1, 1, {0,0,0}, 0, tile_synth, 51 },
162   { "xa", 1, 1, {0,0,0}, 0, tile_synth, 52 },
163   { "xx", 1, 1, {0,0,0}, 0, tile_synth, 53 },
164 
165   { "cr", 1, 1, {0,0,0}, 0, tile_synth, 56 },
166   { "cg", 1, 1, {0,0,0}, 0, tile_synth, 57 },
167   { "cb", 1, 1, {0,0,0}, 0, tile_synth, 58 },
168   { "ck", 1, 1, {0,0,0}, 0, tile_synth, 59 },
169 
170   { "sh", 1, 1, {0,0,0}, 0, tile_synth, 61 },
171   { "sd", 1, 1, {0,0,0}, 0, tile_synth, 62 },
172   { "sc", 1, 1, {0,0,0}, 0, tile_synth, 63 },
173   { "ss", 1, 1, {0,0,0}, 0, tile_synth, 64 },
174 
175   { "du", 1, 1, {0,0,0}, 0, tile_synth, 66 },
176   { "dd", 1, 1, {0,0,0}, 0, tile_synth, 67 },
177   { "dl", 1, 1, {0,0,0}, 0, tile_synth, 68 },
178   { "dr", 1, 1, {0,0,0}, 0, tile_synth, 69 },
179   { 0 }
180 };
181 
182