00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef HAVE_CONFIG_H
00022 # include <config.h>
00023 #endif
00024
00025 #include "bodies.h"
00026 #include "hash_utils.h"
00027 #include "game.h"
00028
00029 using std::size_t;
00030
00031
00032
00033
00034
00035 short Body_lookup::bg_table[] = {
00036
00037
00038
00039
00040
00041
00042
00043 154, 762, 22,
00044 155, 762, 2,
00045 226, 892, 29,
00046 227, 400, 5,
00047 228, 414, 28,
00048 229, 414, 27,
00049 230, 762, 0,
00050
00051 247, 762, 23,
00052 259, 400, 20,
00053 265, 400, 27,
00054 274, 414, 2,
00055 299, 762, 0,
00056 304, 400, 28,
00057 317, 762, 0,
00058 318, 400, 5,
00059 319, 400, 9,
00060 337, 762, 0,
00061 354, 762, 8,
00062 375, 778, 2,
00063 380, 778, 4,
00064 381, 778, 3,
00065 382, 414, 7,
00066 394, 892, 10,
00067 401, 762, 25,
00068 401, 400, 16,
00069 403, 414, 16,
00070 445, 400, 3,
00071 446, 400, 4,
00072 447, 892, 11,
00073 448, 400, 6,
00074 449, 400, 7,
00075 450, 400, 8,
00076 451, 400, 13,
00077 452, 400, 10,
00078 454, 400, 12,
00079 455, 400, 11,
00080 456, 400, 14,
00081 457, 400, 15,
00082 458, 400, 16,
00083 459, 400, 17,
00084 460, 400, 18,
00085 461, 400, 19,
00086 462, 400, 20,
00087 463, 400, 21,
00088 464, 400, 22,
00089 465, 414, 18,
00090 466, 414, 13,
00091 467, 400, 24,
00092 468, 400, 25,
00093 469, 400, 26,
00094 471, 400, 30,
00095 472, 400, 31,
00096 473, 414, 1,
00097 475, 892, 4,
00098 476, 778, 1,
00099 477, 414, 6,
00100 478, 414, 10,
00101 479, 414, 11,
00102 480, 414, 14,
00103 482, 414, 16,
00104 485, 414, 17,
00105 487, 414, 19,
00106 488, 414, 20,
00107 489, 414, 21,
00108 490, 414, 22,
00109 491, 892, 12,
00110 492, 892, 13,
00111 493, 762, 0,
00112
00113 494, 892, 15,
00114 495, 892, 18,
00115 496, 892, 24,
00116 498, 892, 20,
00117 499, 892, 21,
00118 500, 778, 11,
00119 501, 778, 6,
00120 502, 778, 12,
00121 504, 778, 7,
00122 505, 778, 8,
00123 506, 892, 19,
00124 509, 892, 26,
00125 510, 892, 27,
00126 511, 762, 2,
00127 513, 762, 4,
00128 514, 762, 6,
00129 517, 762, 7,
00130 519, 762, 8,
00131 521, 762, 10,
00132 523, 762, 11,
00133 524, 762, 12,
00134 525, 762, 13,
00135 528, 762, 16,
00136 529, 762, 17,
00137 530, 762, 18,
00138 532, 762, 5,
00139 533, 778, 5,
00140 534, 762, 0,
00141 536, 762, 0,
00142 537, 762, 21,
00143 617, 414, 23,
00144 661, 762, 9,
00145 706, 762, 26,
00146 716, 892, 16,
00147 720, 400, 23,
00148 721, 400, 1,
00149 727, 778, 9,
00150 753, 762, 20,
00151 784, 892, 25,
00152 805, 892, 4,
00153 806, 892, 7,
00154 811, 892, 17,
00155 861, 778, 5,
00156 864, 400, 29,
00157 865, 762, 19,
00158 881, 892, 2,
00159 882, 892, 1,
00160 883, 762, 1,
00161 884, 892, 5,
00162 929, 400, 10,
00163 946, 892, 8,
00164 952, 762, 2,
00165 957, 400, 11,
00166 965, 400, 30,
00167 970, 762, 14,
00168 989, 400, 2,
00169 1015, 414, 4
00170 };
00171
00172 short Body_lookup::si_table[] = {
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 179, 402, 23,
00198 214, 402, 3,
00199 226, 414, 10,
00200 228, 402, 11,
00201 229, 414, 8,
00202 230, 414, 27,
00203 247, 400, 24,
00204 250, 414, 23,
00205 259, 402, 12,
00206 265, 400, 27,
00207 274, 414, 15,
00208 298, 892, 16,
00209 299, 414, 21,
00210 302, 762, 3,
00211 304, 400, 28,
00212 312, 892, 19,
00213 317, 402, 13,
00214 318, 414, 16,
00215 319, 400, 9,
00216 329, 892, 25,
00217 334, 762, 22,
00218 337, 762, 15,
00219 354, 762, 11,
00220 363, 892, 14,
00221 372, 778, 1,
00222 373, 402, 31,
00223 375, 778, 2,
00224 381, 414, 17,
00225 382, 762, 10,
00226 401, 402, 15,
00227 446, 400, 4,
00228 447, 402, 18,
00229 449, 762, 29,
00230 451, 400, 13,
00231 454, 400, 12,
00232 455, 400, 11,
00233 457, 400, 15,
00234 458, 400, 16,
00235 460, 778, 7,
00236 461, 400, 19,
00237 462, 400, 20,
00238 464, 400, 22,
00239 465, 414, 18,
00240 468, 400, 25,
00241 469, 400, 26,
00242 472, 892, 29,
00243 478, 414, 4,
00244 480, 414, 1,
00245 487, 414, 19,
00246 488, 414, 20,
00247 491, 892, 12,
00248 492, 762, 1,
00249 493, 892, 9,
00250 494, 402, 19,
00251 495, 892, 18,
00252 496, 892, 24,
00253 498, 892, 11,
00254 499, 892, 13,
00255 500, 778, 11,
00256 501, 778, 4,
00257 502, 778, 12,
00258 509, 892, 26,
00259 510, 892, 27,
00260 511, 892, 1,
00261 512, 400, 0,
00262 514, 762, 6,
00263 517, 892, 2,
00264 521, 400, 0,
00265 523, 892, 4,
00266 524, 762, 12,
00267 528, 762, 16,
00268 529, 892, 8,
00269 530, 892, 6,
00270 532, 762, 5,
00271 533, 778, 5,
00272 536, 400, 0,
00273 537, 892, 7,
00274 550, 762, 7,
00275 560, 400, 3,
00276 565, 400, 6,
00277 581, 400, 7,
00278 588, 762, 8,
00279 647, 400, 5,
00280 652, 400, 17,
00281 658, 400, 30,
00282 660, 400, 10,
00283 661, 762, 9,
00284 665, 402, 22,
00285 669, 400, 8,
00286 691, 414, 4,
00287 702, 892, 20,
00288 703, 400, 0,
00289 706, 762, 26,
00290 716, 892, 10,
00291 720, 400, 23,
00292 721, 400, 1,
00293 725, 414, 4,
00294 734, 402, 21,
00295 742, 400, 21,
00296 744, 414, 5,
00297 747, 762, 27,
00298 753, 762, 20,
00299 754, 762, 2,
00300 763, 892, 28,
00301 766, 402, 2,
00302 772, 892, 31,
00303 798, 402, 16,
00304 805, 402, 4,
00305 809, 414, 2,
00306 811, 892, 17,
00307 814, 402, 5,
00308 815, 402, 6,
00309 816, 402, 7,
00310 817, 402, 14,
00311 818, 402, 9,
00312 830, 402, 8,
00313 832, 778, 8,
00314 846, 762, 24,
00315 855, 414, 6,
00316 861, 762, 23,
00317 862, 414, 7,
00318 865, 762, 19,
00319 867, 892, 30,
00320 874, 762, 17,
00321 877, 778, 6,
00322 880, 762, 18,
00323 882, 892, 21,
00324 883, 414, 3,
00325 885, 778, 3,
00326 888, 414, 11,
00327 906, 762, 21,
00328 915, 400, 0,
00329 916, 414, 12,
00330 917, 402, 10,
00331 945, 402, 29,
00332 946, 402, 27,
00333 947, 402, 28,
00334 957, 402, 30,
00335 968, 402, 17,
00336 970, 892, 5,
00337 975, 400, 20,
00338 978, 778, 9,
00339 979, 778, 10,
00340 981, 402, 25,
00341 989, 400, 2,
00342 1015, 402, 26,
00343 1024, 414, 28,
00344 1025, 414, 29,
00345 1026, 414, 30,
00346 1027, 414, 31,
00347 1028, 400, 1,
00348 1029, 400, 2
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 };
00372
00373 #ifndef DONT_HAVE_HASH_SET
00374
00375
00376
00377
00378 class Hash_shapes
00379 {
00380 public:
00381
00382 size_t operator() (const short *t) const
00383 { return t[0]; }
00384 };
00385
00386
00387
00388
00389 class Equal_shapes
00390 {
00391 public:
00392 bool operator() (const short *a, const short *b) const
00393 { return a[0] == b[0]; }
00394 };
00395
00396 #else
00397
00398
00399
00400
00401 class Less_shapes
00402 {
00403 public:
00404 bool operator() (const short *a, const short *b) const
00405 { return a[0] < b[0]; }
00406 };
00407
00408 #endif
00409
00410
00411
00412
00413
00414
00415
00416 int Body_lookup::find
00417 (
00418 int liveshape,
00419 int& deadshape,
00420 int& deadframe
00421 )
00422 {
00423 #ifndef DONT_HAVE_HASH_SET
00424 static hash_set<short *, Hash_shapes, Equal_shapes> *htable = 0;
00425 #else
00426 static std::set<short *, Less_shapes> *htable = 0;
00427 #endif
00428
00429 if (!htable)
00430 {
00431 #ifndef DONT_HAVE_HASH_SET
00432 htable = new hash_set<short *, Hash_shapes, Equal_shapes>(300);
00433 #else
00434 htable = new std::set<short *, Less_shapes>();
00435 #endif
00436 short *ptr;
00437 int cnt;
00438 if (Game::get_game_type() == BLACK_GATE)
00439 {
00440 cnt = sizeof(bg_table)/(3*sizeof(bg_table[0]));
00441 ptr = &bg_table[0];
00442 }
00443 else
00444 {
00445 cnt = sizeof(si_table)/(3*sizeof(si_table[0]));
00446 ptr = &si_table[0];
00447 }
00448 while (cnt--)
00449 {
00450 htable->insert(ptr);
00451 ptr += 3;
00452 }
00453 }
00454 short key = (short) liveshape;
00455 #ifndef DONT_HAVE_HASH_SET
00456 hash_set<short *, Hash_shapes, Equal_shapes>::iterator it =
00457 htable->find(&key);
00458 #else
00459 std::set<short *, Less_shapes>::iterator it = htable->find(&key);
00460 #endif
00461 if (it != htable->end())
00462 {
00463 short *triple = *it;
00464 deadshape = triple[1];
00465 deadframe = triple[2];
00466 return 1;
00467 }
00468 else
00469 return 0;
00470 }
00471
00472
00473
00474
00475
00476
00477 int Is_body
00478 (
00479 int shapeid
00480 )
00481 {
00482 switch (shapeid)
00483 {
00484 case 400:
00485 case 414:
00486 case 762:
00487 case 778:
00488 case 892:
00489 return 1;
00490 case 402:
00491 return Game::get_game_type() == SERPENT_ISLE;
00492 default:
00493 return 0;
00494 }
00495 }