Debian Codegraph @

src/cdogs/cwolfmap/cwolfmap.c

raw symbols SCIP
1 #include "cwolfmap.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #ifdef _MSC_VER
6 #include <direct.h>
7 #include <io.h>
8 #define access _access
9 /* Values for the second argument to access.
10 These may be OR'd together. */
11 #define R_OK 4 /* Test for read permission. */
12 #define W_OK 2 /* Test for write permission. */
13 #define F_OK 0 /* Test for existence. */
14 #else
15 #include <sys/time.h>
16 #include <unistd.h>
17 #endif
18
19 #include "audio_n3d.h"
20 #include "audiowl6.h"
21 #include "expand.h"
22 #include "n3d.h"
23
24 // TODO: use map header magic value
25 #define MAGIC 0xABCD
26
27 #ifndef PATH_MAX
28 #define PATH_MAX 4096
29 #endif
30
31 CWMapType CWGetType(
32 const char *path, const char **ext, const char **ext1,
33 const int spearMission)
34 {
35 char pathBuf[PATH_MAX];
36 sprintf(pathBuf, "%s/MAPHEAD.WL1", path);
37 if (access(pathBuf, F_OK) != -1)
38 {
39 if (ext && ext1)
40 *ext = *ext1 = "WL1";
41 return CWMAPTYPE_WL1;
42 }
43 sprintf(pathBuf, "%s/MAPHEAD.WL6", path);
44 if (access(pathBuf, F_OK) != -1)
45 {
46 if (ext && ext1)
47 *ext = *ext1 = "WL6";
48 return CWMAPTYPE_WL6;
49 }
50 sprintf(pathBuf, "%s/MAPHEAD.SD%d", path, spearMission);
51 if (access(pathBuf, F_OK) != -1)
52 {
53 if (ext && ext1)
54 {
55 // Steam keeps common files as .SOD extension,
56 // but specific files as .SD1/.SD2/.SD3 extension
57 switch (spearMission)
58 {
59 case 1:
60 *ext = "SD1";
61 break;
62 case 2:
63 *ext = "SD2";
64 break;
65 case 3:
66 *ext = "SD3";
67 break;
68 }
69 *ext1 = "SOD";
70 }
71 return CWMAPTYPE_SOD;
72 }
73 else
74 {
75 sprintf(pathBuf, "%s/MAPHEAD.SOD", path);
76 if (access(pathBuf, F_OK) != -1)
77 {
78 if (ext && ext1)
79 *ext = *ext1 = "SOD";
80 return CWMAPTYPE_SOD;
81 }
82 }
83 sprintf(pathBuf, "%s/MAPHEAD.BS6", path);
84 if (access(pathBuf, F_OK) != -1)
85 {
86 if (ext && ext1)
87 *ext = *ext1 = "BS6";
88 return CWMAPTYPE_BS6;
89 }
90 sprintf(pathBuf, "%s/MAPHEAD.BS1", path);
91 if (access(pathBuf, F_OK) != -1)
92 {
93 if (ext && ext1)
94 *ext = *ext1 = "BS1";
95 return CWMAPTYPE_BS1;
96 }
97 sprintf(pathBuf, "%s/maphead.n3d", path);
98 if (access(pathBuf, F_OK) != -1)
99 {
100 if (ext && ext1)
101 *ext = *ext1 = "n3d";
102 return CWMAPTYPE_N3D;
103 }
104 return CWMAPTYPE_UNKNOWN;
105 }
106
107 static int LoadMapHead(CWolfMap *map, const char *path);
108 static int LoadMapData(CWolfMap *map, const char *path);
109 int CWLoad(CWolfMap *map, const char *path, const int spearMission)
110 {
111 memset(map, 0, sizeof *map);
112 char pathBuf[PATH_MAX];
113 int err = 0;
114 int loadErr = 0;
115
116 const char *ext = "WL1";
117 const char *ext1 = "WL1";
118 map->type = CWGetType(path, &ext, &ext1, spearMission);
119 if (map->type == CWMAPTYPE_UNKNOWN)
120 {
121 err = -1;
122 fprintf(stderr, "Cannot find map at %s\n", path);
123 goto bail;
124 }
125
126 #define _TRY_LOAD(_fn, _loadFunc, ...) \
127 sprintf(pathBuf, "%s/" _fn ".%s", path, ext); \
128 loadErr = _loadFunc(__VA_ARGS__); \
129 if (loadErr != 0) \
130 { \
131 sprintf(pathBuf, "%s/" _fn ".%s", path, ext1); \
132 loadErr = _loadFunc(__VA_ARGS__); \
133 if (loadErr != 0) \
134 { \
135 err = loadErr; \
136 } \
137 }
138 _TRY_LOAD("MAPHEAD", LoadMapHead, map, pathBuf);
139
140 if (map->type == CWMAPTYPE_BS1 || map->type == CWMAPTYPE_BS6)
141 {
142 _TRY_LOAD("MAPTEMP", LoadMapData, map, pathBuf);
143 }
144 else
145 {
146 _TRY_LOAD("GAMEMAPS", LoadMapData, map, pathBuf);
147 }
148
149 _TRY_LOAD("AUDIOHED", CWAudioLoadHead, &map->audio.head, pathBuf);
150
151 _TRY_LOAD("AUDIOT", CWAudioLoadAudioT, &map->audio, map->type, pathBuf);
152
153 if (map->type == CWMAPTYPE_N3D)
154 {
155 // N3D stores music as ogg files in wad
156 sprintf(pathBuf, "%s/noah3d.wad", path);
157 loadErr = CWAudioN3DLoadAudioWAD(&map->audio, pathBuf);
158 if (loadErr != 0)
159 {
160 err = loadErr;
161 }
162
163 // Load custom level data
164 sprintf(pathBuf, "%s/noah3d.pk3", path);
165 char *languageBuf = CWN3DLoadLanguageEnu(pathBuf);
166 for (int i = 0; i < map->nLevels; i++)
167 {
168 map->levels[i].description =
169 CWLevelN3DLoadDescription(languageBuf, i);
170 }
171
172 CWN3DLoadQuizzes(map, languageBuf);
173 free(languageBuf);
174 }
175
176 _TRY_LOAD("VSWAP", CWVSwapLoad, &map->vswap, pathBuf);
177
178 bail:
179 return err;
180 }
181 static int LoadMapHead(CWolfMap *map, const char *path)
182 {
183 int err = 0;
184 memset(&map->mapHead, 0, sizeof map->mapHead);
185 FILE *f = fopen(path, "rb");
186 if (!f)
187 {
188 err = -1;
189 fprintf(stderr, "Failed to read %s\n", path);
190 goto bail;
191 }
192 const size_t size = sizeof map->mapHead;
193 // Read as many maps as we can; some versions of the game (SOD MP) truncate
194 // the headers
195 (void)!fread((void *)&map->mapHead, 1, size, f);
196 if (map->mapHead.magic != MAGIC)
197 {
198 err = -1;
199 fprintf(stderr, "Unexpected magic value: %x\n", map->mapHead.magic);
200 goto bail;
201 }
202
203 bail:
204 if (f)
205 {
206 fclose(f);
207 }
208 return err;
209 }
210
211 static void LevelsFree(CWolfMap *map);
212
213 static int LoadLevel(
214 const CWolfMap *map, CWLevel *level, const unsigned char *data,
215 const int off);
216 static int LoadMapData(CWolfMap *map, const char *path)
217 {
218 int err = 0;
219 unsigned char *buf = NULL;
220 FILE *f = fopen(path, "rb");
221 if (!f)
222 {
223 err = -1;
224 fprintf(stderr, "Failed to read %s\n", path);
225 goto bail;
226 }
227 fseek(f, 0, SEEK_END);
228 const long fsize = ftell(f);
229 fseek(f, 0, SEEK_SET);
230 buf = malloc(fsize);
231 if (fread(buf, 1, fsize, f) != (size_t)fsize)
232 {
233 err = -1;
234 fprintf(stderr, "Failed to read file\n");
235 goto bail;
236 }
237
238 LevelsFree(map);
239
240 for (const int32_t *ptr = &map->mapHead.ptr[0]; *ptr > 0; ptr++)
241 {
242 map->nLevels++;
243 }
244 map->levels = malloc(sizeof(CWLevel) * map->nLevels);
245 CWLevel *lPtr = map->levels;
246 for (const int32_t *ptr = &map->mapHead.ptr[0]; *ptr > 0; ptr++, lPtr++)
247 {
248 err = LoadLevel(map, lPtr, buf, *ptr);
249 if (err != 0)
250 {
251 goto bail;
252 }
253 }
254
255 bail:
256 if (f)
257 {
258 fclose(f);
259 }
260 free(buf);
261 if (err != 0)
262 {
263 CWFree(map);
264 }
265 return err;
266 }
267 static int LoadPlane(
268 const CWolfMap *map, CWPlane *plane, const unsigned char *data,
269 const uint32_t off, unsigned char *buf, const int bufSize);
270 // https://moddingwiki.shikadi.net/wiki/GameMaps_Format#Level_headers
271 static int LoadLevel(
272 const CWolfMap *map, CWLevel *level, const unsigned char *data,
273 const int off)
274 {
275 int err = 0;
276 unsigned char *buf = NULL;
277 level->description = NULL;
278 memcpy(&level->header, data + off, sizeof(level->header));
279
280 const int bufSize =
281 level->header.width * level->header.height * sizeof(uint16_t);
282 buf = malloc(bufSize);
283 for (int i = 0; i < NUM_PLANES; i++)
284 {
285 const int32_t plen = *(&level->header.lenPlane0 + i);
286 if (plen <= 0)
287 {
288 memset(&level->planes[i], 0, sizeof level->planes[i]);
289 continue;
290 }
291 const uint32_t poff = *(&level->header.offPlane0 + i);
292 err = LoadPlane(map, &level->planes[i], data, poff, buf, bufSize);
293 if (err != 0)
294 {
295 goto bail;
296 }
297 }
298
299 // Check if level has any player spawns
300 level->hasPlayerSpawn = false;
301 for (int y = 0; y < level->header.height && !level->hasPlayerSpawn; y++)
302 {
303 for (int x = 0; x < level->header.width && !level->hasPlayerSpawn; x++)
304 {
305 const uint16_t ch = CWLevelGetCh(level, 1, x, y);
306 const CWEntity entity = CWChToEntity(ch);
307 if (entity == CWENT_PLAYER_SPAWN_N ||
308 entity == CWENT_PLAYER_SPAWN_E ||
309 entity == CWENT_PLAYER_SPAWN_S ||
310 entity == CWENT_PLAYER_SPAWN_W)
311 {
312 level->hasPlayerSpawn = true;
313 }
314 }
315 }
316
317 bail:
318 free(buf);
319 return err;
320 }
321 static int LoadPlane(
322 const CWolfMap *map, CWPlane *plane, const unsigned char *data,
323 const uint32_t off, unsigned char *buf, const int bufSize)
324 {
325 int err = 0;
326
327 if (off == 0)
328 {
329 goto bail;
330 }
331
332 ExpandCarmack(data + off, buf);
333 plane->len = bufSize;
334 plane->plane = malloc(bufSize);
335 const bool hasFinalLength =
336 map->type != CWMAPTYPE_BS6 && map->type != CWMAPTYPE_BS1;
337 ExpandRLEW(buf, (unsigned char *)plane->plane, MAGIC, hasFinalLength);
338
339 bail:
340 return err;
341 }
342
343 void CWCopy(CWolfMap *dst, const CWolfMap *src)
344 {
345 memcpy(dst, src, sizeof *dst);
346 const size_t levelsSize = sizeof(CWLevel) * dst->nLevels;
347 dst->levels = malloc(levelsSize);
348 memcpy(dst->levels, src->levels, levelsSize);
349 for (int i = 0; i < dst->nLevels; i++)
350 {
351 for (int j = 0; j < NUM_PLANES; j++)
352 {
353 const int len = dst->levels[i].planes[j].len;
354 dst->levels[i].planes[j].plane = malloc(len);
355 memcpy(
356 dst->levels[i].planes[j].plane, src->levels[i].planes[j].plane,
357 len);
358 }
359 if (src->levels[i].description)
360 {
361 dst->levels[i].description = strdup(src->levels[i].description);
362 }
363 }
364 const size_t audioHeadLen = dst->audio.head.nOffsets * sizeof(uint32_t);
365 dst->audio.head.offsets = malloc(audioHeadLen);
366 memcpy(dst->audio.head.offsets, src->audio.head.offsets, audioHeadLen);
367 const uint32_t audioDataLen =
368 dst->audio.head.offsets[dst->audio.head.nOffsets - 1];
369 dst->audio.data = malloc(audioDataLen);
370 memcpy(dst->audio.data, src->audio.data, audioDataLen);
371 dst->vswap.data = malloc(dst->vswap.dataLen);
372 memcpy(dst->vswap.data, src->vswap.data, dst->vswap.dataLen);
373 const size_t vswapSoundsLen = dst->vswap.nSounds * sizeof(CWVSwapSound);
374 dst->vswap.sounds = malloc(vswapSoundsLen);
375 memcpy(dst->vswap.sounds, src->vswap.sounds, vswapSoundsLen);
376 // TODO: copy wad
377 // TODO: copy quizzes
378 }
379
380 void CWFree(CWolfMap *map)
381 {
382 if (map == NULL)
383 {
384 return;
385 }
386 LevelsFree(map);
387 CWAudioFree(&map->audio);
388 CWVSwapFree(&map->vswap);
389 for (int i = 0; i < map->nQuizzes; i++)
390 {
391 CWN3DQuizFree(&map->quizzes[i]);
392 }
393 free(map->quizzes);
394 memset(map, 0, sizeof *map);
395 }
396 static void LevelFree(CWLevel *level);
397 static void LevelsFree(CWolfMap *map)
398 {
399 for (int i = 0; i < map->nLevels; i++)
400 {
401 LevelFree(&map->levels[i]);
402 }
403 free(map->levels);
404 map->nLevels = 0;
405 }
406 static void LevelFree(CWLevel *level)
407 {
408 for (int i = 0; i < NUM_PLANES; i++)
409 {
410 free(level->planes[i].plane);
411 }
412 free(level->description);
413 }
414
415 const char *CWGetDescription(CWolfMap *map, const int spearMission)
416 {
417 switch (map->type)
418 {
419 case CWMAPTYPE_BS1:
420 case CWMAPTYPE_BS6: // fallthrough
421 return "You're pitted against Dr. Pyrus Goldfire. He's found a way to "
422 "replicate pure gold, which he's using to fund his maniacal "
423 "plan. Goldfire has built six highly-secure, futuristic "
424 "locations where his creations are being hatched. It's up to "
425 "you to penetrate his security and stop him at all costs.";
426 case CWMAPTYPE_N3D:
427 return "It's been a long journey. In just a few days, the ark doors "
428 "will open and Noah, his family & the animals will be back on "
429 "dry land. But the animals have become a bit restless and are "
430 "out of their cages. Camels, giraffes, monkeys, kangaroos and "
431 "more are wandering throughout the corridors of the ark. As "
432 "Noah, it's your job to regain order & get the animals to "
433 "sleep until you leave the ark. Your only tool to accomplish "
434 "this is the food you brought aboard the ark. Can it be done? "
435 "You bet! But how?";
436 case CWMAPTYPE_SOD:
437 switch (spearMission)
438 {
439 case 1:
440 return "It's World War II and you are B.J. Blazkowicz, the "
441 "Allies' "
442 "most valuable agent. In the midst of the German "
443 "Blitzkrieg, "
444 "the Spear that pierced the side of Christ is taken from "
445 "Versailles by the Nazis and secured in the impregnable "
446 "Castle "
447 "Wolfenstein. According to legend, no man can be defeated "
448 "when "
449 "he has the Spear. Hitler believes himself to be "
450 "invincible "
451 "with the power of the Spear as his brutal army sweeps "
452 "across "
453 "Europe.\n\nYour mission is to infiltrate the heavily "
454 "guarded "
455 "Nazi stronghold and recapture the Spear from an already "
456 "unbalanced Hitler. The loss of his most coveted weapon "
457 "could "
458 "push him over the edge. It could also get you ripped to "
459 "pieces.";
460 case 2:
461 return "Six weeks after the Spear of Destiny has been brought out "
462 "of enemy hands, the Axis mounts a successful commando "
463 "raid to recover it! After a bloody battle and narrow "
464 "escape, it's taken to the Nazis' Secret Scandinavian "
465 "Base, excavated from the solid rock of a fjord. The "
466 "fortress is said to be impregnable!";
467 case 3:
468 return "As the Allies' top agent, you face your toughest "
469 "challenge yet! Learning from his past mistakes, Hitler "
470 "has expanded his subterranean command bunker beneath the "
471 "chancellery in Berlin so that he can keep the Spear of "
472 "Destiny nearby and well-guarded!\n\nCalling upon the dark "
473 "forces of the occult, Hitler can see into the future and "
474 "obtain the plans to future weapon systems!";
475 }
476 break;
477 case CWMAPTYPE_WL1:
478 return "Captured in your attempt to grab the secret plans, you "
479 "were taken to the Nazi prison Castle Wolfenstein for "
480 "questioning and eventual execution. Now for twelve long "
481 "days you've been imprisoned beneath the castle fortress. "
482 "Just beyond your cell door sits a lone thick-necked Nazi "
483 "guard. He assisted an SS Dentist / Mechanic in an attempt "
484 "to jump start your tonsils earlier that morning. You're "
485 "at your breaking point! Quivering on the floor you beg "
486 "for medical assistance in return for information. His "
487 "face hints a smug grin of victory as he reaches for his "
488 "keys. He opens the door, tumblers in the lock echo "
489 "through the corridors and the door squeaks open. HIS "
490 "MISTAKE!\n\nA single kick to his knee sends him to the "
491 "floor. Giving him your version of the victory sign, you "
492 "grab his knife and quickly finish the job. You stand over "
493 "the guard's fallen body, grabbing frantically for his "
494 "gun. You're not sure if the other guards heard his "
495 "muffled scream. Deep in the belly of a Nazi dungeon, you "
496 "must escape. This desperate act has sealed your fate-get "
497 "out or die trying.";
498 case CWMAPTYPE_WL6:
499 return "You're William J. \"B.J.\" Blazkowicz, the Allies' bad "
500 "boy of espionage and a terminal action seeker. Your "
501 "mission was to infiltrate the Nazi fortress Castle "
502 "Hollehammer and find the plans for Operation Eisenfaust "
503 "(Iron Fist), the Nazi's blueprint for building the "
504 "perfect army. Rumors are that deep within Castle "
505 "Hollehammer the diabolical Dr. Schabbs has perfected a "
506 "technique for building a fierce army from the bodies of "
507 "the dead. It's so far removed from reality that it would "
508 "seem silly if it wasn't so sick. But what if it were "
509 "true?";
510 default:
511 break;
512 }
513 return NULL;
514 }
515
516 void CWN3DLoadQuizzes(CWolfMap *map, const char *languageBuf)
517 {
518 // May be reloading quizzes
519 for (int i = 0; i < map->nQuizzes; i++)
520 {
521 CWN3DQuizFree(&map->quizzes[i]);
522 }
523 free(map->quizzes);
524 map->quizzes = NULL;
525 map->nQuizzes = 0;
526 for (int q = 1;; q++)
527 {
528 char *question = CWLevelN3DLoadQuizQuestion(languageBuf, q);
529 if (question == NULL)
530 {
531 break;
532 }
533 map->nQuizzes++;
534 map->quizzes =
535 realloc(map->quizzes, map->nQuizzes * sizeof(CWN3DQuiz));
536 CWN3DQuiz *quiz = &map->quizzes[map->nQuizzes - 1];
537 memset(quiz, 0, sizeof *quiz);
538 quiz->question = question;
539 for (char a = 'A';; a++)
540 {
541 bool correct = false;
542 char *answer =
543 CWLevelN3DLoadQuizAnswer(languageBuf, q, a, &correct);
544 if (answer == NULL)
545 {
546 break;
547 }
548 quiz->nAnswers++;
549 quiz->answers =
550 realloc(quiz->answers, quiz->nAnswers * sizeof(char *));
551 quiz->answers[quiz->nAnswers - 1] = answer;
552 if (correct)
553 {
554 quiz->correctIdx = quiz->nAnswers - 1;
555 }
556 }
557 }
558 }
559
560 int CWGetAudioSampleRate(const CWolfMap *map)
561 {
562 switch (map->type)
563 {
564 case CWMAPTYPE_N3D:
565 return 11025;
566 default:
567 return 7042;
568 }
569 }
570
571 // http://gaarabis.free.fr/_sites/specs/wlspec_index.html
572
573 uint16_t CWLevelGetCh(
574 const CWLevel *level, const int planeIndex, const int x, const int y)
575 {
576 const CWPlane *plane = &level->planes[planeIndex];
577 return plane->plane[y * level->header.width + x];
578 }
579
580 static const CWTile tileMap[] = {
581 // 0-63
582 CWTILE_WALL,
583 CWTILE_WALL,
584 CWTILE_WALL,
585 CWTILE_WALL,
586 CWTILE_WALL,
587 CWTILE_WALL,
588 CWTILE_WALL,
589 CWTILE_WALL,
590 CWTILE_WALL,
591 CWTILE_WALL,
592 CWTILE_WALL,
593 CWTILE_WALL,
594 CWTILE_WALL,
595 CWTILE_WALL,
596 CWTILE_WALL,
597 CWTILE_WALL,
598 CWTILE_WALL,
599 CWTILE_WALL,
600 CWTILE_WALL,
601 CWTILE_WALL,
602 CWTILE_WALL,
603 CWTILE_WALL,
604 CWTILE_WALL,
605 CWTILE_WALL,
606 CWTILE_WALL,
607 CWTILE_WALL,
608 CWTILE_WALL,
609 CWTILE_WALL,
610 CWTILE_WALL,
611 CWTILE_WALL,
612 CWTILE_WALL,
613 CWTILE_WALL,
614 CWTILE_WALL,
615 CWTILE_WALL,
616 CWTILE_WALL,
617 CWTILE_WALL,
618 CWTILE_WALL,
619 CWTILE_WALL,
620 CWTILE_WALL,
621 CWTILE_WALL,
622 CWTILE_WALL,
623 CWTILE_WALL,
624 CWTILE_WALL,
625 CWTILE_WALL,
626 CWTILE_WALL,
627 CWTILE_WALL,
628 CWTILE_WALL,
629 CWTILE_WALL,
630 CWTILE_WALL,
631 CWTILE_WALL,
632 CWTILE_WALL,
633 CWTILE_WALL,
634 CWTILE_WALL,
635 CWTILE_WALL,
636 CWTILE_WALL,
637 CWTILE_WALL,
638 CWTILE_WALL,
639 CWTILE_WALL,
640 CWTILE_WALL,
641 CWTILE_WALL,
642 CWTILE_WALL,
643 CWTILE_WALL,
644 CWTILE_WALL,
645 CWTILE_WALL,
646 // 64-79
647 CWTILE_UNKNOWN,
648 CWTILE_UNKNOWN,
649 CWTILE_UNKNOWN,
650 CWTILE_UNKNOWN,
651 CWTILE_UNKNOWN,
652 CWTILE_UNKNOWN,
653 CWTILE_UNKNOWN,
654 CWTILE_UNKNOWN,
655 CWTILE_UNKNOWN,
656 CWTILE_UNKNOWN,
657 CWTILE_UNKNOWN,
658 CWTILE_UNKNOWN,
659 CWTILE_UNKNOWN,
660 CWTILE_UNKNOWN,
661 CWTILE_UNKNOWN,
662 CWTILE_UNKNOWN,
663 // 80
664 CWTILE_UNKNOWN,
665 CWTILE_UNKNOWN,
666 CWTILE_UNKNOWN,
667 CWTILE_UNKNOWN,
668 CWTILE_UNKNOWN,
669 CWTILE_AREA,
670 CWTILE_UNKNOWN,
671 CWTILE_UNKNOWN,
672 CWTILE_UNKNOWN,
673 CWTILE_BACKGROUND,
674 // 90
675 CWTILE_DOOR_V,
676 CWTILE_DOOR_H,
677 CWTILE_DOOR_GOLD_V,
678 CWTILE_DOOR_GOLD_H,
679 CWTILE_DOOR_SILVER_V,
680 CWTILE_DOOR_SILVER_H,
681 // 96-99
682 CWTILE_DOOR_V, // Doors to stairs
683 CWTILE_DOOR_H,
684 CWTILE_UNKNOWN,
685 CWTILE_UNKNOWN,
686 // 100
687 CWTILE_ELEVATOR_V,
688 CWTILE_ELEVATOR_H,
689 // 102-105
690 CWTILE_UNKNOWN,
691 CWTILE_UNKNOWN,
692 CWTILE_UNKNOWN,
693 CWTILE_UNKNOWN,
694 // 106-143
695 CWTILE_AREA,
696 CWTILE_SECRET_EXIT,
697 CWTILE_AREA,
698 CWTILE_AREA,
699 CWTILE_AREA,
700 CWTILE_AREA,
701 CWTILE_AREA,
702 CWTILE_AREA,
703 CWTILE_AREA,
704 CWTILE_AREA,
705 CWTILE_AREA,
706 CWTILE_AREA,
707 CWTILE_AREA,
708 CWTILE_AREA,
709 CWTILE_AREA,
710 CWTILE_AREA,
711 CWTILE_AREA,
712 CWTILE_AREA,
713 CWTILE_AREA,
714 CWTILE_AREA,
715 CWTILE_AREA,
716 CWTILE_AREA,
717 CWTILE_AREA,
718 CWTILE_AREA,
719 CWTILE_AREA,
720 CWTILE_AREA,
721 CWTILE_AREA,
722 CWTILE_AREA,
723 CWTILE_AREA,
724 CWTILE_AREA,
725 CWTILE_AREA,
726 CWTILE_AREA,
727 CWTILE_AREA,
728 CWTILE_AREA,
729 CWTILE_AREA,
730 CWTILE_AREA,
731 CWTILE_AREA,
732 CWTILE_AREA,
733 };
734
735 CWTile CWChToTile(const uint16_t ch)
736 {
737 if (ch < sizeof tileMap / sizeof tileMap[0])
738 {
739 return tileMap[ch];
740 }
741 return CWTILE_UNKNOWN;
742 }
743
744 static const CWWall wallMap[] = {
745 CWWALL_UNKNOWN,
746 CWWALL_GREY_BRICK_1,
747 CWWALL_GREY_BRICK_2,
748 CWWALL_GREY_BRICK_FLAG,
749 CWWALL_GREY_BRICK_HITLER,
750 CWWALL_CELL,
751 CWWALL_GREY_BRICK_EAGLE,
752 CWWALL_CELL_SKELETON,
753 CWWALL_BLUE_BRICK_1,
754 CWWALL_BLUE_BRICK_2,
755 // 10
756 CWWALL_WOOD_EAGLE,
757 CWWALL_WOOD_HITLER,
758 CWWALL_WOOD,
759 CWWALL_ENTRANCE,
760 CWWALL_STEEL_SIGN,
761 CWWALL_STEEL,
762 CWWALL_LANDSCAPE,
763 CWWALL_RED_BRICK,
764 CWWALL_RED_BRICK_SWASTIKA,
765 CWWALL_PURPLE,
766 // 20
767 CWWALL_RED_BRICK_FLAG,
768 CWWALL_ELEVATOR,
769 CWWALL_DEAD_ELEVATOR,
770 CWWALL_WOOD_IRON_CROSS,
771 CWWALL_DIRTY_BRICK_1,
772 CWWALL_PURPLE_BLOOD,
773 CWWALL_DIRTY_BRICK_2,
774 CWWALL_GREY_BRICK_3,
775 CWWALL_GREY_BRICK_SIGN,
776 CWWALL_BROWN_WEAVE,
777 // 30
778 CWWALL_BROWN_WEAVE_BLOOD_2,
779 CWWALL_BROWN_WEAVE_BLOOD_3,
780 CWWALL_BROWN_WEAVE_BLOOD_1,
781 CWWALL_STAINED_GLASS,
782 CWWALL_BLUE_WALL_SKULL,
783 CWWALL_GREY_WALL_1,
784 CWWALL_BLUE_WALL_SWASTIKA,
785 CWWALL_GREY_WALL_VENT,
786 CWWALL_MULTICOLOR_BRICK,
787 CWWALL_GREY_WALL_2,
788 // 40
789 CWWALL_BLUE_WALL,
790 CWWALL_BLUE_BRICK_SIGN,
791 CWWALL_BROWN_MARBLE_1,
792 CWWALL_GREY_WALL_MAP,
793 CWWALL_BROWN_STONE_1,
794 CWWALL_BROWN_STONE_2,
795 CWWALL_BROWN_MARBLE_2,
796 CWWALL_BROWN_MARBLE_FLAG,
797 CWWALL_WOOD_PANEL,
798 CWWALL_GREY_WALL_HITLER,
799 // 50
800 CWWALL_STONE_WALL_1,
801 CWWALL_STONE_WALL_2,
802 CWWALL_STONE_WALL_FLAG,
803 CWWALL_STONE_WALL_WREATH,
804 CWWALL_GREY_CONCRETE_LIGHT,
805 CWWALL_GREY_CONCRETE_DARK,
806 CWWALL_BLOOD_WALL,
807 CWWALL_CONCRETE,
808 CWWALL_RAMPART_STONE_1,
809 CWWALL_RAMPART_STONE_2,
810 // 60
811 CWWALL_ELEVATOR_WALL,
812 CWWALL_WHITE_PANEL,
813 CWWALL_BROWN_CONCRETE,
814 CWWALL_PURPLE_BRICK,
815 CWWALL_UNKNOWN,
816 CWWALL_UNKNOWN,
817 CWWALL_UNKNOWN,
818 CWWALL_UNKNOWN,
819 CWWALL_UNKNOWN,
820 CWWALL_UNKNOWN,
821 };
822
823 CWWall CWChToWall(const uint16_t ch)
824 {
825 if (ch < sizeof wallMap / sizeof wallMap[0])
826 {
827 return wallMap[ch];
828 }
829 return CWWALL_UNKNOWN;
830 }
831
832 static const CWEntity entityMap[] = {
833 CWENT_NONE,
834 CWENT_UNKNOWN,
835 CWENT_UNKNOWN,
836 CWENT_UNKNOWN,
837 CWENT_UNKNOWN,
838 CWENT_UNKNOWN,
839 CWENT_UNKNOWN,
840 CWENT_UNKNOWN,
841 CWENT_UNKNOWN,
842 CWENT_UNKNOWN,
843 CWENT_UNKNOWN,
844 CWENT_UNKNOWN,
845 CWENT_UNKNOWN,
846 CWENT_UNKNOWN,
847 CWENT_UNKNOWN,
848 CWENT_UNKNOWN,
849 CWENT_UNKNOWN,
850 CWENT_UNKNOWN,
851 CWENT_UNKNOWN,
852 CWENT_PLAYER_SPAWN_N,
853 // 20
854 CWENT_PLAYER_SPAWN_E,
855 CWENT_PLAYER_SPAWN_S,
856 CWENT_PLAYER_SPAWN_W,
857 CWENT_WATER,
858 CWENT_OIL_DRUM,
859 CWENT_TABLE_WITH_CHAIRS,
860 CWENT_FLOOR_LAMP,
861 CWENT_CHANDELIER,
862 CWENT_HANGING_SKELETON,
863 CWENT_DOG_FOOD,
864 // 30
865 CWENT_WHITE_COLUMN,
866 CWENT_GREEN_PLANT,
867 CWENT_SKELETON,
868 CWENT_SINK_SKULLS_ON_STICK,
869 CWENT_BROWN_PLANT,
870 CWENT_VASE,
871 CWENT_TABLE,
872 CWENT_CEILING_LIGHT_GREEN,
873 CWENT_UTENSILS_BROWN_CAGE_BLOODY_BONES,
874 CWENT_ARMOR,
875 // 40
876 CWENT_CAGE,
877 CWENT_CAGE_SKELETON,
878 CWENT_BONES1,
879 CWENT_KEY_GOLD,
880 CWENT_KEY_SILVER,
881 CWENT_BED_CAGE_SKULLS,
882 CWENT_BASKET,
883 CWENT_FOOD,
884 CWENT_MEDKIT,
885 CWENT_AMMO,
886 // 50
887 CWENT_MACHINE_GUN,
888 CWENT_CHAIN_GUN,
889 CWENT_CROSS,
890 CWENT_CHALICE,
891 CWENT_CHEST,
892 CWENT_CROWN,
893 CWENT_LIFE,
894 CWENT_BONES_BLOOD,
895 CWENT_BARREL,
896 CWENT_WELL_WATER,
897 // 60
898 CWENT_WELL,
899 CWENT_POOL_OF_BLOOD,
900 CWENT_FLAG,
901 CWENT_CEILING_LIGHT_RED_AARDWOLF,
902 CWENT_BONES2,
903 CWENT_BONES3,
904 CWENT_BONES4,
905 CWENT_UTENSILS_BLUE_COW_SKULL,
906 CWENT_STOVE_WELL_BLOOD,
907 CWENT_RACK_ANGEL_STATUE,
908 // 70
909 CWENT_VINES,
910 CWENT_BROWN_COLUMN,
911 CWENT_AMMO_BOX,
912 CWENT_TRUCK_REAR,
913 CWENT_SPEAR,
914 CWENT_UNKNOWN,
915 CWENT_UNKNOWN,
916 CWENT_UNKNOWN,
917 CWENT_UNKNOWN,
918 CWENT_UNKNOWN,
919 // 80
920 CWENT_UNKNOWN,
921 CWENT_UNKNOWN,
922 CWENT_UNKNOWN,
923 CWENT_UNKNOWN,
924 CWENT_UNKNOWN,
925 CWENT_UNKNOWN,
926 CWENT_UNKNOWN,
927 CWENT_UNKNOWN,
928 CWENT_UNKNOWN,
929 CWENT_UNKNOWN,
930 // 90
931 CWENT_TURN_E,
932 CWENT_TURN_NE,
933 CWENT_TURN_N,
934 CWENT_TURN_NW,
935 CWENT_TURN_W,
936 CWENT_TURN_SW,
937 CWENT_TURN_S,
938 CWENT_TURN_SE,
939 CWENT_PUSHWALL,
940 CWENT_ENDGAME,
941 // 100
942 CWENT_NEXT_LEVEL,
943 CWENT_SECRET_LEVEL,
944 CWENT_UNKNOWN,
945 CWENT_UNKNOWN,
946 CWENT_UNKNOWN,
947 CWENT_UNKNOWN,
948 CWENT_GHOST,
949 CWENT_ANGEL,
950 CWENT_GUARD_E,
951 CWENT_GUARD_N,
952 // 110
953 CWENT_GUARD_W,
954 CWENT_GUARD_S,
955 CWENT_GUARD_MOVING_E,
956 CWENT_GUARD_MOVING_N,
957 CWENT_GUARD_MOVING_W,
958 CWENT_GUARD_MOVING_S,
959 CWENT_OFFICER_E,
960 CWENT_OFFICER_N,
961 CWENT_OFFICER_W,
962 CWENT_OFFICER_S,
963 // 120
964 CWENT_OFFICER_MOVING_E,
965 CWENT_OFFICER_MOVING_N,
966 CWENT_OFFICER_MOVING_W,
967 CWENT_OFFICER_MOVING_S,
968 CWENT_DEAD_GUARD,
969 CWENT_TRANS,
970 CWENT_SS_E,
971 CWENT_SS_N,
972 CWENT_SS_W,
973 CWENT_SS_S,
974 // 130
975 CWENT_SS_MOVING_E,
976 CWENT_SS_MOVING_N,
977 CWENT_SS_MOVING_W,
978 CWENT_SS_MOVING_S,
979 CWENT_KERRY_KANGAROO,
980 CWENT_ERNIE_ELEPHANT,
981 CWENT_UNKNOWN,
982 CWENT_UNKNOWN,
983 CWENT_DOG_E,
984 CWENT_DOG_N,
985 // 140
986 CWENT_DOG_W,
987 CWENT_DOG_S,
988 CWENT_UBER_MUTANT,
989 CWENT_BARNACLE_WILHELM,
990 CWENT_GUARD_E,
991 CWENT_GUARD_N,
992 CWENT_GUARD_W,
993 CWENT_GUARD_S,
994 CWENT_GUARD_MOVING_E,
995 CWENT_GUARD_MOVING_N,
996 // 150
997 CWENT_GUARD_MOVING_W,
998 CWENT_GUARD_MOVING_S,
999 CWENT_OFFICER_E,
1000 CWENT_OFFICER_N,
1001 CWENT_OFFICER_W,
1002 CWENT_OFFICER_S,
1003 CWENT_OFFICER_MOVING_E,
1004 CWENT_OFFICER_MOVING_N,
1005 CWENT_OFFICER_MOVING_W,
1006 CWENT_OFFICER_MOVING_S,
1007 // 160
1008 CWENT_ROBED_HITLER,
1009 CWENT_DEATH_KNIGHT,
1010 CWENT_SS_E,
1011 CWENT_SS_N,
1012 CWENT_SS_W,
1013 CWENT_SS_S,
1014 CWENT_SS_MOVING_E,
1015 CWENT_SS_MOVING_N,
1016 CWENT_SS_MOVING_W,
1017 CWENT_SS_MOVING_S,
1018 // 170
1019 CWENT_UNKNOWN,
1020 CWENT_UNKNOWN,
1021 CWENT_UNKNOWN,
1022 CWENT_UNKNOWN,
1023 CWENT_DOG_E,
1024 CWENT_DOG_N,
1025 CWENT_DOG_W,
1026 CWENT_DOG_S,
1027 CWENT_HITLER,
1028 CWENT_FETTGESICHT,
1029 // 180
1030 CWENT_GUARD_E,
1031 CWENT_GUARD_N,
1032 CWENT_GUARD_W,
1033 CWENT_GUARD_S,
1034 CWENT_GUARD_MOVING_E,
1035 CWENT_GUARD_MOVING_N,
1036 CWENT_GUARD_MOVING_W,
1037 CWENT_GUARD_MOVING_S,
1038 CWENT_OFFICER_E,
1039 CWENT_OFFICER_N,
1040 // 190
1041 CWENT_OFFICER_W,
1042 CWENT_OFFICER_S,
1043 CWENT_OFFICER_MOVING_E,
1044 CWENT_OFFICER_MOVING_N,
1045 CWENT_OFFICER_MOVING_W,
1046 CWENT_OFFICER_MOVING_S,
1047 CWENT_SCHABBS,
1048 CWENT_GRETEL,
1049 CWENT_SS_E,
1050 CWENT_SS_N,
1051 // 200
1052 CWENT_SS_W,
1053 CWENT_SS_S,
1054 CWENT_SS_MOVING_E,
1055 CWENT_SS_MOVING_N,
1056 CWENT_SS_MOVING_W,
1057 CWENT_SS_MOVING_S,
1058 CWENT_UNKNOWN,
1059 CWENT_UNKNOWN,
1060 CWENT_UNKNOWN,
1061 CWENT_UNKNOWN,
1062 // 210
1063 CWENT_DOG_E,
1064 CWENT_DOG_N,
1065 CWENT_DOG_W,
1066 CWENT_DOG_S,
1067 CWENT_HANS,
1068 CWENT_OTTO,
1069 CWENT_MUTANT_E,
1070 CWENT_MUTANT_N,
1071 CWENT_MUTANT_W,
1072 CWENT_MUTANT_S,
1073 // 220
1074 CWENT_MUTANT_MOVING_E,
1075 CWENT_MUTANT_MOVING_N,
1076 CWENT_MUTANT_MOVING_W,
1077 CWENT_MUTANT_MOVING_S,
1078 CWENT_PACMAN_GHOST_RED,
1079 CWENT_PACMAN_GHOST_YELLOW,
1080 CWENT_PACMAN_GHOST_ROSE,
1081 CWENT_PACMAN_GHOST_BLUE,
1082 CWENT_UNKNOWN,
1083 CWENT_UNKNOWN,
1084 // 230
1085 CWENT_UNKNOWN,
1086 CWENT_UNKNOWN,
1087 CWENT_UNKNOWN,
1088 CWENT_UNKNOWN,
1089 CWENT_MUTANT_E,
1090 CWENT_MUTANT_N,
1091 CWENT_MUTANT_W,
1092 CWENT_MUTANT_S,
1093 CWENT_MUTANT_MOVING_E,
1094 CWENT_MUTANT_MOVING_N,
1095 // 240
1096 CWENT_MUTANT_MOVING_W,
1097 CWENT_MUTANT_MOVING_S,
1098 CWENT_UNKNOWN,
1099 CWENT_UNKNOWN,
1100 CWENT_UNKNOWN,
1101 CWENT_UNKNOWN,
1102 CWENT_UNKNOWN,
1103 CWENT_UNKNOWN,
1104 CWENT_UNKNOWN,
1105 CWENT_UNKNOWN,
1106 // 250
1107 CWENT_UNKNOWN,
1108 CWENT_UNKNOWN,
1109 CWENT_MUTANT_E,
1110 CWENT_MUTANT_N,
1111 CWENT_MUTANT_W,
1112 CWENT_MUTANT_S,
1113 CWENT_MUTANT_MOVING_E,
1114 CWENT_MUTANT_MOVING_N,
1115 CWENT_MUTANT_MOVING_W,
1116 CWENT_MUTANT_MOVING_S,
1117 };
1118
1119 CWEntity CWChToEntity(const uint16_t ch)
1120 {
1121 if (ch < sizeof entityMap / sizeof entityMap[0])
1122 {
1123 return entityMap[ch];
1124 }
1125 return CWENT_UNKNOWN;
1126 }