Debian Codegraph @

editor/WorldObjectsPlayerDialog.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/WorldObjectsPlayerDialog.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:57:39 $
23 * $Author: kevinb $
24 *
25 * WorldObjectsPlayerDialog.cpp : implementation file
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 31 4/21/99 4:39p Jason
30 * fixed ship model loading
31 *
32 * 30 11/06/98 12:34p Jason
33 * more speedups for manage system
34 *
35 * 29 10/15/98 11:06a Jason
36 * fixed stupid checkin bug
37 *
38 * 28 10/14/98 12:09p Jason
39 * fixed some long standing name problems
40 *
41 * 27 10/02/98 1:47p Jason
42 * added lod player ships
43 *
44 * 26 8/20/98 11:53a Samir
45 * fixed filename make when choosing a cockpit inf file.
46 *
47 * 25 8/07/98 2:43p Jeff
48 * added allow by default
49 *
50 * 24 7/31/98 5:23p Jason
51 * added ship armor scalars
52 *
53 * 23 6/23/98 2:43p Matt
54 * Changed calls to OutrageMessageBox() & Debug_MessageBox() to deal with
55 * int return value (instead of bool).
56 *
57 * 22 6/15/98 4:00p Jason
58 * replaced monochromatic polymodel lighting with rgb lighting
59 *
60 * 21 4/30/98 11:32a Chris
61 * ClearWB to WBClear
62 *
63 * 20 4/17/98 1:53p Matt
64 * Reinitialize all objects when leaving the editor dialogs for generic
65 * objects (robots, powerps), doors, and player ships.
66 *
67 * 19 4/06/98 1:33p Samir
68 * Added interface to get cockpit inf filename and store in page.
69 *
70 * 18 4/02/98 3:54p Jason
71 * first pass in getting polymodel paging to work
72 *
73 * 17 3/12/98 6:51p Chris
74 * Added a check
75 *
76 * 16 2/25/98 12:23p Jason
77 * ask users if they want to delete WB info when changing the model
78 *
79 * 15 2/06/98 6:29p Jason
80 * fixed broken checkin
81 *
82 * 14 2/06/98 6:18p Jason
83 * fixed model mixup bug
84 *
85 * 13 12/19/97 11:25a Samir
86 * g3_StartFrame and g3_EndFrame replaced by EditorStartFrame and
87 * EditorEndFrame
88 *
89 * 12 12/01/97 6:06p Samir
90 * Implemented new FileDialog tracker system.
91 *
92 * 11 11/04/97 6:18p Chris
93 * Added support so that the player ship uses the robot's firing dialog.
94 *
95 * 10 11/02/97 4:27p Matt
96 * Made physics dialog copy data back into original struct, instead of
97 * having the caller do it.
98 *
99 * 9 10/21/97 11:57a Jason
100 * added ability to set dying model for player ship
101 *
102 * 8 10/06/97 3:24p Jason
103 * fixed checkin problem
104 *
105 * 7 9/02/97 3:28p Matt
106 * Got rid of warnings
107 *
108 * 6 8/13/97 11:25a Matt
109 * Made player ship dialog use standard physics dialog
110 *
111 * 5 8/08/97 2:25p Matt
112 * Took out error messages which are now handled by mng_MakeLocker()
113 *
114 * 4 8/06/97 12:40p Jason
115 * fixed some potentially serious memory problems
116 *
117 * 3 7/24/97 6:11p Matt
118 * Created symbolic constant for default zoom, and used it every place
119 * that specifies zoom
120 *
121 * $NoKeywords: $
122 */
123
124 #include <filesystem>
125
126 #include "mfc_compatibility.h"
127 #include "editor.h"
128 #include "WorldObjectsPlayerDialog.h"
129 #include "shippage.h"
130 #include "ship.h"
131 #include "manage.h"
132 #include "polymodel.h"
133 #include "PhysicsDlg.h"
134 #include "PlayerWeaponsDialog.h"
135 #include "robotfire.h"
136 #include "ddio.h"
137 #include "polymodel.h"
138 #include "objinit.h"
139
140 #ifdef _DEBUG
141 #define new DEBUG_NEW
142 #undef THIS_FILE
143 static char THIS_FILE[] = __FILE__;
144 #endif
145
146 /////////////////////////////////////////////////////////////////////////////
147 // CWorldObjectsPlayerDialog dialog
148
149 CWorldObjectsPlayerDialog::CWorldObjectsPlayerDialog(CWnd *pParent /*=NULL*/)
150 : CDialog(CWorldObjectsPlayerDialog::IDD, pParent) {
151 //{{AFX_DATA_INIT(CWorldObjectsPlayerDialog)
152 // NOTE: the ClassWizard will add member initialization here
153 //}}AFX_DATA_INIT
154 }
155
156 void CWorldObjectsPlayerDialog::DoDataExchange(CDataExchange *pDX) {
157 CDialog::DoDataExchange(pDX);
158 //{{AFX_DATA_MAP(CWorldObjectsPlayerDialog)
159 // NOTE: the ClassWizard will add DDX and DDV calls here
160 //}}AFX_DATA_MAP
161 }
162
163 BEGIN_MESSAGE_MAP(CWorldObjectsPlayerDialog, CDialog)
164 //{{AFX_MSG_MAP(CWorldObjectsPlayerDialog)
165 ON_BN_CLICKED(IDC_ADD_PSHIP, OnAddPship)
166 ON_BN_CLICKED(IDC_PSHIP_CHECKIN, OnPshipCheckin)
167 ON_BN_CLICKED(IDC_PSHIP_DELETE, OnPshipDelete)
168 ON_BN_CLICKED(IDC_PSHIP_LOAD_MODEL, OnPshipLoadModel)
169 ON_BN_CLICKED(IDC_PSHIP_LOCK, OnPshipLock)
170 ON_EN_KILLFOCUS(IDC_PSHIP_NAME_EDIT, OnKillfocusPshipNameEdit)
171 ON_BN_CLICKED(IDC_PSHIP_NEXT, OnPshipNext)
172 ON_BN_CLICKED(IDC_PSHIP_PREV, OnPshipPrev)
173 ON_BN_CLICKED(IDC_PSHIPS_OUT, OnPshipsOut)
174 ON_CBN_SELENDOK(IDC_PSHIP_PULLDOWN, OnSelendokPshipPulldown)
175 ON_WM_TIMER()
176 ON_WM_HELPINFO()
177 ON_BN_CLICKED(IDC_PSHIP_EDIT_PHYSICS, OnPshipEditPhysics)
178 ON_BN_CLICKED(IDC_PSHIP_DYING_MODEL, OnPshipDyingModel)
179 ON_BN_CLICKED(IDC_NULL_DYING, OnNullDying)
180 ON_BN_CLICKED(IDC_EDIT_WEAPONS, OnEditWeapons)
181 ON_BN_CLICKED(IDC_PSHIP_COCKPIT, OnPshipCockpit)
182 ON_EN_KILLFOCUS(IDC_PSHIP_COCKPIT_EDIT, OnKillfocusPshipCockpitEdit)
183 ON_WM_DESTROY()
184 ON_EN_KILLFOCUS(IDC_SHIP_ARMOR_EDIT, OnKillfocusShipArmorEdit)
185 ON_BN_CLICKED(IDC_DEFAULTALLOW, OnDefaultallow)
186 ON_BN_CLICKED(IDC_HIRES_RADIO, OnHiresRadio)
187 ON_BN_CLICKED(IDC_MEDRES_RADIO, OnMedresRadio)
188 ON_BN_CLICKED(IDC_LORES_RADIO, OnLoresRadio)
189 ON_BN_CLICKED(IDC_NOLOD, OnNolod)
190 ON_EN_KILLFOCUS(IDC_LOD_DISTANCE_EDIT, OnKillfocusLodDistanceEdit)
191 //}}AFX_MSG_MAP
192 END_MESSAGE_MAP()
193
194 /////////////////////////////////////////////////////////////////////////////
195 // CWorldObjectsPlayerDialog message handlers
196
197 void CWorldObjectsPlayerDialog::OnAddPship() {
198 char filename[256], dir[256], fname[256], ext[32];
199 char cur_name[100];
200 int img_handle;
201 int ship_handle;
202 int c = 1, finding_name = 1;
203
204 if (!Network_up) {
205 OutrageMessageBox("Sorry babe, the network is down. This action is a no-no.\n");
206 return;
207 }
208
209 // Get the filename of the representing image
210
211 CString filter = "Descent III files (*.pof,*.oof)|*.pof;*.oof||";
212
213 if (!OpenFileDialog(this, (LPCTSTR)filter, filename, Current_model_dir, sizeof(Current_model_dir)))
214 return;
215
216 ddio_SplitPath(filename, dir, fname, ext);
217
218 // Okay, we selected a file. Lets do what needs to be done here.
219 img_handle = LoadShipImage(filename);
220
221 if (img_handle < 0) {
222 OutrageMessageBox("Couldn't open that model file.");
223 return;
224 }
225
226 // Alloc a ship and give a name not already taken by some other ship
227
228 ship_handle = AllocShip();
229
230 while (finding_name) {
231 if (c == 1)
232 sprintf(cur_name, "%s", fname);
233 else
234 sprintf(cur_name, "%s%d", fname, c);
235 if (FindShipName(cur_name) != -1)
236 c++;
237 else
238 finding_name = 0;
239 }
240
241 strcpy(Ships[ship_handle].name, cur_name);
242
243 Ships[ship_handle].model_handle = img_handle;
244
245 // Finally, save a local copy of the model/anim and alloc a tracklock
246 mprintf(0, "Making a copy of this model locally...\n");
247
248 std::filesystem::path destname = LocalModelsDir / Poly_models[Ships[ship_handle].model_handle].name;
249 cf_CopyFile(destname, filename);
250
251 mng_AllocTrackLock(cur_name, PAGETYPE_SHIP);
252
253 D3EditState.current_ship = ship_handle;
254
255 RemapShips();
256
257 UpdateDialog();
258 }
259
260 void CWorldObjectsPlayerDialog::OnPshipCheckin() {
261 int n = D3EditState.current_ship;
262 mngs_Pagelock temp_pl;
263 int r;
264
265 if (Num_ships < 1)
266 return;
267
268 if (!mng_MakeLocker())
269 return;
270
271 // Make sure we own this ship
272 strcpy(temp_pl.name, Ships[n].name);
273 temp_pl.pagetype = PAGETYPE_SHIP;
274
275 r = mng_CheckIfPageOwned(&temp_pl, TableUser);
276 if (r < 0)
277 OutrageMessageBox(ErrorString);
278 else if (r == 0)
279 OutrageMessageBox(InfoString);
280 else {
281 // Change the pagelock state to UNLOCKED
282 strcpy(temp_pl.holder, "UNLOCKED");
283 if (!mng_ReplacePagelock(temp_pl.name, &temp_pl)) {
284 MessageBox(ErrorString, "Error!");
285 mng_EraseLocker();
286 return;
287 } else {
288 // Now actually replace the copy on the net with our local one
289
290 if (!mng_ReplacePage(Ships[n].name, Ships[n].name, n, PAGETYPE_SHIP, 0))
291 OutrageMessageBox(ErrorString);
292 else {
293 // Save this ship anim/model to the network for all
294 std::filesystem::path srcname = LocalModelsDir / Poly_models[Ships[n].model_handle].name;
295 std::filesystem::path destname = NetModelsDir / Poly_models[Ships[n].model_handle].name;
296
297 cf_CopyFile(destname, srcname);
298
299 if (Ships[n].dying_model_handle != -1) {
300 srcname = LocalModelsDir / Poly_models[Ships[n].dying_model_handle].name;
301 destname = NetModelsDir / Poly_models[Ships[n].dying_model_handle].name;
302
303 cf_CopyFile(destname, srcname);
304 }
305
306 if (Ships[n].med_render_handle != -1) {
307 srcname = LocalModelsDir / Poly_models[Ships[n].med_render_handle].name;
308 destname = NetModelsDir / Poly_models[Ships[n].med_render_handle].name;
309
310 cf_CopyFile(destname, srcname);
311 }
312
313 if (Ships[n].lo_render_handle != -1) {
314 srcname = LocalModelsDir / Poly_models[Ships[n].lo_render_handle].name;
315 destname = NetModelsDir / Poly_models[Ships[n].lo_render_handle].name;
316
317 cf_CopyFile(destname, srcname);
318 }
319
320 if (Ships[n].cockpit_name[0]) {
321 srcname = LocalMiscDir / Ships[n].cockpit_name;
322 destname = NetMiscDir / Ships[n].cockpit_name;
323
324 cf_CopyFile(destname, srcname);
325 }
326
327 OutrageMessageBox("Ship checked in.");
328
329 // Delete it from local pagefile if its there
330 int dret = mng_DeletePage(Ships[n].name, PAGETYPE_SHIP, 1);
331 ASSERT(dret == 1);
332 mng_EraseLocker();
333
334 // Free the tracklock
335 int p = mng_FindTrackLock(Ships[n].name, PAGETYPE_SHIP);
336 ASSERT(p != -1);
337 mng_FreeTrackLock(p);
338 UpdateDialog();
339 }
340 }
341 }
342
343 mng_EraseLocker();
344 }
345
346 void CWorldObjectsPlayerDialog::OnPshipDelete() {
347 int answer, tl;
348 mngs_Pagelock pl;
349 int n = D3EditState.current_ship;
350
351 if (Num_ships < 1)
352 return;
353
354 // Check to see if we even have it locked
355 if ((tl = mng_FindTrackLock(Ships[n].name, PAGETYPE_SHIP)) == -1) {
356 OutrageMessageBox("This ship is not yours to delete. Lock first.");
357 return;
358 }
359
360 // Make sure its to be deleted
361 answer = MessageBox("Are you sure you want to delete this ship?", Ships[n].name, MB_YESNO);
362 if (answer == IDNO)
363 return;
364
365 if (!mng_MakeLocker())
366 return;
367
368 strcpy(pl.name, Ships[n].name);
369 pl.pagetype = PAGETYPE_SHIP;
370
371 // Check to see if this is a local ship only. If so, only delete it locally
372 if (mng_CheckIfPageOwned(&pl, TableUser) != 1) {
373 mng_FreeTrackLock(tl);
374 if (!mng_DeletePage(Ships[n].name, PAGETYPE_SHIP, 1)) {
375 mprintf(0, ErrorString);
376 Int3();
377 }
378 } else // if its network, delete it from both the net and local drives
379 {
380
381 mng_FreeTrackLock(tl);
382
383 mng_DeletePage(Ships[n].name, PAGETYPE_SHIP, 0);
384 mng_DeletePage(Ships[n].name, PAGETYPE_SHIP, 1);
385
386 mng_DeletePagelock(Ships[n].name, PAGETYPE_SHIP);
387 }
388
389 // Advance to the next ship
390 D3EditState.current_ship = GetNextShip(n);
391
392 FreePolyModel(Ships[n].model_handle);
393 if (Ships[n].dying_model_handle != -1)
394 FreePolyModel(Ships[n].dying_model_handle);
395
396 FreeShip(n);
397
398 mng_EraseLocker();
399
400 OutrageMessageBox("Ship deleted.");
401
402 RemapShips();
403
404 UpdateDialog();
405 }
406
407 void CWorldObjectsPlayerDialog::OnPshipLoadModel() {
408 char filename[255];
409 int img_handle;
410 int ship_handle;
411 int c = 1, finding_name = 1;
412 int model = 0;
413
414 // Get the filename of the representing image
415
416 CString filter = "Descent III files (*.pof,*.oof)|*.pof;*.oof||";
417
418 if (!OpenFileDialog(this, (LPCTSTR)filter, filename, Current_model_dir, sizeof(Current_model_dir)))
419 return;
420
421 // Okay, we selected a file. Lets do what needs to be done here.
422 img_handle = LoadPolyModel(filename, 0);
423
424 if (img_handle < 0) {
425 OutrageMessageBox("Couldn't open that animation/model file.");
426 return;
427 }
428
429 ship_handle = D3EditState.current_ship;
430
431 // Get rid of the old one possibly
432 if (m_lod == 0) {
433 ChangeOldModelsForObjects(Ships[ship_handle].model_handle, img_handle);
434 FreePolyModel(Ships[ship_handle].model_handle);
435 Ships[ship_handle].model_handle = img_handle;
436 } else if (m_lod == 1) {
437 if (Ships[ship_handle].med_render_handle != -1)
438 FreePolyModel(Ships[ship_handle].med_render_handle);
439
440 Ships[ship_handle].med_render_handle = img_handle;
441 } else {
442 if (Ships[ship_handle].lo_render_handle != -1)
443 FreePolyModel(Ships[ship_handle].lo_render_handle);
444
445 Ships[ship_handle].lo_render_handle = img_handle;
446 }
447
448 // A new model might induce a new weapon stucture
449 if (OutrageMessageBox(MBOX_YESNO, "Would you like to clear the weapon battery info?") == IDYES) {
450 WBClearInfo(Ships[ship_handle].static_wb);
451 }
452
453 // Finally, save a local copy of the model
454 std::filesystem::path curname = LocalModelsDir / Poly_models[img_handle].name;
455 cf_CopyFile(curname, filename);
456
457 UpdateDialog();
458 }
459
460 void CWorldObjectsPlayerDialog::OnPshipLock() {
461 int n = D3EditState.current_ship;
462 mngs_Pagelock temp_pl;
463 mngs_ship_page shippage;
464 int r;
465
466 if (Num_ships < 1)
467 return;
468
469 if (!mng_MakeLocker())
470 return;
471
472 // Make sure it can be locked
473 strcpy(temp_pl.name, Ships[n].name);
474 temp_pl.pagetype = PAGETYPE_SHIP;
475
476 r = mng_CheckIfPageLocked(&temp_pl);
477 if (r == 2) {
478 int answer;
479 answer = OutrageMessageBox(MBOX_YESNO, "This page is not even in the table file, or the database maybe corrupt. "
480 "Override to 'Unlocked'? (Select NO if you don't know what you're doing)");
481 if (answer == IDYES) {
482 strcpy(temp_pl.holder, "UNLOCKED");
483 if (!mng_ReplacePagelock(temp_pl.name, &temp_pl))
484 MessageBox(ErrorString, "Error!");
485 }
486
487 } else if (r < 0)
488 OutrageMessageBox(ErrorString);
489 else if (r == 1)
490 OutrageMessageBox(InfoString);
491 else {
492
493 // Everything is ok. Tell the network we're locking it and get a copy to
494 // our local drive
495
496 strcpy(temp_pl.holder, TableUser);
497 if (!mng_ReplacePagelock(temp_pl.name, &temp_pl)) {
498 MessageBox(ErrorString, "Error!");
499 mng_EraseLocker();
500 return;
501 } else {
502 // Search thru the net pagefile and get a new copy in RAM in case anyone
503 // changed it since we started the editor
504 if (mng_FindSpecificShipPage(temp_pl.name, &shippage)) {
505 if (mng_AssignShipPageToShip(&shippage, n)) {
506 if (!mng_ReplacePage(Ships[n].name, Ships[n].name, n, PAGETYPE_SHIP, 1)) {
507 OutrageMessageBox("There was problem writing that page locally!");
508 mng_EraseLocker();
509 return;
510 }
511
512 OutrageMessageBox("Ship locked.");
513 } else
514 OutrageMessageBox(
515 "There was a problem loading this ship. You might encounter problems in dealing with it. Good luck!");
516
517 mng_AllocTrackLock(Ships[n].name, PAGETYPE_SHIP);
518 UpdateDialog();
519 } else
520 OutrageMessageBox("Couldn't find that ship in the table file!");
521 }
522 }
523 mng_EraseLocker();
524 }
525
526 void CWorldObjectsPlayerDialog::OnKillfocusPshipNameEdit() {
527 CEdit *ebox;
528 int n = D3EditState.current_ship;
529 char name[PAGENAME_LEN];
530 mngs_Pagelock pl;
531
532 // Make sure we have this ship locked, if not reset name and bail
533 int p = mng_FindTrackLock(Ships[n].name, PAGETYPE_SHIP);
534 if (p == -1) {
535 OutrageMessageBox("You must lock this ship if you wish to change its name.");
536 CEdit *ebox = (CEdit *)GetDlgItem(IDC_PSHIP_NAME_EDIT);
537 ebox->SetWindowText(Ships[n].name);
538 return;
539 }
540
541 // Get the new name
542 ebox = (CEdit *)GetDlgItem(IDC_PSHIP_NAME_EDIT);
543 ebox->GetWindowText(name, PAGENAME_LEN);
544
545 // Check to see if there is already a ship with this name. If so, reset and bail
546 if (FindShipName(name) != -1) {
547 OutrageMessageBox("There already is a ship with that name...choose another name.");
548
549 CEdit *ebox = (CEdit *)GetDlgItem(IDC_PSHIP_NAME_EDIT);
550 ebox->SetWindowText(Ships[n].name);
551 return;
552 }
553
554 if (!mng_MakeLocker())
555 return;
556
557 // Check to see if this page exists on the network. If so, we have to
558 // rename it so we can prevent havoc
559 strcpy(pl.name, Ships[n].name);
560 pl.pagetype = PAGETYPE_SHIP;
561
562 int ret = mng_CheckIfPageOwned(&pl, TableUser);
563 if (ret < 0)
564 OutrageMessageBox(ErrorString);
565 else if (ret == 1)
566 mng_RenamePage(Ships[n].name, name, PAGETYPE_SHIP);
567 else if (ret == 2) {
568 // This page has never been checked in, replace only local copy
569
570 char oldname[PAGENAME_LEN];
571 strcpy(oldname, Ships[n].name);
572 strcpy(Ships[n].name, name);
573
574 mng_ReplacePage(oldname, Ships[n].name, n, PAGETYPE_SHIP, 1);
575 } else if (ret == 0) {
576 OutrageMessageBox("You don't own this page. Get Jason now!");
577 mng_FreeTrackLock(p);
578 return;
579 }
580
581 // Finally, copy our new name to the appropriate arrays
582 strcpy(GlobalTrackLocks[p].name, name);
583 strcpy(Ships[n].name, name);
584 mng_EraseLocker();
585
586 RemapShips();
587 UpdateDialog();
588 }
589
590 void CWorldObjectsPlayerDialog::OnPshipNext() {
591 D3EditState.current_ship = GetNextShip(D3EditState.current_ship);
592 m_lod = 0;
593 UpdateDialog();
594 }
595
596 void CWorldObjectsPlayerDialog::OnPshipPrev() {
597 D3EditState.current_ship = GetPrevShip(D3EditState.current_ship);
598 m_lod = 0;
599 UpdateDialog();
600 }
601
602 void CWorldObjectsPlayerDialog::OnPshipsOut() {
603 char str[10000];
604 int total = 0;
605
606 mng_DisplayLockList(TableUser);
607
608 sprintf(str, "User %s has these ships held locally:\n\n", TableUser);
609 for (int i = 0; i < MAX_TRACKLOCKS; i++) {
610 if (GlobalTrackLocks[i].used && GlobalTrackLocks[i].pagetype == PAGETYPE_SHIP) {
611 char temp[90];
612
613 sprintf(temp, "%s", GlobalTrackLocks[i].name);
614 strcat(str, temp);
615 strcat(str, "\n");
616 total++;
617 }
618 }
619
620 if (total != 0) {
621 // Display that string
622 MessageBox(str, "Ships", MB_OK);
623 }
624 }
625
626 void CWorldObjectsPlayerDialog::OnSelendokPshipPulldown() {
627 int i, cur;
628 char name[200];
629
630 cur = SendDlgItemMessage(IDC_PSHIP_PULLDOWN, CB_GETCURSEL, 0, 0);
631 SendDlgItemMessage(IDC_PSHIP_PULLDOWN, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name);
632
633 i = FindShipName(name);
634
635 if (i == -1) {
636 mprintf(0, "Possible corrupted ship list, but probably nothing.");
637 UpdateDialog();
638 }
639
640 D3EditState.current_ship = i;
641 UpdateDialog();
642 }
643
644 // When closing, save all our checked out ships locally so we know
645 // what stuff to flag as "checked out" the next time we start up
646 void CWorldObjectsPlayerDialog::SaveShipsOnClose() {
647 int i, t;
648
649 if (!Network_up)
650 return; // don't save a damn thing if the network is down
651
652 for (i = 0; i < MAX_TRACKLOCKS; i++) {
653 if (GlobalTrackLocks[i].used == 1 && GlobalTrackLocks[i].pagetype == PAGETYPE_SHIP) {
654 t = FindShipName(GlobalTrackLocks[i].name);
655 ASSERT(t != -1);
656
657 mng_ReplacePage(Ships[t].name, Ships[t].name, t, PAGETYPE_SHIP, 1);
658 }
659 }
660 }
661
662 BOOL CWorldObjectsPlayerDialog::DestroyWindow() {
663
664 SaveShipsOnClose();
665 return CDialog::DestroyWindow();
666 }
667
668 BOOL CWorldObjectsPlayerDialog::OnInitDialog() {
669 CDialog::OnInitDialog();
670
671 CWnd::SetTimer(1, 50, NULL);
672
673 m_lod = 0;
674
675 UpdateDialog();
676
677 return TRUE; // return TRUE unless you set the focus to a control
678 // EXCEPTION: OCX Property Pages should return FALSE
679 }
680
681 void CWorldObjectsPlayerDialog::OnTimer(UINT nIDEvent) {
682
683 UpdateShipView();
684 CDialog::OnTimer(nIDEvent);
685 }
686
687 void CWorldObjectsPlayerDialog::UpdateDialog() {
688 CEdit *ebox;
689 CButton *bbox;
690 // CStatic *stext;
691 int n = D3EditState.current_ship;
692 char str[50];
693 char txt[50];
694
695 if (Num_ships < 1) {
696 bbox = (CButton *)GetDlgItem(IDC_PSHIP_NEXT);
697 bbox->EnableWindow(FALSE);
698 bbox = (CButton *)GetDlgItem(IDC_PSHIP_PREV);
699 bbox->EnableWindow(FALSE);
700 bbox = (CButton *)GetDlgItem(IDC_PSHIP_COCKPIT);
701 bbox->EnableWindow(FALSE);
702 return;
703 } else {
704 bbox = (CButton *)GetDlgItem(IDC_PSHIP_NEXT);
705 bbox->EnableWindow(TRUE);
706 bbox = (CButton *)GetDlgItem(IDC_PSHIP_PREV);
707 bbox->EnableWindow(TRUE);
708 bbox = (CButton *)GetDlgItem(IDC_PSHIP_COCKPIT);
709 bbox->EnableWindow(TRUE);
710 }
711
712 if (!Ships[n].used)
713 n = D3EditState.current_ship = GetNextShip(n);
714
715 ebox = (CEdit *)GetDlgItem(IDC_PSHIP_NAME_EDIT);
716 ebox->SetWindowText(Ships[n].name);
717
718 ebox = (CEdit *)GetDlgItem(IDC_PSHIP_MODEL_NAME_EDIT);
719
720 if (m_lod == 0)
721 ebox->SetWindowText(Poly_models[Ships[n].model_handle].name);
722 else if (m_lod == 1) {
723 if (Ships[n].med_render_handle == -1)
724 ebox->SetWindowText("No model defined");
725 else
726 ebox->SetWindowText(Poly_models[Ships[n].med_render_handle].name);
727 } else {
728 if (Ships[n].lo_render_handle == -1)
729 ebox->SetWindowText("No model defined");
730 else
731 ebox->SetWindowText(Poly_models[Ships[n].lo_render_handle].name);
732 }
733
734 // Do LOD distance edit box
735 ebox = (CEdit *)GetDlgItem(IDC_LOD_DISTANCE_EDIT);
736
737 if (m_lod == 0)
738 ebox->SetWindowText("0");
739 else if (m_lod == 1) {
740 sprintf(txt, "%f", Ships[n].med_lod_distance);
741 ebox->SetWindowText(txt);
742 } else {
743 sprintf(txt, "%f", Ships[n].lo_lod_distance);
744 ebox->SetWindowText(txt);
745 }
746
747 ebox = (CEdit *)GetDlgItem(IDC_PSHIP_DYING_MODEL_NAME_EDIT);
748 if (Ships[n].dying_model_handle == -1)
749 ebox->SetWindowText("<none>");
750 else
751 ebox->SetWindowText(Poly_models[Ships[n].dying_model_handle].name);
752
753 ebox = (CEdit *)GetDlgItem(IDC_PSHIP_COCKPIT_EDIT);
754 ebox->SetWindowText(Ships[n].cockpit_name);
755
756 ebox = (CEdit *)GetDlgItem(IDC_SHIP_ARMOR_EDIT);
757 sprintf(str, "%f", Ships[n].armor_scalar);
758 ebox->SetWindowText(str);
759
760 bbox = (CButton *)GetDlgItem(IDC_PSHIP_CHECKIN);
761 if (mng_FindTrackLock(Ships[n].name, PAGETYPE_SHIP) == -1) {
762 bbox->EnableWindow(FALSE);
763 bbox = (CButton *)GetDlgItem(IDC_PSHIP_LOCK);
764 bbox->EnableWindow(TRUE);
765 } else {
766 bbox->EnableWindow(TRUE);
767 bbox = (CButton *)GetDlgItem(IDC_PSHIP_LOCK);
768 bbox->EnableWindow(FALSE);
769 }
770
771 bbox = (CButton *)GetDlgItem(IDC_DEFAULTALLOW);
772 if (Ships[n].flags & SF_DEFAULT_ALLOW)
773 bbox->SetCheck(1);
774 else
775 bbox->SetCheck(0);
776
777 SendDlgItemMessage(IDC_PSHIP_PULLDOWN, CB_RESETCONTENT, 0, 0);
778
779 for (int i = 0; i < MAX_SHIPS; i++) {
780 if (Ships[i].used)
781 SendDlgItemMessage(IDC_PSHIP_PULLDOWN, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)Ships[i].name);
782 }
783 SendDlgItemMessage(IDC_PSHIP_PULLDOWN, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)Ships[n].name);
784
785 ebox = (CEdit *)GetDlgItem(IDC_NOLOD);
786 if (m_lod == 0)
787 ebox->EnableWindow(FALSE);
788 else if (m_lod == 1) {
789 if (Ships[n].med_render_handle == -1)
790 ebox->EnableWindow(FALSE);
791 else
792 ebox->EnableWindow(TRUE);
793 } else {
794 if (Ships[n].lo_render_handle == -1)
795 ebox->EnableWindow(FALSE);
796 else
797 ebox->EnableWindow(TRUE);
798 }
799
800 bbox = (CButton *)GetDlgItem(IDC_HIRES_RADIO);
801 bbox->SetCheck(m_lod == 0);
802
803 bbox = (CButton *)GetDlgItem(IDC_MEDRES_RADIO);
804 bbox->SetCheck(m_lod == 1);
805
806 bbox = (CButton *)GetDlgItem(IDC_LORES_RADIO);
807 bbox->SetCheck(m_lod == 2);
808
809 UpdateShipView();
810 }
811
812 #define NUM_ANIM_FRAMES 30
813
814 void CWorldObjectsPlayerDialog::UpdateShipView(void) {
815 int n = D3EditState.current_ship;
816 CWnd *shipwnd;
817 RECT rect;
818 int x, y, bm_handle, w, h, render_handle;
819 static int frame = 0, spin_frame = 0;
820 static int last_ship = -1;
821 static int last_model_handle = -1;
822 static int ship_dir = 0;
823
824 if (Num_ships < 1)
825 return;
826
827 if (ship_dir == 0) {
828 frame++;
829 if (frame == NUM_ANIM_FRAMES) {
830 frame = NUM_ANIM_FRAMES - 1;
831 ship_dir = 1;
832 }
833 } else {
834 frame--;
835 if (frame == -1) {
836 frame = 0;
837 ship_dir = 0;
838 }
839 }
840
841 shipwnd = GetDlgItem(IDC_SHIPVIEW);
842 shipwnd->GetWindowRect(&rect);
843 ScreenToClient(&rect);
844
845 Desktop_surf->attach_to_window((unsigned)m_hWnd);
846
847 w = rect.right - rect.left;
848 h = rect.bottom - rect.top;
849
850 if (m_lod == 0)
851 render_handle = Ships[n].model_handle;
852 else if (m_lod == 1)
853 render_handle = Ships[n].med_render_handle;
854 else
855 render_handle = Ships[n].lo_render_handle;
856
857 if (last_ship != n || last_model_handle != render_handle) {
858 Desktop_surf->clear(rect.left, rect.top, w, h);
859 last_ship = n;
860 last_model_handle = Ships[n].model_handle;
861 }
862
863 bm_handle = render_handle;
864
865 if (bm_handle == -1)
866 return;
867
868 vector zero_vector;
869 vector view_vector = {0, 0, -20};
870 matrix id_matrix, rot_matrix;
871 poly_model *pm = GetPolymodelPointer(bm_handle);
872
873 vm_MakeZero(&zero_vector);
874 vm_MakeIdentity(&id_matrix);
875
876 float norm_angles[30];
877
878 for (int i = 0; i < 30; i++)
879 norm_angles[i] = (float)frame / (float)NUM_ANIM_FRAMES;
880
881 spin_frame++;
882
883 vm_AnglesToMatrix(&rot_matrix, 0, spin_frame * 400, 0);
884
885 m_ShipSurf.create(128, 128, BPP_16);
886 grViewport *vport = new grViewport(&m_ShipSurf);
887 StartEditorFrame(vport, &view_vector, &id_matrix, D3_DEFAULT_ZOOM);
888 DrawPolygonModel(&zero_vector, &rot_matrix, bm_handle, norm_angles, 0, 1.0, 1.0, 1.0);
889 EndEditorFrame();
890
891 x = rect.left + ((rect.right - rect.left) / 2) - m_ShipSurf.width() / 2;
892 y = rect.top + ((rect.bottom - rect.top) / 2) - m_ShipSurf.height() / 2;
893 Desktop_surf->blt(x, y, &m_ShipSurf);
894
895 delete vport;
896 m_ShipSurf.free();
897 }
898
899 BOOL CWorldObjectsPlayerDialog::OnHelpInfo(HELPINFO *pHelpInfo) {
900 WinHelp(HID_PLAYERSHIPSDLG, HELP_CONTEXT);
901 return TRUE;
902 // return CDialog::OnHelpInfo(pHelpInfo);
903 }
904
905 void CWorldObjectsPlayerDialog::OnPshipEditPhysics() {
906 int n = D3EditState.current_ship;
907
908 CPhysicsDlg dlg(&Ships[n].phys_info);
909
910 dlg.DoModal();
911 }
912
913 void CWorldObjectsPlayerDialog::OnPshipDyingModel() {
914 char filename[_MAX_PATH];
915 int img_handle;
916 int ship_handle;
917 int c = 1, finding_name = 1;
918 int model = 0;
919
920 // Get the filename of the representing image
921
922 CString filter = "Descent III files (*.pof,*.oof)|*.pof;*.oof||";
923
924 if (!OpenFileDialog(this, (LPCTSTR)filter, filename, Current_model_dir, sizeof(Current_model_dir)))
925 return;
926
927 // Okay, we selected a file. Lets do what needs to be done here.
928 img_handle = LoadShipImage(filename);
929
930 if (img_handle < 0) {
931 OutrageMessageBox("Couldn't open that animation/model file.");
932 return;
933 }
934
935 ship_handle = D3EditState.current_ship;
936
937 Ships[ship_handle].dying_model_handle = img_handle;
938
939 // Finally, save a local copy of the model
940
941 std::filesystem::path curname = LocalModelsDir / Poly_models[Ships[ship_handle].dying_model_handle].name;
942 cf_CopyFile(curname, filename);
943
944 UpdateDialog();
945 }
946
947 void CWorldObjectsPlayerDialog::OnNullDying() {
948 int n = D3EditState.current_ship;
949 Ships[n].dying_model_handle = -1;
950 UpdateDialog();
951 }
952
953 void CWorldObjectsPlayerDialog::OnEditWeapons() {
954 PlayerWeaponsDialog dlg(D3EditState.current_ship);
955
956 dlg.DoModal();
957 // if (dlg.DoModal() == IDOK)
958 // dlg.GetData();
959 }
960
961 void CWorldObjectsPlayerDialog::OnPshipCockpit() {
962 char filename[_MAX_PATH];
963 char curname[_MAX_PATH];
964 char ext[32];
965
966 // Get the filename of the representing image
967
968 CString filter = "Descent III files (*.inf)|*.inf||";
969
970 if (!OpenFileDialog(this, (LPCTSTR)filter, filename, NULL, 0))
971 return;
972
973 // Okay, we selected a file. Lets do what needs to be done here.
974 ddio_SplitPath(filename, NULL, curname, ext);
975 sprintf(Ships[D3EditState.current_ship].cockpit_name, "%s%s", curname, ext);
976
977 // Finally, save a local copy of the inf file.
978 sprintf(curname, "%s\\%s", LocalMiscDir.u8string().c_str(), Ships[D3EditState.current_ship].cockpit_name);
979 cf_CopyFile(curname, filename);
980
981 UpdateDialog();
982 }
983
984 void CWorldObjectsPlayerDialog::OnKillfocusPshipCockpitEdit() {
985 CEdit *ebox;
986 char name[PAGENAME_LEN];
987
988 // Get the new name
989 ebox = (CEdit *)GetDlgItem(IDC_PSHIP_COCKPIT_EDIT);
990 ebox->GetWindowText(name, PAGENAME_LEN);
991
992 strcpy(Ships[D3EditState.current_ship].cockpit_name, name);
993 }
994
995 void CWorldObjectsPlayerDialog::OnDestroy() {
996 CDialog::OnDestroy();
997
998 ObjReInitAll();
999 }
1000
1001 void CWorldObjectsPlayerDialog::OnKillfocusShipArmorEdit() {
1002 CEdit *ebox;
1003 char name[PAGENAME_LEN];
1004
1005 // Get the new name
1006 ebox = (CEdit *)GetDlgItem(IDC_SHIP_ARMOR_EDIT);
1007
1008 ebox->GetWindowText(name, PAGENAME_LEN);
1009 float val = atof(name);
1010
1011 if (val < .05)
1012 val = .05f;
1013 if (val > 10)
1014 val = 10;
1015
1016 Ships[D3EditState.current_ship].armor_scalar = val;
1017 UpdateDialog();
1018 }
1019
1020 void CWorldObjectsPlayerDialog::OnDefaultallow() {
1021 CButton *bbox;
1022
1023 bbox = (CButton *)GetDlgItem(IDC_DEFAULTALLOW);
1024
1025 if (bbox->GetCheck())
1026 Ships[D3EditState.current_ship].flags |= SF_DEFAULT_ALLOW;
1027 else
1028 Ships[D3EditState.current_ship].flags &= ~SF_DEFAULT_ALLOW;
1029 }
1030
1031 void CWorldObjectsPlayerDialog::OnHiresRadio() {
1032 m_lod = 0;
1033 UpdateDialog();
1034 }
1035
1036 void CWorldObjectsPlayerDialog::OnMedresRadio() {
1037 m_lod = 1;
1038 UpdateDialog();
1039 }
1040
1041 void CWorldObjectsPlayerDialog::OnLoresRadio() {
1042 m_lod = 2;
1043 UpdateDialog();
1044 }
1045
1046 void CWorldObjectsPlayerDialog::OnNolod() {
1047 int n = D3EditState.current_ship;
1048
1049 if (m_lod == 0) {
1050 MessageBox("You must have a hi-res model.");
1051 return;
1052 }
1053
1054 else if (m_lod == 1) {
1055 FreePolyModel(Ships[n].med_render_handle);
1056 Ships[n].med_render_handle = -1;
1057
1058 } else {
1059 FreePolyModel(Ships[n].lo_render_handle);
1060 Ships[n].lo_render_handle = -1;
1061 }
1062
1063 UpdateDialog();
1064 }
1065
1066 void CWorldObjectsPlayerDialog::OnKillfocusLodDistanceEdit() {
1067 CEdit *ebox;
1068 char str[255];
1069 float dist;
1070 int n = D3EditState.current_ship;
1071
1072 ebox = (CEdit *)GetDlgItem(IDC_LOD_DISTANCE_EDIT);
1073 ebox->GetWindowText(str, 180);
1074 dist = atof(str);
1075
1076 if (dist < 0)
1077 return;
1078
1079 if (m_lod == 1) {
1080 Ships[n].med_lod_distance = dist;
1081 } else if (m_lod == 2) {
1082 Ships[n].lo_lod_distance = dist;
1083 }
1084
1085 UpdateDialog();
1086 }