| 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/ObjectDialog.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003-08-26 03:57:38 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Object keypad dialog |
| 26 | * |
| 27 | * $Log: not supported by cvs2svn $ |
| 28 | * |
| 29 | * 46 5/08/99 1:39a Matt |
| 30 | * Added a function to delete all objects of a certain type, and support |
| 31 | * for placing and attaching groups to the terrain. |
| 32 | * |
| 33 | * 45 4/05/99 3:34p Matt |
| 34 | * Cleaned up player start flags |
| 35 | * |
| 36 | * 44 4/02/99 12:58p Chris |
| 37 | * Change object now preserves names |
| 38 | * |
| 39 | * 43 3/27/99 12:52p Chris |
| 40 | * The editor object placement code now allows objects to be pushed into |
| 41 | * wall (when a toggle box is checked) |
| 42 | * |
| 43 | * 42 2/18/99 2:09p Luke |
| 44 | * Checking in for Matt |
| 45 | * |
| 46 | * 41 2/05/99 1:25p Matt |
| 47 | * Show more info on the status line when an object is selected |
| 48 | * |
| 49 | * 40 2/03/99 1:58a Matt |
| 50 | * Fixed small bug |
| 51 | * |
| 52 | * 39 2/03/99 1:20a Matt |
| 53 | * Made the object combo box on the object tab sort, and replaced the |
| 54 | * listbox of pictures with a big picture of the current item. |
| 55 | * |
| 56 | * 38 1/27/99 11:03a Samir |
| 57 | * added rotate 90 button to object dialog. |
| 58 | * |
| 59 | * 37 1/19/99 6:53p Matt |
| 60 | * Fixed a problem when the viewer was instantaneously moved from inside |
| 61 | * to ourside or vise-versa. |
| 62 | * |
| 63 | * 36 1/15/99 7:52p Chris |
| 64 | * Updated ObjSetPos() to include a f_update_attach_children flag |
| 65 | * |
| 66 | * 35 10/22/98 11:01a Chris |
| 67 | * Added object regrounding |
| 68 | * |
| 69 | * 34 10/08/98 7:17p Chris |
| 70 | * Added object swap types |
| 71 | * |
| 72 | * 33 8/24/98 12:24p Jason |
| 73 | * added waypoints and player start position flags |
| 74 | * |
| 75 | * 32 6/15/98 4:00p Jason |
| 76 | * replaced monochromatic polymodel lighting with rgb lighting |
| 77 | * |
| 78 | * 31 5/18/98 2:56p Matt |
| 79 | * Added code to readjust all ground object (for after the terrain has |
| 80 | * moved). |
| 81 | * |
| 82 | * 30 5/06/98 4:02p Sean |
| 83 | * |
| 84 | * 29 5/06/98 1:55p Sean |
| 85 | * |
| 86 | * 28 5/06/98 1:49p Sean |
| 87 | * fixed dumb bug with my last rev |
| 88 | * |
| 89 | * 27 5/06/98 12:34p Jason |
| 90 | * Added next object in terrain stuff |
| 91 | * |
| 92 | * 26 4/02/98 3:54p Jason |
| 93 | * first pass in getting polymodel paging to work |
| 94 | * |
| 95 | * 25 3/30/98 6:20p Matt |
| 96 | * Renamed ResetObject() to be ObjReInitAll() |
| 97 | * |
| 98 | * 24 2/24/98 11:19a Samir |
| 99 | * objects should look better in listbox. |
| 100 | * |
| 101 | * 23 2/05/98 11:25a Samir |
| 102 | * Maybe this will work to fix ListNextItem problems. |
| 103 | * |
| 104 | * 22 1/30/98 6:05p Matt |
| 105 | * Got Next Object in object keypad working, and made a routine to set the |
| 106 | * current editor object. |
| 107 | * |
| 108 | * 21 1/18/98 9:07p Matt |
| 109 | * New parms for ResetObjects() |
| 110 | * |
| 111 | * 20 1/07/98 6:39p Jason |
| 112 | * Fixed player object number stuff |
| 113 | * |
| 114 | * 19 12/19/97 11:26a Samir |
| 115 | * Oops. |
| 116 | * |
| 117 | * 18 12/19/97 11:25a Samir |
| 118 | * g3_StartFrame and g3_EndFrame replaced by EditorStartFrame and |
| 119 | * EditorEndFrame |
| 120 | * |
| 121 | * 17 12/01/97 3:20p Samir |
| 122 | * No Int3 when trying to place objects outside the mine. |
| 123 | * |
| 124 | * 16 9/17/97 1:26p Samir |
| 125 | * BIG SEGMENT RIPOUT |
| 126 | * |
| 127 | * 15 9/15/97 11:55a Samir |
| 128 | * Fixed playership adding. |
| 129 | * |
| 130 | * 14 9/02/97 3:02p Samir |
| 131 | * fixed bug. accidentally set wrong variable for axis movement. |
| 132 | * |
| 133 | * 13 8/29/97 2:49p Samir |
| 134 | * Added new object movement features. |
| 135 | * |
| 136 | * 12 8/25/97 7:39p Samir |
| 137 | * Using new GrListBox from old editorPictListBox |
| 138 | * |
| 139 | * 11 8/18/97 12:09p Matt |
| 140 | * Fixed a stupid bug, and added some error checking and handling |
| 141 | * |
| 142 | * 10 8/13/97 9:50a Matt |
| 143 | * Changed highlighted object to draw with magenta box around it |
| 144 | * |
| 145 | * 9 8/12/97 10:57p Matt |
| 146 | * Made object page work for the generic object types (robot, powerup, |
| 147 | * building, clutter) |
| 148 | * |
| 149 | * 8 8/11/97 1:53p Matt |
| 150 | * Ripped out robot & powerup pages, and added generic page |
| 151 | * |
| 152 | * 7 8/06/97 11:11a Mark |
| 153 | * Took out Int3 for 'untested' draw code in DrawItem. - Samir |
| 154 | * |
| 155 | * 6 7/24/97 7:18p Matt |
| 156 | * Cleaned up code that draws robots & powerups |
| 157 | * |
| 158 | * 5 7/24/97 6:11p Matt |
| 159 | * Created symbolic constant for default zoom, and used it every place |
| 160 | * that specifies zoom |
| 161 | * |
| 162 | * 4 7/24/97 4:21p Matt |
| 163 | * On object keypad, only list this object types the the designer can |
| 164 | * place |
| 165 | * |
| 166 | * 3 7/24/97 2:54p Matt |
| 167 | * Got rid of some member variables that kept track of current robot, |
| 168 | * powerup, & object type, and used variables in D3EditState instead. |
| 169 | * |
| 170 | * 2 7/22/97 7:08p Matt |
| 171 | * Cleaned up D3EditState, moving some vars in and some out, and renaming |
| 172 | * and changing a few others |
| 173 | * |
| 174 | * 35 6/04/97 11:56a Samir |
| 175 | * Added PowerupProp Dialog. |
| 176 | * |
| 177 | * 34 6/03/97 4:55p Mark |
| 178 | * |
| 179 | * 34 6/03/97 4:50p Jeff |
| 180 | * added Context Sensitive Help |
| 181 | * |
| 182 | * 33 5/01/97 12:33p Jason |
| 183 | * added reset objects function |
| 184 | * |
| 185 | * 32 5/01/97 11:16a Samir |
| 186 | * No Int3 in Object type selection |
| 187 | * |
| 188 | * 26 4/02/97 6:25p Samir |
| 189 | * Fixed screwup with decrease heading function. |
| 190 | * |
| 191 | * 25 4/02/97 12:22p Samir |
| 192 | * Fixed object box scroll problems by keeping an array of item starts for |
| 193 | * each obj_type and fixed problem of placing a bad robot (door) when |
| 194 | * first placing objects. |
| 195 | * |
| 196 | * 14 3/13/97 6:17p Jason |
| 197 | * changed door/polymodel prototype |
| 198 | * |
| 199 | * 13 3/03/97 5:56p Jason |
| 200 | * changed function name to be more generic |
| 201 | * GetPowerupBitmap -> GetPowerupImage |
| 202 | * |
| 203 | * 12 2/26/97 3:35p Mark |
| 204 | * |
| 205 | * 11 2/25/97 4:35p Samir |
| 206 | * Selecting from combo box sets pictoral list box selection. |
| 207 | * |
| 208 | * 10 2/21/97 6:25p Samir |
| 209 | * Object palette works (shitty scaling of powerups.) |
| 210 | * |
| 211 | * 9 2/20/97 4:26p Mark |
| 212 | * |
| 213 | * 8 2/19/97 5:26p Samir |
| 214 | * When setting focus on objID listbox, update its contents. |
| 215 | * |
| 216 | * 7 2/19/97 2:16p Samir |
| 217 | * Added RunKeypadFunction handler. |
| 218 | * |
| 219 | * 6 2/18/97 12:47p Samir |
| 220 | * Able to select object types and ids from keypad. |
| 221 | * |
| 222 | * 5 2/17/97 6:19p Samir |
| 223 | * Added place object and move left,right,for, back functionality. |
| 224 | * |
| 225 | * 4 1/27/97 11:38a Samir |
| 226 | * Added horizontal scrolling of keypad modeless dialog. |
| 227 | * |
| 228 | * $NoKeywords: $ |
| 229 | */ |
| 230 | |
| 231 | #include "stdafx.h" |
| 232 | #include "editor.h" |
| 233 | #include "ObjectDialog.h" |
| 234 | #include "ObjMoveManager.h" |
| 235 | |
| 236 | #include "HObject.h" |
| 237 | #include "polymodel.h" |
| 238 | |
| 239 | #include "object.h" |
| 240 | #include "ship.h" |
| 241 | #include "objinfo.h" |
| 242 | #include "multi.h" |
| 243 | #include "objinit.h" |
| 244 | #include "room.h" |
| 245 | #include "d3edit.h" |
| 246 | #include "physics.h" |
| 247 | #include "door.h" |
| 248 | #include "mem.h" |
| 249 | |
| 250 | #include "PowerupPropDialog.h" |
| 251 | |
| 252 | #ifdef _DEBUG |
| 253 | #define new DEBUG_NEW |
| 254 | #undef THIS_FILE |
| 255 | static char THIS_FILE[] = __FILE__; |
| 256 | #endif |
| 257 | |
| 258 | ///////////////////////////////////////////////////////////////////////////// |
| 259 | |
| 260 | // List of object types & names for the editor |
| 261 | int edit_object_types[] = {OBJ_ROBOT, OBJ_POWERUP, OBJ_BUILDING, OBJ_CLUTTER, OBJ_PLAYER}; |
| 262 | char *edit_objtype_names[] = {"Robot", "Powerup", "Building", "Clutter", "Player ship"}; |
| 263 | |
| 264 | int Swap_source_id = -1; |
| 265 | int Swap_dest_id = -1; |
| 266 | int Reground_id = -1; |
| 267 | |
| 268 | bool f_allow_objects_to_be_pushed_through_walls = false; |
| 269 | |
| 270 | void DrawItemModel(grHardwareSurface *surf, int model_num); |
| 271 | |
| 272 | #define NUM_EDIT_OBJTYPES (sizeof(edit_object_types) / sizeof(*edit_object_types)) |
| 273 | |
| 274 | ///////////////////////////////////////////////////////////////////////////// |
| 275 | // CObjectDialog dialog |
| 276 | |
| 277 | CObjectDialog::CObjectDialog(CWnd *pParent /*=NULL*/) : CKeypadDialog(CObjectDialog::IDD, pParent) { |
| 278 | //{{AFX_DATA_INIT(CObjectDialog) |
| 279 | // NOTE: the ClassWizard will add member initialization here |
| 280 | //}}AFX_DATA_INIT |
| 281 | } |
| 282 | |
| 283 | void CObjectDialog::DoDataExchange(CDataExchange *pDX) { |
| 284 | CDialog::DoDataExchange(pDX); |
| 285 | //{{AFX_DATA_MAP(CObjectDialog) |
| 286 | // NOTE: the ClassWizard will add DDX and DDV calls here |
| 287 | //}}AFX_DATA_MAP |
| 288 | } |
| 289 | |
| 290 | void CObjectDialog::UpdateIDList() { InitObjIDComboBox((CComboBox *)GetDlgItem(IDC_COMBO_OBJID)); } |
| 291 | |
| 292 | void CObjectDialog::PlaceObject() { OnObjectPlaceObject(); } |
| 293 | |
| 294 | void CObjectDialog::DeleteObject() { OnObjPadDelobj(); } |
| 295 | |
| 296 | BEGIN_MESSAGE_MAP(CObjectDialog, CDialog) |
| 297 | //{{AFX_MSG_MAP(CObjectDialog) |
| 298 | ON_WM_SIZE() |
| 299 | ON_WM_VSCROLL() |
| 300 | ON_WM_HSCROLL() |
| 301 | ON_BN_CLICKED(IDC_OBJPAD_PLACEOBJ, OnObjectPlaceObject) |
| 302 | ON_CBN_SELCHANGE(IDC_COMBO_OBJTYPE, OnSelchangeComboObjType) |
| 303 | ON_CBN_SELCHANGE(IDC_COMBO_OBJID, OnSelchangeComboObjID) |
| 304 | ON_BN_CLICKED(IDC_OBJ_DELOBJ, OnObjPadDelobj) |
| 305 | ON_BN_CLICKED(IDC_OBJPAD_NEXTOBJ, OnObjpadNextobj) |
| 306 | ON_CBN_SETFOCUS(IDC_COMBO_OBJID, OnSetfocusComboObjID) |
| 307 | ON_BN_CLICKED(IDC_OBJECTPAD_GROUP, OnObjectpadGroup) |
| 308 | ON_BN_CLICKED(IDC_OBJ_CONT_PREVIEW, OnObjContPreview) |
| 309 | ON_WM_PAINT() |
| 310 | ON_WM_LBUTTONDOWN() |
| 311 | ON_BN_CLICKED(IDC_OBJPAD_FLAGOBJMULTI, OnObjpadFlagobjmulti) |
| 312 | ON_BN_CLICKED(IDC_OBJPAD_FLIPOBJ, OnObjpadFlipobj) |
| 313 | ON_BN_CLICKED(IDC_OBJPAD_SETDEFAULT, OnObjpadSetdefault) |
| 314 | ON_WM_DESTROY() |
| 315 | ON_BN_CLICKED(IDC_RESET_OBJECTS, OnResetObjects) |
| 316 | ON_WM_HELPINFO() |
| 317 | ON_BN_CLICKED(IDC_OBJPAD_PROPERTIES, OnObjpadProperties) |
| 318 | ON_CBN_SELCHANGE(IDC_COORDSYS_SELECT, OnSelChangeCoordSysSelect) |
| 319 | ON_BN_CLICKED(IDC_OBJMOVEX, OnObjmoveX) |
| 320 | ON_BN_CLICKED(IDC_OBJMOVEY, OnObjmoveY) |
| 321 | ON_BN_CLICKED(IDC_OBJMOVEXY, OnObjmoveXY) |
| 322 | ON_BN_CLICKED(IDC_OBJMOVEZ, OnObjmoveZ) |
| 323 | ON_BN_CLICKED(IDC_OBJMOVEP, OnObjmoveP) |
| 324 | ON_BN_CLICKED(IDC_OBJMOVEH, OnObjmoveH) |
| 325 | ON_BN_CLICKED(IDC_OBJMOVEB, OnObjmoveB) |
| 326 | ON_BN_CLICKED(IDC_OBJMOVEPH, OnObjmovePH) |
| 327 | ON_BN_CLICKED(IDC_OBJPAD_RESET_ALL_OBJ_HEIGHTS, OnObjpadResetAllObjHeights) |
| 328 | ON_BN_CLICKED(IDC_OBJPAD_RESET_CUROBJ_HEIGHT, OnObjpadResetCurobjHeight) |
| 329 | ON_BN_CLICKED(IDC_PREV_START_POSITON, OnPrevStartPositon) |
| 330 | ON_BN_CLICKED(IDC_NEXT_START_POS, OnNextStartPos) |
| 331 | ON_BN_CLICKED(IDC_JUMP_TO_START_POS, OnJumpToStartPos) |
| 332 | ON_BN_CLICKED(IDC_RED_CHECK, OnRedCheck) |
| 333 | ON_BN_CLICKED(IDC_BLUE_CHECK, OnBlueCheck) |
| 334 | ON_BN_CLICKED(IDC_GREEN_CHECK, OnGreenCheck) |
| 335 | ON_BN_CLICKED(IDC_YELLOW_CHECK, OnYellowCheck) |
| 336 | ON_CBN_SELENDOK(IDC_SWAP_SOURCE_COMBO, OnSelendokSwapSourceCombo) |
| 337 | ON_CBN_SELENDOK(IDC_SWAP_DEST_COMBO, OnSelendokSwapDestCombo) |
| 338 | ON_BN_CLICKED(IDC_OBJECT_SWAP_BUTTON, OnObjectSwapButton) |
| 339 | ON_CBN_SELENDOK(IDC_REGROUND_COMBO, OnSelendokRegroundCombo) |
| 340 | ON_BN_CLICKED(IDC_REGROUND_BUTTON, OnRegroundButton) |
| 341 | ON_BN_CLICKED(IDC_OBJ_ROT90, OnObjRot90) |
| 342 | ON_BN_CLICKED(IDC_OBJECT_PUSHTHROUGHWALLS, OnObjectPushthroughwalls) |
| 343 | ON_BN_CLICKED(IDC_OBJPAD_DELETEALL, OnObjpadDeleteAll) |
| 344 | //}}AFX_MSG_MAP |
| 345 | END_MESSAGE_MAP() |
| 346 | |
| 347 | // Current player isn't saved, so just keep it locally |
| 348 | int current_player = 0; |
| 349 | |
| 350 | // Sets the current index of the given type |
| 351 | void SetCurrentIndex(int index) { |
| 352 | switch (D3EditState.current_obj_type) { |
| 353 | case OBJ_ROBOT: |
| 354 | D3EditState.current_robot = index; |
| 355 | break; |
| 356 | case OBJ_POWERUP: |
| 357 | D3EditState.current_powerup = index; |
| 358 | break; |
| 359 | case OBJ_CLUTTER: |
| 360 | D3EditState.current_clutter = index; |
| 361 | break; |
| 362 | case OBJ_BUILDING: |
| 363 | D3EditState.current_building = index; |
| 364 | break; |
| 365 | case OBJ_PLAYER: |
| 366 | current_player = index; |
| 367 | break; |
| 368 | default: |
| 369 | Int3(); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | // Returns the current index of the given type |
| 374 | int GetCurrentIndex() { |
| 375 | int type = D3EditState.current_obj_type; |
| 376 | int current; |
| 377 | |
| 378 | switch (type) { |
| 379 | case OBJ_ROBOT: |
| 380 | current = D3EditState.current_robot; |
| 381 | break; |
| 382 | case OBJ_POWERUP: |
| 383 | current = D3EditState.current_powerup; |
| 384 | break; |
| 385 | case OBJ_CLUTTER: |
| 386 | current = D3EditState.current_clutter; |
| 387 | break; |
| 388 | case OBJ_BUILDING: |
| 389 | current = D3EditState.current_building; |
| 390 | break; |
| 391 | case OBJ_PLAYER: |
| 392 | return current_player; |
| 393 | break; |
| 394 | default: |
| 395 | Int3(); |
| 396 | } |
| 397 | |
| 398 | if (Object_info[current].type != type) { // current is of wrong type |
| 399 | current = GetObjectID(type); //...so get a new current |
| 400 | SetCurrentIndex(current); |
| 401 | } |
| 402 | |
| 403 | return current; |
| 404 | } |
| 405 | |
| 406 | ///////////////////////////////////////////////////////////////////////////// |
| 407 | // CObjectDialog message handlers |
| 408 | |
| 409 | void CObjectDialog::InitObjIDComboBox(CComboBox *box) { |
| 410 | int i, first, n; |
| 411 | |
| 412 | box->ResetContent(); |
| 413 | |
| 414 | // Add names of object IDs of current object type |
| 415 | switch (D3EditState.current_obj_type) { |
| 416 | case OBJ_ROBOT: |
| 417 | case OBJ_POWERUP: |
| 418 | case OBJ_CLUTTER: |
| 419 | case OBJ_BUILDING: |
| 420 | first = GetObjectID(D3EditState.current_obj_type); |
| 421 | |
| 422 | if (first == -1) |
| 423 | break; |
| 424 | |
| 425 | if (GetCurrentIndex() == -1) |
| 426 | SetCurrentIndex(first); |
| 427 | |
| 428 | n = first; |
| 429 | do { |
| 430 | int index = box->AddString(Object_info[n].name); |
| 431 | box->SetItemData(index, n); |
| 432 | |
| 433 | if (n == GetCurrentIndex()) |
| 434 | box->SetCurSel(index); |
| 435 | |
| 436 | n = GetNextObjectID(n); |
| 437 | } while (n != first); |
| 438 | |
| 439 | break; |
| 440 | |
| 441 | case OBJ_PLAYER: |
| 442 | for (i = 0; i < MAX_SHIPS; i++) { |
| 443 | if (Ships[i].used) { |
| 444 | int index = box->AddString(Ships[i].name); |
| 445 | box->SetItemData(index, i); |
| 446 | if (i == D3EditState.current_ship) |
| 447 | box->SetCurSel(index); |
| 448 | } |
| 449 | } |
| 450 | break; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | void CObjectDialog::InitObjTypeComboBox(CComboBox *box) { |
| 455 | box->ResetContent(); |
| 456 | |
| 457 | for (int i = 0; i < NUM_EDIT_OBJTYPES; i++) { |
| 458 | if (box->AddString(edit_objtype_names[i]) < 0) |
| 459 | Int3(); |
| 460 | if (edit_object_types[i] == D3EditState.current_obj_type) |
| 461 | box->SetCurSel(i); |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | BOOL CObjectDialog::OnInitDialog() { |
| 466 | CComboBox *box; |
| 467 | int current; |
| 468 | |
| 469 | CDialog::OnInitDialog(); |
| 470 | |
| 471 | // Init types combo box |
| 472 | InitObjTypeComboBox((CComboBox *)GetDlgItem(IDC_COMBO_OBJTYPE)); |
| 473 | |
| 474 | // Init IDs combo box |
| 475 | InitObjIDComboBox((CComboBox *)GetDlgItem(IDC_COMBO_OBJID)); |
| 476 | |
| 477 | // Get index of current item |
| 478 | current = GetCurrentIndex(); |
| 479 | ASSERT(current != -1); |
| 480 | |
| 481 | // set selection in object movement combobox and move axis. |
| 482 | box = (CComboBox *)GetDlgItem(IDC_COORDSYS_SELECT); |
| 483 | if (D3EditState.object_move_mode == REL_OBJECT) |
| 484 | box->SelectString(-1, "Local"); |
| 485 | else if (D3EditState.object_move_mode == REL_VIEWER) |
| 486 | box->SelectString(-1, "Viewer"); |
| 487 | else { |
| 488 | D3EditState.object_move_mode = REL_OBJECT; |
| 489 | box->SelectString(-1, "Local"); |
| 490 | } |
| 491 | |
| 492 | ObjMoveManager.SetMoveAxis(D3EditState.object_move_axis); |
| 493 | |
| 494 | CButton *btn = NULL; |
| 495 | |
| 496 | switch (D3EditState.object_move_axis) { |
| 497 | case OBJMOVEAXIS_X: |
| 498 | btn = (CButton *)GetDlgItem(IDC_OBJMOVEX); |
| 499 | break; |
| 500 | case OBJMOVEAXIS_Y: |
| 501 | btn = (CButton *)GetDlgItem(IDC_OBJMOVEY); |
| 502 | break; |
| 503 | case OBJMOVEAXIS_Z: |
| 504 | btn = (CButton *)GetDlgItem(IDC_OBJMOVEZ); |
| 505 | break; |
| 506 | case OBJMOVEAXIS_XY: |
| 507 | btn = (CButton *)GetDlgItem(IDC_OBJMOVEXY); |
| 508 | break; |
| 509 | case OBJMOVEAXIS_P: |
| 510 | btn = (CButton *)GetDlgItem(IDC_OBJMOVEP); |
| 511 | break; |
| 512 | case OBJMOVEAXIS_H: |
| 513 | btn = (CButton *)GetDlgItem(IDC_OBJMOVEH); |
| 514 | break; |
| 515 | case OBJMOVEAXIS_B: |
| 516 | btn = (CButton *)GetDlgItem(IDC_OBJMOVEB); |
| 517 | break; |
| 518 | case OBJMOVEAXIS_PH: |
| 519 | btn = (CButton *)GetDlgItem(IDC_OBJMOVEPH); |
| 520 | break; |
| 521 | |
| 522 | default: |
| 523 | Int3(); // THIS SHOULD NEVER HAPPEN - samir |
| 524 | } |
| 525 | |
| 526 | btn->SetCheck(1); |
| 527 | |
| 528 | m_current_start_pos = 0; |
| 529 | UpdateDialog(); |
| 530 | |
| 531 | // Done. |
| 532 | return TRUE; // return TRUE unless you set the focus to a control |
| 533 | // EXCEPTION: OCX Property Pages should return FALSE |
| 534 | } |
| 535 | |
| 536 | void CObjectDialog::OnDestroy() { CDialog::OnDestroy(); } |
| 537 | |
| 538 | void CObjectDialog::OnSize(UINT nType, int cx, int cy) { CKeypadDialog::OnSize(nType, cx, cy); } |
| 539 | |
| 540 | void CObjectDialog::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) { |
| 541 | CKeypadDialog::OnVScroll(nSBCode, nPos, pScrollBar); |
| 542 | } |
| 543 | |
| 544 | void CObjectDialog::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) { |
| 545 | CKeypadDialog::OnHScroll(nSBCode, nPos, pScrollBar); |
| 546 | } |
| 547 | |
| 548 | void CObjectDialog::OnPaint() { |
| 549 | CPaintDC dc(this); // device context for painting |
| 550 | |
| 551 | if (!m_Active) |
| 552 | return; |
| 553 | |
| 554 | UpdateIDList(); // this is here to update the object ids in case of any changes |
| 555 | |
| 556 | ASSERT(GetCurrentIndex() != -1); |
| 557 | |
| 558 | // Draw picture of current item |
| 559 | DrawPicture(GetDlgItem(IDC_OBJ_PALETTE)); |
| 560 | } |
| 561 | |
| 562 | void CObjectDialog::OnLButtonDown(UINT nFlags, CPoint point) { CDialog::OnLButtonDown(nFlags, point); } |
| 563 | |
| 564 | void CObjectDialog::UpdateDialog() { |
| 565 | CEdit *box; |
| 566 | char str[255]; |
| 567 | int cur = m_current_start_pos; |
| 568 | int i; |
| 569 | |
| 570 | sprintf(str, "Current start position: %d", cur); |
| 571 | box = (CEdit *)GetDlgItem(IDC_START_POS_TEXT); |
| 572 | box->SetWindowText(str); |
| 573 | |
| 574 | CheckDlgButton(IDC_RED_CHECK, Players[cur].startpos_flags & PSPF_RED); |
| 575 | CheckDlgButton(IDC_BLUE_CHECK, Players[cur].startpos_flags & PSPF_BLUE); |
| 576 | CheckDlgButton(IDC_GREEN_CHECK, Players[cur].startpos_flags & PSPF_GREEN); |
| 577 | CheckDlgButton(IDC_YELLOW_CHECK, Players[cur].startpos_flags & PSPF_YELLOW); |
| 578 | |
| 579 | SendDlgItemMessage(IDC_SWAP_SOURCE_COMBO, CB_RESETCONTENT, 0, 0); |
| 580 | SendDlgItemMessage(IDC_SWAP_DEST_COMBO, CB_RESETCONTENT, 0, 0); |
| 581 | SendDlgItemMessage(IDC_REGROUND_COMBO, CB_RESETCONTENT, 0, 0); |
| 582 | |
| 583 | for (i = 0; i < MAX_OBJECT_IDS; i++) { |
| 584 | if (Object_info[i].type != OBJ_NONE) { |
| 585 | SendDlgItemMessage(IDC_SWAP_SOURCE_COMBO, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)Object_info[i].name); |
| 586 | SendDlgItemMessage(IDC_SWAP_DEST_COMBO, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)Object_info[i].name); |
| 587 | SendDlgItemMessage(IDC_REGROUND_COMBO, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)Object_info[i].name); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | if (Swap_source_id >= 0 && Swap_source_id < MAX_OBJECT_IDS && Object_info[Swap_source_id].type != OBJ_NONE) |
| 592 | SendDlgItemMessage(IDC_SWAP_SOURCE_COMBO, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)Object_info[Swap_source_id].name); |
| 593 | else |
| 594 | SendDlgItemMessage(IDC_SWAP_SOURCE_COMBO, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR) "None"); |
| 595 | |
| 596 | if (Swap_dest_id >= 0 && Swap_dest_id < MAX_OBJECT_IDS && Object_info[Swap_dest_id].type != OBJ_NONE) |
| 597 | SendDlgItemMessage(IDC_SWAP_DEST_COMBO, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)Object_info[Swap_dest_id].name); |
| 598 | else |
| 599 | SendDlgItemMessage(IDC_SWAP_DEST_COMBO, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR) "None"); |
| 600 | |
| 601 | if (Reground_id >= 0 && Reground_id < MAX_OBJECT_IDS && Object_info[Reground_id].type != OBJ_NONE) |
| 602 | SendDlgItemMessage(IDC_REGROUND_COMBO, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)Object_info[Reground_id].name); |
| 603 | else |
| 604 | SendDlgItemMessage(IDC_REGROUND_COMBO, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR) "None"); |
| 605 | } |
| 606 | |
| 607 | void CObjectDialog::DrawPicture(CWnd *wnd) { |
| 608 | RECT box_rect; |
| 609 | int width, height, model_num; |
| 610 | grHardwareSurface hw_surf; |
| 611 | |
| 612 | if (!Editor_active) |
| 613 | return; |
| 614 | |
| 615 | // initialize graphic objects |
| 616 | wnd->GetClientRect(&box_rect); |
| 617 | |
| 618 | width = box_rect.right - box_rect.left; |
| 619 | height = box_rect.bottom - box_rect.top; |
| 620 | |
| 621 | Desktop_surf->attach_to_window((unsigned)wnd->m_hWnd); |
| 622 | |
| 623 | hw_surf.create(width, height, BPP_16); |
| 624 | |
| 625 | switch (D3EditState.current_obj_type) { |
| 626 | case OBJ_CLUTTER: |
| 627 | case OBJ_BUILDING: |
| 628 | case OBJ_POWERUP: |
| 629 | case OBJ_ROBOT: |
| 630 | model_num = GetObjectImage(GetCurrentIndex()); |
| 631 | break; |
| 632 | case OBJ_PLAYER: |
| 633 | model_num = GetShipImage(GetCurrentIndex()); |
| 634 | break; |
| 635 | default: |
| 636 | Int3(); |
| 637 | } |
| 638 | |
| 639 | DrawItemModel(&hw_surf, model_num); |
| 640 | } |
| 641 | |
| 642 | // Keypad functions! |
| 643 | |
| 644 | void CObjectDialog::OnObjmoveX() { |
| 645 | D3EditState.object_move_axis = OBJMOVEAXIS_X; |
| 646 | ObjMoveManager.SetMoveAxis(D3EditState.object_move_axis); |
| 647 | } |
| 648 | |
| 649 | void CObjectDialog::OnObjmoveY() { |
| 650 | D3EditState.object_move_axis = OBJMOVEAXIS_Y; |
| 651 | ObjMoveManager.SetMoveAxis(D3EditState.object_move_axis); |
| 652 | } |
| 653 | |
| 654 | void CObjectDialog::OnObjmoveXY() { |
| 655 | D3EditState.object_move_axis = OBJMOVEAXIS_XY; |
| 656 | ObjMoveManager.SetMoveAxis(D3EditState.object_move_axis); |
| 657 | } |
| 658 | |
| 659 | void CObjectDialog::OnObjmoveZ() { |
| 660 | D3EditState.object_move_axis = OBJMOVEAXIS_Z; |
| 661 | ObjMoveManager.SetMoveAxis(D3EditState.object_move_axis); |
| 662 | } |
| 663 | |
| 664 | void CObjectDialog::OnObjmoveP() { |
| 665 | D3EditState.object_move_axis = OBJMOVEAXIS_P; |
| 666 | ObjMoveManager.SetMoveAxis(D3EditState.object_move_axis); |
| 667 | } |
| 668 | |
| 669 | void CObjectDialog::OnObjmoveH() { |
| 670 | D3EditState.object_move_axis = OBJMOVEAXIS_H; |
| 671 | ObjMoveManager.SetMoveAxis(D3EditState.object_move_axis); |
| 672 | } |
| 673 | |
| 674 | void CObjectDialog::OnObjmoveB() { |
| 675 | D3EditState.object_move_axis = OBJMOVEAXIS_B; |
| 676 | ObjMoveManager.SetMoveAxis(D3EditState.object_move_axis); |
| 677 | } |
| 678 | |
| 679 | void CObjectDialog::OnObjmovePH() { |
| 680 | D3EditState.object_move_axis = OBJMOVEAXIS_PH; |
| 681 | ObjMoveManager.SetMoveAxis(D3EditState.object_move_axis); |
| 682 | } |
| 683 | |
| 684 | int CObjectDialog::GetFreePlayerIndex() { |
| 685 | uint8_t slots[MAX_NET_PLAYERS]; |
| 686 | |
| 687 | memset(slots, 0, MAX_NET_PLAYERS); |
| 688 | |
| 689 | for (int i = 0; i <= Highest_object_index; i++) { |
| 690 | if (Objects[i].type == OBJ_PLAYER) { |
| 691 | // Get Jason if these asserts fail |
| 692 | ASSERT(slots[Objects[i].id] == 0); |
| 693 | ASSERT(Objects[i].id < MAX_NET_PLAYERS); |
| 694 | |
| 695 | slots[Objects[i].id] = 1; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | for (i = 0; i < MAX_NET_PLAYERS; i++) { |
| 700 | if (slots[i] == 0) { |
| 701 | mprintf(0, "Making new ship with id of %d...\n", i); |
| 702 | return i; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | return -1; |
| 707 | } |
| 708 | |
| 709 | void CObjectDialog::OnObjectPlaceObject() { |
| 710 | int objid = -1; |
| 711 | |
| 712 | if (D3EditState.current_obj_type == OBJ_PLAYER) { |
| 713 | objid = GetFreePlayerIndex(); |
| 714 | if (objid == -1) { |
| 715 | mprintf(0, "No more player slots! You already have %d players in this level!\n", MAX_NET_PLAYERS); |
| 716 | return; |
| 717 | } |
| 718 | |
| 719 | } else |
| 720 | objid = GetCurrentIndex(); |
| 721 | |
| 722 | ASSERT(objid > -1); |
| 723 | |
| 724 | if (!HObjectPlace(D3EditState.current_obj_type, objid)) { |
| 725 | mprintf(0, "Attempt to place object outside mine failed!\n"); |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | void CObjectDialog::OnSelchangeComboObjType() { |
| 730 | // make sure to save the old item start value. |
| 731 | int old_obj_type = D3EditState.current_obj_type; |
| 732 | |
| 733 | D3EditState.current_obj_type = edit_object_types[((CComboBox *)GetDlgItem(IDC_COMBO_OBJTYPE))->GetCurSel()]; |
| 734 | InitObjIDComboBox((CComboBox *)GetDlgItem(IDC_COMBO_OBJID)); |
| 735 | ASSERT(GetCurrentIndex() != -1); |
| 736 | |
| 737 | // Draw picture of current item |
| 738 | DrawPicture(GetDlgItem(IDC_OBJ_PALETTE)); |
| 739 | } |
| 740 | |
| 741 | void CObjectDialog::OnSelchangeComboObjID() { |
| 742 | CComboBox *box = (CComboBox *)GetDlgItem(IDC_COMBO_OBJID); |
| 743 | |
| 744 | switch (D3EditState.current_obj_type) { |
| 745 | case OBJ_ROBOT: |
| 746 | case OBJ_POWERUP: |
| 747 | case OBJ_BUILDING: |
| 748 | case OBJ_CLUTTER: { |
| 749 | int id = box->GetItemData(box->GetCurSel()); |
| 750 | ASSERT(Object_info[id].type == D3EditState.current_obj_type); |
| 751 | SetCurrentIndex(id); |
| 752 | break; |
| 753 | } |
| 754 | |
| 755 | case OBJ_PLAYER: { |
| 756 | char text[32]; |
| 757 | int i, j; |
| 758 | box->GetLBText(box->GetCurSel(), text); |
| 759 | j = 0; |
| 760 | for (i = 0; i < MAX_SHIPS; i++) |
| 761 | if (Ships[i].used && (stricmp(text, Ships[i].name) == 0)) { |
| 762 | j++; |
| 763 | break; |
| 764 | } |
| 765 | |
| 766 | ASSERT(i < MAX_SHIPS); |
| 767 | SetCurrentIndex(i); |
| 768 | break; |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | // Draw picture of current item |
| 773 | DrawPicture(GetDlgItem(IDC_OBJ_PALETTE)); |
| 774 | } |
| 775 | |
| 776 | void CObjectDialog::OnObjPadDelobj() { HObjectDelete(); } |
| 777 | |
| 778 | // Set the current object |
| 779 | void SelectObject(int objnum) { |
| 780 | char *type_name, *obj_name; |
| 781 | char *id_name = NULL; |
| 782 | |
| 783 | ASSERT(objnum != -1); |
| 784 | |
| 785 | Cur_object_index = objnum; |
| 786 | |
| 787 | object *objp = &Objects[objnum]; |
| 788 | type_name = Object_type_names[objp->type]; |
| 789 | obj_name = objp->name ? objp->name : "<none>"; |
| 790 | |
| 791 | if (IS_GENERIC(objp->type)) |
| 792 | id_name = Object_info[objp->id].name; |
| 793 | else if (objp->type == OBJ_DOOR) |
| 794 | id_name = Doors[objp->id].name; |
| 795 | |
| 796 | if (id_name) |
| 797 | EditorStatus("Object %d selected. Type = %s:%s, Name = %s", objnum, type_name, id_name, obj_name); |
| 798 | else |
| 799 | EditorStatus("Object %d selected. Type = %s, Name = %s", objnum, type_name, obj_name); |
| 800 | |
| 801 | State_changed = 1; |
| 802 | } |
| 803 | |
| 804 | void CObjectDialog::OnObjpadNextobj() { |
| 805 | int next; |
| 806 | |
| 807 | // If on the terrain, advance to the next object |
| 808 | if (Editor_view_mode == VM_TERRAIN && OBJECT_OUTSIDE(&Objects[Cur_object_index])) { |
| 809 | next = -1; |
| 810 | int done = 0; |
| 811 | for (int i = Cur_object_index + 1; i <= Highest_object_index && !done; i++) { |
| 812 | object *obj = &Objects[i]; |
| 813 | |
| 814 | if (obj->type != OBJ_NONE && OBJECT_OUTSIDE(obj) && obj->type != OBJ_ROOM) { |
| 815 | next = i; |
| 816 | done = 1; |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | if (!done) { |
| 821 | // Start counting from zero |
| 822 | for (int i = 0; i <= Cur_object_index && !done; i++) { |
| 823 | object *obj = &Objects[i]; |
| 824 | |
| 825 | if (obj->type != OBJ_NONE && OBJECT_OUTSIDE(obj) && obj->type != OBJ_ROOM) { |
| 826 | next = i; |
| 827 | done = 1; |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | if (next == -1) { |
| 832 | EditorStatus("There are no other objects on the terrain"); |
| 833 | return; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | SelectObject(next); |
| 838 | return; |
| 839 | } |
| 840 | |
| 841 | if (Objects[Cur_object_index].roomnum != ROOMNUM(Curroomp)) { |
| 842 | next = Curroomp->objects; |
| 843 | if (next == -1) { |
| 844 | EditorStatus("There are no objects in the current room"); |
| 845 | return; |
| 846 | } |
| 847 | } else { |
| 848 | next = Objects[Cur_object_index].next; |
| 849 | if (next == -1) { |
| 850 | next = Curroomp->objects; |
| 851 | if (next == Cur_object_index) { |
| 852 | EditorStatus("There are no other objects in this room"); |
| 853 | return; |
| 854 | } |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | SelectObject(next); |
| 859 | } |
| 860 | |
| 861 | void CObjectDialog::OnSetfocusComboObjID() { InitObjIDComboBox((CComboBox *)GetDlgItem(IDC_COMBO_OBJID)); } |
| 862 | |
| 863 | void CObjectDialog::OnObjectpadGroup() { |
| 864 | // TODO: Add your control notification handler code here |
| 865 | } |
| 866 | |
| 867 | void CObjectDialog::OnObjContPreview() { |
| 868 | // TODO: Add your control notification handler code here |
| 869 | } |
| 870 | |
| 871 | void CObjectDialog::OnObjpadFlagobjmulti() { |
| 872 | // TODO: Add your control notification handler code here |
| 873 | } |
| 874 | |
| 875 | void CObjectDialog::OnObjpadFlipobj() { |
| 876 | // TODO: Add your control notification handler code here |
| 877 | HObjectFlip(); |
| 878 | } |
| 879 | |
| 880 | void CObjectDialog::OnObjpadSetdefault() { |
| 881 | // TODO: Add your control notification handler code here |
| 882 | HObjectSetDefault(); |
| 883 | } |
| 884 | |
| 885 | void CObjectDialog::OnResetObjects() { |
| 886 | ObjReInitAll(); |
| 887 | OutrageMessageBox("All objects reset!"); |
| 888 | } |
| 889 | |
| 890 | BOOL CObjectDialog::OnHelpInfo(HELPINFO *pHelpInfo) { |
| 891 | // TODO: Add your message handler code here and/or call default |
| 892 | WinHelp(HID_OBJECTTAB, HELP_CONTEXT); |
| 893 | return TRUE; |
| 894 | // return CDialog::OnHelpInfo(pHelpInfo); |
| 895 | } |
| 896 | |
| 897 | // This function will allow you to edit individual properties for the current selected object. |
| 898 | |
| 899 | void CObjectDialog::OnObjpadProperties() { |
| 900 | if (Cur_object_index == -1) { |
| 901 | OutrageMessageBox("Must select an object before editing it's properties."); |
| 902 | return; |
| 903 | } |
| 904 | |
| 905 | theApp.pause(); |
| 906 | |
| 907 | switch (Objects[Cur_object_index].type) { |
| 908 | case OBJ_POWERUP: { |
| 909 | CPowerupPropDialog dlg; |
| 910 | dlg.DoModal(); |
| 911 | break; |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | theApp.resume(); |
| 916 | } |
| 917 | |
| 918 | ///////////////////////////////////////////////////////////////////// |
| 919 | // New Object Movement Control implementation |
| 920 | |
| 921 | void CObjectDialog::OnSelChangeCoordSysSelect() { |
| 922 | CComboBox *cbox = (CComboBox *)GetDlgItem(IDC_COORDSYS_SELECT); |
| 923 | char seltext[8]; |
| 924 | |
| 925 | cbox->GetLBText(cbox->GetCurSel(), seltext); |
| 926 | |
| 927 | if (stricmp(seltext, "local") == 0) { |
| 928 | D3EditState.object_move_mode = REL_OBJECT; |
| 929 | } else if (stricmp(seltext, "viewer") == 0) { |
| 930 | D3EditState.object_move_mode = REL_VIEWER; |
| 931 | } else if (stricmp(seltext, "world") == 0) { |
| 932 | D3EditState.object_move_mode = REL_VIEWER; |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | void DrawItemModel(grHardwareSurface *surf, int model_num) { |
| 937 | vector zero_vector = {0, 0, 0}; |
| 938 | vector view_pos = {0, 0, 0}; |
| 939 | matrix id_matrix, rot_matrix; |
| 940 | |
| 941 | poly_model *pm = GetPolymodelPointer(model_num); |
| 942 | |
| 943 | // Calculate viewer position |
| 944 | vector maxs = pm->maxs, mins = pm->mins; |
| 945 | view_pos.x = -(mins.x + maxs.x) / 2; |
| 946 | view_pos.y = (mins.y + maxs.y) / 2; |
| 947 | maxs.x += view_pos.x; |
| 948 | maxs.y -= view_pos.y; |
| 949 | maxs.z = 0; |
| 950 | view_pos.z = -2.5 * vm_GetMagnitude(&maxs); |
| 951 | |
| 952 | // Set viewer and object orientations |
| 953 | vm_MakeIdentity(&id_matrix); |
| 954 | vm_AnglesToMatrix(&rot_matrix, 0, 32768, 0); |
| 955 | |
| 956 | // Set up surface & vuewport |
| 957 | surf->clear(); |
| 958 | grViewport *vport = new grViewport(surf); |
| 959 | vport->clear(); |
| 960 | |
| 961 | // Draw to our surface |
| 962 | StartEditorFrame(vport, &view_pos, &id_matrix, D3_DEFAULT_ZOOM); |
| 963 | DrawPolygonModel(&zero_vector, &rot_matrix, model_num, NULL, 0, 1.0, 1.0, 1.0); |
| 964 | EndEditorFrame(); |
| 965 | |
| 966 | // Copy to the screen |
| 967 | Desktop_surf->blt(0, 0, surf); |
| 968 | |
| 969 | // Delete our viewport |
| 970 | delete vport; |
| 971 | } |
| 972 | |
| 973 | void CObjectDialog::OnObjpadResetCurobjHeight() { |
| 974 | if (Cur_object_index == -1) { |
| 975 | OutrageMessageBox("You must have a current object for this operation."); |
| 976 | return; |
| 977 | } |
| 978 | |
| 979 | object *objp = &Objects[Cur_object_index]; |
| 980 | |
| 981 | // Make sure object is outside |
| 982 | if (!OBJECT_OUTSIDE(objp)) { |
| 983 | OutrageMessageBox("The object must be on the terrain this operation."); |
| 984 | return; |
| 985 | } |
| 986 | |
| 987 | // Make sure object has a ground plane |
| 988 | if (!((objp->render_type == RT_POLYOBJ) && ((GetPolymodelPointer(objp->rtype.pobj_info.model_num))->n_ground))) { |
| 989 | OutrageMessageBox("The object must have a ground plane for this operation."); |
| 990 | return; |
| 991 | } |
| 992 | |
| 993 | ResetGroundObject(objp); |
| 994 | } |
| 995 | |
| 996 | void CObjectDialog::OnObjpadResetAllObjHeights() { |
| 997 | object *objp; |
| 998 | int i; |
| 999 | int n_moved = 0; |
| 1000 | |
| 1001 | for (i = 0, objp = Objects; i <= Highest_object_index; i++, objp++) { |
| 1002 | |
| 1003 | // Make sure object is outside |
| 1004 | if (!OBJECT_OUTSIDE(objp)) |
| 1005 | continue; |
| 1006 | |
| 1007 | // Make sure object has a ground plane |
| 1008 | if (!((objp->render_type == RT_POLYOBJ) && ((GetPolymodelPointer(objp->rtype.pobj_info.model_num))->n_ground))) |
| 1009 | continue; |
| 1010 | |
| 1011 | // Do it |
| 1012 | ResetGroundObject(objp); |
| 1013 | n_moved++; |
| 1014 | } |
| 1015 | |
| 1016 | EditorStatus("%d objects adjusted.", n_moved); |
| 1017 | } |
| 1018 | |
| 1019 | void CObjectDialog::OnPrevStartPositon() { |
| 1020 | if (m_current_start_pos == 0) |
| 1021 | m_current_start_pos = MAX_PLAYERS - 1; |
| 1022 | else |
| 1023 | m_current_start_pos--; |
| 1024 | |
| 1025 | UpdateDialog(); |
| 1026 | } |
| 1027 | |
| 1028 | void CObjectDialog::OnNextStartPos() { |
| 1029 | m_current_start_pos++; |
| 1030 | |
| 1031 | if (m_current_start_pos >= MAX_PLAYERS) |
| 1032 | m_current_start_pos = 0; |
| 1033 | |
| 1034 | UpdateDialog(); |
| 1035 | } |
| 1036 | |
| 1037 | void CObjectDialog::OnJumpToStartPos() { |
| 1038 | char str[255]; |
| 1039 | int found_obj = -1; |
| 1040 | int highest = -1; |
| 1041 | for (int i = 0; i <= Highest_object_index && found_obj == -1; i++) { |
| 1042 | if (Objects[i].type == OBJ_PLAYER) { |
| 1043 | if (Objects[i].id > highest) |
| 1044 | highest = Objects[i].id; |
| 1045 | |
| 1046 | if (Objects[i].id == m_current_start_pos) { |
| 1047 | found_obj = i; |
| 1048 | } |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | if (found_obj == -1) { |
| 1053 | sprintf(str, "There was no player defined for this start position. The highest numbered player is #%d.", highest); |
| 1054 | OutrageMessageBox(str); |
| 1055 | } else { |
| 1056 | MoveViewer(&Objects[found_obj].pos, Objects[found_obj].roomnum, &Objects[found_obj].orient); |
| 1057 | TV_changed = 1; |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | void CObjectDialog::OnRedCheck() { |
| 1062 | int cur = m_current_start_pos; |
| 1063 | |
| 1064 | int c = IsDlgButtonChecked(IDC_RED_CHECK); |
| 1065 | |
| 1066 | if (c) |
| 1067 | Players[cur].startpos_flags |= PSPF_RED; |
| 1068 | else |
| 1069 | Players[cur].startpos_flags &= ~PSPF_RED; |
| 1070 | } |
| 1071 | |
| 1072 | void CObjectDialog::OnBlueCheck() { |
| 1073 | int cur = m_current_start_pos; |
| 1074 | |
| 1075 | int c = IsDlgButtonChecked(IDC_BLUE_CHECK); |
| 1076 | |
| 1077 | if (c) |
| 1078 | Players[cur].startpos_flags |= PSPF_BLUE; |
| 1079 | else |
| 1080 | Players[cur].startpos_flags &= ~PSPF_BLUE; |
| 1081 | } |
| 1082 | |
| 1083 | void CObjectDialog::OnGreenCheck() { |
| 1084 | int cur = m_current_start_pos; |
| 1085 | |
| 1086 | int c = IsDlgButtonChecked(IDC_GREEN_CHECK); |
| 1087 | |
| 1088 | if (c) |
| 1089 | Players[cur].startpos_flags |= PSPF_GREEN; |
| 1090 | else |
| 1091 | Players[cur].startpos_flags &= ~PSPF_GREEN; |
| 1092 | } |
| 1093 | |
| 1094 | void CObjectDialog::OnYellowCheck() { |
| 1095 | int cur = m_current_start_pos; |
| 1096 | |
| 1097 | int c = IsDlgButtonChecked(IDC_YELLOW_CHECK); |
| 1098 | |
| 1099 | if (c) |
| 1100 | Players[cur].startpos_flags |= PSPF_YELLOW; |
| 1101 | else |
| 1102 | Players[cur].startpos_flags &= ~PSPF_YELLOW; |
| 1103 | } |
| 1104 | |
| 1105 | void CObjectDialog::OnSelendokSwapSourceCombo() { |
| 1106 | int cur; |
| 1107 | char name[200]; |
| 1108 | |
| 1109 | cur = SendDlgItemMessage(IDC_SWAP_SOURCE_COMBO, CB_GETCURSEL, 0, 0); |
| 1110 | SendDlgItemMessage(IDC_SWAP_SOURCE_COMBO, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name); |
| 1111 | |
| 1112 | Swap_source_id = FindObjectIDName(name); |
| 1113 | |
| 1114 | UpdateDialog(); |
| 1115 | } |
| 1116 | |
| 1117 | void CObjectDialog::OnSelendokSwapDestCombo() { |
| 1118 | int cur; |
| 1119 | char name[200]; |
| 1120 | |
| 1121 | cur = SendDlgItemMessage(IDC_SWAP_DEST_COMBO, CB_GETCURSEL, 0, 0); |
| 1122 | SendDlgItemMessage(IDC_SWAP_DEST_COMBO, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name); |
| 1123 | |
| 1124 | Swap_dest_id = FindObjectIDName(name); |
| 1125 | |
| 1126 | UpdateDialog(); |
| 1127 | } |
| 1128 | |
| 1129 | void CObjectDialog::OnObjectSwapButton() { |
| 1130 | int i; |
| 1131 | int cur; |
| 1132 | char name[200]; |
| 1133 | |
| 1134 | cur = SendDlgItemMessage(IDC_SWAP_SOURCE_COMBO, CB_GETCURSEL, 0, 0); |
| 1135 | SendDlgItemMessage(IDC_SWAP_SOURCE_COMBO, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name); |
| 1136 | int s_id = FindObjectIDName(name); |
| 1137 | |
| 1138 | cur = SendDlgItemMessage(IDC_SWAP_DEST_COMBO, CB_GETCURSEL, 0, 0); |
| 1139 | SendDlgItemMessage(IDC_SWAP_DEST_COMBO, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name); |
| 1140 | int d_id = FindObjectIDName(name); |
| 1141 | |
| 1142 | if (s_id >= 0 && d_id >= 0) { |
| 1143 | for (i = 0; i <= Highest_object_index; i++) { |
| 1144 | if (Objects[i].type == OBJ_ROBOT || Objects[i].type == OBJ_CLUTTER || Objects[i].type == OBJ_POWERUP || |
| 1145 | Objects[i].type == OBJ_BUILDING) { |
| 1146 | if (Objects[i].id == s_id) { |
| 1147 | vector pos = Objects[i].pos; |
| 1148 | matrix orient = Objects[i].orient; |
| 1149 | int room = Objects[i].roomnum; |
| 1150 | int parent = Objects[i].parent_handle; |
| 1151 | |
| 1152 | char temp_name[256]; |
| 1153 | temp_name[0] = '\0'; |
| 1154 | |
| 1155 | if (Objects[i].name) { |
| 1156 | strcpy(temp_name, Objects[i].name); |
| 1157 | } |
| 1158 | |
| 1159 | ObjDelete(i); |
| 1160 | int o_index = ObjCreate(Object_info[d_id].type, d_id, room, &pos, &orient, parent); |
| 1161 | |
| 1162 | if (temp_name[0] != '\0') { |
| 1163 | Objects[o_index].name = (char *)mem_malloc(strlen(temp_name) + 1); |
| 1164 | strcpy(Objects[o_index].name, temp_name); |
| 1165 | } |
| 1166 | } |
| 1167 | } |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | World_changed = 1; |
| 1172 | |
| 1173 | UpdateDialog(); |
| 1174 | } |
| 1175 | |
| 1176 | void CObjectDialog::OnSelendokRegroundCombo() { |
| 1177 | int cur; |
| 1178 | char name[200]; |
| 1179 | |
| 1180 | cur = SendDlgItemMessage(IDC_REGROUND_COMBO, CB_GETCURSEL, 0, 0); |
| 1181 | SendDlgItemMessage(IDC_REGROUND_COMBO, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name); |
| 1182 | |
| 1183 | Reground_id = FindObjectIDName(name); |
| 1184 | |
| 1185 | UpdateDialog(); |
| 1186 | } |
| 1187 | |
| 1188 | void CObjectDialog::OnRegroundButton() { |
| 1189 | if (Reground_id >= 0 && Object_info[Reground_id].type != OBJ_NONE) { |
| 1190 | int i; |
| 1191 | for (i = 0; i <= Highest_object_index; i++) { |
| 1192 | vector gp; |
| 1193 | object *obj = &Objects[i]; |
| 1194 | |
| 1195 | if (obj->type == OBJ_ROBOT || obj->type == OBJ_CLUTTER || obj->type == OBJ_POWERUP || obj->type == OBJ_BUILDING) { |
| 1196 | if (obj->id == Reground_id && PhysCalcGround(&gp, NULL, &Objects[i], 0)) { |
| 1197 | fvi_info hit_info; |
| 1198 | fvi_query fq; |
| 1199 | int fate; |
| 1200 | vector start = obj->pos + obj->size * 0.8f * obj->orient.uvec; |
| 1201 | vector end = obj->pos - obj->size * 2.0f * obj->orient.uvec; |
| 1202 | |
| 1203 | fq.p0 = &start; |
| 1204 | fq.p1 = &end; |
| 1205 | fq.startroom = obj->roomnum; |
| 1206 | |
| 1207 | fq.rad = 0.0f; |
| 1208 | fq.flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS; |
| 1209 | fq.thisobjnum = OBJNUM(obj); |
| 1210 | fq.ignore_obj_list = NULL; |
| 1211 | |
| 1212 | fate = fvi_FindIntersection(&fq, &hit_info); |
| 1213 | |
| 1214 | if (fate != HIT_NONE) { |
| 1215 | float ps; |
| 1216 | float pr; |
| 1217 | float diff; |
| 1218 | |
| 1219 | ps = (gp - obj->pos) * obj->orient.uvec; |
| 1220 | pr = (hit_info.hit_pnt - obj->pos) * obj->orient.uvec; |
| 1221 | |
| 1222 | if (ps != pr) { |
| 1223 | diff = ps - pr; |
| 1224 | obj->pos -= diff * obj->orient.uvec; |
| 1225 | ObjSetPos(obj, &obj->pos, obj->roomnum, NULL, false); |
| 1226 | |
| 1227 | World_changed = 1; |
| 1228 | } |
| 1229 | } |
| 1230 | } |
| 1231 | } |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | UpdateDialog(); |
| 1236 | } |
| 1237 | |
| 1238 | extern bool RotateObject(int objnum, angle p, angle h, angle b); |
| 1239 | |
| 1240 | void CObjectDialog::OnObjRot90() { |
| 1241 | angle p = 0, b = 0, h = 0; |
| 1242 | |
| 1243 | switch (D3EditState.object_move_axis) { |
| 1244 | case OBJMOVEAXIS_P: |
| 1245 | p = 0x4000; |
| 1246 | break; |
| 1247 | case OBJMOVEAXIS_H: |
| 1248 | h = 0x4000; |
| 1249 | break; |
| 1250 | case OBJMOVEAXIS_B: |
| 1251 | b = 0x4000; |
| 1252 | break; |
| 1253 | case OBJMOVEAXIS_PH: |
| 1254 | p = 0x4000; |
| 1255 | h = 0x4000; |
| 1256 | break; |
| 1257 | |
| 1258 | default: |
| 1259 | return; |
| 1260 | } |
| 1261 | |
| 1262 | RotateObject(Cur_object_index, p, h, b); |
| 1263 | } |
| 1264 | |
| 1265 | void CObjectDialog::OnObjectPushthroughwalls() { |
| 1266 | if (f_allow_objects_to_be_pushed_through_walls) |
| 1267 | f_allow_objects_to_be_pushed_through_walls = false; |
| 1268 | else |
| 1269 | f_allow_objects_to_be_pushed_through_walls = true; |
| 1270 | } |
| 1271 | |
| 1272 | void CObjectDialog::OnObjpadDeleteAll() { |
| 1273 | if (Cur_object_index == -1) |
| 1274 | return; |
| 1275 | |
| 1276 | object *objp = &Objects[Cur_object_index]; |
| 1277 | |
| 1278 | if (objp->type == OBJ_PLAYER) { |
| 1279 | OutrageMessageBox("You cannot use this function on player objects."); |
| 1280 | return; |
| 1281 | } |
| 1282 | |
| 1283 | int type = objp->type, id = objp->id; |
| 1284 | |
| 1285 | if (type == OBJ_DOOR) { |
| 1286 | if (OutrageMessageBox(MBOX_YESNO, |
| 1287 | "It's very, very bad to delete a door object. Are you sure you want to delete all instances " |
| 1288 | "of the \"%s\" door?", |
| 1289 | Doors[id].name) != IDYES) |
| 1290 | return; |
| 1291 | } else { // Not a door |
| 1292 | char *objid_name; |
| 1293 | if (IS_GENERIC(type)) |
| 1294 | objid_name = Object_info[id].name; |
| 1295 | else |
| 1296 | objid_name = "<unknown>"; |
| 1297 | if (OutrageMessageBox(MBOX_YESNO, "Are you sure you want to delete all %s objects of type \"%s\" in the mine?", |
| 1298 | Object_type_names[type], objid_name) != IDYES) |
| 1299 | return; |
| 1300 | } |
| 1301 | |
| 1302 | int count = 0; |
| 1303 | for (int objnum = 0; objnum <= Highest_object_index; objnum++) { |
| 1304 | if ((Objects[objnum].type == type) && (Objects[objnum].id == id)) { |
| 1305 | ObjDelete(objnum); |
| 1306 | count++; |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | EditorStatus("%d objects deleted.", count); |
| 1311 | World_changed = 1; |
| 1312 | } |