| 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/selectedroom.cpp $ |
| 21 |
* $Revision: 1.1.1.1 $ |
| 22 |
* $Date: 2003-08-26 03:57:39 $ |
| 23 |
* $Author: kevinb $ |
| 24 |
* |
| 25 |
* Functions for dealing with selected list |
| 26 |
* |
| 27 |
* $Log: not supported by cvs2svn $ |
| 28 |
* |
| 29 |
* 10 4/16/99 5:18p Matt |
| 30 |
* Don't free selected list memory if none was allocated. |
| 31 |
* |
| 32 |
* 9 4/11/99 2:41a Jeff |
| 33 |
* had to include stdafx.h for neweditor |
| 34 |
* |
| 35 |
* 8 4/07/99 7:07p Gwar |
| 36 |
* added #define NEWEDITOR checks |
| 37 |
* |
| 38 |
* 7 1/21/99 11:15p Jeff |
| 39 |
* pulled out some structs and defines from header files and moved them |
| 40 |
* into seperate header files so that multiplayer dlls don't require major |
| 41 |
* game headers, just those new headers. Side effect is a shorter build |
| 42 |
* time. Also cleaned up some header file #includes that weren't needed. |
| 43 |
* This affected polymodel.h, object.h, player.h, vecmat.h, room.h, |
| 44 |
* manage.h and multi.h |
| 45 |
* |
| 46 |
* 6 10/08/98 4:24p Kevin |
| 47 |
* Changed code to comply with memory library usage. Always use mem_malloc |
| 48 |
* , mem_free and mem_strdup |
| 49 |
* |
| 50 |
* 5 12/23/97 1:33p Samir |
| 51 |
* Added pserror.h |
| 52 |
* |
| 53 |
* 4 9/04/97 4:39p Matt |
| 54 |
* Added includes needed as a result of removing includes from d3edit.h |
| 55 |
* |
| 56 |
* 3 8/29/97 5:26p Matt |
| 57 |
* Fixed name of ClearRoomSelectedList() |
| 58 |
* |
| 59 |
* 2 7/31/97 3:31p Jason |
| 60 |
* added functions to rotate portal rooms |
| 61 |
* |
| 62 |
* 1 7/31/97 10:35a Jason |
| 63 |
* |
| 64 |
* $NoKeywords: $ |
| 65 |
*/ |
| 66 |
|
| 67 |
#include "selectedroom.h" |
| 68 |
|
| 69 |
#ifdef NEWEDITOR |
| 70 |
#include "../neweditor/stdafx.h" |
| 71 |
#include "../neweditor/globals.h" |
| 72 |
#else |
| 73 |
#include "d3edit.h" |
| 74 |
#endif |
| 75 |
|
| 76 |
#include "room.h" |
| 77 |
#include "pserror.h" |
| 78 |
#include "mem.h" |
| 79 |
|
| 80 |
// Returns true if a room is in the selected list |
| 81 |
int IsRoomSelected(int roomnum) { |
| 82 |
int i; |
| 83 |
|
| 84 |
for (i = 0; i < N_selected_rooms; i++) |
| 85 |
if (Selected_rooms[i] == roomnum) |
| 86 |
return 1; |
| 87 |
|
| 88 |
return 0; |
| 89 |
} |
| 90 |
|
| 91 |
// Adds a room to the selected list, if it's not already there |
| 92 |
void AddRoomToSelectedList(int roomnum) { |
| 93 |
if (!IsRoomSelected(roomnum)) { |
| 94 |
Selected_rooms[N_selected_rooms++] = roomnum; |
| 95 |
State_changed = 1; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
// Removes a room from the selected list, if it's there |
| 100 |
void RemoveRoomFromSelectedList(int roomnum) { |
| 101 |
int i; |
| 102 |
|
| 103 |
for (i = 0; i < N_selected_rooms; i++) |
| 104 |
if (Selected_rooms[i] == roomnum) { |
| 105 |
int j; |
| 106 |
for (j = i; j < N_selected_rooms - 1; j++) |
| 107 |
Selected_rooms[j] = Selected_rooms[j + 1]; |
| 108 |
N_selected_rooms--; |
| 109 |
State_changed = 1; |
| 110 |
return; |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
// Empties the selected list |
| 115 |
void ClearRoomSelectedList() { |
| 116 |
N_selected_rooms = 0; |
| 117 |
State_changed = 1; |
| 118 |
} |
| 119 |
|
| 120 |
// Adds to selected list if not already in there, else removes from list |
| 121 |
// Returns: 1 if room was selected, 0 if un-selected |
| 122 |
int ToggleRoomSelectedState(int roomnum) { |
| 123 |
int i; |
| 124 |
|
| 125 |
State_changed = 1; |
| 126 |
|
| 127 |
for (i = 0; i < N_selected_rooms; i++) |
| 128 |
if (Selected_rooms[i] == roomnum) { |
| 129 |
int j; |
| 130 |
for (j = i; j < N_selected_rooms - 1; j++) |
| 131 |
Selected_rooms[j] = Selected_rooms[j + 1]; |
| 132 |
N_selected_rooms--; |
| 133 |
return 0; // room was un-selected |
| 134 |
} |
| 135 |
|
| 136 |
// not found, so add to list |
| 137 |
Selected_rooms[N_selected_rooms++] = roomnum; |
| 138 |
|
| 139 |
return 1; // room was selected |
| 140 |
} |
| 141 |
|
| 142 |
// Add all the connected room to the selected list |
| 143 |
// Parameters: room - the starting room |
| 144 |
// Returns: the number of rooms added to the list |
| 145 |
int SelectConnectedRooms(int roomnum) { |
| 146 |
int count; |
| 147 |
int s; |
| 148 |
|
| 149 |
if (IsRoomSelected(roomnum)) // this room already selected? |
| 150 |
return 0; |
| 151 |
|
| 152 |
// Add this rooom to selected list |
| 153 |
Selected_rooms[N_selected_rooms++] = roomnum; |
| 154 |
count = 1; |
| 155 |
|
| 156 |
State_changed = 1; |
| 157 |
|
| 158 |
// Now add this room's children |
| 159 |
for (s = 0; s < Rooms[roomnum].num_portals; s++) { |
| 160 |
if (Rooms[roomnum].portals[s].croom != -1) |
| 161 |
count += SelectConnectedRooms(Rooms[roomnum].portals[s].croom); |
| 162 |
} |
| 163 |
|
| 164 |
return count; |
| 165 |
} |
| 166 |
|
| 167 |
static int *Save_selected_rooms; |
| 168 |
static int N_save_selected_rooms = -1; //-1 means empty list |
| 169 |
|
| 170 |
// Save the (user's) selected list so that an internal function can use it |
| 171 |
// You must call RestoreSelectedList() when you're done with the selected list |
| 172 |
void SaveRoomSelectedList() { |
| 173 |
int i; |
| 174 |
|
| 175 |
if (N_save_selected_rooms != -1) { // already have saved list? |
| 176 |
Int3(); //..yes, error |
| 177 |
return; |
| 178 |
} |
| 179 |
|
| 180 |
N_save_selected_rooms = N_selected_rooms; |
| 181 |
|
| 182 |
if (!N_save_selected_rooms) // are there any rooms in the list? |
| 183 |
return; //..no, so don't bother to save them |
| 184 |
|
| 185 |
Save_selected_rooms = (int *)mem_malloc(N_save_selected_rooms * sizeof(*Save_selected_rooms)); |
| 186 |
|
| 187 |
ASSERT(Save_selected_rooms != NULL); |
| 188 |
|
| 189 |
for (i = 0; i < N_selected_rooms; i++) |
| 190 |
Save_selected_rooms[i] = Selected_rooms[i]; |
| 191 |
} |
| 192 |
|
| 193 |
// Restore a previously-saved selected list. You must have previously called SaveSelectedList() |
| 194 |
void RestoreRoomSelectedList() { |
| 195 |
int i; |
| 196 |
|
| 197 |
if (N_save_selected_rooms == -1) { // no save list? |
| 198 |
Int3(); //..then generate error |
| 199 |
return; |
| 200 |
} |
| 201 |
|
| 202 |
N_selected_rooms = N_save_selected_rooms; |
| 203 |
|
| 204 |
N_save_selected_rooms = -1; // say no saved list |
| 205 |
|
| 206 |
if (!N_selected_rooms) // are there any rooms in the list? |
| 207 |
return; //..no, so don't restore them |
| 208 |
|
| 209 |
for (i = 0; i < N_selected_rooms; i++) |
| 210 |
Selected_rooms[i] = Save_selected_rooms[i]; |
| 211 |
|
| 212 |
mem_free(Save_selected_rooms); // free up memory |
| 213 |
} |