| 1 |
/* |
| 2 |
* Descent 3 |
| 3 |
* Copyright (C) 2024 Parallax Software |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
--- HISTORICAL COMMENTS FOLLOW --- |
| 19 |
|
| 20 |
* $Logfile: /DescentIII/Main/editor/HFile.cpp $ |
| 21 |
* $Revision: 1.1.1.1 $ |
| 22 |
* $Date: 2003-08-26 03:57:38 $ |
| 23 |
* $Author: kevinb $ |
| 24 |
* |
| 25 |
* Handler funcs for File menu |
| 26 |
* |
| 27 |
* $Log: not supported by cvs2svn $ |
| 28 |
* |
| 29 |
* 81 10/13/99 2:19p Chris |
| 30 |
* Added the ability to disable wind for powerups on a level |
| 31 |
* |
| 32 |
* 80 10/13/99 10:40a Chris |
| 33 |
* Added 'special forcefields' that have custom bounce factors |
| 34 |
* |
| 35 |
* 79 10/08/99 4:29p Chris |
| 36 |
* Added the forcefield and glass breaking override options |
| 37 |
* |
| 38 |
* 78 5/18/99 11:10a Matt |
| 39 |
* Added variable ceiling height. |
| 40 |
* |
| 41 |
* 77 4/27/99 3:24p Jeff |
| 42 |
* showlevelstats shows information about goals and special flags |
| 43 |
* |
| 44 |
* 76 4/21/99 1:08p Chris |
| 45 |
* Fixed new mines from having the always check ceiling flag |
| 46 |
* |
| 47 |
* 75 4/20/99 8:14p Chris |
| 48 |
* Added support for object's that hit the ceiling and for making the |
| 49 |
* level always check for the ceiling (inside and outside the mine) |
| 50 |
* |
| 51 |
* 74 4/18/99 5:42a Chris |
| 52 |
* Added the FQ_IGNORE_RENDER_THROUGH_PORTALS flag |
| 53 |
* |
| 54 |
* 73 3/22/99 6:26p Matt |
| 55 |
* Cleaned up error handling in cfile and editor level loads. |
| 56 |
* |
| 57 |
* 72 3/02/99 4:54p Matt |
| 58 |
* Fixed another stupid bug |
| 59 |
* |
| 60 |
* 71 3/02/99 4:07p Matt |
| 61 |
* Fixed stupid bug in duplicate room name check |
| 62 |
* |
| 63 |
* 70 3/01/99 10:39a Matt |
| 64 |
* Strip leading and trailing spaces from object, trigger, and room names |
| 65 |
* on level load and when the names are entered. |
| 66 |
* |
| 67 |
* 69 2/28/99 10:41p Matt |
| 68 |
* After a level is loaded, check for duplicate trigger, room, & object |
| 69 |
* names. |
| 70 |
* |
| 71 |
* 68 2/28/99 9:28p Matt |
| 72 |
* Cleaned up load level error handing and version checking. |
| 73 |
* |
| 74 |
* 67 2/21/99 12:28p Matt |
| 75 |
* Added terrain sound system |
| 76 |
* |
| 77 |
* 66 2/17/99 3:06p Matt |
| 78 |
* Updated copyrights. |
| 79 |
* |
| 80 |
* 65 2/16/99 3:47p Jason |
| 81 |
* added marker updates to multiplayer server stream |
| 82 |
* |
| 83 |
* 64 2/02/99 10:46a Matt |
| 84 |
* Only reset the wireframe view radius when loading an actual new level, |
| 85 |
* and not whenever a level is loading, which incudes going from the game |
| 86 |
* to the editor. |
| 87 |
* |
| 88 |
* 63 1/29/99 12:48p Matt |
| 89 |
* Rewrote the doorway system |
| 90 |
* |
| 91 |
* 62 1/21/99 11:15p Jeff |
| 92 |
* pulled out some structs and defines from header files and moved them |
| 93 |
* into seperate header files so that multiplayer dlls don't require major |
| 94 |
* game headers, just those new headers. Side effect is a shorter build |
| 95 |
* time. Also cleaned up some header file #includes that weren't needed. |
| 96 |
* This affected polymodel.h, object.h, player.h, vecmat.h, room.h, |
| 97 |
* manage.h and multi.h |
| 98 |
* |
| 99 |
* 61 1/08/99 2:56p Samir |
| 100 |
* Ripped out OSIRIS1. |
| 101 |
* |
| 102 |
* 60 1/04/99 6:19p Jason |
| 103 |
* counts number of specular faces in mine |
| 104 |
* |
| 105 |
* 59 12/18/98 5:40p Chris |
| 106 |
* Ambient life is now all sequenced up |
| 107 |
* |
| 108 |
* 58 10/08/98 8:14p Matt |
| 109 |
* Fixed stupid bug that's just started causing problems. |
| 110 |
* |
| 111 |
* 57 10/08/98 4:23p Kevin |
| 112 |
* Changed code to comply with memory library usage. Always use mem_malloc |
| 113 |
* , mem_free and mem_strdup |
| 114 |
* |
| 115 |
* 56 10/05/98 2:42a Chris |
| 116 |
* Level goals are relatively functional |
| 117 |
* |
| 118 |
* 55 9/24/98 5:00p Matt |
| 119 |
* Improved error checking for running out of rooms. |
| 120 |
* |
| 121 |
* 54 9/16/98 12:07p Chris |
| 122 |
* Improved BOA AABB computation with room checksums |
| 123 |
* |
| 124 |
* 53 9/10/98 3:07p Chris |
| 125 |
* Improved matcen sequencing code and test effect1 |
| 126 |
* |
| 127 |
* 52 9/08/98 12:05p Jason |
| 128 |
* moved doorway.h out of room.h |
| 129 |
* |
| 130 |
* 51 8/17/98 2:16p Jason |
| 131 |
* fixed erroneous reporting of specular lightmap bytes |
| 132 |
* |
| 133 |
* 50 8/10/98 11:25a Jason |
| 134 |
* added better specular lighting |
| 135 |
* |
| 136 |
* 49 8/03/98 5:47p Chris |
| 137 |
* Improved the partial AABB computation |
| 138 |
* |
| 139 |
* 48 5/15/98 5:41p Jason |
| 140 |
* implemented volume lighting system |
| 141 |
* |
| 142 |
* 47 5/13/98 3:06p Jason |
| 143 |
* got rid of square-power-of-two lightmap limitations |
| 144 |
* |
| 145 |
* 46 5/13/98 12:06p Jason |
| 146 |
* trimmed some memory usage |
| 147 |
* |
| 148 |
* 45 4/21/98 2:40p Matt |
| 149 |
* Added option to show level stats |
| 150 |
* |
| 151 |
* 44 4/14/98 7:50p Matt |
| 152 |
* Added system to keep info for each level |
| 153 |
* |
| 154 |
* 43 2/18/98 8:43p Chris |
| 155 |
* Made BOA get saved with the level. It should only get built when it |
| 156 |
* needs to be updated. |
| 157 |
* |
| 158 |
* 42 2/04/98 1:26p Matt |
| 159 |
* Got rid of compile warning |
| 160 |
* |
| 161 |
* 41 2/03/98 5:01p Chris |
| 162 |
* UPdated the path system |
| 163 |
* |
| 164 |
* 40 1/27/98 12:01p Chris |
| 165 |
* Game path system now works with new, load, and save in the editor. |
| 166 |
* Also, the game path system is further bug proved. |
| 167 |
* |
| 168 |
* 39 1/21/98 12:32p Matt |
| 169 |
* Revamped viewer system |
| 170 |
* |
| 171 |
* 38 1/20/98 1:36p Matt |
| 172 |
* Moved mine origin to the center of the terrain |
| 173 |
* |
| 174 |
* 37 1/19/98 10:04a Matt |
| 175 |
* Added new object handle system |
| 176 |
* |
| 177 |
* 36 1/15/98 7:34p Matt |
| 178 |
* Revamped error checking when computing face normals |
| 179 |
* |
| 180 |
* 35 1/02/98 12:00p Jason |
| 181 |
* got rid of redundant rebuilding of min/max terrain |
| 182 |
* |
| 183 |
* 34 10/08/97 5:20p Jason |
| 184 |
* clear object memory when "New" is selected |
| 185 |
* |
| 186 |
* 33 10/01/97 7:49p Matt |
| 187 |
* Fixed bug w/ script memory freeing (as per Samir's instructions) |
| 188 |
* |
| 189 |
* 32 10/01/97 4:49p Samir |
| 190 |
* Free level script after loading it, since the editor doesn't need the |
| 191 |
* compiled program. |
| 192 |
* |
| 193 |
* 31 9/25/97 5:28p Samir |
| 194 |
* Even newer script code due to more changes in ObjCScript.cpp |
| 195 |
* |
| 196 |
* 30 9/24/97 2:57p Samir |
| 197 |
* Modified NewScript for level function. |
| 198 |
* |
| 199 |
* 29 9/22/97 5:59p Samir |
| 200 |
* Changed ObjCScript system, so everything is broken, but it shouldn't |
| 201 |
* crash the game. |
| 202 |
* |
| 203 |
* 28 9/17/97 1:24p Matt |
| 204 |
* Ripped out segment code |
| 205 |
* |
| 206 |
* 27 9/17/97 12:53p Samir |
| 207 |
* BIG SEGMENT RIPOUT |
| 208 |
* |
| 209 |
* 26 9/10/97 1:55p Samir |
| 210 |
* Create a default level script for a new mine. |
| 211 |
* |
| 212 |
* 25 9/09/97 2:38p Samir |
| 213 |
* Added include for string.h |
| 214 |
* |
| 215 |
* 24 9/09/97 1:04p Samir |
| 216 |
* Added code to create new script and save level script name. |
| 217 |
* |
| 218 |
* 23 9/09/97 10:44a Matt |
| 219 |
* Fixed a small bug, & ripped out some segment engine code |
| 220 |
* |
| 221 |
* 22 9/06/97 3:35p Matt |
| 222 |
* Reset cur porral when room changes |
| 223 |
* Ripped out some old segment engine code |
| 224 |
* |
| 225 |
* 21 8/29/97 5:21p Matt |
| 226 |
* Made CreateNewMine() clear the room (not segment) selected list, and |
| 227 |
* clear Placed_group |
| 228 |
* |
| 229 |
* 20 8/21/97 2:06p Matt |
| 230 |
* Clear marked room when creating a new level |
| 231 |
* |
| 232 |
* 19 8/18/97 6:59p Matt |
| 233 |
* Implemented Place Room/Attach room system |
| 234 |
* |
| 235 |
* 18 8/15/97 6:32p Samir |
| 236 |
* Took out references to default/level scripts due to newer system. |
| 237 |
* |
| 238 |
* 17 8/12/97 3:22p Samir |
| 239 |
* D3XReallocProgram now has two more args. |
| 240 |
* |
| 241 |
* 16 8/06/97 10:36a Samir |
| 242 |
* Fixed D3XReallocProgram calls. |
| 243 |
* |
| 244 |
* 15 8/04/97 4:12p Samir |
| 245 |
* Reset level script code every new mine. |
| 246 |
* |
| 247 |
* 14 7/24/97 2:58p Matt |
| 248 |
* Reset editor viewer variables when creating a new mine |
| 249 |
* |
| 250 |
* 13 7/22/97 7:07p Matt |
| 251 |
* Cleaned up D3EditState, moving some vars in and some out, and renaming |
| 252 |
* and changing a few others |
| 253 |
* |
| 254 |
* 12 7/18/97 5:42p Matt |
| 255 |
* Changed default level script to use CR/LF pair instead of Newline |
| 256 |
* |
| 257 |
* 11 7/17/97 7:22p Matt |
| 258 |
* Initialize level script when create new level |
| 259 |
* |
| 260 |
* 26 6/30/97 1:30p Jason |
| 261 |
* added netherspace stuff |
| 262 |
* |
| 263 |
* 25 6/24/97 3:50p Jason |
| 264 |
* changes for y only terrain positions |
| 265 |
* |
| 266 |
* 24 5/13/97 10:29p Matt |
| 267 |
* Deleted some unused code |
| 268 |
* |
| 269 |
* 23 5/13/97 12:01p Matt |
| 270 |
* Added support for floating segments |
| 271 |
* |
| 272 |
* 22 5/08/97 7:29p Matt |
| 273 |
* Made seperate viewers for mine & terrain, and cleaned up code the |
| 274 |
* switched between modes |
| 275 |
* |
| 276 |
* 21 5/06/97 2:30p Jason |
| 277 |
* added check for terrain viewer |
| 278 |
* |
| 279 |
* 20 4/25/97 2:31p Jason |
| 280 |
* implemented game event system |
| 281 |
* |
| 282 |
* 19 4/04/97 2:57p Matt |
| 283 |
* Added code to initialize all the type-specific data for an object from |
| 284 |
* the page for that object type. This means that we need to pass less |
| 285 |
* info to ObjCreate(), and that we save less info in the level save file. |
| 286 |
* It also makes it easy to reset all the objects when an object page has |
| 287 |
* changed. |
| 288 |
* |
| 289 |
* 18 4/01/97 11:00p Matt |
| 290 |
* Changed editor to keep a viewer object (type camera) seperate from the |
| 291 |
* player object. This camera, and not the player, is now moved by |
| 292 |
* slewing, the C key, etc. When going into the game, the viewer position |
| 293 |
* & orientation are copied to the player. When going back to the editor, |
| 294 |
* the player position is copied to the viewer, and the player object is |
| 295 |
* reset to its start location. |
| 296 |
* |
| 297 |
* 17 3/31/97 5:58p Matt |
| 298 |
* Revamped mine update flags |
| 299 |
* |
| 300 |
* 16 3/31/97 3:47p Matt |
| 301 |
* Added code to keep track of, render, and display current vertex. |
| 302 |
* |
| 303 |
* 15 3/21/97 5:01p Jason |
| 304 |
* incremental terrain improvments |
| 305 |
* |
| 306 |
* |
| 307 |
* 14 3/18/97 11:27a Samir |
| 308 |
* Reset current trigger and doorway to 0 when loading a level in. |
| 309 |
* |
| 310 |
* 13 3/17/97 2:54p Samir |
| 311 |
* Dont initialize initial doorways or triggers. |
| 312 |
* |
| 313 |
* 12 3/17/97 12:00p Matt |
| 314 |
* Reset warning segments when creating new level and loading |
| 315 |
* level. |
| 316 |
* |
| 317 |
* 11 3/12/97 1:14p Matt |
| 318 |
* Clear selected list when creating a new mine |
| 319 |
* |
| 320 |
* 10 3/12/97 12:37p Samir |
| 321 |
* Initialized doorways |
| 322 |
* |
| 323 |
* 9 3/05/97 3:33p Samir |
| 324 |
* Define initial default Doorway for mine. |
| 325 |
* |
| 326 |
* 8 3/04/97 7:12p Samir |
| 327 |
* Initialized a default trigger when new level |
| 328 |
* |
| 329 |
* 7 2/26/97 12:23p Matt |
| 330 |
* Use real funcs to create segment sides & assign uvs. |
| 331 |
* Deleted temp func that did the same. |
| 332 |
* |
| 333 |
* 6 2/24/97 6:00p Matt |
| 334 |
* Added code to set marked segment. |
| 335 |
* Changed code to not say that mine has changed when curside or curside |
| 336 |
* has changed. |
| 337 |
* |
| 338 |
* 5 2/21/97 5:23p Matt |
| 339 |
* Added new ResetVertices() to set Vertex_active array after level |
| 340 |
* loaded. Renamed old ResetVertices() to InitVertices(); |
| 341 |
* |
| 342 |
* 4 2/20/97 9:56a Matt |
| 343 |
* Moved some general-purpose segment code from HFile.cpp to ESegments.cpp |
| 344 |
* |
| 345 |
* 3 2/11/97 6:44p Matt |
| 346 |
* Reset player when do a new level |
| 347 |
* Added new function: ResetFreeSegList() |
| 348 |
* |
| 349 |
* 2 2/10/97 5:40p Matt |
| 350 |
* Code to handle several File menu options |
| 351 |
* |
| 352 |
* 1 2/10/97 12:16a Matt |
| 353 |
* |
| 354 |
* $NoKeywords: $ |
| 355 |
*/ |
| 356 |
|
| 357 |
#include <string.h> |
| 358 |
|
| 359 |
#include "descent.h" |
| 360 |
#include "HFile.h" |
| 361 |
#include "d3edit.h" |
| 362 |
#include "room.h" |
| 363 |
#include "object.h" |
| 364 |
#include "game.h" |
| 365 |
#include "LoadLevel.h" |
| 366 |
#include "MoveWorld.h" |
| 367 |
#include "ERooms.h" |
| 368 |
#include "trigger.h" |
| 369 |
#include "door.h" |
| 370 |
#include "selectedroom.h" |
| 371 |
#include "terrain.h" |
| 372 |
#include "player.h" |
| 373 |
#include "gameevent.h" |
| 374 |
#include "HView.h" |
| 375 |
#include "gamepath.h" |
| 376 |
#include "boa.h" |
| 377 |
#include "mission.h" |
| 378 |
#include "lighting.h" |
| 379 |
#include "lightmap_info.h" |
| 380 |
#include "lightmap.h" |
| 381 |
#include "special_face.h" |
| 382 |
#include "doorway.h" |
| 383 |
#include "matcen.h" |
| 384 |
#include "levelgoal.h" |
| 385 |
#include "aiambient.h" |
| 386 |
#include "polymodel.h" |
| 387 |
#include "bnode.h" |
| 388 |
#include "findintersection.h" |
| 389 |
|
| 390 |
// Scripting stuff |
| 391 |
// #include "d3x.h" |
| 392 |
// #include "ObjScript.h" |
| 393 |
|
| 394 |
// vertices for the default room created by CreateNewMine() |
| 395 |
vector default_room_verts[] = {{-10, 8, 20}, {-5, 10, 20}, {5, 10, 20}, {10, 8, 20}, {10, -8, 20}, {5, -10, 20}, |
| 396 |
{-5, -10, 20}, {-10, -8, 20}, {-10, 8, -20}, {-5, 10, -20}, {5, 10, -20}, {10, 8, -20}, |
| 397 |
{10, -8, -20}, {5, -10, -20}, {-5, -10, -20}, {-10, -8, -20}}; |
| 398 |
|
| 399 |
extern void AssignDefaultUVsToRoom(room *rp); |
| 400 |
|
| 401 |
// Where the center of the (mine's) world is |
| 402 |
vector Mine_origin = {TERRAIN_WIDTH * (TERRAIN_SIZE / 2), -100, TERRAIN_DEPTH *(TERRAIN_SIZE / 2)}; |
| 403 |
|
| 404 |
// Create a default room for a new mine |
| 405 |
room *CreateDefaultRoom() { |
| 406 |
room *rp; |
| 407 |
int i; |
| 408 |
|
| 409 |
// Get a pointer to our room |
| 410 |
rp = CreateNewRoom(16, 10, 0); // 16 verts, 10 faces, normal room |
| 411 |
ASSERT(rp != NULL); |
| 412 |
|
| 413 |
// Set the vertices for the room |
| 414 |
for (i = 0; i < 16; i++) |
| 415 |
rp->verts[i] = default_room_verts[i] + Mine_origin; |
| 416 |
|
| 417 |
// Set the faces for the room |
| 418 |
InitRoomFace(&rp->faces[0], 8); |
| 419 |
for (i = 0; i < 8; i++) |
| 420 |
rp->faces[0].face_verts[i] = i; |
| 421 |
|
| 422 |
InitRoomFace(&rp->faces[1], 8); |
| 423 |
for (i = 0; i < 8; i++) |
| 424 |
rp->faces[1].face_verts[i] = 15 - i; |
| 425 |
|
| 426 |
for (i = 0; i < 8; i++) { |
| 427 |
InitRoomFace(&rp->faces[i + 2], 4); |
| 428 |
rp->faces[i + 2].face_verts[0] = i; |
| 429 |
rp->faces[i + 2].face_verts[1] = i + 8; |
| 430 |
rp->faces[i + 2].face_verts[2] = ((i + 1) % 8) + 8; |
| 431 |
rp->faces[i + 2].face_verts[3] = (i + 1) % 8; |
| 432 |
} |
| 433 |
|
| 434 |
// Set normals, textures and UVLs for face |
| 435 |
for (i = 0; i < 10; i++) { |
| 436 |
if (!ComputeFaceNormal(rp, i)) |
| 437 |
Int3(); // this is odd. Get Matt! |
| 438 |
rp->faces[i].tmap = i + 1; |
| 439 |
AssignDefaultUVsToRoomFace(rp, i); |
| 440 |
} |
| 441 |
|
| 442 |
return rp; |
| 443 |
} |
| 444 |
|
| 445 |
#define DEFAULT_SCRIPT "//Empty script\xd\xa" |
| 446 |
|
| 447 |
// Create a new mine with one segment |
| 448 |
void CreateNewMine() { |
| 449 |
// Get rid of old mine |
| 450 |
FreeAllRooms(); |
| 451 |
FreeAllObjects(); |
| 452 |
|
| 453 |
// Create a new room |
| 454 |
Curroomp = CreateDefaultRoom(); |
| 455 |
ASSERT(Curroomp != NULL); |
| 456 |
|
| 457 |
// Reset misc. vars |
| 458 |
Curface = Curedge = Curvert = 0; |
| 459 |
Curportal = -1; |
| 460 |
|
| 461 |
// Say that this is a new mine |
| 462 |
New_mine = 1; |
| 463 |
|
| 464 |
// Reset the view position, etc. for the wireframe view |
| 465 |
ResetWireframeView(); |
| 466 |
|
| 467 |
// Reintialize the objects |
| 468 |
ResetObjectList(); |
| 469 |
|
| 470 |
// Create the player and put him in the center of the fa |
| 471 |
CreatePlayerObject(ROOMNUM(Curroomp)); |
| 472 |
|
| 473 |
// Initialize editor viewer |
| 474 |
Editor_view_mode = VM_MINE; |
| 475 |
Editor_viewer_id = -1; |
| 476 |
|
| 477 |
// Create a camera for this level |
| 478 |
SetEditorViewer(); |
| 479 |
|
| 480 |
// Look for player objects & set player starts |
| 481 |
FindPlayerStarts(); |
| 482 |
|
| 483 |
// Clear the marked room |
| 484 |
Markedroomp = NULL; |
| 485 |
|
| 486 |
// Clear the selected segments |
| 487 |
ClearRoomSelectedList(); |
| 488 |
|
| 489 |
// Clear the placed room & group |
| 490 |
Placed_room = -1; |
| 491 |
Placed_group = NULL; |
| 492 |
|
| 493 |
// Reset the triggers |
| 494 |
Num_triggers = 0; |
| 495 |
Current_trigger = -1; |
| 496 |
|
| 497 |
// Reset the terrain |
| 498 |
ResetTerrain(1); |
| 499 |
|
| 500 |
// Reset terrain sound |
| 501 |
ClearTerrainSound(); |
| 502 |
|
| 503 |
// Clear game events |
| 504 |
ClearAllEvents(); |
| 505 |
|
| 506 |
int i; |
| 507 |
BOA_AABB_checksum = BOA_mine_checksum = 0; |
| 508 |
for (i = 0; i < MAX_ROOMS; i++) { |
| 509 |
BOA_AABB_ROOM_checksum[i] = 0; |
| 510 |
} |
| 511 |
InitGamePaths(); |
| 512 |
DestroyAllMatcens(); |
| 513 |
// Resets the ambient life controller |
| 514 |
a_life.ALReset(); |
| 515 |
Level_goals.CleanupAfterLevel(); |
| 516 |
|
| 517 |
BNode_ClearBNodeInfo(); |
| 518 |
FVI_always_check_ceiling = false; |
| 519 |
Ceiling_height = MAX_TERRAIN_HEIGHT; |
| 520 |
|
| 521 |
sound_override_force_field = -1; |
| 522 |
sound_override_glass_breaking = -1; |
| 523 |
|
| 524 |
for (i = 0; i < MAX_FORCE_FIELD_BOUNCE_TEXTURES; i++) { |
| 525 |
force_field_bounce_texture[i] = -1; |
| 526 |
force_field_bounce_multiplier[i] = 1.0f; |
| 527 |
} |
| 528 |
|
| 529 |
Level_powerups_ignore_wind = false; |
| 530 |
|
| 531 |
// Init level info |
| 532 |
strcpy(Level_info.name, "Unnamed"); |
| 533 |
strcpy(Level_info.designer, "Anonymous"); |
| 534 |
strcpy(Level_info.copyright, "Copyright (c) 1999 Outrage Entertainment, Inc."); |
| 535 |
strcpy(Level_info.notes, ""); |
| 536 |
} |
| 537 |
|
| 538 |
#include "osiris_predefs.h" |
| 539 |
|
| 540 |
// Strips leading and trailing spaces from a string |
| 541 |
// Returns true if spaces were stripped |
| 542 |
bool StripLeadingTrailingSpaces(char *s) { |
| 543 |
char *t; |
| 544 |
bool stripped = 0; |
| 545 |
|
| 546 |
// Look for leading spaces |
| 547 |
t = s; |
| 548 |
while (*t == ' ') |
| 549 |
t++; |
| 550 |
|
| 551 |
// Leading spaces found, so copy string over spaces |
| 552 |
if (t != s) { |
| 553 |
strcpy(s, t); |
| 554 |
stripped = 1; |
| 555 |
} |
| 556 |
|
| 557 |
// Strip any trailing spaces |
| 558 |
for (t = s + strlen(s) - 1; (t >= s) && (*t == ' '); t--) { |
| 559 |
*t = 0; |
| 560 |
stripped = 1; |
| 561 |
} |
| 562 |
|
| 563 |
return stripped; |
| 564 |
} |
| 565 |
|
| 566 |
// Check for duplicate names in the level |
| 567 |
void CheckLevelNames() { |
| 568 |
int i; |
| 569 |
|
| 570 |
// Check objects |
| 571 |
object *objp; |
| 572 |
for (i = 0, objp = Objects; i <= Highest_object_index; i++, objp++) { |
| 573 |
if ((objp->type != OBJ_NONE) && objp->name) { |
| 574 |
int handle = osipf_FindObjectName(objp->name); |
| 575 |
if (handle != objp->handle) |
| 576 |
EditorMessageBox("Error: Objects %d and %d are both named \"%s\"", i, OBJNUM(ObjGet(handle)), objp->name); |
| 577 |
if (StripLeadingTrailingSpaces(objp->name)) |
| 578 |
EditorMessageBox( |
| 579 |
"Note: Object %d (\"%s\") had leading and/or trailing spaces in its name that have been removed.", i, |
| 580 |
objp->name); |
| 581 |
} |
| 582 |
} |
| 583 |
|
| 584 |
// Check triggers |
| 585 |
trigger *tp; |
| 586 |
for (i = 0, tp = Triggers; i < Num_triggers; i++, tp++) { |
| 587 |
if (tp->name) { |
| 588 |
int n = osipf_FindTriggerName(tp->name); |
| 589 |
if (n != i) |
| 590 |
EditorMessageBox("Error: Triggers %d and %d are both named \"%s\"", i, n, tp->name); |
| 591 |
if (StripLeadingTrailingSpaces(tp->name)) |
| 592 |
EditorMessageBox( |
| 593 |
"Note: Trigger %d (\"%s\") had leading and/or trailing spaces in its name that have been removed.", i, |
| 594 |
tp->name); |
| 595 |
} |
| 596 |
} |
| 597 |
|
| 598 |
// Check rooms |
| 599 |
room *rp; |
| 600 |
for (i = 0, rp = Rooms; i <= Highest_room_index; i++, rp++) { |
| 601 |
if (rp->used && rp->name) { |
| 602 |
int n = osipf_FindRoomName(rp->name); |
| 603 |
if (n != i) |
| 604 |
EditorMessageBox("Error: Rooms %d and %d are both named \"%s\"", i, n, rp->name); |
| 605 |
if (StripLeadingTrailingSpaces(rp->name)) |
| 606 |
EditorMessageBox( |
| 607 |
"Note: Room %d (\"%s\") had leading and/or trailing spaces in its name that have been removed.", i, |
| 608 |
rp->name); |
| 609 |
} |
| 610 |
} |
| 611 |
} |
| 612 |
|
| 613 |
// Load a new level |
| 614 |
bool EditorLoadLevel(char *filename) { |
| 615 |
if (LoadLevel(filename)) { |
| 616 |
|
| 617 |
// Check for duplicate names in the level |
| 618 |
CheckLevelNames(); |
| 619 |
|
| 620 |
New_mine = 1; // say that this is a new mine |
| 621 |
|
| 622 |
// Set viewer object |
| 623 |
SetEditorViewer(); |
| 624 |
|
| 625 |
// Reset view radius |
| 626 |
ResetWireframeViewRad(); |
| 627 |
|
| 628 |
// Done |
| 629 |
return TRUE; |
| 630 |
} else |
| 631 |
return FALSE; |
| 632 |
} |
| 633 |
|
| 634 |
// Save the current level |
| 635 |
// Returns 1 if level saved sucessfully |
| 636 |
int EditorSaveLevel(char *filename) { |
| 637 |
int sucess; |
| 638 |
|
| 639 |
sucess = SaveLevel(filename); |
| 640 |
|
| 641 |
if (sucess) |
| 642 |
Mine_changed = 0; |
| 643 |
|
| 644 |
return sucess; |
| 645 |
} |
| 646 |
|
| 647 |
// Returns a pointer to enough spaces to right-justify a number that's printed after the spaces |
| 648 |
char *IntSpacing(int i) { |
| 649 |
static char *spaces = " "; |
| 650 |
|
| 651 |
i = abs(i); |
| 652 |
|
| 653 |
for (int n = 1; i >= 10; n++) |
| 654 |
i /= 10; |
| 655 |
|
| 656 |
ASSERT(n <= 20); |
| 657 |
|
| 658 |
return spaces + n * 2 + n / 2; |
| 659 |
} |
| 660 |
|
| 661 |
extern void dump_text_to_clipboard(char *text); |
| 662 |
|
| 663 |
// Shows the stats for a level in a messagebox, and copies to the clipboard |
| 664 |
void ShowLevelStats() { |
| 665 |
int n_rooms, n_rooms_external, n_faces, n_verts, n_objects, n_portals, n_doors, n_objects_outside; |
| 666 |
int n_object_faces, n_object_lightmap_faces; |
| 667 |
int i; |
| 668 |
room *rp; |
| 669 |
int bytes_wasted = 0, spec_faces = 0, lm_bytes = 0; |
| 670 |
int total_volume_bytes = 0; |
| 671 |
int num_redgoals = 0, num_bluegoals = 0, num_greengoals = 0, num_yellowgoals = 0; |
| 672 |
int num_sp1 = 0, num_sp2 = 0, num_sp3 = 0, num_sp4 = 0, num_sp5 = 0, num_sp6 = 0; |
| 673 |
|
| 674 |
uint8_t lightmaps_used[MAX_LIGHTMAPS]; |
| 675 |
|
| 676 |
object *objp; |
| 677 |
#define BUF_LEN 5000 |
| 678 |
char text_buf[BUF_LEN]; |
| 679 |
|
| 680 |
// Count the number of rooms, and the number of faces & points per room |
| 681 |
n_rooms = n_rooms_external = n_faces = n_verts = n_doors = n_portals = 0; |
| 682 |
for (i = 0, rp = Rooms; i <= Highest_room_index; i++, rp++) |
| 683 |
if (rp->used) { |
| 684 |
n_rooms++; |
| 685 |
n_verts += rp->num_verts; |
| 686 |
n_faces += rp->num_faces; |
| 687 |
n_portals += rp->num_portals; |
| 688 |
if (rp->flags & RF_EXTERNAL) |
| 689 |
n_rooms_external++; |
| 690 |
else { |
| 691 |
// Get volume size of room |
| 692 |
total_volume_bytes += GetVolumeSizeOfRoom(rp); |
| 693 |
} |
| 694 |
|
| 695 |
for (int t = 0; t < rp->num_faces; t++) { |
| 696 |
face *fp = &rp->faces[t]; |
| 697 |
if (fp->special_handle != BAD_SPECIAL_FACE_INDEX && GameTextures[fp->tmap].flags & TF_SPECULAR && |
| 698 |
fp->lmi_handle != BAD_LMI_INDEX) |
| 699 |
spec_faces++; |
| 700 |
} |
| 701 |
|
| 702 |
if (rp->flags & RF_DOOR) |
| 703 |
n_doors++; |
| 704 |
|
| 705 |
if (rp->flags & RF_SPECIAL1) |
| 706 |
num_sp1++; |
| 707 |
|
| 708 |
if (rp->flags & RF_SPECIAL2) |
| 709 |
num_sp2++; |
| 710 |
|
| 711 |
if (rp->flags & RF_SPECIAL3) |
| 712 |
num_sp3++; |
| 713 |
|
| 714 |
if (rp->flags & RF_SPECIAL4) |
| 715 |
num_sp4++; |
| 716 |
|
| 717 |
if (rp->flags & RF_SPECIAL5) |
| 718 |
num_sp5++; |
| 719 |
|
| 720 |
if (rp->flags & RF_SPECIAL6) |
| 721 |
num_sp6++; |
| 722 |
|
| 723 |
if (rp->flags & RF_GOAL1) |
| 724 |
num_redgoals++; |
| 725 |
|
| 726 |
if (rp->flags & RF_GOAL2) |
| 727 |
num_bluegoals++; |
| 728 |
|
| 729 |
if (rp->flags & RF_GOAL3) |
| 730 |
num_greengoals++; |
| 731 |
|
| 732 |
if (rp->flags & RF_GOAL4) |
| 733 |
num_yellowgoals++; |
| 734 |
} |
| 735 |
|
| 736 |
// Count the number of objects |
| 737 |
n_objects = n_object_faces = n_object_lightmap_faces = n_objects_outside = 0; |
| 738 |
for (i = 0, objp = Objects; i <= Highest_object_index; i++, objp++) |
| 739 |
if ((objp->type != OBJ_NONE) && (objp->type != OBJ_ROOM) && (objp->render_type == RT_POLYOBJ)) { |
| 740 |
n_objects++; |
| 741 |
if (OBJECT_OUTSIDE(objp)) |
| 742 |
n_objects_outside++; |
| 743 |
// Count the number of faces in this object |
| 744 |
poly_model *pm; |
| 745 |
pm = GetPolymodelPointer(objp->rtype.pobj_info.model_num); |
| 746 |
for (int m = 0; m < pm->n_models; m++) { |
| 747 |
n_object_faces += pm->submodel[m].num_faces; |
| 748 |
if (objp->lighting_render_type == LRT_LIGHTMAPS) |
| 749 |
n_object_lightmap_faces += pm->submodel[m].num_faces; |
| 750 |
} |
| 751 |
} |
| 752 |
|
| 753 |
memset(lightmaps_used, 0, MAX_LIGHTMAPS); |
| 754 |
for (i = 0; i < MAX_LIGHTMAP_INFOS; i++) { |
| 755 |
if (!LightmapInfo[i].used) |
| 756 |
continue; |
| 757 |
if (LightmapInfo[i].type == LMI_DYNAMIC || LightmapInfo[i].type == LMI_TERRAIN) |
| 758 |
continue; |
| 759 |
|
| 760 |
lightmaps_used[LightmapInfo[i].lm_handle] = 1; |
| 761 |
} |
| 762 |
|
| 763 |
for (i = 0; i < MAX_LIGHTMAPS; i++) { |
| 764 |
if (lightmaps_used[i]) { |
| 765 |
uint16_t *data = lm_data(i); |
| 766 |
int w = lm_w(i); |
| 767 |
int h = lm_h(i); |
| 768 |
|
| 769 |
for (int j = 0; j < w * h; j++) { |
| 770 |
if (!(data[j] & OPAQUE_FLAG)) { |
| 771 |
bytes_wasted += 2; |
| 772 |
} else { |
| 773 |
lm_bytes += 2; |
| 774 |
} |
| 775 |
} |
| 776 |
} |
| 777 |
} |
| 778 |
|
| 779 |
i = sprintf(text_buf, |
| 780 |
"Level Stats:\n" |
| 781 |
"\n" |
| 782 |
"%s%d Rooms (%d external)\n" |
| 783 |
"%s%d Faces\n" |
| 784 |
"%s%d Vertices\n" |
| 785 |
"\n" |
| 786 |
"%s%d Portals\n" |
| 787 |
"%s%d Doors\n" |
| 788 |
"\n" |
| 789 |
"%s%d Polygon Objects (%d inside, %d outside)\n" |
| 790 |
"%s%d Object Faces (%d with lightmaps)\n" |
| 791 |
"\n" |
| 792 |
"%s%d Total lightmap faces\n" |
| 793 |
"%d Total volume bytes\n" |
| 794 |
"%d Total bytes in lightmaps\n" |
| 795 |
"%d Total specular faces\n" |
| 796 |
"%d Bytes wasted in lightmaps\n" |
| 797 |
"\n" |
| 798 |
"%d Red Goals\n" |
| 799 |
"%d Blue Goals\n" |
| 800 |
"%d Green Goals\n" |
| 801 |
"%d Yellow Goals\n" |
| 802 |
"%d Special 1 Rooms\n" |
| 803 |
"%d Special 2 Rooms\n" |
| 804 |
"%d Special 3 Rooms\n" |
| 805 |
"%d Special 4 Rooms\n" |
| 806 |
"%d Special 5 Rooms\n" |
| 807 |
"%d Special 6 Rooms\n", |
| 808 |
IntSpacing(n_rooms), n_rooms, n_rooms_external, IntSpacing(n_faces), n_faces, IntSpacing(n_verts), |
| 809 |
n_verts, IntSpacing(n_portals / 2), n_portals / 2, IntSpacing(n_doors), n_doors, IntSpacing(n_objects), |
| 810 |
n_objects, n_objects - n_objects_outside, n_objects_outside, IntSpacing(n_object_faces), n_object_faces, |
| 811 |
n_object_lightmap_faces, IntSpacing(n_faces + n_object_lightmap_faces), n_faces + n_object_lightmap_faces, |
| 812 |
total_volume_bytes, lm_bytes, spec_faces, bytes_wasted, num_redgoals, num_bluegoals, num_greengoals, |
| 813 |
num_yellowgoals, num_sp1, num_sp2, num_sp3, num_sp4, num_sp5, num_sp6); |
| 814 |
|
| 815 |
ASSERT(i < BUF_LEN); |
| 816 |
|
| 817 |
dump_text_to_clipboard(text_buf); |
| 818 |
OutrageMessageBox( |
| 819 |
"%s\n\nThis info has also been posted to the clipboard.\n\nWhat other info would you like here? Let MattT know.", |
| 820 |
text_buf); |
| 821 |
} |