| 1 |
/* |
| 2 |
* Portions of this file are copyright Rebirth contributors and licensed as |
| 3 |
* described in COPYING.txt. |
| 4 |
* Portions of this file are copyright Parallax Software and licensed |
| 5 |
* according to the Parallax license below. |
| 6 |
* See COPYING.txt for license details. |
| 7 |
|
| 8 |
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
| 9 |
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
| 10 |
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
| 11 |
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
| 12 |
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
| 13 |
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
| 14 |
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
| 15 |
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
| 16 |
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
| 17 |
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
| 18 |
*/ |
| 19 |
|
| 20 |
/* |
| 21 |
* |
| 22 |
* Functions to dump text description of mine. |
| 23 |
* An editor-only function, called at mine load time. |
| 24 |
* To be read by a human to verify the correctness and completeness of a mine. |
| 25 |
* |
| 26 |
*/ |
| 27 |
|
| 28 |
#include <bitset> |
| 29 |
#include <stdio.h> |
| 30 |
#include <cinttypes> |
| 31 |
#include <string.h> |
| 32 |
#include <stdarg.h> |
| 33 |
#include <ranges> |
| 34 |
#include <errno.h> |
| 35 |
|
| 36 |
#include "pstypes.h" |
| 37 |
#include "console.h" |
| 38 |
#include "physfsx.h" |
| 39 |
#include "gr.h" |
| 40 |
#include "palette.h" |
| 41 |
#include "fmtcheck.h" |
| 42 |
|
| 43 |
#include "inferno.h" |
| 44 |
#include "dxxerror.h" |
| 45 |
#include "object.h" |
| 46 |
#include "wall.h" |
| 47 |
#include "gameseg.h" |
| 48 |
#include "robot.h" |
| 49 |
#include "newmenu.h" |
| 50 |
#include "textures.h" |
| 51 |
#include "text.h" |
| 52 |
#include "bm.h" |
| 53 |
#include "switch.h" |
| 54 |
#include "fuelcen.h" |
| 55 |
#include "powerup.h" |
| 56 |
#include "polyobj.h" |
| 57 |
#include "gamesave.h" |
| 58 |
#include "piggy.h" |
| 59 |
|
| 60 |
#include "compiler-range_for.h" |
| 61 |
#include "d_enumerate.h" |
| 62 |
#include "d_levelstate.h" |
| 63 |
#include "d_underlying_value.h" |
| 64 |
#include "d_zip.h" |
| 65 |
#include "segiter.h" |
| 66 |
|
| 67 |
#if DXX_USE_EDITOR |
| 68 |
|
| 69 |
namespace dsx { |
| 70 |
namespace { |
| 71 |
#if DXX_BUILD_DESCENT == 1 |
| 72 |
using perm_tmap_buffer_type = enumerated_array<int, MAX_TEXTURES, bitmap_index>; |
| 73 |
using level_tmap_buffer_type = enumerated_array<int8_t, MAX_TEXTURES, bitmap_index>; |
| 74 |
using wall_buffer_type = std::array<int, MAX_WALL_ANIMS>; |
| 75 |
#elif DXX_BUILD_DESCENT == 2 |
| 76 |
using perm_tmap_buffer_type = enumerated_array<int, MAX_BITMAP_FILES, bitmap_index>; |
| 77 |
using level_tmap_buffer_type = enumerated_array<int8_t, MAX_BITMAP_FILES, bitmap_index>; |
| 78 |
using wall_buffer_type = std::array<int, MAX_BITMAP_FILES>; |
| 79 |
#endif |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
namespace dcx { |
| 84 |
const std::array<char[10], 7> Wall_names{{ |
| 85 |
"NORMAL ", |
| 86 |
"BLASTABLE", |
| 87 |
"DOOR ", |
| 88 |
"ILLUSION ", |
| 89 |
"OPEN ", |
| 90 |
"CLOSED ", |
| 91 |
"EXTERNAL " |
| 92 |
}}; |
| 93 |
} |
| 94 |
|
| 95 |
namespace { |
| 96 |
static void dump_used_textures_level(PHYSFS_File *my_file, int level_num, const char *Gamesave_current_filename); |
| 97 |
static void say_totals(fvcobjptridx &vcobjptridx, PHYSFS_File *my_file, const char *level_name); |
| 98 |
} |
| 99 |
|
| 100 |
namespace dsx { |
| 101 |
namespace { |
| 102 |
const std::array<char[9], MAX_OBJECT_TYPES> Object_type_names{{ |
| 103 |
"WALL ", |
| 104 |
"FIREBALL", |
| 105 |
"ROBOT ", |
| 106 |
"HOSTAGE ", |
| 107 |
"PLAYER ", |
| 108 |
"WEAPON ", |
| 109 |
"CAMERA ", |
| 110 |
"POWERUP ", |
| 111 |
"DEBRIS ", |
| 112 |
"CNTRLCEN", |
| 113 |
"FLARE ", |
| 114 |
"CLUTTER ", |
| 115 |
"GHOST ", |
| 116 |
"LIGHT ", |
| 117 |
"COOP ", |
| 118 |
#if DXX_BUILD_DESCENT == 2 |
| 119 |
"MARKER ", |
| 120 |
#endif |
| 121 |
}}; |
| 122 |
|
| 123 |
// ---------------------------------------------------------------------------- |
| 124 |
static const char *object_types(const object_base &objp) |
| 125 |
{ |
| 126 |
const auto type{objp.type}; |
| 127 |
assert(type == OBJ_NONE || type < MAX_OBJECT_TYPES); |
| 128 |
return &Object_type_names[type][0]; |
| 129 |
} |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
namespace { |
| 134 |
|
| 135 |
// ---------------------------------------------------------------------------- |
| 136 |
static const char *object_ids(const object_base &objp) |
| 137 |
{ |
| 138 |
switch (objp.type) |
| 139 |
{ |
| 140 |
case OBJ_ROBOT: |
| 141 |
return Robot_names[get_robot_id(objp)].data(); |
| 142 |
case OBJ_POWERUP: |
| 143 |
return Powerup_names[get_powerup_id(objp)].data(); |
| 144 |
default: |
| 145 |
return nullptr; |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
static void err_puts(PHYSFS_File *f, const std::span<const char> str) |
| 150 |
{ |
| 151 |
++Errors_in_mine; |
| 152 |
con_puts(CON_CRITICAL, str); |
| 153 |
PHYSFSX_puts(f, str); |
| 154 |
} |
| 155 |
|
| 156 |
template <std::size_t len> |
| 157 |
static void err_puts_literal(PHYSFS_File *f, const char (&str)[len]) |
| 158 |
{ |
| 159 |
err_puts(f, {str, len - 1}); |
| 160 |
} |
| 161 |
|
| 162 |
void err_printf(PHYSFS_File *my_file, const char * format) = delete; |
| 163 |
|
| 164 |
dxx_compiler_attribute_format_printf(2, 3) |
| 165 |
static void err_printf(PHYSFS_File *my_file, const char * format, ... ) |
| 166 |
{ |
| 167 |
va_list args; |
| 168 |
char message[256]; |
| 169 |
|
| 170 |
va_start(args, format ); |
| 171 |
const std::size_t len = std::max(vsnprintf(message, sizeof(message), format, args), 0); |
| 172 |
va_end(args); |
| 173 |
err_puts(my_file, {message, len}); |
| 174 |
} |
| 175 |
|
| 176 |
static void warning_puts(PHYSFS_File *f, const std::span<const char> str) |
| 177 |
{ |
| 178 |
con_puts(CON_URGENT, str); |
| 179 |
PHYSFSX_puts(f, str); |
| 180 |
} |
| 181 |
|
| 182 |
void warning_printf(PHYSFS_File *my_file, const char *format) = delete; |
| 183 |
|
| 184 |
static void warning_printf(PHYSFS_File *my_file, const char * format, ... ) dxx_compiler_attribute_format_printf(2, 3); |
| 185 |
static void warning_printf(PHYSFS_File *my_file, const char * format, ... ) |
| 186 |
{ |
| 187 |
va_list args; |
| 188 |
char message[256]; |
| 189 |
|
| 190 |
va_start(args, format ); |
| 191 |
const std::size_t written = std::max(vsnprintf(message, sizeof(message), format, args), 0); |
| 192 |
va_end(args); |
| 193 |
warning_puts(my_file, {message, written}); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
// ---------------------------------------------------------------------------- |
| 198 |
namespace dsx { |
| 199 |
namespace { |
| 200 |
static void write_exit_text(fvcsegptridx &vcsegptridx, fvcwallptridx &vcwallptridx, PHYSFS_File *my_file) |
| 201 |
{ |
| 202 |
int count; |
| 203 |
|
| 204 |
PHYSFSX_puts_literal(my_file, "-----------------------------------------------------------------------------\n"); |
| 205 |
PHYSFSX_puts_literal(my_file, "Exit stuff\n"); |
| 206 |
|
| 207 |
// ---------- Find exit triggers ---------- |
| 208 |
count=0; |
| 209 |
auto &Triggers = LevelUniqueWallSubsystemState.Triggers; |
| 210 |
auto &vctrgptridx = Triggers.vcptridx; |
| 211 |
range_for (const auto &&t, vctrgptridx) |
| 212 |
{ |
| 213 |
if (trigger_is_exit(t)) |
| 214 |
{ |
| 215 |
int count2; |
| 216 |
|
| 217 |
const auto i = t.get_unchecked_index(); |
| 218 |
PHYSFSX_printf(my_file, "Trigger %2i, is an exit trigger with %i links.\n", underlying_value(i), t->num_links); |
| 219 |
count++; |
| 220 |
if (t->num_links != 0) |
| 221 |
err_printf(my_file, "Error: Exit triggers must have 0 links, this one has %i links.", t->num_links); |
| 222 |
|
| 223 |
// Find wall pointing to this trigger. |
| 224 |
count2 = 0; |
| 225 |
range_for (const auto &&w, vcwallptridx) |
| 226 |
{ |
| 227 |
if (w->trigger == i) |
| 228 |
{ |
| 229 |
count2++; |
| 230 |
PHYSFSX_printf(my_file, "Exit trigger %i is in segment %i, on side %i, bound to wall %hu\n", underlying_value(i), w->segnum, underlying_value(w->sidenum), underlying_value(wallnum_t{w})); |
| 231 |
} |
| 232 |
} |
| 233 |
if (count2 == 0) |
| 234 |
err_printf(my_file, "Error: Trigger %i is not bound to any wall.", underlying_value(i)); |
| 235 |
else if (count2 > 1) |
| 236 |
err_printf(my_file, "Error: Trigger %i is bound to %i walls.", underlying_value(i), count2); |
| 237 |
|
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
if (count == 0) |
| 242 |
err_puts_literal(my_file, "Error: No exit trigger in this mine."); |
| 243 |
else if (count != 1) |
| 244 |
err_puts_literal(my_file, "Error: More than one exit trigger in this mine."); |
| 245 |
else |
| 246 |
PHYSFSX_puts_literal(my_file, "\n"); |
| 247 |
|
| 248 |
// ---------- Find exit doors ---------- |
| 249 |
count = 0; |
| 250 |
range_for (const auto &&segp, vcsegptridx) |
| 251 |
{ |
| 252 |
for (const auto &&[sidenum, child_segnum] : enumerate(segp->shared_segment::children)) |
| 253 |
{ |
| 254 |
if (child_segnum == segment_exit) |
| 255 |
{ |
| 256 |
PHYSFSX_printf(my_file, "Segment %3hu, side %u is an exit door.\n", segp.get_unchecked_index(), underlying_value(sidenum)); |
| 257 |
count++; |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
if (count == 0) |
| 263 |
err_puts_literal(my_file, "Error: No external wall in this mine."); |
| 264 |
else if (count != 1) { |
| 265 |
#if DXX_BUILD_DESCENT == 1 |
| 266 |
warning_printf(my_file, "Warning: %i external walls in this mine.", count); |
| 267 |
warning_printf(my_file, "(If %i are secret exits, then no problem.)", count-1); |
| 268 |
#endif |
| 269 |
} else |
| 270 |
PHYSFSX_puts_literal(my_file, "\n"); |
| 271 |
} |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
namespace { |
| 276 |
|
| 277 |
class key_stat |
| 278 |
{ |
| 279 |
const char *const label; |
| 280 |
unsigned wall_count{0}, powerup_count = 0; |
| 281 |
segnum_t seg = segment_none; |
| 282 |
sidenum_t side{}; |
| 283 |
public: |
| 284 |
key_stat(const char *const p) : |
| 285 |
label(p) |
| 286 |
{ |
| 287 |
} |
| 288 |
void check_wall(const segment_array &segments, PHYSFS_File *const fp, const vcwallptridx_t wpi, const wall_key key) |
| 289 |
{ |
| 290 |
auto &w = *wpi; |
| 291 |
if (!(w.keys & key)) |
| 292 |
return; |
| 293 |
PHYSFSX_printf(fp, "Wall %hu (seg=%i, side=%i) is keyed to the %s key.\n", underlying_value(wallnum_t{wpi}), w.segnum, underlying_value(w.sidenum), label); |
| 294 |
if (seg == segment_none) |
| 295 |
{ |
| 296 |
seg = w.segnum; |
| 297 |
side = w.sidenum; |
| 298 |
} |
| 299 |
else |
| 300 |
{ |
| 301 |
const auto &&connect_side = find_connect_side(segments.vcptridx(w.segnum), segments.vcptr(seg)); |
| 302 |
if (connect_side == side) |
| 303 |
return; |
| 304 |
warning_printf(fp, "Warning: This door at seg %i, is different than the one at seg %i, side %i", w.segnum, seg, underlying_value(side)); |
| 305 |
} |
| 306 |
++wall_count; |
| 307 |
} |
| 308 |
void report_walls(PHYSFS_File *const fp) const |
| 309 |
{ |
| 310 |
if (wall_count > 1) |
| 311 |
warning_printf(fp, "Warning: %i doors are keyed to the %s key.", wall_count, label); |
| 312 |
} |
| 313 |
void found_powerup(const unsigned amount = 1) |
| 314 |
{ |
| 315 |
powerup_count += amount; |
| 316 |
} |
| 317 |
void report_keys(PHYSFS_File *const fp) const |
| 318 |
{ |
| 319 |
if (!powerup_count) |
| 320 |
{ |
| 321 |
if (wall_count) |
| 322 |
err_printf(fp, "Error: There is a door keyed to the %s key, but no %s key!", label, label); |
| 323 |
} |
| 324 |
else if (powerup_count > 1) |
| 325 |
err_printf(fp, "Error: There are %i %s keys!", powerup_count, label); |
| 326 |
} |
| 327 |
}; |
| 328 |
|
| 329 |
// ---------------------------------------------------------------------------- |
| 330 |
static void write_key_text(fvcobjptridx &vcobjptridx, segment_array &segments, fvcwallptridx &vcwallptridx, PHYSFS_File *my_file) |
| 331 |
{ |
| 332 |
PHYSFSX_puts_literal(my_file, "-----------------------------------------------------------------------------\n"); |
| 333 |
PHYSFSX_puts_literal(my_file, "Key stuff:\n"); |
| 334 |
|
| 335 |
key_stat blue("blue"), gold("gold"), red("red"); |
| 336 |
|
| 337 |
range_for (const auto &&w, vcwallptridx) |
| 338 |
{ |
| 339 |
blue.check_wall(segments, my_file, w, wall_key::blue); |
| 340 |
gold.check_wall(segments, my_file, w, wall_key::gold); |
| 341 |
red.check_wall(segments, my_file, w, wall_key::red); |
| 342 |
} |
| 343 |
|
| 344 |
blue.report_walls(my_file); |
| 345 |
gold.report_walls(my_file); |
| 346 |
red.report_walls(my_file); |
| 347 |
|
| 348 |
range_for (const auto &&objp, vcobjptridx) |
| 349 |
{ |
| 350 |
if (objp->type == OBJ_POWERUP) |
| 351 |
{ |
| 352 |
const char *color; |
| 353 |
const auto id = get_powerup_id(objp); |
| 354 |
if ( |
| 355 |
(id == powerup_type_t::POW_KEY_BLUE && (blue.found_powerup(), color = "BLUE", true)) || |
| 356 |
(id == powerup_type_t::POW_KEY_RED && (red.found_powerup(), color = "RED", true)) || |
| 357 |
(id == powerup_type_t::POW_KEY_GOLD && (gold.found_powerup(), color = "GOLD", true)) |
| 358 |
) |
| 359 |
{ |
| 360 |
PHYSFSX_printf(my_file, "The %s key is object %hu in segment %i\n", color, static_cast<objnum_t>(objp), objp->segnum); |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
if (const auto contains_count = objp->contains.count) |
| 365 |
{ |
| 366 |
if (objp->contains.type == contained_object_type::powerup) |
| 367 |
{ |
| 368 |
const char *color; |
| 369 |
const auto id = objp->contains.id.powerup; |
| 370 |
if ( |
| 371 |
(id == powerup_type_t::POW_KEY_BLUE && (blue.found_powerup(contains_count), color = "BLUE", true)) || |
| 372 |
(id == powerup_type_t::POW_KEY_RED && (red.found_powerup(contains_count), color = "RED", true)) || |
| 373 |
(id == powerup_type_t::POW_KEY_GOLD && (gold.found_powerup(contains_count), color = "GOLD", true)) |
| 374 |
) |
| 375 |
PHYSFSX_printf(my_file, "The %s key is contained in object %hu (a %s %s) in segment %hu\n", color, static_cast<objnum_t>(objp), object_types(objp), Robot_names[get_robot_id(objp)].data(), objp->segnum); |
| 376 |
} |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
blue.report_keys(my_file); |
| 381 |
gold.report_keys(my_file); |
| 382 |
red.report_keys(my_file); |
| 383 |
} |
| 384 |
|
| 385 |
// ---------------------------------------------------------------------------- |
| 386 |
static void write_control_center_text(fvcsegptridx &vcsegptridx, PHYSFS_File *my_file) |
| 387 |
{ |
| 388 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 389 |
auto &vcobjptridx = Objects.vcptridx; |
| 390 |
int count, count2; |
| 391 |
|
| 392 |
PHYSFSX_puts_literal(my_file, "-----------------------------------------------------------------------------\n"); |
| 393 |
PHYSFSX_puts_literal(my_file, "Control Center stuff:\n"); |
| 394 |
|
| 395 |
count = 0; |
| 396 |
range_for (const auto &&segp, vcsegptridx) |
| 397 |
{ |
| 398 |
if (segp->special == segment_special::controlcen) |
| 399 |
{ |
| 400 |
count++; |
| 401 |
PHYSFSX_printf(my_file, "Segment %3hu is a control center.\n", static_cast<uint16_t>(segp)); |
| 402 |
count2 = 0; |
| 403 |
for (auto &objp : objects_in<const object_base>(segp, vcobjptridx, vcsegptr)) |
| 404 |
{ |
| 405 |
if (objp.type == OBJ_CNTRLCEN) |
| 406 |
count2++; |
| 407 |
} |
| 408 |
if (count2 == 0) |
| 409 |
PHYSFSX_puts_literal(my_file, "No control center object in control center segment.\n"); |
| 410 |
else if (count2 != 1) |
| 411 |
PHYSFSX_printf(my_file, "%i control center objects in control center segment.\n", count2); |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
if (count == 0) |
| 416 |
err_puts_literal(my_file, "Error: No control center in this mine."); |
| 417 |
else if (count != 1) |
| 418 |
err_puts_literal(my_file, "Error: More than one control center in this mine."); |
| 419 |
} |
| 420 |
|
| 421 |
// ---------------------------------------------------------------------------- |
| 422 |
static void write_fuelcen_text(PHYSFS_File *my_file) |
| 423 |
{ |
| 424 |
auto &Station = LevelUniqueFuelcenterState.Station; |
| 425 |
|
| 426 |
PHYSFSX_puts_literal(my_file, "-----------------------------------------------------------------------------\n"); |
| 427 |
PHYSFSX_puts_literal(my_file, "Fuel Center stuff: (Note: This means fuel, repair, materialize, control centers!)\n"); |
| 428 |
|
| 429 |
const auto Num_fuelcenters = LevelUniqueFuelcenterState.Num_fuelcenters; |
| 430 |
for (auto &&[i, f] : enumerate(partial_const_range(Station, Num_fuelcenters))) |
| 431 |
{ |
| 432 |
PHYSFSX_printf(my_file, "Fuelcenter %u: Type=%i (%s), segment = %3i\n", underlying_value(i), underlying_value(f.Type), Special_names[f.Type], f.segnum); |
| 433 |
if (Segments[f.segnum].special != f.Type) |
| 434 |
err_printf(my_file, "Error: Conflicting data: Segment %i has special type %i (%s), expected to be %i", f.segnum, underlying_value(Segments[f.segnum].special), Special_names[Segments[f.segnum].special], underlying_value(f.Type)); |
| 435 |
} |
| 436 |
} |
| 437 |
|
| 438 |
// ---------------------------------------------------------------------------- |
| 439 |
static void write_segment_text(fvcsegptridx &vcsegptridx, PHYSFS_File *my_file) |
| 440 |
{ |
| 441 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 442 |
auto &vcobjptridx = Objects.vcptridx; |
| 443 |
PHYSFSX_puts_literal(my_file, "-----------------------------------------------------------------------------\n"); |
| 444 |
PHYSFSX_puts_literal(my_file, "Segment stuff:\n"); |
| 445 |
|
| 446 |
range_for (const auto &&segp, vcsegptridx) |
| 447 |
{ |
| 448 |
PHYSFSX_printf(my_file, "Segment %4hu:", static_cast<uint16_t>(segp)); |
| 449 |
if (segp->special != segment_special::nothing) |
| 450 |
PHYSFSX_printf(my_file, " special = %3i (%s), station_idx=%3u", underlying_value(segp->special), Special_names[segp->special], underlying_value(segp->station_idx)); |
| 451 |
if (segp->matcen_num != materialization_center_number::None) |
| 452 |
PHYSFSX_printf(my_file, " matcen = %3i", underlying_value(segp->matcen_num)); |
| 453 |
PHYSFSX_puts_literal(my_file, "\n"); |
| 454 |
} |
| 455 |
|
| 456 |
range_for (const auto &&segp, vcsegptridx) |
| 457 |
{ |
| 458 |
int depth; |
| 459 |
|
| 460 |
PHYSFSX_printf(my_file, "Segment %4hu: ", static_cast<uint16_t>(segp)); |
| 461 |
depth=0; |
| 462 |
PHYSFSX_puts_literal(my_file, "Objects: "); |
| 463 |
range_for (const auto objp, objects_in(segp, vcobjptridx, vcsegptr)) |
| 464 |
{ |
| 465 |
short objnum = objp; |
| 466 |
PHYSFSX_printf(my_file, "[%8s %8s %3i] ", object_types(objp), object_ids(objp), objnum); |
| 467 |
if (depth++ > 30) { |
| 468 |
PHYSFSX_printf(my_file, "\nAborted after %i links\n", depth); |
| 469 |
break; |
| 470 |
} |
| 471 |
} |
| 472 |
PHYSFSX_puts_literal(my_file, "\n"); |
| 473 |
} |
| 474 |
} |
| 475 |
|
| 476 |
// ---------------------------------------------------------------------------- |
| 477 |
static void write_matcen_text(PHYSFS_File *my_file) |
| 478 |
{ |
| 479 |
PHYSFSX_puts_literal(my_file, "-----------------------------------------------------------------------------\n"); |
| 480 |
PHYSFSX_puts_literal(my_file, "Materialization centers:\n"); |
| 481 |
auto &RobotCenters = LevelSharedRobotcenterState.RobotCenters; |
| 482 |
auto &Station = LevelUniqueFuelcenterState.Station; |
| 483 |
auto &Triggers = LevelUniqueWallSubsystemState.Triggers; |
| 484 |
auto &vctrgptridx = Triggers.vcptridx; |
| 485 |
const auto Num_robot_centers = LevelSharedRobotcenterState.Num_robot_centers; |
| 486 |
for (auto &&[i, robotcen] : enumerate(partial_const_range(RobotCenters, Num_robot_centers))) |
| 487 |
{ |
| 488 |
const auto fuelcen_num = robotcen.fuelcen_num; |
| 489 |
auto &station = Station[fuelcen_num]; |
| 490 |
if (station.Type != segment_special::robotmaker) |
| 491 |
{ |
| 492 |
err_printf(my_file, "Error: Matcen %u corresponds to Station %u, which has type %i (%s).", underlying_value(i), underlying_value(fuelcen_num), underlying_value(station.Type), Special_names[station.Type]); |
| 493 |
continue; |
| 494 |
} |
| 495 |
int trigger_count{0}; |
| 496 |
|
| 497 |
const auto segnum{station.segnum}; |
| 498 |
PHYSFSX_printf(my_file, "FuelCenter[%02i].Segment = %04i ", underlying_value(i), segnum); |
| 499 |
PHYSFSX_printf(my_file, "Segment[%04i].matcen_num = %02i ", segnum, underlying_value(Segments[segnum].matcen_num)); |
| 500 |
|
| 501 |
// Find trigger for this materialization center. |
| 502 |
range_for (auto &&t, vctrgptridx) |
| 503 |
{ |
| 504 |
if (trigger_is_matcen(t)) |
| 505 |
{ |
| 506 |
range_for (auto &k, partial_const_range(t->seg, t->num_links)) |
| 507 |
if (k == segnum) |
| 508 |
{ |
| 509 |
PHYSFSX_printf(my_file, "Trigger = %2i ", underlying_value(t.get_unchecked_index())); |
| 510 |
trigger_count++; |
| 511 |
} |
| 512 |
} |
| 513 |
} |
| 514 |
PHYSFSX_puts_literal(my_file, "\n"); |
| 515 |
|
| 516 |
if (trigger_count == 0) |
| 517 |
err_printf(my_file, "Error: Matcen %i in segment %i has no trigger!", underlying_value(i), segnum); |
| 518 |
} |
| 519 |
} |
| 520 |
|
| 521 |
} |
| 522 |
|
| 523 |
// ---------------------------------------------------------------------------- |
| 524 |
namespace dsx { |
| 525 |
namespace { |
| 526 |
static void write_wall_text(fvcsegptridx &vcsegptridx, fvcwallptridx &vcwallptridx, PHYSFS_File *my_file) |
| 527 |
{ |
| 528 |
enumerated_array<int8_t, MAX_WALLS, wallnum_t> wall_flags; |
| 529 |
|
| 530 |
PHYSFSX_puts_literal(my_file, "-----------------------------------------------------------------------------\n"); |
| 531 |
PHYSFSX_puts_literal(my_file, "Walls:\n"); |
| 532 |
#if DXX_BUILD_DESCENT == 2 |
| 533 |
auto &Triggers = LevelUniqueWallSubsystemState.Triggers; |
| 534 |
#endif |
| 535 |
range_for (auto &&wp, vcwallptridx) |
| 536 |
{ |
| 537 |
auto &w = *wp; |
| 538 |
const auto i = underlying_value(wallnum_t{wp}); |
| 539 |
PHYSFSX_printf(my_file, "Wall %03hu: seg=%3i, side=%2i, linked_wall=%3hu, type=%s, flags=%4x, hps=%3i, trigger=%2i, clip_num=%2i, keys=%2i, state=%i\n", i, w.segnum, underlying_value(w.sidenum), underlying_value(wallnum_t{w.linked_wall}), Wall_names[w.type], underlying_value(w.flags), w.hps >> 16, underlying_value(w.trigger), w.clip_num, underlying_value(w.keys), underlying_value(w.state)); |
| 540 |
|
| 541 |
#if DXX_BUILD_DESCENT == 2 |
| 542 |
if (const auto utw = underlying_value(w.trigger); utw >= Triggers.get_count()) |
| 543 |
PHYSFSX_printf(my_file, "Wall %03hu points to invalid trigger %u\n", i, utw); |
| 544 |
#endif |
| 545 |
|
| 546 |
auto segnum = w.segnum; |
| 547 |
const auto sidenum{w.sidenum}; |
| 548 |
|
| 549 |
if (const auto actual_wall_num = Segments[segnum].shared_segment::sides[sidenum].wall_num; actual_wall_num != wp) |
| 550 |
err_printf(my_file, "Error: Wall %hu points at segment %i, side %i, but that segment doesn't point back (it's wall_num = %hi)", i, segnum, underlying_value(sidenum), underlying_value(actual_wall_num)); |
| 551 |
} |
| 552 |
|
| 553 |
wall_flags = {}; |
| 554 |
|
| 555 |
range_for (const auto &&segp, vcsegptridx) |
| 556 |
{ |
| 557 |
for (const auto &&[idx, value] : enumerate(segp->shared_segment::sides)) |
| 558 |
{ |
| 559 |
const auto sidep = &value; |
| 560 |
if (sidep->wall_num != wall_none) |
| 561 |
{ |
| 562 |
if (auto &wf = wall_flags[sidep->wall_num]) |
| 563 |
err_printf(my_file, "Error: Wall %hu appears in two or more segments, including segment %hu, side %u.", underlying_value(sidep->wall_num), segp.get_unchecked_index(), underlying_value(idx)); |
| 564 |
else |
| 565 |
wf = 1; |
| 566 |
} |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
} |
| 571 |
|
| 572 |
// ---------------------------------------------------------------------------- |
| 573 |
static void write_player_text(fvcobjptridx &vcobjptridx, PHYSFS_File *my_file) |
| 574 |
{ |
| 575 |
int num_players{0}; |
| 576 |
|
| 577 |
PHYSFSX_puts_literal(my_file, "-----------------------------------------------------------------------------\n"); |
| 578 |
PHYSFSX_puts_literal(my_file, "Players:\n"); |
| 579 |
range_for (const auto &&objp, vcobjptridx) |
| 580 |
{ |
| 581 |
if (objp->type == OBJ_PLAYER) |
| 582 |
{ |
| 583 |
num_players++; |
| 584 |
PHYSFSX_printf(my_file, "Player %2i is object #%3hu in segment #%3i.\n", get_player_id(objp), static_cast<uint16_t>(objp), objp->segnum); |
| 585 |
} |
| 586 |
} |
| 587 |
|
| 588 |
#if DXX_BUILD_DESCENT == 2 |
| 589 |
if (num_players != MAX_PLAYERS) |
| 590 |
err_printf(my_file, "Error: %i player objects. %i are required.", num_players, MAX_PLAYERS); |
| 591 |
#endif |
| 592 |
if (num_players > MAX_MULTI_PLAYERS) |
| 593 |
err_printf(my_file, "Error: %i player objects. %i are required.", num_players, MAX_PLAYERS); |
| 594 |
} |
| 595 |
|
| 596 |
// ---------------------------------------------------------------------------- |
| 597 |
static void write_trigger_text(PHYSFS_File *my_file) |
| 598 |
{ |
| 599 |
PHYSFSX_puts_literal(my_file, "-----------------------------------------------------------------------------\n"); |
| 600 |
PHYSFSX_puts_literal(my_file, "Triggers:\n"); |
| 601 |
auto &Triggers = LevelUniqueWallSubsystemState.Triggers; |
| 602 |
auto &vctrgptridx = Triggers.vcptridx; |
| 603 |
auto &Walls = LevelUniqueWallSubsystemState.Walls; |
| 604 |
auto &vcwallptr = Walls.vcptr; |
| 605 |
for (auto &&t : vctrgptridx) |
| 606 |
{ |
| 607 |
const auto i = static_cast<trgnum_t>(t); |
| 608 |
#if DXX_BUILD_DESCENT == 1 |
| 609 |
PHYSFSX_printf(my_file, "Trigger %03i: flags=%04x, value=%08x, time=%8x, num_links=%i ", underlying_value(i), t->flags, static_cast<unsigned>(t->value), 0, t->num_links); |
| 610 |
#elif DXX_BUILD_DESCENT == 2 |
| 611 |
PHYSFSX_printf(my_file, "Trigger %03i: type=%02x flags=%04x, value=%08x, time=%8x, num_links=%i ", underlying_value(i), |
| 612 |
static_cast<uint8_t>(t->type), static_cast<uint8_t>(t->flags), t->value, 0, t->num_links); |
| 613 |
#endif |
| 614 |
|
| 615 |
for (const auto &&[seg, side] : zip(partial_range(t->seg, t->num_links), t->side)) |
| 616 |
PHYSFSX_printf(my_file, "[%03i:%i] ", seg, underlying_value(side)); |
| 617 |
|
| 618 |
// Find which wall this trigger is connected to. |
| 619 |
const auto &&we = vcwallptr.end(); |
| 620 |
const auto &&wi{std::ranges::find(vcwallptr.begin(), we, i, &wall::trigger)}; |
| 621 |
if (wi == we) |
| 622 |
err_printf(my_file, "Error: Trigger %i is not connected to any wall, so it can never be triggered.", underlying_value(i)); |
| 623 |
else |
| 624 |
{ |
| 625 |
auto &w{*wi}; |
| 626 |
const auto wseg{w.segnum}; |
| 627 |
const auto wside{w.sidenum}; |
| 628 |
PHYSFSX_printf(my_file, "Attached to seg:side = %i:%i, wall %hi\n", wseg, underlying_value(wside), underlying_value(vcsegptr(wseg)->shared_segment::sides[wside].wall_num)); |
| 629 |
} |
| 630 |
} |
| 631 |
} |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
// ---------------------------------------------------------------------------- |
| 636 |
void write_game_text_file(const char *filename) |
| 637 |
{ |
| 638 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 639 |
auto &vcobjptridx = Objects.vcptridx; |
| 640 |
char my_filename[128]; |
| 641 |
int namelen; |
| 642 |
Errors_in_mine = 0; |
| 643 |
|
| 644 |
namelen = strlen(filename); |
| 645 |
|
| 646 |
Assert (namelen > 4); |
| 647 |
|
| 648 |
Assert (filename[namelen-4] == '.'); |
| 649 |
|
| 650 |
strcpy(my_filename, filename); |
| 651 |
strcpy( &my_filename[namelen-4], ".txm"); |
| 652 |
|
| 653 |
auto &&[my_file, physfserr] = PHYSFSX_openWriteBuffered(my_filename); |
| 654 |
if (!my_file) { |
| 655 |
gr_palette_load(gr_palette); |
| 656 |
nm_messagebox(menu_title{nullptr}, {TXT_OK}, "ERROR: Unable to open %s\n%s", my_filename, PHYSFS_getErrorByCode(physfserr)); |
| 657 |
return; |
| 658 |
} |
| 659 |
|
| 660 |
dump_used_textures_level(my_file, 0, filename); |
| 661 |
say_totals(vcobjptridx, my_file, filename); |
| 662 |
|
| 663 |
PHYSFSX_printf(my_file, "\nNumber of segments: %4i\n", Highest_segment_index+1); |
| 664 |
PHYSFSX_printf(my_file, "Number of objects: %4i\n", Objects.get_count()); |
| 665 |
auto &Walls = LevelUniqueWallSubsystemState.Walls; |
| 666 |
auto &vcwallptridx = Walls.vcptridx; |
| 667 |
PHYSFSX_printf(my_file, "Number of walls: %4i\n", Walls.get_count()); |
| 668 |
auto &ActiveDoors = LevelUniqueWallSubsystemState.ActiveDoors; |
| 669 |
PHYSFSX_printf(my_file, "Number of open doors: %4i\n", ActiveDoors.get_count()); |
| 670 |
{ |
| 671 |
auto &Triggers = LevelUniqueWallSubsystemState.Triggers; |
| 672 |
PHYSFSX_printf(my_file, "Number of triggers: %4i\n", Triggers.get_count()); |
| 673 |
} |
| 674 |
PHYSFSX_printf(my_file, "Number of matcens: %4i\n\n", LevelSharedRobotcenterState.Num_robot_centers); |
| 675 |
|
| 676 |
write_segment_text(vcsegptridx, my_file); |
| 677 |
|
| 678 |
write_fuelcen_text(my_file); |
| 679 |
|
| 680 |
write_matcen_text(my_file); |
| 681 |
|
| 682 |
write_player_text(vcobjptridx, my_file); |
| 683 |
|
| 684 |
write_wall_text(vcsegptridx, vcwallptridx, my_file); |
| 685 |
|
| 686 |
write_trigger_text(my_file); |
| 687 |
|
| 688 |
write_exit_text(vcsegptridx, vcwallptridx, my_file); |
| 689 |
|
| 690 |
// ---------- Find control center segment ---------- |
| 691 |
write_control_center_text(vcsegptridx, my_file); |
| 692 |
|
| 693 |
// ---------- Show keyed walls ---------- |
| 694 |
write_key_text(vcobjptridx, Segments, vcwallptridx, my_file); |
| 695 |
} |
| 696 |
|
| 697 |
namespace dsx { |
| 698 |
namespace { |
| 699 |
|
| 700 |
#if DXX_BUILD_DESCENT == 1 |
| 701 |
const char Shareware_level_names[NUM_SHAREWARE_LEVELS][12] = { |
| 702 |
"level01.rdl", |
| 703 |
"level02.rdl", |
| 704 |
"level03.rdl", |
| 705 |
"level04.rdl", |
| 706 |
"level05.rdl", |
| 707 |
"level06.rdl", |
| 708 |
"level07.rdl" |
| 709 |
}; |
| 710 |
|
| 711 |
const char Registered_level_names[NUM_REGISTERED_LEVELS][12] = { |
| 712 |
"level08.rdl", |
| 713 |
"level09.rdl", |
| 714 |
"level10.rdl", |
| 715 |
"level11.rdl", |
| 716 |
"level12.rdl", |
| 717 |
"level13.rdl", |
| 718 |
"level14.rdl", |
| 719 |
"level15.rdl", |
| 720 |
"level16.rdl", |
| 721 |
"level17.rdl", |
| 722 |
"level18.rdl", |
| 723 |
"level19.rdl", |
| 724 |
"level20.rdl", |
| 725 |
"level21.rdl", |
| 726 |
"level22.rdl", |
| 727 |
"level23.rdl", |
| 728 |
"level24.rdl", |
| 729 |
"level25.rdl", |
| 730 |
"level26.rdl", |
| 731 |
"level27.rdl", |
| 732 |
"levels1.rdl", |
| 733 |
"levels2.rdl", |
| 734 |
"levels3.rdl" |
| 735 |
}; |
| 736 |
#endif |
| 737 |
|
| 738 |
#if DXX_BUILD_DESCENT == 2 |
| 739 |
static int Ignore_tmap_num2_error; |
| 740 |
#endif |
| 741 |
|
| 742 |
// ---------------------------------------------------------------------------- |
| 743 |
#if DXX_BUILD_DESCENT == 1 |
| 744 |
#define determine_used_textures_level(load_level_flag,shareware_flag,level_num,tmap_buf,wall_buffer_type,level_tmap_buf,max_tmap) determine_used_textures_level(load_level_flag,shareware_flag,level_num,tmap_buf,wall_buffer_type,level_tmap_buf,max_tmap) |
| 745 |
#endif |
| 746 |
static void determine_used_textures_level(int load_level_flag, int shareware_flag, int level_num, perm_tmap_buffer_type &tmap_buf, wall_buffer_type &wall_buf, level_tmap_buffer_type &level_tmap_buf, int max_tmap) |
| 747 |
{ |
| 748 |
#if DXX_BUILD_DESCENT == 2 |
| 749 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 750 |
auto &vcobjptr = Objects.vcptr; |
| 751 |
#endif |
| 752 |
int j; |
| 753 |
|
| 754 |
auto &Walls = LevelUniqueWallSubsystemState.Walls; |
| 755 |
auto &WallAnims = GameSharedState.WallAnims; |
| 756 |
#if DXX_BUILD_DESCENT == 1 |
| 757 |
tmap_buf = {}; |
| 758 |
|
| 759 |
if (load_level_flag) { |
| 760 |
load_level(shareware_flag ? Shareware_level_names[level_num] : Registered_level_names[level_num]); |
| 761 |
} |
| 762 |
|
| 763 |
range_for (const cscusegment segp, vcsegptr) |
| 764 |
{ |
| 765 |
range_for (const auto &&z, zip(segp.s.sides, segp.u.sides)) |
| 766 |
{ |
| 767 |
auto &sside = std::get<0>(z); |
| 768 |
if (sside.wall_num != wall_none) |
| 769 |
{ |
| 770 |
const auto clip_num = Walls.vcptr(sside.wall_num)->clip_num; |
| 771 |
if (clip_num != -1) { |
| 772 |
|
| 773 |
const auto num_frames = WallAnims[clip_num].num_frames; |
| 774 |
|
| 775 |
wall_buf[clip_num] = 1; |
| 776 |
|
| 777 |
for (j=0; j<num_frames; j++) { |
| 778 |
const bitmap_index tmap_num{WallAnims[clip_num].frames[j]}; |
| 779 |
tmap_buf[tmap_num]++; |
| 780 |
if (level_tmap_buf[tmap_num] == -1) |
| 781 |
level_tmap_buf[tmap_num] = level_num + (!shareware_flag) * NUM_SHAREWARE_LEVELS; |
| 782 |
} |
| 783 |
} |
| 784 |
} |
| 785 |
|
| 786 |
auto &uside = std::get<1>(z); |
| 787 |
if (const bitmap_index tmap1idx{get_texture_index(uside.tmap_num)}; underlying_value(tmap1idx) < max_tmap) |
| 788 |
{ |
| 789 |
++ tmap_buf[tmap1idx]; |
| 790 |
if (auto &t = level_tmap_buf[tmap1idx]; t == -1) |
| 791 |
t = level_num + (!shareware_flag) * NUM_SHAREWARE_LEVELS; |
| 792 |
} |
| 793 |
else |
| 794 |
{ |
| 795 |
Int3(); // Error, bogus texture map. Should not be greater than max_tmap. |
| 796 |
} |
| 797 |
|
| 798 |
if (const bitmap_index tmap_num2{get_texture_index(uside.tmap_num2)}; tmap_num2 != bitmap_index{}) |
| 799 |
{ |
| 800 |
if (underlying_value(tmap_num2) < max_tmap) { |
| 801 |
++tmap_buf[tmap_num2]; |
| 802 |
if (level_tmap_buf[tmap_num2] == -1) |
| 803 |
level_tmap_buf[tmap_num2] = level_num + (!shareware_flag) * NUM_SHAREWARE_LEVELS; |
| 804 |
} else |
| 805 |
Int3(); // Error, bogus texture map. Should not be greater than max_tmap. |
| 806 |
} |
| 807 |
} |
| 808 |
} |
| 809 |
#elif DXX_BUILD_DESCENT == 2 |
| 810 |
(void)load_level_flag; |
| 811 |
(void)max_tmap; |
| 812 |
(void)shareware_flag; |
| 813 |
|
| 814 |
tmap_buf = {}; |
| 815 |
|
| 816 |
auto &Polygon_models = LevelSharedPolygonModelState.Polygon_models; |
| 817 |
// Process robots. |
| 818 |
for (auto &obj : vcobjptr) |
| 819 |
{ |
| 820 |
if (obj.render_type == render_type::RT_POLYOBJ) |
| 821 |
{ |
| 822 |
const polymodel *const po{&Polygon_models[obj.rtype.pobj_info.model_num]}; |
| 823 |
|
| 824 |
for (unsigned i = 0; i < po->n_textures; ++i) |
| 825 |
{ |
| 826 |
const auto tli = ObjBitmaps[ObjBitmapPtrs[po->first_texture + i]]; |
| 827 |
if (tmap_buf.valid_index(tli)) |
| 828 |
{ |
| 829 |
tmap_buf[tli]++; |
| 830 |
if (auto <b = level_tmap_buf[tli]; ltb == -1) |
| 831 |
ltb = level_num; |
| 832 |
} else |
| 833 |
Int3(); // Hmm, It seems this texture is bogus! |
| 834 |
} |
| 835 |
} |
| 836 |
} |
| 837 |
|
| 838 |
|
| 839 |
Ignore_tmap_num2_error = 0; |
| 840 |
|
| 841 |
// Process walls and segment sides. |
| 842 |
range_for (const csmusegment segp, vmsegptr) |
| 843 |
{ |
| 844 |
range_for (const auto &&z, zip(segp.s.sides, segp.u.sides, segp.s.children)) |
| 845 |
{ |
| 846 |
auto &sside = std::get<0>(z); |
| 847 |
auto &uside = std::get<1>(z); |
| 848 |
const auto child = std::get<2>(z); |
| 849 |
if (sside.wall_num != wall_none) { |
| 850 |
const auto clip_num = Walls.vcptr(sside.wall_num)->clip_num; |
| 851 |
if (clip_num != -1) { |
| 852 |
|
| 853 |
// -- int num_frames = WallAnims[clip_num].num_frames; |
| 854 |
|
| 855 |
wall_buf[clip_num] = 1; |
| 856 |
|
| 857 |
for (j=0; j<1; j++) { // Used to do through num_frames, but don't really want all the door01#3 stuff. |
| 858 |
const auto tmap_num = Textures[WallAnims[clip_num].frames[j]]; |
| 859 |
assert(tmap_buf.valid_index(tmap_num)); |
| 860 |
tmap_buf[tmap_num]++; |
| 861 |
if (auto <b = level_tmap_buf[tmap_num]; ltb == -1) |
| 862 |
ltb = level_num; |
| 863 |
} |
| 864 |
} |
| 865 |
} else if (child == segment_none) { |
| 866 |
{ |
| 867 |
const auto tmap1idx = get_texture_index(uside.tmap_num); |
| 868 |
if (tmap1idx < Textures.size()) { |
| 869 |
const auto ti = Textures[tmap1idx]; |
| 870 |
assert(tmap_buf.valid_index(ti)); |
| 871 |
++tmap_buf[ti]; |
| 872 |
if (auto <b = level_tmap_buf[ti]; ltb == -1) |
| 873 |
ltb = level_num; |
| 874 |
} else |
| 875 |
Int3(); // Error, bogus texture map. Should not be greater than max_tmap. |
| 876 |
} |
| 877 |
|
| 878 |
if (const auto masked_tmap_num2 = get_texture_index(uside.tmap_num2)) |
| 879 |
{ |
| 880 |
if (masked_tmap_num2 < Textures.size()) |
| 881 |
{ |
| 882 |
const auto ti = Textures[masked_tmap_num2]; |
| 883 |
assert(tmap_buf.valid_index(ti)); |
| 884 |
++tmap_buf[ti]; |
| 885 |
if (level_tmap_buf[ti] == -1) |
| 886 |
level_tmap_buf[ti] = level_num; |
| 887 |
} else { |
| 888 |
if (!Ignore_tmap_num2_error) |
| 889 |
Int3(); // Error, bogus texture map. Should not be greater than max_tmap. |
| 890 |
Ignore_tmap_num2_error = 1; |
| 891 |
uside.tmap_num2 = texture2_value::None; |
| 892 |
} |
| 893 |
} |
| 894 |
} |
| 895 |
} |
| 896 |
} |
| 897 |
#endif |
| 898 |
} |
| 899 |
} |
| 900 |
} |
| 901 |
|
| 902 |
namespace { |
| 903 |
// ---------------------------------------------------------------------------- |
| 904 |
template <std::size_t N> |
| 905 |
static void merge_buffers(std::array<int, N> &dest, const std::array<int, N> &src) |
| 906 |
{ |
| 907 |
std::transform(dest.begin(), dest.end(), src.begin(), dest.begin(), std::plus<int>()); |
| 908 |
} |
| 909 |
} |
| 910 |
|
| 911 |
// ---------------------------------------------------------------------------- |
| 912 |
namespace dsx { |
| 913 |
namespace { |
| 914 |
static void say_used_tmaps(PHYSFS_File *const my_file, const perm_tmap_buffer_type &tb) |
| 915 |
{ |
| 916 |
#if DXX_BUILD_DESCENT == 1 |
| 917 |
int count{0}; |
| 918 |
|
| 919 |
auto &TmapInfo = LevelUniqueTmapInfoState.TmapInfo; |
| 920 |
const auto Num_tmaps = LevelUniqueTmapInfoState.Num_tmaps; |
| 921 |
for (const uint16_t i : xrange(Num_tmaps)) |
| 922 |
{ |
| 923 |
const bitmap_index bi{i}; |
| 924 |
if (tb[bi]) { |
| 925 |
PHYSFSX_printf(my_file, "[%3i %8s (%4i)]%s", i, TmapInfo[i].filename.data(), tb[bi], count++ >= 4 ? (count = 0, "\n") : " "); |
| 926 |
} |
| 927 |
} |
| 928 |
#elif DXX_BUILD_DESCENT == 2 |
| 929 |
for (const uint16_t i : xrange(std::size(tb))) |
| 930 |
{ |
| 931 |
const bitmap_index bi{i}; |
| 932 |
if (tb[bi]) { |
| 933 |
PHYSFSX_printf(my_file, "[%3i %8s (%4i)]\n", i, AllBitmaps[bi].name.data(), tb[bi]); |
| 934 |
} |
| 935 |
} |
| 936 |
#endif |
| 937 |
} |
| 938 |
|
| 939 |
#if DXX_BUILD_DESCENT == 1 |
| 940 |
// ----------------------------------------------------------------------------- |
| 941 |
static void say_used_once_tmaps(PHYSFS_File *const my_file, const perm_tmap_buffer_type &tb, const level_tmap_buffer_type &tb_lnum) |
| 942 |
{ |
| 943 |
const char *level_name; |
| 944 |
|
| 945 |
auto &TmapInfo = LevelUniqueTmapInfoState.TmapInfo; |
| 946 |
const auto Num_tmaps = LevelUniqueTmapInfoState.Num_tmaps; |
| 947 |
for (const uint16_t i : xrange(Num_tmaps)) |
| 948 |
{ |
| 949 |
const bitmap_index bi{i}; |
| 950 |
if (tb[bi] == 1) |
| 951 |
{ |
| 952 |
const auto level_num = tb_lnum[bi]; |
| 953 |
if (level_num >= NUM_SHAREWARE_LEVELS) { |
| 954 |
Assert((level_num - NUM_SHAREWARE_LEVELS >= 0) && (level_num - NUM_SHAREWARE_LEVELS < NUM_REGISTERED_LEVELS)); |
| 955 |
level_name = Registered_level_names[level_num - NUM_SHAREWARE_LEVELS]; |
| 956 |
} else { |
| 957 |
Assert((level_num >= 0) && (level_num < NUM_SHAREWARE_LEVELS)); |
| 958 |
level_name = Shareware_level_names[level_num]; |
| 959 |
} |
| 960 |
|
| 961 |
PHYSFSX_printf(my_file, "Texture %3i %8s used only once on level %s\n", i, static_cast<const char *>(TmapInfo[i].filename), level_name); |
| 962 |
} |
| 963 |
} |
| 964 |
} |
| 965 |
#endif |
| 966 |
|
| 967 |
// ---------------------------------------------------------------------------- |
| 968 |
static void say_unused_tmaps(PHYSFS_File *my_file, perm_tmap_buffer_type &perm_tmap_buf) |
| 969 |
{ |
| 970 |
#if DXX_BUILD_DESCENT == 1 |
| 971 |
const unsigned bound = LevelUniqueTmapInfoState.Num_tmaps; |
| 972 |
auto &TmapInfo = LevelUniqueTmapInfoState.TmapInfo; |
| 973 |
auto &tmap_name_source = TmapInfo; |
| 974 |
#elif DXX_BUILD_DESCENT == 2 |
| 975 |
const unsigned bound = MAX_BITMAP_FILES; |
| 976 |
auto &tmap_name_source = AllBitmaps; |
| 977 |
#endif |
| 978 |
unsigned count{0}; |
| 979 |
for (auto &&[i, tb, texture, tmap_name] : enumerate(zip(partial_range(perm_tmap_buf, bound), Textures, tmap_name_source))) |
| 980 |
if (!tb) |
| 981 |
{ |
| 982 |
const char usage_indicator = (GameBitmaps[texture].bm_data == bogus_data.data()) |
| 983 |
? 'U' |
| 984 |
: ' '; |
| 985 |
|
| 986 |
#if DXX_BUILD_DESCENT == 1 |
| 987 |
const auto filename = static_cast<const char *>(tmap_name.filename); |
| 988 |
#elif DXX_BUILD_DESCENT == 2 |
| 989 |
const auto filename = tmap_name.name.data(); |
| 990 |
#endif |
| 991 |
const char sep = (count++ >= 4) |
| 992 |
? (count = 0, '\n') |
| 993 |
: ' '; |
| 994 |
PHYSFSX_printf(my_file, "%c[%3" PRIuFAST32 " %8s]%c", usage_indicator, i, filename, sep); |
| 995 |
} |
| 996 |
} |
| 997 |
|
| 998 |
#if DXX_BUILD_DESCENT == 1 |
| 999 |
// ---------------------------------------------------------------------------- |
| 1000 |
static void say_unused_walls(PHYSFS_File *my_file, const wall_buffer_type &tb) |
| 1001 |
{ |
| 1002 |
int i; |
| 1003 |
for (i=0; i<Num_wall_anims; i++) |
| 1004 |
if (!tb[i]) |
| 1005 |
PHYSFSX_printf(my_file, "Wall %3i is unused.\n", i); |
| 1006 |
} |
| 1007 |
#endif |
| 1008 |
} |
| 1009 |
} |
| 1010 |
|
| 1011 |
namespace { |
| 1012 |
|
| 1013 |
static void say_totals(fvcobjptridx &vcobjptridx, PHYSFS_File *my_file, const char *level_name) |
| 1014 |
{ |
| 1015 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 1016 |
int total_robots{0}; |
| 1017 |
int objects_processed{0}; |
| 1018 |
|
| 1019 |
PHYSFSX_printf(my_file, "\nLevel %s\n", level_name); |
| 1020 |
std::bitset<MAX_OBJECTS> used_objects; |
| 1021 |
while (objects_processed < Highest_object_index+1) { |
| 1022 |
int objtype, objid, objcount, min_obj_val; |
| 1023 |
|
| 1024 |
// Find new min objnum. |
| 1025 |
min_obj_val = 0x7fff0000; |
| 1026 |
const object_base *min_objp = nullptr; |
| 1027 |
|
| 1028 |
range_for (const auto &&objp, vcobjptridx) |
| 1029 |
{ |
| 1030 |
if (!used_objects[objp] && objp->type != OBJ_NONE) |
| 1031 |
{ |
| 1032 |
const auto cur_obj_val = (objp->type << 10) + objp->id; |
| 1033 |
if (cur_obj_val < min_obj_val) { |
| 1034 |
min_objp = &*objp; |
| 1035 |
min_obj_val = cur_obj_val; |
| 1036 |
} |
| 1037 |
} |
| 1038 |
} |
| 1039 |
if (!min_objp || min_objp->type == OBJ_NONE) |
| 1040 |
break; |
| 1041 |
|
| 1042 |
objcount = 0; |
| 1043 |
|
| 1044 |
objtype = min_objp->type; |
| 1045 |
objid = min_objp->id; |
| 1046 |
|
| 1047 |
range_for (const auto &&objp, vcobjptridx) |
| 1048 |
{ |
| 1049 |
if (auto &&uo = used_objects[objp]) |
| 1050 |
{ |
| 1051 |
} |
| 1052 |
else |
| 1053 |
{ |
| 1054 |
if ((objp->type == objtype && objp->id == objid) || |
| 1055 |
(objp->type == objtype && objtype == OBJ_PLAYER) || |
| 1056 |
(objp->type == objtype && objtype == OBJ_COOP) || |
| 1057 |
(objp->type == objtype && objtype == OBJ_HOSTAGE)) { |
| 1058 |
if (objp->type == OBJ_ROBOT) |
| 1059 |
total_robots++; |
| 1060 |
uo = true; |
| 1061 |
objcount++; |
| 1062 |
objects_processed++; |
| 1063 |
} |
| 1064 |
} |
| 1065 |
} |
| 1066 |
|
| 1067 |
if (objcount) { |
| 1068 |
PHYSFSX_printf(my_file, "Object: %8s %8s %3i\n", object_types(*min_objp), object_ids(*min_objp), objcount); |
| 1069 |
} |
| 1070 |
} |
| 1071 |
|
| 1072 |
PHYSFSX_printf(my_file, "Total robots = %3i\n", total_robots); |
| 1073 |
} |
| 1074 |
|
| 1075 |
} |
| 1076 |
|
| 1077 |
namespace dsx { |
| 1078 |
namespace { |
| 1079 |
|
| 1080 |
// ---------------------------------------------------------------------------- |
| 1081 |
static void say_totals_all(void) |
| 1082 |
{ |
| 1083 |
auto &&[my_file, physfserr] = PHYSFSX_openWriteBuffered("levels.all"); |
| 1084 |
if (!my_file) { |
| 1085 |
gr_palette_load(gr_palette); |
| 1086 |
nm_messagebox(menu_title{nullptr}, {TXT_OK}, "ERROR: Unable to open levels.all\n%s", PHYSFS_getErrorByCode(physfserr)); |
| 1087 |
return; |
| 1088 |
} |
| 1089 |
|
| 1090 |
#if DXX_BUILD_DESCENT == 1 |
| 1091 |
auto &Objects = LevelUniqueObjectState.Objects; |
| 1092 |
auto &vcobjptridx = Objects.vcptridx; |
| 1093 |
for (unsigned i = 0; i < NUM_SHAREWARE_LEVELS; ++i) |
| 1094 |
{ |
| 1095 |
load_level(Shareware_level_names[i]); |
| 1096 |
say_totals(vcobjptridx, my_file, Shareware_level_names[i]); |
| 1097 |
} |
| 1098 |
|
| 1099 |
for (unsigned i = 0; i < NUM_REGISTERED_LEVELS; ++i) |
| 1100 |
{ |
| 1101 |
load_level(Registered_level_names[i]); |
| 1102 |
say_totals(vcobjptridx, my_file, Registered_level_names[i]); |
| 1103 |
} |
| 1104 |
#endif |
| 1105 |
} |
| 1106 |
} |
| 1107 |
} |
| 1108 |
|
| 1109 |
namespace { |
| 1110 |
static void dump_used_textures_level(PHYSFS_File *my_file, int level_num, const char *const Gamesave_current_filename) |
| 1111 |
{ |
| 1112 |
perm_tmap_buffer_type temp_tmap_buf; |
| 1113 |
level_tmap_buffer_type level_tmap_buf; |
| 1114 |
|
| 1115 |
level_tmap_buf.fill(-1); |
| 1116 |
|
| 1117 |
wall_buffer_type temp_wall_buf; |
| 1118 |
determine_used_textures_level(0, 1, level_num, temp_tmap_buf, temp_wall_buf, level_tmap_buf, level_tmap_buf.size()); |
| 1119 |
PHYSFSX_printf(my_file, "\nTextures used in [%s]\n", Gamesave_current_filename); |
| 1120 |
say_used_tmaps(my_file, temp_tmap_buf); |
| 1121 |
} |
| 1122 |
} |
| 1123 |
|
| 1124 |
// ---------------------------------------------------------------------------- |
| 1125 |
namespace dsx { |
| 1126 |
void dump_used_textures_all(void) |
| 1127 |
{ |
| 1128 |
say_totals_all(); |
| 1129 |
|
| 1130 |
auto &&[my_file, physfserr] = PHYSFSX_openWriteBuffered("textures.dmp"); |
| 1131 |
if (!my_file) { |
| 1132 |
gr_palette_load(gr_palette); |
| 1133 |
nm_messagebox(menu_title{nullptr}, {TXT_OK}, "ERROR: Can't open textures.dmp\n%s", PHYSFS_getErrorByCode(physfserr)); |
| 1134 |
return; |
| 1135 |
} |
| 1136 |
|
| 1137 |
perm_tmap_buffer_type perm_tmap_buf{}; |
| 1138 |
level_tmap_buffer_type level_tmap_buf; |
| 1139 |
level_tmap_buf.fill(-1); |
| 1140 |
|
| 1141 |
#if DXX_BUILD_DESCENT == 1 |
| 1142 |
perm_tmap_buffer_type temp_tmap_buf; |
| 1143 |
wall_buffer_type perm_wall_buf{}; |
| 1144 |
|
| 1145 |
for (unsigned i = 0; i < NUM_SHAREWARE_LEVELS; ++i) |
| 1146 |
{ |
| 1147 |
wall_buffer_type temp_wall_buf; |
| 1148 |
determine_used_textures_level(1, 1, i, temp_tmap_buf, temp_wall_buf, level_tmap_buf, level_tmap_buf.size()); |
| 1149 |
PHYSFSX_printf(my_file, "\nTextures used in [%s]\n", Shareware_level_names[i]); |
| 1150 |
say_used_tmaps(my_file, temp_tmap_buf); |
| 1151 |
merge_buffers(perm_tmap_buf, temp_tmap_buf); |
| 1152 |
merge_buffers(perm_wall_buf, temp_wall_buf); |
| 1153 |
} |
| 1154 |
|
| 1155 |
PHYSFSX_puts_literal(my_file, "\n\nUsed textures in all shareware mines:\n"); |
| 1156 |
say_used_tmaps(my_file, perm_tmap_buf); |
| 1157 |
|
| 1158 |
PHYSFSX_puts_literal(my_file, "\nUnused textures in all shareware mines:\n"); |
| 1159 |
say_unused_tmaps(my_file, perm_tmap_buf); |
| 1160 |
|
| 1161 |
PHYSFSX_puts_literal(my_file, "\nTextures used exactly once in all shareware mines:\n"); |
| 1162 |
say_used_once_tmaps(my_file, perm_tmap_buf, level_tmap_buf); |
| 1163 |
|
| 1164 |
PHYSFSX_puts_literal(my_file, "\nWall anims (eg, doors) unused in all shareware mines:\n"); |
| 1165 |
say_unused_walls(my_file, perm_wall_buf); |
| 1166 |
|
| 1167 |
for (unsigned i = 0; i < NUM_REGISTERED_LEVELS; ++i) |
| 1168 |
{ |
| 1169 |
wall_buffer_type temp_wall_buf; |
| 1170 |
determine_used_textures_level(1, 0, i, temp_tmap_buf, temp_wall_buf, level_tmap_buf, level_tmap_buf.size()); |
| 1171 |
PHYSFSX_printf(my_file, "\nTextures used in [%s]\n", Registered_level_names[i]); |
| 1172 |
say_used_tmaps(my_file, temp_tmap_buf); |
| 1173 |
merge_buffers(perm_tmap_buf, temp_tmap_buf); |
| 1174 |
} |
| 1175 |
#endif |
| 1176 |
|
| 1177 |
PHYSFSX_puts_literal(my_file, "\n\nUsed textures in all (including registered) mines:\n"); |
| 1178 |
say_used_tmaps(my_file, perm_tmap_buf); |
| 1179 |
|
| 1180 |
PHYSFSX_puts_literal(my_file, "\nUnused textures in all (including registered) mines:\n"); |
| 1181 |
say_unused_tmaps(my_file, perm_tmap_buf); |
| 1182 |
} |
| 1183 |
} |
| 1184 |
|
| 1185 |
#endif |