From f9c92c892de6b8b08942eb64dfe32c29fddb538d Mon Sep 17 00:00:00 2001 From: Chris Taylor Date: Wed, 22 Jun 2005 09:22:16 +0000 Subject: [PATCH] add function for converting descent 2 texture numbers back to descent 1 texture numbers --- ChangeLog | 4 + main/editor/mine.c | 269 ++++++++++++++++++++++++++++++++++++++++++++- main/gamemine.c | 6 +- main/gamemine.h | 4 +- 4 files changed, 274 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index ed44c648..92ca1418 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,10 @@ main/wall.c, main/wall.h: add level component saving functions, which use PhysicsFS and are endian friendly + * main/editor/mine.c, main/gamemine.c, main/gamemine.h: + add function for converting descent 2 texture numbers back to + descent 1 texture numbers + 2005-06-14 Chris Taylor * main/mission.c: make sure there is a path to free for D2 Demo/OEM diff --git a/main/editor/mine.c b/main/editor/mine.c index d5d2f234..70e3f11e 100644 --- a/main/editor/mine.c +++ b/main/editor/mine.c @@ -1,4 +1,4 @@ -/* $Id: mine.c,v 1.7 2005-02-25 14:55:49 chris Exp $ */ +/* $Id: mine.c,v 1.8 2005-06-22 09:21:52 chris Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -19,7 +19,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ #ifdef RCS -static char rcsid[] = "$Id: mine.c,v 1.7 2005-02-25 14:55:49 chris Exp $"; +static char rcsid[] = "$Id: mine.c,v 1.8 2005-06-22 09:21:52 chris Exp $"; #endif #ifdef HAVE_CONFIG_H @@ -64,6 +64,269 @@ int save_mine_data_compiled_new(FILE * SaveFile); static char current_tmap_list[MAX_TEXTURES][13]; +int New_file_format_save = 1; + +// Converts descent 2 texture numbers back to descent 1 texture numbers. +// Only works properly when the full Descent 1 texture set (descent.pig) is available. +short convert_to_d1_tmap_num(short tmap_num) +{ + switch (tmap_num) + { + case 137: return 0; // grey rock001 + case 0: return 1; + case 1: return 3; // rock021 + case 270: return 6; // blue rock002 + case 271: return 7; // yellow rock265 + case 2: return 8; // rock004 + case 138: return 9; // purple (devil:179) + case 272: return 10; // red rock006 + case 139: return 11; + case 140: return 12; //devil:43 + case 3: return 13; // rock014 + case 4: return 14; // rock019 + case 5: return 15; // rock020 + case 6: return 16; + case 141: return 17; + case 129: return 18; + case 7: return 19; + case 142: return 20; + case 143: return 21; + case 8: return 22; + case 9: return 23; + case 10: return 24; + case 144: return 25; //devil:35 + case 11: return 26; + case 12: return 27; + case 145: return 28; //devil:43 + //range handled by default case, returns 13..21 (- 16) + case 163: return 38; //devil:27 + case 147: return 39; //31 + case 22: return 40; + case 266: return 41; + case 23: return 42; + case 24: return 43; + case 136: return 44; //devil:135 + case 25: return 45; + case 26: return 46; + case 27: return 47; + case 28: return 48; + case 146: return 49; //devil:60 + case 131: return 50; //devil:138 + case 29: return 51; + case 30: return 52; + case 31: return 53; + case 32: return 54; + case 165: return 55; //devil:193 + case 33: return 56; + case 132: return 57; //devil:119 + // range handled by default case, returns 58..88 (+ 24) + case 197: return 88; //devil:15 + // range handled by default case, returns 89..106 (- 25) + case 167: return 132; + // range handled by default case, returns 107..114 (- 26) + case 148: return 141; //devil:106 + case 115: return 142; + case 116: return 143; + case 117: return 144; + case 118: return 145; + case 119: return 146; + case 149: return 147; + case 120: return 148; + case 121: return 149; + case 122: return 150; + case 123: return 151; + case 124: return 152; + case 125: return 153; // rock263 + case 150: return 154; + case 126: return 155; // rock269 + case 200: return 156; // metl002 + case 201: return 157; // metl003 + case 186: return 158; //devil:227 + case 190: return 159; //devil:246 + case 151: return 160; + case 152: return 161; //devil:206 + case 202: return 162; + case 203: return 163; + case 204: return 164; + case 205: return 165; + case 206: return 166; + case 153: return 167; + case 154: return 168; + case 155: return 169; + case 156: return 170;//206; + case 157: return 171;//227; + case 207: return 172; + case 208: return 173; + case 158: return 174; + case 159: return 175; + // range handled by default case, returns 209..217 (+ 33) + case 160: return 185; + // range handled by default case, returns 218..224 (+ 32) + case 161: return 193; + case 162: return 194;//206; + case 166: return 195; + case 225: return 196; + case 226: return 197; + case 193: return 198; + case 168: return 199; //devil:204 + case 169: return 200; //devil:204 + case 227: return 201; + case 170: return 202; //devil:227 + // range handled by default case, returns 228..234 (+ 25) + case 171: return 210; //devil:242 + case 172: return 211; //devil:240 + // range handled by default case, returns 235..242 (+ 23) + case 173: return 220; //devil:240 + case 243: return 221; + case 244: return 222; + case 174: return 223; + case 245: return 224; + case 246: return 225; + case 164: return 226;//247; matching names but not matching textures + case 179: return 227; //devil:181 + case 196: return 228;//248; matching names but not matching textures + case 175: return 229; //devil:66 + case 176: return 230; //devil:66 + // range handled by default case, returns 249..257 (+ 18) + case 177: return 240; //devil:132 + case 130: return 241; //devil:131 + case 178: return 242; //devil:15 + case 180: return 243; //devil:38 + case 258: return 244; + case 259: return 245; + case 181: return 246; // grate metl127 + case 260: return 247; + case 261: return 248; + case 262: return 249; + case 340: return 250; // white doorframe metl126 + case 412: return 251; // red doorframe metl133 + case 410: return 252; // blue doorframe metl134 + case 411: return 253; // yellow doorframe metl135 + case 263: return 254; // metl136 + case 264: return 255; // metl139 + case 265: return 256; // metl140 + case 182: return 257;//246; brig001 + case 183: return 258;//246; brig002 + case 184: return 259;//246; brig003 + case 185: return 260;//246; brig004 + case 273: return 261; // exit01 + case 274: return 262; // exit02 + case 187: return 263; // ceil001 + case 275: return 264; // ceil002 + case 276: return 265; // ceil003 + case 188: return 266; //devil:291 + // range handled by default case, returns 277..291 (+ 10) + case 293: return 282; + case 189: return 283; + case 295: return 284; + case 296: return 285; + case 298: return 286; + // range handled by default case, returns 300..310 (+ 13) + case 191: return 298; // devil:374 misc010 + // range handled by default case, returns 311..326 (+ 12) + case 192: return 315; // bad producer misc044 + // range handled by default case, returns 327..337 (+ 11) + case 352: return 327; // arw01 + case 353: return 328; // misc17 + case 354: return 329; // fan01 + case 380: return 330; // mntr04 + case 379: return 331;//373; matching names but not matching textures + case 355: return 332;//344; matching names but not matching textures + case 409: return 333; // lava misc11 //devil:404 + case 356: return 334; // ctrl04 + case 357: return 335; // ctrl01 + case 358: return 336; // ctrl02 + case 359: return 337; // ctrl03 + case 360: return 338; // misc14 + case 361: return 339; // producer misc16 + case 362: return 340; // misc049 + case 364: return 341; // misc060 + case 363: return 342; // blown01 + case 366: return 343; // misc061 + case 365: return 344; + case 368: return 345; + case 376: return 346; + case 370: return 347; + case 367: return 348; + case 372: return 349; + case 369: return 350; + case 374: return 351;//429; matching names but not matching textures + case 375: return 352;//387; matching names but not matching textures + case 371: return 353; + case 377: return 354;//425; matching names but not matching textures + case 408: return 355; + case 378: return 356; // lava02 + case 383: return 357;//384; matching names but not matching textures + case 384: return 358;//385; matching names but not matching textures + case 385: return 359;//386; matching names but not matching textures + case 386: return 360; + case 387: return 361; + case 194: return 362; // mntr04b (devil: -1) + case 388: return 363; + case 391: return 364; + case 392: return 365; + case 393: return 366; + case 394: return 367; + case 395: return 368; + case 396: return 369; + case 195: return 370; // mntr04d (devil: -1) + // range 371..584 handled by default case (wall01 and door frames) + default: + // ranges: + if (tmap_num >= 13 && tmap_num <= 21) + return tmap_num + 16; + if (tmap_num >= 34 && tmap_num <= 63) + return tmap_num + 24; + if (tmap_num >= 64 && tmap_num <= 106) + return tmap_num + 25; + if (tmap_num >= 107 && tmap_num <= 114) + return tmap_num + 26; + if (tmap_num >= 209 && tmap_num <= 217) + return tmap_num - 33; + if (tmap_num >= 218 && tmap_num <= 224) + return tmap_num - 32; + if (tmap_num >= 228 && tmap_num <= 234) + return tmap_num - 25; + if (tmap_num >= 235 && tmap_num <= 242) + return tmap_num - 23; + if (tmap_num >= 249 && tmap_num <= 257) + return tmap_num - 18; + if (tmap_num >= 277 && tmap_num <= 291) + return tmap_num - 10; + if (tmap_num >= 300 && tmap_num <= 310) + return tmap_num - 13; + if (tmap_num >= 311 && tmap_num <= 326) + return tmap_num - 12; + if (tmap_num >= 327 && tmap_num <= 337) + return tmap_num - 11; // matching names but not matching textures + // wall01 and door frames: + if (tmap_num > 434 && tmap_num < 731) + { + if (New_file_format_save) return tmap_num - 64; + // d1 shareware needs special treatment: + if (tmap_num < 478) return tmap_num - 68; + if (tmap_num < 490) return tmap_num - 73; + if (tmap_num < 537) return tmap_num - 91; + if (tmap_num < 557) return tmap_num - 104; + if (tmap_num < 573) return tmap_num - 111; + if (tmap_num < 603) return tmap_num - 117; + if (tmap_num < 635) return tmap_num - 141; + if (tmap_num < 731) return tmap_num - 147; + } + { // handle rare case where orientation != 0 + short tmap_num_part = tmap_num & TMAP_NUM_MASK; + short orient = tmap_num & ~TMAP_NUM_MASK; + if (orient != 0) + return orient | convert_to_d1_tmap_num(tmap_num_part); + else + { + Warning("can't convert unknown texture #%d to descent 1.\n", tmap_num_part); + return tmap_num; + } + } + } +} + // ----------------------------------------------------------------------------- // Save mine will: // 1. Write file info, header info, editor info, vertex data, segment data, @@ -274,8 +537,6 @@ void dump_fix_as_ushort( fix value, int nbits, CFILE * SaveFile ) cfwrite( &short_value, sizeof(short_value), 1, SaveFile ); } -int New_file_format_save = 1; - // ----------------------------------------------------------------------------- // saves compiled mine data to an already-open file... int save_mine_data_compiled(FILE * SaveFile) diff --git a/main/gamemine.c b/main/gamemine.c index 242900e8..a123edd1 100644 --- a/main/gamemine.c +++ b/main/gamemine.c @@ -1,4 +1,4 @@ -/* $Id: gamemine.c,v 1.33 2005-06-13 03:05:45 chris Exp $ */ +/* $Id: gamemine.c,v 1.34 2005-06-22 09:21:52 chris Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -23,7 +23,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -static char rcsid[] = "$Id: gamemine.c,v 1.33 2005-06-13 03:05:45 chris Exp $"; +static char rcsid[] = "$Id: gamemine.c,v 1.34 2005-06-22 09:21:52 chris Exp $"; #endif #include @@ -182,8 +182,6 @@ int d1_tmap_num_unique(short d1_tmap_num) { } } -#define TMAP_NUM_MASK 0x3FFF - /* Converts descent 1 texture numbers to descent 2 texture numbers. * Textures from d1 which are unique to d1 have extra spaces around "return". * If we can load the original d1 pig, we make sure this function is bijective. diff --git a/main/gamemine.h b/main/gamemine.h index 4ec90ba1..4506a5a1 100644 --- a/main/gamemine.h +++ b/main/gamemine.h @@ -1,4 +1,4 @@ -/* $Id: gamemine.h,v 1.9 2004-12-20 06:34:42 btb Exp $ */ +/* $Id: gamemine.h,v 1.10 2005-06-22 09:21:52 chris Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -127,6 +127,8 @@ extern fix Level_shake_frequency, Level_shake_duration; extern int Secret_return_segment; extern vms_matrix Secret_return_orient; +#define TMAP_NUM_MASK 0x3FFF + /* stuff for loading descent.pig of descent 1 */ extern short convert_d1_tmap_num(short d1_tmap_num); extern int d1_tmap_num_unique(short d1_tmap_num); //is d1_tmap_num's texture only in d1? -- 2.39.2