Debian Codegraph @

editor/TableFileFilterMng.cpp

raw symbols SCIP
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/TableFileFilterMng.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:57:39 $
23 * $Author: kevinb $
24 *
25 *
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 49 10/22/99 6:05p Jeff
30 * fixed bugs and compiler errors resulting from mac code merge
31 *
32 * 48 4/21/99 4:49p Kevin
33 *
34 * 47 4/21/99 4:18p Jason
35 * check texture sounds when determining pages
36 *
37 * 46 4/08/99 5:11p Nate
38 * Added logging of Remaining and Removed Pages during a filtering
39 *
40 * 45 3/30/99 4:42p Kevin
41 * For Matt T. -- Silly bug.
42 *
43 * 44 3/28/99 4:03p Matt
44 * Added code to handle soundsource objects
45 *
46 * 43 3/05/99 6:54p Jason
47 * fixed table file filter for sound bands
48 *
49 * 42 3/04/99 5:27p Jason
50 * added matcen stuff to table file
51 *
52 * 41 2/19/99 12:01p Jason
53 * took out sky band
54 *
55 * 40 2/17/99 7:06p Kevin
56 * OEM build setup
57 *
58 * 39 2/11/99 5:46p Kevin
59 * changes for jason
60 *
61 * 38 2/11/99 12:50p Kevin
62 * Changes for jason -- to get fireball stuff in
63 *
64 * 37 2/09/99 4:58p Nate
65 * Fixed up the TableParse file stuff
66 *
67 * 36 2/09/99 4:20p Nate
68 * Added TableParse file support
69 *
70 * 35 2/08/99 10:23a Jason
71 * made table file filter work again
72 *
73 * 34 1/22/99 3:59p Jason
74 * added 256x256 textures to help with terrain skies
75 *
76 * 33 1/21/99 11:15p Jeff
77 * pulled out some structs and defines from header files and moved them
78 * into seperate header files so that multiplayer dlls don't require major
79 * game headers, just those new headers. Side effect is a shorter build
80 * time. Also cleaned up some header file #includes that weren't needed.
81 * This affected polymodel.h, object.h, player.h, vecmat.h, room.h,
82 * manage.h and multi.h
83 *
84 * 32 1/20/99 10:50a Jason
85 * added new terrain
86 *
87 * 31 1/08/99 2:56p Samir
88 * Ripped out OSIRIS1.
89 *
90 * 30 11/05/98 7:54p Jason
91 * changes for new manage system
92 *
93 * 29 10/23/98 1:37p Nate
94 * Fixed spelling of sound page.
95 *
96 * 28 10/23/98 12:39p Nate
97 * Added a few more pages.
98 *
99 * 27 10/21/98 8:53a Nate
100 *
101 * 26 10/19/98 11:33p Nate
102 * Yet more hard coded pages to add
103 *
104 * 25 10/19/98 7:21p Nate
105 *
106 * 24 10/19/98 7:19p Matt
107 * Added system to support different types of damage to the player and
108 * have these different types make different sounds.
109 *
110 * 23 10/16/98 6:01p Nate
111 * added more hard-coded pages
112 *
113 * 22 10/16/98 11:35a Jason
114 * added some more defaults
115 *
116 * 21 10/14/98 1:02p Jason
117 * fixed FindSoundName issues
118 *
119 * 20 10/14/98 11:32a Jason
120 * added gunboy
121 *
122 * 19 10/13/98 8:41p Jason
123 * fixed cockpit problem
124 *
125 * 18 10/13/98 5:25p Nate
126 * Added ship flags
127 *
128 * 17 10/13/98 4:44p Jason
129 * added more primitives
130 *
131 * 16 10/13/98 2:32p Chris
132 * BuddyBot to GuideBot
133 *
134 * 15 10/12/98 11:38p Jeff
135 * wrapped all the Object_info[].description whenever freed...trying to
136 * find an obscure bug. Added icon_name to manage page of Generic
137 *
138 * 14 10/09/98 10:45p Jeff
139 * renamed FlagYellow bug
140 *
141 * 13 10/09/98 7:40p Jason
142 * fixed gamefile .oofs to read in their textures
143 *
144 *
145 * 12 10/09/98 1:41p Jason
146 * Hard coded more stuff for demo
147 *
148 * 11 10/09/98 10:55a Nate
149 * Fixed bug, now correctly displays which pages weren't written out to
150 * the table file
151 *
152 * 10 10/09/98 3:16a Jason
153 * more changes for demo
154 *
155 * 9 10/09/98 2:40a Jason
156 * fixed table file issues with demo
157 *
158 * 8 10/08/98 10:48p Nate
159 *
160 * 7 10/08/98 2:26p Jason
161 * added table file filter functionality
162 *
163 * 6 10/08/98 10:48a Nate
164 * Fixed memory leaks by freeing level script when done with loaded level.
165 *
166 * 5 10/08/98 10:30a Nate
167 * Initial version
168 *
169 * $NoKeywords: $
170 */
171
172 #include "stdafx.h"
173 #include "resource.h"
174 #include "TableFileFilterMng.h"
175 #include "manage.h"
176 #include "mono.h"
177 #include "LoadLevel.h"
178 #include "object.h"
179 #include "objinfo.h"
180 //@@#include "d3x.h"
181
182 #include "texpage.h"
183 #include "doorpage.h"
184 #include "soundpage.h"
185 #include "megapage.h"
186 #include "shippage.h"
187 #include "weaponpage.h"
188 #include "gamefilepage.h"
189 #include "genericpage.h"
190 #include "sounds.h"
191 #include "gametexture.h"
192 #include "terrain.h"
193 #include "fireball.h"
194 #include "mem.h"
195 #include "polymodel.h"
196 #include "ddio.h"
197 #include "DallasUtilities.h"
198 #include "matcen.h"
199 #include "game.h"
200
201 #define TITLE_NAME "Table File Filter v1.0"
202
203 // Function Prototypes
204 void DeferMessages(void);
205 void OpenFilterLogFiles(void);
206 void WriteToRemainingLog(char *name, int type);
207 void WriteToRemovedLog(char *name, int type);
208 void CloseFilterLogFiles(void);
209
210 ////////////////////////////////////////////////////////////////
211 // PageDataNode Class Members
212 ////////////////////////////////////////////////////////////////
213 PageDataNode::PageDataNode() {
214 prev = NULL;
215 next = NULL;
216
217 name[0] = '\0';
218 type = PAGETYPE_UNKNOWN;
219
220 flags = 0;
221 tag_count = 0;
222 }
223
224 PageDataNode::~PageDataNode() {}
225
226 // Performs a comparison based upon the page name
227 bool PageDataNode::operator<(const PageDataNode &node) { return (stricmp(name, node.name) < 0); }
228
229 // Loads a Page Data Node from a given stream
230 bool PageDataNode::Load(CFILE *infile) {
231 cf_ReadString(name, PAGENAME_LEN, infile);
232 type = (uint8_t)cf_ReadByte(infile);
233 flags = cf_ReadInt(infile);
234 tag_count = cf_ReadInt(infile);
235
236 return TRUE;
237 }
238
239 // Saves a Page Data Node to a given stream
240 bool PageDataNode::Save(CFILE *outfile) {
241 cf_WriteString(outfile, name);
242 cf_WriteByte(outfile, (int8_t)type);
243 cf_WriteInt(outfile, flags);
244 cf_WriteInt(outfile, tag_count);
245
246 return TRUE;
247 }
248
249 ////////////////////////////////////////////////////////////////
250 // PageDataList Class Members
251 ////////////////////////////////////////////////////////////////
252 PageDataList::PageDataList() {
253 int j;
254
255 // Init the list to be empty
256 m_head = NULL;
257 m_tail = NULL;
258 m_size = 0;
259
260 // Init the level filename list to be empty
261 m_NumLevelFilenames = 0;
262 for (j = 0; j < MAX_LEVEL_FILENAMES; j++)
263 m_LevelFilenames[j][0] = '\0';
264
265 // Init the dialog control pointers
266 m_Dlg = NULL;
267 m_TableParseFile = NULL;
268 m_PageDataListCtrl = NULL;
269 m_LevelListBox = NULL;
270 m_NumPagesText = NULL;
271 m_StatusText = NULL;
272
273 m_DataListFilename = "";
274 m_DataListLoaded = FALSE;
275 m_DataListModified = FALSE;
276 }
277
278 PageDataList::~PageDataList() {
279 // Detach the dialog control pointers
280 m_Dlg = NULL;
281 m_TableParseFile = NULL;
282 m_PageDataListCtrl = NULL;
283 m_LevelListBox = NULL;
284 m_NumPagesText = NULL;
285 m_StatusText = NULL;
286
287 ClearList();
288 }
289
290 // Wipes out the data list
291 void PageDataList::ClearList(void) {
292 PageDataNode *temp, *node;
293 int j;
294
295 CWaitCursor wc;
296
297 node = m_head;
298 while (node != NULL) {
299 temp = node;
300 node = node->next;
301 delete temp;
302 }
303 m_size = 0;
304 m_head = NULL;
305 m_tail = NULL;
306
307 // Init the level filename list to be empty
308 m_NumLevelFilenames = 0;
309 for (j = 0; j < MAX_LEVEL_FILENAMES; j++)
310 m_LevelFilenames[j][0] = '\0';
311
312 m_DataListFilename = "";
313 m_DataListLoaded = FALSE;
314 m_DataListModified = FALSE;
315
316 // Clear out the dialog data
317 if (m_PageDataListCtrl)
318 m_PageDataListCtrl->DeleteAllItems();
319 if (m_LevelListBox)
320 m_LevelListBox->ResetContent();
321 if (m_NumPagesText)
322 m_NumPagesText->Format("0");
323 if (m_StatusText)
324 m_StatusText->Format("Blank Page Data List Created");
325 if (m_Dlg)
326 m_Dlg->UpdateData(FALSE);
327 DeferMessages();
328 wc.Restore();
329 }
330
331 // Adds the node to the list in ascending alphabetical order
332 // according to the page names of the nodes
333 bool PageDataList::AddToList(PageDataNode *new_node) {
334 PageDataNode *node;
335
336 CWaitCursor wc;
337
338 if (new_node == NULL)
339 return FALSE;
340
341 // Handle empty list case
342 if (m_head == NULL) {
343 m_head = new_node;
344 m_tail = new_node;
345 new_node->next = NULL;
346 new_node->prev = NULL;
347
348 m_size++;
349 goto UpdateControls;
350 }
351
352 // Handle (new node < list head) case
353 if ((*new_node) < (*m_head)) {
354 new_node->next = m_head;
355 new_node->prev = NULL;
356 m_head->prev = new_node;
357 m_head = new_node;
358
359 m_size++;
360 goto UpdateControls;
361 }
362
363 // Search through list until end of list or until the new node is less
364 // than the next node, then add the new node after the current node
365 node = m_head;
366 while (node->next != NULL && (*(node->next)) < (*new_node))
367 node = node->next;
368
369 new_node->next = node->next;
370 new_node->prev = node;
371
372 if (node->next == NULL)
373 m_tail = new_node;
374 else
375 node->next->prev = new_node;
376
377 node->next = new_node;
378
379 m_size++;
380
381 UpdateControls:
382
383 // Add it to the data list control
384 AddToListCtrl(0, new_node);
385
386 // Update the count
387 if (m_NumPagesText)
388 m_NumPagesText->Format("%d", m_size);
389 if (m_Dlg)
390 m_Dlg->UpdateData(FALSE);
391 DeferMessages();
392 wc.Restore();
393
394 m_DataListModified = TRUE;
395
396 return TRUE;
397 }
398
399 // Creates a new node and adds it to the list (if not already in it)
400 bool PageDataList::AddToList(char *page_name, uint8_t page_type, int page_flags) {
401 PageDataNode *new_node, *found_node;
402 CWaitCursor wc;
403
404 // If the node is already in the list, don't add it!
405 found_node = FindNode(page_name, page_type);
406 if (found_node != NULL) {
407
408 // If the new node has been added for a level, tag it once
409 if (page_flags & ADDED_FOR_LEVEL_FLAG) {
410 found_node->flags |= ADDED_FOR_LEVEL_FLAG;
411 found_node->tag_count++;
412 }
413
414 // If it's been added directly by user, set that flag
415 if (page_flags & ADDED_FOR_USER_FLAG)
416 found_node->flags |= ADDED_FOR_USER_FLAG;
417
418 return TRUE;
419 }
420
421 // Allocate memory for the new node
422 new_node = new PageDataNode;
423 if (new_node == NULL) {
424 mprintf(0, "ERROR: Could not allocate new PageDataNode!\n");
425 return FALSE;
426 }
427
428 // Initialize the data
429 strcpy(new_node->name, page_name);
430 new_node->type = page_type;
431 new_node->flags = page_flags;
432 new_node->tag_count = 0;
433
434 // If the new node has been added for a level, tag it once
435 if (new_node->flags & ADDED_FOR_LEVEL_FLAG)
436 new_node->tag_count++;
437
438 // Add the new node to the list
439 AddToList(new_node);
440
441 return TRUE;
442 }
443
444 // Searches for and removes matching node from the list
445 bool PageDataList::RemoveFromList(char *page_name, uint8_t page_type) {
446 int index;
447 LVFINDINFO find_info;
448 CWaitCursor wc;
449
450 if (m_PageDataListCtrl == NULL)
451 return FALSE;
452
453 // Find and remove node from the data list
454 PageDataNode *found_node;
455 found_node = FindNode(page_name, page_type);
456 if (found_node != NULL) {
457 // If node has been "level tagged", decrement it
458 if (found_node->tag_count > 0)
459 found_node->tag_count--;
460
461 // If node is still tagged by another level, leave it
462 if (found_node->tag_count > 0)
463 return TRUE;
464
465 // Otherwise, continue and get rid of it
466 RemoveFromList(found_node);
467 }
468
469 // Find and remove item from the list control
470 find_info.flags = LVFI_STRING;
471 find_info.psz = page_name;
472 index = m_PageDataListCtrl->FindItem(&find_info, -1);
473 if (index == -1)
474 return FALSE;
475 m_PageDataListCtrl->DeleteItem(index);
476
477 return TRUE;
478 }
479
480 // Removes the given node from the list
481 bool PageDataList::RemoveFromList(PageDataNode *goner_node) {
482 CWaitCursor wc;
483
484 if (goner_node == NULL)
485 return FALSE;
486
487 // Connect previous node to the next node
488 if (goner_node->prev != NULL)
489 goner_node->prev->next = goner_node->next;
490
491 // Connect the next node to the previous node
492 if (goner_node->next != NULL)
493 goner_node->next->prev = goner_node->prev;
494
495 // If node to be removed is the head, make the next node the head
496 if (goner_node == m_head)
497 m_head = goner_node->next;
498
499 // If node to be removed is the tail, make the previous node the tail
500 if (goner_node == m_tail)
501 m_tail = goner_node->prev;
502
503 delete goner_node;
504 m_size--;
505
506 // Update the count
507 if (m_NumPagesText)
508 m_NumPagesText->Format("%d", m_size);
509 if (m_Dlg)
510 m_Dlg->UpdateData(FALSE);
511 DeferMessages();
512 wc.Restore();
513
514 m_DataListModified = TRUE;
515
516 return TRUE;
517 }
518
519 // Loads a Page Data List from a file
520 bool PageDataList::LoadList(char *list_filename) {
521 int i, list_size;
522 CFILE *infile;
523 PageDataNode *new_node;
524
525 CWaitCursor wc;
526
527 // Wipe out the current data list
528 ClearList();
529 wc.Restore();
530
531 // Try to open the file for loading
532 infile = cfopen(list_filename, "rb");
533 if (!infile) {
534 mprintf(0, "Couldn't open the input list file!\n");
535 return FALSE;
536 }
537
538 // Display "saving" message
539 m_StatusText->Format("Loading %s...", list_filename);
540 m_Dlg->UpdateData(FALSE);
541 DeferMessages();
542 wc.Restore();
543
544 // Read in the number of nodes in the list
545 list_size = cf_ReadInt(infile);
546
547 // Read in each data node to the list
548 for (i = 0; i < list_size; i++) {
549
550 // Allocate memory for the new node
551 new_node = new PageDataNode;
552 if (new_node == NULL) {
553 mprintf(0, "ERROR: Could not allocate new PageDataNode!\n");
554 return FALSE;
555 }
556
557 // Read in the node's data
558 new_node->Load(infile);
559
560 // Add the new node to the list
561 AddToList(new_node);
562 wc.Restore();
563 }
564
565 // Read in the number of level filenames
566 m_NumLevelFilenames = cf_ReadInt(infile);
567
568 // Read in each level filename
569 for (i = 0; i < m_NumLevelFilenames; i++) {
570 cf_ReadString(m_LevelFilenames[i], _MAX_PATH, infile);
571
572 // Add the filename to the list box
573 m_LevelListBox->InsertString(-1, m_LevelFilenames[i]);
574 DeferMessages();
575 wc.Restore();
576 }
577
578 // Close the saved file
579 cfclose(infile);
580
581 // Save the current filename
582 m_DataListFilename = list_filename;
583 m_DataListModified = FALSE;
584
585 // Display "saving" message
586 m_StatusText->Format("Load Complete");
587 m_Dlg->UpdateData(FALSE);
588 DeferMessages();
589 wc.Restore();
590
591 return TRUE;
592 }
593
594 // Saves a Page Data List to a file
595 bool PageDataList::SaveList(char *list_filename) {
596 int i;
597 CFILE *outfile;
598 PageDataNode *node;
599
600 CWaitCursor wc;
601
602 if (list_filename == NULL) {
603 if (!FilenameSpecified())
604 return FALSE;
605 list_filename = m_DataListFilename.GetBuffer(0);
606 }
607
608 // Try to open the file for saving
609 outfile = cfopen(list_filename, "wb");
610 if (!outfile) {
611 mprintf(0, "Couldn't open the output list file!\n");
612 return FALSE;
613 }
614
615 // Display "saving" message
616 m_StatusText->Format("Saving %s...", list_filename);
617 m_Dlg->UpdateData(FALSE);
618 DeferMessages();
619 wc.Restore();
620
621 // Write out the number of nodes in the list
622 cf_WriteInt(outfile, m_size);
623
624 // Write out each data node in the list
625 node = m_head;
626 for (i = 0; i < m_size; i++) {
627 node->Save(outfile);
628 node = node->next;
629 }
630
631 // Write out the number of level filenames
632 cf_WriteInt(outfile, m_NumLevelFilenames);
633
634 // Write out each level filename
635 for (i = 0; i < m_NumLevelFilenames; i++)
636 cf_WriteString(outfile, m_LevelFilenames[i]);
637
638 // Close the saved file
639 cfclose(outfile);
640
641 // Save the current filename
642 m_DataListFilename = list_filename;
643 m_DataListModified = FALSE;
644
645 // Display "saving" message
646 m_StatusText->Format("Save Complete");
647 m_Dlg->UpdateData(FALSE);
648 DeferMessages();
649 wc.Restore();
650
651 return TRUE;
652 }
653
654 // Scans the list for a certain page, and returns a pointer to the
655 // matching data node (or NULL if not found)
656 PageDataNode *PageDataList::FindNode(char *page_name, uint8_t page_type) {
657 PageDataNode *node, *found_node;
658
659 found_node = NULL;
660 node = m_head;
661 while (node != NULL) {
662 if (node->type == page_type && stricmp(node->name, page_name) == 0) {
663 found_node = node;
664 break;
665 }
666 node = node->next;
667 }
668
669 return (found_node);
670 }
671
672 // Adds a level filename to the filename list (and to the dialog list box)
673 bool PageDataList::AddLevelFilename(char *level_filename) {
674 int i, level_found;
675
676 CWaitCursor wc;
677
678 if (level_filename == NULL)
679 return FALSE;
680
681 // Make sure the level hasn't already been added
682 level_found = -1;
683 for (i = 0; i < m_NumLevelFilenames; i++)
684 if (stricmp(m_LevelFilenames[i], level_filename) == 0)
685 level_found = i;
686
687 if (level_found >= 0)
688 return FALSE;
689
690 // Add the filename to the list
691 if (m_NumLevelFilenames >= MAX_LEVEL_FILENAMES)
692 return FALSE;
693 strcpy(m_LevelFilenames[m_NumLevelFilenames], level_filename);
694 m_NumLevelFilenames++;
695
696 // Add the filename to the list box
697 m_LevelListBox->InsertString(-1, level_filename);
698
699 // Add the pages required by this level
700 ProcessPagesForLevel(level_filename, ADD_PAGES);
701 wc.Restore();
702
703 m_DataListModified = TRUE;
704
705 return TRUE;
706 }
707
708 // Removes the selected level from the filename list (and from the dialog list box)
709 bool PageDataList::RemoveSelLevelFilename(void) {
710 int i, level_found;
711 int index;
712 CString level_filename;
713
714 CWaitCursor wc;
715
716 if (m_LevelListBox == NULL)
717 return FALSE;
718
719 index = m_LevelListBox->GetCurSel();
720 if (index == LB_ERR)
721 return FALSE;
722 m_LevelListBox->GetText(index, level_filename);
723
724 // Find the level position in the filename list
725 level_found = -1;
726 for (i = 0; i < m_NumLevelFilenames; i++)
727 if (stricmp(m_LevelFilenames[i], level_filename.GetBuffer(0)) == 0)
728 level_found = i;
729
730 if (level_found < 0)
731 return FALSE;
732
733 // Remove the filename from the list
734 for (i = level_found; i < m_NumLevelFilenames - 1; i++)
735 strcpy(m_LevelFilenames[i], m_LevelFilenames[i + 1]);
736 m_NumLevelFilenames--;
737
738 // Remove the filename from the list box
739 m_LevelListBox->DeleteString(index);
740
741 // Remove the pages required by this level
742 ProcessPagesForLevel(level_filename.GetBuffer(0), REMOVE_PAGES);
743 wc.Restore();
744
745 m_DataListModified = TRUE;
746
747 return TRUE;
748 }
749
750 char *gamefile_level_ext[] = {".d3l", ".cpp", ".dll", ".msg", ".omf", ".brf", ".str", ".msn", NULL};
751
752 // Processes all pages needed by the given level
753 bool PageDataList::ProcessPagesForLevel(char *level_filename, int process_type) {
754 CWaitCursor wc;
755
756 if (level_filename == NULL)
757 return FALSE;
758
759 m_StatusText->Format("Loading level - %s...", level_filename);
760 m_Dlg->UpdateData(FALSE);
761 DeferMessages();
762 wc.Restore();
763
764 // Load the given level
765 if (!LoadLevel(level_filename)) {
766 m_Dlg->MessageBox("Error loading level", "Level Load Error");
767 return FALSE;
768 }
769
770 m_StatusText->Format("Processing level - %s...", level_filename);
771 m_NumPagesText->Format("%d", m_size);
772 m_Dlg->UpdateData(FALSE);
773 DeferMessages();
774 wc.Restore();
775
776 // Process level, adding pages that it requires
777 DetermineRequiredPages(process_type);
778
779 // Add Level's gamefile pages
780 char filename[_MAX_FNAME + 1];
781 char pagename[_MAX_PATH + 1];
782
783 _splitpath(level_filename, NULL, NULL, filename, NULL);
784 for (int j = 0; gamefile_level_ext[j] != NULL; j++) {
785 sprintf(pagename, "%s%s", filename, gamefile_level_ext[j]);
786 ProcessPage(pagename, PAGETYPE_GAMEFILE, process_type);
787 }
788
789 wc.Restore();
790
791 m_StatusText->Format("Processing Complete", level_filename);
792 m_Dlg->UpdateData(FALSE);
793 DeferMessages();
794 wc.Restore();
795
796 return TRUE;
797 }
798
799 // Either adds the given level page to the list, or removes it
800 bool PageDataList::ProcessPage(char *page_name, uint8_t page_type, int process_type, int flags) {
801 CWaitCursor wc;
802
803 switch (process_type) {
804 case ADD_PAGES:
805 AddToList(page_name, page_type, ADDED_FOR_LEVEL_FLAG);
806 break;
807 case REMOVE_PAGES:
808 RemoveFromList(page_name, page_type);
809 break;
810 default:
811 break;
812 }
813
814 m_NumPagesText->Format("%d", m_size);
815 m_Dlg->UpdateData(FALSE);
816 DeferMessages();
817 wc.Restore();
818
819 return TRUE;
820 }
821
822 // Get extension of a file
823 bool GetFileExt(char *file, char *ext) {
824 char *temp;
825 if (strlen(file) < 4)
826 return FALSE;
827
828 temp = (file + strlen(file) - 4);
829 strcpy(ext, temp);
830
831 if (ext[0] != '.')
832 return FALSE;
833
834 return TRUE;
835 }
836
837 // Determines what pages are required by the currently loaded level,
838 // and processes each one appropriately
839
840 void PageDataList::AddTexturePage(int id, int process_type) {
841 if (id == -1)
842 return;
843
844 CWaitCursor wc;
845 ProcessPage(GameTextures[id].name, PAGETYPE_TEXTURE, process_type);
846 wc.Restore();
847
848 if (GameTextures[id].flags & TF_DESTROYABLE && GameTextures[id].destroy_handle != -1) {
849 AddTexturePage(GameTextures[id].destroy_handle, process_type);
850 }
851
852 if (GameTextures[id].sound != -1)
853 AddSoundPage(GameTextures[id].sound, process_type);
854 }
855
856 void PageDataList::AddSoundPage(int id, int process_type) {
857 if (id == -1)
858 return;
859
860 CWaitCursor wc;
861 ProcessPage(Sounds[id].name, PAGETYPE_SOUND, process_type);
862 wc.Restore();
863 }
864
865 void PageDataList::AddDoorPage(int id, int process_type) {
866 CWaitCursor wc;
867 // Set sounds
868 door *doorpointer = &Doors[id];
869
870 ProcessPage(Doors[id].name, PAGETYPE_DOOR, process_type);
871 wc.Restore();
872
873 PageInPolymodel(doorpointer->model_handle);
874 poly_model *pm = &Poly_models[doorpointer->model_handle];
875 for (int t = 0; t < pm->n_textures; t++)
876 AddTexturePage(pm->textures[t], process_type);
877
878 if (doorpointer->open_sound != -1 && doorpointer->open_sound != SOUND_NONE_INDEX)
879 AddSoundPage(doorpointer->open_sound, process_type);
880 if (doorpointer->close_sound != -1 && doorpointer->close_sound != SOUND_NONE_INDEX)
881 AddSoundPage(doorpointer->close_sound, process_type);
882 }
883
884 void PageDataList::AddWeaponPage(int id, int process_type) {
885 CWaitCursor wc;
886 weapon *weaponpointer = &Weapons[id];
887
888 if (id == -1)
889 return;
890
891 int i;
892 ProcessPage(Weapons[id].name, PAGETYPE_WEAPON, process_type);
893 wc.Restore();
894
895 if (!(weaponpointer->flags & (WF_IMAGE_BITMAP | WF_IMAGE_VCLIP))) {
896 PageInPolymodel(weaponpointer->fire_image_handle);
897 poly_model *pm = &Poly_models[weaponpointer->fire_image_handle];
898 for (int t = 0; t < pm->n_textures; t++)
899 AddTexturePage(pm->textures[t], process_type);
900 }
901
902 // Load the various textures associated with this weapon
903 if (weaponpointer->explode_image_handle != -1) {
904 AddTexturePage(weaponpointer->explode_image_handle, process_type);
905 }
906
907 if (weaponpointer->particle_handle != -1) {
908 AddTexturePage(weaponpointer->particle_handle, process_type);
909 }
910
911 if (weaponpointer->smoke_handle != -1) {
912 AddTexturePage(weaponpointer->smoke_handle, process_type);
913 }
914
915 if (weaponpointer->scorch_handle != -1) {
916 AddTexturePage(weaponpointer->scorch_handle, process_type);
917 }
918
919 if (weaponpointer->icon_handle != -1) {
920 AddTexturePage(weaponpointer->icon_handle, process_type);
921 }
922
923 // Try to load spawn weapons
924 if (weaponpointer->spawn_handle != -1 && weaponpointer->spawn_count > 0 && weaponpointer->spawn_handle != id) {
925 AddWeaponPage(weaponpointer->spawn_handle, process_type);
926 }
927
928 if (weaponpointer->alternate_spawn_handle != -1 && weaponpointer->spawn_count > 0 &&
929 weaponpointer->alternate_spawn_handle != id) {
930 AddWeaponPage(weaponpointer->alternate_spawn_handle, process_type);
931 }
932
933 if (weaponpointer->robot_spawn_handle != -1) {
934 AddGenericPage(weaponpointer->robot_spawn_handle, process_type);
935 }
936
937 // Try and load the various sounds
938 for (i = 0; i < MAX_WEAPON_SOUNDS; i++) {
939 if (weaponpointer->sounds[i] != SOUND_NONE_INDEX) {
940 AddSoundPage(weaponpointer->sounds[i], process_type);
941 }
942 }
943 }
944
945 void PageDataList::AddShipPage(int id, int process_type) {
946 int i, t;
947 CWaitCursor wc;
948
949 ProcessPage(Ships[id].name, PAGETYPE_SHIP, process_type);
950 wc.Restore();
951
952 ship *shippointer = &Ships[id];
953
954 // Page in all textures for this object
955
956 PageInPolymodel(shippointer->model_handle);
957 poly_model *pm = &Poly_models[shippointer->model_handle];
958
959 for (t = 0; t < pm->n_textures; t++)
960 AddTexturePage(pm->textures[t], process_type);
961
962 if (shippointer->med_render_handle != -1) {
963 PageInPolymodel(shippointer->med_render_handle);
964 pm = &Poly_models[shippointer->med_render_handle];
965 for (t = 0; t < pm->n_textures; t++)
966 AddTexturePage(pm->textures[t], process_type);
967 }
968
969 if (shippointer->lo_render_handle != -1) {
970 PageInPolymodel(shippointer->lo_render_handle);
971 pm = &Poly_models[shippointer->lo_render_handle];
972 for (t = 0; t < pm->n_textures; t++)
973 AddTexturePage(pm->textures[t], process_type);
974 }
975
976 if (shippointer->dying_model_handle != -1) {
977 PageInPolymodel(shippointer->dying_model_handle);
978 pm = &Poly_models[shippointer->dying_model_handle];
979 for (t = 0; t < pm->n_textures; t++)
980 AddTexturePage(pm->textures[t], process_type);
981 }
982
983 // Try and load the various weapons
984 int j;
985 for (i = 0; i < MAX_PLAYER_WEAPONS; i++) {
986 for (j = 0; j < MAX_WB_GUNPOINTS; j++) {
987 if (shippointer->static_wb[i].gp_weapon_index[j] != LASER_INDEX) {
988 AddWeaponPage(shippointer->static_wb[i].gp_weapon_index[j], process_type);
989 }
990 }
991 }
992
993 // Try and load the various weapons
994 for (i = 0; i < MAX_PLAYER_WEAPONS; i++) {
995 for (j = 0; j < MAX_WB_FIRING_MASKS; j++) {
996 if (shippointer->static_wb[i].fm_fire_sound_index[j] != SOUND_NONE_INDEX)
997 AddSoundPage(shippointer->static_wb[i].fm_fire_sound_index[j], process_type);
998 }
999 }
1000
1001 for (i = 0; i < MAX_PLAYER_WEAPONS; i++) {
1002 if (shippointer->firing_sound[i] != -1)
1003 AddSoundPage(shippointer->firing_sound[i], process_type);
1004
1005 if (shippointer->firing_release_sound[i] != -1)
1006 AddSoundPage(shippointer->firing_release_sound[i], process_type);
1007
1008 if (shippointer->spew_powerup[i] != -1)
1009 AddGenericPage(shippointer->spew_powerup[i], process_type);
1010 }
1011 }
1012
1013 void PageDataList::AddGenericPage(int id, int process_type) {
1014 int i, t;
1015 CWaitCursor wc;
1016
1017 if (id == -1)
1018 return;
1019
1020 ProcessPage(Object_info[id].name, PAGETYPE_GENERIC, process_type);
1021 wc.Restore();
1022
1023 object_info *objinfopointer = &Object_info[id];
1024
1025 // Page in all textures for this object
1026
1027 PageInPolymodel(objinfopointer->render_handle);
1028 poly_model *pm = &Poly_models[objinfopointer->render_handle];
1029
1030 for (t = 0; t < pm->n_textures; t++)
1031 AddTexturePage(pm->textures[t], process_type);
1032
1033 if (objinfopointer->med_render_handle != -1) {
1034 PageInPolymodel(objinfopointer->med_render_handle);
1035 pm = &Poly_models[objinfopointer->med_render_handle];
1036 for (t = 0; t < pm->n_textures; t++)
1037 AddTexturePage(pm->textures[t], process_type);
1038 }
1039
1040 if (objinfopointer->lo_render_handle != -1) {
1041 PageInPolymodel(objinfopointer->lo_render_handle);
1042 pm = &Poly_models[objinfopointer->lo_render_handle];
1043 for (t = 0; t < pm->n_textures; t++)
1044 AddTexturePage(pm->textures[t], process_type);
1045 }
1046
1047 // Process all sounds for this object
1048 for (i = 0; i < MAX_OBJ_SOUNDS; i++) {
1049 if (objinfopointer->sounds[i] != SOUND_NONE_INDEX) {
1050 AddSoundPage(objinfopointer->sounds[i], process_type);
1051 }
1052 }
1053
1054 for (i = 0; i < MAX_AI_SOUNDS; i++) {
1055 if (objinfopointer->ai_info->sound[i] != SOUND_NONE_INDEX) {
1056 AddSoundPage(objinfopointer->ai_info->sound[i], process_type);
1057 }
1058 }
1059
1060 // Try and load the various wb sounds
1061 int j;
1062 for (i = 0; i < MAX_WBS_PER_OBJ; i++) {
1063 for (j = 0; j < MAX_WB_FIRING_MASKS; j++) {
1064 if (objinfopointer->static_wb[i].fm_fire_sound_index[j] != SOUND_NONE_INDEX) {
1065 AddSoundPage(objinfopointer->static_wb[i].fm_fire_sound_index[j], process_type);
1066 }
1067 }
1068 }
1069
1070 // Try and load the various wb sounds
1071 for (i = 0; i < NUM_MOVEMENT_CLASSES; i++) {
1072 for (j = 0; j < NUM_ANIMS_PER_CLASS; j++) {
1073 if (objinfopointer->anim[i].elem[j].anim_sound_index != SOUND_NONE_INDEX) {
1074 AddSoundPage(objinfopointer->anim[i].elem[j].anim_sound_index, process_type);
1075 }
1076 }
1077 }
1078
1079 // Load the spew types
1080 for (i = 0; i < MAX_DSPEW_TYPES; i++) {
1081 if (objinfopointer->dspew_number[i] > 0 && objinfopointer->dspew[i] != 0 && objinfopointer->dspew[i] != id) {
1082 AddGenericPage(objinfopointer->dspew[i], process_type);
1083 }
1084 }
1085
1086 // Try and load the various weapons
1087
1088 // Automatically include laser
1089 AddWeaponPage(LASER_INDEX, process_type);
1090
1091 for (i = 0; i < MAX_WBS_PER_OBJ; i++) {
1092 for (j = 0; j < MAX_WB_GUNPOINTS; j++) {
1093 if (objinfopointer->static_wb[i].gp_weapon_index[j] != LASER_INDEX) {
1094 AddWeaponPage(objinfopointer->static_wb[i].gp_weapon_index[j], process_type);
1095 }
1096 }
1097 }
1098 }
1099
1100 extern const char *Static_sound_names[];
1101 bool PageDataList::DetermineRequiredPages(int process_type) {
1102 CWaitCursor wc;
1103 CString filename;
1104 int i;
1105
1106 ////////////////////////////////////////////////////////////
1107 // Note to Jason:
1108 //
1109 // For every page needed by the level call these functions:
1110 // ProcessPage(page_name,page_type,process_type);
1111 // wc.Restore();
1112 ////////////////////////////////////////////////////////////
1113
1114 // Processes all the pages in the TableParse output file
1115 m_TableParseFile->GetWindowText(filename);
1116 ProcessPagesInTextFile(filename.GetBuffer(0), process_type);
1117
1118 /* SHOULDN'T NEED THE FOLLOWING ANYMORE
1119
1120 // Add all the other files
1121 char ext[12];
1122 for(i=0;i<MAX_GAMEFILES;i++)
1123 {
1124 if(Gamefiles[i].used != 0)
1125 {
1126 GetFileExt(Gamefiles[i].name,ext);
1127
1128 if (stricmp(ext,".d3l"))
1129 {
1130 AddToList(Gamefiles[i].name,PAGETYPE_GAMEFILE,process_type);
1131 }
1132
1133 if (!stricmp(ext,".oof"))
1134 {
1135 int pid=LoadPolyModel (Gamefiles[i].name,0);
1136 if (pid!=-1)
1137 {
1138 PageInPolymodel (pid);
1139 poly_model *pm=&Poly_models[pid];
1140 for (int t=0;t<pm->n_textures;t++)
1141 AddTexturePage (pm->textures[t],process_type);
1142 }
1143 else
1144 {
1145 mprintf(0,"Couldn't find polymodel %s!\n",Gamefiles[i].name);
1146 Int3();
1147 }
1148 }
1149 }
1150 }
1151
1152 // Get misc pages
1153
1154 AddSoundPage (FindSoundName ("AmbSwitch31"),process_type);
1155 AddSoundPage (FindSoundName ("AmbLavaLoop1"),process_type);
1156
1157 AddTexturePage (FindTextureName("Ready1"),process_type);
1158 AddTexturePage (FindTextureName("Online"),process_type);
1159
1160
1161 AddTexturePage (FindTextureName("hilite0"),process_type);
1162 AddTexturePage (FindTextureName("hilite1"),process_type);
1163 AddTexturePage (FindTextureName("hilite2"),process_type);
1164 AddTexturePage (FindTextureName("hilite3"),process_type);
1165 AddTexturePage (FindTextureName("hilite4"),process_type);
1166 AddTexturePage (FindTextureName("hilite5"),process_type);
1167
1168 AddTexturePage (FindTextureName("smhilite01"),process_type);
1169 AddTexturePage (FindTextureName("smhilite11"),process_type);
1170 AddTexturePage (FindTextureName("smhilite21"),process_type);
1171 AddTexturePage (FindTextureName("smhilite31"),process_type);
1172 AddTexturePage (FindTextureName("smhilite41"),process_type);
1173 AddTexturePage (FindTextureName("smhilite51"),process_type);
1174 AddTexturePage (FindTextureName("smhilite61"),process_type);
1175 AddTexturePage (FindTextureName("smhilite71"),process_type);
1176
1177 AddWeaponPage (FindWeaponName ("GunBoy"),process_type);
1178 AddWeaponPage (FindWeaponName ("FragBarrel"),process_type);
1179 AddWeaponPage (FindWeaponName ("NapalmBarrel"),process_type);
1180 AddWeaponPage (FindWeaponName ("TubbsHitBlast"),process_type);
1181 AddWeaponPage (FindWeaponName ("ChaffSpark"),process_type);
1182 AddWeaponPage (FindWeaponName ("NapalmBlob"),process_type);
1183
1184 AddGenericPage (FindObjectIDName ("ShipRedFlag"),process_type);
1185 AddGenericPage (FindObjectIDName ("ShipBlueFlag"),process_type);
1186 AddGenericPage (FindObjectIDName ("ShipYellowFlag"),process_type);
1187 AddGenericPage (FindObjectIDName ("ShipGreenFlag"),process_type);
1188 AddGenericPage (FindObjectIDName ("GuideBot"),process_type);
1189 AddGenericPage (FindObjectIDName ("SmallDebris"),process_type);
1190 AddGenericPage (FindObjectIDName ("BigDebris"),process_type);
1191 AddGenericPage (FindObjectIDName ("VirusHousing"),process_type);
1192 AddGenericPage (FindObjectIDName ("Afterburner"),process_type);
1193 AddGenericPage (FindObjectIDName ("attached light bulb"),process_type);
1194 AddGenericPage (FindObjectIDName ("GuideBot"),process_type);
1195 AddGenericPage (FindObjectIDName ("ChaffChunk"),process_type);
1196 AddGenericPage (FindObjectIDName ("Jugghead"),process_type);
1197 AddGenericPage (FindObjectIDName ("Jugg main turret"),process_type);
1198 AddGenericPage (FindObjectIDName ("Juggbelly"),process_type);
1199 AddGenericPage (FindObjectIDName ("Jugg flame turret"),process_type);
1200 AddGenericPage (FindObjectIDName ("Trackerhatch"),process_type);
1201 AddGenericPage (FindObjectIDName ("Trackerturret"),process_type);
1202 AddGenericPage (FindObjectIDName ("Pesttail"),process_type);
1203 AddGenericPage (FindObjectIDName ("Aliencuplinkhousing"),process_type);
1204
1205 AddTexturePage (FindTextureName("LightFlareStar"),process_type);
1206 AddTexturePage (FindTextureName("TelcomPowerBar"),process_type);
1207 AddTexturePage (FindTextureName("Matcen Lightning"),process_type);
1208 AddTexturePage (FindTextureName("WhiteGlowingBall"),process_type);
1209 AddTexturePage (FindTextureName("SkyDome10"),process_type);
1210 AddTexturePage (FindTextureName("SkyBand10"),process_type);
1211 AddTexturePage (FindTextureName("Multicolor"),process_type);
1212
1213 AddSoundPage (FindSoundName ("Energy Converter"),process_type);
1214 AddSoundPage (FindSoundName ("CockpitSequenceTest1"),process_type);
1215 AddSoundPage (FindSoundName ("Player hit by weapon"),process_type);
1216 AddSoundPage (FindSoundName ("Metallic Door Hit"),process_type);
1217 AddSoundPage (FindSoundName ("Wall Fade ???"),process_type);
1218 AddSoundPage (FindSoundName ("RainDrop"),process_type);
1219 AddSoundPage (FindSoundName ("Lightning"),process_type);
1220 AddSoundPage (FindSoundName ("AmbSwitch31"),process_type);
1221 AddSoundPage (FindSoundName ("AmbLavaLoop1"),process_type);
1222 AddSoundPage (FindSoundName ("Invulnerability on"),process_type);
1223 AddSoundPage (FindSoundName ("Invulnerability off"),process_type);
1224 AddSoundPage (FindSoundName ("Cloak on"),process_type);
1225 AddSoundPage (FindSoundName ("Cloak off"),process_type);
1226 AddSoundPage (FindSoundName ("GBotConcern1"),process_type);
1227 AddSoundPage (FindSoundName ("Drop bomb"),process_type);
1228 AddSoundPage (FindSoundName ("RbtStingeattack1"),process_type);
1229
1230 AddSoundPage (FindSoundName ("AmbDroneV"),process_type);
1231 AddSoundPage (FindSoundName ("AmbDroneR"),process_type);
1232 AddSoundPage (FindSoundName ("AmbDroneO"),process_type);
1233 AddSoundPage (FindSoundName ("AmbDroneN"),process_type);
1234 AddSoundPage (FindSoundName ("AmbDroneI"),process_type);
1235 AddSoundPage (FindSoundName ("AmbDroneK"),process_type);
1236 AddSoundPage (FindSoundName ("AmbDroneM"),process_type);
1237 AddSoundPage (FindSoundName ("AmbDroneX"),process_type);
1238 AddSoundPage (FindSoundName ("AmbDroneQ"),process_type);
1239 AddSoundPage (FindSoundName ("AmbDroneL"),process_type);
1240 AddSoundPage (FindSoundName ("AmbDroneF"),process_type);
1241 AddSoundPage (FindSoundName ("AmbDroneS"),process_type);
1242 AddSoundPage (FindSoundName ("AmbDroneD"),process_type);
1243 AddSoundPage (FindSoundName ("AmbDroneU"),process_type);
1244 AddSoundPage (FindSoundName ("AmbDroneH"),process_type);
1245 AddSoundPage (FindSoundName ("rainhigh1"),process_type);
1246 AddSoundPage (FindSoundName ("rainlow1"),process_type);
1247 AddSoundPage (FindSoundName ("AmbWindGust"),process_type);
1248 AddSoundPage (FindSoundName ("AmbVirusSwitch"),process_type);
1249 AddSoundPage (FindSoundName ("VoxCompAutoSecurity.osf"),process_type);
1250 AddSoundPage (FindSoundName ("CTFHatTrick"),process_type);
1251
1252 AddSoundPage (FindSoundName ("CTFPickupFlag1"),process_type);
1253 AddSoundPage (FindSoundName ("CTFScore1"),process_type);
1254 AddSoundPage (FindSoundName ("CTFLostFlag1"),process_type);
1255 AddSoundPage (FindSoundName ("CTFReturnedFlag1"),process_type);
1256 AddSoundPage (FindSoundName ("Cheater!"),process_type);
1257 AddSoundPage (FindSoundName ("Hostage pickup"),process_type);
1258
1259 AddGenericPage (FindObjectIDName ("Converter"),process_type);
1260 AddGenericPage (FindObjectIDName ("Shield"),process_type);
1261 AddGenericPage (FindObjectIDName ("Energy"),process_type);
1262
1263 AddGenericPage (FindObjectIDName ("Afterburner"),process_type);
1264 AddGenericPage (FindObjectIDName ("Attached light bulb"),process_type);
1265 AddGenericPage (FindObjectIDName ("ChaffChunk"),process_type);
1266 AddGenericPage (FindObjectIDName ("TrackerHatch"),process_type);
1267 AddGenericPage (FindObjectIDName ("TrackerTurret"),process_type);
1268 AddGenericPage (FindObjectIDName ("PestTail"),process_type);
1269 AddGenericPage (FindObjectIDName ("Virushousing"),process_type);
1270 AddGenericPage (FindObjectIDName ("Viruscartridge"),process_type);
1271
1272 AddWeaponPage (FindWeaponName ("TubbsHitBlast"),process_type);
1273
1274 AddShipPage (FindShipName ("Pyro-SE"),process_type);
1275
1276 AddGenericPage (FindObjectIDName ("FlagRed"),process_type);
1277 AddGenericPage (FindObjectIDName ("FlagBlue"),process_type);
1278 AddGenericPage (FindObjectIDName ("FlagGreen"),process_type);
1279 AddGenericPage (FindObjectIDName ("FlagYellow"),process_type);
1280
1281 AddTexturePage (FindTextureName("RedBase"),process_type);
1282 AddTexturePage (FindTextureName("BlueBase"),process_type);
1283 AddTexturePage (FindTextureName("YellowBase"),process_type);
1284 AddTexturePage (FindTextureName("GreenBase"),process_type);
1285
1286 AddTexturePage (FindTextureName("Multicolor"),process_type);
1287 */
1288
1289 // Add in matcen stuff
1290 for (i = 0; i < Num_matcens; i++) {
1291 int t;
1292 AddTexturePage(Matcen[i]->GetCreationTexture(), process_type);
1293 for (t = 0; t < MAX_MATCEN_SOUNDS; t++)
1294 AddSoundPage(Matcen[i]->GetSound(t), process_type);
1295
1296 for (t = 0; t < Matcen[i]->GetNumProdTypes(); t++) {
1297 int index;
1298 Matcen[i]->GetProdInfo(t, &index, NULL, NULL, NULL);
1299 if (index != MATCEN_ERROR)
1300 AddGenericPage(index, process_type);
1301 }
1302 }
1303
1304 for (i = 0; i < NUM_TERRAIN_SOUND_BANDS; i++) {
1305 if (Terrain_sound_bands[i].sound_index != -1)
1306 AddSoundPage(Terrain_sound_bands[i].sound_index, process_type);
1307 }
1308
1309 // Get static fireballs
1310 for (i = 0; i < NUM_FIREBALLS; i++) {
1311 char name[PAGENAME_LEN];
1312 strcpy(name, Fireballs[i].name);
1313
1314 name[strlen(name) - 4] = 0;
1315 int id = FindTextureName(name);
1316 if (id != -1)
1317 AddTexturePage(id, process_type);
1318 else
1319 AddToList(Fireballs[i].name, PAGETYPE_GAMEFILE, process_type);
1320 }
1321
1322 // Get static sounds
1323 for (i = 0; i < NUM_STATIC_SOUNDS; i++) {
1324 int sid = FindSoundName(Static_sound_names[i]);
1325
1326 if (sid != -1)
1327 AddSoundPage(sid, process_type);
1328 }
1329
1330 // First get textures
1331 for (i = 0; i <= Highest_room_index; i++) {
1332 if (!Rooms[i].used)
1333 continue;
1334
1335 room *rp = &Rooms[i];
1336 for (int t = 0; t < rp->num_faces; t++) {
1337 AddTexturePage(rp->faces[t].tmap, process_type);
1338 }
1339 }
1340
1341 // Touch all terrain textures
1342 for (i = 0; i < TERRAIN_TEX_WIDTH * TERRAIN_TEX_DEPTH; i++) {
1343 AddTexturePage(Terrain_tex_seg[i].tex_index, process_type);
1344 }
1345
1346 AddTexturePage(Terrain_sky.dome_texture, process_type);
1347
1348 for (i = 0; i < Terrain_sky.num_satellites; i++) {
1349 AddTexturePage(Terrain_sky.satellite_texture[i], process_type);
1350 }
1351
1352 // Touch all objects
1353 for (i = 0; i <= Highest_object_index; i++) {
1354 object *obj = &Objects[i];
1355
1356 if (obj->type == OBJ_NONE) {
1357 continue;
1358 }
1359 if (obj->type == OBJ_POWERUP || obj->type == OBJ_ROBOT || obj->type == OBJ_CLUTTER || obj->type == OBJ_BUILDING) {
1360 AddGenericPage(obj->id, process_type);
1361 continue;
1362 }
1363
1364 if (obj->type == OBJ_DOOR) {
1365 AddDoorPage(obj->id, process_type);
1366 continue;
1367 }
1368
1369 if (obj->control_type == CT_SOUNDSOURCE) {
1370 ASSERT(obj->type == OBJ_SOUNDSOURCE);
1371 if (obj->ctype.soundsource_info.sound_index != -1)
1372 AddSoundPage(obj->ctype.soundsource_info.sound_index, process_type);
1373 }
1374 }
1375
1376 return TRUE;
1377 }
1378
1379 // Creates the new table file by filtering out any pages that
1380 // are not in the current page data list
1381 bool PageDataList::CreateNewTableFile(char *new_table_filename, char *src_table_filename) {
1382 CFILE *infile, *outfile;
1383 uint8_t pagetype, replaced = 0;
1384 int done = 0, len;
1385 int pages_written;
1386 PageDataNode *node;
1387 CString summary_msg;
1388 bool unwritten_page_found;
1389 char ext[12];
1390
1391 mngs_texture_page texpage;
1392 //@@mngs_power_page powpage;
1393 mngs_door_page doorpage;
1394 //@@mngs_robot_page robotpage;
1395 mngs_generic_page genericpage;
1396 mngs_gamefile_page gamefilepage;
1397 mngs_sound_page soundpage;
1398 mngs_ship_page shippage;
1399 mngs_weapon_page weaponpage;
1400 mngs_megacell_page megacellpage;
1401
1402 CWaitCursor wc;
1403
1404 if (new_table_filename == NULL || src_table_filename == NULL)
1405 return FALSE;
1406
1407 if (m_StatusText)
1408 m_StatusText->Format("Creating new table file - %s...", new_table_filename);
1409 if (m_Dlg)
1410 m_Dlg->UpdateData(FALSE);
1411 DeferMessages();
1412 wc.Restore();
1413
1414 // First make sure we can open the table file and the temp table file
1415 infile = cfopen(src_table_filename, "rb");
1416 if (!infile) {
1417 mprintf(0, "Couldn't open input table file!\n");
1418 return FALSE;
1419 }
1420
1421 outfile = cfopen(new_table_filename, "wb");
1422 if (!outfile) {
1423 mprintf(0, "Couldn't open output table file!\n");
1424 cfclose(infile);
1425 return FALSE;
1426 }
1427
1428 // Mark all pages in data list as not having been written out
1429 for (node = m_head; node != NULL; node = node->next)
1430 node->flags &= ~PAGE_WRITTEN_FLAG;
1431
1432 OpenFilterLogFiles();
1433
1434 // Read in every page from the source table file, but only write
1435 // out a page to the new table file if the same page name (and type)
1436 // are found in the current page data list
1437 pages_written = 0;
1438 while (!done) {
1439 if (cfeof(infile)) {
1440 done = 1;
1441 continue;
1442 }
1443 pagetype = cf_ReadByte(infile);
1444 len = cf_ReadInt(infile);
1445
1446 switch (pagetype) {
1447 case PAGETYPE_TEXTURE:
1448 // Read it in, write it out.
1449 mng_ReadNewTexturePage(infile, &texpage);
1450 if ((node = FindNode(texpage.tex_struct.name, pagetype)) != NULL) {
1451 WriteToRemainingLog(texpage.tex_struct.name, pagetype);
1452 mng_WriteNewTexturePage(outfile, &texpage);
1453 node->flags |= PAGE_WRITTEN_FLAG;
1454 pages_written++;
1455 } else {
1456 WriteToRemovedLog(texpage.tex_struct.name, pagetype);
1457 }
1458 break;
1459 case PAGETYPE_POWERUP:
1460 // Read it in, write it out.
1461 //@@mng_ReadPowerPage (infile,&powpage);
1462 //@@mng_WritePowerPage (outfile,&powpage);
1463 if (m_Dlg)
1464 m_Dlg->MessageBox("A Powerup page was encountered in the source table file", "Powerup Page Encountered");
1465 break;
1466 case PAGETYPE_DOOR:
1467 // Read it in, write it out.
1468 mng_ReadNewDoorPage(infile, &doorpage);
1469 if ((node = FindNode(doorpage.door_struct.name, pagetype)) != NULL) {
1470 WriteToRemainingLog(doorpage.door_struct.name, pagetype);
1471 mng_WriteNewDoorPage(outfile, &doorpage);
1472 node->flags |= PAGE_WRITTEN_FLAG;
1473 pages_written++;
1474 } else {
1475 WriteToRemovedLog(doorpage.door_struct.name, pagetype);
1476 }
1477 break;
1478 case PAGETYPE_ROBOT:
1479 // Read it in, write it out.
1480 //@@mng_ReadRobotPage (infile,&robotpage);
1481 //@@mng_WriteRobotPage (outfile,&robotpage);
1482 if (m_Dlg)
1483 m_Dlg->MessageBox("A Robot page was encountered in the source table file", "Robot Page Encountered");
1484 break;
1485 case PAGETYPE_GENERIC:
1486 // Read it in, write it out.
1487 mng_ReadNewGenericPage(infile, &genericpage);
1488 if ((node = FindNode(genericpage.objinfo_struct.name, pagetype)) != NULL) {
1489 WriteToRemainingLog(genericpage.objinfo_struct.name, pagetype);
1490 mng_WriteNewGenericPage(outfile, &genericpage);
1491 node->flags |= PAGE_WRITTEN_FLAG;
1492 pages_written++;
1493 } else {
1494 WriteToRemovedLog(genericpage.objinfo_struct.name, pagetype);
1495 }
1496 if (genericpage.objinfo_struct.description != NULL) {
1497 mem_free(genericpage.objinfo_struct.description);
1498 genericpage.objinfo_struct.description = NULL;
1499 }
1500 break;
1501 case PAGETYPE_GAMEFILE:
1502 // Read it in, write it out.
1503 mng_ReadNewGamefilePage(infile, &gamefilepage);
1504 node = NULL;
1505 strcpy(ext, "");
1506 if ((node = FindNode(gamefilepage.gamefile_struct.name, pagetype)) != NULL || ALWAYS_WRITE_GAMEFILE_PAGES) {
1507 // if(GetFileExt(gamefilepage.gamefile_struct.name,ext) && stricmp(ext,".d3l")!=0) {
1508 WriteToRemainingLog(gamefilepage.gamefile_struct.name, pagetype);
1509 mng_WriteNewGamefilePage(outfile, &gamefilepage);
1510 if (node)
1511 node->flags |= PAGE_WRITTEN_FLAG;
1512 pages_written++;
1513 //} else {
1514 // WriteToRemovedLog(gamefilepage.gamefile_struct.name,pagetype);
1515 //}
1516 } else {
1517 WriteToRemovedLog(gamefilepage.gamefile_struct.name, pagetype);
1518 }
1519 break;
1520 case PAGETYPE_SOUND:
1521 // Read it in, write it out.
1522 mng_ReadNewSoundPage(infile, &soundpage);
1523 if ((node = FindNode(soundpage.sound_struct.name, pagetype)) != NULL) {
1524 WriteToRemainingLog(soundpage.sound_struct.name, pagetype);
1525 mng_WriteNewSoundPage(outfile, &soundpage);
1526 node->flags |= PAGE_WRITTEN_FLAG;
1527 pages_written++;
1528 } else {
1529 WriteToRemovedLog(soundpage.sound_struct.name, pagetype);
1530 }
1531 break;
1532 case PAGETYPE_MEGACELL:
1533 // Read it in, write it out.
1534 mng_ReadNewMegacellPage(infile, &megacellpage);
1535 if ((node = FindNode(megacellpage.megacell_struct.name, pagetype)) != NULL) {
1536 WriteToRemainingLog(megacellpage.megacell_struct.name, pagetype);
1537 mng_WriteNewMegacellPage(outfile, &megacellpage);
1538 node->flags |= PAGE_WRITTEN_FLAG;
1539 pages_written++;
1540 } else {
1541 WriteToRemovedLog(megacellpage.megacell_struct.name, pagetype);
1542 }
1543 break;
1544 case PAGETYPE_SHIP:
1545 // Read it in, write it out.
1546 mng_ReadNewShipPage(infile, &shippage);
1547 if ((node = FindNode(shippage.ship_struct.name, pagetype)) != NULL) {
1548 WriteToRemainingLog(shippage.ship_struct.name, pagetype);
1549 mng_WriteNewShipPage(outfile, &shippage);
1550 node->flags |= PAGE_WRITTEN_FLAG;
1551 pages_written++;
1552 } else {
1553 WriteToRemovedLog(shippage.ship_struct.name, pagetype);
1554 }
1555 break;
1556 case PAGETYPE_WEAPON:
1557 // Read it in, write it out.
1558 mng_ReadNewWeaponPage(infile, &weaponpage);
1559 if ((node = FindNode(weaponpage.weapon_struct.name, pagetype)) != NULL) {
1560 WriteToRemainingLog(weaponpage.weapon_struct.name, pagetype);
1561 mng_WriteNewWeaponPage(outfile, &weaponpage);
1562 node->flags |= PAGE_WRITTEN_FLAG;
1563 pages_written++;
1564 } else {
1565 WriteToRemovedLog(weaponpage.weapon_struct.name, pagetype);
1566 }
1567 break;
1568 case PAGETYPE_UNKNOWN:
1569 WriteToRemainingLog("Unknown", pagetype);
1570 mng_WriteUnknownPage(outfile);
1571 break;
1572 default:
1573 Int3(); // unrecognized pagetype
1574 break;
1575 }
1576 }
1577
1578 CloseFilterLogFiles();
1579
1580 cfclose(infile);
1581 cfclose(outfile);
1582
1583 if (m_StatusText)
1584 m_StatusText->Format("New Table File Created (%d pages)", pages_written);
1585 if (m_Dlg)
1586 m_Dlg->UpdateData(FALSE);
1587 DeferMessages();
1588
1589 // Create message summary (if some pages weren't written)
1590 unwritten_page_found = FALSE;
1591 summary_msg = "The following pages were not written out (they were not found in the source table file):\n\n";
1592 for (node = m_head; node != NULL; node = node->next) {
1593 if (node->flags & PAGE_WRITTEN_FLAG)
1594 continue;
1595
1596 // This node was not written out!
1597 unwritten_page_found = TRUE;
1598 CString temp_str;
1599 temp_str.Format("%s, ", node->name);
1600 summary_msg += temp_str;
1601 }
1602
1603 // Display message summary (if some pages weren't written)
1604 if (unwritten_page_found)
1605 if (m_Dlg)
1606 m_Dlg->MessageBox(summary_msg, "Not All Pages Were Written");
1607
1608 // Mark all pages in data list as not having been written out
1609 for (node = m_head; node != NULL; node = node->next)
1610 node->flags &= ~PAGE_WRITTEN_FLAG;
1611
1612 return TRUE; // successful!
1613 }
1614
1615 // Inserts data from the given node into the dialog list control
1616 bool PageDataList::AddToListCtrl(int index, PageDataNode *node) {
1617 int pos;
1618 CString type_text;
1619
1620 CWaitCursor wc;
1621
1622 // Make sure this is worth doing
1623 if (node == NULL)
1624 return FALSE;
1625 if (m_PageDataListCtrl == NULL)
1626 return FALSE;
1627
1628 // Add the data to the list control
1629 if ((pos = m_PageDataListCtrl->InsertItem(0, node->name)) == -1)
1630 return FALSE;
1631
1632 switch (node->type) {
1633 case PAGETYPE_UNKNOWN:
1634 type_text = "Unknown";
1635 break;
1636 case PAGETYPE_TEXTURE:
1637 type_text = "Texture";
1638 break;
1639 case PAGETYPE_WEAPON:
1640 type_text = "Weapon";
1641 break;
1642 case PAGETYPE_ROBOT:
1643 type_text = "Robot";
1644 break;
1645 case PAGETYPE_POWERUP:
1646 type_text = "Powerup";
1647 break;
1648 case PAGETYPE_DOOR:
1649 type_text = "Door";
1650 break;
1651 case PAGETYPE_SHIP:
1652 type_text = "Ship";
1653 break;
1654 case PAGETYPE_SOUND:
1655 type_text = "Sound";
1656 break;
1657 case PAGETYPE_MEGACELL:
1658 type_text = "Megacell";
1659 break;
1660 case PAGETYPE_GAMEFILE:
1661 type_text = "Gamefile";
1662 break;
1663 case PAGETYPE_GENERIC:
1664 type_text = "Generic";
1665 break;
1666 }
1667
1668 m_PageDataListCtrl->SetItem(pos, PAGE_TYPE_COLUMN, LVIF_TEXT, type_text.GetBuffer(0), 0, 0, 0, 0);
1669
1670 return TRUE;
1671 }
1672
1673 // Removes all selected items from the list control
1674 bool PageDataList::RemoveSelFromListCtrl(void) {
1675 int j, num_items;
1676 LV_ITEM item_info;
1677
1678 char name[PAGENAME_LEN + 1];
1679 char type[_MAX_PATH + 1];
1680
1681 CWaitCursor wc;
1682
1683 if (m_PageDataListCtrl == NULL)
1684 return FALSE;
1685
1686 // How many items in the control list?
1687 num_items = m_PageDataListCtrl->GetItemCount();
1688
1689 j = 0;
1690 while (j < num_items) {
1691
1692 // Grab the info for item #j
1693 item_info.iItem = j;
1694 item_info.iSubItem = 0;
1695 item_info.mask = LVIF_TEXT | LVIF_STATE;
1696 item_info.stateMask = LVIS_SELECTED;
1697 item_info.pszText = name;
1698 item_info.cchTextMax = PSFILENAME_LEN + 1;
1699 m_PageDataListCtrl->GetItem(&item_info);
1700
1701 // Is item at index j selected?
1702 if (item_info.state & LVIS_SELECTED) { // yes, delete it
1703
1704 // Get Directory name for item #j
1705 item_info.iSubItem = PAGE_TYPE_COLUMN;
1706 item_info.pszText = type;
1707 item_info.cchTextMax = _MAX_PATH;
1708 m_PageDataListCtrl->GetItem(&item_info);
1709
1710 int page_type;
1711 if (stricmp(type, "Unknown") == 0)
1712 page_type = PAGETYPE_UNKNOWN;
1713 else if (stricmp(type, "Texture") == 0)
1714 page_type = PAGETYPE_TEXTURE;
1715 else if (stricmp(type, "Weapon") == 0)
1716 page_type = PAGETYPE_WEAPON;
1717 else if (stricmp(type, "Robot") == 0)
1718 page_type = PAGETYPE_ROBOT;
1719 else if (stricmp(type, "Powerup") == 0)
1720 page_type = PAGETYPE_POWERUP;
1721 else if (stricmp(type, "Door") == 0)
1722 page_type = PAGETYPE_DOOR;
1723 else if (stricmp(type, "Ship") == 0)
1724 page_type = PAGETYPE_SHIP;
1725 else if (stricmp(type, "Sound") == 0)
1726 page_type = PAGETYPE_SOUND;
1727 else if (stricmp(type, "Megacell") == 0)
1728 page_type = PAGETYPE_MEGACELL;
1729 else if (stricmp(type, "Gamefile") == 0)
1730 page_type = PAGETYPE_GAMEFILE;
1731 else
1732 page_type = PAGETYPE_GENERIC;
1733
1734 // Search for and remove corresponding entry from Document Library
1735 PageDataNode *found_node;
1736 found_node = FindNode(name, page_type);
1737 if (found_node != NULL) {
1738 RemoveFromList(found_node);
1739 wc.Restore();
1740 } else {
1741 if (m_Dlg)
1742 m_Dlg->MessageBox("The list control does not match the data list.", "List Mismatch Error!");
1743 wc.Restore();
1744 }
1745
1746 // Delete entry/item from control list
1747 m_PageDataListCtrl->DeleteItem(j);
1748 num_items = m_PageDataListCtrl->GetItemCount();
1749
1750 } else
1751 j++;
1752 }
1753
1754 return TRUE;
1755 }
1756
1757 // Displays the modified confirmation prompt if appropriate
1758 int PageDataList::ModifiedPrompt(void) {
1759 if (m_Dlg == NULL)
1760 return (IDNO);
1761
1762 // If current file has been modified, check with user first...
1763 if (!m_DataListModified)
1764 return (IDYES);
1765 if (m_Dlg->MessageBox("Changes to data list will be lost. Proceed?", "Page Data List Has Been Modified", MB_YESNO) ==
1766 IDYES)
1767 return (IDYES);
1768 return (IDNO);
1769 }
1770
1771 // Sets the title bar string
1772 void PageDataList::SetTitleString(void) {
1773 if (m_Dlg == NULL)
1774 return;
1775
1776 char title[1024];
1777 char loaded_file[1024];
1778
1779 if (!m_DataListFilename.IsEmpty())
1780 sprintf(loaded_file, " - [%s%s]", m_DataListFilename.GetBuffer(0), (m_DataListModified) ? "*" : "");
1781 else
1782 sprintf(loaded_file, "");
1783
1784 sprintf(title, "%s%s", TITLE_NAME, loaded_file);
1785 m_Dlg->SetWindowText(title);
1786 }
1787
1788 // Adds a page specified by the "Add Page" button
1789 bool PageDataList::AddPageFromUser(char *page_name, uint8_t page_type) {
1790 int id;
1791 switch (page_type) {
1792 case PAGETYPE_GENERIC:
1793 id = FindObjectIDName(page_name);
1794 if (id == -1)
1795 return FALSE;
1796 AddGenericPage(id, ADD_PAGES);
1797 break;
1798
1799 case PAGETYPE_TEXTURE:
1800 id = FindTextureName(page_name);
1801 if (id == -1)
1802 return FALSE;
1803 AddTexturePage(id, ADD_PAGES);
1804 break;
1805
1806 case PAGETYPE_SOUND:
1807 id = FindSoundName(page_name);
1808 if (id == -1)
1809 return FALSE;
1810 AddSoundPage(id, ADD_PAGES);
1811 break;
1812
1813 case PAGETYPE_DOOR:
1814 id = FindDoorName(page_name);
1815 if (id == -1)
1816 return FALSE;
1817 AddDoorPage(id, ADD_PAGES);
1818 break;
1819
1820 case PAGETYPE_SHIP:
1821 id = FindShipName(page_name);
1822 if (id == -1)
1823 return FALSE;
1824 AddShipPage(id, ADD_PAGES);
1825 break;
1826
1827 case PAGETYPE_WEAPON:
1828 id = FindWeaponName(page_name);
1829 if (id == -1)
1830 return FALSE;
1831 AddWeaponPage(id, ADD_PAGES);
1832 break;
1833
1834 default:
1835 return FALSE;
1836 }
1837
1838 return TRUE;
1839 }
1840
1841 // Returns the pagetype for a given string (PAGETYPE_UNKNOWN if not valid)
1842 uint8_t PageDataList::GetPageTypeFromString(char *text) {
1843 int type;
1844
1845 if (text == NULL)
1846 return (PAGETYPE_UNKNOWN);
1847
1848 type = PAGETYPE_UNKNOWN;
1849 if (strcmp(text, "PAGETYPE_SOUND") == 0)
1850 type = PAGETYPE_SOUND;
1851 else if (strcmp(text, "PAGETYPE_GENERIC") == 0)
1852 type = PAGETYPE_GENERIC;
1853 else if (strcmp(text, "PAGETYPE_WEAPON") == 0)
1854 type = PAGETYPE_WEAPON;
1855 else if (strcmp(text, "PAGETYPE_GAMEFILE") == 0)
1856 type = PAGETYPE_GAMEFILE;
1857 else if (strcmp(text, "PAGETYPE_TEXTURE") == 0)
1858 type = PAGETYPE_TEXTURE;
1859 else if (strcmp(text, "PAGETYPE_DOOR") == 0)
1860 type = PAGETYPE_DOOR;
1861 else if (strcmp(text, "PAGETYPE_SHIP") == 0)
1862 type = PAGETYPE_SHIP;
1863
1864 return (type);
1865 }
1866
1867 // Processes a page read in from text file
1868 bool PageDataList::ProcessPageFromFile(char *page_name, uint8_t page_type, int process_type) {
1869 char ext[12];
1870 int id;
1871 switch (page_type) {
1872 case PAGETYPE_GENERIC:
1873 id = FindObjectIDName(page_name);
1874 if (id == -1)
1875 return FALSE;
1876 AddGenericPage(id, process_type);
1877 break;
1878
1879 case PAGETYPE_TEXTURE:
1880 id = FindTextureName(page_name);
1881 if (id == -1)
1882 return FALSE;
1883 AddTexturePage(id, process_type);
1884 break;
1885
1886 case PAGETYPE_SOUND:
1887 id = FindSoundName(page_name);
1888 if (id == -1)
1889 return FALSE;
1890 AddSoundPage(id, process_type);
1891 break;
1892
1893 case PAGETYPE_DOOR:
1894 id = FindDoorName(page_name);
1895 if (id == -1)
1896 return FALSE;
1897 AddDoorPage(id, process_type);
1898 break;
1899
1900 case PAGETYPE_SHIP:
1901 id = FindShipName(page_name);
1902 if (id == -1)
1903 return FALSE;
1904 AddShipPage(id, process_type);
1905 break;
1906
1907 case PAGETYPE_WEAPON:
1908 id = FindWeaponName(page_name);
1909 if (id == -1)
1910 return FALSE;
1911 AddWeaponPage(id, process_type);
1912 break;
1913
1914 case PAGETYPE_GAMEFILE:
1915 GetFileExt(page_name, ext);
1916
1917 // if (stricmp(ext,".d3l"))
1918 //{
1919 ProcessPage(page_name, PAGETYPE_GAMEFILE, process_type);
1920 //}
1921
1922 if (!stricmp(ext, ".oof")) {
1923 int pid = LoadPolyModel(page_name, 0);
1924 if (pid != -1) {
1925 PageInPolymodel(pid);
1926 poly_model *pm = &Poly_models[pid];
1927 for (int t = 0; t < pm->n_textures; t++)
1928 AddTexturePage(pm->textures[t], process_type);
1929 } else {
1930 mprintf(0, "Couldn't find polymodel %s!\n", page_name);
1931 Int3();
1932 }
1933 }
1934 break;
1935
1936 default:
1937 return FALSE;
1938 }
1939
1940 return TRUE;
1941 }
1942
1943 // Scans one of Jeff's TableParse output files and processes
1944 // all of the pages contained within
1945 bool PageDataList::ProcessPagesInTextFile(char *filename, int process_type) {
1946 CFILE *infile;
1947 char linebuf[2048];
1948 char *line;
1949 int linenum;
1950
1951 char *pagename;
1952 uint8_t pagetype;
1953 char *pagetype_text;
1954
1955 CString pages_not_added;
1956 int num_pages_not_added;
1957
1958 // Try to open the file for loading
1959 infile = cfopen(filename, "rt");
1960 if (!infile) {
1961 CString msg;
1962 msg.Format("Unable to open \"%s\"!", filename);
1963 m_Dlg->MessageBox(msg, "TableParse Output File Error!", MB_OK | MB_ICONEXCLAMATION);
1964 return FALSE;
1965 }
1966
1967 linenum = 0;
1968 pages_not_added = "The following pages were not processed successfully:\n\n";
1969 num_pages_not_added = 0;
1970
1971 // Read in and parse each line of the file
1972 while (!cfeof(infile)) {
1973
1974 // Clear the buffer
1975 strcpy(linebuf, "");
1976
1977 // Read in a line from the file
1978 cf_ReadString(linebuf, sizeof(linebuf), infile);
1979 linenum++;
1980
1981 // Remove whitespace padding at start and end of line
1982 RemoveTrailingWhitespace(linebuf);
1983 line = SkipInitialWhitespace(linebuf);
1984
1985 // If the line is empty, grab a new one
1986 if (strlen(line) == 0)
1987 continue;
1988
1989 // Grab the page type
1990 line = strtok(line, " \t\n");
1991 if (line == NULL)
1992 continue;
1993 pagetype = GetPageTypeFromString(line);
1994 if (pagetype == PAGETYPE_UNKNOWN) {
1995 CString msg;
1996 msg.Format("Found invalid page type: %s, in %s, line %d", line, filename, linenum);
1997 m_Dlg->MessageBox(msg, "Invalid Page Type", MB_OK | MB_ICONEXCLAMATION);
1998 continue;
1999 }
2000 pagetype_text = line;
2001
2002 // Grab the page name
2003 pagename = strtok(NULL, "");
2004 if (pagename == NULL || strlen(pagename) == 0) {
2005 CString msg;
2006 msg.Format("No page name found in %s, line %d", filename, linenum);
2007 m_Dlg->MessageBox(msg, "Invalid Page Name", MB_OK | MB_ICONEXCLAMATION);
2008 continue;
2009 }
2010
2011 // remove quotes
2012 if (pagename[0] == '"') {
2013 char *end_of_name;
2014
2015 pagename++;
2016 end_of_name = strchr(pagename, '"');
2017 if (end_of_name != NULL)
2018 (*end_of_name) = '\0';
2019 }
2020
2021 // Make sure we still have a name
2022 if (strlen(pagename) == 0) {
2023 CString msg;
2024 msg.Format("No page name found in %s, line %d", filename, linenum);
2025 m_Dlg->MessageBox(msg, "Invalid Page Name", MB_OK | MB_ICONEXCLAMATION);
2026 continue;
2027 }
2028
2029 // Try and add the page
2030 if (!ProcessPageFromFile(pagename, pagetype, process_type)) {
2031 CString msg;
2032 msg.Format("%s(%s), ", pagename, pagetype_text);
2033 if (num_pages_not_added < 30)
2034 pages_not_added += msg;
2035 else if (num_pages_not_added == 30)
2036 pages_not_added += "and even more...";
2037 num_pages_not_added++;
2038 }
2039 }
2040
2041 cfclose(infile);
2042 /*
2043 if(num_pages_not_added>0) {
2044 m_Dlg->MessageBox(pages_not_added,"Not All Pages From File Were Processed",MB_OK|MB_ICONEXCLAMATION);
2045 }
2046 */
2047 return TRUE;
2048 }
2049
2050 // Adds all appropriate gamefiles to the list
2051 bool PageDataList::AddAllGamefilePages(void) {
2052 int i;
2053 char ext[12];
2054
2055 for (i = 0; i < MAX_GAMEFILES; i++) {
2056 if (Gamefiles[i].used != 0 && GetFileExt(Gamefiles[i].name, ext) && stricmp(ext, ".d3l") != 0) {
2057 AddToList(Gamefiles[i].name, PAGETYPE_GAMEFILE, ADDED_FOR_LEVEL_FLAG);
2058 }
2059 }
2060 return TRUE;
2061 }
2062
2063 // Processes any waiting messages
2064 #define MAX_MESSAGES 10 // max messages to process during a message deferral
2065 void DeferMessages(void) {
2066 MSG msg;
2067 for (int MsgCount = MAX_MESSAGES; MsgCount && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); MsgCount--) {
2068 TranslateMessage(&msg);
2069 DispatchMessage(&msg);
2070 }
2071 }
2072
2073 // Log file handles
2074 CFILE *remaining_log_file = NULL;
2075 CFILE *removed_log_file = NULL;
2076
2077 // Opens the Filter Log Files
2078 void OpenFilterLogFiles(void) {
2079 char fullpath[_MAX_PATH + 1];
2080
2081 ddio_MakePath(fullpath, LocalD3Dir, "Remaining Pages.txt", NULL);
2082 remaining_log_file = cfopen(fullpath, "wt");
2083 if (remaining_log_file == NULL) {
2084 mprintf(0, "Couldn't open \"Remaining Pages\" log file!\n");
2085 return;
2086 }
2087
2088 ddio_MakePath(fullpath, LocalD3Dir, "Removed Pages.txt", NULL);
2089 removed_log_file = cfopen(fullpath, "wt");
2090 if (removed_log_file == NULL) {
2091 mprintf(0, "Couldn't open \"Removed Pages\" log file!\n");
2092 return;
2093 }
2094 }
2095
2096 // Returns the pagetype string for a given type
2097 void GetPageTypeString(int type, CString &type_text) {
2098 switch (type) {
2099 case PAGETYPE_TEXTURE:
2100 type_text = "Texture ";
2101 break;
2102 case PAGETYPE_WEAPON:
2103 type_text = "Weapon ";
2104 break;
2105 case PAGETYPE_ROBOT:
2106 type_text = "Robot ";
2107 break;
2108 case PAGETYPE_POWERUP:
2109 type_text = "Powerup ";
2110 break;
2111 case PAGETYPE_DOOR:
2112 type_text = "Door ";
2113 break;
2114 case PAGETYPE_SHIP:
2115 type_text = "Ship ";
2116 break;
2117 case PAGETYPE_SOUND:
2118 type_text = "Sound ";
2119 break;
2120 case PAGETYPE_MEGACELL:
2121 type_text = "Megacell";
2122 break;
2123 case PAGETYPE_GAMEFILE:
2124 type_text = "Gamefile";
2125 break;
2126 case PAGETYPE_GENERIC:
2127 type_text = "Generic ";
2128 break;
2129 default:
2130 type_text = "Unknown ";
2131 break;
2132 }
2133 }
2134
2135 // Writes a page to the "remaining pages" log file
2136 void WriteToRemainingLog(char *name, int type) {
2137 if (remaining_log_file != NULL) {
2138 CString line, type_string;
2139 GetPageTypeString(type, type_string);
2140 line.Format("%s\t%s", type_string, name);
2141 cf_WriteString(remaining_log_file, line.GetBuffer(0));
2142 }
2143 }
2144
2145 // Writes a page to the "removed pages" log file
2146 void WriteToRemovedLog(char *name, int type) {
2147 if (removed_log_file != NULL) {
2148 CString line, type_string;
2149 GetPageTypeString(type, type_string);
2150 line.Format("%s\t%s", type_string, name);
2151 cf_WriteString(removed_log_file, line.GetBuffer(0));
2152 }
2153 }
2154
2155 // Closes the Filter Log Files
2156 void CloseFilterLogFiles(void) {
2157 if (remaining_log_file != NULL)
2158 cfclose(remaining_log_file);
2159 if (removed_log_file != NULL)
2160 cfclose(removed_log_file);
2161 }