Debian Codegraph @

editor/DallasMainDlg.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/DallasMainDlg.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:57:37 $
23 * $Author: kevinb $
24 *
25 * This is the code for the main dialog of the DALLAS graphical scripting interface
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 87 10/23/99 6:16p Nate
30 * Added support for Polish Message Files
31 *
32 * 86 10/08/99 4:55p Nate
33 * Dallas will now attempt to load the english .msg if a foreign language
34 * .msg cannot be found
35 *
36 * 85 8/31/99 12:05p Nate
37 * Copy command now displays an "Invalid Copy" message and returns if
38 * selected item cannot be copied (instead of just copying the entire
39 * script)
40 *
41 * 84 8/30/99 4:11p Nate
42 * Added copy/paste for conditions, log ops, and nested if-then clauses
43 *
44 * 83 6/17/99 10:24a Kevin
45 * Made things work in a release build
46 *
47 * 82 6/09/99 7:05p Jeff
48 * stub functions added. #ifdef NEWEDITORs added, files changed, to get
49 * Dallas integrated into new editor
50 *
51 * 81 5/21/99 7:32p Nate
52 * Added Save and Restore ability to the custom script section
53 *
54 * 80 5/07/99 10:54a Nate
55 * Added fix for fitting more scripts in the script type popup menu
56 *
57 * 79 5/04/99 6:53p Jeff
58 * added event for when a player dies
59 *
60 * 78 4/27/99 4:27p Jeff
61 * added player respawn osiris event
62 *
63 * 77 4/14/99 6:03p Nate
64 * Added Event Type specification to Dallas Script Highlighting system.
65 *
66 * 76 4/02/99 2:16p Nate
67 * Added AI Init event
68 *
69 * 75 4/01/99 6:02p Nate
70 * added clipping of long messages when reading them in
71 *
72 * 74 3/30/99 4:47p Jeff
73 * added level events for when IGC occurs for a player
74 *
75 * 73 3/17/99 3:57p Nate
76 * Added localization support for message files, and added level check to
77 * script grouping system
78 *
79 * 72 3/11/99 10:51a Nate
80 * Added deletion of "Untitled" Dallas files when doing a New from editor
81 *
82 * 71 3/03/99 3:07p Nate
83 * Temporarily allow designer to select named players
84 *
85 * 70 3/03/99 12:05a Nate
86 * Added IT to AI goal complete event, added dynamic message file name
87 * determination, and made it so you can't select a named player for an
88 * object type
89 *
90 * 69 2/22/99 1:17p Nate
91 * Added 'level goal item complete' event
92 *
93 * 68 2/22/99 1:18a Jeff
94 * added handling for evt_use
95 *
96 * 67 2/20/99 6:07p Nate
97 * Added Level Goal events
98 *
99 * 66 2/19/99 5:35p Nate
100 * Added new types and events
101 *
102 * 65 2/17/99 4:14p Nate
103 * Added condition query shortcuts
104 *
105 * 64 2/17/99 11:36a Nate
106 * Fixed mprintf in script checksum code
107 *
108 * 63 2/17/99 10:57a Nate
109 * Added script checksum code for Jeff
110 *
111 * 62 2/11/99 7:26p Nate
112 * Added check to save button to make sure editor is up before doing
113 * anything
114 *
115 * 61 2/10/99 1:47p Matt
116 * Changed object handle symbolic constants
117 *
118 * 60 2/08/99 7:40p Nate
119 * Fixed up event names to reflect IT's
120 *
121 * 59 2/08/99 3:53p Nate
122 * Added new event types
123 *
124 * 58 2/07/99 4:43p Nate
125 * Added OWNER selection to Door parameter types
126 *
127 * 57 2/05/99 11:52a Nate
128 * Added importing/exporting of scripts
129 *
130 * 56 2/03/99 7:20p Nate
131 * Fixed clipboard bug and added script chaining option
132 *
133 * 55 2/03/99 2:19p Nate
134 * Added cool drag-n-drop support
135 *
136 * 54 2/03/99 11:57a Nate
137 * Added script highlighting interface
138 *
139 * 53 2/03/99 10:37a Nate
140 * Max popup items per column is now 40 for Luke
141 *
142 * 52 2/02/99 7:41p Nate
143 * Added columnization of popup menus
144 *
145 * 51 2/02/99 8:43a Chris
146 * I made buildings with AI work correctly (ie really big robots should be
147 * buildings)
148 * anim to and from states are now shorts instead of bytes
149 *
150 * 50 2/01/99 4:15p Nate
151 * Changed TIMER HANDLE to TIMER ID to match DallasFuncs
152 *
153 * 49 2/01/99 3:48p Nate
154 * Added fix to INVALID_SCRIPT_ID errors
155 *
156 * 48 2/01/99 2:41p Nate
157 * Added title bar display of level and modified indicator
158 *
159 * 47 1/29/99 4:41p Nate
160 * A few minor tweaks and fixes
161 *
162 * 46 1/28/99 9:41p Nate
163 * Added tons of new stuff
164 *
165 * 45 1/26/99 1:15p Nate
166 * Added UserTypes Workshop implementation
167 *
168 * 44 1/25/99 7:16p Nate
169 * Added UserTypes dialog (non-functional)
170 *
171 * 43 1/25/99 2:38p Nate
172 * Added Valid Flag Mask range support.
173 *
174 * 42 1/24/99 4:49p Nate
175 * Added code for Dallas Save Format Version 1, but didn't enable it yet
176 *
177 * 41 1/23/99 5:52p Nate
178 * Added flag support
179 *
180 * 40 1/21/99 8:56p Nate
181 * Added warnings when saving objects
182 *
183 * 39 1/20/99 3:51p Nate
184 * Added Specific Name parameter type 'a'
185 *
186 * 38 1/19/99 7:37p Nate
187 * Added sound selection prompt dialog
188 *
189 * 37 1/19/99 12:18p Nate
190 * Made it so Owner objects can now be "other"
191 *
192 * 36 1/19/99 10:35a Nate
193 * Fixed Other object submenu bug
194 *
195 * 35 1/18/99 2:29p Nate
196 * Added support for default parameters and valid range specification
197 *
198 * 34 1/17/99 6:29p Nate
199 * Layed groundwork for default parameter values and valid parameter
200 * ranges
201 *
202 * 33 1/15/99 7:31p Nate
203 * Added some more interface features/fixes
204 *
205 * 32 1/15/99 2:05p Nate
206 * Added collapse/expand all, fixed me and delete problems, made dlg
207 * longer
208 *
209 * 31 1/15/99 10:37a Nate
210 * Fixed highest room index bug
211 *
212 * 30 1/14/99 6:11p Nate
213 * Added Trigger Script support and many other things, too numerous to
214 * count.
215 *
216 * 29 1/13/99 7:28p Nate
217 * Added message file reading from created script
218 *
219 * 28 1/13/99 10:50a Nate
220 * Fixed up copy/pase, added highlighting of all scripts matching
221 * specified owner
222 *
223 * 27 1/12/99 7:32p Nate
224 * Added copy and paste support
225 *
226 * 26 1/12/99 4:45p Nate
227 * Added max exec time support, added more interface features
228 *
229 * 25 1/11/99 8:42p Nate
230 * Added script parameter support
231 *
232 * 24 1/11/99 6:40p Nate
233 * Added ENUM support
234 *
235 * 23 1/11/99 10:19a Nate
236 * Fixed AND/OR insertion bug
237 *
238 * 22 1/08/99 12:32p Nate
239 * Added glue function validation upon loading scripts
240 *
241 * 21 1/07/99 10:17p Nate
242 * Added first round of script loading code...
243 *
244 * 20 1/06/99 7:09p Nate
245 * Added saving of scripts
246 *
247 * 19 1/06/99 1:13p Nate
248 * Added support for IT objects and ELSE clauses
249 *
250 * 18 1/05/99 8:00p Nate
251 * Added conditional code creation... fixed up interface yet a little
252 * more.
253 *
254 * 17 1/05/99 2:03p Nate
255 * Fixed up events and conditional interface a little
256 *
257 * 16 1/04/99 7:34p Nate
258 * Added rough interface for Conditions
259 *
260 * 15 1/02/99 3:22p Matt
261 * Added support for SaveRestoreState() (new code emailed to me from Jeff)
262 *
263 * 14 12/23/98 6:44p Nate
264 * Added reading in of queries
265 *
266 * 13 12/23/98 4:03p Nate
267 * Added code to implement as a modeless dialog
268 *
269 * 12 12/23/98 12:43p Nate
270 * Fixed small message file parse bug.
271 *
272 * 11 12/23/98 12:35p Nate
273 * Added use of level name in Dallas script file naming system.
274 *
275 * 10 12/22/98 3:55p Nate
276 * Added object and room assignments
277 *
278 * 9 12/21/98 8:00p Nate
279 * Added creation of shell code, started conditional interface.
280 *
281 * 8 12/20/98 4:29p Nate
282 * Added script grouping code (based upon owner, then event type)
283 *
284 * 7 12/18/98 3:10p Nate
285 * Added more interface features.
286 *
287 * 6 12/17/98 9:48p Nate
288 * Added editing of paramaters
289 *
290 * 5 12/16/98 8:45p Nate
291 * Added loading of Actions
292 *
293 * 4 12/15/98 7:47p Nate
294 * Added inserting and deleting of default script trees.
295 *
296 * 3 12/13/98 6:08p Nate
297 * Implemented the Message List interface
298 *
299 * 2 12/11/98 6:45p Nate
300 * Initial Version
301 *
302 * $NoKeywords: $
303 */
304
305 // DallasMainDlg.cpp : implementation file
306 //
307
308 #include "stdafx.h"
309
310 #include <string.h>
311 #include <ctype.h>
312 #include <io.h>
313
314 #include "pserror.h"
315 #include "cfile.h"
316 #include "mem.h"
317 #include "mono.h"
318 #include "ddio.h"
319 #include "manage.h"
320 #include "object.h"
321 #include "room.h"
322 #include "trigger.h"
323 #include "hlsoundlib.h"
324 #include "soundload.h"
325 #include "gametexture.h"
326 #include "gamepath.h"
327 #include "matcen.h"
328 #include "levelgoal.h"
329
330 #ifdef NEWEDITOR
331 #include "globals.h"
332 #include "NewEditor.h"
333 #else
334 #include "editor.h"
335 #include "editorDoc.h"
336 #include "osiris_predefs.h"
337 #include "descent.h"
338 #endif
339
340 #include "ScriptCompilerAPI.h"
341 #include "DallasMainDlg.h"
342 #include "DallasGenericPromptDlg.h"
343 #include "DallasVectorPromptDialog.h"
344 #include "DallasSoundDlg.h"
345 #include "DallasStrmAudioDlg.h"
346 #include "DallasTextureDlg.h"
347 #include "DallasFlagDlg.h"
348 #include "DallasImportDlg.h"
349 #include "DallasUserTypesDlg.h"
350 #include "DallasUtilities.h"
351
352 #ifdef _DEBUG
353 #define new DEBUG_NEW
354 #undef THIS_FILE
355 static char THIS_FILE[] = __FILE__;
356 #endif
357
358 ////////////////////////////////////////////////////////////////////////////
359 // Macro and function to make writing out text to a file a bit easier
360 #define O(x) OutToFile x
361 CFILE *CurrentOutputFile;
362 int CurrentTabLevel;
363
364 // Writes out text to CurrentFile
365 void OutToFile(char *format, ...) {
366 char buffer[1024];
367
368 if (CurrentOutputFile == NULL)
369 return;
370
371 va_list marker;
372 va_start(marker, format);
373 std::vsprintf(buffer, format, marker);
374 cf_WriteString(CurrentOutputFile, buffer);
375 va_end(marker);
376 }
377
378 #define DALLASFUNCS_FILENAME "dallasfuncs.cpp"
379
380 #define NOT_SPECIFIED_MSG "<NOT_SPECIFIED>"
381
382 #define LEVEL_ID_NAME "ID_LEVEL_0000"
383 #define LEVEL_CLASS_NAME "LevelScript_0000"
384
385 // Global declaration of event information database
386 #define UNKNOWN_EVENT_STRING "*Unknown Event*"
387 #define UNKNOWN_EVENT_CODE_NAME "EVT_UNKNOWN"
388 #define UNKNOWN_EVENT_DATA_LINE "// No event data line found!"
389 EventInfoItem event_info[] = {
390 {COLLIDE_EVENT_TYPE, "Collided (with IT)", "EVT_COLLIDE", "tOSIRISEVTCOLLIDE *event_data=&data->evt_collide;",
391 OBJECT_MASK | HAS_IT_MASK},
392 {ACTIVATED_EVENT_TYPE, "Activated (by IT)", "EVT_COLLIDE", "tOSIRISEVTCOLLIDE *event_data=&data->evt_collide;",
393 TRIGGER_MASK | HAS_IT_MASK},
394 {CREATED_EVENT_TYPE, "Created", "EVT_CREATED", "tOSIRISEVTCREATED *event_data=&data->evt_created;", OBJECT_MASK},
395 {DAMAGED_EVENT_TYPE, "Damaged (by IT)", "EVT_DAMAGED", "tOSIRISEVTDAMAGED *event_data=&data->evt_damaged;",
396 OBJECT_MASK | HAS_IT_MASK},
397 {DESTROYED_EVENT_TYPE, "Destroyed", "EVT_DESTROY", "tOSIRISEVTDESTROY *event_data=&data->evt_destroy;",
398 OBJECT_MASK},
399 {FRAME_INTERVAL_EVENT_TYPE, "Frame Interval", "EVT_INTERVAL", "tOSIRISEVTINTERVAL *event_data=&data->evt_interval;",
400 OBJECT_MASK | LEVEL_MASK},
401 {LEVEL_START_EVENT_TYPE, "Level Start", "EVT_LEVELSTART", "tOSIRISEVTLEVELSTART *event_data=&data->evt_levelstart;",
402 LEVEL_MASK},
403 {LEVEL_END_EVENT_TYPE, "Level End", "EVT_LEVELEND", "tOSIRISEVTLEVELEND *event_data=&data->evt_levelend;",
404 LEVEL_MASK},
405 {CHANGE_SEGMENT_EVENT_TYPE, "Changed Segment", "EVT_CHANGESEG",
406 "tOSIRISEVTCHANGESEG *event_data=&data->evt_changeseg;", OBJECT_MASK},
407 {TIMER_EVENT_TYPE, "Timer (TIMER ID) Went Off", "EVT_TIMER", "tOSIRISEVTTIMER *event_data=&data->evt_timer;",
408 OBJECT_MASK | LEVEL_MASK | HAS_TIMERID_MASK},
409 {AI_INIT_EVENT_TYPE, "AI-Initialized", "EVT_AI_INIT", "tOSIRISEVTAIINIT *event_data=&data->evt_ai_init;",
410 OBJECT_MASK},
411 {AIN_OBJKILLED_EVENT_TYPE, "AI-Target (IT) Killed", "EVT_AIN_OBJKILLED",
412 "tOSIRISEVTAINOTIFY *event_data=&data->evt_ain_objkilled;", OBJECT_MASK | HAS_IT_MASK},
413 {AIN_SEEPLAYER_EVENT_TYPE, "AI-Saw Target (IT)", "EVT_AIN_SEEPLAYER",
414 "tOSIRISEVTAINOTIFY *event_data=&data->evt_ain_seeplayer;", OBJECT_MASK | HAS_IT_MASK},
415 {AIN_WHITOBJECT_EVENT_TYPE, "AI-Weapon Damaged Target (IT)", "EVT_AIN_WHITOBJECT",
416 "tOSIRISEVTAINOTIFY *event_data=&data->evt_ain_whitobject;", OBJECT_MASK | HAS_IT_MASK},
417 {AIN_GOALCOMPLETE_EVENT_TYPE, "AI-Goal (GOAL ID) Completed (by IT)", "EVT_AIN_GOALCOMPLETE",
418 "tOSIRISEVTAINOTIFY *event_data=&data->evt_ain_goalcomplete;",
419 OBJECT_MASK | LEVEL_MASK | HAS_GOALID_MASK | HAS_IT_MASK},
420 {AIN_GOALFAIL_EVENT_TYPE, "AI-Goal (GOAL ID) Failed", "EVT_AIN_GOALFAIL",
421 "tOSIRISEVTAINOTIFY *event_data=&data->evt_ain_goalfail;", OBJECT_MASK | LEVEL_MASK | HAS_GOALID_MASK},
422 {AIN_MELHIT_EVENT_TYPE, "AI-Melee Hit on Target (IT)", "EVT_AIN_MELEE_HIT",
423 "tOSIRISEVTAINOTIFY *event_data=&data->evt_ain_melee_hit;", OBJECT_MASK | HAS_IT_MASK},
424 {AIN_MELATTACKFRAME_EVENT_TYPE, "AI-Melee Attack Frame", "EVT_AIN_MELEE_ATTACK_FRAME",
425 "tOSIRISEVTAINOTIFY *event_data=&data->evt_ain_melee_attack_frame;", OBJECT_MASK},
426 {AIN_MOVIE_STARTED_EVENT_TYPE, "AI-Movie Started", "EVT_AIN_MOVIE_START",
427 "tOSIRISEVTAINOTIFY *event_data=&data->evt_ain_movie_start;", OBJECT_MASK},
428 {AIN_MOVIE_ENDED_EVENT_TYPE, "AI-Movie Ended", "EVT_AIN_MOVIE_END",
429 "tOSIRISEVTAINOTIFY *event_data=&data->evt_ain_movie_end;", OBJECT_MASK},
430 {CHILD_DIED_EVENT_TYPE, "A Child (IT) Has Died", "EVT_CHILD_DIED",
431 "tOSIRISEVTCHILDDIED *event_data=&data->evt_child_died;", OBJECT_MASK | HAS_IT_MASK},
432 {DOOR_CLOSED_EVENT_TYPE, "Door Closed", "EVT_DOOR_CLOSE", "tOSIRISEVTDOORCLOSE *event_data=&data->evt_door_close;",
433 DOOR_OBJECT_MASK},
434 {DOOR_ACTIVATED_EVENT_TYPE, "Door Activated", "EVT_DOOR_ACTIVATE",
435 "tOSIRISEVTDOORACTIVATE *event_data=&data->evt_door_activate;", DOOR_OBJECT_MASK},
436 {MATCEN_NOTIFY_EVENT_TYPE, "Matcen (MATCEN ID) Has Spawned (an IT)", "EVT_MATCEN_CREATE",
437 "tOSIRISEVTMATCENCREATE *event_data=&data->evt_matcen_create;", LEVEL_MASK | HAS_MATCENID_MASK | HAS_IT_MASK},
438 {LGOAL_COMPLETED_EVENT_TYPE, "Level Goal (LEVEL GOAL ID) Completed", "EVT_LEVEL_GOAL_COMPLETE",
439 "tOSIRISEVTLEVELGOALCOMPLETE *event_data=&data->evt_level_goal_complete;", LEVEL_MASK | HAS_LEVGOALID_MASK},
440 {LGOAL_ITEM_COMPLETE_EVENT_TYPE, "Level Goal (LEVEL GOAL ID) Item Completed", "EVT_LEVEL_GOAL_ITEM_COMPLETE",
441 "tOSIRISEVTLEVELGOALITEMCOMPLETE *event_data=&data->evt_level_goal_item_complete;",
442 LEVEL_MASK | HAS_LEVGOALID_MASK},
443 {ALL_LGOALS_COMPLETE_EVENT_TYPE, "All Level Goals Completed", "EVT_ALL_LEVEL_GOALS_COMPLETE",
444 "tOSIRISEVTALLLEVELGOALSCOMPLETE *event_data=&data->evt_all_level_goals_complete;", LEVEL_MASK},
445 {PLAYER_MOVIE_START_TYPE, "Movie Starts With Player Target", "EVT_PLAYER_MOVIE_START",
446 "tOSIRISEVTPLAYERMOVIESTART *event_data=&data->evt_player_movie_start;", LEVEL_MASK},
447 {PLAYER_MOVIE_END_TYPE, "Movie Ends With Player Target", "EVT_PLAYER_MOVIE_END",
448 "tOSIRISEVTPLAYERMOVIEEND *event_data=&data->evt_player_movie_end;", LEVEL_MASK},
449 {USED_EVENT_TYPE, "Used (by IT)", "EVT_USE", "tOSIRISEVTUSE *event_data=&data->evt_use;",
450 OBJECT_MASK | HAS_IT_MASK},
451 {PLAYER_RESPAWN_TYPE, "Player (IT) respawns", "EVT_PLAYER_RESPAWN",
452 "tOSIRISEVTPLAYERRESPAWN *event_data=&data->evt_player_respawn;", LEVEL_MASK | HAS_IT_MASK},
453 {PLAYER_DIES_TYPE, "Player (IT) dies", "EVT_PLAYER_DIES",
454 "tOSIRISEVTPLAYERDIES *event_data=&data->evt_player_dies;", LEVEL_MASK | HAS_IT_MASK},
455 {-1, "", "", "", 0}};
456
457 // Global declaration of expression operator information database
458 #define UNKNOWN_EXPOP_STRING "???"
459 ExpOpInfoItem expop_info[] = {
460 {EQUAL_TO, "=", "Equal To (==)", "==", COMPARISON_OPERATOR_TYPE},
461 {NOT_EQUAL_TO, "!=", "Not Equal To (!=)", "!=", COMPARISON_OPERATOR_TYPE},
462 {GREATER_THAN, ">", "Greater Than (>)", ">", COMPARISON_OPERATOR_TYPE},
463 {LESS_THAN, "<", "Less Than (<)", "<", COMPARISON_OPERATOR_TYPE},
464 {GREATER_THAN_OR_EQUAL_TO, ">=", "Greater Than or Equal To (>=)", ">=", COMPARISON_OPERATOR_TYPE},
465 {LESS_THAN_OR_EQUAL_TO, "<=", "Less Than or Equal To (<=)", "<=", COMPARISON_OPERATOR_TYPE},
466 {IS_TRUE, "is TRUE", "Is TRUE (!=0)", "==true", BINARY_OPERATOR_TYPE},
467 {IS_FALSE, "is FALSE", "Is FALSE (==0)", "==false", BINARY_OPERATOR_TYPE},
468 {-1, "", "", ""}};
469
470 // Global declaration of literal info database
471 #define UNKNOWN_LITERAL_STRING "UNKNOWN"
472 ParamMenuItem param_menu_item[] = {{DOOR_PARAMETER_TYPE, "Door"},
473 {OBJECT_PARAMETER_TYPE, "Object"},
474 {ROOM_PARAMETER_TYPE, "Room"},
475 {TRIGGER_PARAMETER_TYPE, "Trigger"},
476 {INT_PARAMETER_TYPE, "Integer"},
477 {BOOL_PARAMETER_TYPE, "Bool"},
478 {FLOAT_PARAMETER_TYPE, "Float"},
479 {VECTOR_PARAMETER_TYPE, "Vector"},
480 {STRING_PARAMETER_TYPE, "String"},
481 {PERCENTAGE_PARAMETER_TYPE, "Percentage"},
482 {ENUM_PARAMETER_TYPE, "Enumerated Types"},
483 {SCRIPT_PARAMETER_TYPE, "Script"},
484 {SOUND_PARAMETER_TYPE, "Sound"},
485 {SPECNAME_PARAMETER_TYPE, "Specific Name"},
486 {TEXTURE_PARAMETER_TYPE, "Texture"},
487 {FLAG_PARAMETER_TYPE, "Flag"},
488 {PATH_PARAMETER_TYPE, "Path"},
489 {MATCEN_PARAMETER_TYPE, "Matcen"},
490 {LEVEL_GOAL_PARAMETER_TYPE, "Level Goal"},
491 {STRM_AUDIO_PARAMETER_TYPE, "Streaming Audio File"},
492 {-1, ""}};
493
494 #define MAX_MESSAGES 10 // max messages to process during a message deferral
495
496 // Processes and waiting messages
497 void DeferMsgs(void) {
498 MSG msg;
499 for (int MsgCount = MAX_MESSAGES; MsgCount && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); MsgCount--) {
500 TranslateMessage(&msg);
501 DispatchMessage(&msg);
502 }
503 }
504
505 bool Compiling = FALSE;
506 CString CompilerOutputText = "";
507 CEdit *help_edit_ctrl = NULL;
508
509 // Gets compiler output and displays it
510 #define HELP_EDIT_CTRL_HEIGHT 7
511 void CompilerCallback(char *text) {
512 CompilerOutputText += text;
513
514 if (help_edit_ctrl == NULL)
515 return;
516 help_edit_ctrl->SetWindowText(CompilerOutputText.GetBuffer(0));
517
518 int total_lines = help_edit_ctrl->GetLineCount();
519 int curr_index = help_edit_ctrl->GetFirstVisibleLine();
520 if ((total_lines - curr_index) > HELP_EDIT_CTRL_HEIGHT) {
521 // we need to scroll down a line
522 help_edit_ctrl->LineScroll((total_lines - curr_index) - HELP_EDIT_CTRL_HEIGHT);
523 }
524
525 DeferMsgs();
526 }
527
528 /////////////////////////////////////////////////////////////////////////////
529 // CDallasMainDlg dialog
530
531 CDallasMainDlg::CDallasMainDlg(CWnd *pParent /*=NULL*/) : CDialog(CDallasMainDlg::IDD, pParent) {
532 //{{AFX_DATA_INIT(CDallasMainDlg)
533 //}}AFX_DATA_INIT
534
535 InitAll();
536
537 help_edit_ctrl = &m_HelpEdit;
538
539 m_pDragImage = NULL;
540 m_bLDragging = FALSE;
541 m_hitemDrag = NULL;
542 m_hitemDrop = NULL;
543 }
544
545 void CDallasMainDlg::DoDataExchange(CDataExchange *pDX) {
546 CDialog::DoDataExchange(pDX);
547 //{{AFX_DATA_MAP(CDallasMainDlg)
548 DDX_Control(pDX, IDC_EVENT_COMBO, m_EventList);
549 DDX_Control(pDX, IDC_EVENT_TREE, m_ScriptTree);
550 DDX_Control(pDX, IDC_HELP_EDIT, m_HelpEdit);
551 DDX_Control(pDX, IDC_MESSAGE_LIST, m_MessageList);
552 DDX_Control(pDX, IDC_MESSAGE_EDIT, m_MessageEdit);
553 //}}AFX_DATA_MAP
554 }
555
556 BEGIN_MESSAGE_MAP(CDallasMainDlg, CDialog)
557 //{{AFX_MSG_MAP(CDallasMainDlg)
558 ON_BN_CLICKED(IDC_NEW_MESSAGE_BUTTON, OnNewMessageButton)
559 ON_BN_CLICKED(IDC_DELETE_MESSAGE_BUTTON, OnDeleteMessageButton)
560 ON_LBN_SELCHANGE(IDC_MESSAGE_LIST, OnSelchangeMessageList)
561 ON_EN_CHANGE(IDC_MESSAGE_EDIT, OnChangeMessageEdit)
562 ON_LBN_DBLCLK(IDC_MESSAGE_LIST, OnDblclkMessageList)
563 ON_BN_CLICKED(IDC_CHANGE_MESSAGE_NAME_BUTTON, OnChangeMessageNameButton)
564 ON_WM_CLOSE()
565 ON_WM_DESTROY()
566 ON_BN_CLICKED(IDC_NEW_EVENT_BUTTON, OnNewScriptButton)
567 ON_BN_CLICKED(IDC_INSERT_EVENT_BUTTON, OnInsertScriptButton)
568 ON_BN_CLICKED(IDC_DELETE_EVENT_BUTTON, OnDeleteScriptButton)
569 ON_NOTIFY(NM_RCLICK, IDC_EVENT_TREE, OnRclickEventTree)
570 ON_NOTIFY(NM_DBLCLK, IDC_EVENT_TREE, OnDblclkScriptTree)
571 ON_NOTIFY(TVN_SELCHANGED, IDC_EVENT_TREE, OnSelchangedScriptTree)
572 ON_BN_CLICKED(IDC_SAVE_BUTTON, OnSaveButton)
573 ON_NOTIFY(TVN_KEYDOWN, IDC_EVENT_TREE, OnKeydownEventTree)
574 ON_BN_CLICKED(IDC_COPY_BUTTON, OnCopyButton)
575 ON_BN_CLICKED(IDC_PASTE_BUTTON, OnPasteButton)
576 ON_BN_CLICKED(IDC_HIGHLIGHT_BUTTON, OnHighlightButton)
577 ON_BN_CLICKED(IDC_EXPAND_ALL_BUTTON, OnExpandAllButton)
578 ON_BN_CLICKED(IDC_COLLAPSE_ALL_BUTTON, OnCollapseAllButton)
579 ON_BN_CLICKED(IDC_UTYPES_BUTTON, OnUtypesButton)
580 ON_NOTIFY(TVN_BEGINDRAG, IDC_EVENT_TREE, OnBegindragEventTree)
581 ON_WM_MOUSEMOVE()
582 ON_WM_LBUTTONUP()
583 ON_BN_CLICKED(IDC_ALLOBJ_RADIO, OnAllobjRadio)
584 ON_BN_CLICKED(IDC_ALLTRIG_RADIO, OnAlltrigRadio)
585 ON_BN_CLICKED(IDC_NONE_RADIO, OnNoneRadio)
586 ON_BN_CLICKED(IDC_SPECIFIC_RADIO, OnSpecificRadio)
587 ON_BN_CLICKED(IDC_LEVEL_RADIO, OnLevelRadio)
588 ON_BN_CLICKED(IDC_IMPORT_BUTTON, OnImportButton)
589 ON_BN_CLICKED(IDC_EXPORT_BUTTON, OnExportButton)
590 ON_BN_CLICKED(IDC_EVENT_RADIO, OnEventRadio)
591 ON_CBN_SELCHANGE(IDC_EVENT_COMBO, OnSelchangeEventCombo)
592 //}}AFX_MSG_MAP
593 ON_WM_ACTIVATE()
594 ON_MESSAGE(WM_HIGHLIGHT_SCRIPTS, OnHighlightScripts)
595 ON_MESSAGE(WM_ADD_SCRIPT, OnAddScript)
596 ON_MESSAGE(WM_ADD_SCRIPT_AND_HIGHLIGHT, OnAddScriptAndHighlight)
597 ON_COMMAND_RANGE(ASSIGN_COMMAND_RANGE_START, ASSIGN_COMMAND_RANGE_END, OnMenuSelectionOfTypeAssign)
598 ON_COMMAND_RANGE(ADD_COMMAND_RANGE_START, ADD_COMMAND_RANGE_END, OnMenuSelectionOfTypeAdd)
599 ON_COMMAND_RANGE(REPLACE_COMMAND_RANGE_START, REPLACE_COMMAND_RANGE_END, OnMenuSelectionOfTypeReplace)
600 ON_COMMAND_RANGE(DELETE_COMMAND_RANGE_START, DELETE_COMMAND_RANGE_END, OnMenuSelectionOfTypeDelete)
601 END_MESSAGE_MAP()
602
603 // Sets up the dialog before it is displayed
604 BOOL CDallasMainDlg::OnInitDialog() {
605 CDialog::OnInitDialog();
606
607 // CString msg;
608 // msg.Format("Starting ID: %d\nEnding ID: %d",STARTING_COMMAND_ID,DELETE_COMMAND_RANGE_END);
609 // MessageBox(msg,"Used ID Range",MB_OK);
610
611 // Setup the tree image list
612 CBitmap bm;
613
614 m_TreeImageList.Create(16, 16, 0, 19, 0);
615
616 bm.LoadBitmap(IDB_DALLAS_TREE_ICONS_BITMAP);
617 m_TreeImageList.Add(&bm, &bm);
618 m_ScriptTree.SetImageList(&m_TreeImageList, TVSIL_NORMAL);
619
620 // Setup the Message List GUI and data
621 m_MessageEdit.SetLimitText(MAX_MESSAGE_LEN);
622
623 // Make sure everything is cleared out, then load in everything
624 Refresh();
625 Compiling = FALSE;
626
627 // m_ScriptOwnerType=LEVEL_TYPE;
628 // m_ScriptOwnerHandle=0;
629 // PostMessage(WM_ADD_SCRIPT_AND_HIGHLIGHT);
630
631 // Set the highlighting to none
632 ClearHighlightRadioButtons();
633 ((CButton *)GetDlgItem(IDC_NONE_RADIO))->SetCheck(1);
634 OnNoneRadio();
635 FillHighlightEventList();
636
637 return TRUE; // return TRUE unless you set the focus to a control
638 // EXCEPTION: OCX Property Pages should return FALSE
639 }
640
641 // Gets called whenever Dallas is activated, allows for validating of script values
642 void CDallasMainDlg::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized) {
643 CDialog::OnActivate(nState, pWndOther, bMinimized);
644
645 #ifndef NEWEDITOR
646 // Make sure we're in the editor
647 if (GetFunctionMode() != EDITOR_MODE)
648 return;
649 #endif
650
651 if (pWndOther == NULL)
652 return;
653
654 CWnd *parent_window;
655 parent_window = pWndOther->GetParent();
656
657 // If Dallas has been activated because it's returned from a child popup,
658 // then get out of here...
659 if (parent_window != NULL) {
660 if (this->m_hWnd == parent_window->m_hWnd)
661 return;
662 }
663
664 // Make sure it's been activated, then scan the tree for bad values
665 if (nState == WA_ACTIVE || nState == WA_CLICKACTIVE) {
666 ClearNameLists();
667 FillNameListsFromTree(TVI_ROOT, FALSE);
668 }
669 }
670
671 // Saves all data
672 void CDallasMainDlg::OnSaveButton() {
673 CString temp_str;
674 char fullpath[_MAX_PATH];
675
676 #ifndef NEWEDITOR
677 // Make sure we're in the editor
678 if (GetFunctionMode() != EDITOR_MODE)
679 return;
680 #endif
681
682 Compiling = TRUE;
683
684 // Create the script source file
685 if (!CreateScriptFile(m_ScriptFilename.GetBuffer(0))) {
686 Compiling = FALSE;
687 return;
688 }
689 SetModified(FALSE);
690
691 // Write out the message list
692 CreateMsgTableFile(m_ScriptMessagesFilename.GetBuffer(0));
693
694 // Get the full DLL path, and delete the DLL
695 ddio_MakePath(fullpath, LocalScriptDir, m_ScriptDLLFilename.GetBuffer(0), NULL);
696 ddio_DeleteFile(fullpath);
697
698 // Attempt to compile it and create the dll
699 CompilerOutputText = "";
700 tCompilerInfo ci;
701 ci.callback = CompilerCallback;
702 ci.script_type = ST_LEVEL;
703
704 strcpy(ci.source_filename, m_ScriptFilename.GetBuffer(0));
705 ScriptCompile(&ci);
706
707 // Check to see if the DLL has been created
708 ddio_MakePath(fullpath, LocalScriptDir, m_ScriptDLLFilename.GetBuffer(0), NULL);
709 if (_access(fullpath, 0x00) == -1) {
710 MessageBox("The compile failed. See output for error details.", "Compiler Error");
711 }
712
713 Compiling = FALSE;
714 }
715
716 // Called when the cancel button is pressed
717 void CDallasMainDlg::OnCancel() {
718 if (Compiling)
719 return;
720
721 if (ModifiedPrompt() == IDNO)
722 return;
723
724 // Shut it all down
725 DestroyWindow();
726
727 // CDialog::OnCancel();
728 }
729
730 // Called just before the window is destroyed
731 void CDallasMainDlg::OnDestroy() {
732 CDialog::OnDestroy();
733
734 // Peform clean-up
735 ClearAll();
736 }
737
738 // Destroy this instance
739 void CDallasMainDlg::PostNcDestroy() {
740 help_edit_ctrl = NULL;
741
742 // Set the pointer back to null so rest of app knows Dallas has shut down
743 #ifdef NEWEDITOR
744 CNewEditorApp *theApp = (CNewEditorApp *)AfxGetApp();
745 theApp->DallasDone();
746 #else
747 theApp.m_DallasModelessDlgPtr = NULL;
748 #endif
749
750 // Delete the Dallas instance
751 delete this;
752 }
753
754 // Called before the window is closed
755 void CDallasMainDlg::OnClose() {
756 if (Compiling)
757 return;
758 if (ModifiedPrompt() == IDNO)
759 return;
760
761 // Shut it all down
762 DestroyWindow();
763 // CDialog::OnClose();
764 }
765
766 // HACK to handle the pressing of the ENTER button (DOESN'T WORK RIGHT NOW)
767 void CDallasMainDlg::OnOK() {
768 if (Compiling)
769 return;
770
771 HTREEITEM selected_item;
772
773 // Pressing ENTER will now cause an edit popup to appear for selected node
774 selected_item = m_ScriptTree.GetSelectedItem();
775 if (selected_item == NULL)
776 return;
777 AssignSpecificValue();
778 }
779
780 // Launches the UserTypes Dialog
781 void CDallasMainDlg::OnUtypesButton() {
782 CDallasUserTypesDlg dlg;
783
784 dlg.DoModal();
785
786 UpdateTreeText(TVI_ROOT);
787 }
788
789 /////////////////////////////////////////////////////////////////////////////
790 // CDallasMainDlg message handlers
791 /////////////////////////////////////////////////////////////////////////////
792
793 // Adds a new (default) message to the message list
794 void CDallasMainDlg::OnNewMessageButton() {
795 CString new_name;
796
797 // Create the new name
798 new_name.Format("%s%d", DEFAULT_MESSAGE_NAME, m_NextMessageID);
799
800 // Make sure the default name isn't already taken
801 while (FindMessageInList(new_name.GetBuffer(0)) != NULL) {
802 m_NextMessageID++;
803 new_name.Format("%s%d", DEFAULT_MESSAGE_NAME, m_NextMessageID);
804 }
805
806 // Add it to the list
807 AddToMessageList(new_name.GetBuffer(0), DEFAULT_MESSAGE_TEXT);
808 m_NextMessageID++;
809
810 // Now let the user change the name if they want to
811 OnDblclkMessageList();
812
813 // And then set focus to the message entry box
814 m_MessageEdit.SetFocus();
815
816 SetModified(TRUE);
817 }
818
819 // Deletes the currently selected message from the list
820 void CDallasMainDlg::OnDeleteMessageButton() {
821 int index;
822 tMessageListEntry *msg_entry;
823
824 index = m_MessageList.GetCurSel();
825 if (index == LB_ERR)
826 return;
827
828 // Get the entry for this item
829 msg_entry = (tMessageListEntry *)m_MessageList.GetItemData(index);
830
831 // Mark this entry as being free
832 DeleteMessageListEntry(msg_entry->name);
833
834 // Delete the list box item and update edit boxes
835 m_MessageList.DeleteString(index);
836 OnSelchangeMessageList();
837
838 SetModified(TRUE);
839 }
840
841 // Callback for when the Message List Box selection changes
842 void CDallasMainDlg::OnSelchangeMessageList() {
843 int index;
844 CString name;
845 tMessageListEntry *msg_entry;
846
847 index = m_MessageList.GetCurSel();
848 if (index == LB_ERR) {
849 m_MessageEdit.SetWindowText("");
850 return;
851 }
852
853 // Get the entry for this item
854 msg_entry = (tMessageListEntry *)m_MessageList.GetItemData(index);
855
856 // Set the edit boxes to reflect the appropriate data
857 m_MessageEdit.SetWindowText(msg_entry->message);
858 }
859
860 // Allows user to change the name of the string
861 void CDallasMainDlg::OnDblclkMessageList() {
862 CDallasGenericPromptDlg dlg;
863 int index;
864 tMessageListEntry *msg_entry;
865 CString message, old_name;
866
867 index = m_MessageList.GetCurSel();
868 if (index == LB_ERR)
869 return;
870
871 // Get the entry for this item
872 msg_entry = (tMessageListEntry *)m_MessageList.GetItemData(index);
873
874 // Display the prompt dialog
875 old_name = msg_entry->name;
876 dlg.m_DialogTitle = "Message Name Prompt";
877 dlg.m_PromptText = "Enter the new name for this message:";
878 dlg.m_PromptData = old_name;
879 dlg.m_MaxDataLength = MAX_MESSAGE_NAME_LEN;
880
881 if (dlg.DoModal() == IDCANCEL)
882 return;
883
884 // Check if the message name is valid
885 char *msgname = dlg.m_PromptData.GetBuffer(0);
886 if (strlen(msgname) == 0)
887 return;
888 for (uint32_t j = 0; j < strlen(msgname); j++)
889 if (isspace(msgname[j]) || (!isalnum(msgname[j]) && msgname[j] != '_')) {
890 MessageBox("That message ID is invalid!\n\nAn ID may only contain letters and numbers",
891 "Invalid Message ID Error", MB_OK | MB_ICONEXCLAMATION);
892 return;
893 }
894
895 // Check if the message name already exists in the list
896 if (FindMessageInList(msgname) != NULL && strcmp(msgname, old_name.GetBuffer(0)) != 0) {
897 MessageBox("That message ID is already in use!\n\nYou must enter a UNIQUE message ID.", "Invalid Message ID Error",
898 MB_OK | MB_ICONEXCLAMATION);
899 return;
900 }
901
902 // Store the message
903 message = msg_entry->message;
904
905 // Remove the old name from list box
906 OnDeleteMessageButton();
907
908 // Now, add the new name (and old message) back in
909 AddToMessageList(dlg.m_PromptData.GetBuffer(0), message.GetBuffer(0));
910
911 // Update any old messageID's in the tree to use the new name
912 UpdateStringParams(TVI_ROOT, old_name.GetBuffer(0), dlg.m_PromptData.GetBuffer(0));
913 SetModified(TRUE);
914 }
915
916 // Does the same thing as double-clicking a name (allows you to change it)
917 void CDallasMainDlg::OnChangeMessageNameButton() {
918 // TODO: Add your control notification handler code here
919 OnDblclkMessageList();
920 }
921
922 // Updates the text for the message being edited
923 void CDallasMainDlg::OnChangeMessageEdit() {
924 // TODO: If this is a RICHEDIT control, the control will not
925 // send this notification unless you override the CDialog::OnInitDialog()
926 // function and call CRichEditCtrl().SetEventMask()
927 // with the ENM_CHANGE flag ORed into the mask.
928
929 // TODO: Add your control notification handler code here
930 int index;
931 CString name, new_message;
932 char *message;
933
934 index = m_MessageList.GetCurSel();
935 if (index == LB_ERR)
936 return;
937
938 m_MessageList.GetText(index, name);
939
940 message = FindMessageInList(name.GetBuffer(0));
941 if (message == NULL)
942 return;
943 m_MessageEdit.GetWindowText(new_message);
944 strcpy(message, new_message.GetBuffer(0));
945 SetModified(TRUE);
946 }
947
948 // Adds a new default script to the end of the list
949 void CDallasMainDlg::OnNewScriptButton() {
950 HTREEITEM new_node;
951
952 int new_id = GetLowestUnusedScriptID();
953
954 new_node = CreateDefaultScriptTree(new_id);
955 if (new_node != NULL) {
956 if (new_id == m_NextScriptID)
957 m_NextScriptID++;
958 m_ScriptTree.SelectItem(new_node);
959 AssignSpecificValue();
960 }
961 }
962
963 // Inserts a new default script before the currently selected script
964 void CDallasMainDlg::OnInsertScriptButton() {
965 HTREEITEM new_node;
966
967 int new_id = GetLowestUnusedScriptID();
968
969 new_node = CreateDefaultScriptTree(new_id, m_ScriptTree.GetSelectedItem());
970 if (new_node != NULL) {
971 if (new_id == m_NextScriptID)
972 m_NextScriptID++;
973 m_ScriptTree.SelectItem(new_node);
974 AssignSpecificValue();
975 }
976 }
977
978 // Deletes the currently selected script
979 void CDallasMainDlg::OnDeleteScriptButton() {
980 HTREEITEM script_header_node;
981
982 script_header_node = GetParentNodeOfType(m_ScriptTree.GetSelectedItem(), SCRIPT_HEADER_NODE);
983 if (script_header_node == NULL)
984 return;
985
986 if (DeletePrompt("Are you sure you want to delete this script?") == IDYES) {
987 FreeTreeItem(script_header_node);
988 SetModified(TRUE);
989 }
990 }
991
992 // Do a script copy
993 void CDallasMainDlg::OnCopyButton() { PerformScriptCopy(); }
994
995 // Do a script paste
996 void CDallasMainDlg::OnPasteButton() { PerformScriptPaste(); }
997
998 // Collapses all node from the selected node on down
999 void CDallasMainDlg::OnExpandAllButton() {
1000 HTREEITEM selected_node;
1001
1002 selected_node = m_ScriptTree.GetSelectedItem();
1003 if (selected_node == NULL)
1004 return;
1005
1006 ExpandAll(selected_node, TVE_EXPAND);
1007 m_ScriptTree.EnsureVisible(selected_node);
1008 }
1009
1010 // Collapses all node from the selected node on down
1011 void CDallasMainDlg::OnCollapseAllButton() {
1012 HTREEITEM selected_node;
1013
1014 selected_node = m_ScriptTree.GetSelectedItem();
1015 if (selected_node == NULL)
1016 return;
1017
1018 ExpandAll(selected_node, TVE_COLLAPSE);
1019 m_ScriptTree.EnsureVisible(selected_node);
1020 }
1021
1022 // Handles the script highlighting
1023 void CDallasMainDlg::OnHighlightButton() {
1024 HTREEITEM selected_node, owner_node;
1025
1026 selected_node = m_ScriptTree.GetSelectedItem();
1027 owner_node = GetScriptOwnerNode(selected_node);
1028 if (owner_node == NULL)
1029 return;
1030
1031 tTreeNodeData *data = (tTreeNodeData *)m_ScriptTree.GetItemData(owner_node);
1032 if (data == NULL)
1033 return;
1034
1035 m_ScriptOwnerType = data->ID;
1036 m_ScriptOwnerHandle = data->int_val;
1037
1038 HighlightAllScripts();
1039
1040 ClearHighlightRadioButtons();
1041 ((CButton *)GetDlgItem(IDC_SPECIFIC_RADIO))->SetCheck(1);
1042 }
1043
1044 // Calls up edit dialogs when double clicking on a node
1045 void CDallasMainDlg::OnDblclkScriptTree(NMHDR *pNMHDR, LRESULT *pResult) {
1046 // TODO: Add your control notification handler code here
1047
1048 *pResult = 0;
1049 }
1050
1051 // Displays a context sensitive pop-up menu
1052 void CDallasMainDlg::OnRclickEventTree(NMHDR *pNMHDR, LRESULT *pResult) {
1053 POINT pt;
1054 TVHITTESTINFO hit_info;
1055
1056 ::GetCursorPos(&pt);
1057 m_ScriptTree.ScreenToClient(&pt);
1058 hit_info.pt = pt;
1059
1060 // Check to see if the mouse is lined up with a tree item
1061 m_ScriptTree.HitTest(&hit_info);
1062 if (hit_info.flags & TVHT_ONITEM || hit_info.flags & TVHT_ONITEMRIGHT || hit_info.flags & TVHT_ONITEMINDENT) {
1063
1064 // Select the item
1065 m_ScriptTree.SelectItem(hit_info.hItem);
1066
1067 // Convert back to screen coordinates for displaying the menu
1068 m_ScriptTree.ClientToScreen(&pt);
1069
1070 DisplayFloatingPopupMenu(hit_info.hItem, pt);
1071 }
1072
1073 *pResult = 0;
1074 }
1075
1076 // Displays a context sensitive pop-up menu for the given node at the given screen pt
1077 void CDallasMainDlg::DisplayFloatingPopupMenu(HTREEITEM node, POINT &pt) {
1078 int valid_return_type;
1079 CString valid_return_name;
1080 tTreeNodeData *data;
1081
1082 if (node == NULL)
1083 return;
1084
1085 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
1086 if (data == NULL)
1087 return;
1088
1089 // Call the appropriate Menu Creation function
1090 switch (data->type) {
1091 case SCRIPT_HEADER_NODE:
1092 DisplayScriptHeaderNodeMenu(&pt);
1093 break;
1094 case SCRIPT_OWNER_NODE:
1095 DisplayScriptOwnerNodeMenu(&pt);
1096 break;
1097 case SCRIPT_EVENT_NODE:
1098 DisplayScriptEventNodeMenu(&pt, GetScriptOwnerType(node), ScriptHasADoorMe(node));
1099 break;
1100 case CONDITIONAL_HEADER_NODE:
1101 break;
1102 case ACTIONS_HEADER_NODE:
1103 DisplayActionHeaderNodeMenu(&pt, data->ID, data->subID, CanAppendElseToNode(node));
1104 break;
1105 case CONDITIONAL_STATEMENT_NODE:
1106 DisplayConditionalStatementNodeMenu(&pt);
1107 break;
1108 case EXPRESSION_NODE:
1109 valid_return_type = GetValidParamType(node, valid_return_name);
1110 DisplayExpressionNodeMenu(&pt, valid_return_type, valid_return_name.GetBuffer(0));
1111 break;
1112 case EXPRESSION_OPERATOR_NODE:
1113 DisplayExpressionOperatorNodeMenu(&pt, data->ID);
1114 break;
1115 case ACTION_STATEMENT_NODE:
1116 DisplayActionStatementNodeMenu(&pt);
1117 break;
1118 case LOGICAL_OPERATOR_NODE:
1119 DisplayLogicalOperatorNodeMenu(&pt);
1120 break;
1121 case PARAMETER_NODE:
1122 valid_return_type = GetValidParamType(node, valid_return_name);
1123 DisplayParameterNodeMenu(&pt, data->ID, data->name, valid_return_type, valid_return_name.GetBuffer(0),
1124 ScriptHasAnIt(node), ScriptHasAMe(node), ScriptHasADoorMe(node), ScriptHasAGoalID(node),
1125 ScriptHasATimerID(node), ScriptHasAMatcenID(node), ScriptHasALevelGoalID(node));
1126 break;
1127 case PARAMETER_OPERATOR_NODE:
1128 break;
1129 case UNKNOWN_NODE:
1130 break;
1131 default:
1132 break;
1133 }
1134 }
1135
1136 // Displays appropriate help for the newly selected item
1137 void CDallasMainDlg::OnSelchangedScriptTree(NMHDR *pNMHDR, LRESULT *pResult) {
1138 NM_TREEVIEW *pNMTreeView = (NM_TREEVIEW *)pNMHDR;
1139
1140 // TODO: Add your control notification handler code here
1141 HTREEITEM selected_item;
1142 tTreeNodeData *data;
1143
1144 selected_item = m_ScriptTree.GetSelectedItem();
1145 if (selected_item == NULL)
1146 return;
1147
1148 data = GetNearestFunctionNode(selected_item);
1149 if (data != NULL) {
1150 // If it's an action node, display the help
1151 if (data->type == ACTION_STATEMENT_NODE) {
1152 char *help = GetActionHelp(data->ID);
1153 if (help != NULL)
1154 m_HelpEdit.SetWindowText(help);
1155 }
1156
1157 // If it's a query node, display the help
1158 if (data->type == EXPRESSION_NODE) {
1159 char *help = GetQueryHelp(data->ID);
1160 if (help != NULL)
1161 m_HelpEdit.SetWindowText(help);
1162 }
1163 }
1164
1165 *pResult = 0;
1166 }
1167
1168 // Allow keyboard input for the tree control
1169 void CDallasMainDlg::OnKeydownEventTree(NMHDR *pNMHDR, LRESULT *pResult) {
1170 TV_KEYDOWN *pTVKeyDown = (TV_KEYDOWN *)pNMHDR;
1171 CTreeCtrl *tree = (CTreeCtrl *)GetDlgItem(pTVKeyDown->hdr.idFrom);
1172 HTREEITEM hSelectedItem = tree->GetSelectedItem();
1173
1174 switch (pTVKeyDown->wVKey) {
1175 case VK_INSERT:
1176 break;
1177
1178 case VK_DELETE:
1179 break;
1180
1181 case VK_SPACE:
1182 tree->Expand(hSelectedItem, TVE_TOGGLE);
1183 break;
1184 }
1185
1186 *pResult = 0;
1187 }
1188
1189 /////////////////////////////////////////////////////////////////////////////
1190 // External DALLAS messaging system
1191 /////////////////////////////////////////////////////////////////////////////
1192
1193 LRESULT CDallasMainDlg::OnHighlightScripts(WPARAM, LPARAM) {
1194 HighlightAllScripts();
1195
1196 ClearHighlightRadioButtons();
1197 ((CButton *)GetDlgItem(IDC_SPECIFIC_RADIO))->SetCheck(1);
1198
1199 return 0;
1200 }
1201
1202 LRESULT CDallasMainDlg::OnAddScript(WPARAM, LPARAM) {
1203 HTREEITEM new_node;
1204
1205 int new_id = GetLowestUnusedScriptID();
1206
1207 new_node = CreateDefaultScriptTree(new_id);
1208 if (new_node != NULL) {
1209 if (new_id == m_NextScriptID)
1210 m_NextScriptID++;
1211 m_ScriptTree.SelectItem(new_node);
1212
1213 // Assign given data to owner
1214 HTREEITEM owner_node = GetScriptOwnerNode(new_node);
1215 if (owner_node != NULL) {
1216 tTreeNodeData *data = (tTreeNodeData *)m_ScriptTree.GetItemData(owner_node);
1217 if (data != NULL) {
1218 data->ID = m_ScriptOwnerType;
1219 data->int_val = m_ScriptOwnerHandle;
1220 if (data->ID == OBJECT_TYPE) {
1221 object *objp = ObjGet(data->int_val);
1222 if (objp == NULL || objp->type == OBJ_NONE || objp->name == NULL) {
1223 data->int_val = OBJECT_HANDLE_NONE;
1224 strcpy(data->str_val, "");
1225 } else {
1226 strcpy(data->str_val, objp->name);
1227 }
1228 } else if (data->ID == TRIGGER_TYPE) {
1229 if (data->int_val < 0 || data->int_val >= Num_triggers) {
1230 data->int_val = NOT_SPECIFIED_TYPE;
1231 strcpy(data->str_val, "");
1232 } else {
1233 strcpy(data->str_val, Triggers[data->int_val].name);
1234 }
1235 } else {
1236 strcpy(data->str_val, "");
1237 }
1238 UpdateNodeText(owner_node);
1239 }
1240 }
1241 // Prompt the user for the name of this script
1242 AssignSpecificValue();
1243 }
1244 return 0;
1245 }
1246
1247 LRESULT CDallasMainDlg::OnAddScriptAndHighlight(WPARAM, LPARAM) {
1248 HTREEITEM new_node;
1249
1250 int new_id = GetLowestUnusedScriptID();
1251
1252 new_node = CreateDefaultScriptTree(new_id);
1253 if (new_node != NULL) {
1254 if (new_id == m_NextScriptID)
1255 m_NextScriptID++;
1256 m_ScriptTree.SelectItem(new_node);
1257
1258 // Assign given data to owner
1259 HTREEITEM owner_node = GetScriptOwnerNode(new_node);
1260 if (owner_node != NULL) {
1261 tTreeNodeData *data = (tTreeNodeData *)m_ScriptTree.GetItemData(owner_node);
1262 if (data != NULL) {
1263 data->ID = m_ScriptOwnerType;
1264 data->int_val = m_ScriptOwnerHandle;
1265 if (data->ID == OBJECT_TYPE) {
1266 object *objp = ObjGet(data->int_val);
1267 if (objp == NULL || objp->type == OBJ_NONE || objp->name == NULL) {
1268 data->int_val = OBJECT_HANDLE_NONE;
1269 strcpy(data->str_val, "");
1270 } else {
1271 strcpy(data->str_val, objp->name);
1272 }
1273 } else if (data->ID == TRIGGER_TYPE) {
1274 if (data->int_val < 0 || data->int_val >= Num_triggers) {
1275 data->int_val = NOT_SPECIFIED_TYPE;
1276 strcpy(data->str_val, "");
1277 } else {
1278 strcpy(data->str_val, Triggers[data->int_val].name);
1279 }
1280 } else {
1281 strcpy(data->str_val, "");
1282 }
1283 UpdateNodeText(owner_node);
1284 }
1285 }
1286
1287 // Highlight all the scripts
1288 HighlightAllScripts();
1289
1290 ClearHighlightRadioButtons();
1291 ((CButton *)GetDlgItem(IDC_SPECIFIC_RADIO))->SetCheck(1);
1292
1293 // Prompt the user for the name of this script
1294 AssignSpecificValue();
1295 }
1296 return 0;
1297 }
1298
1299 // Displays the "are you sure?" dialog
1300 int CDallasMainDlg::ModifiedPrompt(void) {
1301 // If current file has been modified, check with user first...
1302 if (!m_Modified)
1303 return (IDYES);
1304 if (MessageBox("Your changes will be lost. Proceed?", "Script Has Been Modified", MB_YESNO) == IDYES)
1305 return (IDYES);
1306 return (IDNO);
1307 }
1308
1309 // Sets the modified flag
1310 void CDallasMainDlg::SetModified(bool value) {
1311 m_Modified = value;
1312 SetTitleBar();
1313 }
1314
1315 #define DALLAS_TITLE_STRING "Dallas Graphical Script Editor v1.0"
1316
1317 // Updates the Dallas title bar
1318 void CDallasMainDlg::SetTitleBar(void) {
1319 CString title;
1320
1321 // Get the current level name
1322 char filename[_MAX_PATH + 1];
1323
1324 if (m_ScriptFilename.IsEmpty())
1325 strcpy(filename, "Untitled");
1326 else
1327 ddio_SplitPath(m_ScriptFilename.GetBuffer(0), NULL, filename, NULL);
1328
1329 title.Format("%s - %s%s", DALLAS_TITLE_STRING, filename, (m_Modified) ? "*" : "");
1330 SetWindowText(title.GetBuffer(0));
1331 }
1332
1333 /////////////////////////////////////////////////////////////////////////////
1334 // Floating Popup Menu Callbacks
1335 /////////////////////////////////////////////////////////////////////////////
1336
1337 // Translates the type of Assign being requested
1338 void CDallasMainDlg::OnMenuSelectionOfTypeAssign(UINT nID) {
1339 // Check for the assigning of a message name
1340 if (nID >= ASSIGN_SCRIPT_ID_RANGE_START && nID < ASSIGN_SCRIPT_ID_RANGE_END)
1341 AssignScriptID(nID - ASSIGN_SCRIPT_ID_RANGE_START);
1342
1343 // Check for the assigning of an execution time
1344 if (nID >= ASSIGN_EXEC_TIME_ID_RANGE_START && nID < ASSIGN_EXEC_TIME_ID_RANGE_END)
1345 AssignExecTime(nID - ASSIGN_EXEC_TIME_ID_RANGE_START);
1346
1347 // Check for the assigning of a chain option
1348 if (nID >= ASSIGN_CHAIN_ID_RANGE_START && nID < ASSIGN_CHAIN_ID_RANGE_END)
1349 AssignChainOption(nID - ASSIGN_CHAIN_ID_RANGE_START);
1350
1351 // Check for the entering of a specific value (i.e. popup dialog)
1352 if (nID == ASSIGN_SPECIFIC_VALUE_ID)
1353 AssignSpecificValue();
1354
1355 // Check for the entering of a specific value (i.e. popup dialog)
1356 if (nID == ASSIGN_TRUE_ID)
1357 AssignBooleanValue(TRUE);
1358 if (nID == ASSIGN_FALSE_ID)
1359 AssignBooleanValue(FALSE);
1360
1361 // Check for the assigning of a message name
1362 if (nID >= ASSIGN_MESSAGE_ID_RANGE_START && nID < ASSIGN_MESSAGE_ID_RANGE_END)
1363 AssignMessageName(nID - ASSIGN_MESSAGE_ID_RANGE_START);
1364
1365 // Check for the assigning of an event type
1366 if (nID >= ASSIGN_EVENT_ID_RANGE_START && nID < ASSIGN_EVENT_ID_RANGE_END)
1367 AssignEventType(nID - ASSIGN_EVENT_ID_RANGE_START);
1368
1369 // Check for the assigning of a level owner
1370 if (nID == ASSIGN_LEVEL_ID)
1371 AssignNamedValue(LEVEL_TYPE, 0x000);
1372
1373 // Check for the assigning of a trigger owner
1374 if (nID >= ASSIGN_TRIGGER_ID_RANGE_START && nID < ASSIGN_TRIGGER_ID_RANGE_END)
1375 AssignNamedValue(TRIGGER_TYPE, nID - ASSIGN_TRIGGER_ID_RANGE_START);
1376
1377 // Check for the assigning of object none
1378 if (nID == ASSIGN_OBJECT_NONE_ID)
1379 AssignNamedValue(OBJECT_TYPE, OBJECT_NONE_HANDLE);
1380
1381 // Check for the assigning of object IT
1382 if (nID == ASSIGN_OBJECT_IT_ID)
1383 AssignNamedValue(OBJECT_TYPE, OBJECT_IT_HANDLE);
1384
1385 // Check for the assigning of object ME
1386 if (nID == ASSIGN_OBJECT_ME_ID)
1387 AssignNamedValue(OBJECT_TYPE, OBJECT_ME_HANDLE);
1388
1389 // Check for the assigning of a named object
1390 if (nID >= ASSIGN_OBJECT_ID_RANGE_START && nID < ASSIGN_OBJECT_ID_RANGE_END)
1391 AssignNamedValue(OBJECT_TYPE, nID - ASSIGN_OBJECT_ID_RANGE_START);
1392
1393 // Check for the assigning of a named room
1394 if (nID >= ASSIGN_ROOM_ID_RANGE_START && nID < ASSIGN_ROOM_ID_RANGE_END)
1395 AssignNamedValue(ROOM_TYPE, nID - ASSIGN_ROOM_ID_RANGE_START);
1396
1397 // Check for the assigning of an expression operator
1398 if (nID >= ASSIGN_EXPOP_ID_RANGE_START && nID < ASSIGN_EXPOP_ID_RANGE_END)
1399 AssignExpOpType(nID - ASSIGN_EXPOP_ID_RANGE_START);
1400
1401 // Check for the assigning of enum GoalID
1402 if (nID == ASSIGN_ENUM_GOAL_ID)
1403 AssignEnumValueType(ENUM_GOALID_VALUE);
1404
1405 // Check for the assigning of enum TimerID
1406 if (nID == ASSIGN_ENUM_TIMER_ID)
1407 AssignEnumValueType(ENUM_TIMERID_VALUE);
1408
1409 // Check for the assigning of enum MatcenID
1410 if (nID == ASSIGN_ENUM_MATCEN_ID)
1411 AssignEnumValueType(ENUM_MATCENID_VALUE);
1412
1413 // Check for the assigning of an enum value
1414 if (nID >= ASSIGN_ENUM_VALUE_ID_RANGE_START && nID < ASSIGN_ENUM_VALUE_ID_RANGE_END)
1415 AssignEnumValueType(nID - ASSIGN_ENUM_VALUE_ID_RANGE_START);
1416
1417 // Check for the assigning of a path
1418 if (nID >= ASSIGN_PATH_ID_RANGE_START && nID < ASSIGN_PATH_ID_RANGE_END)
1419 AssignNamedValue(PATH_TYPE, nID - ASSIGN_PATH_ID_RANGE_START);
1420
1421 // Check for the assigning of a matcen
1422 if (nID == ASSIGN_MATCEN_EVENT_ID)
1423 AssignNamedValue(MATCEN_TYPE, MATCEN_ID_VALUE);
1424
1425 // Check for the assigning of a matcen
1426 if (nID >= ASSIGN_MATCEN_ID_RANGE_START && nID < ASSIGN_MATCEN_ID_RANGE_END)
1427 AssignNamedValue(MATCEN_TYPE, nID - ASSIGN_MATCEN_ID_RANGE_START);
1428
1429 // Check for the assigning of a level goal
1430 if (nID == ASSIGN_LEVEL_GOAL_ID)
1431 AssignNamedValue(LEVEL_GOAL_TYPE, LEVEL_GOAL_ID_VALUE);
1432
1433 // Check for the assigning of a level goal
1434 if (nID >= ASSIGN_LEVEL_GOAL_ID_RANGE_START && nID < ASSIGN_LEVEL_GOAL_ID_RANGE_END)
1435 AssignNamedValue(LEVEL_GOAL_TYPE, nID - ASSIGN_LEVEL_GOAL_ID_RANGE_START);
1436 }
1437
1438 // Translates the type of Add being requested
1439 void CDallasMainDlg::OnMenuSelectionOfTypeAdd(UINT nID) {
1440 // Check for adding of a nested IF-THEN clause
1441 if (nID == ADD_IF_THEN_CLAUSE_ID)
1442 AddNestedIfThenClause();
1443
1444 // Check for adding of a nested ELSE clause
1445 if (nID == ADD_ELSE_CLAUSE_ID)
1446 AddNestedElseClause();
1447
1448 // Check for adding of a nested IF-THEN-ELSE clause
1449 if (nID == ADD_IF_THEN_ELSE_CLAUSE_ID)
1450 AddNestedIfThenElseClause();
1451
1452 // Check for the adding of a DO_NOTHING Action
1453 if (nID == ADD_DO_NOTHING_ACTION_ID)
1454 AddActionStatementNode(DO_NOTHING_ID);
1455
1456 // Check for the adding of a specific Action
1457 if (nID >= ADD_ACTION_ID_RANGE_START && nID < ADD_ACTION_ID_RANGE_END)
1458 AddActionStatementNode(nID - ADD_ACTION_ID_RANGE_START);
1459
1460 // Check for the adding of a logical operator
1461 if (nID >= ADD_LOGOP_ID_RANGE_START && nID < ADD_LOGOP_ID_RANGE_END)
1462 AddLogicalOperatorNode(nID - ADD_LOGOP_ID_RANGE_START);
1463
1464 // Check for the adding of a logical operator
1465 if (nID >= INSERT_LOGOP_ID_RANGE_START && nID < INSERT_LOGOP_ID_RANGE_END)
1466 InsertLogicalOperatorNode(nID - INSERT_LOGOP_ID_RANGE_START);
1467
1468 // Check for the adding of a condition
1469 if (nID >= ADD_CONDITION_ID_RANGE_START && nID < ADD_CONDITION_ID_RANGE_END)
1470 AddConditionalStatementNode(nID - ADD_CONDITION_ID_RANGE_START);
1471
1472 // Check for the adding of a binary condition (query)
1473 if (nID >= ADD_COND_QBIN_ID_RANGE_START && nID < ADD_COND_QBIN_ID_RANGE_END)
1474 AddConditionalStatementNode(BINARY_STATEMENT, nID - ADD_COND_QBIN_ID_RANGE_START);
1475
1476 // Check for the adding of a comparison condition (query)
1477 if (nID >= ADD_COND_QCOMP_ID_RANGE_START && nID < ADD_COND_QCOMP_ID_RANGE_END)
1478 AddConditionalStatementNode(COMPARISON_STATEMENT, nID - ADD_COND_QCOMP_ID_RANGE_START);
1479 }
1480
1481 // Handle replace commands
1482 void CDallasMainDlg::OnMenuSelectionOfTypeReplace(UINT nID) {
1483 // Check for the replacement of a node with a specific Query
1484 if (nID >= REPLACE_QUERY_ID_RANGE_START && nID < REPLACE_QUERY_ID_RANGE_END)
1485 ReplaceWithQueryNode(nID - REPLACE_QUERY_ID_RANGE_START);
1486
1487 // Check for the replacement of a node with a Literal
1488 if (nID >= REPLACE_LITERAL_ID_RANGE_START && nID < REPLACE_LITERAL_ID_RANGE_END)
1489 ReplaceWithLiteralNode(nID - REPLACE_LITERAL_ID_RANGE_START, 0);
1490
1491 // Check for the replacement of a node with a Literal enumeration
1492 if (nID >= REPLACE_LIT_ENUM_ID_RANGE_START && nID < REPLACE_LIT_ENUM_ID_RANGE_END)
1493 ReplaceWithLiteralNode(ENUM_PARAMETER_TYPE, nID - REPLACE_LIT_ENUM_ID_RANGE_START);
1494
1495 // Check for the replacement of a node with a Literal flag
1496 if (nID >= REPLACE_LIT_FLAG_ID_RANGE_START && nID < REPLACE_LIT_FLAG_ID_RANGE_END)
1497 ReplaceWithLiteralNode(FLAG_PARAMETER_TYPE, nID - REPLACE_LIT_FLAG_ID_RANGE_START);
1498
1499 // Check for the replacement of a node with a DO_NOTHING Action
1500 if (nID == REPLACE_DO_NOTHING_ACTION_ID)
1501 ReplaceWithActionNode(DO_NOTHING_ID);
1502
1503 // Check for the replacement of a node with an action
1504 if (nID >= REPLACE_ACTION_ID_RANGE_START && nID < REPLACE_ACTION_ID_RANGE_END)
1505 ReplaceWithActionNode(nID - REPLACE_ACTION_ID_RANGE_START);
1506
1507 // Check for the replacement of a node with a logical operator
1508 if (nID >= REPLACE_LOGOP_ID_RANGE_START && nID < REPLACE_LOGOP_ID_RANGE_END)
1509 ReplaceWithLogOpNode(nID - REPLACE_LOGOP_ID_RANGE_START);
1510
1511 // Check for the replacement of a node with a condition
1512 if (nID >= REPLACE_CONDITION_ID_RANGE_START && nID < REPLACE_CONDITION_ID_RANGE_END)
1513 ReplaceWithConditionNode(nID - REPLACE_CONDITION_ID_RANGE_START);
1514
1515 // Check for the replacement of a node with a binary condition (query)
1516 if (nID >= REPLACE_COND_QBIN_ID_RANGE_START && nID < REPLACE_COND_QBIN_ID_RANGE_END)
1517 ReplaceWithConditionNode(BINARY_STATEMENT, nID - REPLACE_COND_QBIN_ID_RANGE_START);
1518
1519 // Check for the replacement of a node with a comparison condition (query)
1520 if (nID >= REPLACE_COND_QCOMP_ID_RANGE_START && nID < REPLACE_COND_QCOMP_ID_RANGE_END)
1521 ReplaceWithConditionNode(COMPARISON_STATEMENT, nID - REPLACE_COND_QCOMP_ID_RANGE_START);
1522 }
1523
1524 // Handle delete commands
1525 void CDallasMainDlg::OnMenuSelectionOfTypeDelete(UINT nID) {
1526 HTREEITEM selected_node, parent_node;
1527 tTreeNodeData *data;
1528
1529 // Obtain the currently selected node
1530 selected_node = m_ScriptTree.GetSelectedItem();
1531 if (selected_node == NULL)
1532 return;
1533
1534 // Save the parent of this node
1535 parent_node = m_ScriptTree.GetParentItem(selected_node);
1536
1537 // Get the node's data
1538 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
1539 if (data == NULL)
1540 return;
1541
1542 // Handle Delete all's
1543 if (nID == DELETE_ALL_ID) {
1544 switch (data->type) {
1545 case ACTION_STATEMENT_NODE:
1546 FreeTreeItem(selected_node);
1547 ConfirmAfterDelete(parent_node);
1548 SetModified(TRUE);
1549 break;
1550 case CONDITIONAL_STATEMENT_NODE:
1551 FreeTreeItem(selected_node);
1552 ConfirmAfterDelete(parent_node);
1553 SetModified(TRUE);
1554 break;
1555 case LOGICAL_OPERATOR_NODE:
1556 FreeTreeItem(selected_node);
1557 ConfirmAfterDelete(parent_node);
1558 SetModified(TRUE);
1559 break;
1560 case ACTIONS_HEADER_NODE:
1561 if (data->ID == NESTED) {
1562 if (data->subID == THEN_CLAUSE) {
1563 HTREEITEM temp_node;
1564
1565 // Delete the IF clause
1566 temp_node = m_ScriptTree.GetPrevSiblingItem(selected_node);
1567 if (GetNodeType(temp_node) == CONDITIONAL_HEADER_NODE)
1568 FreeTreeItem(temp_node);
1569
1570 // Delete the ELSE clause (if it exists)
1571 temp_node = m_ScriptTree.GetNextSiblingItem(selected_node);
1572 if (GetNodeType(temp_node) == ACTIONS_HEADER_NODE)
1573 FreeTreeItem(temp_node);
1574
1575 // Delete the THEN clause
1576 FreeTreeItem(selected_node);
1577 } else { // Delete just the ELSE clause
1578 FreeTreeItem(selected_node);
1579 }
1580 ConfirmAfterDelete(parent_node);
1581 SetModified(TRUE);
1582 }
1583 break;
1584 }
1585 return;
1586 }
1587
1588 // Handle Delete children only's
1589 if (nID == DELETE_CHILDREN_ONLY_ID) {
1590 switch (data->type) {
1591 case ACTIONS_HEADER_NODE:
1592 if (DeletePrompt("Are you sure you want to delete all children of this Clause?") == IDYES) {
1593 FreeTreeItemChildren(selected_node);
1594 ConfirmAfterDelete(selected_node);
1595 SetModified(TRUE);
1596 }
1597 break;
1598 }
1599 return;
1600 }
1601 }
1602
1603 // Displays a deletion prompt
1604 int CDallasMainDlg::DeletePrompt(char *msg) {
1605 CString title = "Deletion Prompt";
1606 return (MessageBox(msg, title.GetBuffer(0), MB_YESNO | MB_ICONQUESTION));
1607 }
1608
1609 // Makes sure everything is as it should be after a delete
1610 void CDallasMainDlg::ConfirmAfterDelete(HTREEITEM parent) {
1611 tTreeNodeData *data;
1612 HTREEITEM new_node;
1613
1614 if (parent == NULL)
1615 return;
1616
1617 // Get the node's data
1618 data = (tTreeNodeData *)m_ScriptTree.GetItemData(parent);
1619 if (data == NULL)
1620 return;
1621
1622 // Make sure IF statement has one child!
1623 if (data->type == CONDITIONAL_HEADER_NODE) {
1624 if (GetChildCount(parent) != 1) {
1625 FreeTreeItemChildren(parent);
1626 new_node = CreateDefaultConditionalStatementNode(parent);
1627 if (new_node != NULL)
1628 m_ScriptTree.SelectItem(new_node);
1629 }
1630 return;
1631 }
1632
1633 // Make sure THEN statement has at least one child
1634 if (data->type == ACTIONS_HEADER_NODE) {
1635 if (GetChildCount(parent) == 0) {
1636 new_node = CreateDefaultActionStatementNode(parent);
1637 if (new_node != NULL)
1638 m_ScriptTree.SelectItem(new_node);
1639 }
1640 return;
1641 }
1642
1643 // Make sure Logical operators have right number of children
1644 if (data->type == LOGICAL_OPERATOR_NODE) {
1645 if (data->ID == AND_TYPE || data->ID == OR_TYPE) {
1646 if (GetChildCount(parent) < 2) {
1647 new_node = CreateDefaultConditionalStatementNode(parent);
1648 if (new_node != NULL)
1649 m_ScriptTree.SelectItem(new_node);
1650 }
1651 }
1652 return;
1653 }
1654 }
1655
1656 /////////////////////////////////////////////////////////////////////////////
1657 // General Refresh functions
1658 /////////////////////////////////////////////////////////////////////////////
1659
1660 // Performs all basic initialization tasks
1661 void CDallasMainDlg::InitAll(void) {
1662 m_Modified = FALSE;
1663
1664 InitTree();
1665 InitMessageList();
1666 InitEnumDatabase();
1667 InitFlagDatabase();
1668 InitFunctionDatabases();
1669 InitScriptGroupingList();
1670 InitObjectHandleList();
1671 InitCustomScriptStorage();
1672 InitNameLists();
1673
1674 CurrentOutputFile = NULL;
1675 CurrentTabLevel = 0;
1676
1677 m_ScriptOwnerType = NONE_TYPE;
1678 m_ScriptOwnerHandle = 0;
1679 }
1680
1681 // Frees up all DALLAS memory
1682 void CDallasMainDlg::ClearAll(void) {
1683 ClearMessageList();
1684 ClearEnumDatabase();
1685 ClearFlagDatabase();
1686 ClearFunctionDatabases();
1687 ClearTree();
1688 ClearScriptGroupingList();
1689 ClearObjectHandleList();
1690 ClearCustomScriptStorage();
1691 ClearNameLists();
1692 }
1693
1694 // Loads in everything
1695 void CDallasMainDlg::LoadAll(void) {
1696 // Parse the message file (string table) for this level
1697 ParseMsgTableFile(m_ScriptMessagesFilename.GetBuffer(0));
1698
1699 // Parse actions into the Action Database
1700 ParseFunctionFile(m_DallasFunctionsFilename.GetBuffer(0));
1701 ParseFunctionFile(m_ScriptFilename.GetBuffer(0), FALSE);
1702
1703 // Read in the saved script tree
1704 ParseSourceScript(m_ScriptFilename.GetBuffer(0));
1705
1706 // Read in the custom script text
1707 ParseCustomScriptFile(m_ScriptFilename.GetBuffer(0), FALSE);
1708 }
1709
1710 // Sets all the filenames to match the currently loaded level
1711 void CDallasMainDlg::SetAllFilenames(void) {
1712 // Set the Dallas Functions Filename
1713 m_DallasFunctionsFilename = DALLASFUNCS_FILENAME;
1714
1715 // Get the current level name
1716 char filename[_MAX_PATH + 1];
1717
1718 CString level_fname;
1719 #ifdef NEWEDITOR
1720 level_fname = Level_name;
1721 #else
1722 level_fname = theApp.main_doc->GetPathName();
1723 #endif
1724
1725 if (level_fname.IsEmpty())
1726 strcpy(filename, "Untitled");
1727 else
1728 ddio_SplitPath(level_fname.GetBuffer(0), NULL, filename, NULL);
1729
1730 // Create the script source filename
1731 m_ScriptFilename.Format("%s.cpp", filename);
1732
1733 // Create the script DLL filename
1734 m_ScriptDLLFilename.Format("%s.dll", filename);
1735
1736 // Create the message table filename
1737 m_ScriptMessagesFilename.Format("%s.msg", filename);
1738 }
1739
1740 // Sets all the filenames to match the given level name
1741 void CDallasMainDlg::SetAllFilenamesToThis(char *level_path) {
1742 if (level_path == NULL)
1743 return;
1744
1745 // Set the Dallas Functions Filename
1746 m_DallasFunctionsFilename = DALLASFUNCS_FILENAME;
1747
1748 // Get the current level name
1749 char filename[_MAX_PATH + 1];
1750
1751 CString level_fname;
1752 level_fname = level_path;
1753
1754 if (level_fname.IsEmpty())
1755 strcpy(filename, "Untitled");
1756 else
1757 ddio_SplitPath(level_fname.GetBuffer(0), NULL, filename, NULL);
1758
1759 // Create the script source filename
1760 m_ScriptFilename.Format("%s.cpp", filename);
1761
1762 // Create the script DLL filename
1763 m_ScriptDLLFilename.Format("%s.dll", filename);
1764
1765 // Create the message table filename
1766 m_ScriptMessagesFilename.Format("%s.msg", filename);
1767
1768 // Reflect changes in the title bar
1769 SetTitleBar();
1770 }
1771
1772 // Does a complete refresh of DALLAS
1773 void CDallasMainDlg::Refresh(void) {
1774 // Make sure everything is cleared out
1775 ClearAll();
1776
1777 // Set all the filenames to match the currently loaded level
1778 SetAllFilenames();
1779
1780 // Load in everything
1781 LoadAll();
1782
1783 // Highlight the appropriate scripts
1784 HighlightAllScripts();
1785
1786 SetModified(FALSE);
1787 }
1788
1789 /////////////////////////////////////////////////////////////////////////////
1790 // Manage System functions
1791 /////////////////////////////////////////////////////////////////////////////
1792
1793 void CDallasMainDlg::CheckinScriptFiles(void) {}
1794
1795 void CDallasMainDlg::CheckoutScriptFiles(void) {}
1796
1797 void CDallasMainDlg::DeleteScriptFiles(void) {}
1798
1799 /////////////////////////////////////////////////////////////////////////////
1800 // Tree Control Functions
1801 /////////////////////////////////////////////////////////////////////////////
1802
1803 // Performs any necessary initialization of the tree control (and node data)
1804 void CDallasMainDlg::InitTree(void) {
1805 m_NextScriptID = 0;
1806 m_ClipboardNode = NULL;
1807 }
1808
1809 // Performs any necessary de-initialization of the tree control (and node data)
1810 void CDallasMainDlg::ClearTree(void) {
1811 FreeTreeItemChildren(TVI_ROOT);
1812 m_NextScriptID = 0;
1813 m_ClipboardNode = NULL;
1814 }
1815
1816 // Obtains the string name for an event type
1817 char *CDallasMainDlg::GetEventTypeString(int type) {
1818 for (int j = 0; event_info[j].type >= 0; j++)
1819 if (event_info[j].type == type)
1820 return (event_info[j].name);
1821
1822 return (UNKNOWN_EVENT_STRING);
1823 }
1824
1825 // Updates the text for every node in the tree
1826 void CDallasMainDlg::UpdateTreeText(HTREEITEM parent) {
1827 HTREEITEM child;
1828
1829 if (parent == NULL)
1830 return;
1831
1832 // Process the children
1833 child = m_ScriptTree.GetChildItem(parent);
1834 while (child != NULL) {
1835 UpdateTreeText(child);
1836 UpdateNodeText(child);
1837
1838 // Get the next child
1839 child = m_ScriptTree.GetNextSiblingItem(child);
1840 }
1841 }
1842
1843 // Obtains the in-code DEFINE name for an event type
1844 char *CDallasMainDlg::GetEventCodeName(int type) {
1845 for (int j = 0; event_info[j].type >= 0; j++)
1846 if (event_info[j].type == type)
1847 return (event_info[j].code_name);
1848
1849 return (UNKNOWN_EVENT_CODE_NAME);
1850 }
1851
1852 // Obtains the data line for an event type
1853 char *CDallasMainDlg::GetEventDataLine(int type) {
1854 for (int j = 0; event_info[j].type >= 0; j++)
1855 if (event_info[j].type == type)
1856 return (event_info[j].data_line);
1857
1858 return (UNKNOWN_EVENT_DATA_LINE);
1859 }
1860
1861 // Obtains the string name for a logical operator type
1862 void CDallasMainDlg::GetLogicalOperatorTypeString(int type, CString &string) {
1863 switch (type) {
1864 case AND_TYPE:
1865 string = "AND";
1866 break;
1867 case OR_TYPE:
1868 string = "OR";
1869 break;
1870 default:
1871 string = "Unknown";
1872 break;
1873 }
1874 }
1875
1876 // Checks to see if the given script has an IT (based upon the event type)
1877 bool CDallasMainDlg::ScriptHasAnIt(HTREEITEM script_node) {
1878 // Check the owner type (only triggers and objects can have an it)
1879 // int owner_type=GetScriptOwnerType(script_node);
1880 // if(owner_type!=OBJECT_TYPE && owner_type!=TRIGGER_TYPE)
1881 // return FALSE;
1882
1883 // Check the script's event type
1884 int event_type = GetScriptEventType(script_node);
1885
1886 for (int j = 0; event_info[j].type >= 0; j++)
1887 if (event_info[j].type == event_type) {
1888 if (event_info[j].flags & HAS_IT_MASK)
1889 return TRUE;
1890 else
1891 return FALSE;
1892 }
1893
1894 return FALSE;
1895 }
1896
1897 // Checks to see if the given script has an ME (based upon the event type)
1898 bool CDallasMainDlg::ScriptHasAMe(HTREEITEM script_node) {
1899 // Check the owner type (only an object owner can have a me)
1900 int owner_type = GetScriptOwnerType(script_node);
1901 if (owner_type != OBJECT_TYPE)
1902 return FALSE;
1903
1904 return TRUE;
1905 }
1906
1907 // Checks to see if the given script has a ME of type DOOR (based upon the event type)
1908 bool CDallasMainDlg::ScriptHasADoorMe(HTREEITEM script_node) {
1909 HTREEITEM owner_node;
1910 tTreeNodeData *data;
1911
1912 owner_node = GetScriptOwnerNode(script_node);
1913 if (owner_node == NULL)
1914 return (FALSE);
1915
1916 data = (tTreeNodeData *)m_ScriptTree.GetItemData(owner_node);
1917 if (data == NULL)
1918 return (FALSE);
1919
1920 // Check the owner type (only an object owner can have a me)
1921 if (data->ID != OBJECT_TYPE)
1922 return FALSE;
1923
1924 // Make sure it's a Door object
1925 object *objp = ObjGet(data->int_val);
1926 if (objp == NULL || objp->type != OBJ_DOOR || objp->name == NULL)
1927 return FALSE;
1928
1929 return TRUE;
1930 }
1931
1932 // Checks to see if the given script has an GoalID (based upon the event type)
1933 bool CDallasMainDlg::ScriptHasAGoalID(HTREEITEM script_node) {
1934 // Check the owner type (only levels and objects can have a GoalID)
1935 int owner_type = GetScriptOwnerType(script_node);
1936 if (owner_type != OBJECT_TYPE && owner_type != LEVEL_TYPE)
1937 return FALSE;
1938
1939 // Check the script's event type
1940 int event_type = GetScriptEventType(script_node);
1941
1942 for (int j = 0; event_info[j].type >= 0; j++)
1943 if (event_info[j].type == event_type) {
1944 if (event_info[j].flags & HAS_GOALID_MASK)
1945 return TRUE;
1946 else
1947 return FALSE;
1948 }
1949
1950 return FALSE;
1951 }
1952
1953 // Checks to see if the given script has a Timer ID (based upon the event type)
1954 bool CDallasMainDlg::ScriptHasATimerID(HTREEITEM script_node) {
1955 // Check the owner type (only levels and objects can have a MatcenID)
1956 int owner_type = GetScriptOwnerType(script_node);
1957 if (owner_type != OBJECT_TYPE && owner_type != LEVEL_TYPE)
1958 return FALSE;
1959
1960 // Check the script's event type
1961 int event_type = GetScriptEventType(script_node);
1962
1963 for (int j = 0; event_info[j].type >= 0; j++)
1964 if (event_info[j].type == event_type) {
1965 if (event_info[j].flags & HAS_TIMERID_MASK)
1966 return TRUE;
1967 else
1968 return FALSE;
1969 }
1970
1971 return FALSE;
1972 }
1973
1974 // Checks to see if the given script has a Matcen ID (based upon the event type)
1975 bool CDallasMainDlg::ScriptHasAMatcenID(HTREEITEM script_node) {
1976 // Check the owner type (only levels and objects can have a MatcenID)
1977 int owner_type = GetScriptOwnerType(script_node);
1978 if (owner_type != OBJECT_TYPE && owner_type != LEVEL_TYPE)
1979 return FALSE;
1980
1981 // Check the script's event type
1982 int event_type = GetScriptEventType(script_node);
1983
1984 for (int j = 0; event_info[j].type >= 0; j++)
1985 if (event_info[j].type == event_type) {
1986 if (event_info[j].flags & HAS_MATCENID_MASK)
1987 return TRUE;
1988 else
1989 return FALSE;
1990 }
1991
1992 return FALSE;
1993 }
1994
1995 // Checks to see if the given script has a Level Goal ID (based upon the event type)
1996 bool CDallasMainDlg::ScriptHasALevelGoalID(HTREEITEM script_node) {
1997 // Check the owner type (only levels and objects can have a MatcenID)
1998 int owner_type = GetScriptOwnerType(script_node);
1999 if (owner_type != LEVEL_TYPE)
2000 return FALSE;
2001
2002 // Check the script's event type
2003 int event_type = GetScriptEventType(script_node);
2004
2005 for (int j = 0; event_info[j].type >= 0; j++)
2006 if (event_info[j].type == event_type) {
2007 if (event_info[j].flags & HAS_LEVGOALID_MASK)
2008 return TRUE;
2009 else
2010 return FALSE;
2011 }
2012
2013 return FALSE;
2014 }
2015
2016 // Checks to see if a given node is a clause of the given type
2017 bool CDallasMainDlg::NodeIsIfClause(HTREEITEM node) {
2018 tTreeNodeData *data;
2019
2020 if (node == NULL)
2021 return (FALSE);
2022
2023 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
2024 if (data == NULL || data->type != CONDITIONAL_HEADER_NODE)
2025 return (FALSE);
2026
2027 if (data->ID != NESTED)
2028 return (FALSE);
2029
2030 return (TRUE);
2031 }
2032
2033 // Checks to see if a given node is a clause of the given type
2034 bool CDallasMainDlg::NodeIsClauseOfType(HTREEITEM node, int type) {
2035 tTreeNodeData *data;
2036
2037 if (node == NULL)
2038 return (FALSE);
2039
2040 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
2041 if (data == NULL || data->type != ACTIONS_HEADER_NODE)
2042 return (FALSE);
2043
2044 if (data->ID != NESTED)
2045 return (FALSE);
2046 if (data->subID != type)
2047 return (FALSE);
2048
2049 return (TRUE);
2050 }
2051
2052 // Checks to see if it's ok to add an else clause to the given node
2053 bool CDallasMainDlg::CanAppendElseToNode(HTREEITEM node) {
2054 HTREEITEM next_node;
2055
2056 // Make sure given node is a nested THEN
2057 if (!NodeIsClauseOfType(node, THEN_CLAUSE))
2058 return (FALSE);
2059
2060 // Make sure this node doesn't already have an else
2061 next_node = m_ScriptTree.GetNextSiblingItem(node);
2062 if (NodeIsClauseOfType(next_node, ELSE_CLAUSE))
2063 return (FALSE);
2064
2065 return (TRUE);
2066 }
2067
2068 // Obtains the string name for an expression operator type
2069 char *CDallasMainDlg::GetExpressionOperatorTypeString(int type) {
2070 for (int j = 0; expop_info[j].type >= 0; j++)
2071 if (expop_info[j].type == type)
2072 return (expop_info[j].name);
2073
2074 return (UNKNOWN_EXPOP_STRING);
2075 }
2076
2077 // Obtains the string name for an expression operator type
2078 char *CDallasMainDlg::GetExpressionOperatorCodeName(int type) {
2079 for (int j = 0; expop_info[j].type >= 0; j++)
2080 if (expop_info[j].type == type)
2081 return (expop_info[j].code_name);
2082
2083 return (UNKNOWN_EXPOP_STRING);
2084 }
2085
2086 // Obtains the string name for a literal
2087 char *CDallasMainDlg::GetLiteralName(int type) {
2088 for (int j = 0; param_menu_item[j].type >= 0; j++)
2089 if (param_menu_item[j].type == type)
2090 return (param_menu_item[j].name);
2091
2092 return (UNKNOWN_LITERAL_STRING);
2093 }
2094
2095 // Updates the text display of the given node
2096 void CDallasMainDlg::UpdateNodeText(HTREEITEM node) {
2097 CString new_text;
2098 tTreeNodeData *data;
2099
2100 if (node == NULL)
2101 return;
2102
2103 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
2104 if (data == NULL)
2105 return;
2106
2107 // Format and set the new text
2108 FormatTreeText(new_text, data, node);
2109 m_ScriptTree.SetItemText(node, new_text.GetBuffer(0));
2110 }
2111
2112 // Updates the text of given node and all parent nodes above the given node
2113 void CDallasMainDlg::UpdateAllParentNodesText(HTREEITEM node) {
2114 HTREEITEM parent;
2115
2116 if (node == NULL)
2117 return;
2118
2119 UpdateNodeText(node);
2120
2121 parent = m_ScriptTree.GetParentItem(node);
2122 while (parent != NULL) {
2123 UpdateNodeText(parent);
2124 parent = m_ScriptTree.GetParentItem(parent);
2125 }
2126 }
2127
2128 // Formats the given string according to the given node data
2129 void CDallasMainDlg::FormatTreeText(CString &text, tTreeNodeData *data, HTREEITEM node /*=NULL*/) {
2130 CString tmp_str1, tmp_str2;
2131 object *objp;
2132
2133 // Make sure given data is valid
2134 if (data == NULL)
2135 return;
2136
2137 // Format the text according to the tree node type
2138 switch (data->type) {
2139 case SCRIPT_HEADER_NODE:
2140 text.Format("Script %.03d: %s", data->ID, data->name);
2141 break;
2142 case SCRIPT_OWNER_NODE:
2143 switch (data->ID) {
2144 case OBJECT_TYPE:
2145 if (data->int_val == OBJECT_HANDLE_NONE) {
2146 text.Format("Owner: %s (Object)", NONE_STRING);
2147 break;
2148 }
2149 objp = ObjGet(data->int_val);
2150 if (objp == NULL || objp->type == OBJ_NONE || objp->name == NULL)
2151 text.Format("Owner: *OBJECT_ERROR*");
2152 else
2153 text.Format("Owner: %s (Object)", objp->name);
2154 break;
2155 case TRIGGER_TYPE:
2156 if (data->int_val == NOT_SPECIFIED_TYPE) {
2157 text.Format("Owner: %s (Trigger)", NOT_SPECIFIED_STRING);
2158 break;
2159 }
2160 if (data->int_val < 0 || data->int_val >= Num_triggers)
2161 text.Format("Owner: *INVALID_TRIGGER*");
2162 else
2163 text.Format("Owner: %s (Trigger)", Triggers[data->int_val].name);
2164 break;
2165 case LEVEL_TYPE:
2166 text.Format("Owner: Level");
2167 break;
2168 default:
2169 text.Format("Owner: %s", NOT_SPECIFIED_STRING);
2170 break;
2171 }
2172 break;
2173 case SCRIPT_EVENT_NODE:
2174 text.Format("Event: %s", GetEventTypeString(data->ID));
2175 break;
2176 case CONDITIONAL_HEADER_NODE:
2177 text.Format("If the following condition is met:");
2178 break;
2179 case ACTIONS_HEADER_NODE:
2180 if (data->ID == TOP_LEVEL && data->int_val == BREAK_SCRIPT_CHAIN)
2181 tmp_str2 = " and BREAK script chain";
2182 else
2183 tmp_str2 = "";
2184 if (data->ID == TOP_LEVEL && data->subID == 1)
2185 tmp_str1.Format(" (only do once%s)", tmp_str2);
2186 else if (data->ID == TOP_LEVEL && data->subID == 2)
2187 tmp_str1.Format(" (only do twice%s)", tmp_str2);
2188 else if (data->ID == TOP_LEVEL && data->subID >= 3)
2189 tmp_str1.Format(" (only do %d times%s)", data->subID, tmp_str2);
2190 else
2191 tmp_str1.Format("%s", tmp_str2);
2192 if (data->ID == NESTED && data->subID == ELSE_CLAUSE)
2193 text.Format("Else, perform these actions:");
2194 else
2195 text.Format("Then perform the following actions%s:", tmp_str1);
2196 break;
2197 case CONDITIONAL_STATEMENT_NODE:
2198 if (data->ID == ALWAYS_STATEMENT)
2199 text.Format("%s", ALWAYS_STRING);
2200 else
2201 FormatConditionText(text, node);
2202 break;
2203 case EXPRESSION_NODE:
2204 FormatQueryNodeText(tmp_str1, node);
2205 text.Format("%s: %s", data->name, tmp_str1);
2206 break;
2207 case EXPRESSION_OPERATOR_NODE:
2208 text.Format("Operation: %s", GetExpressionOperatorTypeString(data->subID));
2209 break;
2210 case ACTION_STATEMENT_NODE:
2211 if (data->ID == DO_NOTHING_ID)
2212 text.Format("%s", DO_NOTHING_STRING);
2213 else
2214 FormatActionNodeText(text, node);
2215 break;
2216 case LOGICAL_OPERATOR_NODE:
2217 GetLogicalOperatorTypeString(data->ID, tmp_str1);
2218 text.Format("%s", tmp_str1);
2219 break;
2220 case PARAMETER_NODE:
2221 FormatParameterValueText(tmp_str1, data);
2222 text.Format("%s: %s", data->name, tmp_str1.GetBuffer(0));
2223 break;
2224 case PARAMETER_OPERATOR_NODE:
2225 text.Format("this is a parameter operator");
2226 break;
2227 case CLIPBOARD_HEADER_NODE:
2228 text.Format("Clipboard");
2229 break;
2230 case UNKNOWN_NODE:
2231 text.Format("Unknown Type");
2232 break;
2233 default:
2234 text.Format("REALLY Unknown Type");
2235 break;
2236 }
2237 }
2238
2239 // Formats the text for a Conditional Statement according to it and its children
2240 void CDallasMainDlg::FormatConditionText(CString &text, HTREEITEM condition_node) {
2241 tTreeNodeData *data;
2242 HTREEITEM child_node;
2243
2244 // Make sure given node is valid
2245 if (condition_node == NULL) {
2246 text = "*ERROR*";
2247 return;
2248 }
2249
2250 // Get node's data
2251 data = (tTreeNodeData *)m_ScriptTree.GetItemData(condition_node);
2252 if (data == NULL) {
2253 text = "*ERROR*";
2254 return;
2255 }
2256
2257 // Make sure given data node is a conditional statement node
2258 if (data->type != CONDITIONAL_STATEMENT_NODE) {
2259 text = "<Not a Conditional Statement>";
2260 return;
2261 }
2262
2263 text = "(";
2264
2265 // Get the first child (literal or query)
2266 child_node = m_ScriptTree.GetChildItem(condition_node);
2267 if (child_node != NULL) {
2268 CString temp_str;
2269 FormatGenericExpressionText(temp_str, child_node);
2270 text += temp_str;
2271 } else {
2272 text += "???";
2273 }
2274
2275 text += ") ";
2276
2277 // Get the second child (expression operator)
2278 if (child_node != NULL) {
2279 child_node = m_ScriptTree.GetNextSiblingItem(child_node);
2280 if (child_node != NULL) {
2281 CString temp_str;
2282 FormatGenericExpressionText(temp_str, child_node);
2283 text += temp_str;
2284 } else {
2285 text += "???";
2286 }
2287 }
2288
2289 // If it's a comparison, get the third child (literal or query)
2290 if (child_node != NULL && data->ID == COMPARISON_STATEMENT) {
2291 child_node = m_ScriptTree.GetNextSiblingItem(child_node);
2292 if (child_node != NULL) {
2293 CString temp_str;
2294 FormatGenericExpressionText(temp_str, child_node);
2295 text += " (";
2296 text += temp_str;
2297 text += ")";
2298 } else {
2299 text += " (???)";
2300 }
2301 }
2302 }
2303
2304 // Formats a child node of a conditional statement node
2305 void CDallasMainDlg::FormatGenericExpressionText(CString &text, HTREEITEM gen_exp_node) {
2306 tTreeNodeData *data;
2307
2308 // Make sure given node is valid
2309 if (gen_exp_node == NULL) {
2310 text = "*ERROR*";
2311 return;
2312 }
2313
2314 // Get node's data
2315 data = (tTreeNodeData *)m_ScriptTree.GetItemData(gen_exp_node);
2316 if (data == NULL) {
2317 text = "*ERROR*";
2318 return;
2319 }
2320
2321 // See if it's a parameter node
2322 if (data->type == PARAMETER_NODE) {
2323 FormatParameterValueText(text, data);
2324 return;
2325 }
2326
2327 // See if it's a query node
2328 if (data->type == EXPRESSION_NODE) {
2329 FormatQueryNodeText(text, gen_exp_node);
2330 return;
2331 }
2332
2333 // See if it's an expression operator node
2334 if (data->type == EXPRESSION_OPERATOR_NODE) {
2335 text.Format("%s", GetExpressionOperatorTypeString(data->subID));
2336 return;
2337 }
2338
2339 text = "<Invalid Expression>";
2340 }
2341
2342 // Formats the text for a Parameter Value according to the given node data
2343 void CDallasMainDlg::FormatParameterValueText(CString &text, tTreeNodeData *data) {
2344 object *objp;
2345 char *temp_str;
2346 char temp_name[_MAX_PATH + 1];
2347
2348 // Make sure given data is valid
2349 if (data == NULL) {
2350 text = "";
2351 return;
2352 }
2353
2354 // Make sure given data node is a parameter node
2355 if (data->type != PARAMETER_NODE) {
2356 text = "<Not a Parameter>";
2357 return;
2358 }
2359
2360 // Format the text according to the parameter type and value data
2361 switch (data->ID) {
2362 case DOOR_PARAMETER_TYPE:
2363 if (data->subID == USE_ME_HANDLE) {
2364 text.Format("OWNER");
2365 break;
2366 }
2367 if (data->int_val == OBJECT_HANDLE_NONE) {
2368 text.Format("%s", NONE_STRING);
2369 break;
2370 }
2371 objp = ObjGet(data->int_val);
2372 if (objp == NULL || objp->type == OBJ_NONE || objp->name == NULL)
2373 text.Format("*DOOR_ERROR*");
2374 else
2375 text.Format("%s", objp->name);
2376 break;
2377 case OBJECT_PARAMETER_TYPE:
2378 if (data->subID == USE_IT_HANDLE) {
2379 text.Format("IT");
2380 break;
2381 }
2382 if (data->subID == USE_ME_HANDLE) {
2383 text.Format("OWNER");
2384 break;
2385 }
2386 if (data->int_val == OBJECT_HANDLE_NONE) {
2387 text.Format("%s", NONE_STRING);
2388 break;
2389 }
2390 objp = ObjGet(data->int_val);
2391 if (objp == NULL || objp->type == OBJ_NONE || objp->name == NULL)
2392 text.Format("*OBJECT_ERROR*");
2393 else
2394 text.Format("%s", objp->name);
2395 break;
2396 case ROOM_PARAMETER_TYPE:
2397 if (data->int_val == NOT_SPECIFIED_TYPE) {
2398 text.Format("%s", NOT_SPECIFIED_STRING);
2399 break;
2400 }
2401 if (data->int_val < 0 || data->int_val > Highest_room_index)
2402 text.Format("*INVALID_ROOM*");
2403 else
2404 text.Format("%s", Rooms[data->int_val].name);
2405 break;
2406 case TRIGGER_PARAMETER_TYPE:
2407 if (data->int_val == NOT_SPECIFIED_TYPE) {
2408 text.Format("%s", NOT_SPECIFIED_STRING);
2409 break;
2410 }
2411 if (data->int_val < 0 || data->int_val >= Num_triggers)
2412 text.Format("*INVALID_TRIGGER*");
2413 else
2414 text.Format("%s", Triggers[data->int_val].name);
2415 break;
2416 case INT_PARAMETER_TYPE:
2417 text.Format("%d", data->int_val);
2418 break;
2419 case BOOL_PARAMETER_TYPE:
2420 if (data->int_val)
2421 text.Format("TRUE");
2422 else
2423 text.Format("FALSE");
2424 break;
2425 case FLOAT_PARAMETER_TYPE:
2426 text.Format("%.2f", data->float_val1);
2427 break;
2428 case VECTOR_PARAMETER_TYPE:
2429 text.Format("<%.2f,%.2f,%.2f>", data->float_val1, data->float_val2, data->float_val3);
2430 break;
2431 case STRING_PARAMETER_TYPE:
2432 if (strlen(data->str_val) == 0)
2433 text.Format("No ID Chosen");
2434 else {
2435 /*
2436 CString msg;
2437 char *full_msg;
2438 char short_msg[MAX_STRING_DISPLAY_LEN+1];
2439
2440 // Display the first X chars in message
2441 full_msg=FindMessageInList(data->str_val);
2442 if(full_msg!=NULL) {
2443 if(strlen(full_msg) > MAX_STRING_DISPLAY_LEN) {
2444 strncpy(short_msg,full_msg,MAX_STRING_DISPLAY_LEN);
2445 short_msg[MAX_STRING_DISPLAY_LEN]='\0';
2446 msg=short_msg;
2447 msg+="...";
2448 }
2449 else
2450 msg=full_msg;
2451 }
2452 else
2453 msg="<Message Not Found>";
2454
2455 text.Format("%s=\"%s\"",data->str_val,msg);
2456 */
2457 text.Format("%s", data->str_val);
2458 }
2459 break;
2460 case PERCENTAGE_PARAMETER_TYPE:
2461 text.Format("%.1f%%", data->float_val1 * 100.0);
2462 break;
2463 case ENUM_PARAMETER_TYPE:
2464 if (data->subID == USE_GOALID_VALUE) {
2465 text.Format("GOAL ID");
2466 } else if (data->subID == USE_TIMERID_VALUE) {
2467 text.Format("TIMER ID");
2468 } else if (data->subID == USE_MATCENID_VALUE) {
2469 text.Format("MATCEN ID");
2470 } else {
2471 temp_str = GetEnumValueName(data->name, data->int_val);
2472 if (temp_str == NULL)
2473 text.Format("*UNKNOWN_ENUM*");
2474 else
2475 text.Format("%s", temp_str);
2476 }
2477 break;
2478 case SCRIPT_PARAMETER_TYPE:
2479 if (data->int_val == NOT_SPECIFIED_TYPE) {
2480 text.Format("%s", NOT_SPECIFIED_STRING);
2481 break;
2482 }
2483 text.Format("%d", data->int_val);
2484 break;
2485 case SOUND_PARAMETER_TYPE:
2486 if (data->int_val == NOT_SPECIFIED_TYPE) {
2487 text.Format("%s", NOT_SPECIFIED_STRING);
2488 break;
2489 }
2490 if (data->int_val < 0 || data->int_val >= MAX_SOUNDS || !Sounds[data->int_val].used)
2491 text.Format("*INVALID_SOUND*");
2492 else
2493 text.Format("%s", Sounds[data->int_val].name);
2494 break;
2495 case SPECNAME_PARAMETER_TYPE:
2496 if (strlen(data->str_val) == 0)
2497 text.Format("%s", NOT_SPECIFIED_STRING);
2498 else
2499 text.Format("\"%s\"", data->str_val);
2500 break;
2501 case TEXTURE_PARAMETER_TYPE:
2502 if (data->int_val == NOT_SPECIFIED_TYPE) {
2503 text.Format("%s", NOT_SPECIFIED_STRING);
2504 break;
2505 }
2506 if (data->int_val < 0 || data->int_val >= MAX_TEXTURES || !GameTextures[data->int_val].used)
2507 text.Format("*INVALID_TEXTURE*");
2508 else
2509 text.Format("%s", GameTextures[data->int_val].name);
2510 break;
2511 case FLAG_PARAMETER_TYPE:
2512 if (!FormatFlagValueNames(data->name, data->int_val, text))
2513 text.Format("*UNKNOWN_FLAG*");
2514 break;
2515 case PATH_PARAMETER_TYPE:
2516 if (data->int_val == NOT_SPECIFIED_TYPE) {
2517 text.Format("%s", NOT_SPECIFIED_STRING);
2518 break;
2519 }
2520 if (data->int_val < 0 || data->int_val >= MAX_GAME_PATHS || !GamePaths[data->int_val].used)
2521 text.Format("*INVALID_PATH*");
2522 else
2523 text.Format("%s", GamePaths[data->int_val].name);
2524 break;
2525 case MATCEN_PARAMETER_TYPE:
2526 if (data->subID == USE_MATCEN_EVENT_ID) {
2527 text.Format("MATCEN ID");
2528 break;
2529 }
2530 if (data->int_val == NOT_SPECIFIED_TYPE) {
2531 text.Format("%s", NOT_SPECIFIED_STRING);
2532 break;
2533 }
2534 if (!MatcenValid(data->int_val))
2535 text.Format("*INVALID_MATCEN*");
2536 else {
2537 char name[MAX_MATCEN_NAME_LEN + 1];
2538 Matcen[data->int_val]->GetName(name);
2539 text.Format("%s", name);
2540 }
2541 break;
2542 case LEVEL_GOAL_PARAMETER_TYPE:
2543 if (data->subID == USE_LEVEL_GOAL_ID) {
2544 text.Format("LEVEL GOAL ID");
2545 break;
2546 }
2547 if (data->int_val == NOT_SPECIFIED_TYPE) {
2548 text.Format("%s", NOT_SPECIFIED_STRING);
2549 break;
2550 }
2551 if (Level_goals.GoalGetName(data->int_val, temp_name, _MAX_PATH) < 0)
2552 text.Format("*INVALID_LEVEL_GOAL*");
2553 else {
2554 text.Format("%s", temp_name);
2555 }
2556 break;
2557 case STRM_AUDIO_PARAMETER_TYPE:
2558 if (strlen(data->str_val) == 0)
2559 text.Format("%s", NOT_SPECIFIED_STRING);
2560 else
2561 text.Format("\"%s\"", data->str_val);
2562 break;
2563 default:
2564 text.Format("Unknown Value Type");
2565 break;
2566 }
2567 }
2568
2569 // Parses an action desc, replacing arg blocks with value strings taken from
2570 // its child parameter nodes
2571 void CDallasMainDlg::FormatActionNodeText(CString &text, HTREEITEM action_node) {
2572 CString name_text, default_text, range_text;
2573 char *desc;
2574 tTreeNodeData *data;
2575 HTREEITEM child;
2576
2577 if (action_node == NULL) {
2578 text = "*ERROR*";
2579 return;
2580 }
2581
2582 data = (tTreeNodeData *)m_ScriptTree.GetItemData(action_node);
2583 if (data == NULL) {
2584 text = "*ERROR*";
2585 return;
2586 }
2587
2588 if (data->ID == INVALID_FUNCTION_ID) {
2589 text = INVALID_FUNCTION_NAME;
2590 return;
2591 }
2592
2593 desc = GetActionDesc(data->ID);
2594 if (desc == NULL) {
2595 text = "*ERROR*";
2596 return;
2597 }
2598
2599 // obtain the first child
2600 child = m_ScriptTree.GetChildItem(action_node);
2601
2602 text = "";
2603 while ((*desc) != '\0') {
2604 if ((*desc) == '[') {
2605 ParseParamBlock(desc, name_text, default_text, range_text);
2606
2607 if (child == NULL)
2608 text += "???";
2609 else {
2610 CString tmp_str;
2611 tTreeNodeData *data;
2612
2613 // Get node's data
2614 data = (tTreeNodeData *)m_ScriptTree.GetItemData(child);
2615
2616 if (data->type == PARAMETER_NODE) {
2617 FormatParameterValueText(tmp_str, data);
2618 text += tmp_str;
2619 } else if (data->type == EXPRESSION_NODE) {
2620 FormatQueryNodeText(tmp_str, child);
2621 text += "(";
2622 text += tmp_str;
2623 text += ")";
2624 } else
2625 text += "<Invalid Node>";
2626
2627 // Get next child
2628 child = m_ScriptTree.GetNextSiblingItem(child);
2629 }
2630 } else {
2631 text += (*desc);
2632 desc++;
2633 }
2634 }
2635 }
2636
2637 /* OLD VERSION
2638 // Parses an action desc, replacing arg blocks with value strings taken from
2639 // its child parameter nodes
2640 void CDallasMainDlg::FormatActionNodeText(CString &text, HTREEITEM action_node)
2641 {
2642 char *desc;
2643 int j;
2644 tTreeNodeData *data;
2645 HTREEITEM child;
2646 bool ok_to_copy;
2647
2648 if(action_node==NULL) {
2649 text="*ERROR*";
2650 return;
2651 }
2652
2653 data=(tTreeNodeData *)m_ScriptTree.GetItemData(action_node);
2654 if(data==NULL) {
2655 text="*ERROR*";
2656 return;
2657 }
2658
2659 if(data->ID==INVALID_FUNCTION_ID) {
2660 text=INVALID_FUNCTION_NAME;
2661 return;
2662 }
2663
2664 desc=GetActionDesc(data->ID);
2665 if(desc==NULL) {
2666 text="*ERROR*";
2667 return;
2668 }
2669
2670 // obtain the first child
2671 child=m_ScriptTree.GetChildItem(action_node);
2672
2673 j=0;
2674 ok_to_copy=TRUE;
2675 text="";
2676 while(desc[j]!='\0') {
2677 if(desc[j]=='[') {
2678 ok_to_copy=FALSE;
2679 }
2680 else if(desc[j]==']') {
2681 ok_to_copy=TRUE;
2682
2683 if(child==NULL)
2684 text+="???";
2685 else {
2686 CString tmp_str;
2687 tTreeNodeData *data;
2688
2689 // Get node's data
2690 data=(tTreeNodeData *)m_ScriptTree.GetItemData(child);
2691
2692 if(data->type==PARAMETER_NODE) {
2693 FormatParameterValueText(tmp_str,data);
2694 text+=tmp_str;
2695 }
2696 else if(data->type==EXPRESSION_NODE) {
2697 FormatQueryNodeText(tmp_str,child);
2698 text+="(";
2699 text+=tmp_str;
2700 text+=")";
2701 }
2702 else
2703 text+="<Invalid Node>";
2704
2705 // Get next child
2706 child=m_ScriptTree.GetNextSiblingItem(child);
2707 }
2708 }
2709 else if(ok_to_copy) {
2710 text+=desc[j];
2711 }
2712
2713 j++;
2714 }
2715 }
2716 */
2717
2718 // Parses a query desc, replacing arg blocks with value strings taken from
2719 // its child parameter nodes
2720 void CDallasMainDlg::FormatQueryNodeText(CString &text, HTREEITEM query_node) {
2721 CString name_text, default_text, range_text;
2722 char *desc;
2723 HTREEITEM child;
2724 tTreeNodeData *data;
2725
2726 if (query_node == NULL) {
2727 text = "*ERROR*";
2728 return;
2729 }
2730
2731 data = (tTreeNodeData *)m_ScriptTree.GetItemData(query_node);
2732 if (data == NULL) {
2733 text = "*ERROR*";
2734 return;
2735 }
2736
2737 if (data->ID == INVALID_FUNCTION_ID) {
2738 text = INVALID_FUNCTION_NAME;
2739 return;
2740 }
2741
2742 desc = GetQueryDesc(data->ID);
2743 if (desc == NULL) {
2744 text = "*ERROR*";
2745 return;
2746 }
2747
2748 // obtain the first child
2749 child = m_ScriptTree.GetChildItem(query_node);
2750
2751 text = "";
2752
2753 // Skip over the return type
2754 desc = strchr(desc, ':');
2755 if (desc == NULL)
2756 return;
2757 desc++;
2758
2759 while ((*desc) != '\0') {
2760 if ((*desc) == '[') {
2761 ParseParamBlock(desc, name_text, default_text, range_text);
2762
2763 if (child == NULL)
2764 text += "???";
2765 else {
2766 CString tmp_str;
2767 tTreeNodeData *data;
2768
2769 // Get node's data
2770 data = (tTreeNodeData *)m_ScriptTree.GetItemData(child);
2771
2772 if (data->type == PARAMETER_NODE) {
2773 FormatParameterValueText(tmp_str, data);
2774 text += tmp_str;
2775 } else if (data->type == EXPRESSION_NODE) {
2776 CString tmp_str;
2777 FormatQueryNodeText(tmp_str, child);
2778 text += "(";
2779 text += tmp_str;
2780 text += ")";
2781 } else
2782 text += "<Invalid Node>";
2783
2784 // Get next child
2785 child = m_ScriptTree.GetNextSiblingItem(child);
2786 }
2787 } else {
2788 text += (*desc);
2789 desc++;
2790 }
2791 }
2792 }
2793
2794 /* OLD VERSION
2795 // Parses a query desc, replacing arg blocks with value strings taken from
2796 // its child parameter nodes
2797 void CDallasMainDlg::FormatQueryNodeText(CString &text, HTREEITEM query_node)
2798 {
2799 char *desc;
2800 int j;
2801 HTREEITEM child;
2802 tTreeNodeData *data;
2803 bool ok_to_copy, first_colon_found;
2804
2805 if(query_node==NULL) {
2806 text="*ERROR*";
2807 return;
2808 }
2809
2810 data=(tTreeNodeData *)m_ScriptTree.GetItemData(query_node);
2811 if(data==NULL) {
2812 text="*ERROR*";
2813 return;
2814 }
2815
2816 if(data->ID==INVALID_FUNCTION_ID) {
2817 text=INVALID_FUNCTION_NAME;
2818 return;
2819 }
2820
2821 desc=GetQueryDesc(data->ID);
2822 if(desc==NULL) {
2823 text="*ERROR*";
2824 return;
2825 }
2826
2827 // obtain the first child
2828 child=m_ScriptTree.GetChildItem(query_node);
2829
2830 j=0;
2831 ok_to_copy=FALSE;
2832 first_colon_found=FALSE;
2833 text="";
2834 while(desc[j]!='\0') {
2835 if(desc[j]=='[') {
2836 ok_to_copy=FALSE;
2837 }
2838 else if(desc[j]==']') {
2839 ok_to_copy=TRUE;
2840
2841 if(child==NULL)
2842 text+="???";
2843 else {
2844 CString tmp_str;
2845 tTreeNodeData *data;
2846
2847 // Get node's data
2848 data=(tTreeNodeData *)m_ScriptTree.GetItemData(child);
2849
2850 if(data->type==PARAMETER_NODE) {
2851 FormatParameterValueText(tmp_str,data);
2852 text+=tmp_str;
2853 }
2854 else if(data->type==EXPRESSION_NODE) {
2855 CString tmp_str;
2856 FormatQueryNodeText(tmp_str,child);
2857 text+="(";
2858 text+=tmp_str;
2859 text+=")";
2860 }
2861 else
2862 text+="<Invalid Node>";
2863
2864 // Get next child
2865 child=m_ScriptTree.GetNextSiblingItem(child);
2866 }
2867 }
2868 else if(desc[j]==':' && !first_colon_found) {
2869 first_colon_found=TRUE;
2870 ok_to_copy=TRUE;
2871 }
2872 else if(ok_to_copy) {
2873 text+=desc[j];
2874 }
2875
2876 j++;
2877 }
2878 }
2879 */
2880
2881 // Converts a parameter character ID into a paramter type
2882 int CDallasMainDlg::ConvertParamCharToType(int param_char_ID) {
2883 int param_type;
2884
2885 switch (param_char_ID) {
2886 case 'd':
2887 param_type = DOOR_PARAMETER_TYPE;
2888 break;
2889 case 'o':
2890 param_type = OBJECT_PARAMETER_TYPE;
2891 break;
2892 case 'r':
2893 param_type = ROOM_PARAMETER_TYPE;
2894 break;
2895 case 't':
2896 param_type = TRIGGER_PARAMETER_TYPE;
2897 break;
2898 case 'i':
2899 param_type = INT_PARAMETER_TYPE;
2900 break;
2901 case 'b':
2902 param_type = BOOL_PARAMETER_TYPE;
2903 break;
2904 case 'f':
2905 param_type = FLOAT_PARAMETER_TYPE;
2906 break;
2907 case 'v':
2908 param_type = VECTOR_PARAMETER_TYPE;
2909 break;
2910 case 's':
2911 param_type = STRING_PARAMETER_TYPE;
2912 break;
2913 case 'p':
2914 param_type = PERCENTAGE_PARAMETER_TYPE;
2915 break;
2916 case 'e':
2917 param_type = ENUM_PARAMETER_TYPE;
2918 break;
2919 case 'x':
2920 param_type = SCRIPT_PARAMETER_TYPE;
2921 break;
2922 case 'n':
2923 param_type = SOUND_PARAMETER_TYPE;
2924 break;
2925 case 'a':
2926 param_type = SPECNAME_PARAMETER_TYPE;
2927 break;
2928 case 'u':
2929 param_type = TEXTURE_PARAMETER_TYPE;
2930 break;
2931 case 'g':
2932 param_type = FLAG_PARAMETER_TYPE;
2933 break;
2934 case 'h':
2935 param_type = PATH_PARAMETER_TYPE;
2936 break;
2937 case 'm':
2938 param_type = MATCEN_PARAMETER_TYPE;
2939 break;
2940 case 'l':
2941 param_type = LEVEL_GOAL_PARAMETER_TYPE;
2942 break;
2943 case 'z':
2944 param_type = STRM_AUDIO_PARAMETER_TYPE;
2945 break;
2946 default:
2947 param_type = UNKNOWN_PARAMETER_TYPE;
2948 break;
2949 }
2950
2951 return (param_type);
2952 }
2953
2954 // Converts a parameter type into a character ID
2955 int CDallasMainDlg::ConvertParamTypeToChar(int param_type) {
2956 int param_char_ID;
2957
2958 switch (param_type) {
2959 case DOOR_PARAMETER_TYPE:
2960 param_char_ID = 'd';
2961 break;
2962 case OBJECT_PARAMETER_TYPE:
2963 param_char_ID = 'o';
2964 break;
2965 case ROOM_PARAMETER_TYPE:
2966 param_char_ID = 'r';
2967 break;
2968 case TRIGGER_PARAMETER_TYPE:
2969 param_char_ID = 't';
2970 break;
2971 case INT_PARAMETER_TYPE:
2972 param_char_ID = 'i';
2973 break;
2974 case BOOL_PARAMETER_TYPE:
2975 param_char_ID = 'b';
2976 break;
2977 case FLOAT_PARAMETER_TYPE:
2978 param_char_ID = 'f';
2979 break;
2980 case VECTOR_PARAMETER_TYPE:
2981 param_char_ID = 'v';
2982 break;
2983 case STRING_PARAMETER_TYPE:
2984 param_char_ID = 's';
2985 break;
2986 case PERCENTAGE_PARAMETER_TYPE:
2987 param_char_ID = 'p';
2988 break;
2989 case ENUM_PARAMETER_TYPE:
2990 param_char_ID = 'e';
2991 break;
2992 case SCRIPT_PARAMETER_TYPE:
2993 param_char_ID = 'x';
2994 break;
2995 case SOUND_PARAMETER_TYPE:
2996 param_char_ID = 'n';
2997 break;
2998 case SPECNAME_PARAMETER_TYPE:
2999 param_char_ID = 'a';
3000 break;
3001 case TEXTURE_PARAMETER_TYPE:
3002 param_char_ID = 'u';
3003 break;
3004 case FLAG_PARAMETER_TYPE:
3005 param_char_ID = 'g';
3006 break;
3007 case PATH_PARAMETER_TYPE:
3008 param_char_ID = 'h';
3009 break;
3010 case MATCEN_PARAMETER_TYPE:
3011 param_char_ID = 'm';
3012 break;
3013 case LEVEL_GOAL_PARAMETER_TYPE:
3014 param_char_ID = 'l';
3015 break;
3016 case STRM_AUDIO_PARAMETER_TYPE:
3017 param_char_ID = 'z';
3018 break;
3019 default:
3020 param_char_ID = '?';
3021 break;
3022 }
3023
3024 return (param_char_ID);
3025 }
3026
3027 // Turns bold on or off for a specified node
3028 void CDallasMainDlg::SetBoldNodeText(HTREEITEM node, bool bold_on) {
3029 if (node == NULL)
3030 return;
3031
3032 if (bold_on)
3033 m_ScriptTree.SetItemState(node, TVIS_BOLD, TVIS_BOLD);
3034 else
3035 m_ScriptTree.SetItemState(node, ~TVIS_BOLD, TVIS_BOLD);
3036 }
3037
3038 // Checks to see if the parent of the given node is a Conditional Statement
3039 // node of type COMPARISON_STATEMENT
3040 bool CDallasMainDlg::ParentIsComparisonConditional(HTREEITEM node) {
3041 HTREEITEM parent;
3042 tTreeNodeData *data;
3043
3044 if (node == NULL)
3045 return (FALSE);
3046
3047 // Get the parent
3048 parent = m_ScriptTree.GetParentItem(node);
3049 if (parent == NULL)
3050 return (FALSE);
3051
3052 // Get the node's data
3053 data = (tTreeNodeData *)m_ScriptTree.GetItemData(parent);
3054 if (data == NULL)
3055 return (FALSE);
3056
3057 // Check the parent node
3058 if (data->type == CONDITIONAL_STATEMENT_NODE && data->ID == COMPARISON_STATEMENT)
3059 return (TRUE);
3060
3061 return (FALSE);
3062 }
3063
3064 // If the given node is a parameter or query, it determines its type (or return type)
3065 // and returns it, unless the parent of the given node is a Comparison conditional
3066 // statement. In this case, any parameter type is allowed
3067 int CDallasMainDlg::GetValidParamType(HTREEITEM node, CString &name) {
3068 tTreeNodeData *data;
3069
3070 // Get the node's data
3071 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
3072 if (data == NULL)
3073 return (-1);
3074
3075 name = "";
3076
3077 if (data->type == PARAMETER_NODE) {
3078 if (ParentIsComparisonConditional(node) && GetChildPosition(node) == 1)
3079 return (ANY_PARAMETER_TYPE);
3080 name = data->name;
3081 return (data->ID);
3082 }
3083
3084 if (data->type == EXPRESSION_NODE) {
3085 if (ParentIsComparisonConditional(node) && GetChildPosition(node) == 1)
3086 return (ANY_PARAMETER_TYPE);
3087 return (GetQueryReturnType(data->ID, name));
3088 }
3089
3090 return (-1);
3091 }
3092
3093 // If the given node is a parameter or query, it determines its type (or return type)
3094 // and returns it
3095 int CDallasMainDlg::GetParamType(HTREEITEM node, CString &name) {
3096 tTreeNodeData *data;
3097
3098 // Get the node's data
3099 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
3100 if (data == NULL)
3101 return (-1);
3102
3103 name = "";
3104
3105 if (data->type == PARAMETER_NODE) {
3106 name = data->name;
3107 return (data->ID);
3108 }
3109
3110 if (data->type == EXPRESSION_NODE) {
3111 return (GetQueryReturnType(data->ID, name));
3112 }
3113
3114 return (-1);
3115 }
3116
3117 // Attaches the correct bitmap image to a node
3118 void CDallasMainDlg::SetTreeNodeImage(HTREEITEM node) {
3119 tTreeNodeData *data;
3120 int temp_id;
3121
3122 // Make sure node is valid
3123 if (node == NULL)
3124 return;
3125
3126 // Get node data, make sure it's valid
3127 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
3128 if (data == NULL)
3129 return;
3130
3131 // Set the item's display images appropriately
3132 switch (data->type) {
3133 case SCRIPT_HEADER_NODE:
3134 m_ScriptTree.SetItemImage(node, 0, 0);
3135 break;
3136 case SCRIPT_OWNER_NODE:
3137 m_ScriptTree.SetItemImage(node, 10, 10);
3138 break;
3139 case SCRIPT_EVENT_NODE:
3140 m_ScriptTree.SetItemImage(node, 11, 11);
3141 break;
3142 case CONDITIONAL_HEADER_NODE:
3143 if (data->ID == TOP_LEVEL)
3144 m_ScriptTree.SetItemImage(node, 1, 1);
3145 else
3146 m_ScriptTree.SetItemImage(node, 8, 8);
3147 break;
3148 case ACTIONS_HEADER_NODE:
3149 if (data->ID == TOP_LEVEL)
3150 m_ScriptTree.SetItemImage(node, 2, 2);
3151 else {
3152 if (data->subID == THEN_CLAUSE)
3153 m_ScriptTree.SetItemImage(node, 9, 9);
3154 else
3155 m_ScriptTree.SetItemImage(node, 18, 18);
3156 }
3157 break;
3158 case CONDITIONAL_STATEMENT_NODE:
3159 m_ScriptTree.SetItemImage(node, 3, 3);
3160 break;
3161 case EXPRESSION_NODE:
3162 m_ScriptTree.SetItemImage(node, 16, 16);
3163 break;
3164 case EXPRESSION_OPERATOR_NODE:
3165 m_ScriptTree.SetItemImage(node, 17, 17);
3166 break;
3167 case ACTION_STATEMENT_NODE:
3168 m_ScriptTree.SetItemImage(node, 4, 4);
3169 break;
3170 case LOGICAL_OPERATOR_NODE:
3171 if (data->ID == AND_TYPE)
3172 m_ScriptTree.SetItemImage(node, 6, 6);
3173 else if (data->ID == OR_TYPE)
3174 m_ScriptTree.SetItemImage(node, 5, 5);
3175 else
3176 m_ScriptTree.SetItemImage(node, 7, 7);
3177 break;
3178 case PARAMETER_NODE:
3179 // Get image type based upon what kind of parameter it is
3180 switch (data->ID) {
3181 case DOOR_PARAMETER_TYPE:
3182 temp_id = 12;
3183 break;
3184 case OBJECT_PARAMETER_TYPE:
3185 temp_id = 12;
3186 break;
3187 case ROOM_PARAMETER_TYPE:
3188 temp_id = 12;
3189 break;
3190 case TRIGGER_PARAMETER_TYPE:
3191 temp_id = 12;
3192 break;
3193 case INT_PARAMETER_TYPE:
3194 temp_id = 13;
3195 break;
3196 case BOOL_PARAMETER_TYPE:
3197 temp_id = 14;
3198 break;
3199 case FLOAT_PARAMETER_TYPE:
3200 temp_id = 13;
3201 break;
3202 case VECTOR_PARAMETER_TYPE:
3203 temp_id = 15;
3204 break;
3205 case STRING_PARAMETER_TYPE:
3206 temp_id = 12;
3207 break;
3208 case PERCENTAGE_PARAMETER_TYPE:
3209 temp_id = 14;
3210 break;
3211 case ENUM_PARAMETER_TYPE:
3212 temp_id = 12;
3213 break;
3214 case SCRIPT_PARAMETER_TYPE:
3215 temp_id = 12;
3216 break;
3217 case SOUND_PARAMETER_TYPE:
3218 temp_id = 15;
3219 break;
3220 case SPECNAME_PARAMETER_TYPE:
3221 temp_id = 13;
3222 break;
3223 case TEXTURE_PARAMETER_TYPE:
3224 temp_id = 15;
3225 break;
3226 case FLAG_PARAMETER_TYPE:
3227 temp_id = 15;
3228 break;
3229 case PATH_PARAMETER_TYPE:
3230 temp_id = 12;
3231 break;
3232 case MATCEN_PARAMETER_TYPE:
3233 temp_id = 12;
3234 break;
3235 case LEVEL_GOAL_PARAMETER_TYPE:
3236 temp_id = 12;
3237 break;
3238 case STRM_AUDIO_PARAMETER_TYPE:
3239 temp_id = 15;
3240 break;
3241 default:
3242 temp_id = 12;
3243 break;
3244 }
3245 m_ScriptTree.SetItemImage(node, temp_id, temp_id);
3246 break;
3247 case PARAMETER_OPERATOR_NODE:
3248 m_ScriptTree.SetItemImage(node, 13, 13);
3249 break;
3250 case CLIPBOARD_HEADER_NODE:
3251 m_ScriptTree.SetItemImage(node, 19, 19);
3252 break;
3253 case UNKNOWN_NODE:
3254 m_ScriptTree.SetItemImage(node, 0, 0);
3255 break;
3256 default:
3257 m_ScriptTree.SetItemImage(node, 0, 0);
3258 break;
3259 }
3260 }
3261
3262 // Adds a node to the tree using the given data
3263 HTREEITEM CDallasMainDlg::AddNodeToTree(HTREEITEM parent, HTREEITEM insertbefore, HTREEITEM src_node,
3264 bool expand /*=FALSE*/) {
3265 tTreeNodeData *data;
3266
3267 data = (tTreeNodeData *)m_ScriptTree.GetItemData(src_node);
3268 return (AddNodeToTree(parent, insertbefore, data, expand));
3269 }
3270
3271 // Adds a node to the tree using the given data
3272 HTREEITEM CDallasMainDlg::AddNodeToTree(HTREEITEM parent, HTREEITEM insertbefore, tTreeNodeData *data_node,
3273 bool expand /*=FALSE*/) {
3274 HTREEITEM added_item, insertafter, new_parent;
3275 TV_INSERTSTRUCT tvs;
3276 TV_ITEM tvi;
3277 tTreeNodeData *new_data_node;
3278 CString node_text;
3279
3280 // Allocate a new data node, and copy given data into it
3281 new_data_node = new tTreeNodeData;
3282 if (new_data_node == NULL) {
3283 MessageBox("Unable to Allocate a New Data Node", "Out of Memory Error!", MB_OK | MB_ICONEXCLAMATION);
3284 return NULL;
3285 }
3286
3287 // Copy given data into new node
3288 (*new_data_node) = (*data_node);
3289
3290 // Fill out the Item structure
3291 tvi.mask = TVIF_TEXT;
3292 // FormatTreeText(node_text,new_data_node);
3293 // tvi.pszText=node_text.GetBuffer(0);
3294 tvi.pszText = "";
3295
3296 // Get the previous child node for "insert before"
3297 if (insertbefore != TVI_FIRST && insertbefore != TVI_LAST && insertbefore != TVI_SORT) {
3298 insertafter = m_ScriptTree.GetPrevSiblingItem(insertbefore);
3299 if (insertafter == NULL)
3300 insertafter = TVI_FIRST;
3301 new_parent = parent;
3302 } else {
3303 insertafter = insertbefore;
3304 new_parent = parent;
3305 }
3306
3307 // Fill out the Insert structure
3308 tvs.hInsertAfter = insertafter;
3309 tvs.hParent = new_parent;
3310 tvs.item = tvi;
3311
3312 added_item = m_ScriptTree.InsertItem(&tvs);
3313
3314 // If add was unsuccessfull, delete the item data
3315 if (added_item == NULL) {
3316 delete new_data_node;
3317 MessageBox("Unable to Allocate a New Tree Node", "Out of Memory Error!", MB_OK | MB_ICONEXCLAMATION);
3318 return NULL;
3319 }
3320
3321 // Set the node data and image
3322 m_ScriptTree.SetItemData(added_item, (DWORD)new_data_node);
3323 SetTreeNodeImage(added_item);
3324
3325 // Set the new node's text
3326 UpdateNodeText(added_item);
3327
3328 // Expand the parent if necessary
3329 if (parent != NULL && expand)
3330 m_ScriptTree.Expand(parent, TVE_EXPAND);
3331
3332 return (added_item);
3333 }
3334
3335 // Frees all data for a tree leaf (and all children of the given leaf)
3336 void CDallasMainDlg::FreeTreeItem(HTREEITEM item) {
3337 tTreeNodeData *data;
3338
3339 if (item == NULL)
3340 return;
3341
3342 // Free all children of this node
3343 FreeTreeItemChildren(item);
3344
3345 // Deallocate the data structure
3346 data = (tTreeNodeData *)m_ScriptTree.GetItemData(item);
3347 delete data;
3348
3349 // Delete the actual tree node
3350 m_ScriptTree.DeleteItem(item);
3351 }
3352
3353 // Frees all children of the given leaf, but leaves the given leaf intact
3354 void CDallasMainDlg::FreeTreeItemChildren(HTREEITEM item) {
3355 HTREEITEM child, old_child;
3356
3357 if (item == NULL)
3358 return;
3359
3360 child = m_ScriptTree.GetChildItem(item);
3361 while (child) {
3362 old_child = child;
3363 child = m_ScriptTree.GetNextSiblingItem(child);
3364 FreeTreeItem(old_child);
3365 }
3366 }
3367
3368 // Expands given node and all children
3369 void CDallasMainDlg::ExpandAll(HTREEITEM node, UINT nCode) {
3370 HTREEITEM child;
3371
3372 if (node == NULL)
3373 return;
3374
3375 child = m_ScriptTree.GetChildItem(node);
3376 while (child != NULL) {
3377 ExpandAll(child, nCode);
3378 child = m_ScriptTree.GetNextSiblingItem(child);
3379 }
3380
3381 // Expand this node
3382 m_ScriptTree.Expand(node, nCode);
3383 }
3384
3385 // Copies the entire tree starting at src_node to the specified destination
3386 HTREEITEM CDallasMainDlg::CopyTree(HTREEITEM dest_parent, HTREEITEM dest_insert_before, HTREEITEM src_node) {
3387 HTREEITEM dest_node;
3388
3389 dest_node = AddNodeToTree(dest_parent, dest_insert_before, src_node);
3390 if (dest_node != NULL) {
3391 CopyChildren(dest_node, src_node);
3392 UpdateNodeText(dest_node);
3393 }
3394
3395 return (dest_node);
3396 }
3397
3398 // Copies all the children of src_parent to dest_parent
3399 HTREEITEM CDallasMainDlg::CopyChildren(HTREEITEM dest_parent, HTREEITEM src_parent) {
3400 HTREEITEM src_child, dest_child;
3401
3402 dest_child = NULL;
3403 src_child = m_ScriptTree.GetChildItem(src_parent);
3404 while (src_child != NULL) {
3405 dest_child = AddNodeToTree(dest_parent, TVI_LAST, src_child);
3406 if (dest_child == NULL)
3407 return NULL;
3408 CopyChildren(dest_child, src_child);
3409 UpdateNodeText(dest_child);
3410 src_child = m_ScriptTree.GetNextSiblingItem(src_child);
3411 }
3412
3413 return (dest_child);
3414 }
3415
3416 // Returns the position of the given child (i.e. child is the Nth child of parent)
3417 int CDallasMainDlg::GetChildPosition(HTREEITEM child) {
3418 HTREEITEM node;
3419 int count;
3420
3421 if (child == NULL)
3422 return 0;
3423
3424 count = 1;
3425 node = m_ScriptTree.GetPrevSiblingItem(child);
3426 while (node != NULL) {
3427 node = m_ScriptTree.GetPrevSiblingItem(node);
3428 count++;
3429 }
3430
3431 return (count);
3432 }
3433
3434 // Returns the Nth child of the given parent (NULL if one doesn't exist)
3435 HTREEITEM CDallasMainDlg::GetNthChild(HTREEITEM parent, int n) {
3436 HTREEITEM child;
3437 int count;
3438
3439 if (parent == NULL || n <= 0)
3440 return NULL;
3441
3442 count = 1;
3443 child = m_ScriptTree.GetChildItem(parent);
3444
3445 while (child != NULL && count != n) {
3446 child = m_ScriptTree.GetNextSiblingItem(child);
3447 count++;
3448 }
3449
3450 return (child);
3451 }
3452
3453 // Returns the child count
3454 int CDallasMainDlg::GetChildCount(HTREEITEM parent) {
3455 HTREEITEM child;
3456 int count;
3457
3458 if (parent == NULL)
3459 return 0;
3460
3461 count = 0;
3462 child = m_ScriptTree.GetChildItem(parent);
3463 while (child != NULL) {
3464 child = m_ScriptTree.GetNextSiblingItem(child);
3465 count++;
3466 }
3467
3468 return (count);
3469 }
3470
3471 // Returns the script ID for any given node (must be a descendant of SCRIPT_HEADER_NODE though)
3472 int CDallasMainDlg::GetScriptID(HTREEITEM script_node) {
3473 HTREEITEM script_header_node;
3474 tTreeNodeData *data;
3475
3476 script_header_node = GetParentNodeOfType(script_node, SCRIPT_HEADER_NODE);
3477 if (script_header_node == NULL)
3478 return (-1);
3479
3480 data = (tTreeNodeData *)m_ScriptTree.GetItemData(script_header_node);
3481 if (data == NULL)
3482 return (-1);
3483
3484 return (data->ID);
3485 }
3486
3487 // Returns script header node of script matching given script ID (NULL if not found)
3488 HTREEITEM CDallasMainDlg::FindScriptIDNode(int scriptID) {
3489 HTREEITEM node;
3490
3491 // Fill up the list
3492 node = m_ScriptTree.GetChildItem(TVI_ROOT);
3493 while (node != NULL) {
3494 int id = GetScriptID(node);
3495 if (id == scriptID) {
3496 return (node);
3497 }
3498 node = m_ScriptTree.GetNextSiblingItem(node);
3499 }
3500
3501 return (NULL);
3502 }
3503
3504 // Compare function for GetLowestUnusedScriptID()
3505 int id_list_compare(const void *arg1, const void *arg2) {
3506 int *num1 = (int *)arg1;
3507 int *num2 = (int *)arg2;
3508
3509 if ((*num1) < (*num2))
3510 return (-1);
3511 return (1);
3512 }
3513
3514 // Looks through scripts to determine the lowest unused script ID
3515 int CDallasMainDlg::GetLowestUnusedScriptID(void) {
3516 int *list;
3517 int size;
3518 int max_size;
3519 int lowest_id;
3520 HTREEITEM node;
3521
3522 lowest_id = 0;
3523
3524 // Create the Script ID List
3525 max_size = GetChildCount(TVI_ROOT);
3526 if (max_size == 0)
3527 return (lowest_id);
3528 list = (int *)mem_malloc(sizeof(int) * max_size);
3529 if (list == NULL)
3530 return (m_NextScriptID);
3531
3532 // Fill up the list
3533 size = 0;
3534 node = m_ScriptTree.GetChildItem(TVI_ROOT);
3535 while (node != NULL) {
3536 int id = GetScriptID(node);
3537 if (id >= 0 && size < max_size) {
3538 list[size] = id;
3539 size++;
3540 }
3541 node = m_ScriptTree.GetNextSiblingItem(node);
3542 }
3543
3544 // Sort and determine the lowest unused ID
3545 qsort((void *)list, size, sizeof(int), id_list_compare);
3546
3547 // Determine the lowest number
3548 int j;
3549 lowest_id = 0;
3550 for (j = 0; j < size; j++) {
3551 if (lowest_id < list[j])
3552 break;
3553 lowest_id = list[j] + 1;
3554 }
3555
3556 /* Debugging output
3557 CString msg, num;
3558 msg="";
3559 for(j=0;j<size;j++) {
3560 num.Format("%d ",list[j]);
3561 msg+=num;
3562 }
3563 num.Format("-> %d ",lowest_id);
3564 msg+=num;
3565 MessageBox(msg,"The Script ID List");
3566 */
3567
3568 // Free up the list
3569 mem_free(list);
3570
3571 return (lowest_id);
3572 }
3573
3574 // Returns the node type of given node
3575 int CDallasMainDlg::GetNodeType(HTREEITEM node) {
3576 tTreeNodeData *data;
3577
3578 if (node == NULL)
3579 return (UNKNOWN_NODE);
3580
3581 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
3582 if (data == NULL)
3583 return (UNKNOWN_NODE);
3584
3585 return (data->type);
3586 }
3587
3588 // Returns the script owner type for any given node (must be a descendant of SCRIPT_HEADER_NODE though)
3589 int CDallasMainDlg::GetScriptOwnerType(HTREEITEM script_node) {
3590 HTREEITEM script_owner_node;
3591 tTreeNodeData *data;
3592
3593 script_owner_node = GetScriptOwnerNode(script_node);
3594 if (script_owner_node == NULL)
3595 return (-1);
3596
3597 data = (tTreeNodeData *)m_ScriptTree.GetItemData(script_owner_node);
3598 if (data == NULL)
3599 return (-1);
3600
3601 return (data->ID);
3602 }
3603
3604 // Returns the script event type for any given node (must be a descendant of SCRIPT_HEADER_NODE though)
3605 int CDallasMainDlg::GetScriptEventType(HTREEITEM script_node) {
3606 HTREEITEM script_event_node;
3607 tTreeNodeData *data;
3608
3609 script_event_node = GetScriptEventNode(script_node);
3610 if (script_event_node == NULL)
3611 return (-1);
3612
3613 data = (tTreeNodeData *)m_ScriptTree.GetItemData(script_event_node);
3614 if (data == NULL)
3615 return (-1);
3616
3617 return (data->ID);
3618 }
3619
3620 // Sets the script event type for any given node (must be a descendant of SCRIPT_HEADER_NODE though)
3621 bool CDallasMainDlg::SetScriptEventType(HTREEITEM script_node, int type) {
3622 HTREEITEM script_event_node;
3623 tTreeNodeData *data;
3624
3625 script_event_node = GetScriptEventNode(script_node);
3626 if (script_event_node == NULL)
3627 return FALSE;
3628
3629 data = (tTreeNodeData *)m_ScriptTree.GetItemData(script_event_node);
3630 if (data == NULL)
3631 return FALSE;
3632
3633 data->ID = type;
3634 UpdateAllParentNodesText(script_event_node);
3635
3636 return TRUE;
3637 }
3638
3639 // Searches for a parent node (or current node) that matches the given type (returns NULL if none found)
3640 HTREEITEM CDallasMainDlg::GetParentNodeOfType(HTREEITEM child_node, int node_type) {
3641 HTREEITEM parent;
3642 tTreeNodeData *data;
3643
3644 parent = child_node;
3645 while (parent != NULL) {
3646 data = (tTreeNodeData *)m_ScriptTree.GetItemData(parent);
3647 if (data != NULL && data->type == node_type)
3648 return (parent);
3649 parent = m_ScriptTree.GetParentItem(parent);
3650 }
3651
3652 return (parent);
3653 }
3654
3655 // Returns the data of the closest EXPRESSION or ACTION node to the given node
3656 tTreeNodeData *CDallasMainDlg::GetNearestFunctionNode(HTREEITEM node) {
3657 HTREEITEM parent;
3658 tTreeNodeData *data;
3659
3660 parent = node;
3661 while (parent != NULL) {
3662 data = (tTreeNodeData *)m_ScriptTree.GetItemData(parent);
3663 if (data != NULL && (data->type == EXPRESSION_NODE || data->type == ACTION_STATEMENT_NODE))
3664 return (data);
3665 parent = m_ScriptTree.GetParentItem(parent);
3666 }
3667
3668 return (NULL);
3669 }
3670
3671 // Searches for either an ACTION_STATEMENT_NODE or an EXPRESSION_NODE
3672 // that is the closest parent to the given PARAMETER_NODE (returns NULL if none found)
3673 HTREEITEM CDallasMainDlg::GetParameterParentNode(HTREEITEM param_node) {
3674 HTREEITEM parent;
3675 tTreeNodeData *data;
3676
3677 // Make sure given node is a parameter node
3678 data = (tTreeNodeData *)m_ScriptTree.GetItemData(param_node);
3679 if (data == NULL || data->type != PARAMETER_NODE)
3680 return NULL;
3681
3682 // Keep getting the parent until we find a good match (or run out of parents)
3683 parent = m_ScriptTree.GetParentItem(param_node);
3684 while (parent != NULL) {
3685 data = (tTreeNodeData *)m_ScriptTree.GetItemData(parent);
3686 if (data != NULL && data->type == ACTION_STATEMENT_NODE)
3687 return (parent);
3688 if (data != NULL && data->type == EXPRESSION_NODE)
3689 return (parent);
3690 parent = m_ScriptTree.GetParentItem(parent);
3691 }
3692
3693 return (parent);
3694 }
3695
3696 // Returns the owner node for any given Script node
3697 HTREEITEM CDallasMainDlg::GetScriptOwnerNode(HTREEITEM node) {
3698 HTREEITEM temp_node;
3699
3700 // Get the parent Script header node of the given node
3701 temp_node = GetParentNodeOfType(node, SCRIPT_HEADER_NODE);
3702 if (temp_node == NULL)
3703 return NULL;
3704
3705 // Get the owner node (first child of script header)
3706 temp_node = m_ScriptTree.GetChildItem(temp_node);
3707
3708 return (temp_node);
3709 }
3710
3711 // Returns the event node for any given Script node
3712 HTREEITEM CDallasMainDlg::GetScriptEventNode(HTREEITEM node) {
3713 HTREEITEM temp_node;
3714
3715 // Get the script owner node
3716 temp_node = GetScriptOwnerNode(node);
3717 if (node == NULL)
3718 return NULL;
3719
3720 // Get the event node (next node after owner)
3721 temp_node = m_ScriptTree.GetNextSiblingItem(temp_node);
3722
3723 return (temp_node);
3724 }
3725
3726 // Returns the conditional header (TOP LEVEL) node for any given Script node
3727 HTREEITEM CDallasMainDlg::GetConditionalHeaderNode(HTREEITEM node) {
3728 HTREEITEM temp_node;
3729
3730 // Get the script owner node
3731 temp_node = GetScriptEventNode(node);
3732 if (node == NULL)
3733 return NULL;
3734
3735 // Get the conditional header node (next node after event node)
3736 temp_node = m_ScriptTree.GetNextSiblingItem(temp_node);
3737
3738 return (temp_node);
3739 }
3740
3741 // Returns the action header (TOP LEVEL) node for any given Script node
3742 HTREEITEM CDallasMainDlg::GetActionHeaderNode(HTREEITEM node) {
3743 HTREEITEM temp_node;
3744
3745 // Get the script owner node
3746 temp_node = GetConditionalHeaderNode(node);
3747 if (node == NULL)
3748 return NULL;
3749
3750 // Get the action header node (next node after conditional header)
3751 temp_node = m_ScriptTree.GetNextSiblingItem(temp_node);
3752
3753 return (temp_node);
3754 }
3755
3756 // Highlights the headers for all scripts whose owner matches
3757 // the owner specified in m_ScriptOwnerType and m_ScriptOwnerHandle
3758 void CDallasMainDlg::HighlightAllScripts(void) {
3759 HTREEITEM script_header_node;
3760
3761 // Group each script header node into the list
3762 script_header_node = m_ScriptTree.GetChildItem(TVI_ROOT);
3763 while (script_header_node != NULL) {
3764 HighlightScript(script_header_node);
3765 script_header_node = m_ScriptTree.GetNextSiblingItem(script_header_node);
3766 }
3767 }
3768
3769 // Highlights the headers for all scripts whose owner matches
3770 // the owner specified in m_ScriptOwnerType and m_ScriptOwnerHandle
3771 void CDallasMainDlg::HighlightScript(HTREEITEM node) {
3772 HTREEITEM script_header_node;
3773
3774 script_header_node = GetParentNodeOfType(node, SCRIPT_HEADER_NODE);
3775 if (script_header_node == NULL)
3776 return;
3777
3778 HTREEITEM owner_node, event_node;
3779 tTreeNodeData *data;
3780 bool owners_match;
3781
3782 owners_match = FALSE;
3783 owner_node = GetScriptOwnerNode(script_header_node);
3784 if (owner_node != NULL) {
3785 data = (tTreeNodeData *)m_ScriptTree.GetItemData(owner_node);
3786 if (data != NULL) {
3787 if (m_ScriptOwnerType == ALL_OWNERS_TYPE)
3788 owners_match = TRUE;
3789 else if (m_ScriptOwnerType == LEVEL_TYPE && data->ID == LEVEL_TYPE)
3790 owners_match = TRUE;
3791 else if (m_ScriptOwnerType == ALL_OBJECTS_TYPE && data->ID == OBJECT_TYPE)
3792 owners_match = TRUE;
3793 else if (m_ScriptOwnerType == ALL_TRIGGERS_TYPE && data->ID == TRIGGER_TYPE)
3794 owners_match = TRUE;
3795 else if (m_ScriptOwnerType == data->ID && m_ScriptOwnerHandle == data->int_val)
3796 owners_match = TRUE;
3797 }
3798 }
3799
3800 event_node = GetScriptEventNode(script_header_node);
3801 if (event_node != NULL) {
3802 data = (tTreeNodeData *)m_ScriptTree.GetItemData(event_node);
3803 if (data != NULL) {
3804 int event_type = GetHighlightedEvent();
3805 if (event_type != ALL_EVENT_TYPES && data->ID != event_type)
3806 owners_match = FALSE;
3807 }
3808 }
3809
3810 if (owners_match)
3811 SetBoldNodeText(script_header_node, TRUE);
3812 else
3813 SetBoldNodeText(script_header_node, FALSE);
3814 }
3815
3816 /////////////////////////////////////////////////////////////////////////////
3817 // Message List Functions
3818 /////////////////////////////////////////////////////////////////////////////
3819
3820 // Initializes the message list,
3821 // MUST BE CALLED BEFORE USING ANY MESSAGE LIST functions!!!
3822 void CDallasMainDlg::InitMessageList(void) {
3823 int j;
3824
3825 // Init the list of message entries to empty
3826 for (j = 0; j < MAX_MESSAGE_LIST_ENTRIES; j++)
3827 m_MessageEntryList[j] = NULL;
3828 }
3829
3830 // Clears the message list
3831 void CDallasMainDlg::ClearMessageList(void) {
3832 int j;
3833
3834 // Wipeout the list of message entries
3835 for (j = 0; j < MAX_MESSAGE_LIST_ENTRIES; j++)
3836 if (m_MessageEntryList[j] != NULL) {
3837 delete m_MessageEntryList[j];
3838 m_MessageEntryList[j] = NULL;
3839 }
3840
3841 // Reset the next message ID
3842 m_NextMessageID = 1;
3843
3844 // Clear the message list and edit boxes
3845 m_MessageEdit.SetWindowText("");
3846 m_MessageList.ResetContent();
3847 }
3848
3849 // Adds a message to the list
3850 bool CDallasMainDlg::AddToMessageList(char *name, char *message) {
3851 tMessageListEntry *empty_slot;
3852 int index;
3853
3854 // Make sure no duplicate entries exist
3855 if (FindMessageInList(name) != NULL) {
3856 m_MessageListErrorCode = MSG_LIST_DUP_NAME_ERROR;
3857 return FALSE;
3858 }
3859
3860 // Search the list for an empty slot, and add the message
3861 empty_slot = GetEmptyMessageListEntry();
3862 if (empty_slot == NULL) {
3863 m_MessageListErrorCode = MSG_LIST_FULL_ERROR;
3864 return FALSE;
3865 }
3866
3867 // Set the data
3868 strncpy(empty_slot->name, name, MAX_MESSAGE_NAME_LEN);
3869 empty_slot->name[MAX_MESSAGE_NAME_LEN] = '\0';
3870 strncpy(empty_slot->message, message, MAX_MESSAGE_LEN);
3871 empty_slot->message[MAX_MESSAGE_LEN] = '\0';
3872
3873 // Add to the list and edit controls
3874 index = m_MessageList.AddString(name);
3875 if (index < 0) {
3876 m_MessageListErrorCode = MSG_LIST_FULL_ERROR;
3877 return FALSE;
3878 }
3879
3880 m_MessageList.SetItemData(index, (DWORD)empty_slot);
3881
3882 // Set the new selection to be the current selection
3883 m_MessageList.SetCurSel(index);
3884 OnSelchangeMessageList();
3885
3886 return TRUE;
3887 }
3888
3889 // Returns a message matching the given name, or NULL if none found
3890 char *CDallasMainDlg::FindMessageInList(char *name) {
3891 int j;
3892
3893 // Scan entry list for given name
3894 for (j = 0; j < MAX_MESSAGE_LIST_ENTRIES; j++)
3895 if (m_MessageEntryList[j] != NULL && strcmp(m_MessageEntryList[j]->name, name) == 0)
3896 return (m_MessageEntryList[j]->message);
3897
3898 return (NULL);
3899 }
3900
3901 // Deletes a message entry
3902 int CDallasMainDlg::DeleteMessageListEntry(char *name) {
3903 int j;
3904
3905 // Scan entry list for given name
3906 for (j = 0; j < MAX_MESSAGE_LIST_ENTRIES; j++)
3907 if (m_MessageEntryList[j] != NULL && strcmp(m_MessageEntryList[j]->name, name) == 0) {
3908 delete m_MessageEntryList[j];
3909 m_MessageEntryList[j] = NULL;
3910 return (TRUE);
3911 }
3912
3913 return (FALSE);
3914 }
3915
3916 // Returns an available entry slot, or NULL if none exist
3917 tMessageListEntry *CDallasMainDlg::GetEmptyMessageListEntry(void) {
3918 int j;
3919
3920 // Scan entry list for an empty slot
3921 for (j = 0; j < MAX_MESSAGE_LIST_ENTRIES; j++)
3922 if (m_MessageEntryList[j] == NULL) {
3923 m_MessageEntryList[j] = new tMessageListEntry;
3924 return (m_MessageEntryList[j]);
3925 }
3926
3927 return (NULL);
3928 }
3929
3930 /////////////////////////////////////////////////////////////////////////////
3931 // Name List functions
3932 /////////////////////////////////////////////////////////////////////////////
3933
3934 // Initialize all the name lists
3935 void CDallasMainDlg::InitNameLists(void) {
3936 int j;
3937
3938 // Init the Door list
3939 for (j = 0; j < MAX_NAMED_DOORS; j++)
3940 m_DoorList[j] = NULL;
3941 m_DoorListSize = 0;
3942
3943 // Init the object list
3944 for (j = 0; j < MAX_NAMED_OBJECTS; j++)
3945 m_ObjectList[j] = NULL;
3946 m_ObjectListSize = 0;
3947
3948 // Init the Room list
3949 for (j = 0; j < MAX_NAMED_ROOMS; j++)
3950 m_RoomList[j] = NULL;
3951 m_RoomListSize = 0;
3952
3953 // Init the Trigger list
3954 for (j = 0; j < MAX_NAMED_TRIGGERS; j++)
3955 m_TriggerList[j] = NULL;
3956 m_TriggerListSize = 0;
3957
3958 // Init the sound list
3959 for (j = 0; j < MAX_NAMED_SOUNDS; j++)
3960 m_SoundList[j] = NULL;
3961 m_SoundListSize = 0;
3962
3963 // Init the Texture list
3964 for (j = 0; j < MAX_NAMED_TEXTURES; j++)
3965 m_TextureList[j] = NULL;
3966 m_TextureListSize = 0;
3967
3968 // Init the Specname list
3969 for (j = 0; j < MAX_SPECNAMES; j++)
3970 m_SpecnameList[j] = NULL;
3971 m_SpecnameListSize = 0;
3972
3973 // Init the Path list
3974 for (j = 0; j < MAX_NAMED_PATHS; j++)
3975 m_PathList[j] = NULL;
3976 m_PathListSize = 0;
3977
3978 // Init the Matcen list
3979 for (j = 0; j < MAX_NAMED_MATCENS; j++)
3980 m_MatcenList[j] = NULL;
3981 m_MatcenListSize = 0;
3982
3983 // Init the Goal list
3984 for (j = 0; j < MAX_NAMED_GOALS; j++)
3985 m_GoalList[j] = NULL;
3986 m_GoalListSize = 0;
3987
3988 // Init the StrmAudio list
3989 for (j = 0; j < MAX_NAMED_STRM_AUDIO; j++)
3990 m_StrmAudioList[j] = NULL;
3991 m_StrmAudioListSize = 0;
3992
3993 // Init the Message name list
3994 for (j = 0; j < MAX_MESSAGE_LIST_ENTRIES; j++)
3995 m_MessageNameList[j] = NULL;
3996 m_MessageNameListSize = 0;
3997 }
3998
3999 // Empty the name lists
4000 void CDallasMainDlg::ClearNameLists(void) {
4001 int j;
4002
4003 // Clear the Door list
4004 for (j = 0; j < m_DoorListSize; j++)
4005 if (m_DoorList[j] != NULL) {
4006 mem_free(m_DoorList[j]);
4007 m_DoorList[j] = NULL;
4008 }
4009 m_DoorListSize = 0;
4010
4011 // Clear the object list
4012 for (j = 0; j < m_ObjectListSize; j++)
4013 if (m_ObjectList[j] != NULL) {
4014 mem_free(m_ObjectList[j]);
4015 m_ObjectList[j] = NULL;
4016 }
4017 m_ObjectListSize = 0;
4018
4019 // Clear the Room list
4020 for (j = 0; j < m_RoomListSize; j++)
4021 if (m_RoomList[j] != NULL) {
4022 mem_free(m_RoomList[j]);
4023 m_RoomList[j] = NULL;
4024 }
4025 m_RoomListSize = 0;
4026
4027 // Clear the Trigger list
4028 for (j = 0; j < m_TriggerListSize; j++)
4029 if (m_TriggerList[j] != NULL) {
4030 mem_free(m_TriggerList[j]);
4031 m_TriggerList[j] = NULL;
4032 }
4033 m_TriggerListSize = 0;
4034
4035 // Clear the sound list
4036 for (j = 0; j < m_SoundListSize; j++)
4037 if (m_SoundList[j] != NULL) {
4038 mem_free(m_SoundList[j]);
4039 m_SoundList[j] = NULL;
4040 }
4041 m_SoundListSize = 0;
4042
4043 // Clear the Texture list
4044 for (j = 0; j < m_TextureListSize; j++)
4045 if (m_TextureList[j] != NULL) {
4046 mem_free(m_TextureList[j]);
4047 m_TextureList[j] = NULL;
4048 }
4049 m_TextureListSize = 0;
4050
4051 // Clear the Specname list
4052 for (j = 0; j < m_SpecnameListSize; j++)
4053 if (m_SpecnameList[j] != NULL) {
4054 mem_free(m_SpecnameList[j]);
4055 m_SpecnameList[j] = NULL;
4056 }
4057 m_SpecnameListSize = 0;
4058
4059 // Clear the Path list
4060 for (j = 0; j < m_PathListSize; j++)
4061 if (m_PathList[j] != NULL) {
4062 mem_free(m_PathList[j]);
4063 m_PathList[j] = NULL;
4064 }
4065 m_PathListSize = 0;
4066
4067 // Clear the Matcen list
4068 for (j = 0; j < m_MatcenListSize; j++)
4069 if (m_MatcenList[j] != NULL) {
4070 mem_free(m_MatcenList[j]);
4071 m_MatcenList[j] = NULL;
4072 }
4073 m_MatcenListSize = 0;
4074
4075 // Clear the Goal list
4076 for (j = 0; j < m_GoalListSize; j++)
4077 if (m_GoalList[j] != NULL) {
4078 mem_free(m_GoalList[j]);
4079 m_GoalList[j] = NULL;
4080 }
4081 m_GoalListSize = 0;
4082
4083 // Clear the StrmAudio list
4084 for (j = 0; j < m_StrmAudioListSize; j++)
4085 if (m_StrmAudioList[j] != NULL) {
4086 mem_free(m_StrmAudioList[j]);
4087 m_StrmAudioList[j] = NULL;
4088 }
4089 m_StrmAudioListSize = 0;
4090
4091 // Clear the Message Name list
4092 for (j = 0; j < m_MessageNameListSize; j++)
4093 if (m_MessageNameList[j] != NULL) {
4094 mem_free(m_MessageNameList[j]);
4095 m_MessageNameList[j] = NULL;
4096 }
4097 m_MessageNameListSize = 0;
4098 }
4099
4100 // Search the tree, and fill all of the name lists
4101 // Returns a count of all invalid name fields encountered
4102 int CDallasMainDlg::FillNameListsFromTree(HTREEITEM parent, bool show_notspec_warnings) {
4103 HTREEITEM child;
4104 int inv_name_count;
4105
4106 if (parent == NULL)
4107 return 0;
4108
4109 // Search the tree for named things
4110 inv_name_count = 0;
4111 child = m_ScriptTree.GetChildItem(parent);
4112 while (child != NULL) {
4113 inv_name_count += FillNameListsFromTree(child, show_notspec_warnings);
4114 inv_name_count += AddNameToListFromTreeNode(child, show_notspec_warnings);
4115 child = m_ScriptTree.GetNextSiblingItem(child);
4116 }
4117
4118 return (inv_name_count);
4119 }
4120
4121 // Checks to see if the node contains a named thing,
4122 // and, if it does, adds it to the appropriate name list
4123 // It returns 1 if an invalid name is found, 0 otherwise
4124 int CDallasMainDlg::AddNameToListFromTreeNode(HTREEITEM node, bool show_notspec_warnings) {
4125 tTreeNodeData *data;
4126 int scriptID;
4127
4128 if (node == NULL)
4129 return 0;
4130
4131 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
4132 if (data == NULL)
4133 return 0;
4134
4135 // Make sure this node isn't in the clipboard
4136 HTREEITEM script_header_node;
4137 script_header_node = GetParentNodeOfType(node, SCRIPT_HEADER_NODE);
4138 if (script_header_node == NULL)
4139 return 0;
4140 if (m_ScriptTree.GetParentItem(script_header_node) != NULL)
4141 return 0;
4142
4143 // Get the script ID
4144 scriptID = GetScriptID(node);
4145 if (scriptID == -1)
4146 return 0;
4147
4148 // See if it's an Owner Node
4149 if (data->type == SCRIPT_OWNER_NODE) {
4150 if (data->ID == NOT_SPECIFIED_TYPE) {
4151 if (show_notspec_warnings)
4152 IndValNotSpecMsg(scriptID, "Script Owner");
4153 return 1;
4154 }
4155 if (data->ID == LEVEL_TYPE)
4156 return 0;
4157 if (data->ID == OBJECT_TYPE) {
4158 // Check for object None
4159 if (data->int_val == OBJECT_HANDLE_NONE) {
4160 if (show_notspec_warnings)
4161 IndValNotSpecMsg(scriptID, "Script Owner (Object)");
4162 return 1;
4163 }
4164
4165 // Check for invalid objects
4166 object *objp = ObjGet(data->int_val);
4167 if (objp == NULL || objp->type == OBJ_NONE || objp->name == NULL) {
4168 int handle = osipf_FindObjectName(data->str_val);
4169 if (handle != OBJECT_HANDLE_NONE) {
4170 if (InvObjPrompt(scriptID, data->int_val, data->str_val, handle) == IDYES) {
4171 data->int_val = handle;
4172 UpdateAllParentNodesText(node);
4173 AddObjectToList(data->str_val);
4174 return 0;
4175 }
4176 }
4177 InvObjMsg(scriptID, data->int_val, data->str_val);
4178 data->int_val = OBJECT_HANDLE_NONE;
4179 strcpy(data->str_val, "");
4180 UpdateAllParentNodesText(node);
4181 return 1;
4182 }
4183
4184 // Check for invalid object names
4185 if (strcmp(data->str_val, objp->name) != 0) {
4186 int handle = osipf_FindObjectName(data->str_val);
4187 if (handle != OBJECT_HANDLE_NONE) {
4188 if (InvNameObjPrompt(scriptID, data->int_val, data->str_val, objp->name, handle) == IDYES) {
4189 data->int_val = handle;
4190 UpdateAllParentNodesText(node);
4191 AddObjectToList(data->str_val);
4192 return 0;
4193 }
4194 }
4195 InvNameObjMsg(scriptID, data->int_val, data->str_val, objp->name);
4196 strcpy(data->str_val, objp->name);
4197 UpdateAllParentNodesText(node);
4198 AddObjectToList(data->str_val);
4199 return 0;
4200 }
4201
4202 // All is cool, so just add the name
4203 AddObjectToList(objp->name);
4204 return 0;
4205 }
4206 if (data->ID == TRIGGER_TYPE) {
4207 // Check for not specified triggers
4208 if (data->int_val == NOT_SPECIFIED_TYPE) {
4209 if (show_notspec_warnings)
4210 IndValNotSpecMsg(scriptID, "Script Owner (Trigger)");
4211 return 1;
4212 }
4213
4214 // Check for invalid triggers
4215 int t = data->int_val;
4216 if (t < 0 || t >= Num_triggers || t >= MAX_NAMED_TRIGGERS || strlen(Triggers[t].name) == 0) {
4217 int index = osipf_FindTriggerName(data->str_val);
4218 if (index >= 0) {
4219 if (InvIndValPrompt(scriptID, "Trigger", t, data->str_val, index) == IDYES) {
4220 data->int_val = index;
4221 UpdateAllParentNodesText(node);
4222 AddTriggerToList(data->str_val);
4223 return 0;
4224 }
4225 }
4226 InvIndValMsg(scriptID, "Trigger", t, data->str_val);
4227 data->int_val = NOT_SPECIFIED_TYPE;
4228 strcpy(data->str_val, "");
4229 UpdateAllParentNodesText(node);
4230 return 1;
4231 }
4232
4233 // Check for invalid trigger names
4234 if (strcmp(data->str_val, Triggers[t].name) != 0) {
4235 int index = osipf_FindTriggerName(data->str_val);
4236 if (index >= 0) {
4237 if (InvNameIndValPrompt(scriptID, "Trigger", t, data->str_val, Triggers[t].name, index) == IDYES) {
4238 data->int_val = index;
4239 UpdateAllParentNodesText(node);
4240 AddTriggerToList(data->str_val);
4241 return 0;
4242 }
4243 }
4244 InvNameIndValMsg(scriptID, "Trigger", t, data->str_val, Triggers[t].name);
4245 strcpy(data->str_val, Triggers[t].name);
4246 UpdateAllParentNodesText(node);
4247 AddTriggerToList(data->str_val);
4248 return 0;
4249 }
4250
4251 // All is cool, so just add the name
4252 AddTriggerToList(Triggers[t].name);
4253 return 0;
4254 }
4255 }
4256
4257 // See if it's a parameter Node
4258 if (data->type == PARAMETER_NODE) {
4259 switch (data->ID) {
4260 case DOOR_PARAMETER_TYPE: {
4261 // Check for ME handle
4262 if (data->subID == USE_ME_HANDLE) {
4263 if (ScriptHasADoorMe(node)) {
4264 return 0;
4265 } else {
4266 InvSpecParamMsg(scriptID, "an OWNER (Door object)");
4267 return 1;
4268 }
4269 }
4270
4271 // Check for IT handle
4272 if (data->subID == USE_IT_HANDLE)
4273 return 0;
4274
4275 // Check for object None
4276 if (data->int_val == OBJECT_HANDLE_NONE) {
4277 if (show_notspec_warnings)
4278 IndValNotSpecMsg(scriptID, "Door Object");
4279 return 1;
4280 }
4281
4282 // Check for invalid door objects
4283 object *objp = ObjGet(data->int_val);
4284 if (objp == NULL || objp->type == OBJ_NONE || objp->name == NULL) {
4285 int handle = osipf_FindDoorName(data->str_val);
4286 if (handle != OBJECT_HANDLE_NONE) {
4287 if (InvObjPrompt(scriptID, data->int_val, data->str_val, handle) == IDYES) {
4288 data->int_val = handle;
4289 UpdateAllParentNodesText(node);
4290 AddObjectToList(data->str_val);
4291 return 0;
4292 }
4293 }
4294 InvObjMsg(scriptID, data->int_val, data->str_val);
4295 data->int_val = OBJECT_HANDLE_NONE;
4296 strcpy(data->str_val, "");
4297 UpdateAllParentNodesText(node);
4298 return 1;
4299 }
4300
4301 // Check for invalid door object names
4302 if (strcmp(data->str_val, objp->name) != 0) {
4303 int handle = osipf_FindDoorName(data->str_val);
4304 if (handle != OBJECT_HANDLE_NONE) {
4305 if (InvNameObjPrompt(scriptID, data->int_val, data->str_val, objp->name, handle) == IDYES) {
4306 data->int_val = handle;
4307 UpdateAllParentNodesText(node);
4308 AddObjectToList(data->str_val);
4309 return 0;
4310 }
4311 }
4312 InvNameObjMsg(scriptID, data->int_val, data->str_val, objp->name);
4313 strcpy(data->str_val, objp->name);
4314 UpdateAllParentNodesText(node);
4315 AddObjectToList(data->str_val);
4316 return 0;
4317 }
4318
4319 // All is cool, so just add the name
4320 AddDoorToList(objp->name);
4321 } break;
4322 case OBJECT_PARAMETER_TYPE: {
4323 // Check for ME and IT handles
4324 if (data->subID == USE_ME_HANDLE) {
4325 if (ScriptHasAMe(node)) {
4326 return 0;
4327 } else {
4328 InvSpecParamMsg(scriptID, "an OWNER (object)");
4329 return 1;
4330 }
4331 }
4332
4333 if (data->subID == USE_IT_HANDLE) {
4334 if (ScriptHasAnIt(node)) {
4335 return 0;
4336 } else {
4337 InvSpecParamMsg(scriptID, "an IT (object)");
4338 return 1;
4339 }
4340 }
4341
4342 // Check for object None
4343 if (data->int_val == OBJECT_HANDLE_NONE) {
4344 if (show_notspec_warnings)
4345 IndValNotSpecMsg(scriptID, "Generic Object");
4346 return 1;
4347 }
4348
4349 // Check for invalid objects
4350 object *objp = ObjGet(data->int_val);
4351 if (objp == NULL || objp->type == OBJ_NONE || objp->name == NULL) {
4352 int handle = osipf_FindObjectName(data->str_val);
4353 if (handle != OBJECT_HANDLE_NONE) {
4354 if (InvObjPrompt(scriptID, data->int_val, data->str_val, handle) == IDYES) {
4355 data->int_val = handle;
4356 UpdateAllParentNodesText(node);
4357 AddObjectToList(data->str_val);
4358 return 0;
4359 }
4360 }
4361 InvObjMsg(scriptID, data->int_val, data->str_val);
4362 data->int_val = OBJECT_HANDLE_NONE;
4363 strcpy(data->str_val, "");
4364 UpdateAllParentNodesText(node);
4365 return 1;
4366 }
4367
4368 // Check for invalid object names
4369 if (strcmp(data->str_val, objp->name) != 0) {
4370 int handle = osipf_FindObjectName(data->str_val);
4371 if (handle != OBJECT_HANDLE_NONE) {
4372 if (InvNameObjPrompt(scriptID, data->int_val, data->str_val, objp->name, handle) == IDYES) {
4373 data->int_val = handle;
4374 UpdateAllParentNodesText(node);
4375 AddObjectToList(data->str_val);
4376 return 0;
4377 }
4378 }
4379 InvNameObjMsg(scriptID, data->int_val, data->str_val, objp->name);
4380 strcpy(data->str_val, objp->name);
4381 UpdateAllParentNodesText(node);
4382 AddObjectToList(data->str_val);
4383 return 0;
4384 }
4385
4386 // All is cool, so just add the name
4387 AddObjectToList(objp->name);
4388 } break;
4389 case ROOM_PARAMETER_TYPE: {
4390 // Check for not specified rooms
4391 if (data->int_val == NOT_SPECIFIED_TYPE) {
4392 if (show_notspec_warnings)
4393 IndValNotSpecMsg(scriptID, "Room");
4394 return 1;
4395 }
4396
4397 // Check for invalid rooms
4398 int r = data->int_val;
4399 if (r < 0 || r > Highest_room_index || !Rooms[r].used || Rooms[r].name == NULL) {
4400 int index = osipf_FindRoomName(data->str_val);
4401 if (index >= 0) {
4402 if (InvIndValPrompt(scriptID, "Room", r, data->str_val, index) == IDYES) {
4403 data->int_val = index;
4404 UpdateAllParentNodesText(node);
4405 AddRoomToList(data->str_val);
4406 return 0;
4407 }
4408 }
4409 InvIndValMsg(scriptID, "Room", r, data->str_val);
4410 data->int_val = NOT_SPECIFIED_TYPE;
4411 strcpy(data->str_val, "");
4412 UpdateAllParentNodesText(node);
4413 return 1;
4414 }
4415
4416 // Check for invalid room names
4417 if (strcmp(data->str_val, Rooms[r].name) != 0) {
4418 int index = osipf_FindRoomName(data->str_val);
4419 if (index >= 0) {
4420 if (InvNameIndValPrompt(scriptID, "Room", r, data->str_val, Rooms[r].name, index) == IDYES) {
4421 data->int_val = index;
4422 UpdateAllParentNodesText(node);
4423 AddRoomToList(data->str_val);
4424 return 0;
4425 }
4426 }
4427 InvNameIndValMsg(scriptID, "Room", r, data->str_val, Rooms[r].name);
4428 strcpy(data->str_val, Rooms[r].name);
4429 UpdateAllParentNodesText(node);
4430 AddRoomToList(data->str_val);
4431 return 0;
4432 }
4433
4434 // All is cool, so just add the name
4435 AddRoomToList(Rooms[r].name);
4436 } break;
4437 case TRIGGER_PARAMETER_TYPE: {
4438 // Check for not specified triggers
4439 if (data->int_val == NOT_SPECIFIED_TYPE) {
4440 if (show_notspec_warnings)
4441 IndValNotSpecMsg(scriptID, "Trigger");
4442 return 1;
4443 }
4444
4445 // Check for invalid triggers
4446 int t = data->int_val;
4447 if (t < 0 || t >= Num_triggers || t >= MAX_NAMED_TRIGGERS || strlen(Triggers[t].name) == 0) {
4448 int index = osipf_FindTriggerName(data->str_val);
4449 if (index >= 0) {
4450 if (InvIndValPrompt(scriptID, "Trigger", t, data->str_val, index) == IDYES) {
4451 data->int_val = index;
4452 UpdateAllParentNodesText(node);
4453 AddTriggerToList(data->str_val);
4454 return 0;
4455 }
4456 }
4457 InvIndValMsg(scriptID, "Trigger", t, data->str_val);
4458 data->int_val = NOT_SPECIFIED_TYPE;
4459 strcpy(data->str_val, "");
4460 UpdateAllParentNodesText(node);
4461 return 1;
4462 }
4463
4464 // Check for invalid trigger names
4465 if (strcmp(data->str_val, Triggers[t].name) != 0) {
4466 int index = osipf_FindTriggerName(data->str_val);
4467 if (index >= 0) {
4468 if (InvNameIndValPrompt(scriptID, "Trigger", t, data->str_val, Triggers[t].name, index) == IDYES) {
4469 data->int_val = index;
4470 UpdateAllParentNodesText(node);
4471 AddTriggerToList(data->str_val);
4472 return 0;
4473 }
4474 }
4475 InvNameIndValMsg(scriptID, "Trigger", t, data->str_val, Triggers[t].name);
4476 strcpy(data->str_val, Triggers[t].name);
4477 UpdateAllParentNodesText(node);
4478 AddTriggerToList(data->str_val);
4479 return 0;
4480 }
4481
4482 // All is cool, so just add the name
4483 AddTriggerToList(Triggers[t].name);
4484 } break;
4485 case SOUND_PARAMETER_TYPE: {
4486 // Check for not specified sounds
4487 if (data->int_val == NOT_SPECIFIED_TYPE) {
4488 if (show_notspec_warnings)
4489 IndValNotSpecMsg(scriptID, "Sound");
4490 return 1;
4491 }
4492
4493 // Check for invalid sounds
4494 int s = data->int_val;
4495 if (s < 0 || s >= MAX_SOUNDS || !Sounds[s].used) {
4496 int index = osipf_FindSoundName(data->str_val);
4497 if (index >= 0) {
4498 if (InvIndValPrompt(scriptID, "Sound", s, data->str_val, index) == IDYES) {
4499 data->int_val = index;
4500 UpdateAllParentNodesText(node);
4501 AddSoundToList(data->str_val);
4502 return 0;
4503 }
4504 }
4505 InvIndValMsg(scriptID, "Sound", s, data->str_val);
4506 data->int_val = NOT_SPECIFIED_TYPE;
4507 strcpy(data->str_val, "");
4508 UpdateAllParentNodesText(node);
4509 return 1;
4510 }
4511
4512 // Check for invalid sound names
4513 if (strcmp(data->str_val, Sounds[s].name) != 0) {
4514 int index = osipf_FindSoundName(data->str_val);
4515 if (index >= 0) {
4516 if (InvNameIndValPrompt(scriptID, "Sound", s, data->str_val, Sounds[s].name, index) == IDYES) {
4517 data->int_val = index;
4518 UpdateAllParentNodesText(node);
4519 AddSoundToList(data->str_val);
4520 return 0;
4521 }
4522 }
4523 InvNameIndValMsg(scriptID, "Sound", s, data->str_val, Sounds[s].name);
4524 strcpy(data->str_val, Sounds[s].name);
4525 UpdateAllParentNodesText(node);
4526 AddSoundToList(data->str_val);
4527 return 0;
4528 }
4529
4530 // All is cool, so just add the name
4531 AddSoundToList(Sounds[s].name);
4532 } break;
4533 case TEXTURE_PARAMETER_TYPE: {
4534 // Check for not specified textures
4535 if (data->int_val == NOT_SPECIFIED_TYPE) {
4536 if (show_notspec_warnings)
4537 IndValNotSpecMsg(scriptID, "Texture");
4538 return 1;
4539 }
4540
4541 // Check for invalid textures
4542 int t = data->int_val;
4543 if (t < 0 || t >= MAX_TEXTURES || !GameTextures[t].used) {
4544 int index = osipf_FindTextureName(data->str_val);
4545 if (index >= 0) {
4546 if (InvIndValPrompt(scriptID, "Texture", t, data->str_val, index) == IDYES) {
4547 data->int_val = index;
4548 UpdateAllParentNodesText(node);
4549 AddTextureToList(data->str_val);
4550 return 0;
4551 }
4552 }
4553 InvIndValMsg(scriptID, "Texture", t, data->str_val);
4554 data->int_val = NOT_SPECIFIED_TYPE;
4555 strcpy(data->str_val, "");
4556 UpdateAllParentNodesText(node);
4557 return 1;
4558 }
4559
4560 // Check for invalid texture names
4561 if (strcmp(data->str_val, GameTextures[t].name) != 0) {
4562 int index = osipf_FindTextureName(data->str_val);
4563 if (index >= 0) {
4564 if (InvNameIndValPrompt(scriptID, "Texture", t, data->str_val, GameTextures[t].name, index) == IDYES) {
4565 data->int_val = index;
4566 UpdateAllParentNodesText(node);
4567 AddTextureToList(data->str_val);
4568 return 0;
4569 }
4570 }
4571 InvNameIndValMsg(scriptID, "Texture", t, data->str_val, GameTextures[t].name);
4572 strcpy(data->str_val, GameTextures[t].name);
4573 UpdateAllParentNodesText(node);
4574 AddTextureToList(data->str_val);
4575 return 0;
4576 }
4577
4578 // All is cool, so just add the name
4579 AddTextureToList(GameTextures[t].name);
4580 } break;
4581 case PATH_PARAMETER_TYPE: {
4582 // Check for not specified paths
4583 if (data->int_val == NOT_SPECIFIED_TYPE) {
4584 if (show_notspec_warnings)
4585 IndValNotSpecMsg(scriptID, "Path");
4586 return 1;
4587 }
4588
4589 // Check for invalid paths
4590 int t = data->int_val;
4591 if (t < 0 || t >= MAX_GAME_PATHS || !GamePaths[t].used) {
4592 int index = osipf_FindPathName(data->str_val);
4593 if (index >= 0) {
4594 if (InvIndValPrompt(scriptID, "Path", t, data->str_val, index) == IDYES) {
4595 data->int_val = index;
4596 UpdateAllParentNodesText(node);
4597 AddPathToList(data->str_val);
4598 return 0;
4599 }
4600 }
4601 InvIndValMsg(scriptID, "Path", t, data->str_val);
4602 data->int_val = NOT_SPECIFIED_TYPE;
4603 strcpy(data->str_val, "");
4604 UpdateAllParentNodesText(node);
4605 return 1;
4606 }
4607
4608 // Check for invalid path names
4609 if (strcmp(data->str_val, GamePaths[t].name) != 0) {
4610 int index = osipf_FindPathName(data->str_val);
4611 if (index >= 0) {
4612 if (InvNameIndValPrompt(scriptID, "Path", t, data->str_val, GamePaths[t].name, index) == IDYES) {
4613 data->int_val = index;
4614 UpdateAllParentNodesText(node);
4615 AddPathToList(data->str_val);
4616 return 0;
4617 }
4618 }
4619 InvNameIndValMsg(scriptID, "Path", t, data->str_val, GamePaths[t].name);
4620 strcpy(data->str_val, GamePaths[t].name);
4621 UpdateAllParentNodesText(node);
4622 AddPathToList(data->str_val);
4623 return 0;
4624 }
4625
4626 // All is cool, so just add the name
4627 AddPathToList(GamePaths[t].name);
4628 } break;
4629 case MATCEN_PARAMETER_TYPE: {
4630 // Check for MATCEN ID
4631 if (data->subID == USE_MATCEN_EVENT_ID) {
4632 if (ScriptHasAMatcenID(node)) {
4633 return 0;
4634 } else {
4635 InvSpecParamMsg(scriptID, "a MATCEN ID (Matcen type)");
4636 return 1;
4637 }
4638 }
4639
4640 // Check for not specified matcens
4641 if (data->int_val == NOT_SPECIFIED_TYPE) {
4642 if (show_notspec_warnings)
4643 IndValNotSpecMsg(scriptID, "Matcen");
4644 return 1;
4645 }
4646
4647 // Check for invalid matcens
4648 int t = data->int_val;
4649 if (!MatcenValid(t)) {
4650 int index = osipf_FindMatcenName(data->str_val);
4651 if (index >= 0) {
4652 if (InvIndValPrompt(scriptID, "Matcen", t, data->str_val, index) == IDYES) {
4653 data->int_val = index;
4654 UpdateAllParentNodesText(node);
4655 AddMatcenToList(data->str_val);
4656 return 0;
4657 }
4658 }
4659 InvIndValMsg(scriptID, "Matcen", t, data->str_val);
4660 data->int_val = NOT_SPECIFIED_TYPE;
4661 strcpy(data->str_val, "");
4662 UpdateAllParentNodesText(node);
4663 return 1;
4664 }
4665
4666 // Check for invalid matcen names
4667 char matcen_name[MAX_MATCEN_NAME_LEN + 1];
4668 Matcen[t]->GetName(matcen_name);
4669 if (strcmp(data->str_val, matcen_name) != 0) {
4670 int index = osipf_FindMatcenName(data->str_val);
4671 if (index >= 0) {
4672 if (InvNameIndValPrompt(scriptID, "Matcen", t, data->str_val, matcen_name, index) == IDYES) {
4673 data->int_val = index;
4674 UpdateAllParentNodesText(node);
4675 AddMatcenToList(data->str_val);
4676 return 0;
4677 }
4678 }
4679 InvNameIndValMsg(scriptID, "Matcen", t, data->str_val, matcen_name);
4680 strcpy(data->str_val, matcen_name);
4681 UpdateAllParentNodesText(node);
4682 AddMatcenToList(data->str_val);
4683 return 0;
4684 }
4685
4686 // All is cool, so just add the name
4687 AddMatcenToList(matcen_name);
4688 } break;
4689 case LEVEL_GOAL_PARAMETER_TYPE: {
4690 // Check for LEVEL GOAL ID
4691 if (data->subID == USE_LEVEL_GOAL_ID) {
4692 if (ScriptHasALevelGoalID(node)) {
4693 return 0;
4694 } else {
4695 InvSpecParamMsg(scriptID, "a LEVEL GOAL ID (Level Goal type)");
4696 return 1;
4697 }
4698 }
4699
4700 // Check for not specified level goals
4701 if (data->int_val == NOT_SPECIFIED_TYPE) {
4702 if (show_notspec_warnings)
4703 IndValNotSpecMsg(scriptID, "Level Goal");
4704 return 1;
4705 }
4706
4707 // Check for invalid level goals
4708 int t = osipf_FindLevelGoalName(data->str_val);
4709 if (t < 0) {
4710 InvIndValMsg(scriptID, "Level Goal", t, data->str_val);
4711 data->int_val = NOT_SPECIFIED_TYPE;
4712 strcpy(data->str_val, "");
4713 UpdateAllParentNodesText(node);
4714 return 1;
4715 }
4716 data->int_val = t;
4717
4718 // All is cool, so just add the name
4719 AddGoalToList(data->str_val);
4720 } break;
4721 case STRM_AUDIO_PARAMETER_TYPE: {
4722 // Check for not specified streaming audio filenames
4723 if (strlen(data->str_val) == 0) {
4724 if (show_notspec_warnings)
4725 IndValNotSpecMsg(scriptID, "Streaming Audio File");
4726 return 1;
4727 }
4728
4729 // Check if filename is invalid
4730 if (!GamefileExists(data->str_val)) {
4731 InvIndValMsg(scriptID, "Streaming Audio File", 0, data->str_val);
4732 strcpy(data->str_val, "");
4733 UpdateAllParentNodesText(node);
4734 return 1;
4735 }
4736
4737 // All is cool, so just add the name
4738 AddStrmAudioToList(data->str_val);
4739 } break;
4740 case SPECNAME_PARAMETER_TYPE: {
4741 // Check for not specified special names
4742 if (strlen(data->str_val) == 0) {
4743 if (show_notspec_warnings)
4744 IndValNotSpecMsg(scriptID, "Specific Name");
4745 return 1;
4746 }
4747
4748 // All is cool, so just add the name
4749 AddSpecnameToList(data->str_val);
4750 } break;
4751 case STRING_PARAMETER_TYPE: {
4752 // Check for not specified messages
4753 if (strlen(data->str_val) == 0) {
4754 if (show_notspec_warnings)
4755 IndValNotSpecMsg(scriptID, "Message ID");
4756 return 1;
4757 }
4758
4759 // Check if message name is invalid
4760 if (FindMessageInList(data->str_val) == NULL) {
4761 InvIndValMsg(scriptID, "Message ID", 0, data->str_val);
4762 strcpy(data->str_val, "");
4763 UpdateAllParentNodesText(node);
4764 return 1;
4765 }
4766
4767 // All is cool, so just add the message name
4768 AddMessageNameToList(data->str_val);
4769 } break;
4770 case ENUM_PARAMETER_TYPE: {
4771 // Check for GOAL ID and TIMER ID handles
4772 if (data->subID == USE_GOALID_VALUE) {
4773 if (ScriptHasAGoalID(node)) {
4774 return 0;
4775 } else {
4776 InvSpecParamMsg(scriptID, "a GOAL ID (Enumerated type:GoalID)");
4777 return 1;
4778 }
4779 }
4780
4781 if (data->subID == USE_TIMERID_VALUE) {
4782 if (ScriptHasATimerID(node)) {
4783 return 0;
4784 } else {
4785 InvSpecParamMsg(scriptID, "a TIMER ID (Enumerated type:TimerID)");
4786 return 1;
4787 }
4788 }
4789
4790 if (data->subID == USE_MATCENID_VALUE) {
4791 if (ScriptHasAMatcenID(node)) {
4792 return 0;
4793 } else {
4794 InvSpecParamMsg(scriptID, "a MATCEN ID (Enumerated type:MatcenID)");
4795 return 1;
4796 }
4797 }
4798
4799 // Check for invalid enums
4800 if (GetEnumValueName(data->name, data->int_val) == NULL) {
4801 IndValNotSpecMsg(scriptID, "Enumerated Type");
4802 UpdateAllParentNodesText(node);
4803 return 1;
4804 }
4805 } break;
4806 case SCRIPT_PARAMETER_TYPE: {
4807 // Check for NOT SPECIFIED script ID's
4808 if (data->int_val == NOT_SPECIFIED_TYPE) {
4809 if (show_notspec_warnings)
4810 IndValNotSpecMsg(scriptID, "Script ID");
4811 return 1;
4812 }
4813
4814 // Check for invalid script ID's
4815 if (FindScriptIDNode(data->int_val) == NULL) {
4816 InvIndValMsg(scriptID, "Script ID", data->int_val, "Unknown");
4817 data->int_val = NOT_SPECIFIED_TYPE;
4818 UpdateAllParentNodesText(node);
4819 return 1;
4820 }
4821 } break;
4822 }
4823 return 0;
4824 }
4825
4826 return 0;
4827 }
4828
4829 // Displays the invalid special parameter warning message
4830 void CDallasMainDlg::InvSpecParamMsg(int scriptID, char *type_name) {
4831 CString msg, title;
4832
4833 if (type_name == NULL)
4834 return;
4835
4836 msg.Format("WARNING: Script #%d references %s even though its selected event (or owner) type does not support one.",
4837 scriptID, type_name);
4838 title.Format("Invalid Special Parameter Warning!");
4839 MessageBox(msg, title, MB_OK | MB_ICONEXCLAMATION);
4840 }
4841
4842 // Displays the NOT SPECIFIED indexed value warning message
4843 void CDallasMainDlg::IndValNotSpecMsg(int scriptID, char *type_name) {
4844 CString msg, title;
4845
4846 if (type_name == NULL)
4847 return;
4848
4849 msg.Format("WARNING: Script #%d references a %s which has not been specified.", scriptID, type_name);
4850 title.Format("%s Not Specified Warning!", type_name);
4851 MessageBox(msg, title, MB_OK | MB_ICONEXCLAMATION);
4852 }
4853
4854 // Displays the invalid indexed value warning message
4855 void CDallasMainDlg::InvIndValMsg(int scriptID, char *type_name, int index, char *name) {
4856 CString msg, title;
4857
4858 if (type_name == NULL || name == NULL)
4859 return;
4860
4861 msg.Format("WARNING: Script #%d references a %s (index=%d, name=%s) that no longer exists. It will be changed to "
4862 "NOT SPECIFIED.",
4863 scriptID, type_name, index, name);
4864 title.Format("Invalid %s Warning!", type_name);
4865 MessageBox(msg, title, MB_OK | MB_ICONEXCLAMATION);
4866 }
4867
4868 // Displays the invalid indexed value prompt
4869 int CDallasMainDlg::InvIndValPrompt(int scriptID, char *type_name, int index, char *name, int new_index) {
4870 CString msg, title;
4871
4872 if (type_name == NULL || name == NULL)
4873 return (IDNO);
4874
4875 msg.Format("WARNING: Script #%d references a %s (index=%d, name=%s) that no longer exists. However, another %s "
4876 "(index=%d) exists with the same name.\n\nDo you want to use this other one instead?",
4877 scriptID, type_name, index, name, type_name, new_index);
4878 title.Format("Invalid %s Warning!", type_name);
4879 return (MessageBox(msg, title, MB_YESNO | MB_ICONEXCLAMATION));
4880 }
4881
4882 // Displays the invalid indexed value name warning message
4883 void CDallasMainDlg::InvNameIndValMsg(int scriptID, char *type_name, int index, char *name, char *new_name) {
4884 CString msg, title;
4885
4886 if (type_name == NULL || name == NULL || new_name == NULL)
4887 return;
4888
4889 msg.Format("WARNING: Script #%d references a %s (index=%d, name=%s) whose name has changed to \"%s\". Its name will "
4890 "be updated.",
4891 scriptID, type_name, index, name, new_name);
4892 title.Format("Invalid %s Name Warning!", type_name);
4893 MessageBox(msg, title, MB_OK | MB_ICONEXCLAMATION);
4894 }
4895
4896 // Displays the invalid indexed value name prompt
4897 int CDallasMainDlg::InvNameIndValPrompt(int scriptID, char *type_name, int index, char *name, char *new_name,
4898 int new_index) {
4899 CString msg, title;
4900
4901 if (type_name == NULL || name == NULL || new_name == NULL)
4902 return (IDNO);
4903
4904 msg.Format("WARNING: Script #%d references a %s (index=%d, name=%s) whose name has changed to \"%s\". However, "
4905 "another %s (index=%d) exists with the old name.\n\nDo you want to use this other one instead?",
4906 scriptID, type_name, index, name, new_name, type_name, new_index);
4907 title.Format("Invalid %s Name Warning!", type_name);
4908 return (MessageBox(msg, title, MB_YESNO | MB_ICONEXCLAMATION));
4909 }
4910
4911 // Displays the invalid Object warning message
4912 void CDallasMainDlg::InvObjMsg(int scriptID, int handle, char *name) {
4913 CString msg, title;
4914
4915 if (name == NULL)
4916 return;
4917
4918 msg.Format("WARNING: Script #%d references an Object (handle=%d, name=%s) that no longer exists. It will be changed "
4919 "to Object NONE.",
4920 scriptID, handle, name);
4921 title.Format("Invalid Object Warning!");
4922 MessageBox(msg, title, MB_OK | MB_ICONEXCLAMATION);
4923 }
4924
4925 // Displays the invalid Object prompt
4926 int CDallasMainDlg::InvObjPrompt(int scriptID, int handle, char *name, int new_handle) {
4927 CString msg, title;
4928
4929 if (name == NULL)
4930 return (IDNO);
4931
4932 msg.Format("WARNING: Script #%d references an Object (handle=%d, name=%s) that no longer exists. However, another "
4933 "object (handle=%d) exists with the same name.\n\nDo you want to use this other one instead?",
4934 scriptID, handle, name, new_handle);
4935 title.Format("Invalid Object Warning!");
4936 return (MessageBox(msg, title, MB_YESNO | MB_ICONEXCLAMATION));
4937 }
4938
4939 // Displays the invalid object name warning message
4940 void CDallasMainDlg::InvNameObjMsg(int scriptID, int handle, char *name, char *new_name) {
4941 CString msg, title;
4942
4943 if (name == NULL || new_name == NULL)
4944 return;
4945
4946 msg.Format("WARNING: Script #%d references an Object (handle=%d, name=%s) whose name has changed to \"%s\". Its "
4947 "name will be updated.",
4948 scriptID, handle, name, new_name);
4949 title.Format("Invalid Object Name Warning!");
4950 MessageBox(msg, title, MB_OK | MB_ICONEXCLAMATION);
4951 }
4952
4953 // Displays the invalid object name prompt
4954 int CDallasMainDlg::InvNameObjPrompt(int scriptID, int handle, char *name, char *new_name, int new_handle) {
4955 CString msg, title;
4956
4957 if (name == NULL || new_name == NULL)
4958 return (IDNO);
4959
4960 msg.Format(
4961 "WARNING: Script #%d references an Object (handle=%d, name=%s) whose name has changed to \"%s\". However, "
4962 "another object (handle=%d) exists with the old name.\n\nDo you want to use this other one instead?",
4963 scriptID, handle, name, new_name, new_handle);
4964 title.Format("Invalid Object Name Warning!");
4965 return (MessageBox(msg, title, MB_YESNO | MB_ICONEXCLAMATION));
4966 }
4967
4968 // Adds the given door name to the door name list
4969 int CDallasMainDlg::AddDoorToList(char *name) {
4970 // Make sure we've got a name
4971 if (name == NULL || strlen(name) == 0)
4972 return FALSE;
4973
4974 // See if it's already in the list
4975 if (FindDoorInList(name) >= 0)
4976 return TRUE;
4977
4978 // If there's room in the list, add the new name
4979 if (m_DoorListSize >= MAX_NAMED_DOORS)
4980 return FALSE;
4981
4982 int pos = m_DoorListSize;
4983 m_DoorList[pos] = (char *)mem_malloc(strlen(name) + 1);
4984 if (m_DoorList[pos] == NULL) {
4985 MessageBox("Out of memory in AddDoorToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
4986 return FALSE;
4987 }
4988 strcpy(m_DoorList[pos], name);
4989 m_DoorListSize++;
4990
4991 return TRUE;
4992 }
4993
4994 // Returns the list index of the given door name (or -1 if not found)
4995 int CDallasMainDlg::FindDoorInList(char *name) {
4996 if (name == NULL)
4997 return (-1);
4998
4999 for (int j = 0; j < m_DoorListSize; j++)
5000 if (strcmp(m_DoorList[j], name) == 0)
5001 return (j);
5002
5003 return (-1);
5004 }
5005
5006 // Adds the given object name to the object name list
5007 int CDallasMainDlg::AddObjectToList(char *name) {
5008 // Make sure we've got a name
5009 if (name == NULL || strlen(name) == 0)
5010 return FALSE;
5011
5012 // See if it's already in the list
5013 if (FindObjectInList(name) >= 0)
5014 return TRUE;
5015
5016 // If there's room in the list, add the new name
5017 if (m_ObjectListSize >= MAX_NAMED_OBJECTS)
5018 return FALSE;
5019
5020 int pos = m_ObjectListSize;
5021 m_ObjectList[pos] = (char *)mem_malloc(strlen(name) + 1);
5022 if (m_ObjectList[pos] == NULL) {
5023 MessageBox("Out of memory in AddObjectToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
5024 return FALSE;
5025 }
5026 strcpy(m_ObjectList[pos], name);
5027 m_ObjectListSize++;
5028
5029 return TRUE;
5030 }
5031
5032 // Returns the list index of the given object name (or -1 if not found)
5033 int CDallasMainDlg::FindObjectInList(char *name) {
5034 if (name == NULL)
5035 return (-1);
5036
5037 for (int j = 0; j < m_ObjectListSize; j++)
5038 if (strcmp(m_ObjectList[j], name) == 0)
5039 return (j);
5040
5041 return (-1);
5042 }
5043
5044 // Adds the given Room name to the Room name list
5045 int CDallasMainDlg::AddRoomToList(char *name) {
5046 // Make sure we've got a name
5047 if (name == NULL || strlen(name) == 0)
5048 return FALSE;
5049
5050 // See if it's already in the list
5051 if (FindRoomInList(name) >= 0)
5052 return TRUE;
5053
5054 // If there's room in the list, add the new name
5055 if (m_RoomListSize >= MAX_NAMED_ROOMS)
5056 return FALSE;
5057
5058 int pos = m_RoomListSize;
5059 m_RoomList[pos] = (char *)mem_malloc(strlen(name) + 1);
5060 if (m_RoomList[pos] == NULL) {
5061 MessageBox("Out of memory in AddRoomToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
5062 return FALSE;
5063 }
5064 strcpy(m_RoomList[pos], name);
5065 m_RoomListSize++;
5066
5067 return TRUE;
5068 }
5069
5070 // Returns the list index of the given room name (or -1 if not found)
5071 int CDallasMainDlg::FindRoomInList(char *name) {
5072 if (name == NULL)
5073 return (-1);
5074
5075 for (int j = 0; j < m_RoomListSize; j++)
5076 if (strcmp(m_RoomList[j], name) == 0)
5077 return (j);
5078
5079 return (-1);
5080 }
5081
5082 // Adds the given Trigger name to the Trigger name list
5083 int CDallasMainDlg::AddTriggerToList(char *name) {
5084 // Make sure we've got a name
5085 if (name == NULL || strlen(name) == 0)
5086 return FALSE;
5087
5088 // See if it's already in the list
5089 if (FindTriggerInList(name) >= 0)
5090 return TRUE;
5091
5092 // If there's Trigger in the list, add the new name
5093 if (m_TriggerListSize >= MAX_NAMED_TRIGGERS)
5094 return FALSE;
5095
5096 int pos = m_TriggerListSize;
5097 m_TriggerList[pos] = (char *)mem_malloc(strlen(name) + 1);
5098 if (m_TriggerList[pos] == NULL) {
5099 MessageBox("Out of memory in AddTriggerToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
5100 return FALSE;
5101 }
5102 strcpy(m_TriggerList[pos], name);
5103 m_TriggerListSize++;
5104
5105 return TRUE;
5106 }
5107
5108 // Returns the list index of the given Trigger name (or -1 if not found)
5109 int CDallasMainDlg::FindTriggerInList(char *name) {
5110 if (name == NULL)
5111 return (-1);
5112
5113 for (int j = 0; j < m_TriggerListSize; j++)
5114 if (strcmp(m_TriggerList[j], name) == 0)
5115 return (j);
5116
5117 return (-1);
5118 }
5119
5120 // Adds the given sound name to the sound name list
5121 int CDallasMainDlg::AddSoundToList(char *name) {
5122 // Make sure we've got a name
5123 if (name == NULL || strlen(name) == 0)
5124 return FALSE;
5125
5126 // See if it's already in the list
5127 if (FindSoundInList(name) >= 0)
5128 return TRUE;
5129
5130 // If there's room in the list, add the new name
5131 if (m_SoundListSize >= MAX_NAMED_SOUNDS)
5132 return FALSE;
5133
5134 int pos = m_SoundListSize;
5135 m_SoundList[pos] = (char *)mem_malloc(strlen(name) + 1);
5136 if (m_SoundList[pos] == NULL) {
5137 MessageBox("Out of memory in AddSoundToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
5138 return FALSE;
5139 }
5140 strcpy(m_SoundList[pos], name);
5141 m_SoundListSize++;
5142
5143 return TRUE;
5144 }
5145
5146 // Returns the list index of the given sound name (or -1 if not found)
5147 int CDallasMainDlg::FindSoundInList(char *name) {
5148 if (name == NULL)
5149 return (-1);
5150
5151 for (int j = 0; j < m_SoundListSize; j++)
5152 if (strcmp(m_SoundList[j], name) == 0)
5153 return (j);
5154
5155 return (-1);
5156 }
5157
5158 // Adds the given Texture name to the Texture name list
5159 int CDallasMainDlg::AddTextureToList(char *name) {
5160 // Make sure we've got a name
5161 if (name == NULL || strlen(name) == 0)
5162 return FALSE;
5163
5164 // See if it's already in the list
5165 if (FindTextureInList(name) >= 0)
5166 return TRUE;
5167
5168 // If there's room in the list, add the new name
5169 if (m_TextureListSize >= MAX_NAMED_TEXTURES)
5170 return FALSE;
5171
5172 int pos = m_TextureListSize;
5173 m_TextureList[pos] = (char *)mem_malloc(strlen(name) + 1);
5174 if (m_TextureList[pos] == NULL) {
5175 MessageBox("Out of memory in AddTextureToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
5176 return FALSE;
5177 }
5178 strcpy(m_TextureList[pos], name);
5179 m_TextureListSize++;
5180
5181 return TRUE;
5182 }
5183
5184 // Returns the list index of the given Texture name (or -1 if not found)
5185 int CDallasMainDlg::FindTextureInList(char *name) {
5186 if (name == NULL)
5187 return (-1);
5188
5189 for (int j = 0; j < m_TextureListSize; j++)
5190 if (strcmp(m_TextureList[j], name) == 0)
5191 return (j);
5192
5193 return (-1);
5194 }
5195
5196 // Adds the given Specname name to the Specname name list
5197 int CDallasMainDlg::AddSpecnameToList(char *name) {
5198 // Make sure we've got a name
5199 if (name == NULL || strlen(name) == 0)
5200 return FALSE;
5201
5202 // See if it's already in the list
5203 if (FindSpecnameInList(name) >= 0)
5204 return TRUE;
5205
5206 // If there's room in the list, add the new name
5207 if (m_SpecnameListSize >= MAX_SPECNAMES)
5208 return FALSE;
5209
5210 int pos = m_SpecnameListSize;
5211 m_SpecnameList[pos] = (char *)mem_malloc(strlen(name) + 1);
5212 if (m_SpecnameList[pos] == NULL) {
5213 MessageBox("Out of memory in AddSpecnameToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
5214 return FALSE;
5215 }
5216 strcpy(m_SpecnameList[pos], name);
5217 m_SpecnameListSize++;
5218
5219 return TRUE;
5220 }
5221
5222 // Returns the list index of the given Specname name (or -1 if not found)
5223 int CDallasMainDlg::FindSpecnameInList(char *name) {
5224 if (name == NULL)
5225 return (-1);
5226
5227 for (int j = 0; j < m_SpecnameListSize; j++)
5228 if (strcmp(m_SpecnameList[j], name) == 0)
5229 return (j);
5230
5231 return (-1);
5232 }
5233
5234 // Adds the given Path name to the Path name list
5235 int CDallasMainDlg::AddPathToList(char *name) {
5236 // Make sure we've got a name
5237 if (name == NULL || strlen(name) == 0)
5238 return FALSE;
5239
5240 // See if it's already in the list
5241 if (FindPathInList(name) >= 0)
5242 return TRUE;
5243
5244 // If there's room in the list, add the new name
5245 if (m_PathListSize >= MAX_NAMED_PATHS)
5246 return FALSE;
5247
5248 int pos = m_PathListSize;
5249 m_PathList[pos] = (char *)mem_malloc(strlen(name) + 1);
5250 if (m_PathList[pos] == NULL) {
5251 MessageBox("Out of memory in AddPathToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
5252 return FALSE;
5253 }
5254 strcpy(m_PathList[pos], name);
5255 m_PathListSize++;
5256
5257 return TRUE;
5258 }
5259
5260 // Returns the list index of the given Path name (or -1 if not found)
5261 int CDallasMainDlg::FindPathInList(char *name) {
5262 if (name == NULL)
5263 return (-1);
5264
5265 for (int j = 0; j < m_PathListSize; j++)
5266 if (strcmp(m_PathList[j], name) == 0)
5267 return (j);
5268
5269 return (-1);
5270 }
5271
5272 // Adds the given Matcen name to the Matcen name list
5273 int CDallasMainDlg::AddMatcenToList(char *name) {
5274 // Make sure we've got a name
5275 if (name == NULL || strlen(name) == 0)
5276 return FALSE;
5277
5278 // See if it's already in the list
5279 if (FindMatcenInList(name) >= 0)
5280 return TRUE;
5281
5282 // If there's room in the list, add the new name
5283 if (m_MatcenListSize >= MAX_NAMED_MATCENS)
5284 return FALSE;
5285
5286 int pos = m_MatcenListSize;
5287 m_MatcenList[pos] = (char *)mem_malloc(strlen(name) + 1);
5288 if (m_MatcenList[pos] == NULL) {
5289 MessageBox("Out of memory in AddMatcenToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
5290 return FALSE;
5291 }
5292 strcpy(m_MatcenList[pos], name);
5293 m_MatcenListSize++;
5294
5295 return TRUE;
5296 }
5297
5298 // Returns the list index of the given Matcen name (or -1 if not found)
5299 int CDallasMainDlg::FindMatcenInList(char *name) {
5300 if (name == NULL)
5301 return (-1);
5302
5303 for (int j = 0; j < m_MatcenListSize; j++)
5304 if (strcmp(m_MatcenList[j], name) == 0)
5305 return (j);
5306
5307 return (-1);
5308 }
5309
5310 // Adds the given Goal name to the Goal name list
5311 int CDallasMainDlg::AddGoalToList(char *name) {
5312 // Make sure we've got a name
5313 if (name == NULL || strlen(name) == 0)
5314 return FALSE;
5315
5316 // See if it's already in the list
5317 if (FindGoalInList(name) >= 0)
5318 return TRUE;
5319
5320 // If there's room in the list, add the new name
5321 if (m_GoalListSize >= MAX_NAMED_GOALS)
5322 return FALSE;
5323
5324 int pos = m_GoalListSize;
5325 m_GoalList[pos] = (char *)mem_malloc(strlen(name) + 1);
5326 if (m_GoalList[pos] == NULL) {
5327 MessageBox("Out of memory in AddGoalToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
5328 return FALSE;
5329 }
5330 strcpy(m_GoalList[pos], name);
5331 m_GoalListSize++;
5332
5333 return TRUE;
5334 }
5335
5336 // Returns the list index of the given Goal name (or -1 if not found)
5337 int CDallasMainDlg::FindGoalInList(char *name) {
5338 if (name == NULL)
5339 return (-1);
5340
5341 for (int j = 0; j < m_GoalListSize; j++)
5342 if (strcmp(m_GoalList[j], name) == 0)
5343 return (j);
5344
5345 return (-1);
5346 }
5347
5348 // Adds the given StrmAudio name to the StrmAudio name list
5349 int CDallasMainDlg::AddStrmAudioToList(char *name) {
5350 // Make sure we've got a name
5351 if (name == NULL || strlen(name) == 0)
5352 return FALSE;
5353
5354 // See if it's already in the list
5355 if (FindStrmAudioInList(name) >= 0)
5356 return TRUE;
5357
5358 // If there's room in the list, add the new name
5359 if (m_StrmAudioListSize >= MAX_NAMED_STRM_AUDIO)
5360 return FALSE;
5361
5362 int pos = m_StrmAudioListSize;
5363 m_StrmAudioList[pos] = (char *)mem_malloc(strlen(name) + 1);
5364 if (m_StrmAudioList[pos] == NULL) {
5365 MessageBox("Out of memory in AddStrmAudioToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
5366 return FALSE;
5367 }
5368 strcpy(m_StrmAudioList[pos], name);
5369 m_StrmAudioListSize++;
5370
5371 return TRUE;
5372 }
5373
5374 // Returns the list index of the given StrmAudio name (or -1 if not found)
5375 int CDallasMainDlg::FindStrmAudioInList(char *name) {
5376 if (name == NULL)
5377 return (-1);
5378
5379 for (int j = 0; j < m_StrmAudioListSize; j++)
5380 if (strcmp(m_StrmAudioList[j], name) == 0)
5381 return (j);
5382
5383 return (-1);
5384 }
5385
5386 // Adds the given Message name to the Message name list
5387 int CDallasMainDlg::AddMessageNameToList(char *name) {
5388 // Make sure we've got a name
5389 if (name == NULL || strlen(name) == 0)
5390 return FALSE;
5391
5392 // See if it's already in the list
5393 if (FindMessageNameInList(name) >= 0)
5394 return TRUE;
5395
5396 // If there's room in the list, add the new name
5397 if (m_MessageNameListSize >= MAX_MESSAGE_LIST_ENTRIES)
5398 return FALSE;
5399
5400 int pos = m_MessageNameListSize;
5401 m_MessageNameList[pos] = (char *)mem_malloc(strlen(name) + 1);
5402 if (m_MessageNameList[pos] == NULL) {
5403 MessageBox("Out of memory in AddMessageNameToList()!", "Error!", MB_OK | MB_ICONEXCLAMATION);
5404 return FALSE;
5405 }
5406 strcpy(m_MessageNameList[pos], name);
5407 m_MessageNameListSize++;
5408
5409 return TRUE;
5410 }
5411
5412 // Returns the list index of the given MessageName name (or -1 if not found)
5413 int CDallasMainDlg::FindMessageNameInList(char *name) {
5414 if (name == NULL)
5415 return (-1);
5416
5417 for (int j = 0; j < m_MessageNameListSize; j++)
5418 if (strcmp(m_MessageNameList[j], name) == 0)
5419 return (j);
5420
5421 return (-1);
5422 }
5423
5424 /////////////////////////////////////////////////////////////////////////////
5425 // User Type Workshop Functions
5426 /////////////////////////////////////////////////////////////////////////////
5427
5428 // Fills drop down box with available user types
5429 int CDallasMainDlg::FillUserTypeBox(CComboBox *box) {
5430 int j, types_added;
5431
5432 types_added = 0;
5433
5434 // Clear the box
5435 box->ResetContent();
5436
5437 // Add the User Type Names
5438 for (j = 0; j < m_NumEnums; j++) {
5439 if (m_EnumDatabase[j].is_user_type) {
5440 box->AddString(m_EnumDatabase[j].name);
5441 types_added++;
5442 }
5443 }
5444
5445 // Select the first one
5446 box->SetCurSel(0);
5447
5448 return (types_added);
5449 }
5450
5451 // Fills the box with all values for the given User Type
5452 int CDallasMainDlg::FillValuesBox(CListBox *box, char *utype_name) {
5453 int j, DBslot, values_added;
5454
5455 values_added = 0;
5456
5457 // Clear the box
5458 box->ResetContent();
5459
5460 // Fill in the values
5461 DBslot = GetEnumID(utype_name);
5462 if (DBslot == INVALID_ENUM)
5463 return (values_added);
5464
5465 for (j = 0; j < m_EnumDatabase[DBslot].num_values; j++) {
5466 tEnumValueEntry *value_entry = &m_EnumDatabase[DBslot].values[j];
5467 if (value_entry->value != -1) {
5468 box->AddString(value_entry->name);
5469 values_added++;
5470 }
5471 }
5472
5473 // Select the first one
5474 box->SetCurSel(0);
5475
5476 return (values_added);
5477 }
5478
5479 // Adds a value to the user type
5480 // Returns the new position in list, or -1 if add failed
5481 int CDallasMainDlg::AddUserTypeValue(char *utype_name, char *value_name) {
5482 int j, k, DBslot, new_value;
5483
5484 if (utype_name == NULL || value_name == NULL)
5485 return (-1);
5486
5487 new_value = -1;
5488
5489 DBslot = GetEnumID(utype_name);
5490 if (DBslot == INVALID_ENUM)
5491 return (-1);
5492
5493 tEnumDBEntry *entry = &m_EnumDatabase[DBslot];
5494 if (entry->num_values >= (entry->max_values + 2) || entry->num_values >= MAX_ENUM_VALUES)
5495 return (-1);
5496
5497 // Find a place to insert the new value
5498 new_value = 0;
5499 for (j = 0; j < entry->num_values; j++) {
5500 tEnumValueEntry *value_entry = &entry->values[j];
5501 if (new_value < value_entry->value) {
5502 // Bump the higher ones down the list
5503 for (k = entry->num_values; k > j; k--) {
5504 entry->values[k].value = entry->values[k - 1].value;
5505 entry->values[k].name = entry->values[k - 1].name;
5506 }
5507 break;
5508 }
5509 new_value = value_entry->value + 1;
5510 }
5511
5512 // Store the new value at the current position
5513 tEnumValueEntry *value_entry = &entry->values[j];
5514 value_entry->value = new_value;
5515 value_entry->name = (char *)mem_malloc(strlen(value_name) + 1);
5516 if (value_entry->name == NULL) {
5517 MessageBox("ERROR: Out of mem in AddUserTypeValue()!", "Error!");
5518 return (-1);
5519 }
5520 strcpy(value_entry->name, value_name);
5521
5522 entry->num_values++;
5523
5524 SetModified(TRUE);
5525
5526 return (j);
5527 }
5528
5529 // Removes a value
5530 int CDallasMainDlg::DeleteUserTypeValue(char *utype_name, char *value_name) {
5531 int j, k, DBslot;
5532
5533 if (utype_name == NULL || value_name == NULL)
5534 return FALSE;
5535
5536 DBslot = GetEnumID(utype_name);
5537 if (DBslot == INVALID_ENUM)
5538 return FALSE;
5539
5540 tEnumDBEntry *entry = &m_EnumDatabase[DBslot];
5541
5542 // Find the value name in the list
5543 for (j = 0; j < entry->num_values; j++) {
5544 tEnumValueEntry *value_entry = &entry->values[j];
5545 if (strcmp(value_name, value_entry->name) == 0) {
5546 // Free the name memory
5547 mem_free(value_entry->name);
5548
5549 // Compact the list
5550 entry->num_values--;
5551 for (k = j; k < (entry->num_values); k++) {
5552 entry->values[k].value = entry->values[k + 1].value;
5553 entry->values[k].name = entry->values[k + 1].name;
5554 }
5555 entry->values[k].name = NULL;
5556 SetModified(TRUE);
5557 return TRUE;
5558 }
5559 }
5560
5561 return FALSE;
5562 }
5563
5564 // Changes the name of a value
5565 int CDallasMainDlg::ChangeValueName(char *utype_name, char *old_name, char *new_name) {
5566 int j, DBslot;
5567
5568 if (utype_name == NULL || old_name == NULL || new_name == NULL)
5569 return FALSE;
5570
5571 DBslot = GetEnumID(utype_name);
5572 if (DBslot == INVALID_ENUM)
5573 return FALSE;
5574
5575 tEnumDBEntry *entry = &m_EnumDatabase[DBslot];
5576
5577 // Find the value name in the list
5578 for (j = 0; j < entry->num_values; j++) {
5579 tEnumValueEntry *value_entry = &entry->values[j];
5580 if (strcmp(old_name, value_entry->name) == 0) {
5581 // Free the name memory
5582 mem_free(value_entry->name);
5583
5584 // Add the new name
5585 value_entry->name = (char *)mem_malloc(strlen(new_name) + 1);
5586 if (value_entry->name == NULL) {
5587 MessageBox("ERROR: Out of mem in ChangeValueName()!", "Error!");
5588 return FALSE;
5589 }
5590 strcpy(value_entry->name, new_name);
5591 SetModified(TRUE);
5592
5593 return TRUE;
5594 }
5595 }
5596
5597 return FALSE;
5598 }
5599
5600 /////////////////////////////////////////////////////////////////////////////
5601 // Enumeration Database Functions
5602 /////////////////////////////////////////////////////////////////////////////
5603
5604 // Initializes the enum DB for use
5605 void CDallasMainDlg::InitEnumDatabase(void) {
5606 int j, k;
5607
5608 for (j = 0; j < MAX_ENUMS; j++) {
5609 m_EnumDatabase[j].name = NULL;
5610 for (k = 0; k < MAX_ENUM_VALUES; k++) {
5611 m_EnumDatabase[j].values[k].name = NULL;
5612 m_EnumDatabase[j].values[k].value = 0;
5613 }
5614 m_EnumDatabase[j].num_values = 0;
5615 }
5616 m_NumEnums = 0;
5617 }
5618
5619 // Clears any allocated data for the enums
5620 void CDallasMainDlg::ClearEnumDatabase(void) {
5621 int j, k;
5622
5623 for (j = 0; j < m_NumEnums; j++) {
5624 if (m_EnumDatabase[j].name != NULL) {
5625 mem_free(m_EnumDatabase[j].name);
5626 m_EnumDatabase[j].name = NULL;
5627 }
5628 for (k = 0; k < m_EnumDatabase[j].num_values; k++) {
5629 if (m_EnumDatabase[j].values[k].name != NULL) {
5630 mem_free(m_EnumDatabase[j].values[k].name);
5631 m_EnumDatabase[j].values[k].name = NULL;
5632 }
5633 m_EnumDatabase[j].values[k].value = 0;
5634 }
5635 m_EnumDatabase[j].num_values = 0;
5636 }
5637 m_NumEnums = 0;
5638 }
5639
5640 // Returns the DB slot matching the given enum type name
5641 int CDallasMainDlg::GetEnumID(char *name) {
5642 int i;
5643
5644 if (name == NULL)
5645 return INVALID_ENUM;
5646
5647 for (i = 0; i < m_NumEnums; i++)
5648 if (strcmp(m_EnumDatabase[i].name, name) == 0)
5649 return i;
5650
5651 return INVALID_ENUM;
5652 }
5653
5654 // Returns the name bound to an enum value
5655 char *CDallasMainDlg::GetEnumValueName(char *name, int value) {
5656 int DBslot, j;
5657
5658 DBslot = GetEnumID(name);
5659 if (DBslot == INVALID_ENUM)
5660 return NULL;
5661
5662 for (j = 0; j < m_EnumDatabase[DBslot].num_values; j++)
5663 if (m_EnumDatabase[DBslot].values[j].value == value)
5664 return (m_EnumDatabase[DBslot].values[j].name);
5665
5666 return NULL;
5667 }
5668
5669 // Obtains the value bound to an enum value name,
5670 // Returns TRUE if value was found, FALSE otherwise
5671 bool CDallasMainDlg::GetEnumValue(char *name, char *value_name, int &value) {
5672 int DBslot, j;
5673
5674 DBslot = GetEnumID(name);
5675 if (DBslot == INVALID_ENUM)
5676 return FALSE;
5677
5678 for (j = 0; j < m_EnumDatabase[DBslot].num_values; j++)
5679 if (strcmp(m_EnumDatabase[DBslot].values[j].name, value_name) == 0) {
5680 value = m_EnumDatabase[DBslot].values[j].value;
5681 return TRUE;
5682 }
5683
5684 return FALSE;
5685 }
5686
5687 // Fills up the given menu with the available enumeration types
5688 // NOTE: Command ID's of objects items start at the given command_offset
5689 int CDallasMainDlg::FillEnumTypesMenu(CMenu *enum_menu, int command_offset, char *valid_name) {
5690 CString name;
5691 int enum_types_added;
5692 int i;
5693
5694 // Set the counts
5695 enum_types_added = 0;
5696
5697 // Fill the menu with names of matching enumeration values
5698 for (i = 0; i < m_NumEnums; i++) {
5699 name = m_EnumDatabase[i].name;
5700 if (m_EnumDatabase[i].is_user_type)
5701 name += " (USER TYPE)";
5702 if (strlen(valid_name) == 0 || strcmp(valid_name, m_EnumDatabase[i].name) == 0) {
5703 enum_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + i, name.GetBuffer(0));
5704 enum_types_added++;
5705 } else
5706 enum_menu->AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, command_offset + i, name.GetBuffer(0));
5707 }
5708
5709 return (enum_types_added);
5710 }
5711
5712 // Fills up the given menu with the enumeration values of the given enum name
5713 // NOTE: Command ID's of objects items start at the given command_offset
5714 int CDallasMainDlg::FillEnumValuesMenu(CMenu *enum_menu, int command_offset, char *enum_name) {
5715 int enum_values_added;
5716 int i, DBslot;
5717 tEnumDBEntry *enum_entry;
5718
5719 // Set the counts
5720 enum_values_added = 0;
5721
5722 // Find the correct enum database entry
5723 DBslot = GetEnumID(enum_name);
5724 if (DBslot == INVALID_ENUM)
5725 return 0;
5726
5727 enum_entry = &m_EnumDatabase[DBslot];
5728
5729 // Fill the menu with names of matching enumeration values
5730 for (i = 0; i < enum_entry->num_values; i++) {
5731 enum_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + i, enum_entry->values[i].name);
5732 enum_values_added++;
5733 }
5734
5735 return (enum_values_added);
5736 }
5737
5738 /////////////////////////////////////////////////////////////////////////////
5739 // Flag Database Functions
5740 /////////////////////////////////////////////////////////////////////////////
5741
5742 // Initializes the Flag DB for use
5743 void CDallasMainDlg::InitFlagDatabase(void) {
5744 int j, k;
5745
5746 for (j = 0; j < MAX_FLAGS; j++) {
5747 m_FlagDatabase[j].name = NULL;
5748 for (k = 0; k < MAX_FLAG_VALUES; k++) {
5749 m_FlagDatabase[j].values[k].name = NULL;
5750 m_FlagDatabase[j].values[k].value = 0;
5751 }
5752 m_FlagDatabase[j].num_values = 0;
5753 }
5754 m_NumFlags = 0;
5755 }
5756
5757 // Clears any allocated data for the Flags
5758 void CDallasMainDlg::ClearFlagDatabase(void) {
5759 int j, k;
5760
5761 for (j = 0; j < m_NumFlags; j++) {
5762 if (m_FlagDatabase[j].name != NULL) {
5763 mem_free(m_FlagDatabase[j].name);
5764 m_FlagDatabase[j].name = NULL;
5765 }
5766 for (k = 0; k < m_FlagDatabase[j].num_values; k++) {
5767 if (m_FlagDatabase[j].values[k].name != NULL) {
5768 mem_free(m_FlagDatabase[j].values[k].name);
5769 m_FlagDatabase[j].values[k].name = NULL;
5770 }
5771 m_FlagDatabase[j].values[k].value = 0;
5772 }
5773 m_FlagDatabase[j].num_values = 0;
5774 }
5775 m_NumFlags = 0;
5776 }
5777
5778 // Returns the DB slot matching the given Flag type name
5779 int CDallasMainDlg::GetFlagID(char *name) {
5780 int i;
5781
5782 if (name == NULL)
5783 return INVALID_FLAG;
5784
5785 for (i = 0; i < m_NumFlags; i++)
5786 if (strcmp(m_FlagDatabase[i].name, name) == 0)
5787 return i;
5788
5789 return INVALID_FLAG;
5790 }
5791
5792 // Returns the name bound to an flag value
5793 char *CDallasMainDlg::GetFlagValueName(char *name, int value) {
5794 int DBslot, j;
5795
5796 DBslot = GetFlagID(name);
5797 if (DBslot == INVALID_FLAG)
5798 return NULL;
5799
5800 for (j = 0; j < m_FlagDatabase[DBslot].num_values; j++)
5801 if (m_FlagDatabase[DBslot].values[j].value == value)
5802 return (m_FlagDatabase[DBslot].values[j].name);
5803
5804 return NULL;
5805 }
5806
5807 // Returns the name bound to an Flag value
5808 bool CDallasMainDlg::FormatFlagValueNames(char *name, int value, CString &text) {
5809 int DBslot, j;
5810 bool first_added;
5811
5812 DBslot = GetFlagID(name);
5813 if (DBslot == INVALID_FLAG)
5814 return FALSE;
5815
5816 first_added = TRUE;
5817 text = "";
5818 for (j = 0; j < m_FlagDatabase[DBslot].num_values; j++) {
5819 if (m_FlagDatabase[DBslot].values[j].value & value) {
5820 if (!first_added)
5821 text += ",";
5822 else {
5823 text += '[';
5824 first_added = FALSE;
5825 }
5826 text += m_FlagDatabase[DBslot].values[j].name;
5827 }
5828 }
5829
5830 if (text.IsEmpty())
5831 text = "[NO FLAGS SET]";
5832 else
5833 text += ']';
5834
5835 return TRUE;
5836 }
5837
5838 // Obtains the value bound to an Flag value name,
5839 // Returns TRUE if value was found, FALSE otherwise
5840 bool CDallasMainDlg::GetFlagValue(char *name, char *value_name, int &value) {
5841 int DBslot, j;
5842
5843 DBslot = GetFlagID(name);
5844 if (DBslot == INVALID_FLAG)
5845 return FALSE;
5846
5847 for (j = 0; j < m_FlagDatabase[DBslot].num_values; j++)
5848 if (strcmp(m_FlagDatabase[DBslot].values[j].name, value_name) == 0) {
5849 value = m_FlagDatabase[DBslot].values[j].value;
5850 return TRUE;
5851 }
5852
5853 return FALSE;
5854 }
5855
5856 // Fills up the given menu with the available flag types
5857 // NOTE: Command ID's of objects items start at the given command_offset
5858 int CDallasMainDlg::FillFlagTypesMenu(CMenu *flag_menu, int command_offset, char *valid_name) {
5859 int flag_types_added;
5860 int i;
5861
5862 // Set the counts
5863 flag_types_added = 0;
5864
5865 // Fill the menu with names of matching Flageration values
5866 for (i = 0; i < m_NumFlags; i++) {
5867 if (strlen(valid_name) == 0 || strcmp(valid_name, m_FlagDatabase[i].name) == 0) {
5868 flag_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + i, m_FlagDatabase[i].name);
5869 flag_types_added++;
5870 } else
5871 flag_menu->AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, command_offset + i, m_FlagDatabase[i].name);
5872 }
5873
5874 return (flag_types_added);
5875 }
5876
5877 // Fills up the given CCheckListBox with the flag values of the given flag name
5878 int CDallasMainDlg::FillFlagValuesBox(CCheckListBox *box, char *flag_name, int flags_value, int valid_flags_mask) {
5879 int flag_values_added;
5880 int i, DBslot;
5881 tFlagDBEntry *flag_entry;
5882
5883 // Set the counts
5884 flag_values_added = 0;
5885
5886 // Find the correct enum database entry
5887 DBslot = GetFlagID(flag_name);
5888 if (DBslot == INVALID_FLAG)
5889 return 0;
5890
5891 flag_entry = &m_FlagDatabase[DBslot];
5892
5893 // Fill the box with names of matching flag values
5894 for (i = 0; i < flag_entry->num_values; i++) {
5895 if (valid_flags_mask == 0 || (flag_entry->values[i].value & valid_flags_mask)) {
5896 int index;
5897 index = box->AddString(flag_entry->values[i].name);
5898 if (index != LB_ERR) {
5899 box->SetItemData(index, flag_entry->values[i].value);
5900 if (flag_entry->values[i].value & flags_value)
5901 box->SetCheck(index, 1);
5902 else
5903 box->SetCheck(index, 0);
5904
5905 /* In case you just wanna dim the invalid flags
5906 if(valid_flags_mask==0 || (flag_entry->values[i].value & valid_flags_mask))
5907 box->Enable(index,TRUE);
5908 else
5909 box->Enable(index,FALSE);
5910 */
5911 }
5912 flag_values_added++;
5913 }
5914 }
5915
5916 return (flag_values_added);
5917 }
5918
5919 /////////////////////////////////////////////////////////////////////////////
5920 // Action and Query Database Functions
5921 /////////////////////////////////////////////////////////////////////////////
5922
5923 // Initialize the Database Arrays
5924 void CDallasMainDlg::InitFunctionDatabases(void) {
5925 int j;
5926
5927 for (j = 0; j < MAX_CATEGORIES; j++)
5928 m_FunctionCategories[j] = NULL;
5929 m_NumFunctionCategories = 0;
5930
5931 for (j = 0; j < MAX_ACTIONS; j++) {
5932 m_ActionDatabase[j].category = INVALID_CATEGORY;
5933 m_ActionDatabase[j].desc = NULL;
5934 m_ActionDatabase[j].func = NULL;
5935 m_ActionDatabase[j].help = NULL;
5936 }
5937 m_NumActions = 0;
5938
5939 for (j = 0; j < MAX_QUERIES; j++) {
5940 m_QueryDatabase[j].category = INVALID_CATEGORY;
5941 m_QueryDatabase[j].desc = NULL;
5942 m_QueryDatabase[j].func = NULL;
5943 m_QueryDatabase[j].help = NULL;
5944 }
5945 m_NumQueries = 0;
5946 }
5947
5948 // Frees up any allocated memory
5949 void CDallasMainDlg::ClearFunctionDatabases(void) {
5950 int j;
5951
5952 for (j = 0; j < m_NumFunctionCategories; j++)
5953 mem_free(m_FunctionCategories[j]);
5954 m_NumFunctionCategories = 0;
5955
5956 for (j = 0; j < m_NumActions; j++) {
5957 m_ActionDatabase[j].category = INVALID_CATEGORY;
5958 mem_free(m_ActionDatabase[j].desc);
5959 m_ActionDatabase[j].desc = NULL;
5960 mem_free(m_ActionDatabase[j].func);
5961 m_ActionDatabase[j].func = NULL;
5962 mem_free(m_ActionDatabase[j].help);
5963 m_ActionDatabase[j].help = NULL;
5964 }
5965 m_NumActions = 0;
5966
5967 for (j = 0; j < m_NumQueries; j++) {
5968 m_QueryDatabase[j].category = INVALID_CATEGORY;
5969 mem_free(m_QueryDatabase[j].desc);
5970 m_QueryDatabase[j].desc = NULL;
5971 mem_free(m_QueryDatabase[j].func);
5972 m_QueryDatabase[j].func = NULL;
5973 mem_free(m_QueryDatabase[j].help);
5974 m_QueryDatabase[j].help = NULL;
5975 }
5976 m_NumQueries = 0;
5977 }
5978
5979 // Matches an integer ID to a given category name
5980 int CDallasMainDlg::GetFunctionCategoryID(char *catname) {
5981 for (int i = 0; i < m_NumFunctionCategories; i++)
5982 if (strcmp(m_FunctionCategories[i], catname) == 0)
5983 return i;
5984
5985 return INVALID_CATEGORY;
5986 }
5987
5988 // Handle Parse Errors
5989 void CDallasMainDlg::FunctionFileParseError(int error_code, int linenum, const char *filename) {
5990 CString err_msg;
5991
5992 switch (error_code) {
5993 case INV_CAT_ERR:
5994 err_msg.Format("ERROR: Invalid category assigned in %s, line %d.", filename, linenum);
5995 break;
5996 case INV_ENUM_ERR:
5997 err_msg.Format("ERROR: Invalid or duplicate enumeration name assigned in %s, line %d.", filename, linenum);
5998 break;
5999 case INV_ENUM_VALUE_ERR:
6000 err_msg.Format("ERROR: Invalid or duplicate enumeration value assigned in %s, line %d.", filename, linenum);
6001 break;
6002 case MAX_ENUM_ERR:
6003 err_msg.Format("ERROR: Maximum enumeration limit reached in %s, line %d.", filename, linenum);
6004 break;
6005 case MAX_ENUM_VALUES_ERR:
6006 err_msg.Format("ERROR: Maximum enumeration value limit reached in %s, line %d.", filename, linenum);
6007 break;
6008 case INV_FLAG_ERR:
6009 err_msg.Format("ERROR: Invalid or duplicate flag name assigned in %s, line %d.", filename, linenum);
6010 break;
6011 case INV_FLAG_VALUE_ERR:
6012 err_msg.Format("ERROR: Invalid or duplicate flag value assigned in %s, line %d.", filename, linenum);
6013 break;
6014 case MAX_FLAG_ERR:
6015 err_msg.Format("ERROR: Maximum flag limit reached in %s, line %d.", filename, linenum);
6016 break;
6017 case MAX_FLAG_VALUES_ERR:
6018 err_msg.Format("ERROR: Maximum flag value limit reached in %s, line %d.", filename, linenum);
6019 break;
6020 case NO_MEM_ERR:
6021 err_msg.Format("ERROR: Ran out of memory while parsing %s, line %d.", filename, linenum);
6022 break;
6023 case UEOF_ERR:
6024 err_msg.Format("ERROR: Unexpected end of file while parsing %s, line %d.", filename, linenum);
6025 break;
6026 default:
6027 err_msg.Format("ERROR: An unknown error was detected in %s, line %d.", filename, linenum);
6028 break;
6029 }
6030
6031 MessageBox(err_msg, "Function Database Parse Error", MB_OK | MB_ICONEXCLAMATION);
6032 }
6033
6034 // Returns a pointer to the action description
6035 char *CDallasMainDlg::GetActionDesc(int ID) {
6036 if (ID < 0 || ID >= m_NumActions)
6037 return NULL;
6038
6039 return (m_ActionDatabase[ID].desc);
6040 }
6041
6042 // Returns a pointer to the action help text
6043 char *CDallasMainDlg::GetActionHelp(int ID) {
6044 if (ID < 0 || ID >= m_NumActions)
6045 return NULL;
6046
6047 return (m_ActionDatabase[ID].help);
6048 }
6049
6050 // Returns a pointer to the action function name
6051 char *CDallasMainDlg::GetActionFunc(int ID) {
6052 if (ID == DO_NOTHING_ID)
6053 return DO_NOTHING_STRING;
6054
6055 if (ID < 0 || ID >= m_NumActions)
6056 return INVALID_FUNCTION_NAME;
6057
6058 return (m_ActionDatabase[ID].func);
6059 }
6060
6061 // Searches action list for action matching given function name
6062 int CDallasMainDlg::GetActionFuncID(char *func_name) {
6063 if (func_name == NULL)
6064 return INVALID_FUNCTION_ID;
6065
6066 if (strcmp(DO_NOTHING_STRING, func_name) == 0)
6067 return DO_NOTHING_ID;
6068
6069 for (int j = 0; j < m_NumActions; j++)
6070 if (strcmp(m_ActionDatabase[j].func, func_name) == 0)
6071 return (j);
6072
6073 return INVALID_FUNCTION_ID;
6074 }
6075
6076 // Returns a pointer to the query description
6077 char *CDallasMainDlg::GetQueryDesc(int ID) {
6078 if (ID < 0 || ID >= m_NumQueries)
6079 return NULL;
6080
6081 return (m_QueryDatabase[ID].desc);
6082 }
6083
6084 // Returns a pointer to the query help text
6085 char *CDallasMainDlg::GetQueryHelp(int ID) {
6086 if (ID < 0 || ID >= m_NumQueries)
6087 return NULL;
6088
6089 return (m_QueryDatabase[ID].help);
6090 }
6091
6092 // Returns a pointer to the query function name
6093 char *CDallasMainDlg::GetQueryFunc(int ID) {
6094 if (ID < 0 || ID >= m_NumQueries)
6095 return INVALID_FUNCTION_NAME;
6096
6097 return (m_QueryDatabase[ID].func);
6098 }
6099
6100 // Searches query list for query matching given function name
6101 int CDallasMainDlg::GetQueryFuncID(char *func_name) {
6102 if (func_name == NULL)
6103 return INVALID_FUNCTION_ID;
6104
6105 for (int j = 0; j < m_NumQueries; j++)
6106 if (strcmp(m_QueryDatabase[j].func, func_name) == 0)
6107 return (j);
6108
6109 return INVALID_FUNCTION_ID;
6110 }
6111
6112 // Returns the Query's return type (parameter type), or UNKNOWN_PARAMETER_TYPE
6113 int CDallasMainDlg::GetQueryReturnType(int ID, CString &name) {
6114 char *desc;
6115 int type;
6116
6117 name = "";
6118 desc = GetQueryDesc(ID);
6119 if (desc == NULL)
6120 return (UNKNOWN_PARAMETER_TYPE);
6121
6122 if (!isalpha(desc[0]))
6123 return (UNKNOWN_PARAMETER_TYPE);
6124 type = ConvertParamCharToType(desc[0]);
6125
6126 if (type != ENUM_PARAMETER_TYPE && type != FLAG_PARAMETER_TYPE) {
6127 if (desc[1] != ':')
6128 return (UNKNOWN_PARAMETER_TYPE);
6129 return (type);
6130 }
6131
6132 // If it's an enum or flag, we need to get the name of the enum/flag type as well
6133 if (desc[1] == '(')
6134 for (int j = 2; (desc[j] != '\0' && desc[j] != ')'); j++)
6135 name += desc[j];
6136
6137 return (type);
6138 }
6139
6140 // Parses the given text file, adding categories, actions, and queries, as it finds them
6141 void CDallasMainDlg::ParseFunctionFile(char *filename, bool show_errors /*=TRUE*/) {
6142 CFILE *ifile;
6143 char linebuf[2048];
6144 char *line;
6145 char helpbuf[2048];
6146 int linenum;
6147 char fullpath[_MAX_PATH];
6148
6149 ddio_MakePath(fullpath, LocalScriptDir, filename, NULL);
6150
6151 ifile = cfopen(fullpath, "rt");
6152 if (ifile == NULL) {
6153 if (show_errors) {
6154 CString msg;
6155 msg.Format("Unable to open \"%s\"!", filename);
6156 MessageBox(msg, "No Function Database Found!", MB_OK | MB_ICONEXCLAMATION);
6157 }
6158 return;
6159 }
6160
6161 linenum = 0;
6162
6163 while (!cfeof(ifile)) {
6164
6165 cf_ReadString(linebuf, sizeof(linebuf), ifile);
6166 linenum++;
6167
6168 // Remove whitespace padding at start and end of line
6169 RemoveTrailingWhitespace(linebuf);
6170 line = SkipInitialWhitespace(linebuf);
6171
6172 if (strncmp(line, TAG_CAT, strlen(TAG_CAT)) == 0) { // parse a category block
6173 bool done = 0;
6174
6175 do {
6176
6177 cf_ReadString(linebuf, sizeof(linebuf), ifile);
6178 linenum++;
6179
6180 // Remove whitespace padding at start and end of line
6181 RemoveTrailingWhitespace(linebuf);
6182 line = SkipInitialWhitespace(linebuf);
6183
6184 if (strncmp(line, TAG_END, strlen(TAG_END)) == 0)
6185 done = 1;
6186 else if (m_NumFunctionCategories < MAX_CATEGORIES) {
6187 if (GetFunctionCategoryID(line) == INVALID_CATEGORY) { // don't add duplicate categories
6188 m_FunctionCategories[m_NumFunctionCategories] = (char *)mem_malloc(strlen(line) + 1);
6189 if (m_FunctionCategories[m_NumFunctionCategories] == NULL) {
6190 FunctionFileParseError(NO_MEM_ERR, linenum, filename);
6191 cfclose(ifile);
6192 return;
6193 }
6194 strcpy(m_FunctionCategories[m_NumFunctionCategories], line);
6195 m_NumFunctionCategories++;
6196 if (m_NumFunctionCategories == MAX_CATEGORIES)
6197 MessageBox("Warning: The Maximum Category limit has been reached!", "Warning!");
6198 }
6199 }
6200
6201 } while (!done && !cfeof(ifile));
6202
6203 if (!done)
6204 FunctionFileParseError(UEOF_ERR, linenum, filename);
6205 } else if (strncmp(line, TAG_USERTYPE, strlen(TAG_USERTYPE)) == 0) { // Parse a user type line
6206 tEnumDBEntry *enum_entry;
6207 char *enum_name;
6208 char *max_value_text;
6209
6210 // Strip off the name of this user type
6211 max_value_text = NULL;
6212 enum_name = strtok(line, WHITESPACE_CHARS);
6213 if (enum_name != NULL)
6214 enum_name = strtok(NULL, ":");
6215 if (enum_name != NULL)
6216 max_value_text = strtok(NULL, "");
6217 if (enum_name == NULL || max_value_text == NULL || GetEnumID(enum_name) != INVALID_ENUM) {
6218 FunctionFileParseError(INV_ENUM_ERR, linenum, filename);
6219 enum_entry = NULL;
6220 } else if (m_NumEnums == MAX_ENUMS) {
6221 FunctionFileParseError(MAX_ENUM_ERR, linenum, filename);
6222 enum_entry = NULL;
6223 } else {
6224 enum_entry = &m_EnumDatabase[m_NumEnums++];
6225 enum_entry->name = (char *)mem_malloc(strlen(enum_name) + 1);
6226 if (enum_entry->name == NULL) {
6227 FunctionFileParseError(NO_MEM_ERR, linenum, filename);
6228 cfclose(ifile);
6229 return;
6230 }
6231 strcpy(enum_entry->name, enum_name);
6232 enum_entry->num_values = 0;
6233 enum_entry->is_user_type = TRUE;
6234 enum_entry->max_values = atoi(max_value_text);
6235 if (enum_entry->max_values < 0)
6236 enum_entry->max_values = 0;
6237 if (enum_entry->max_values > (MAX_ENUMS - 2))
6238 enum_entry->max_values = (MAX_ENUMS - 2);
6239
6240 // Add the default (-1:None) value
6241 tEnumValueEntry *value_entry;
6242 value_entry = &enum_entry->values[enum_entry->num_values++];
6243 value_entry->name = (char *)mem_malloc(strlen(USERTYPE_NONE) + 1);
6244 if (value_entry->name == NULL) {
6245 FunctionFileParseError(NO_MEM_ERR, linenum, filename);
6246 cfclose(ifile);
6247 return;
6248 }
6249 strcpy(value_entry->name, USERTYPE_NONE);
6250 value_entry->value = -1;
6251 }
6252 } else if (strncmp(line, TAG_ENUM, strlen(TAG_ENUM)) == 0) { // Parse an enumeration block
6253 tEnumDBEntry *enum_entry;
6254 char *enum_name;
6255 bool done;
6256
6257 // Strip off the name of this enumeration type
6258 enum_name = strtok(line, WHITESPACE_CHARS);
6259 if (enum_name != NULL)
6260 enum_name = strtok(NULL, "");
6261 if (enum_name == NULL || GetEnumID(enum_name) != INVALID_ENUM) {
6262 FunctionFileParseError(INV_ENUM_ERR, linenum, filename);
6263 enum_entry = NULL;
6264 } else if (m_NumEnums == MAX_ENUMS) {
6265 FunctionFileParseError(MAX_ENUM_ERR, linenum, filename);
6266 enum_entry = NULL;
6267 } else {
6268 enum_entry = &m_EnumDatabase[m_NumEnums++];
6269 enum_entry->name = (char *)mem_malloc(strlen(enum_name) + 1);
6270 if (enum_entry->name == NULL) {
6271 FunctionFileParseError(NO_MEM_ERR, linenum, filename);
6272 cfclose(ifile);
6273 return;
6274 }
6275 strcpy(enum_entry->name, enum_name);
6276 enum_entry->num_values = 0;
6277 enum_entry->is_user_type = FALSE;
6278 enum_entry->max_values = 0;
6279 }
6280
6281 // Parse the enumeration values for this entry
6282 done = 0;
6283 do {
6284
6285 cf_ReadString(linebuf, sizeof(linebuf), ifile);
6286 linenum++;
6287
6288 // Remove whitespace padding at start and end of line
6289 RemoveTrailingWhitespace(linebuf);
6290 line = SkipInitialWhitespace(linebuf);
6291
6292 if (strncmp(line, TAG_END, strlen(TAG_END)) == 0)
6293 done = 1;
6294 else if (enum_entry != NULL) {
6295 tEnumValueEntry *value_entry;
6296 int enum_value;
6297 char *enum_value_string;
6298 char *enum_value_name;
6299
6300 // Parse out the enum value and value name
6301 enum_value_string = strtok(line, ":");
6302 if (enum_value_string != NULL) {
6303 enum_value = atoi(enum_value_string);
6304 enum_value_name = strtok(NULL, "");
6305 }
6306
6307 if (enum_value_string == NULL || enum_value_name == NULL ||
6308 GetEnumValueName(enum_entry->name, enum_value) != NULL) {
6309 FunctionFileParseError(INV_ENUM_VALUE_ERR, linenum, filename);
6310 value_entry = NULL;
6311 } else if (enum_entry->num_values == MAX_ENUM_VALUES) {
6312 FunctionFileParseError(MAX_ENUM_VALUES_ERR, linenum, filename);
6313 value_entry = NULL;
6314 } else {
6315 value_entry = &enum_entry->values[enum_entry->num_values++];
6316 value_entry->name = (char *)mem_malloc(strlen(enum_value_name) + 1);
6317 if (value_entry->name == NULL) {
6318 FunctionFileParseError(NO_MEM_ERR, linenum, filename);
6319 cfclose(ifile);
6320 return;
6321 }
6322 strcpy(value_entry->name, enum_value_name);
6323 value_entry->value = enum_value;
6324 }
6325 }
6326
6327 } while (!done && !cfeof(ifile));
6328
6329 if (!done)
6330 FunctionFileParseError(UEOF_ERR, linenum, filename);
6331 } else if (strncmp(line, TAG_FLAG, strlen(TAG_FLAG)) == 0) { // Parse a flag block
6332 tFlagDBEntry *flag_entry;
6333 char *flag_name;
6334 bool done;
6335
6336 // Strip off the name of this flag type
6337 flag_name = strtok(line, WHITESPACE_CHARS);
6338 if (flag_name != NULL)
6339 flag_name = strtok(NULL, "");
6340 if (flag_name == NULL || GetFlagID(flag_name) != INVALID_FLAG) {
6341 FunctionFileParseError(INV_FLAG_ERR, linenum, filename);
6342 flag_entry = NULL;
6343 } else if (m_NumFlags == MAX_FLAGS) {
6344 FunctionFileParseError(MAX_FLAG_ERR, linenum, filename);
6345 flag_entry = NULL;
6346 } else {
6347 flag_entry = &m_FlagDatabase[m_NumFlags++];
6348 flag_entry->name = (char *)mem_malloc(strlen(flag_name) + 1);
6349 if (flag_entry->name == NULL) {
6350 FunctionFileParseError(NO_MEM_ERR, linenum, filename);
6351 cfclose(ifile);
6352 return;
6353 }
6354 strcpy(flag_entry->name, flag_name);
6355 flag_entry->num_values = 0;
6356 }
6357
6358 // Parse the flag values for this entry
6359 done = 0;
6360 do {
6361
6362 cf_ReadString(linebuf, sizeof(linebuf), ifile);
6363 linenum++;
6364
6365 // Remove whitespace padding at start and end of line
6366 RemoveTrailingWhitespace(linebuf);
6367 line = SkipInitialWhitespace(linebuf);
6368
6369 if (strncmp(line, TAG_END, strlen(TAG_END)) == 0)
6370 done = 1;
6371 else if (flag_entry != NULL) {
6372 tFlagValueEntry *value_entry;
6373 int flag_value;
6374 char *flag_value_string;
6375 char *flag_value_name;
6376
6377 // Parse out the flag value and value name
6378 flag_value_string = strtok(line, ":");
6379 if (flag_value_string != NULL) {
6380 flag_value = atoi(flag_value_string);
6381 flag_value_name = strtok(NULL, "");
6382 }
6383
6384 if (flag_value_string == NULL || flag_value_name == NULL ||
6385 GetFlagValueName(flag_entry->name, flag_value) != NULL) {
6386 FunctionFileParseError(INV_FLAG_VALUE_ERR, linenum, filename);
6387 value_entry = NULL;
6388 } else if (flag_entry->num_values == MAX_FLAG_VALUES) {
6389 FunctionFileParseError(MAX_FLAG_VALUES_ERR, linenum, filename);
6390 value_entry = NULL;
6391 } else {
6392 value_entry = &flag_entry->values[flag_entry->num_values++];
6393 value_entry->name = (char *)mem_malloc(strlen(flag_value_name) + 1);
6394 if (value_entry->name == NULL) {
6395 FunctionFileParseError(NO_MEM_ERR, linenum, filename);
6396 cfclose(ifile);
6397 return;
6398 }
6399 strcpy(value_entry->name, flag_value_name);
6400 value_entry->value = flag_value;
6401 }
6402 }
6403
6404 } while (!done && !cfeof(ifile));
6405
6406 if (!done)
6407 FunctionFileParseError(UEOF_ERR, linenum, filename);
6408 } else if (strncmp(line, TAG_ACTION, strlen(TAG_ACTION)) == 0) { // Parse action block
6409 if (m_NumActions >= MAX_ACTIONS) {
6410 MessageBox("ERROR: The Maximum Action limit has been exceeded!\n\nParsing must stop immediately.", "ERROR!");
6411 cfclose(ifile);
6412 return;
6413 }
6414 tActionDBEntry *action = &m_ActionDatabase[m_NumActions++];
6415 if (m_NumActions == MAX_ACTIONS) {
6416 MessageBox("Warning: The Maximum Action limit has been reached!", "Warning!");
6417 }
6418
6419 // Read category
6420 cf_ReadString(linebuf, sizeof(linebuf), ifile);
6421 linenum++;
6422
6423 // Remove whitespace padding at start and end of line
6424 RemoveTrailingWhitespace(linebuf);
6425 line = SkipInitialWhitespace(linebuf);
6426
6427 action->category = GetFunctionCategoryID(line);
6428 if (action->category == INVALID_CATEGORY) {
6429 FunctionFileParseError(INV_CAT_ERR, linenum, filename);
6430 cfclose(ifile);
6431 return;
6432 }
6433
6434 // Read action description
6435 cf_ReadString(linebuf, sizeof(linebuf), ifile);
6436 linenum++;
6437
6438 // Remove whitespace padding at start and end of line
6439 RemoveTrailingWhitespace(linebuf);
6440 line = SkipInitialWhitespace(linebuf);
6441
6442 action->desc = (char *)mem_malloc(strlen(line) + 1);
6443 if (action->desc == NULL) {
6444 FunctionFileParseError(NO_MEM_ERR, linenum, filename);
6445 cfclose(ifile);
6446 return;
6447 }
6448 strcpy(action->desc, line);
6449
6450 // Read action function
6451 cf_ReadString(linebuf, sizeof(linebuf), ifile);
6452 linenum++;
6453
6454 // Remove whitespace padding at start and end of line
6455 RemoveTrailingWhitespace(linebuf);
6456 line = SkipInitialWhitespace(linebuf);
6457
6458 action->func = (char *)mem_malloc(strlen(line) + 1);
6459 if (action->func == NULL) {
6460 FunctionFileParseError(NO_MEM_ERR, linenum, filename);
6461 cfclose(ifile);
6462 return;
6463 }
6464 strcpy(action->func, line);
6465
6466 // Read help
6467 bool done = 0;
6468 helpbuf[0] = 0;
6469 do {
6470
6471 cf_ReadString(linebuf, sizeof(linebuf), ifile);
6472 linenum++;
6473
6474 // Remove whitespace padding at start and end of line
6475 RemoveTrailingWhitespace(linebuf);
6476 line = SkipInitialWhitespace(linebuf);
6477
6478 if (strncmp(line, TAG_END, strlen(TAG_END)) == 0)
6479 done = 1;
6480 else {
6481 strcat(helpbuf, line);
6482 strcat(helpbuf, "\r\n");
6483 }
6484
6485 } while (!done && !cfeof(ifile));
6486
6487 if (!done)
6488 FunctionFileParseError(UEOF_ERR, linenum, filename);
6489
6490 action->help = (char *)mem_malloc(strlen(helpbuf) + 1);
6491 if (action->help == NULL) {
6492 FunctionFileParseError(NO_MEM_ERR, linenum, filename);
6493 cfclose(ifile);
6494 return;
6495 }
6496 strcpy(action->help, helpbuf);
6497 } else if (strncmp(line, TAG_QUERY, strlen(TAG_QUERY)) == 0) { // Parse Query block
6498 if (m_NumQueries >= MAX_QUERIES) {
6499 MessageBox("ERROR: The Maximum Query limit has been exceeded!\n\nParsing must stop immediately.", "ERROR!");
6500 cfclose(ifile);
6501 return;
6502 }
6503 tQueryDBEntry *query = &m_QueryDatabase[m_NumQueries++];
6504 if (m_NumQueries == MAX_QUERIES) {
6505 MessageBox("Warning: The Maximum Query limit has been reached!", "Warning!");
6506 }
6507
6508 // Read category
6509 cf_ReadString(linebuf, sizeof(linebuf), ifile);
6510 linenum++;
6511
6512 // Remove whitespace padding at start and end of line
6513 RemoveTrailingWhitespace(linebuf);
6514 line = SkipInitialWhitespace(linebuf);
6515
6516 query->category = GetFunctionCategoryID(line);
6517 if (query->category == INVALID_CATEGORY) {
6518 FunctionFileParseError(INV_CAT_ERR, linenum, filename);
6519 cfclose(ifile);
6520 return;
6521 }
6522
6523 // Read action description
6524 cf_ReadString(linebuf, sizeof(linebuf), ifile);
6525 linenum++;
6526
6527 // Remove whitespace padding at start and end of line
6528 RemoveTrailingWhitespace(linebuf);
6529 line = SkipInitialWhitespace(linebuf);
6530
6531 query->desc = (char *)mem_malloc(strlen(line) + 1);
6532 if (query->desc == NULL) {
6533 FunctionFileParseError(NO_MEM_ERR, linenum, filename);
6534 cfclose(ifile);
6535 return;
6536 }
6537 strcpy(query->desc, line);
6538
6539 // Read action function
6540 cf_ReadString(linebuf, sizeof(linebuf), ifile);
6541 linenum++;
6542
6543 // Remove whitespace padding at start and end of line
6544 RemoveTrailingWhitespace(linebuf);
6545 line = SkipInitialWhitespace(linebuf);
6546
6547 query->func = (char *)mem_malloc(strlen(line) + 1);
6548 if (query->func == NULL) {
6549 FunctionFileParseError(NO_MEM_ERR, linenum, filename);
6550 cfclose(ifile);
6551 return;
6552 }
6553 strcpy(query->func, line);
6554
6555 // Read help
6556 bool done = 0;
6557 helpbuf[0] = 0;
6558 do {
6559
6560 cf_ReadString(linebuf, sizeof(linebuf), ifile);
6561 linenum++;
6562
6563 // Remove whitespace padding at start and end of line
6564 RemoveTrailingWhitespace(linebuf);
6565 line = SkipInitialWhitespace(linebuf);
6566
6567 if (strncmp(line, TAG_END, strlen(TAG_END)) == 0)
6568 done = 1;
6569 else {
6570 strcat(helpbuf, line);
6571 strcat(helpbuf, "\r\n");
6572 }
6573
6574 } while (!done && !cfeof(ifile));
6575
6576 if (!done)
6577 FunctionFileParseError(UEOF_ERR, linenum, filename);
6578
6579 query->help = (char *)mem_malloc(strlen(helpbuf) + 1);
6580 if (query->help == NULL) {
6581 FunctionFileParseError(NO_MEM_ERR, linenum, filename);
6582 cfclose(ifile);
6583 return;
6584 }
6585 strcpy(query->help, helpbuf);
6586 }
6587 }
6588
6589 cfclose(ifile);
6590 }
6591
6592 // Returns a description copy with the parameter type info removed
6593 void CDallasMainDlg::ParseOutActionVarTypes(char *new_desc, char *old_desc) {
6594 CString name_text, default_text, range_text;
6595 CString new_desc_text;
6596
6597 new_desc_text = "";
6598 while ((*old_desc) != '\0') {
6599
6600 // If it's start of a param block, extract the param name
6601 if ((*old_desc) == '[') {
6602 ParseParamBlock(old_desc, name_text, default_text, range_text);
6603 new_desc_text += '[';
6604 new_desc_text += name_text;
6605 new_desc_text += ']';
6606 } else {
6607 new_desc_text += (*old_desc);
6608 old_desc++;
6609 }
6610 }
6611
6612 strcpy(new_desc, new_desc_text.GetBuffer(0));
6613 }
6614
6615 /* OLD VERSION
6616 // Returns a description copy with the parameter type info removed
6617 void CDallasMainDlg::ParseOutActionVarTypes(char *new_desc, char *old_desc)
6618 {
6619 int ok_to_write=TRUE;
6620
6621 do {
6622 if(ok_to_write) {
6623 (*new_desc)=(*old_desc);
6624 new_desc++;
6625 }
6626
6627 if((*old_desc)=='[')
6628 ok_to_write=FALSE;
6629 else if((*old_desc)==':')
6630 ok_to_write=TRUE;
6631
6632 old_desc++;
6633
6634 } while((*old_desc)!='\0');
6635
6636 (*new_desc)=(*old_desc);
6637 }
6638 */
6639
6640 // Returns a description copy with the parameter type info removed
6641 void CDallasMainDlg::ParseOutQueryVarTypes(char *new_desc, char *old_desc) {
6642 CString name_text, default_text, range_text;
6643 CString new_desc_text;
6644
6645 new_desc_text = "";
6646
6647 // Skip the return type section
6648 old_desc = strchr(old_desc, ':');
6649 if (old_desc == NULL) {
6650 strcpy(new_desc, new_desc_text.GetBuffer(0));
6651 return;
6652 }
6653 old_desc++;
6654
6655 // Parse the rest like it was an action
6656 ParseOutActionVarTypes(new_desc, old_desc);
6657 }
6658
6659 /* OLD VERSION
6660 // Returns a description copy with the parameter type info removed
6661 void CDallasMainDlg::ParseOutQueryVarTypes(char *new_desc, char *old_desc)
6662 {
6663 int ok_to_write=FALSE;
6664
6665 do {
6666 if(ok_to_write) {
6667 (*new_desc)=(*old_desc);
6668 new_desc++;
6669 }
6670
6671 if((*old_desc)=='[')
6672 ok_to_write=FALSE;
6673 else if((*old_desc)==':')
6674 ok_to_write=TRUE;
6675
6676 old_desc++;
6677
6678 } while((*old_desc)!='\0');
6679
6680 (*new_desc)=(*old_desc);
6681 }
6682 */
6683
6684 // Validates an action node by conforming its parameters to what they should be
6685 // returns FALSE if node was modified significantly, otherwise TRUE
6686 bool CDallasMainDlg::ValidateActionNode(HTREEITEM node, int linenum) {
6687 CString name_text, default_text, range_text;
6688 tTreeNodeData *data;
6689 HTREEITEM child_node;
6690 int ID;
6691 char *desc;
6692
6693 if (node == NULL)
6694 return TRUE;
6695
6696 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
6697 if (data == NULL || data->type != ACTION_STATEMENT_NODE)
6698 return TRUE;
6699
6700 ID = data->ID;
6701 if (ID < 0 || ID >= m_NumActions)
6702 return TRUE;
6703
6704 desc = GetActionDesc(ID);
6705 if (desc == NULL)
6706 return TRUE;
6707
6708 // Get the first child, if one exists
6709 child_node = m_ScriptTree.GetChildItem(node);
6710
6711 // Parse the description, adding default parameter nodes appropriately
6712 bool modified = FALSE;
6713 while ((*desc) != '\0') {
6714
6715 if ((*desc) == '[') { // Note the start of a parameter block
6716
6717 int param_type = ParseParamBlock(desc, name_text, default_text, range_text);
6718 if (param_type >= 0) {
6719
6720 // Check the corresponding param (if it exists) and make it match up
6721 if (ConformParamNode(node, child_node, param_type, name_text.GetBuffer(0), default_text.GetBuffer(0)))
6722 modified = TRUE;
6723
6724 if (child_node != NULL)
6725 child_node = m_ScriptTree.GetNextSiblingItem(child_node);
6726 }
6727
6728 } else {
6729 desc++;
6730 }
6731 }
6732
6733 // Delete any remaining child parameter nodes (they are no longer used)
6734 if (child_node != NULL) {
6735 do {
6736 HTREEITEM temp_node = child_node;
6737 child_node = m_ScriptTree.GetNextSiblingItem(child_node);
6738 FreeTreeItem(temp_node);
6739 } while (child_node != NULL);
6740
6741 modified = TRUE;
6742 }
6743
6744 if (modified)
6745 ScriptFileParseError(MODIFIED_FUNC_ERR, linenum, GetScriptID(node), GetActionFunc(ID));
6746
6747 return (!modified);
6748 }
6749
6750 /* OLD VERSION
6751 // Validates an action node by conforming its parameters to what they should be
6752 // returns FALSE if node was modified significantly, otherwise TRUE
6753 bool CDallasMainDlg::ValidateActionNode(HTREEITEM node, int linenum)
6754 {
6755 tTreeNodeData *data;
6756 HTREEITEM child_node;
6757 int ID;
6758 char *desc, *desc_copy;
6759
6760 if(node==NULL) return TRUE;
6761
6762 data=(tTreeNodeData *)m_ScriptTree.GetItemData(node);
6763 if(data==NULL || data->type!=ACTION_STATEMENT_NODE) return TRUE;
6764
6765 ID=data->ID;
6766 if(ID<0 || ID>=m_NumActions) return TRUE;
6767
6768 desc=GetActionDesc(ID);
6769 if(desc==NULL) return TRUE;
6770
6771 // Get the first child, if one exists
6772 child_node=m_ScriptTree.GetChildItem(node);
6773
6774 // Make a copy of description (so null chars can be added)
6775 desc_copy=(char *)mem_malloc(strlen(desc)+1);
6776 if(desc_copy==NULL) {
6777 MessageBox("ERROR: Out of memory in ValidateActionNode()!","Out of Memory
6778 Error!",MB_OK|MB_ICONEXCLAMATION); return FALSE;
6779 }
6780 strcpy(desc_copy,desc);
6781
6782 // Parse the description, adding default parameter nodes appropriately
6783 int j=0;
6784 bool start_block_found=FALSE;
6785 bool type_delim_found=FALSE;
6786 char *param_name=FALSE;
6787 int param_type_char=-1;
6788 int param_type;
6789 bool modified=FALSE;
6790
6791 while(desc_copy[j]!='\0') {
6792
6793 if(desc_copy[j]=='[') { // Note the start of a parameter block
6794 start_block_found=TRUE;
6795 }
6796 else if(desc_copy[j]==':' && start_block_found) { // Note the end of parameter type field
6797 type_delim_found=TRUE;
6798 }
6799 else if(desc_copy[j]==']') { // If end of block, add the parameter
6800
6801 if(param_type_char!=-1 && param_name!=NULL) {
6802
6803 desc_copy[j]='\0'; // mark the end of the variable name
6804
6805 // Get the parameter type
6806 param_type=ConvertParamCharToType(param_type_char);
6807
6808 // Check the corresponding param (if it exists) and make it match up
6809 if(ConformParamNode(node,child_node,param_type,param_name))
6810 modified=TRUE;
6811
6812 if(child_node!=NULL) child_node=m_ScriptTree.GetNextSiblingItem(child_node);
6813 }
6814
6815 start_block_found=FALSE;
6816 type_delim_found=FALSE;
6817 param_name=FALSE;
6818 param_type_char=-1;
6819 }
6820 else if(start_block_found && param_type_char==-1) {
6821 param_type_char=desc_copy[j];
6822 }
6823 else if(type_delim_found && param_name==NULL) {
6824 param_name=&desc_copy[j];
6825 }
6826
6827 j++;
6828 }
6829
6830 // Free up the copy memory
6831 mem_free(desc_copy);
6832
6833 // Delete any remaining child parameter nodes (they are no longer used)
6834 if(child_node!=NULL) {
6835 do {
6836 HTREEITEM temp_node=child_node;
6837 child_node=m_ScriptTree.GetNextSiblingItem(child_node);
6838 FreeTreeItem(temp_node);
6839 } while(child_node!=NULL);
6840
6841 modified=TRUE;
6842 }
6843
6844 if(modified)
6845 ScriptFileParseError(MODIFIED_FUNC_ERR,linenum,GetScriptID(node),GetActionFunc(ID));
6846
6847 return (!modified);
6848 }
6849 */
6850
6851 // Checks the given param node (if it exists) and makes it match up with the given data
6852 // Returns TRUE if a significant modification had to take place, FALSE otherwise
6853 bool CDallasMainDlg::ConformParamNode(HTREEITEM parent_node, HTREEITEM &param_node, int type, char *name,
6854 char *def_value /*=NULL*/) {
6855 tTreeNodeData *data;
6856 CString query_ret_name;
6857 int index;
6858
6859 if (parent_node == NULL)
6860 return FALSE;
6861
6862 // If the param node doesn't exist, then we need to add a default param
6863 if (param_node == NULL) {
6864 CreateDefaultParameterNode(parent_node, TVI_LAST, type, name, def_value);
6865 return TRUE;
6866 }
6867
6868 // See if the node matches the given data
6869 data = (tTreeNodeData *)m_ScriptTree.GetItemData(param_node);
6870 if (data != NULL) {
6871 // Check parameter node
6872 if (data->type == PARAMETER_NODE && data->ID == type) {
6873 // node matches, so copy over the name in case it's changed (not considered a major mod)
6874 strcpy(data->name, name);
6875 UpdateNodeText(param_node);
6876 return FALSE;
6877 }
6878
6879 // If it's a SPECNAME, see if we can transfer it over
6880 if (data->type == PARAMETER_NODE && data->ID == SPECNAME_PARAMETER_TYPE) {
6881 if (type == PATH_PARAMETER_TYPE) {
6882 data->ID = type;
6883 strcpy(data->name, name);
6884 index = osipf_FindPathName(data->str_val);
6885 if (index < 0) {
6886 data->int_val = NOT_SPECIFIED_TYPE;
6887 strcpy(data->str_val, "");
6888 UpdateNodeText(param_node);
6889 return TRUE;
6890 }
6891 data->int_val = index;
6892 strcpy(data->str_val, GamePaths[index].name);
6893 UpdateNodeText(param_node);
6894 return FALSE;
6895 } else if (type == MATCEN_PARAMETER_TYPE) {
6896 data->ID = type;
6897 strcpy(data->name, name);
6898 data->subID = USE_MATCEN_VALUE;
6899 index = osipf_FindMatcenName(data->str_val);
6900 if (index < 0) {
6901 data->int_val = NOT_SPECIFIED_TYPE;
6902 strcpy(data->str_val, "");
6903 UpdateNodeText(param_node);
6904 return TRUE;
6905 }
6906 char matcen_name[MAX_MATCEN_NAME_LEN + 1];
6907 Matcen[index]->GetName(matcen_name);
6908 data->int_val = index;
6909 strcpy(data->str_val, matcen_name);
6910 UpdateNodeText(param_node);
6911 return FALSE;
6912 } else if (type == LEVEL_GOAL_PARAMETER_TYPE) {
6913 data->ID = type;
6914 strcpy(data->name, name);
6915 data->subID = USE_LEVEL_GOAL_VALUE;
6916 index = osipf_FindLevelGoalName(data->str_val);
6917 if (index < 0) {
6918 data->int_val = NOT_SPECIFIED_TYPE;
6919 strcpy(data->str_val, "");
6920 UpdateNodeText(param_node);
6921 return TRUE;
6922 }
6923 data->int_val = index;
6924 UpdateNodeText(param_node);
6925 return FALSE;
6926 } else if (type == STRM_AUDIO_PARAMETER_TYPE) {
6927 data->ID = type;
6928 strcpy(data->name, name);
6929 if (!GamefileExists(data->str_val)) {
6930 strcpy(data->str_val, "");
6931 UpdateNodeText(param_node);
6932 return TRUE;
6933 }
6934 UpdateNodeText(param_node);
6935 return FALSE;
6936 }
6937 }
6938
6939 // Check query node
6940 if (data->type == EXPRESSION_NODE && GetQueryReturnType(data->ID, query_ret_name) == type) {
6941 // node matches, so copy over the name in case it's changed (not considered a major mod)
6942 strcpy(data->name, name);
6943 UpdateNodeText(param_node);
6944 return FALSE;
6945 }
6946 }
6947
6948 // Since the param node doesn't match up with the data, replace it with a default that does
6949 HTREEITEM new_node;
6950 new_node = CreateDefaultParameterNode(parent_node, param_node, type, name, def_value);
6951 FreeTreeItem(param_node);
6952 param_node = new_node;
6953 UpdateNodeText(param_node);
6954
6955 return TRUE;
6956 }
6957
6958 // Validates a query node by conforming its parameters to what they should be
6959 // returns FALSE if node was modified significantly, otherwise TRUE
6960 bool CDallasMainDlg::ValidateQueryNode(HTREEITEM node, int linenum) {
6961 CString name_text, default_text, range_text;
6962 tTreeNodeData *data;
6963 HTREEITEM child_node;
6964 int ID;
6965 char *desc;
6966
6967 if (node == NULL)
6968 return TRUE;
6969
6970 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
6971 if (data == NULL || data->type != EXPRESSION_NODE)
6972 return TRUE;
6973
6974 ID = data->ID;
6975 if (ID < 0 || ID >= m_NumQueries)
6976 return TRUE;
6977
6978 desc = strchr(GetQueryDesc(ID), ':');
6979 if (desc == NULL)
6980 return TRUE;
6981 desc++;
6982
6983 // Get the first child, if one exists
6984 child_node = m_ScriptTree.GetChildItem(node);
6985
6986 // Parse the description, adding default parameter nodes appropriately
6987 bool modified = FALSE;
6988 while ((*desc) != '\0') {
6989
6990 if ((*desc) == '[') { // Note the start of a parameter block
6991
6992 int param_type = ParseParamBlock(desc, name_text, default_text, range_text);
6993 if (param_type >= 0) {
6994
6995 // Check the corresponding param (if it exists) and make it match up
6996 if (ConformParamNode(node, child_node, param_type, name_text.GetBuffer(0), default_text.GetBuffer(0)))
6997 modified = TRUE;
6998
6999 if (child_node != NULL)
7000 child_node = m_ScriptTree.GetNextSiblingItem(child_node);
7001 }
7002 } else {
7003 desc++;
7004 }
7005 }
7006
7007 // Delete any remaining child parameter nodes (they are no longer used)
7008 if (child_node != NULL) {
7009 do {
7010 HTREEITEM temp_node = child_node;
7011 child_node = m_ScriptTree.GetNextSiblingItem(child_node);
7012 FreeTreeItem(temp_node);
7013 } while (child_node != NULL);
7014
7015 modified = TRUE;
7016 }
7017
7018 if (modified)
7019 ScriptFileParseError(MODIFIED_FUNC_ERR, linenum, GetScriptID(node), GetQueryFunc(ID));
7020
7021 return (!modified);
7022 }
7023
7024 /* OLD VERSION
7025 // Validates a query node by conforming its parameters to what they should be
7026 // returns FALSE if node was modified significantly, otherwise TRUE
7027 bool CDallasMainDlg::ValidateQueryNode(HTREEITEM node, int linenum)
7028 {
7029 tTreeNodeData *data;
7030 HTREEITEM child_node;
7031 int ID;
7032 char *desc, *desc_copy;
7033
7034 if(node==NULL) return TRUE;
7035
7036 data=(tTreeNodeData *)m_ScriptTree.GetItemData(node);
7037 if(data==NULL || data->type!=EXPRESSION_NODE) return TRUE;
7038
7039 ID=data->ID;
7040 if(ID<0 || ID>=m_NumQueries) return TRUE;
7041
7042 desc=strchr(GetQueryDesc(ID),':');
7043 if(desc==NULL) return TRUE;
7044 desc++;
7045
7046 // Get the first child, if one exists
7047 child_node=m_ScriptTree.GetChildItem(node);
7048
7049 // Make a copy of description (so null chars can be added)
7050 desc_copy=(char *)mem_malloc(strlen(desc)+1);
7051 if(desc_copy==NULL) {
7052 MessageBox("ERROR: Out of memory in ValidateQueryNode()!","Out of Memory
7053 Error!",MB_OK|MB_ICONEXCLAMATION); return FALSE;
7054 }
7055 strcpy(desc_copy,desc);
7056
7057 // Parse the description, adding default parameter nodes appropriately
7058 int j=0;
7059 bool start_block_found=FALSE;
7060 bool type_delim_found=FALSE;
7061 char *param_name=FALSE;
7062 int param_type_char=-1;
7063 int param_type;
7064 bool modified=FALSE;
7065
7066 while(desc_copy[j]!='\0') {
7067
7068 if(desc_copy[j]=='[') { // Note the start of a parameter block
7069 start_block_found=TRUE;
7070 }
7071 else if(desc_copy[j]==':' && start_block_found) { // Note the end of parameter type field
7072 type_delim_found=TRUE;
7073 }
7074 else if(desc_copy[j]==']') { // If end of block, add the parameter
7075
7076 if(param_type_char!=-1 && param_name!=NULL) {
7077
7078 desc_copy[j]='\0'; // mark the end of the variable name
7079
7080 // Get the parameter type
7081 param_type=ConvertParamCharToType(param_type_char);
7082
7083 // Check the corresponding param (if it exists) and make it match up
7084 if(ConformParamNode(node,child_node,param_type,param_name))
7085 modified=TRUE;
7086
7087 if(child_node!=NULL) child_node=m_ScriptTree.GetNextSiblingItem(child_node);
7088 }
7089
7090 start_block_found=FALSE;
7091 type_delim_found=FALSE;
7092 param_name=FALSE;
7093 param_type_char=-1;
7094 }
7095 else if(start_block_found && param_type_char==-1) {
7096 param_type_char=desc_copy[j];
7097 }
7098 else if(type_delim_found && param_name==NULL) {
7099 param_name=&desc_copy[j];
7100 }
7101
7102 j++;
7103 }
7104
7105 // Free up the copy memory
7106 mem_free(desc_copy);
7107
7108 // Delete any remaining child parameter nodes (they are no longer used)
7109 if(child_node!=NULL) {
7110 do {
7111 HTREEITEM temp_node=child_node;
7112 child_node=m_ScriptTree.GetNextSiblingItem(child_node);
7113 FreeTreeItem(temp_node);
7114 } while(child_node!=NULL);
7115
7116 modified=TRUE;
7117 }
7118
7119 if(modified)
7120 ScriptFileParseError(MODIFIED_FUNC_ERR,linenum,GetScriptID(node),GetQueryFunc(ID));
7121
7122 return (!modified);
7123 }
7124 */
7125
7126 // Fills up the given menu with the categories of actions
7127 // NOTE: Command ID's of menu items start at the given command_offset
7128 void CDallasMainDlg::FillActionMenu(CMenu *action_menu, int command_offset) {
7129 int j, k, actions_added;
7130
7131 // Loop through the categories, creating submenu for each one
7132 for (j = 0; j < m_NumFunctionCategories; j++) {
7133 CMenu category_submenu;
7134 category_submenu.CreatePopupMenu();
7135 actions_added = 0;
7136
7137 // Scan the list, adding Actions that match the current category
7138 for (k = 0; k < m_NumActions; k++)
7139 if (m_ActionDatabase[k].category == j) {
7140 char *temp_desc = (char *)mem_malloc(strlen(m_ActionDatabase[k].desc) + 1);
7141 if (temp_desc == NULL) {
7142 MessageBox("Out of memory error in FillActionMenu()!", "Memory Error!", MB_OK | MB_ICONEXCLAMATION);
7143 return;
7144 }
7145 ParseOutActionVarTypes(temp_desc, m_ActionDatabase[k].desc);
7146 category_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, (command_offset + k), temp_desc);
7147 mem_free(temp_desc);
7148 actions_added++;
7149 }
7150
7151 // Detach and add this submenu to the action menu
7152 ColumnizePopupMenu(&category_submenu);
7153 if (actions_added == 0)
7154 action_menu->AppendMenu(MF_POPUP | MF_GRAYED, (UINT_PTR)category_submenu.Detach(), m_FunctionCategories[j]);
7155 else
7156 action_menu->AppendMenu(MF_POPUP, (UINT_PTR)category_submenu.Detach(), m_FunctionCategories[j]);
7157 }
7158 }
7159
7160 // Fills up the given menu with the categories of queries
7161 // NOTE: Command ID's of menu items start at the given command_offset
7162 void CDallasMainDlg::FillQueryMenu(CMenu *query_menu, int command_offset, int valid_return_type,
7163 char *valid_return_name) {
7164 int j, k, queries_added;
7165 int query_ret_type;
7166 CString query_ret_name;
7167 bool types_match;
7168
7169 // Loop through the categories, creating submenu for each one
7170 for (j = 0; j < m_NumFunctionCategories; j++) {
7171 CMenu category_submenu;
7172 category_submenu.CreatePopupMenu();
7173 queries_added = 0;
7174
7175 // Scan the list, adding queries that match the current category
7176 for (k = 0; k < m_NumActions; k++)
7177 if (m_QueryDatabase[k].category == j) {
7178 char *temp_desc = (char *)mem_malloc(strlen(m_QueryDatabase[k].desc) + 1);
7179 if (temp_desc == NULL) {
7180 MessageBox("Out of memory error in FillQueryMenu()!", "Memory Error!", MB_OK | MB_ICONEXCLAMATION);
7181 return;
7182 }
7183 ParseOutQueryVarTypes(temp_desc, m_QueryDatabase[k].desc);
7184
7185 query_ret_type = GetQueryReturnType(k, query_ret_name);
7186
7187 // See if the types match up
7188 types_match = FALSE;
7189 if (valid_return_type == ANY_PARAMETER_TYPE)
7190 types_match = TRUE;
7191 else if (valid_return_type == query_ret_type) {
7192 if (valid_return_type == ENUM_PARAMETER_TYPE || valid_return_type == FLAG_PARAMETER_TYPE) {
7193 if (strlen(valid_return_name) == 0)
7194 types_match = TRUE;
7195 else if (strcmp(valid_return_name, query_ret_name.GetBuffer(0)) == 0)
7196 types_match = TRUE;
7197 } else
7198 types_match = TRUE;
7199 }
7200
7201 if (types_match) {
7202 category_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, (command_offset + k), temp_desc);
7203 queries_added++;
7204 } else
7205 category_submenu.AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, (command_offset + k), temp_desc);
7206 mem_free(temp_desc);
7207 }
7208
7209 // Detach and add this submenu to the action menu
7210 ColumnizePopupMenu(&category_submenu);
7211 if (queries_added == 0)
7212 query_menu->AppendMenu(MF_POPUP | MF_GRAYED, (UINT_PTR)category_submenu.Detach(), m_FunctionCategories[j]);
7213 else
7214 query_menu->AppendMenu(MF_POPUP, (UINT_PTR)category_submenu.Detach(), m_FunctionCategories[j]);
7215 }
7216 }
7217
7218 // Attempts to parse the Nth (indexed at 1) bracketed section of the given function node's desc,
7219 // and obtain from it the parameter name, default string, and range string.
7220 // It returns the param type if successfull, or -1 if the requested Parameter section
7221 // does not exist
7222 int CDallasMainDlg::ParseNthParam(HTREEITEM func_node, int n, CString &name_text, CString &default_text,
7223 CString &range_text) {
7224 tTreeNodeData *data;
7225
7226 if (func_node == NULL)
7227 return (-1);
7228
7229 data = (tTreeNodeData *)m_ScriptTree.GetItemData(func_node);
7230 if (data == NULL)
7231 return (-1);
7232
7233 // Handle action nodes
7234 if (data->type == ACTION_STATEMENT_NODE) {
7235 char *desc = GetActionDesc(data->ID);
7236 return (ParseNthParam(desc, n, name_text, default_text, range_text));
7237 }
7238
7239 // Handle query nodes
7240 if (data->type == EXPRESSION_NODE) {
7241 char *desc = GetQueryDesc(data->ID);
7242 return (ParseNthParam(desc, n, name_text, default_text, range_text));
7243 }
7244
7245 return (-1);
7246 }
7247
7248 // Attempts to parse the Nth (indexed at 1) bracketed section of the given action desc,
7249 // and obtain from it the parameter name, default string, and range string.
7250 // It returns the param type if successfull, or -1 if the requested Parameter section
7251 // does not exist
7252 int CDallasMainDlg::ParseNthParam(char *desc, int n, CString &name_text, CString &default_text, CString &range_text) {
7253 // Check validity of desc and given n
7254 if (n <= 0 || desc == NULL)
7255 return (-1);
7256
7257 // Find the n'th parameter block (bracketed section)
7258 char *s;
7259 s = strchr(desc, '[');
7260 for (int j = 1; j < n; j++)
7261 if (s != NULL) {
7262 s++;
7263 s = strchr(s, '[');
7264 }
7265
7266 // Make sure the requested section was found
7267 if (s == NULL)
7268 return FALSE;
7269
7270 // Parse the parameter block into its different sections
7271 return (ParseParamBlock(s, name_text, default_text, range_text));
7272 }
7273
7274 #define NO_SECTION 0
7275 #define TYPE_SECTION 1
7276 #define NAME_SECTION 2
7277 #define DEFAULT_SECTION 3
7278 #define RANGE_SECTION 4
7279
7280 // Parses the next param block encountered, and, if successfull, returns the
7281 // parameter type (-1 is returned if a parameter block was not found).
7282 // The name, default, and range strings are also set appropriately, and the
7283 // line pointer will be set to the first character after the closing bracket.
7284 int CDallasMainDlg::ParseParamBlock(char_ptr &line, CString &name_text, CString &default_text, CString &range_text) {
7285 int param_type_char;
7286
7287 // Set all the return data to empty
7288 name_text = "";
7289 default_text = "";
7290 range_text = "";
7291 param_type_char = -1;
7292
7293 // Parse the parameter block
7294 int currently_parsing = NO_SECTION;
7295 bool done = FALSE;
7296 while (!done && (*line) != '\0') {
7297
7298 char ch = (*line);
7299 if (ch == '[') { // Start of parameter block
7300 currently_parsing = TYPE_SECTION;
7301 } else if (ch == ']') { // End of parameter block
7302 done = TRUE;
7303 } else if (ch == ':') { // Start of name section or range section
7304 if (currently_parsing == NAME_SECTION || currently_parsing == DEFAULT_SECTION)
7305 currently_parsing = RANGE_SECTION;
7306 else
7307 currently_parsing = NAME_SECTION;
7308 } else if (ch == '=') { // Start of default section
7309 if (currently_parsing == NAME_SECTION)
7310 currently_parsing = DEFAULT_SECTION;
7311 } else { // It is just a character, so parse it appropriately
7312 switch (currently_parsing) {
7313 case NO_SECTION:
7314 break;
7315 case TYPE_SECTION:
7316 if (param_type_char == -1)
7317 param_type_char = ch;
7318 break;
7319 case NAME_SECTION:
7320 name_text += ch;
7321 break;
7322 case DEFAULT_SECTION:
7323 default_text += ch;
7324 break;
7325 case RANGE_SECTION:
7326 range_text += ch;
7327 break;
7328 }
7329 }
7330
7331 // Get the next character
7332 line++;
7333 }
7334
7335 // If end of line reached before end of block, return an error value
7336 if (!done)
7337 return (-1);
7338
7339 // Otherwise, return what was found
7340 return (ConvertParamCharToType(param_type_char));
7341 }
7342
7343 #define RANGE_START_NUM 0
7344 #define RANGE_END_NUM 1
7345
7346 // Returns TRUE if the given integer is in the given range, FALSE otherwise
7347 bool CDallasMainDlg::VerifyIntegerRange(int value, char *range_desc) {
7348 CString num_text;
7349 int range_start = 0, range_end = 0;
7350
7351 bool value_in_range = FALSE;
7352 int currently_parsing = RANGE_START_NUM;
7353 while ((*range_desc) != '\0') {
7354
7355 char ch = (*range_desc);
7356 if (ch == ',') {
7357 if (currently_parsing == RANGE_START_NUM) {
7358 range_start = atoi(num_text.GetBuffer(0));
7359 if (value == range_start)
7360 value_in_range = TRUE;
7361 } else {
7362 range_end = atoi(num_text.GetBuffer(0));
7363 if (value >= range_start && value <= range_end)
7364 value_in_range = TRUE;
7365 }
7366 num_text = "";
7367 range_start = 0;
7368 range_end = 0;
7369 currently_parsing = RANGE_START_NUM;
7370 } else if (ch == '|') {
7371 currently_parsing = RANGE_END_NUM;
7372 range_start = atoi(num_text.GetBuffer(0));
7373 num_text = "";
7374 } else {
7375 num_text += ch;
7376 }
7377
7378 range_desc++;
7379 }
7380
7381 // Check the last value range
7382 if (currently_parsing == RANGE_START_NUM) {
7383 range_start = atoi(num_text.GetBuffer(0));
7384 if (value == range_start)
7385 value_in_range = TRUE;
7386 } else {
7387 range_end = atoi(num_text.GetBuffer(0));
7388 if (value >= range_start && value <= range_end)
7389 value_in_range = TRUE;
7390 }
7391
7392 return (value_in_range);
7393 }
7394
7395 // Returns TRUE if the given float is in the given range, FALSE otherwise
7396 bool CDallasMainDlg::VerifyFloatRange(float value, char *range_desc) {
7397 CString num_text;
7398 float range_start = 0.0, range_end = 0.0;
7399
7400 bool value_in_range = FALSE;
7401 int currently_parsing = RANGE_START_NUM;
7402 while ((*range_desc) != '\0') {
7403
7404 char ch = (*range_desc);
7405 if (ch == ',') {
7406 if (currently_parsing == RANGE_START_NUM) {
7407 range_start = atof(num_text.GetBuffer(0));
7408 if (value == range_start)
7409 value_in_range = TRUE;
7410 } else {
7411 range_end = atof(num_text.GetBuffer(0));
7412 if (value >= range_start && value <= range_end)
7413 value_in_range = TRUE;
7414 }
7415 num_text = "";
7416 range_start = 0.0;
7417 range_end = 0.0;
7418 currently_parsing = RANGE_START_NUM;
7419 } else if (ch == '|') {
7420 currently_parsing = RANGE_END_NUM;
7421 range_start = atof(num_text.GetBuffer(0));
7422 num_text = "";
7423 } else {
7424 num_text += ch;
7425 }
7426
7427 range_desc++;
7428 }
7429
7430 // Check the last value range
7431 if (currently_parsing == RANGE_START_NUM) {
7432 range_start = atof(num_text.GetBuffer(0));
7433 if (value == range_start)
7434 value_in_range = TRUE;
7435 } else {
7436 range_end = atof(num_text.GetBuffer(0));
7437 if (value >= range_start && value <= range_end)
7438 value_in_range = TRUE;
7439 }
7440
7441 return (value_in_range);
7442 }
7443
7444 /////////////////////////////////////////////////////////////////////////////
7445 // Script Grouping Functions
7446 /////////////////////////////////////////////////////////////////////////////
7447
7448 // Initializes the script grouping list for use
7449 void CDallasMainDlg::InitScriptGroupingList(void) {
7450 m_ScriptGroupingList = NULL;
7451 m_NumScriptGroups = 0;
7452 }
7453
7454 // Deletes memory allocated for the Script Grouping list
7455 void CDallasMainDlg::ClearScriptGroupingList(void) {
7456 int j, k;
7457
7458 // Free up all the individual script node lists
7459 for (j = 0; j < m_NumScriptGroups; j++) {
7460 for (k = 0; k < MAX_EVENT_TYPES; k++) {
7461 tEventSection *event_section = &m_ScriptGroupingList[j].event_sections[k];
7462 if (event_section->num_script_nodes > 0) {
7463 mem_free(event_section->script_node_list);
7464 event_section->script_node_list = NULL;
7465 event_section->num_script_nodes = 0;
7466 }
7467 }
7468 }
7469
7470 // Free up the entire script grouping list
7471 if (m_NumScriptGroups > 0) {
7472 mem_free(m_ScriptGroupingList);
7473 m_ScriptGroupingList = NULL;
7474 m_NumScriptGroups = 0;
7475 }
7476 }
7477
7478 // Adds the node into the appropriate event section of the owner group
7479 int CDallasMainDlg::AddNodeToScriptOwnerGroup(int pos, HTREEITEM script_node) {
7480 HTREEITEM event_node;
7481 tTreeNodeData *event_data;
7482 int event_type;
7483
7484 // Make sure pos is valid
7485 if (pos < 0 || pos >= m_NumScriptGroups)
7486 return FALSE;
7487
7488 // Get the event type
7489 event_node = GetScriptEventNode(script_node);
7490 if (event_node == NULL)
7491 return FALSE;
7492 event_data = (tTreeNodeData *)m_ScriptTree.GetItemData(event_node);
7493 if (event_data == NULL)
7494 return FALSE;
7495 event_type = event_data->ID;
7496
7497 // Make sure event type is valid
7498 if (event_type < 0 || event_type >= MAX_EVENT_TYPES)
7499 return FALSE;
7500
7501 tEventSection *event_section = &m_ScriptGroupingList[pos].event_sections[event_type];
7502
7503 // Add this node to the appropriate event section list
7504 if (event_section->num_script_nodes == 0)
7505 event_section->script_node_list = (HTREEITEM *)mem_malloc(sizeof(HTREEITEM) * 1);
7506 else
7507 event_section->script_node_list = (HTREEITEM *)mem_realloc(
7508 event_section->script_node_list, sizeof(HTREEITEM) * (event_section->num_script_nodes + 1));
7509
7510 if (event_section->script_node_list == NULL)
7511 return FALSE;
7512 event_section->num_script_nodes++;
7513
7514 int new_pos = event_section->num_script_nodes - 1;
7515 event_section->script_node_list[new_pos] = script_node;
7516
7517 return TRUE;
7518 }
7519
7520 // Categorizes the given node into the grouping list
7521 int CDallasMainDlg::AddNodeToScriptGroupingList(HTREEITEM script_node) {
7522 HTREEITEM owner_node;
7523 tTreeNodeData *data, *owner_data;
7524 int j;
7525
7526 // Make sure it's a script header node
7527 data = (tTreeNodeData *)m_ScriptTree.GetItemData(script_node);
7528 if (data == NULL || data->type != SCRIPT_HEADER_NODE)
7529 return FALSE;
7530
7531 // Get the owner node data
7532 owner_node = GetScriptOwnerNode(script_node);
7533 if (owner_node == NULL)
7534 return FALSE;
7535 owner_data = (tTreeNodeData *)m_ScriptTree.GetItemData(owner_node);
7536 if (owner_data == NULL)
7537 return FALSE;
7538
7539 // Search the grouping list for a matching owner group
7540 for (j = 0; j < m_NumScriptGroups; j++) {
7541 if (m_ScriptGroupingList[j].owner_type != owner_data->ID)
7542 continue;
7543
7544 // If it's not a LEVEL owner, we need to make sure the handles also match
7545 if (m_ScriptGroupingList[j].owner_type != LEVEL_TYPE) {
7546 if (m_ScriptGroupingList[j].owner_handle != owner_data->int_val)
7547 continue;
7548 }
7549
7550 return (AddNodeToScriptOwnerGroup(j, script_node));
7551 }
7552
7553 // Since owner does not exist, create a new Script Group entry
7554 if (m_NumScriptGroups == 0)
7555 m_ScriptGroupingList = (tScriptOwnerGroup *)mem_malloc(sizeof(tScriptOwnerGroup) * 1);
7556 else
7557 m_ScriptGroupingList =
7558 (tScriptOwnerGroup *)mem_realloc(m_ScriptGroupingList, sizeof(tScriptOwnerGroup) * (m_NumScriptGroups + 1));
7559
7560 if (m_ScriptGroupingList == NULL)
7561 return FALSE;
7562 m_NumScriptGroups++;
7563
7564 // Initialize the new entry
7565 int new_pos = m_NumScriptGroups - 1;
7566 m_ScriptGroupingList[new_pos].owner_type = owner_data->ID;
7567 m_ScriptGroupingList[new_pos].owner_handle = owner_data->int_val;
7568 for (j = 0; j < MAX_EVENT_TYPES; j++) {
7569 m_ScriptGroupingList[new_pos].event_sections[j].num_script_nodes = 0;
7570 m_ScriptGroupingList[new_pos].event_sections[j].script_node_list = NULL;
7571 }
7572
7573 // Now add it officially to the grouping list
7574 return (AddNodeToScriptOwnerGroup(new_pos, script_node));
7575 }
7576
7577 // Adds every script from the tree to the Grouping List
7578 int CDallasMainDlg::BuildScriptGroupingList(void) {
7579 HTREEITEM script_header_node;
7580
7581 // Clear the grouping list first
7582 ClearScriptGroupingList();
7583
7584 // Group each script header node into the list
7585 script_header_node = m_ScriptTree.GetChildItem(TVI_ROOT);
7586 while (script_header_node != NULL) {
7587 AddNodeToScriptGroupingList(script_header_node);
7588 script_header_node = m_ScriptTree.GetNextSiblingItem(script_header_node);
7589 }
7590
7591 return TRUE;
7592 }
7593
7594 // Creates an ID constant name for a given owner node
7595 char *CDallasMainDlg::CreateScriptConstantName(int pos) {
7596 static CString name = "";
7597
7598 if (pos < 0 || pos >= m_NumScriptGroups)
7599 return (name.GetBuffer(0));
7600
7601 tScriptOwnerGroup *owner_group = &m_ScriptGroupingList[pos];
7602
7603 switch (owner_group->owner_type) {
7604 case OBJECT_TYPE:
7605 name.Format("ID_CUSTOM_OBJECT_%04X", owner_group->owner_handle);
7606 break;
7607 case TRIGGER_TYPE:
7608 name.Format("ID_TRIGGER_%04X", owner_group->owner_handle);
7609 break;
7610 case LEVEL_TYPE:
7611 name.Format("%s", LEVEL_ID_NAME);
7612 break;
7613 default:
7614 name.Format("ID_ILLEGAL_SCRIPT_TYPE");
7615 break;
7616 }
7617
7618 return (name.GetBuffer(0));
7619 }
7620
7621 // Creates a Class name for a given owner node
7622 char *CDallasMainDlg::CreateScriptClassName(int pos) {
7623 static CString name = "";
7624
7625 if (pos < 0 || pos >= m_NumScriptGroups)
7626 return (name.GetBuffer(0));
7627
7628 tScriptOwnerGroup *owner_group = &m_ScriptGroupingList[pos];
7629
7630 switch (owner_group->owner_type) {
7631 case OBJECT_TYPE:
7632 name.Format("CustomObjectScript_%04X", owner_group->owner_handle);
7633 break;
7634 case TRIGGER_TYPE:
7635 name.Format("TriggerScript_%04X", owner_group->owner_handle);
7636 break;
7637 case LEVEL_TYPE:
7638 name.Format("%s", LEVEL_CLASS_NAME);
7639 break;
7640 default:
7641 name.Format("IllegalScriptType");
7642 break;
7643 }
7644
7645 return (name.GetBuffer(0));
7646 }
7647
7648 // Creates a Class name for a given owner node
7649 char *CDallasMainDlg::CreateScriptGlobalCtrName(int ID) {
7650 static CString name = "";
7651
7652 if (ID < 0)
7653 return (name.GetBuffer(0));
7654
7655 name.Format("ScriptActionCtr_%03d", ID);
7656
7657 return (name.GetBuffer(0));
7658 }
7659
7660 /////////////////////////////////////////////////////////////////////////////
7661 // Parsing Functions
7662 /////////////////////////////////////////////////////////////////////////////
7663
7664 CString CurrentParsingFilename = "<FilenameNotSet>";
7665
7666 // Handle Parse Errors
7667 void CDallasMainDlg::ScriptFileParseError(int error_code, int linenum, int script_ID, const char *name) {
7668 CString err_msg;
7669
7670 switch (error_code) {
7671 case UEOS_ERR:
7672 err_msg.Format("ERROR: Unexpected end of file while parsing %s, line %d.", CurrentParsingFilename.GetBuffer(0),
7673 linenum);
7674 break;
7675 case INVALID_FUNC_ERR:
7676 err_msg.Format("ERROR: An invalid glue function name (%s) was encountered in %s, line %d.\n\n"
7677 "Hence, Script #%d now contains an invalid action or query that must be replaced.",
7678 name, CurrentParsingFilename.GetBuffer(0), linenum, script_ID);
7679 break;
7680 case INVALID_NODE_ERR:
7681 err_msg.Format("ERROR: An invalid script node was encountered in %s, line %d.\n\n."
7682 "Because this node could not be added, one or more of your scripts may be corrupt.",
7683 CurrentParsingFilename.GetBuffer(0), linenum);
7684 break;
7685 case MODIFIED_FUNC_ERR:
7686 err_msg.Format("ERROR: A glue function (%s) with out of date parameters was encountered in %s, line %d.\n\n"
7687 "Hence, Script #%d now contains an action or query that may need to be modified.",
7688 name, CurrentParsingFilename.GetBuffer(0), linenum, script_ID);
7689 break;
7690 case INVALID_MSGID_ERR:
7691 err_msg.Format("ERROR: An invalid Message ID (%s) was encountered in %s, line %d.\n\n"
7692 "Hence, Script #%d now contains a Message ID that needs to be replaced.",
7693 name, CurrentParsingFilename.GetBuffer(0), linenum, script_ID);
7694 break;
7695 default:
7696 err_msg.Format("ERROR: An unknown error was detected in %s, line %d", CurrentParsingFilename.GetBuffer(0), linenum);
7697 break;
7698 }
7699
7700 MessageBox(err_msg, "Script File Parse Error", MB_OK | MB_ICONEXCLAMATION);
7701 }
7702
7703 // Reads in the script source file and calls the various parsers for the
7704 // Appropriate sections
7705 int CDallasMainDlg::ParseSourceScript(char *filename) {
7706 CFILE *infile;
7707 char linebuf[2048];
7708 char tempbuf[256];
7709 char *line;
7710 int linenum;
7711 int valid_lines_read, version;
7712 char fullpath[_MAX_PATH];
7713 int rc;
7714
7715 HTREEITEM last_node_added, current_parent, returned_node;
7716 bool skip_children;
7717 int skip_depth;
7718 bool last_node_childless;
7719
7720 CurrentParsingFilename = m_ScriptFilename;
7721
7722 ddio_MakePath(fullpath, LocalScriptDir, filename, NULL);
7723
7724 // Try to open the file for loading
7725 infile = cfopen(fullpath, "rt");
7726 if (!infile) {
7727 CString msg;
7728 msg.Format("Unable to open \"%s\"!", filename);
7729 MessageBox(msg, "No Script Source File Found!", MB_OK | MB_ICONEXCLAMATION);
7730
7731 // Clear out the Script Tree
7732 ClearTree();
7733
7734 // Add the clipboard node
7735 CreateDefaultClipboardNode();
7736
7737 return FALSE;
7738 }
7739
7740 linenum = 0;
7741
7742 // Read in and parse each line of the file
7743 while (!cfeof(infile)) {
7744
7745 // Clear the buffer
7746 strcpy(linebuf, "");
7747
7748 // Read in a line from the file
7749 cf_ReadString(linebuf, sizeof(linebuf), infile);
7750 linenum++;
7751
7752 // Remove whitespace padding at start and end of line
7753 RemoveTrailingWhitespace(linebuf);
7754 line = SkipInitialWhitespace(linebuf);
7755
7756 // Check for Start of Script Block Section
7757 if (strncmp(line, SCRIPT_BLOCK_START_TAG, strlen(SCRIPT_BLOCK_START_TAG)) == 0) {
7758 bool done = false;
7759
7760 // Clear out the Script Tree
7761 ClearTree();
7762
7763 // Clear out the name lists
7764 ClearNameLists();
7765
7766 // Set valid line counter to track whether we're reading header info or tree nodes
7767 valid_lines_read = 0;
7768
7769 // Set tree node trackers so we know where we are in the actual tree
7770 last_node_added = NULL;
7771 current_parent = TVI_ROOT;
7772
7773 // Set variables that allow child nodes to be skipped over
7774 // when a bad Action or Query node is read in (invalid function name)
7775 skip_children = FALSE;
7776 skip_depth = 0;
7777 last_node_childless = FALSE;
7778
7779 // Read all the lines in the block
7780 while (!done && !cfeof(infile)) {
7781
7782 strcpy(linebuf, "");
7783 cf_ReadString(linebuf, sizeof(linebuf), infile);
7784 linenum++;
7785
7786 // Remove whitespace padding at start and end of line
7787 RemoveTrailingWhitespace(linebuf);
7788 line = SkipInitialWhitespace(linebuf);
7789
7790 // If it's an empty line or a comment, skip it
7791 if (strlen(line) == 0 || strncmp(line, "//", 2) == 0)
7792 continue;
7793
7794 // Check for End of Script Block Section
7795 if (strncmp(line, SCRIPT_BLOCK_END_TAG, strlen(SCRIPT_BLOCK_END_TAG)) == 0) {
7796 done = true;
7797 continue;
7798 }
7799
7800 // Check for Start of User Type values
7801 if (strncmp(line, USERTYPE_VALS_START_TAG, strlen(USERTYPE_VALS_START_TAG)) == 0) { // Parse a user type block
7802 tEnumDBEntry *enum_entry;
7803 char *enum_name;
7804 int DBslot;
7805 bool end_of_usertype_found;
7806
7807 enum_entry = NULL;
7808
7809 // Strip off the name of this enumeration type
7810 enum_name = strtok(line, WHITESPACE_CHARS);
7811 if (enum_name != NULL)
7812 enum_name = strtok(NULL, "");
7813 if (enum_name != NULL && (DBslot = GetEnumID(enum_name)) != INVALID_ENUM) {
7814 enum_entry = &m_EnumDatabase[DBslot];
7815 }
7816
7817 // Parse the enumeration values for this user type
7818 end_of_usertype_found = FALSE;
7819 do {
7820
7821 cf_ReadString(linebuf, sizeof(linebuf), infile);
7822 linenum++;
7823
7824 // Remove whitespace padding at start and end of line
7825 RemoveTrailingWhitespace(linebuf);
7826 line = SkipInitialWhitespace(linebuf);
7827
7828 if (strncmp(line, USERTYPE_VALS_END_TAG, strlen(USERTYPE_VALS_END_TAG)) == 0)
7829 end_of_usertype_found = TRUE;
7830 else if (enum_entry != NULL) {
7831 tEnumValueEntry *value_entry;
7832 int enum_value;
7833 char *enum_value_string;
7834 char *enum_value_name;
7835
7836 // Parse out the enum value and value name
7837 enum_value_string = strtok(line, ":");
7838 if (enum_value_string != NULL) {
7839 enum_value = atoi(enum_value_string);
7840 enum_value_name = strtok(NULL, "");
7841 }
7842
7843 if (enum_value_string == NULL || enum_value_name == NULL ||
7844 GetEnumValueName(enum_entry->name, enum_value) != NULL) {
7845 value_entry = NULL;
7846 } else if (enum_entry->num_values >= MAX_ENUM_VALUES ||
7847 enum_entry->num_values >= (enum_entry->max_values + 2)) {
7848 value_entry = NULL;
7849 } else {
7850 value_entry = &enum_entry->values[enum_entry->num_values++];
7851 value_entry->name = (char *)mem_malloc(strlen(enum_value_name) + 1);
7852 if (value_entry->name == NULL) {
7853 FunctionFileParseError(NO_MEM_ERR, linenum, filename);
7854 cfclose(infile);
7855 return FALSE;
7856 }
7857 strcpy(value_entry->name, enum_value_name);
7858 value_entry->value = enum_value;
7859 }
7860 }
7861
7862 } while (!end_of_usertype_found && !cfeof(infile));
7863
7864 continue;
7865 }
7866
7867 // Check for Door List Block, and read it in
7868 if (strncmp(line, DOOR_LIST_START_TAG, strlen(DOOR_LIST_START_TAG)) == 0) {
7869 bool end_list_found = 0;
7870 do {
7871 cf_ReadString(linebuf, sizeof(linebuf), infile);
7872 linenum++;
7873
7874 // Remove whitespace padding at start and end of line
7875 RemoveTrailingWhitespace(linebuf);
7876 line = SkipInitialWhitespace(linebuf);
7877
7878 if (strncmp(line, DOOR_LIST_END_TAG, strlen(DOOR_LIST_END_TAG)) == 0)
7879 end_list_found = TRUE;
7880 else if (strlen(line) > 0)
7881 AddDoorToList(line);
7882
7883 } while (!end_list_found && !cfeof(infile));
7884
7885 continue;
7886 }
7887
7888 // Check for Object List Block, and read it in
7889 if (strncmp(line, OBJECT_LIST_START_TAG, strlen(OBJECT_LIST_START_TAG)) == 0) {
7890 bool end_list_found = 0;
7891 do {
7892 cf_ReadString(linebuf, sizeof(linebuf), infile);
7893 linenum++;
7894
7895 // Remove whitespace padding at start and end of line
7896 RemoveTrailingWhitespace(linebuf);
7897 line = SkipInitialWhitespace(linebuf);
7898
7899 if (strncmp(line, OBJECT_LIST_END_TAG, strlen(OBJECT_LIST_END_TAG)) == 0)
7900 end_list_found = TRUE;
7901 else if (strlen(line) > 0)
7902 AddObjectToList(line);
7903
7904 } while (!end_list_found && !cfeof(infile));
7905
7906 continue;
7907 }
7908
7909 // Check for Room List Block, and read it in
7910 if (strncmp(line, ROOM_LIST_START_TAG, strlen(ROOM_LIST_START_TAG)) == 0) {
7911 bool end_list_found = 0;
7912 do {
7913 cf_ReadString(linebuf, sizeof(linebuf), infile);
7914 linenum++;
7915
7916 // Remove whitespace padding at start and end of line
7917 RemoveTrailingWhitespace(linebuf);
7918 line = SkipInitialWhitespace(linebuf);
7919
7920 if (strncmp(line, ROOM_LIST_END_TAG, strlen(ROOM_LIST_END_TAG)) == 0)
7921 end_list_found = TRUE;
7922 else if (strlen(line) > 0)
7923 AddRoomToList(line);
7924
7925 } while (!end_list_found && !cfeof(infile));
7926
7927 continue;
7928 }
7929
7930 // Check for Trigger List Block, and read it in
7931 if (strncmp(line, TRIGGER_LIST_START_TAG, strlen(TRIGGER_LIST_START_TAG)) == 0) {
7932 bool end_list_found = 0;
7933 do {
7934 cf_ReadString(linebuf, sizeof(linebuf), infile);
7935 linenum++;
7936
7937 // Remove whitespace padding at start and end of line
7938 RemoveTrailingWhitespace(linebuf);
7939 line = SkipInitialWhitespace(linebuf);
7940
7941 if (strncmp(line, TRIGGER_LIST_END_TAG, strlen(TRIGGER_LIST_END_TAG)) == 0)
7942 end_list_found = TRUE;
7943 else if (strlen(line) > 0)
7944 AddTriggerToList(line);
7945
7946 } while (!end_list_found && !cfeof(infile));
7947
7948 continue;
7949 }
7950
7951 // Check for Sound List Block, and read it in
7952 if (strncmp(line, SOUND_LIST_START_TAG, strlen(SOUND_LIST_START_TAG)) == 0) {
7953 bool end_list_found = 0;
7954 do {
7955 cf_ReadString(linebuf, sizeof(linebuf), infile);
7956 linenum++;
7957
7958 // Remove whitespace padding at start and end of line
7959 RemoveTrailingWhitespace(linebuf);
7960 line = SkipInitialWhitespace(linebuf);
7961
7962 if (strncmp(line, SOUND_LIST_END_TAG, strlen(SOUND_LIST_END_TAG)) == 0)
7963 end_list_found = TRUE;
7964 else if (strlen(line) > 0)
7965 AddSoundToList(line);
7966
7967 } while (!end_list_found && !cfeof(infile));
7968
7969 continue;
7970 }
7971
7972 // Check for Texture List Block, and read it in
7973 if (strncmp(line, TEXTURE_LIST_START_TAG, strlen(TEXTURE_LIST_START_TAG)) == 0) {
7974 bool end_list_found = 0;
7975 do {
7976 cf_ReadString(linebuf, sizeof(linebuf), infile);
7977 linenum++;
7978
7979 // Remove whitespace padding at start and end of line
7980 RemoveTrailingWhitespace(linebuf);
7981 line = SkipInitialWhitespace(linebuf);
7982
7983 if (strncmp(line, TEXTURE_LIST_END_TAG, strlen(TEXTURE_LIST_END_TAG)) == 0)
7984 end_list_found = TRUE;
7985 else if (strlen(line) > 0)
7986 AddTextureToList(line);
7987
7988 } while (!end_list_found && !cfeof(infile));
7989
7990 continue;
7991 }
7992
7993 // Check for Specname List Block, and read it in
7994 if (strncmp(line, SPECNAME_LIST_START_TAG, strlen(SPECNAME_LIST_START_TAG)) == 0) {
7995 bool end_list_found = 0;
7996 do {
7997 cf_ReadString(linebuf, sizeof(linebuf), infile);
7998 linenum++;
7999
8000 // Remove whitespace padding at start and end of line
8001 RemoveTrailingWhitespace(linebuf);
8002 line = SkipInitialWhitespace(linebuf);
8003
8004 if (strncmp(line, SPECNAME_LIST_END_TAG, strlen(SPECNAME_LIST_END_TAG)) == 0)
8005 end_list_found = TRUE;
8006 else if (strlen(line) > 0)
8007 AddSpecnameToList(line);
8008
8009 } while (!end_list_found && !cfeof(infile));
8010
8011 continue;
8012 }
8013
8014 // Check for Path List Block, and read it in
8015 if (strncmp(line, PATH_LIST_START_TAG, strlen(PATH_LIST_START_TAG)) == 0) {
8016 bool end_list_found = 0;
8017 do {
8018 cf_ReadString(linebuf, sizeof(linebuf), infile);
8019 linenum++;
8020
8021 // Remove whitespace padding at start and end of line
8022 RemoveTrailingWhitespace(linebuf);
8023 line = SkipInitialWhitespace(linebuf);
8024
8025 if (strncmp(line, PATH_LIST_END_TAG, strlen(PATH_LIST_END_TAG)) == 0)
8026 end_list_found = TRUE;
8027 else if (strlen(line) > 0)
8028 AddPathToList(line);
8029
8030 } while (!end_list_found && !cfeof(infile));
8031
8032 continue;
8033 }
8034
8035 // Check for Matcen List Block, and read it in
8036 if (strncmp(line, MATCEN_LIST_START_TAG, strlen(MATCEN_LIST_START_TAG)) == 0) {
8037 bool end_list_found = 0;
8038 do {
8039 cf_ReadString(linebuf, sizeof(linebuf), infile);
8040 linenum++;
8041
8042 // Remove whitespace padding at start and end of line
8043 RemoveTrailingWhitespace(linebuf);
8044 line = SkipInitialWhitespace(linebuf);
8045
8046 if (strncmp(line, MATCEN_LIST_END_TAG, strlen(MATCEN_LIST_END_TAG)) == 0)
8047 end_list_found = TRUE;
8048 else if (strlen(line) > 0)
8049 AddMatcenToList(line);
8050
8051 } while (!end_list_found && !cfeof(infile));
8052
8053 continue;
8054 }
8055
8056 // Check for Goal List Block, and read it in
8057 if (strncmp(line, GOAL_LIST_START_TAG, strlen(GOAL_LIST_START_TAG)) == 0) {
8058 bool end_list_found = 0;
8059 do {
8060 cf_ReadString(linebuf, sizeof(linebuf), infile);
8061 linenum++;
8062
8063 // Remove whitespace padding at start and end of line
8064 RemoveTrailingWhitespace(linebuf);
8065 line = SkipInitialWhitespace(linebuf);
8066
8067 if (strncmp(line, GOAL_LIST_END_TAG, strlen(GOAL_LIST_END_TAG)) == 0)
8068 end_list_found = TRUE;
8069 else if (strlen(line) > 0)
8070 AddGoalToList(line);
8071
8072 } while (!end_list_found && !cfeof(infile));
8073
8074 continue;
8075 }
8076
8077 // Check for StrmAudio List Block, and read it in
8078 if (strncmp(line, STRM_AUDIO_LIST_START_TAG, strlen(STRM_AUDIO_LIST_START_TAG)) == 0) {
8079 bool end_list_found = 0;
8080 do {
8081 cf_ReadString(linebuf, sizeof(linebuf), infile);
8082 linenum++;
8083
8084 // Remove whitespace padding at start and end of line
8085 RemoveTrailingWhitespace(linebuf);
8086 line = SkipInitialWhitespace(linebuf);
8087
8088 if (strncmp(line, STRM_AUDIO_LIST_END_TAG, strlen(STRM_AUDIO_LIST_END_TAG)) == 0)
8089 end_list_found = TRUE;
8090 else if (strlen(line) > 0)
8091 AddStrmAudioToList(line);
8092
8093 } while (!end_list_found && !cfeof(infile));
8094
8095 continue;
8096 }
8097
8098 // Is it the start of a child block?
8099 if (strncmp(line, CHILD_BLOCK_START_TAG, strlen(CHILD_BLOCK_START_TAG)) == 0) {
8100 last_node_childless = FALSE;
8101 if (!skip_children) {
8102 current_parent = last_node_added;
8103 if (current_parent == NULL)
8104 current_parent = TVI_ROOT;
8105 } else {
8106 skip_depth++;
8107 }
8108 continue;
8109 }
8110
8111 // Handles Validation of childless function nodes
8112 if (last_node_added != NULL && last_node_childless) {
8113 ValidateFunctionNode(last_node_added, linenum);
8114
8115 // Need this to update node text that depends on subnodes
8116 UpdateNodeText(last_node_added);
8117
8118 last_node_childless = FALSE;
8119 }
8120
8121 // Is it the end of a child block?
8122 if (strncmp(line, CHILD_BLOCK_END_TAG, strlen(CHILD_BLOCK_END_TAG)) == 0) {
8123 if (!skip_children || skip_depth <= 0) {
8124
8125 skip_children = FALSE;
8126 skip_depth = 0;
8127
8128 last_node_added = current_parent;
8129 if (last_node_added == TVI_ROOT)
8130 last_node_added = NULL;
8131 else {
8132 // Need this to validate a function node once all of its params have been added
8133 ValidateFunctionNode(last_node_added, linenum);
8134
8135 // Need this to update node text that depends on subnodes
8136 UpdateNodeText(last_node_added);
8137 }
8138
8139 if (current_parent != TVI_ROOT)
8140 current_parent = m_ScriptTree.GetParentItem(current_parent);
8141 if (current_parent == NULL)
8142 current_parent = TVI_ROOT;
8143 } else
8144 skip_depth--;
8145
8146 continue;
8147 }
8148
8149 // If we're skipping children, but the depth is still zero here,
8150 // then must not be any children to skip!
8151 if (skip_children && skip_depth <= 0) {
8152 skip_children = FALSE;
8153 skip_depth = 0;
8154 }
8155
8156 // See if it should be the save version line
8157 if (valid_lines_read == 0) {
8158 rc = sscanf(line, "%s %d", tempbuf, &version);
8159 if (rc == 2 && strcmp(tempbuf, "VERSION") == 0)
8160 valid_lines_read++;
8161 continue;
8162 }
8163
8164 // See if it should be the next script ID line
8165 if (valid_lines_read == 1) {
8166 rc = sscanf(line, "%s %d", tempbuf, &m_NextScriptID);
8167 if (rc == 2 && strcmp(tempbuf, "NEXT_ID") == 0)
8168 valid_lines_read++;
8169 continue;
8170 }
8171
8172 // It must be a node then,
8173 // so (if we're not skipping children) parse it and add it to the tree
8174 if (!skip_children) {
8175 if (version >= 1)
8176 returned_node = ParseScriptNodeLine_v1U(line, linenum, current_parent, skip_children, version);
8177 else
8178 returned_node = ParseScriptNodeLine_v0(line, linenum, current_parent, skip_children);
8179
8180 if (returned_node != NULL) {
8181 last_node_added = returned_node;
8182 last_node_childless = TRUE;
8183 UpdateNodeText(last_node_added);
8184 } else
8185 ScriptFileParseError(INVALID_NODE_ERR, linenum, 0, NULL);
8186
8187 if (returned_node == NULL || skip_children) {
8188 skip_children = TRUE;
8189 skip_depth = 0;
8190 }
8191 }
8192 }
8193
8194 if (!done)
8195 ScriptFileParseError(UEOS_ERR, linenum, 0, NULL);
8196 }
8197 }
8198
8199 cfclose(infile);
8200
8201 // Add the clipboard node
8202 CreateDefaultClipboardNode();
8203
8204 return TRUE;
8205 }
8206
8207 // VERSION 0: Parses a script node line, and if it's valid, adds it to the given parent
8208 HTREEITEM CDallasMainDlg::ParseScriptNodeLine_v0(char *line, int linenum, HTREEITEM parent, bool &skip_all_children,
8209 HTREEITEM insert_before /*=TVI_LAST*/) {
8210 tTreeNodeData node_data;
8211 bool add_node;
8212 int index;
8213
8214 // Make sure given data is ok
8215 if (line == NULL || parent == NULL || skip_all_children)
8216 return NULL;
8217
8218 // Read in the node type
8219 line = strtok(line, ":");
8220 if (line == NULL)
8221 return NULL;
8222 node_data.type = atoi(line);
8223
8224 // Read in the rest of this node's data
8225 add_node = FALSE;
8226 switch (node_data.type) {
8227 case SCRIPT_HEADER_NODE:
8228 if ((line = strtok(NULL, ":")) == NULL)
8229 return NULL;
8230 node_data.ID = atoi(line);
8231 if ((line = strtok(NULL, "")) == NULL)
8232 return NULL;
8233 strcpy(node_data.name, line);
8234 add_node = TRUE;
8235 break;
8236 case SCRIPT_OWNER_NODE:
8237 if ((line = strtok(NULL, ":")) == NULL)
8238 return NULL;
8239 node_data.ID = atoi(line);
8240 if ((line = strtok(NULL, "")) == NULL)
8241 return NULL;
8242 node_data.int_val = atoi(line);
8243
8244 // Verify object name
8245 if (node_data.ID == OBJECT_TYPE) {
8246 object *objp = ObjGet(node_data.int_val);
8247 if (objp == NULL || objp->type == OBJ_NONE || objp->name == NULL) {
8248 node_data.int_val = OBJECT_HANDLE_NONE;
8249 strcpy(node_data.str_val, "");
8250 } else {
8251 strcpy(node_data.str_val, objp->name);
8252 }
8253 }
8254
8255 // Verify trigger name
8256 if (node_data.ID == TRIGGER_TYPE) {
8257 int t = node_data.int_val;
8258 if (t < 0 || t >= Num_triggers || t >= MAX_NAMED_TRIGGERS || strlen(Triggers[t].name) == 0) {
8259 node_data.int_val = NOT_SPECIFIED_TYPE;
8260 strcpy(node_data.str_val, "");
8261 } else {
8262 strcpy(node_data.str_val, Triggers[t].name);
8263 }
8264 }
8265
8266 add_node = TRUE;
8267 break;
8268 case SCRIPT_EVENT_NODE:
8269 if ((line = strtok(NULL, "")) == NULL)
8270 return NULL;
8271 node_data.ID = atoi(line);
8272 add_node = TRUE;
8273 break;
8274 case CONDITIONAL_HEADER_NODE:
8275 if ((line = strtok(NULL, "")) == NULL)
8276 return NULL;
8277 node_data.ID = atoi(line);
8278 add_node = TRUE;
8279 break;
8280 case ACTIONS_HEADER_NODE:
8281 if ((line = strtok(NULL, ":")) == NULL)
8282 return NULL;
8283 node_data.ID = atoi(line);
8284 if ((line = strtok(NULL, "")) == NULL)
8285 return NULL;
8286 node_data.subID = atoi(line);
8287 add_node = TRUE;
8288 break;
8289 case CONDITIONAL_STATEMENT_NODE:
8290 if ((line = strtok(NULL, "")) == NULL)
8291 return NULL;
8292 node_data.ID = atoi(line);
8293 add_node = TRUE;
8294 break;
8295 case EXPRESSION_NODE:
8296 if ((line = strtok(NULL, ":")) == NULL)
8297 return NULL;
8298 node_data.ID = GetQueryFuncID(line);
8299 if (node_data.ID == INVALID_FUNCTION_ID) {
8300 ScriptFileParseError(INVALID_FUNC_ERR, linenum, GetScriptID(parent), line);
8301 skip_all_children = TRUE;
8302 }
8303 if ((line = strtok(NULL, "")) == NULL)
8304 return NULL;
8305 strcpy(node_data.name, line);
8306 add_node = TRUE;
8307 break;
8308 case EXPRESSION_OPERATOR_NODE:
8309 if ((line = strtok(NULL, ":")) == NULL)
8310 return NULL;
8311 node_data.ID = atoi(line);
8312 if ((line = strtok(NULL, "")) == NULL)
8313 return NULL;
8314 node_data.subID = atoi(line);
8315 add_node = TRUE;
8316 break;
8317 case ACTION_STATEMENT_NODE:
8318 if ((line = strtok(NULL, "")) == NULL)
8319 return NULL;
8320 node_data.ID = GetActionFuncID(line);
8321 if (node_data.ID == INVALID_FUNCTION_ID) {
8322 ScriptFileParseError(INVALID_FUNC_ERR, linenum, GetScriptID(parent), line);
8323 skip_all_children = TRUE;
8324 }
8325 add_node = TRUE;
8326 break;
8327 case LOGICAL_OPERATOR_NODE:
8328 if ((line = strtok(NULL, "")) == NULL)
8329 return NULL;
8330 node_data.ID = atoi(line);
8331 add_node = TRUE;
8332 break;
8333 case PARAMETER_NODE:
8334 if ((line = strtok(NULL, ":")) == NULL)
8335 return NULL;
8336 node_data.ID = atoi(line);
8337
8338 // Get param data based upon what kind of parameter it is
8339 switch (node_data.ID) {
8340 case DOOR_PARAMETER_TYPE:
8341 if ((line = strtok(NULL, ":")) == NULL)
8342 return NULL;
8343 node_data.subID = atoi(line);
8344 if ((line = strtok(NULL, ":")) == NULL)
8345 return NULL;
8346 node_data.int_val = atoi(line);
8347 if ((line = strtok(NULL, "")) == NULL)
8348 return NULL;
8349 strcpy(node_data.name, line);
8350
8351 // Verify door name
8352 if (node_data.subID == USE_OBJECT_HANDLE) {
8353 object *objp = ObjGet(node_data.int_val);
8354 if (objp == NULL || objp->type == OBJ_NONE || objp->name == NULL) {
8355 node_data.int_val = OBJECT_HANDLE_NONE;
8356 strcpy(node_data.str_val, "");
8357 } else {
8358 strcpy(node_data.str_val, objp->name);
8359 }
8360 }
8361
8362 add_node = TRUE;
8363 break;
8364 case OBJECT_PARAMETER_TYPE:
8365 if ((line = strtok(NULL, ":")) == NULL)
8366 return NULL;
8367 node_data.subID = atoi(line);
8368 if ((line = strtok(NULL, ":")) == NULL)
8369 return NULL;
8370 node_data.int_val = atoi(line);
8371 if ((line = strtok(NULL, "")) == NULL)
8372 return NULL;
8373 strcpy(node_data.name, line);
8374
8375 // Verify object name
8376 if (node_data.subID == USE_OBJECT_HANDLE) {
8377 object *objp = ObjGet(node_data.int_val);
8378 if (objp == NULL || objp->type == OBJ_NONE || objp->name == NULL) {
8379 node_data.int_val = OBJECT_HANDLE_NONE;
8380 strcpy(node_data.str_val, "");
8381 } else {
8382 strcpy(node_data.str_val, objp->name);
8383 }
8384 }
8385
8386 add_node = TRUE;
8387 break;
8388 case ROOM_PARAMETER_TYPE:
8389 if ((line = strtok(NULL, ":")) == NULL)
8390 return NULL;
8391 node_data.int_val = atoi(line);
8392 if ((line = strtok(NULL, "")) == NULL)
8393 return NULL;
8394 strcpy(node_data.name, line);
8395
8396 // Verify room name
8397 index = node_data.int_val;
8398 if (index < 0 || index > Highest_room_index || !Rooms[index].used || Rooms[index].name == NULL) {
8399 node_data.int_val = NOT_SPECIFIED_TYPE;
8400 strcpy(node_data.str_val, "");
8401 } else {
8402 strcpy(node_data.str_val, Rooms[index].name);
8403 }
8404
8405 add_node = TRUE;
8406 break;
8407 case TRIGGER_PARAMETER_TYPE:
8408 if ((line = strtok(NULL, ":")) == NULL)
8409 return NULL;
8410 node_data.int_val = atoi(line);
8411 if ((line = strtok(NULL, "")) == NULL)
8412 return NULL;
8413 strcpy(node_data.name, line);
8414
8415 // Verify trigger name
8416 index = node_data.int_val;
8417 if (index < 0 || index >= Num_triggers || index >= MAX_NAMED_TRIGGERS || strlen(Triggers[index].name) == 0) {
8418 node_data.int_val = NOT_SPECIFIED_TYPE;
8419 strcpy(node_data.str_val, "");
8420 } else {
8421 strcpy(node_data.str_val, Triggers[index].name);
8422 }
8423
8424 add_node = TRUE;
8425 break;
8426 case INT_PARAMETER_TYPE:
8427 if ((line = strtok(NULL, ":")) == NULL)
8428 return NULL;
8429 node_data.int_val = atoi(line);
8430 if ((line = strtok(NULL, "")) == NULL)
8431 return NULL;
8432 strcpy(node_data.name, line);
8433 add_node = TRUE;
8434 break;
8435 case BOOL_PARAMETER_TYPE:
8436 if ((line = strtok(NULL, ":")) == NULL)
8437 return NULL;
8438 node_data.int_val = atoi(line);
8439 if ((line = strtok(NULL, "")) == NULL)
8440 return NULL;
8441 strcpy(node_data.name, line);
8442 add_node = TRUE;
8443 break;
8444 case FLOAT_PARAMETER_TYPE:
8445 if ((line = strtok(NULL, ":")) == NULL)
8446 return NULL;
8447 node_data.float_val1 = atof(line);
8448 if ((line = strtok(NULL, "")) == NULL)
8449 return NULL;
8450 strcpy(node_data.name, line);
8451 add_node = TRUE;
8452 break;
8453 case VECTOR_PARAMETER_TYPE:
8454 if ((line = strtok(NULL, ":")) == NULL)
8455 return NULL;
8456 node_data.float_val1 = atof(line);
8457 if ((line = strtok(NULL, ":")) == NULL)
8458 return NULL;
8459 node_data.float_val2 = atof(line);
8460 if ((line = strtok(NULL, ":")) == NULL)
8461 return NULL;
8462 node_data.float_val3 = atof(line);
8463 if ((line = strtok(NULL, "")) == NULL)
8464 return NULL;
8465 strcpy(node_data.name, line);
8466 add_node = TRUE;
8467 break;
8468 case STRING_PARAMETER_TYPE:
8469 if ((line = strtok(NULL, ":")) == NULL)
8470 return NULL;
8471 strcpy(node_data.str_val, line);
8472 if (FindMessageInList(line) == NULL) {
8473 strcpy(node_data.str_val, "");
8474 if (strcmp(line, NOT_SPECIFIED_MSG) != 0)
8475 ScriptFileParseError(INVALID_MSGID_ERR, linenum, GetScriptID(parent), line);
8476 }
8477 if ((line = strtok(NULL, "")) == NULL)
8478 return NULL;
8479 strcpy(node_data.name, line);
8480 add_node = TRUE;
8481 break;
8482 case PERCENTAGE_PARAMETER_TYPE:
8483 if ((line = strtok(NULL, ":")) == NULL)
8484 return NULL;
8485 node_data.float_val1 = atof(line);
8486 if ((line = strtok(NULL, "")) == NULL)
8487 return NULL;
8488 strcpy(node_data.name, line);
8489 add_node = TRUE;
8490 break;
8491 case ENUM_PARAMETER_TYPE:
8492 if ((line = strtok(NULL, ":")) == NULL)
8493 return NULL;
8494 node_data.int_val = atoi(line);
8495 if ((line = strtok(NULL, "")) == NULL)
8496 return NULL;
8497 strcpy(node_data.name, line);
8498 add_node = TRUE;
8499 break;
8500 case SCRIPT_PARAMETER_TYPE:
8501 if ((line = strtok(NULL, ":")) == NULL)
8502 return NULL;
8503 node_data.int_val = atoi(line);
8504 if ((line = strtok(NULL, "")) == NULL)
8505 return NULL;
8506 strcpy(node_data.name, line);
8507 add_node = TRUE;
8508 break;
8509 case SOUND_PARAMETER_TYPE:
8510 if ((line = strtok(NULL, ":")) == NULL)
8511 return NULL;
8512 index = atoi(line);
8513 if (index < 0 || index >= m_SoundListSize)
8514 node_data.int_val = -1;
8515 else
8516 node_data.int_val = FindSoundName(m_SoundList[atoi(line)]);
8517
8518 if (node_data.int_val < 0) {
8519 node_data.int_val = NOT_SPECIFIED_TYPE;
8520 strcpy(node_data.str_val, "");
8521
8522 // Display warning message here...
8523 } else {
8524 strcpy(node_data.str_val, m_SoundList[atoi(line)]);
8525 }
8526 if ((line = strtok(NULL, "")) == NULL)
8527 return NULL;
8528 strcpy(node_data.name, line);
8529 add_node = TRUE;
8530 break;
8531 case SPECNAME_PARAMETER_TYPE:
8532 if ((line = strtok(NULL, ":")) == NULL)
8533 return NULL;
8534 strcpy(node_data.str_val, line);
8535 if ((line = strtok(NULL, "")) == NULL)
8536 return NULL;
8537 strcpy(node_data.name, line);
8538 add_node = TRUE;
8539 break;
8540 case TEXTURE_PARAMETER_TYPE:
8541 if ((line = strtok(NULL, ":")) == NULL)
8542 return NULL;
8543 index = atoi(line);
8544 if (index < 0 || index >= m_TextureListSize)
8545 node_data.int_val = -1;
8546 else
8547 node_data.int_val = FindTextureName(m_TextureList[atoi(line)]);
8548
8549 if (node_data.int_val < 0) {
8550 node_data.int_val = NOT_SPECIFIED_TYPE;
8551 strcpy(node_data.str_val, "");
8552
8553 // Display warning message here...
8554 } else {
8555 strcpy(node_data.str_val, m_TextureList[atoi(line)]);
8556 }
8557 if ((line = strtok(NULL, "")) == NULL)
8558 return NULL;
8559 strcpy(node_data.name, line);
8560 add_node = TRUE;
8561 break;
8562 case FLAG_PARAMETER_TYPE:
8563 if ((line = strtok(NULL, ":")) == NULL)
8564 return NULL;
8565 node_data.int_val = atoi(line);
8566 if ((line = strtok(NULL, "")) == NULL)
8567 return NULL;
8568 strcpy(node_data.name, line);
8569 add_node = TRUE;
8570 break;
8571 case PATH_PARAMETER_TYPE:
8572 if ((line = strtok(NULL, ":")) == NULL)
8573 return NULL;
8574 index = atoi(line);
8575 if (index < 0 || index >= m_PathListSize)
8576 node_data.int_val = -1;
8577 else
8578 node_data.int_val = osipf_FindPathName(m_PathList[index]);
8579
8580 if (node_data.int_val < 0) {
8581 node_data.int_val = NOT_SPECIFIED_TYPE;
8582 strcpy(node_data.str_val, "");
8583
8584 // Display warning message here...
8585 } else {
8586 strcpy(node_data.str_val, m_PathList[index]);
8587 }
8588 if ((line = strtok(NULL, "")) == NULL)
8589 return NULL;
8590 strcpy(node_data.name, line);
8591 add_node = TRUE;
8592 break;
8593 case MATCEN_PARAMETER_TYPE:
8594 if ((line = strtok(NULL, ":")) == NULL)
8595 return NULL;
8596 node_data.subID = atoi(line);
8597 if ((line = strtok(NULL, ":")) == NULL)
8598 return NULL;
8599 index = atoi(line);
8600 if (index < 0 || index >= m_MatcenListSize)
8601 node_data.int_val = -1;
8602 else
8603 node_data.int_val = osipf_FindMatcenName(m_MatcenList[index]);
8604
8605 if (node_data.int_val < 0) {
8606 node_data.int_val = NOT_SPECIFIED_TYPE;
8607 strcpy(node_data.str_val, "");
8608
8609 // Display warning message here...
8610 } else {
8611 strcpy(node_data.str_val, m_MatcenList[index]);
8612 }
8613 if ((line = strtok(NULL, "")) == NULL)
8614 return NULL;
8615 strcpy(node_data.name, line);
8616 add_node = TRUE;
8617 break;
8618 case LEVEL_GOAL_PARAMETER_TYPE:
8619 if ((line = strtok(NULL, ":")) == NULL)
8620 return NULL;
8621 node_data.subID = atoi(line);
8622 if ((line = strtok(NULL, ":")) == NULL)
8623 return NULL;
8624 index = atoi(line);
8625 if (index < 0 || index >= m_GoalListSize)
8626 node_data.int_val = -1;
8627 else
8628 node_data.int_val = osipf_FindLevelGoalName(m_GoalList[index]);
8629
8630 if (node_data.int_val < 0) {
8631 node_data.int_val = NOT_SPECIFIED_TYPE;
8632 strcpy(node_data.str_val, "");
8633
8634 // Display warning message here...
8635 } else {
8636 strcpy(node_data.str_val, m_GoalList[index]);
8637 }
8638 if ((line = strtok(NULL, "")) == NULL)
8639 return NULL;
8640 strcpy(node_data.name, line);
8641 add_node = TRUE;
8642 break;
8643 case STRM_AUDIO_PARAMETER_TYPE:
8644 if ((line = strtok(NULL, ":")) == NULL)
8645 return NULL;
8646 index = atoi(line);
8647 if (index < 0 || index >= m_StrmAudioListSize || !GamefileExists(m_StrmAudioList[index]))
8648 strcpy(node_data.str_val, "");
8649 else {
8650 strcpy(node_data.str_val, m_StrmAudioList[index]);
8651
8652 // Display warning message here...
8653 }
8654 if ((line = strtok(NULL, "")) == NULL)
8655 return NULL;
8656 strcpy(node_data.name, line);
8657 add_node = TRUE;
8658 break;
8659 default:
8660 break;
8661 }
8662 break;
8663 case PARAMETER_OPERATOR_NODE:
8664 break;
8665 case UNKNOWN_NODE:
8666 break;
8667 default:
8668 break;
8669 }
8670
8671 if (add_node)
8672 return (AddNodeToTree(parent, insert_before, &node_data));
8673
8674 return NULL;
8675 }
8676
8677 // VERSION 1: Parses a script node line, and if it's valid, adds it to the given parent
8678 HTREEITEM CDallasMainDlg::ParseScriptNodeLine_v1U(char *line, int linenum, HTREEITEM parent, bool &skip_all_children,
8679 int version, HTREEITEM insert_before /*=TVI_LAST*/) {
8680 tTreeNodeData node_data;
8681 bool add_node;
8682 int index;
8683 int scriptID;
8684
8685 // Make sure given data is ok
8686 if (line == NULL || parent == NULL || skip_all_children)
8687 return NULL;
8688
8689 // Determine what script we're in
8690 scriptID = -1;
8691 if (parent != TVI_ROOT)
8692 scriptID = GetScriptID(parent);
8693
8694 // Read in the node type
8695 line = strtok(line, ":");
8696 if (line == NULL)
8697 return NULL;
8698 node_data.type = atoi(line);
8699
8700 // Read in the rest of this node's data
8701 add_node = FALSE;
8702 switch (node_data.type) {
8703 case SCRIPT_HEADER_NODE:
8704 if ((line = strtok(NULL, ":")) == NULL)
8705 return NULL;
8706 node_data.ID = atoi(line);
8707 if ((line = strtok(NULL, "")) == NULL)
8708 return NULL;
8709 strcpy(node_data.name, line);
8710 add_node = TRUE;
8711 break;
8712 case SCRIPT_OWNER_NODE:
8713 if ((line = strtok(NULL, ":")) == NULL)
8714 return NULL;
8715 node_data.ID = atoi(line);
8716 if ((line = strtok(NULL, "")) == NULL)
8717 return NULL;
8718 index = atoi(line);
8719
8720 if (node_data.ID == OBJECT_TYPE) {
8721 if (index >= 0 && index < m_ObjectListSize) {
8722 node_data.int_val = osipf_FindObjectName(m_ObjectList[index]);
8723 if (node_data.int_val != OBJECT_HANDLE_NONE) {
8724 strcpy(node_data.str_val, m_ObjectList[index]);
8725 } else {
8726 strcpy(node_data.str_val, "");
8727 SpecialScriptFileParseError(linenum, scriptID, "Object Script Owner", m_ObjectList[index]);
8728 }
8729 } else {
8730 node_data.int_val = OBJECT_HANDLE_NONE;
8731 strcpy(node_data.str_val, "");
8732 }
8733 } else if (node_data.ID == TRIGGER_TYPE) {
8734 if (index >= 0 && index < m_TriggerListSize) {
8735 node_data.int_val = osipf_FindTriggerName(m_TriggerList[index]);
8736 if (node_data.int_val >= 0) {
8737 strcpy(node_data.str_val, m_TriggerList[index]);
8738 } else {
8739 node_data.int_val = NOT_SPECIFIED_TYPE;
8740 strcpy(node_data.str_val, "");
8741 SpecialScriptFileParseError(linenum, scriptID, "Trigger Script Owner", m_TriggerList[index]);
8742 }
8743 } else {
8744 node_data.int_val = NOT_SPECIFIED_TYPE;
8745 strcpy(node_data.str_val, "");
8746 }
8747 } else {
8748 node_data.int_val = index;
8749 strcpy(node_data.str_val, "");
8750 }
8751
8752 add_node = TRUE;
8753 break;
8754 case SCRIPT_EVENT_NODE:
8755 if ((line = strtok(NULL, "")) == NULL)
8756 return NULL;
8757 node_data.ID = atoi(line);
8758 add_node = TRUE;
8759 break;
8760 case CONDITIONAL_HEADER_NODE:
8761 if ((line = strtok(NULL, "")) == NULL)
8762 return NULL;
8763 node_data.ID = atoi(line);
8764 add_node = TRUE;
8765 break;
8766 case ACTIONS_HEADER_NODE:
8767 if ((line = strtok(NULL, ":")) == NULL)
8768 return NULL;
8769 node_data.ID = atoi(line);
8770 if (version >= 3) {
8771 if ((line = strtok(NULL, ":")) == NULL)
8772 return NULL;
8773 node_data.int_val = atoi(line);
8774 } else {
8775 node_data.int_val = CONTINUE_SCRIPT_CHAIN;
8776 }
8777 if ((line = strtok(NULL, "")) == NULL)
8778 return NULL;
8779 node_data.subID = atoi(line);
8780 add_node = TRUE;
8781 break;
8782 case CONDITIONAL_STATEMENT_NODE:
8783 if ((line = strtok(NULL, "")) == NULL)
8784 return NULL;
8785 node_data.ID = atoi(line);
8786 add_node = TRUE;
8787 break;
8788 case EXPRESSION_NODE:
8789 if ((line = strtok(NULL, ":")) == NULL)
8790 return NULL;
8791 node_data.ID = GetQueryFuncID(line);
8792 if (node_data.ID == INVALID_FUNCTION_ID) {
8793 ScriptFileParseError(INVALID_FUNC_ERR, linenum, scriptID, line);
8794 skip_all_children = TRUE;
8795 }
8796 if ((line = strtok(NULL, "")) == NULL)
8797 return NULL;
8798 strcpy(node_data.name, line);
8799 add_node = TRUE;
8800 break;
8801 case EXPRESSION_OPERATOR_NODE:
8802 if ((line = strtok(NULL, ":")) == NULL)
8803 return NULL;
8804 node_data.ID = atoi(line);
8805 if ((line = strtok(NULL, "")) == NULL)
8806 return NULL;
8807 node_data.subID = atoi(line);
8808 add_node = TRUE;
8809 break;
8810 case ACTION_STATEMENT_NODE:
8811 if ((line = strtok(NULL, "")) == NULL)
8812 return NULL;
8813 node_data.ID = GetActionFuncID(line);
8814 if (node_data.ID == INVALID_FUNCTION_ID) {
8815 ScriptFileParseError(INVALID_FUNC_ERR, linenum, scriptID, line);
8816 skip_all_children = TRUE;
8817 }
8818 add_node = TRUE;
8819 break;
8820 case LOGICAL_OPERATOR_NODE:
8821 if ((line = strtok(NULL, "")) == NULL)
8822 return NULL;
8823 node_data.ID = atoi(line);
8824 add_node = TRUE;
8825 break;
8826 case PARAMETER_NODE:
8827 if ((line = strtok(NULL, ":")) == NULL)
8828 return NULL;
8829 node_data.ID = atoi(line);
8830
8831 // Get param data based upon what kind of parameter it is
8832 switch (node_data.ID) {
8833 case DOOR_PARAMETER_TYPE:
8834 if ((line = strtok(NULL, ":")) == NULL)
8835 return NULL;
8836 node_data.subID = atoi(line);
8837 if ((line = strtok(NULL, ":")) == NULL)
8838 return NULL;
8839 index = atoi(line);
8840 if ((line = strtok(NULL, "")) == NULL)
8841 return NULL;
8842 strcpy(node_data.name, line);
8843
8844 if (node_data.subID == USE_OBJECT_HANDLE) {
8845 if (index >= 0 && index < m_DoorListSize) {
8846 node_data.int_val = osipf_FindDoorName(m_DoorList[index]);
8847 if (node_data.int_val != OBJECT_HANDLE_NONE) {
8848 strcpy(node_data.str_val, m_DoorList[index]);
8849 } else {
8850 strcpy(node_data.str_val, "");
8851 SpecialScriptFileParseError(linenum, scriptID, "Door", m_DoorList[index]);
8852 }
8853 } else {
8854 node_data.int_val = OBJECT_HANDLE_NONE;
8855 strcpy(node_data.str_val, "");
8856 }
8857 } else {
8858 node_data.int_val = OBJECT_HANDLE_NONE;
8859 strcpy(node_data.str_val, "");
8860 }
8861
8862 add_node = TRUE;
8863 break;
8864 case OBJECT_PARAMETER_TYPE:
8865 if ((line = strtok(NULL, ":")) == NULL)
8866 return NULL;
8867 node_data.subID = atoi(line);
8868 if ((line = strtok(NULL, ":")) == NULL)
8869 return NULL;
8870 index = atoi(line);
8871 if ((line = strtok(NULL, "")) == NULL)
8872 return NULL;
8873 strcpy(node_data.name, line);
8874
8875 if (node_data.subID == USE_OBJECT_HANDLE) {
8876 if (index >= 0 && index < m_ObjectListSize) {
8877 node_data.int_val = osipf_FindObjectName(m_ObjectList[index]);
8878 if (node_data.int_val != OBJECT_HANDLE_NONE) {
8879 strcpy(node_data.str_val, m_ObjectList[index]);
8880 } else {
8881 strcpy(node_data.str_val, "");
8882 SpecialScriptFileParseError(linenum, scriptID, "Object", m_ObjectList[index]);
8883 }
8884 } else {
8885 node_data.int_val = OBJECT_HANDLE_NONE;
8886 strcpy(node_data.str_val, "");
8887 }
8888 } else {
8889 node_data.int_val = OBJECT_HANDLE_NONE;
8890 strcpy(node_data.str_val, "");
8891 }
8892
8893 add_node = TRUE;
8894 break;
8895 case ROOM_PARAMETER_TYPE:
8896 if ((line = strtok(NULL, ":")) == NULL)
8897 return NULL;
8898 index = atoi(line);
8899 if ((line = strtok(NULL, "")) == NULL)
8900 return NULL;
8901 strcpy(node_data.name, line);
8902
8903 if (index >= 0 && index < m_RoomListSize) {
8904 node_data.int_val = osipf_FindRoomName(m_RoomList[index]);
8905 if (node_data.int_val >= 0) {
8906 strcpy(node_data.str_val, m_RoomList[index]);
8907 } else {
8908 node_data.int_val = NOT_SPECIFIED_TYPE;
8909 strcpy(node_data.str_val, "");
8910 SpecialScriptFileParseError(linenum, scriptID, "Room", m_RoomList[index]);
8911 }
8912 } else {
8913 node_data.int_val = NOT_SPECIFIED_TYPE;
8914 strcpy(node_data.str_val, "");
8915 }
8916
8917 add_node = TRUE;
8918 break;
8919 case TRIGGER_PARAMETER_TYPE:
8920 if ((line = strtok(NULL, ":")) == NULL)
8921 return NULL;
8922 index = atoi(line);
8923 if ((line = strtok(NULL, "")) == NULL)
8924 return NULL;
8925 strcpy(node_data.name, line);
8926
8927 if (index >= 0 && index < m_TriggerListSize) {
8928 node_data.int_val = osipf_FindTriggerName(m_TriggerList[index]);
8929 if (node_data.int_val >= 0) {
8930 strcpy(node_data.str_val, m_TriggerList[index]);
8931 } else {
8932 node_data.int_val = NOT_SPECIFIED_TYPE;
8933 strcpy(node_data.str_val, "");
8934 SpecialScriptFileParseError(linenum, scriptID, "Trigger", m_TriggerList[index]);
8935 }
8936 } else {
8937 node_data.int_val = NOT_SPECIFIED_TYPE;
8938 strcpy(node_data.str_val, "");
8939 }
8940
8941 add_node = TRUE;
8942 break;
8943 case INT_PARAMETER_TYPE:
8944 if ((line = strtok(NULL, ":")) == NULL)
8945 return NULL;
8946 node_data.int_val = atoi(line);
8947 if ((line = strtok(NULL, "")) == NULL)
8948 return NULL;
8949 strcpy(node_data.name, line);
8950 add_node = TRUE;
8951 break;
8952 case BOOL_PARAMETER_TYPE:
8953 if ((line = strtok(NULL, ":")) == NULL)
8954 return NULL;
8955 node_data.int_val = atoi(line);
8956 if ((line = strtok(NULL, "")) == NULL)
8957 return NULL;
8958 strcpy(node_data.name, line);
8959 add_node = TRUE;
8960 break;
8961 case FLOAT_PARAMETER_TYPE:
8962 if ((line = strtok(NULL, ":")) == NULL)
8963 return NULL;
8964 node_data.float_val1 = atof(line);
8965 if ((line = strtok(NULL, "")) == NULL)
8966 return NULL;
8967 strcpy(node_data.name, line);
8968 add_node = TRUE;
8969 break;
8970 case VECTOR_PARAMETER_TYPE:
8971 if ((line = strtok(NULL, ":")) == NULL)
8972 return NULL;
8973 node_data.float_val1 = atof(line);
8974 if ((line = strtok(NULL, ":")) == NULL)
8975 return NULL;
8976 node_data.float_val2 = atof(line);
8977 if ((line = strtok(NULL, ":")) == NULL)
8978 return NULL;
8979 node_data.float_val3 = atof(line);
8980 if ((line = strtok(NULL, "")) == NULL)
8981 return NULL;
8982 strcpy(node_data.name, line);
8983 add_node = TRUE;
8984 break;
8985 case STRING_PARAMETER_TYPE:
8986 if ((line = strtok(NULL, ":")) == NULL)
8987 return NULL;
8988 strcpy(node_data.str_val, line);
8989 if ((line = strtok(NULL, "")) == NULL)
8990 return NULL;
8991 strcpy(node_data.name, line);
8992
8993 if (FindMessageInList(node_data.str_val) == NULL) {
8994 if (strcmp(node_data.str_val, NOT_SPECIFIED_MSG) != 0)
8995 ScriptFileParseError(INVALID_MSGID_ERR, linenum, scriptID, line);
8996 strcpy(node_data.str_val, "");
8997 }
8998
8999 add_node = TRUE;
9000 break;
9001 case PERCENTAGE_PARAMETER_TYPE:
9002 if ((line = strtok(NULL, ":")) == NULL)
9003 return NULL;
9004 node_data.float_val1 = atof(line);
9005 if ((line = strtok(NULL, "")) == NULL)
9006 return NULL;
9007 strcpy(node_data.name, line);
9008 add_node = TRUE;
9009 break;
9010 case ENUM_PARAMETER_TYPE:
9011 if (version >= 2) {
9012 if ((line = strtok(NULL, ":")) == NULL)
9013 return NULL;
9014 node_data.subID = atoi(line);
9015 } else {
9016 node_data.subID = USE_ENUM_VALUE;
9017 }
9018 if ((line = strtok(NULL, ":")) == NULL)
9019 return NULL;
9020 node_data.int_val = atoi(line);
9021 if ((line = strtok(NULL, "")) == NULL)
9022 return NULL;
9023 strcpy(node_data.name, line);
9024 add_node = TRUE;
9025 break;
9026 case SCRIPT_PARAMETER_TYPE:
9027 if ((line = strtok(NULL, ":")) == NULL)
9028 return NULL;
9029 node_data.int_val = atoi(line);
9030 if ((line = strtok(NULL, "")) == NULL)
9031 return NULL;
9032 strcpy(node_data.name, line);
9033 add_node = TRUE;
9034 break;
9035 case SOUND_PARAMETER_TYPE:
9036 if ((line = strtok(NULL, ":")) == NULL)
9037 return NULL;
9038 index = atoi(line);
9039 if ((line = strtok(NULL, "")) == NULL)
9040 return NULL;
9041 strcpy(node_data.name, line);
9042
9043 if (index >= 0 && index < m_SoundListSize) {
9044 node_data.int_val = osipf_FindSoundName(m_SoundList[index]);
9045 if (node_data.int_val >= 0) {
9046 strcpy(node_data.str_val, m_SoundList[index]);
9047 } else {
9048 node_data.int_val = NOT_SPECIFIED_TYPE;
9049 strcpy(node_data.str_val, "");
9050 SpecialScriptFileParseError(linenum, scriptID, "Sound", m_SoundList[index]);
9051 }
9052 } else {
9053 node_data.int_val = NOT_SPECIFIED_TYPE;
9054 strcpy(node_data.str_val, "");
9055 }
9056
9057 add_node = TRUE;
9058 break;
9059 case SPECNAME_PARAMETER_TYPE:
9060 if ((line = strtok(NULL, ":")) == NULL)
9061 return NULL;
9062 index = atoi(line);
9063 if ((line = strtok(NULL, "")) == NULL)
9064 return NULL;
9065 strcpy(node_data.name, line);
9066
9067 if (index >= 0 && index < m_SpecnameListSize)
9068 strcpy(node_data.str_val, m_SpecnameList[index]);
9069 else
9070 strcpy(node_data.str_val, "");
9071
9072 add_node = TRUE;
9073 break;
9074 case TEXTURE_PARAMETER_TYPE:
9075 if ((line = strtok(NULL, ":")) == NULL)
9076 return NULL;
9077 index = atoi(line);
9078 if ((line = strtok(NULL, "")) == NULL)
9079 return NULL;
9080 strcpy(node_data.name, line);
9081
9082 if (index >= 0 && index < m_TextureListSize) {
9083 node_data.int_val = osipf_FindTextureName(m_TextureList[index]);
9084 if (node_data.int_val >= 0) {
9085 strcpy(node_data.str_val, m_TextureList[index]);
9086 } else {
9087 node_data.int_val = NOT_SPECIFIED_TYPE;
9088 strcpy(node_data.str_val, "");
9089 SpecialScriptFileParseError(linenum, scriptID, "Texture", m_TextureList[index]);
9090 }
9091 } else {
9092 node_data.int_val = NOT_SPECIFIED_TYPE;
9093 strcpy(node_data.str_val, "");
9094 }
9095
9096 add_node = TRUE;
9097 break;
9098 case FLAG_PARAMETER_TYPE:
9099 if ((line = strtok(NULL, ":")) == NULL)
9100 return NULL;
9101 node_data.int_val = atoi(line);
9102 if ((line = strtok(NULL, "")) == NULL)
9103 return NULL;
9104 strcpy(node_data.name, line);
9105 add_node = TRUE;
9106 break;
9107 case PATH_PARAMETER_TYPE:
9108 if ((line = strtok(NULL, ":")) == NULL)
9109 return NULL;
9110 index = atoi(line);
9111 if ((line = strtok(NULL, "")) == NULL)
9112 return NULL;
9113 strcpy(node_data.name, line);
9114
9115 if (index >= 0 && index < m_PathListSize) {
9116 node_data.int_val = osipf_FindPathName(m_PathList[index]);
9117 if (node_data.int_val >= 0) {
9118 strcpy(node_data.str_val, m_PathList[index]);
9119 } else {
9120 node_data.int_val = NOT_SPECIFIED_TYPE;
9121 strcpy(node_data.str_val, "");
9122 SpecialScriptFileParseError(linenum, scriptID, "Path", m_PathList[index]);
9123 }
9124 } else {
9125 node_data.int_val = NOT_SPECIFIED_TYPE;
9126 strcpy(node_data.str_val, "");
9127 }
9128
9129 add_node = TRUE;
9130 break;
9131 case MATCEN_PARAMETER_TYPE:
9132 if ((line = strtok(NULL, ":")) == NULL)
9133 return NULL;
9134 node_data.subID = atoi(line);
9135 if ((line = strtok(NULL, ":")) == NULL)
9136 return NULL;
9137 index = atoi(line);
9138 if ((line = strtok(NULL, "")) == NULL)
9139 return NULL;
9140 strcpy(node_data.name, line);
9141
9142 if (index >= 0 && index < m_MatcenListSize) {
9143 node_data.int_val = osipf_FindMatcenName(m_MatcenList[index]);
9144 if (node_data.int_val >= 0) {
9145 strcpy(node_data.str_val, m_MatcenList[index]);
9146 } else {
9147 node_data.int_val = NOT_SPECIFIED_TYPE;
9148 strcpy(node_data.str_val, "");
9149 SpecialScriptFileParseError(linenum, scriptID, "Matcen", m_MatcenList[index]);
9150 }
9151 } else {
9152 node_data.int_val = NOT_SPECIFIED_TYPE;
9153 strcpy(node_data.str_val, "");
9154 }
9155
9156 add_node = TRUE;
9157 break;
9158 case LEVEL_GOAL_PARAMETER_TYPE:
9159 if ((line = strtok(NULL, ":")) == NULL)
9160 return NULL;
9161 node_data.subID = atoi(line);
9162 if ((line = strtok(NULL, ":")) == NULL)
9163 return NULL;
9164 index = atoi(line);
9165 if ((line = strtok(NULL, "")) == NULL)
9166 return NULL;
9167 strcpy(node_data.name, line);
9168
9169 if (index >= 0 && index < m_GoalListSize) {
9170 node_data.int_val = osipf_FindLevelGoalName(m_GoalList[index]);
9171 if (node_data.int_val >= 0) {
9172 strcpy(node_data.str_val, m_GoalList[index]);
9173 } else {
9174 node_data.int_val = NOT_SPECIFIED_TYPE;
9175 strcpy(node_data.str_val, "");
9176 SpecialScriptFileParseError(linenum, scriptID, "Level Goal", m_GoalList[index]);
9177 }
9178 } else {
9179 node_data.int_val = NOT_SPECIFIED_TYPE;
9180 strcpy(node_data.str_val, "");
9181 }
9182
9183 add_node = TRUE;
9184 break;
9185 case STRM_AUDIO_PARAMETER_TYPE:
9186 if ((line = strtok(NULL, ":")) == NULL)
9187 return NULL;
9188 index = atoi(line);
9189 if ((line = strtok(NULL, "")) == NULL)
9190 return NULL;
9191 strcpy(node_data.name, line);
9192
9193 if (index >= 0 && index < m_StrmAudioListSize) {
9194 if (GamefileExists(m_StrmAudioList[index])) {
9195 strcpy(node_data.str_val, m_StrmAudioList[index]);
9196 } else {
9197 strcpy(node_data.str_val, "");
9198 SpecialScriptFileParseError(linenum, scriptID, "Streaming Audio File", m_StrmAudioList[index]);
9199 }
9200 } else {
9201 strcpy(node_data.str_val, "");
9202 }
9203
9204 add_node = TRUE;
9205 break;
9206 default:
9207 break;
9208 }
9209 break;
9210 case PARAMETER_OPERATOR_NODE:
9211 break;
9212 case UNKNOWN_NODE:
9213 break;
9214 default:
9215 break;
9216 }
9217
9218 if (add_node)
9219 return (AddNodeToTree(parent, insert_before, &node_data));
9220
9221 return NULL;
9222 }
9223
9224 // Handle Special Parse Errors (Invalid Named Values)
9225 void CDallasMainDlg::SpecialScriptFileParseError(int linenum, int script_ID, char *type_name, const char *name) {
9226 CString err_msg;
9227
9228 if (name == NULL || type_name == NULL)
9229 return;
9230
9231 err_msg.Format("ERROR: An invalid %s (%s) was encountered in %s, line %d.\n\n"
9232 "Hence, Script #%d now contains a %s that needs to be replaced.",
9233 type_name, name, CurrentParsingFilename.GetBuffer(0), linenum, script_ID, type_name);
9234
9235 MessageBox(err_msg, "Script File Parse Error", MB_OK | MB_ICONEXCLAMATION);
9236 }
9237
9238 // Validates a function node by conforming its parameters to what they should be
9239 // returns FALSE if node was modified significantly, otherwise TRUE
9240 bool CDallasMainDlg::ValidateFunctionNode(HTREEITEM node, int linenum) {
9241 tTreeNodeData *data;
9242
9243 if (node == NULL)
9244 return TRUE;
9245
9246 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
9247 if (data == NULL)
9248 return TRUE;
9249
9250 if (data->type == EXPRESSION_NODE)
9251 return (ValidateQueryNode(node, linenum));
9252 if (data->type == ACTION_STATEMENT_NODE)
9253 return (ValidateActionNode(node, linenum));
9254
9255 return TRUE;
9256 }
9257
9258 // Reads in the message list from a file
9259 int CDallasMainDlg::ParseMsgTableFile(char *filename) {
9260 CFILE *infile;
9261 char filebuffer[MAX_MSG_FILE_BUFFER_LEN];
9262 char *line, *msg_start;
9263 int line_num;
9264 bool next_msgid_found;
9265 char fullpath[_MAX_PATH];
9266
9267 ddio_MakePath(fullpath, LocalScriptDir, filename, NULL);
9268
9269 // Try to open the file for loading
9270 infile = cfopen(fullpath, "rt");
9271 if (!infile) {
9272 CString msg;
9273 msg.Format("Unable to open \"%s\"!", filename);
9274 MessageBox(msg, "Script Message File Error!", MB_OK | MB_ICONEXCLAMATION);
9275 return FALSE;
9276 }
9277
9278 line_num = 0;
9279 next_msgid_found = FALSE;
9280
9281 // Read in and parse each line of the file
9282 while (!cfeof(infile)) {
9283
9284 // Clear the buffer
9285 strcpy(filebuffer, "");
9286
9287 // Read in a line from the file
9288 cf_ReadString(filebuffer, MAX_MSG_FILE_BUFFER_LEN, infile);
9289 line_num++;
9290
9291 // Remove whitespace padding at start and end of line
9292 RemoveTrailingWhitespace(filebuffer);
9293 line = SkipInitialWhitespace(filebuffer);
9294
9295 // If line is a comment, or empty, discard it
9296 if (strlen(line) == 0 || strncmp(line, "//", 2) == 0)
9297 continue;
9298
9299 if (!next_msgid_found) { // Parse out the last message ID number
9300
9301 // Grab the first keyword, make sure it's valid
9302 line = strtok(line, WHITESPACE_CHARS);
9303 if (line == NULL || strcmp(line, NEXT_MSG_ID_NUM_KEYWORD) != 0)
9304 continue;
9305
9306 // Grab the second keyword, and assign it as the next message ID
9307 line = strtok(NULL, WHITESPACE_CHARS);
9308 if (line == NULL)
9309 continue;
9310 m_NextMessageID = atoi(line);
9311
9312 next_msgid_found = TRUE;
9313 } else { // Parse line as a message line
9314
9315 // Find the start of message, and mark it
9316 msg_start = strchr(line, '=');
9317 if (msg_start == NULL)
9318 continue;
9319 msg_start[0] = '\0';
9320 msg_start++;
9321
9322 // Add the message to the list
9323 AddToMessageList(line, msg_start);
9324 }
9325 }
9326
9327 cfclose(infile);
9328
9329 return TRUE;
9330 }
9331
9332 ///////////////////////////////////
9333 // Custom Script Block Functions
9334 ///////////////////////////////////
9335
9336 // Initializes the data storage space
9337 void CDallasMainDlg::InitCustomScriptStorage(void) {
9338 m_CustomScriptLines = NULL;
9339
9340 m_NumCustomScriptLines = 0;
9341 m_MaxNumCustomScriptLines = 0;
9342 }
9343
9344 // Clears any memory allocated for storage
9345 void CDallasMainDlg::ClearCustomScriptStorage(void) {
9346 // Clear all the lines
9347 for (int j = 0; j < m_NumCustomScriptLines; j++) {
9348 mem_free(m_CustomScriptLines[j]);
9349 m_CustomScriptLines[j] = NULL;
9350 }
9351
9352 // Clear the array of line pointers
9353 if (m_CustomScriptLines != NULL) {
9354 mem_free(m_CustomScriptLines);
9355 m_CustomScriptLines = NULL;
9356 }
9357
9358 m_NumCustomScriptLines = 0;
9359 m_MaxNumCustomScriptLines = 0;
9360 }
9361
9362 // Scans the file for the custom script block and count how many lines are in it
9363 int CDallasMainDlg::CountCustomScriptLines(CFILE *infile) {
9364 int32_t start_pos;
9365 int line_count;
9366 char linebuf[2048];
9367 bool done;
9368
9369 line_count = 0;
9370 done = false;
9371
9372 // Save the current file position
9373 start_pos = cftell(infile);
9374
9375 // Read all the lines in the block
9376 while (!done && !cfeof(infile)) {
9377
9378 strcpy(linebuf, "");
9379 cf_ReadString(linebuf, sizeof(linebuf), infile);
9380
9381 // Check for End of Script Block Section
9382 if (strncmp(linebuf, CUSTOM_SCRIPT_BLOCK_END_TAG, strlen(CUSTOM_SCRIPT_BLOCK_END_TAG)) == 0) {
9383 done = true;
9384 continue;
9385 }
9386
9387 // If it's not the end of custom block tag, then it's a line we need to save
9388 line_count++;
9389 }
9390
9391 // Move file pointer back to the original starting position
9392 cfseek(infile, start_pos, SEEK_SET);
9393
9394 return (line_count);
9395 }
9396
9397 // Reads in and stores all the lines in the custom script block
9398 int CDallasMainDlg::ParseCustomScriptFile(char *filename, bool show_errors /*=TRUE*/) {
9399 CFILE *infile;
9400 char linebuf[2048];
9401 char *line;
9402 int linenum;
9403 char fullpath[_MAX_PATH];
9404
9405 CurrentParsingFilename = m_ScriptFilename;
9406
9407 ddio_MakePath(fullpath, LocalScriptDir, filename, NULL);
9408
9409 // Try to open the file for loading
9410 infile = cfopen(fullpath, "rt");
9411 if (!infile) {
9412 if (show_errors) {
9413 CString msg;
9414 msg.Format("Unable to open \"%s\"!", filename);
9415 MessageBox(msg, "No Custom Script Source File Found!", MB_OK | MB_ICONEXCLAMATION);
9416 }
9417 return FALSE;
9418 }
9419
9420 linenum = 0;
9421
9422 // Read in and parse each line of the file
9423 while (!cfeof(infile)) {
9424
9425 // Clear the buffer
9426 strcpy(linebuf, "");
9427
9428 // Read in a line from the file
9429 cf_ReadString(linebuf, sizeof(linebuf), infile);
9430 linenum++;
9431
9432 // Remove whitespace padding at start and end of line
9433 RemoveTrailingWhitespace(linebuf);
9434 line = SkipInitialWhitespace(linebuf);
9435
9436 // Check for Start of Script Block Section
9437 if (strncmp(line, CUSTOM_SCRIPT_BLOCK_START_TAG, strlen(CUSTOM_SCRIPT_BLOCK_START_TAG)) == 0) {
9438 bool done = false;
9439 bool warning_issued = false;
9440
9441 // Count the number of lines in the file, and allocate room for them
9442 ClearCustomScriptStorage();
9443 m_MaxNumCustomScriptLines = CountCustomScriptLines(infile);
9444 if (m_MaxNumCustomScriptLines > 0) {
9445 m_CustomScriptLines = (char **)mem_malloc(sizeof(char *) * m_MaxNumCustomScriptLines);
9446 if (m_CustomScriptLines == NULL) {
9447 MessageBox("ERROR: Ran out of memory allocating custom script block", "Custom Script Parse Error",
9448 MB_OK | MB_ICONEXCLAMATION);
9449 cfclose(infile);
9450 return FALSE;
9451 }
9452 }
9453
9454 // Read all the lines in the block
9455 while (!done && !cfeof(infile)) {
9456
9457 strcpy(linebuf, "");
9458 cf_ReadString(linebuf, sizeof(linebuf), infile);
9459 linenum++;
9460
9461 // Check for End of Script Block Section
9462 if (strncmp(linebuf, CUSTOM_SCRIPT_BLOCK_END_TAG, strlen(CUSTOM_SCRIPT_BLOCK_END_TAG)) == 0) {
9463 done = true;
9464 continue;
9465 }
9466
9467 // Store this line
9468 if (m_NumCustomScriptLines < m_MaxNumCustomScriptLines) {
9469 m_CustomScriptLines[m_NumCustomScriptLines] = (char *)mem_malloc(strlen(linebuf) + 1);
9470 if (m_CustomScriptLines[m_NumCustomScriptLines] == NULL) {
9471 MessageBox("ERROR: Ran out of memory parsing custom script block", "Custom Script Parse Error",
9472 MB_OK | MB_ICONEXCLAMATION);
9473 cfclose(infile);
9474 return FALSE;
9475 }
9476 strcpy(m_CustomScriptLines[m_NumCustomScriptLines], linebuf);
9477 m_NumCustomScriptLines++;
9478 } else {
9479 MessageBox("ERROR: The maximum custom script block line limit has been exceeded.\n\nThe excess lines will "
9480 "not be saved.",
9481 "Custom Script Parse Error", MB_OK | MB_ICONEXCLAMATION);
9482 done = TRUE;
9483 }
9484 }
9485
9486 if (!done)
9487 ScriptFileParseError(UEOS_ERR, linenum, 0, NULL);
9488 }
9489 }
9490
9491 cfclose(infile);
9492
9493 return TRUE;
9494 }
9495
9496 // Writes out the custom script block
9497 void CDallasMainDlg::WriteCustomScriptBlock(void) {
9498 if (CurrentOutputFile == NULL)
9499 return;
9500
9501 // Create the valid event case statements
9502 O((" "));
9503 O(("// ==============================================================="));
9504 O(("// Start of Custom Script Block - DO NOT EDIT ANYTHING BEFORE THIS"));
9505 O(("// ==============================================================="));
9506 O(("%s", CUSTOM_SCRIPT_BLOCK_START_TAG));
9507
9508 if (m_NumCustomScriptLines == 0) {
9509 O((" "));
9510 O(("// Enter your custom script code here"));
9511 O((" "));
9512 } else {
9513 for (int j = 0; j < m_NumCustomScriptLines; j++)
9514 O(("%s", m_CustomScriptLines[j]));
9515 }
9516
9517 O(("%s", CUSTOM_SCRIPT_BLOCK_END_TAG));
9518 O(("// ============================================================"));
9519 O(("// End of Custom Script Block - DO NOT EDIT ANYTHING AFTER THIS"));
9520 O(("// ============================================================"));
9521 O((" "));
9522 }
9523
9524 /////////////////////////////////////////////////////////////////////////////
9525 // File Creation Functions
9526 /////////////////////////////////////////////////////////////////////////////
9527
9528 // Writes message list to file
9529 int CDallasMainDlg::CreateMsgTableFile(char *filename) {
9530 CFILE *outfile;
9531 CString buffer;
9532 int count, j;
9533 tMessageListEntry *msg_data;
9534 char fullpath[_MAX_PATH];
9535
9536 ddio_MakePath(fullpath, LocalScriptDir, filename, NULL);
9537
9538 // Try to open the file for writing
9539 outfile = cfopen(fullpath, "wt");
9540 if (!outfile) {
9541 CString msg;
9542 msg.Format("Unable to open \"%s\"!", filename);
9543 MessageBox(msg, "Script Message File Error!", MB_OK | MB_ICONEXCLAMATION);
9544 return FALSE;
9545 }
9546
9547 // Write out comment header
9548 buffer.Format("//////////////////////////////////////////////");
9549 cf_WriteString(outfile, buffer.GetBuffer(0));
9550 buffer.Format("// D.A.L.L.A.S. Generated Message Table File");
9551 cf_WriteString(outfile, buffer.GetBuffer(0));
9552 buffer.Format("//////////////////////////////////////////////");
9553 cf_WriteString(outfile, buffer.GetBuffer(0));
9554 cf_WriteString(outfile, "");
9555
9556 // Write out the next message ID number
9557 buffer.Format("%s %d", NEXT_MSG_ID_NUM_KEYWORD, m_NextMessageID);
9558 cf_WriteString(outfile, buffer.GetBuffer(0));
9559 cf_WriteString(outfile, "");
9560
9561 // Write out the message list comment header
9562 buffer.Format("// Message List");
9563 cf_WriteString(outfile, buffer.GetBuffer(0));
9564
9565 // Write out each message
9566 count = m_MessageList.GetCount();
9567 for (j = 0; j < count; j++) {
9568 msg_data = (tMessageListEntry *)m_MessageList.GetItemData(j);
9569 if (msg_data) {
9570 buffer.Format("%s=%s", msg_data->name, msg_data->message);
9571 cf_WriteString(outfile, buffer.GetBuffer(0));
9572 }
9573 }
9574
9575 cfclose(outfile);
9576
9577 return TRUE;
9578 }
9579
9580 // Writes out a series of tabs to the CurrentOutputFile
9581 void CDallasMainDlg::TabOver(void) {
9582 int j;
9583
9584 if (CurrentOutputFile == NULL)
9585 return;
9586
9587 for (j = 0; j < CurrentTabLevel; j++)
9588 cfprintf(CurrentOutputFile, "\t");
9589 }
9590
9591 // Create the source script CPP file
9592 int CDallasMainDlg::CreateScriptFile(char *filename) {
9593 char fullpath[_MAX_PATH];
9594 int j, counter, num_CO_scripts;
9595
9596 // Fill the name lists (and check for any invalid/not selected fields)
9597 ClearNameLists();
9598 if (FillNameListsFromTree(TVI_ROOT, TRUE) != 0) {
9599 int ret_val;
9600 ret_val = MessageBox(
9601 "Due to invalid script data, it is probably unsafe to save and compile.\n\nDo you wish to proceed anyway?",
9602 "Script Problems Encountered!", MB_YESNO | MB_ICONQUESTION);
9603 if (ret_val == IDNO)
9604 return FALSE;
9605 }
9606
9607 // Build the organized list of scripts
9608 BuildScriptGroupingList();
9609
9610 // Open the file for writing
9611 ddio_MakePath(fullpath, LocalScriptDir, filename, NULL);
9612 CurrentOutputFile = cfopen(fullpath, "wt");
9613 if (CurrentOutputFile == NULL) {
9614 CString msg, title;
9615 msg.Format("ERROR: Unable to open %s for output.", fullpath);
9616 title.Format("Script Save Error!");
9617 MessageBox(msg, title, MB_OK | MB_ICONEXCLAMATION);
9618 return FALSE;
9619 }
9620
9621 // Write out the header info
9622 O(("/////////////////////////////////////////////////////////////////////"));
9623 O(("// D.A.L.L.A.S. Generated Level Script - DLL Source File"));
9624 O(("// "));
9625 O(("// Filename: %s", filename));
9626 O(("// Version: %d", DALLAS_SAVE_VERSION));
9627 O(("/////////////////////////////////////////////////////////////////////"));
9628 O(("#include <stdio.h>"));
9629 O(("#include <stdlib.h>"));
9630 O(("#include <string.h>"));
9631 O(("#include <ctype.h>"));
9632 O(("#include \"osiris_import.h\""));
9633 O(("#include \"osiris_common.h\""));
9634 O(("#include \"%s\"", DALLASFUNCS_FILENAME));
9635 O((""));
9636
9637 O(("#ifdef _MSC_VER //Visual C++ Build"));
9638 O(("#define STDCALL __stdcall"));
9639 O(("#define STDCALLPTR *STDCALL"));
9640 O(("#else //Non-Visual C++ Build"));
9641 O(("#define STDCALL __attribute__((stdcall))"));
9642 O(("#define STDCALLPTR STDCALL*"));
9643 O(("#endif"));
9644 O((""));
9645
9646 O(("#ifdef __cplusplus"));
9647 O(("extern \"C\"{"));
9648 O(("#endif"));
9649 O(("char STDCALL InitializeDLL(tOSIRISModuleInit *func_list);"));
9650 O(("void STDCALL ShutdownDLL(void);"));
9651 O(("int STDCALL GetGOScriptID(const char *name,uint8_t is_door);"));
9652 O(("void STDCALLPTR CreateInstance(int id);"));
9653 O(("void STDCALL DestroyInstance(int id,void *ptr);"));
9654 O(("int16_t STDCALL CallInstanceEvent(int id,void *ptr,int event,tOSIRISEventInfo *data);"));
9655 O(("int STDCALL GetTriggerScriptID(int trigger_room, int trigger_face );"));
9656 O(("int STDCALL GetCOScriptList( int **list, int **id_list );"));
9657 O(("int STDCALL SaveRestoreState( void *file_ptr, uint8_t saving_state );"));
9658 O(("#ifdef __cplusplus"));
9659 O(("}"));
9660 O(("#endif"));
9661 O((""));
9662
9663 // Write out the script ID list
9664 O(("// ================="));
9665 O(("// Script ID Numbers"));
9666 O(("// ================="));
9667
9668 counter = 0x000;
9669
9670 // Write out the level ID
9671 O(("#define %s 0x%03x", LEVEL_ID_NAME, counter++));
9672 O((""));
9673
9674 // Write out the custom object ID's (and count the number of custom object scripts)
9675 num_CO_scripts = 0;
9676 for (j = 0; j < m_NumScriptGroups; j++)
9677 if (m_ScriptGroupingList[j].owner_type == OBJECT_TYPE) {
9678 O(("#define %s 0x%03x", CreateScriptConstantName(j), counter++));
9679 num_CO_scripts++;
9680 }
9681 O((""));
9682
9683 // Write out the trigger ID's
9684 for (j = 0; j < m_NumScriptGroups; j++)
9685 if (m_ScriptGroupingList[j].owner_type == TRIGGER_TYPE)
9686 O(("#define %s 0x%03x", CreateScriptConstantName(j), counter++));
9687 O((""));
9688
9689 // Write out the base script class definition
9690 O(("// ========================"));
9691 O(("// Script Class Definitions"));
9692 O(("// ========================"));
9693 O((""));
9694 O(("class BaseScript {"));
9695 O(("public:"));
9696 O((" BaseScript();"));
9697 O((" ~BaseScript();"));
9698 O((" virtual int16_t CallEvent(int event, tOSIRISEventInfo *data);"));
9699 O(("};"));
9700 O((""));
9701
9702 // Write out the level script class definition
9703 O(("class %s : public BaseScript {", LEVEL_CLASS_NAME));
9704 O(("public:"));
9705 O((" int16_t CallEvent(int event, tOSIRISEventInfo *data);"));
9706 O(("};"));
9707 O((""));
9708
9709 // Write out the custom object class definitions
9710 for (j = 0; j < m_NumScriptGroups; j++)
9711 if (m_ScriptGroupingList[j].owner_type == OBJECT_TYPE) {
9712 O(("class %s : public BaseScript {", CreateScriptClassName(j)));
9713 O(("public:"));
9714 O((" int16_t CallEvent(int event, tOSIRISEventInfo *data);"));
9715 O(("};"));
9716 O((""));
9717 }
9718
9719 // Write out the trigger class definitions
9720 for (j = 0; j < m_NumScriptGroups; j++)
9721 if (m_ScriptGroupingList[j].owner_type == TRIGGER_TYPE) {
9722 O(("class %s : public BaseScript {", CreateScriptClassName(j)));
9723 O(("public:"));
9724 O((" int16_t CallEvent(int event, tOSIRISEventInfo *data);"));
9725 O(("};"));
9726 O((""));
9727 }
9728
9729 // Write out the global script action counters
9730 O(("// ======================"));
9731 O(("// Global Action Counters"));
9732 O(("// ======================"));
9733 O((""));
9734 O(("#define MAX_ACTION_CTR_VALUE 100000"));
9735 O((""));
9736
9737 // Loop through all the scripts, write one global for each script
9738 HTREEITEM script_node;
9739 tTreeNodeData *data;
9740
9741 script_node = m_ScriptTree.GetChildItem(TVI_ROOT);
9742 while (script_node != NULL) {
9743 data = (tTreeNodeData *)m_ScriptTree.GetItemData(script_node);
9744 if (data != NULL && data->type == SCRIPT_HEADER_NODE) {
9745 O(("int %s = 0;", CreateScriptGlobalCtrName(data->ID)));
9746 }
9747 script_node = m_ScriptTree.GetNextSiblingItem(script_node);
9748 }
9749 O((" "));
9750
9751 O(("// ========================================"));
9752 O(("// Function to Clear Global Action Counters"));
9753 O(("// ========================================"));
9754 O(("void ClearGlobalActionCtrs(void)"));
9755 O(("{"));
9756
9757 // Write out the clear script statements
9758 script_node = m_ScriptTree.GetChildItem(TVI_ROOT);
9759 while (script_node != NULL) {
9760 data = (tTreeNodeData *)m_ScriptTree.GetItemData(script_node);
9761 if (data != NULL && data->type == SCRIPT_HEADER_NODE) {
9762 O((" %s = 0;", CreateScriptGlobalCtrName(data->ID)));
9763 }
9764 script_node = m_ScriptTree.GetNextSiblingItem(script_node);
9765 }
9766
9767 O(("}"));
9768 O((" "));
9769
9770 O(("// ========================================"));
9771 O(("// Function to Save Global Action Counters"));
9772 O(("// ========================================"));
9773 O(("void SaveGlobalActionCtrs(void *file_ptr)"));
9774 O(("{"));
9775
9776 // Write out the clear script statements
9777 script_node = m_ScriptTree.GetChildItem(TVI_ROOT);
9778 while (script_node != NULL) {
9779 data = (tTreeNodeData *)m_ScriptTree.GetItemData(script_node);
9780 if (data != NULL && data->type == SCRIPT_HEADER_NODE) {
9781 O((" File_WriteInt(%s,file_ptr);", CreateScriptGlobalCtrName(data->ID)));
9782 }
9783 script_node = m_ScriptTree.GetNextSiblingItem(script_node);
9784 }
9785
9786 O(("}"));
9787 O((" "));
9788
9789 O(("// ==========================================="));
9790 O(("// Function to Restore Global Action Counters"));
9791 O(("// ==========================================="));
9792 O(("void RestoreGlobalActionCtrs(void *file_ptr)"));
9793 O(("{"));
9794
9795 // Write out the clear script statements
9796 script_node = m_ScriptTree.GetChildItem(TVI_ROOT);
9797 while (script_node != NULL) {
9798 data = (tTreeNodeData *)m_ScriptTree.GetItemData(script_node);
9799 if (data != NULL && data->type == SCRIPT_HEADER_NODE) {
9800 O((" %s=File_ReadInt(file_ptr);", CreateScriptGlobalCtrName(data->ID)));
9801 }
9802 script_node = m_ScriptTree.GetNextSiblingItem(script_node);
9803 }
9804
9805 O(("}"));
9806 O((" "));
9807
9808 // Write out the Custom Script Block
9809 WriteCustomScriptBlock();
9810 O((" "));
9811
9812 O(("// ================="));
9813 O(("// Message File Data"));
9814 O(("// ================="));
9815 O((" "));
9816 O(("#define MAX_SCRIPT_MESSAGES 256"));
9817 O(("#define MAX_MSG_FILEBUF_LEN 1024"));
9818 O(("#define NO_MESSAGE_STRING \"*Message Not Found*\""));
9819 O(("#define INV_MSGNAME_STRING \"*Message Name Invalid*\""));
9820 O(("#define WHITESPACE_CHARS \" \\t\\r\\n\""));
9821 O((" "));
9822 O(("// Structure for storing a script message"));
9823 O(("struct tScriptMessage {"));
9824 O((" char *name; // the name of the message"));
9825 O((" char *message; // the actual message text"));
9826 O(("};"));
9827 O((" "));
9828 O(("// Global storage for level script messages"));
9829 O(("tScriptMessage *message_list[MAX_SCRIPT_MESSAGES];"));
9830 O(("int num_messages;"));
9831 O((" "));
9832
9833 O(("// ======================"));
9834 O(("// Message File Functions"));
9835 O(("// ======================"));
9836 O((" "));
9837 O(("// Initializes the Message List"));
9838 O(("void InitMessageList(void)"));
9839 O(("{"));
9840 O((" for(int j=0;j<MAX_SCRIPT_MESSAGES;j++)"));
9841 O((" message_list[j]=NULL;"));
9842 O((" num_messages=0;"));
9843 O(("}"));
9844 O((" "));
9845 O(("// Clear the Message List"));
9846 O(("void ClearMessageList(void)"));
9847 O(("{"));
9848 O((" for(int j=0;j<num_messages;j++) {"));
9849 O((" free(message_list[j]->name);"));
9850 O((" free(message_list[j]->message);"));
9851 O((" free(message_list[j]);"));
9852 O((" message_list[j]=NULL;"));
9853 O((" }"));
9854 O((" num_messages=0;"));
9855 O(("}"));
9856 O((" "));
9857 O(("// Adds a message to the list"));
9858 O(("int AddMessageToList(char *name, char *msg)"));
9859 O(("{"));
9860 O((" int pos;"));
9861 O((" "));
9862 O((" // Make sure there is room in the list"));
9863 O((" if(num_messages>=MAX_SCRIPT_MESSAGES) return false;"));
9864 O((" "));
9865 O((" // Allocate memory for this message entry"));
9866 O((" pos=num_messages;"));
9867 O((" message_list[pos]=(tScriptMessage *)malloc(sizeof(tScriptMessage));"));
9868 O((" if(message_list[pos]==NULL) return false;"));
9869 O((" "));
9870 O((" // Allocate memory for the message name"));
9871 O((" message_list[pos]->name=(char *)malloc(strlen(name)+1);"));
9872 O((" if(message_list[pos]->name==NULL) {"));
9873 O((" free(message_list[pos]);"));
9874 O((" return false;"));
9875 O((" }"));
9876 O((" strcpy(message_list[pos]->name,name);"));
9877 O((" "));
9878 O((" // Allocate memory for the message name"));
9879 O((" message_list[pos]->message=(char *)malloc(strlen(msg)+1);"));
9880 O((" if(message_list[pos]->message==NULL) {"));
9881 O((" free(message_list[pos]->name);"));
9882 O((" free(message_list[pos]);"));
9883 O((" return false;"));
9884 O((" }"));
9885 O((" strcpy(message_list[pos]->message,msg);"));
9886 O((" num_messages++;"));
9887 O((" "));
9888 O((" return true;"));
9889 O(("}"));
9890 O((" "));
9891 O(("// Removes any whitespace padding from the end of a string"));
9892 O(("void RemoveTrailingWhitespace(char *s)"));
9893 O(("{"));
9894 O((" int last_char_pos;"));
9895 O((" "));
9896 O((" last_char_pos=strlen(s)-1;"));
9897 O((" while(last_char_pos>=0 && isspace(s[last_char_pos])) {"));
9898 O((" s[last_char_pos]='\\0';"));
9899 O((" last_char_pos--;"));
9900 O((" }"));
9901 O(("}"));
9902 O((" "));
9903 O(("// Returns a pointer to the first non-whitespace char in given string"));
9904 O(("char *SkipInitialWhitespace(char *s)"));
9905 O(("{"));
9906 O((" while((*s)!='\\0' && isspace(*s)) "));
9907 O((" s++;"));
9908 O((" "));
9909 O((" return(s);"));
9910 O(("}"));
9911 O((" "));
9912 O(("// Read in the Messages"));
9913 O(("int ReadMessageFile(char *filename)"));
9914 O(("{"));
9915 O((" void *infile;"));
9916 O((" char filebuffer[MAX_MSG_FILEBUF_LEN+1];"));
9917 O((" char *line, *msg_start;"));
9918 O((" int line_num;"));
9919 O((" bool next_msgid_found;"));
9920 O((" "));
9921 O((" // Try to open the file for loading"));
9922 O((" infile=File_Open(filename,\"rt\");"));
9923 O((" if (!infile) return false;"));
9924 O((" "));
9925 O((" line_num=0;"));
9926 O((" next_msgid_found=true;"));
9927 O((" "));
9928 O((" // Clear the message list"));
9929 O((" ClearMessageList();"));
9930 O((" "));
9931 O((" // Read in and parse each line of the file"));
9932 O((" while (!File_eof(infile)) {"));
9933 O((" "));
9934 O((" // Clear the buffer"));
9935 O((" strcpy(filebuffer,\"\");"));
9936 O((" "));
9937 O((" // Read in a line from the file"));
9938 O((" File_ReadString(filebuffer, MAX_MSG_FILEBUF_LEN, infile);"));
9939 O((" line_num++;"));
9940 O((" "));
9941 O((" // Remove whitespace padding at start and end of line"));
9942 O((" RemoveTrailingWhitespace(filebuffer);"));
9943 O((" line=SkipInitialWhitespace(filebuffer);"));
9944 O((" "));
9945 O((" // If line is a comment, or empty, discard it"));
9946 O((" if(strlen(line)==0 || strncmp(line,\"//\",2)==0)"));
9947 O((" continue;"));
9948 O((" "));
9949 O((" if(!next_msgid_found) { // Parse out the last message ID number"));
9950 O((" "));
9951 O((" // Grab the first keyword, make sure it's valid"));
9952 O((" line=strtok(line,WHITESPACE_CHARS);"));
9953 O((" if(line==NULL) continue;"));
9954 O((" "));
9955 O((" // Grab the second keyword, and assign it as the next message ID"));
9956 O((" line=strtok(NULL,WHITESPACE_CHARS);"));
9957 O((" if(line==NULL) continue;"));
9958 O((" "));
9959 O((" next_msgid_found=true;"));
9960 O((" }"));
9961 O((" else { // Parse line as a message line"));
9962 O((" "));
9963 O((" // Find the start of message, and mark it"));
9964 O((" msg_start=strchr(line,'=');"));
9965 O((" if(msg_start==NULL) continue;"));
9966 O((" msg_start[0]='\\0';"));
9967 O((" msg_start++;"));
9968 O((" "));
9969 O((" // Add the message to the list"));
9970 O((" AddMessageToList(line,msg_start);"));
9971 O((" }"));
9972 O((" }"));
9973 O((" File_Close(infile);"));
9974 O((" "));
9975 O((" return true;"));
9976 O(("}"));
9977 O((" "));
9978 O(("// Find a message"));
9979 O(("const char *GetMessage(const char *name)"));
9980 O(("{"));
9981 O((" // Make sure given name is valid"));
9982 O((" if(name==NULL) return INV_MSGNAME_STRING;"));
9983 O((" "));
9984 O((" // Search message list for name"));
9985 O((" for(int j=0;j<num_messages;j++)"));
9986 O((" if(strcmp(message_list[j]->name,name)==0) return(message_list[j]->message);"));
9987 O((" "));
9988 O((" // Couldn't find it"));
9989 O((" return NO_MESSAGE_STRING;"));
9990 O(("}"));
9991 O((" "));
9992
9993 // Write out the global name arrays
9994 WriteNameListArrays();
9995
9996 O(("// ==============="));
9997 O(("// InitializeDLL()"));
9998 O(("// ==============="));
9999 O(("char STDCALL InitializeDLL(tOSIRISModuleInit *func_list)"));
10000 O(("{"));
10001 O((" osicommon_Initialize((tOSIRISModuleInit *)func_list);"));
10002 #ifndef NEWEDITOR
10003 O((" if(func_list->game_checksum!=CHECKSUM)"));
10004 O((" { "));
10005 O((" mprintf(0,\"Game-Checksum FAIL!!! (%%ul!=%%ul)\\n\",func_list->game_checksum,CHECKSUM);"));
10006 O((" mprintf(0,\"RECOMPILE YOUR SCRIPTS!!!\\n\");"));
10007 O((" return 0;"));
10008 O((" }"));
10009 #endif
10010 O((" "));
10011 O((" ClearGlobalActionCtrs();"));
10012 O((" dfInit();"));
10013 O((" InitMessageList();"));
10014 O((" "));
10015 O((" // Build the filename of the message file"));
10016 O((" char filename[_MAX_PATH+1];"));
10017 O((" char english_filename[_MAX_PATH+1];"));
10018 O((" int lang_type;"));
10019 O((" if(func_list->script_identifier!=NULL) {"));
10020 O((" _splitpath(func_list->script_identifier,NULL,NULL,filename,NULL);"));
10021 O((" sprintf(english_filename,\"%%s.msg\",filename);"));
10022 O((" lang_type=Game_GetLanguage();"));
10023 O((" if(lang_type==LANGUAGE_FRENCH) strcat(filename,\"_FRN\");"));
10024 O((" else if(lang_type==LANGUAGE_GERMAN) strcat(filename,\"_GER\");"));
10025 O((" else if(lang_type==LANGUAGE_ITALIAN) strcat(filename,\"_ITN\");"));
10026 O((" else if(lang_type==LANGUAGE_SPANISH) strcat(filename,\"_SPN\");"));
10027 O((" else if(lang_type==LANGUAGE_POLISH) strcat(filename,\"_POL\");"));
10028 O((" strcat(filename,\".msg\");"));
10029 O((" }"));
10030 O((" else {"));
10031 O((" strcpy(filename,\"%s\");", m_ScriptMessagesFilename.GetBuffer(0)));
10032 O((" lang_type=LANGUAGE_ENGLISH;"));
10033 O((" }"));
10034 O((" if(!ReadMessageFile(filename)) {"));
10035 O((" if(lang_type == LANGUAGE_ENGLISH) {"));
10036 O((" mprintf(0,\"ERROR: Could not load message file - %%s\\n\",filename);"));
10037 O((" }"));
10038 O((" else if(!ReadMessageFile(english_filename)) {"));
10039 O((" mprintf(0,\"ERROR: Could not load message file - %%s\\n\",english_filename);"));
10040 O((" }"));
10041 O((" }"));
10042 O((" "));
10043
10044 // Write out the name array lookup code
10045 WriteNameArrayLookupCode();
10046
10047 O((" "));
10048 O((" return 1;"));
10049 O(("}"));
10050 O((""));
10051
10052 O(("// ============="));
10053 O(("// ShutdownDLL()"));
10054 O(("// ============="));
10055 O(("void STDCALL ShutdownDLL(void)"));
10056 O(("{"));
10057 O((" ClearMessageList();"));
10058 O(("}"));
10059 O((""));
10060
10061 O(("// ==============="));
10062 O(("// GetGOScriptID()"));
10063 O(("// ==============="));
10064 O(("int STDCALL GetGOScriptID(const char *name,uint8_t isdoor)"));
10065 O(("{"));
10066 O((" return -1;"));
10067 O(("}"));
10068 O((""));
10069
10070 O(("// ================"));
10071 O(("// CreateInstance()"));
10072 O(("// ================"));
10073 O(("void STDCALLPTR CreateInstance(int id)"));
10074 O(("{"));
10075 O((" switch(id) {"));
10076
10077 // Level Case
10078 O((" case %s:", LEVEL_ID_NAME));
10079 O((" return new %s;", LEVEL_CLASS_NAME));
10080 O((" break;"));
10081
10082 // Custom object Cases
10083 for (j = 0; j < m_NumScriptGroups; j++)
10084 if (m_ScriptGroupingList[j].owner_type == OBJECT_TYPE) {
10085 O((" case %s:", CreateScriptConstantName(j)));
10086 O((" return new %s;", CreateScriptClassName(j)));
10087 O((" break;"));
10088 }
10089
10090 // Trigger Cases
10091 for (j = 0; j < m_NumScriptGroups; j++)
10092 if (m_ScriptGroupingList[j].owner_type == TRIGGER_TYPE) {
10093 O((" case %s:", CreateScriptConstantName(j)));
10094 O((" return new %s;", CreateScriptClassName(j)));
10095 O((" break;"));
10096 }
10097
10098 O((" default:"));
10099 O((" mprintf(0,\"SCRIPT: Illegal ID (%%d)\\n\",id);"));
10100 O((" break;"));
10101
10102 O((" }"));
10103 O((" return NULL;"));
10104 O(("}"));
10105 O((""));
10106
10107 O(("// ================="));
10108 O(("// DestroyInstance()"));
10109 O(("// ================="));
10110 O(("void STDCALL DestroyInstance(int id,void *ptr)"));
10111 O(("{"));
10112 O((" switch(id) {"));
10113
10114 // Level Case
10115 O((" case %s:", LEVEL_ID_NAME));
10116 O((" delete ((%s *)ptr);", LEVEL_CLASS_NAME));
10117
10118 // Custom object Cases
10119 for (j = 0; j < m_NumScriptGroups; j++)
10120 if (m_ScriptGroupingList[j].owner_type == OBJECT_TYPE) {
10121 O((" case %s:", CreateScriptConstantName(j)));
10122 O((" delete ((%s *)ptr);", CreateScriptClassName(j)));
10123 O((" break;"));
10124 }
10125
10126 // Trigger Cases
10127 for (j = 0; j < m_NumScriptGroups; j++)
10128 if (m_ScriptGroupingList[j].owner_type == TRIGGER_TYPE) {
10129 O((" case %s:", CreateScriptConstantName(j)));
10130 O((" delete ((%s *)ptr);", CreateScriptClassName(j)));
10131 O((" break;"));
10132 }
10133
10134 O((" default:"));
10135 O((" mprintf(0,\"SCRIPT: Illegal ID (%%d)\\n\",id);"));
10136 O((" break;"));
10137
10138 O((" }"));
10139 O(("}"));
10140 O((""));
10141
10142 O(("// ==================="));
10143 O(("// CallInstanceEvent()"));
10144 O(("// ==================="));
10145 O(("int16_t STDCALL CallInstanceEvent(int id,void *ptr,int event,tOSIRISEventInfo *data)"));
10146 O(("{"));
10147 O((" switch(id) {"));
10148
10149 // Level Case
10150 O((" case %s:", LEVEL_ID_NAME));
10151
10152 // Custom object Cases
10153 for (j = 0; j < m_NumScriptGroups; j++)
10154 if (m_ScriptGroupingList[j].owner_type == OBJECT_TYPE)
10155 O((" case %s:", CreateScriptConstantName(j)));
10156
10157 // Trigger Cases
10158 for (j = 0; j < m_NumScriptGroups; j++)
10159 if (m_ScriptGroupingList[j].owner_type == TRIGGER_TYPE)
10160 O((" case %s:", CreateScriptConstantName(j)));
10161
10162 O((" return ((BaseScript *)ptr)->CallEvent(event,data);"));
10163 O((" break;"));
10164
10165 O((" default:"));
10166 O((" mprintf(0,\"SCRIPT: Illegal ID (%%d)\\n\",id);"));
10167 O((" break;"));
10168
10169 O((" }"));
10170 O((" return CONTINUE_CHAIN|CONTINUE_DEFAULT;"));
10171 O(("}"));
10172 O((""));
10173
10174 O(("// =================="));
10175 O(("// SaveRestoreState()"));
10176 O(("// =================="));
10177 O(("int STDCALL SaveRestoreState( void *file_ptr, uint8_t saving_state )"));
10178 O(("{"));
10179 O((" return 0;"));
10180 O(("}"));
10181 O((""));
10182
10183 O(("// ===================="));
10184 O(("// GetTriggerScriptID()"));
10185 O(("// ===================="));
10186 O(("int STDCALL GetTriggerScriptID(int trigger_room,int trigger_face)"));
10187 O(("{"));
10188
10189 // Trigger ID Listing
10190 for (j = 0; j < m_NumScriptGroups; j++)
10191 if (m_ScriptGroupingList[j].owner_type == TRIGGER_TYPE) {
10192 CString troom_text, tface_text;
10193 troom_text = "-1";
10194 tface_text = "-1";
10195 int t = m_ScriptGroupingList[j].owner_handle;
10196 if (t >= 0 && t < Num_triggers && t < MAX_NAMED_TRIGGERS && strlen(Triggers[t].name) != 0) {
10197 int index = FindTriggerInList(Triggers[t].name);
10198 if (index >= 0) {
10199 troom_text.Format("Trigger_rooms[%d]", index);
10200 tface_text.Format("Trigger_faces[%d]", index);
10201 }
10202 }
10203
10204 O((" if(trigger_room==%s && trigger_face==%s)", troom_text.GetBuffer(0), tface_text.GetBuffer(0)));
10205 O((" return %s;", CreateScriptConstantName(j)));
10206 O((" "));
10207 }
10208
10209 O((" return -1;"));
10210 O(("}"));
10211 O((""));
10212
10213 O(("// ================="));
10214 O(("// GetCOScriptList()"));
10215 O(("// ================="));
10216 O(("int STDCALL GetCOScriptList( int **list, int **id_list )"));
10217 O(("{"));
10218
10219 if (num_CO_scripts == 0) {
10220 O((" static int *cust_handle_list=NULL;"));
10221 O((" static int *cust_id_list=NULL;"));
10222 } else {
10223 O((" static int cust_handle_list[%d];", num_CO_scripts));
10224 O((" static int cust_id_list[%d] = { ", num_CO_scripts));
10225
10226 // Write out the custom object IDs
10227 counter = 0;
10228 for (j = 0; j < m_NumScriptGroups; j++)
10229 if (m_ScriptGroupingList[j].owner_type == OBJECT_TYPE) {
10230 counter++;
10231 if (counter < num_CO_scripts)
10232 O((" %s,", CreateScriptConstantName(j)));
10233 else
10234 O((" %s", CreateScriptConstantName(j)));
10235 }
10236
10237 O((" };"));
10238 }
10239
10240 // Fill in the custom object handles array
10241 O((" "));
10242 counter = 0;
10243 for (j = 0; j < m_NumScriptGroups; j++)
10244 if (m_ScriptGroupingList[j].owner_type == OBJECT_TYPE) {
10245
10246 // Obtain the handle text
10247 CString handle_text;
10248
10249 handle_text.Format("0x%04x", OBJECT_HANDLE_NONE);
10250 object *objp = ObjGet(m_ScriptGroupingList[j].owner_handle);
10251 if (objp != NULL && objp->type != OBJ_NONE && objp->name != NULL) {
10252 int index = FindObjectInList(objp->name);
10253 if (index >= 0 && strlen(objp->name) != 0)
10254 handle_text.Format("Object_handles[%d]", index);
10255 }
10256
10257 if (counter == 0)
10258 O((" // Fill in the custom handle list"));
10259 O((" cust_handle_list[%d]=%s;", counter, handle_text.GetBuffer(0)));
10260 counter++;
10261 }
10262
10263 O((""));
10264 O((" *list = cust_handle_list;"));
10265 O((" *id_list = cust_id_list;"));
10266 O((""));
10267 O((" return %d;", num_CO_scripts));
10268 O(("}"));
10269 O((""));
10270
10271 O(("//======================="));
10272 O(("// Script Implementation "));
10273 O(("//======================="));
10274 O((""));
10275
10276 O(("BaseScript::BaseScript()"));
10277 O(("{"));
10278 O(("}"));
10279 O((""));
10280
10281 O(("BaseScript::~BaseScript()"));
10282 O(("{"));
10283 O(("}"));
10284 O((""));
10285
10286 O(("int16_t BaseScript::CallEvent(int event,tOSIRISEventInfo *data)"));
10287 O(("{"));
10288 O((" mprintf(0,\"BaseScript::CallEvent()\\n\");"));
10289 O((" return CONTINUE_CHAIN|CONTINUE_DEFAULT;"));
10290 O(("}"));
10291 O((""));
10292
10293 // Create the Level Script Class' CallEvent() method
10294 O(("int16_t %s::CallEvent(int event,tOSIRISEventInfo *data)", LEVEL_CLASS_NAME));
10295 O(("{"));
10296 O((" switch(event) { "));
10297
10298 // Find the level script group (if it exists)
10299 tScriptOwnerGroup *owner_group = NULL;
10300 ;
10301 for (j = 0; j < m_NumScriptGroups; j++)
10302 if (m_ScriptGroupingList[j].owner_type == LEVEL_TYPE)
10303 owner_group = &m_ScriptGroupingList[j];
10304
10305 // Create the event cases for the level script
10306 CreateLevelEventCases(owner_group);
10307
10308 O((" }"));
10309 O((" return CONTINUE_CHAIN|CONTINUE_DEFAULT;"));
10310 O(("}"));
10311 O((""));
10312
10313 // Create the CallEvent() methods for each custom object script class
10314 for (j = 0; j < m_NumScriptGroups; j++)
10315 if (m_ScriptGroupingList[j].owner_type == OBJECT_TYPE) {
10316 O(("int16_t %s::CallEvent(int event,tOSIRISEventInfo *data)", CreateScriptClassName(j)));
10317 O(("{"));
10318 O((" switch(event) { "));
10319
10320 // Create the event cases for the custom object script
10321 owner_group = &m_ScriptGroupingList[j];
10322 CreateEventCases(owner_group);
10323
10324 O((" }"));
10325 O((" return CONTINUE_CHAIN|CONTINUE_DEFAULT;"));
10326 O(("}"));
10327 O((""));
10328 }
10329
10330 // Create the CallEvent() methods for each trigger script class
10331 for (j = 0; j < m_NumScriptGroups; j++)
10332 if (m_ScriptGroupingList[j].owner_type == TRIGGER_TYPE) {
10333 O(("int16_t %s::CallEvent(int event,tOSIRISEventInfo *data)", CreateScriptClassName(j)));
10334 O(("{"));
10335 O((" switch(event) { "));
10336
10337 // Create the event cases for the trigger script
10338 owner_group = &m_ScriptGroupingList[j];
10339 CreateEventCases(owner_group);
10340
10341 O((" }"));
10342 O((" return CONTINUE_CHAIN|CONTINUE_DEFAULT;"));
10343 O(("}"));
10344 O((""));
10345 }
10346
10347 // Create the Script Save Block
10348 WriteScriptSaveBlock();
10349
10350 cfclose(CurrentOutputFile);
10351 CurrentOutputFile = NULL;
10352
10353 return TRUE;
10354 }
10355
10356 // Creates the level event cases
10357 // NOTE: Some level events must always be handled to perform init/load/save/etc.
10358 void CDallasMainDlg::CreateLevelEventCases(tScriptOwnerGroup *owner_group) {
10359 int j, k;
10360
10361 if (CurrentOutputFile == NULL)
10362 return;
10363
10364 // Handle the saving event
10365 O((" case EVT_SAVESTATE:"));
10366 O((" {"));
10367 O((" tOSIRISEVTSAVESTATE *event_data=&data->evt_savestate;"));
10368 O((" "));
10369 O((" SaveGlobalActionCtrs(event_data->fileptr);"));
10370 O((" dfSave(event_data->fileptr);"));
10371 O(("#ifdef ENABLE_CUSTOM_SAVE_AND_RESTORE"));
10372 O((" dsCustomSave(event_data->fileptr);"));
10373 O(("#endif"));
10374 O((" }"));
10375 O((" break;"));
10376
10377 // Handle the loading event
10378 O((" case EVT_RESTORESTATE:"));
10379 O((" {"));
10380 O((" tOSIRISEVTRESTORESTATE *event_data=&data->evt_restorestate;"));
10381 O((" "));
10382 O((" RestoreGlobalActionCtrs(event_data->fileptr);"));
10383 O((" dfRestore(event_data->fileptr);"));
10384 O(("#ifdef ENABLE_CUSTOM_SAVE_AND_RESTORE"));
10385 O((" dsCustomRestore(event_data->fileptr);"));
10386 O(("#endif"));
10387 O((" }"));
10388 O((" break;"));
10389
10390 // Create the valid event case statements
10391 for (j = 0; j < MAX_EVENT_TYPES; j++) {
10392 tEventSection *event_section;
10393 if (owner_group != NULL)
10394 event_section = &owner_group->event_sections[j];
10395 else
10396 event_section = NULL;
10397
10398 // See if this case has certain events
10399 if (j != LEVEL_START_EVENT_TYPE && (event_section == NULL || event_section->num_script_nodes == 0))
10400 continue;
10401
10402 O((" case %s:", GetEventCodeName(j)));
10403 O((" {"));
10404
10405 // Get the event data code line and write it out
10406 O((" %s", GetEventDataLine(j)));
10407
10408 // If it's a LEVEL STARTED event, then initialize all the data
10409 if (j == LEVEL_START_EVENT_TYPE) {
10410 O((" "));
10411 O((" ClearGlobalActionCtrs();"));
10412 O((" dfInit();"));
10413 }
10414
10415 // If it's a DESTROYED event, then add the conditional code to
10416 // break out if the object is being destroyed because the level is ending
10417 if (j == DESTROYED_EVENT_TYPE) {
10418 O((" "));
10419 O((" // If destroy event is due to level ending, don't run scripts"));
10420 O((" if(!event_data->is_dying) break;"));
10421 }
10422
10423 // If there is an owner group, do the scripts
10424 if (event_section != NULL) {
10425 // Write out all the scripts for this event case
10426 for (k = 0; k < event_section->num_script_nodes; k++)
10427 WriteScriptCode(event_section->script_node_list[k]);
10428 }
10429
10430 O((" }"));
10431 O((" break;"));
10432 }
10433 }
10434
10435 // Creates the event cases
10436 void CDallasMainDlg::CreateEventCases(tScriptOwnerGroup *owner_group) {
10437 int j, k;
10438
10439 if (CurrentOutputFile == NULL || owner_group == NULL)
10440 return;
10441
10442 // Create the valid event case statements
10443 for (j = 0; j < MAX_EVENT_TYPES; j++) {
10444 tEventSection *event_section = &owner_group->event_sections[j];
10445 if (event_section->num_script_nodes == 0)
10446 continue;
10447 O((" case %s:", GetEventCodeName(j)));
10448 O((" {"));
10449
10450 // Get the event data code line and write it out
10451 O((" %s", GetEventDataLine(j)));
10452
10453 // If it's a DESTROYED event, then add the conditional code to
10454 // break out if the object is being destroyed because the level is ending
10455 if (j == DESTROYED_EVENT_TYPE) {
10456 O((" "));
10457 O((" // If destroy event is due to level ending, don't run scripts"));
10458 O((" if(!event_data->is_dying) break;"));
10459 }
10460
10461 // Write out all the scripts for this event case
10462 for (k = 0; k < event_section->num_script_nodes; k++)
10463 WriteScriptCode(event_section->script_node_list[k]);
10464
10465 O((" }"));
10466 O((" break;"));
10467 }
10468 }
10469
10470 // Writes out the code for the given script (handles the top level IF-THEN)
10471 void CDallasMainDlg::WriteScriptCode(HTREEITEM script_node) {
10472 HTREEITEM conditional_header_node, action_header_node;
10473 tTreeNodeData *data;
10474
10475 if (CurrentOutputFile == NULL || script_node == NULL)
10476 return;
10477
10478 data = (tTreeNodeData *)m_ScriptTree.GetItemData(script_node);
10479 if (data == NULL || data->type != SCRIPT_HEADER_NODE)
10480 return;
10481
10482 // Comment this section of script
10483 O((" "));
10484 O((" // Script %03d: %s", data->ID, data->name));
10485
10486 // Set the tab level
10487 CurrentTabLevel = 4;
10488
10489 // Write out the top level conditional statement
10490 conditional_header_node = GetConditionalHeaderNode(script_node);
10491 WriteConditionalCodeBlock(conditional_header_node);
10492
10493 // Write out the top level action block
10494 action_header_node = GetActionHeaderNode(script_node);
10495 WriteActionCodeBlock(action_header_node);
10496 }
10497
10498 // Writes out the code body for a conditional header block (an IF statement)
10499 void CDallasMainDlg::WriteConditionalCodeBlock(HTREEITEM conditional_header_node) {
10500 tTreeNodeData *data, *action_hdr_data;
10501 HTREEITEM child_node, action_hdr_node;
10502
10503 if (CurrentOutputFile == NULL || conditional_header_node == NULL)
10504 return;
10505
10506 data = (tTreeNodeData *)m_ScriptTree.GetItemData(conditional_header_node);
10507 if (data == NULL || data->type != CONDITIONAL_HEADER_NODE)
10508 return;
10509
10510 // Get the first child (literal or query)
10511 child_node = m_ScriptTree.GetChildItem(conditional_header_node);
10512 if (child_node == NULL)
10513 return;
10514
10515 TabOver();
10516 cfprintf(CurrentOutputFile, "if(");
10517
10518 // Write out the max script execution times conditional (if it's not infinite)
10519 action_hdr_data = NULL;
10520 if (data->ID == TOP_LEVEL) {
10521 action_hdr_node = GetActionHeaderNode(conditional_header_node);
10522 if (action_hdr_node != NULL) {
10523 action_hdr_data = (tTreeNodeData *)m_ScriptTree.GetItemData(action_hdr_node);
10524 if (action_hdr_data != NULL && action_hdr_data->subID != 0) {
10525 CString tmp_name = CreateScriptGlobalCtrName(GetScriptID(action_hdr_node));
10526 cfprintf(CurrentOutputFile, "(%s < %d) && (", tmp_name.GetBuffer(0), action_hdr_data->subID);
10527 }
10528 }
10529 }
10530
10531 // Write out the conditional expressions
10532 WriteLogicalOpExpression(child_node);
10533
10534 // If max script execution expression was added, then tack on another parentheses
10535 if (action_hdr_data != NULL && action_hdr_data->subID != 0) {
10536 cfprintf(CurrentOutputFile, ")");
10537 }
10538
10539 O((")"));
10540 }
10541
10542 // Writes out a logical operation block (AND, OR)
10543 void CDallasMainDlg::WriteLogicalOpExpression(HTREEITEM logop_node) {
10544 tTreeNodeData *data;
10545 HTREEITEM child_node;
10546
10547 if (CurrentOutputFile == NULL || logop_node == NULL)
10548 return;
10549
10550 data = (tTreeNodeData *)m_ScriptTree.GetItemData(logop_node);
10551 if (data == NULL || (data->type != LOGICAL_OPERATOR_NODE && data->type != CONDITIONAL_STATEMENT_NODE))
10552 return;
10553
10554 // If it's a Condition, write it out
10555 if (data->type == CONDITIONAL_STATEMENT_NODE) {
10556 WriteConditionalStatement(logop_node);
10557 return;
10558 }
10559
10560 // If it's an AND or an OR, process it
10561 if (data->ID == AND_TYPE || data->ID == OR_TYPE) {
10562 child_node = m_ScriptTree.GetChildItem(logop_node);
10563 while (child_node != NULL) {
10564 cfprintf(CurrentOutputFile, "(");
10565 WriteLogicalOpExpression(child_node);
10566 cfprintf(CurrentOutputFile, ")");
10567 child_node = m_ScriptTree.GetNextSiblingItem(child_node);
10568 if (child_node != NULL) {
10569 if (data->ID == AND_TYPE)
10570 cfprintf(CurrentOutputFile, " && ");
10571 else
10572 cfprintf(CurrentOutputFile, " || ");
10573 }
10574 }
10575 }
10576 }
10577
10578 // Writes out a conditional statement
10579 void CDallasMainDlg::WriteConditionalStatement(HTREEITEM condition_node) {
10580 tTreeNodeData *data;
10581 HTREEITEM child_node;
10582
10583 if (CurrentOutputFile == NULL || condition_node == NULL)
10584 return;
10585
10586 data = (tTreeNodeData *)m_ScriptTree.GetItemData(condition_node);
10587 if (data == NULL || data->type != CONDITIONAL_STATEMENT_NODE)
10588 return;
10589
10590 // If it's an ALWAYS statement, just write out a 1 and get outta here
10591 if (data->ID == ALWAYS_STATEMENT) {
10592 cfprintf(CurrentOutputFile, "1");
10593 return;
10594 }
10595
10596 // Get the first child (literal or query)
10597 child_node = m_ScriptTree.GetChildItem(condition_node);
10598 if (child_node != NULL) {
10599 WriteFunctionParameter(child_node);
10600 } else {
10601 cfprintf(CurrentOutputFile, "???");
10602 }
10603
10604 // Get the second child (expression operator)
10605 if (child_node != NULL) {
10606 child_node = m_ScriptTree.GetNextSiblingItem(child_node);
10607 if (child_node != NULL) {
10608 tTreeNodeData *child_data;
10609 child_data = (tTreeNodeData *)m_ScriptTree.GetItemData(child_node);
10610 if (child_data != NULL && child_data->type == EXPRESSION_OPERATOR_NODE) {
10611 cfprintf(CurrentOutputFile, "%s", GetExpressionOperatorCodeName(child_data->subID));
10612 } else
10613 cfprintf(CurrentOutputFile, "/* Exp Op Error */");
10614 } else {
10615 cfprintf(CurrentOutputFile, "/* Exp Op Missing */");
10616 }
10617 }
10618
10619 // If it's a comparison, get the third child (literal or query)
10620 if (child_node != NULL && data->ID == COMPARISON_STATEMENT) {
10621 child_node = m_ScriptTree.GetNextSiblingItem(child_node);
10622 if (child_node != NULL) {
10623 WriteFunctionParameter(child_node);
10624 } else {
10625 cfprintf(CurrentOutputFile, "/* 2nd Comparison Value Missing */");
10626 }
10627 }
10628 }
10629
10630 // Writes out a query function call
10631 void CDallasMainDlg::WriteQueryFunctionCall(HTREEITEM query_node) {
10632 tTreeNodeData *data;
10633
10634 if (CurrentOutputFile == NULL || query_node == NULL)
10635 return;
10636
10637 data = (tTreeNodeData *)m_ScriptTree.GetItemData(query_node);
10638 if (data == NULL || data->type != EXPRESSION_NODE)
10639 return;
10640
10641 // Check Query ID validity
10642 if (data->ID < 0 || data->ID >= m_NumQueries) {
10643 cfprintf(CurrentOutputFile, "/* ERROR: Invalid Query Function Encountered!!! */");
10644 return;
10645 }
10646
10647 // Handle the DALLAS custom queries first
10648 if (strcmp(m_QueryDatabase[data->ID].func, "qScriptExecuted_DALLAS") == 0) {
10649 HTREEITEM child_node;
10650 tTreeNodeData *child_data;
10651 child_node = m_ScriptTree.GetChildItem(query_node);
10652 if (child_node == NULL)
10653 return;
10654 child_data = (tTreeNodeData *)m_ScriptTree.GetItemData(child_node);
10655 if (child_data == NULL || child_data->type != PARAMETER_NODE || child_data->ID != SCRIPT_PARAMETER_TYPE)
10656 return;
10657 CString tmp_name = CreateScriptGlobalCtrName(child_data->int_val);
10658 cfprintf(CurrentOutputFile, "(%s > 0)", tmp_name.GetBuffer(0));
10659 return;
10660 }
10661 if (strcmp(m_QueryDatabase[data->ID].func, "qTimesScriptExecuted_DALLAS") == 0) {
10662 HTREEITEM child_node;
10663 tTreeNodeData *child_data;
10664 child_node = m_ScriptTree.GetChildItem(query_node);
10665 if (child_node == NULL)
10666 return;
10667 child_data = (tTreeNodeData *)m_ScriptTree.GetItemData(child_node);
10668 if (child_data == NULL || child_data->type != PARAMETER_NODE || child_data->ID != SCRIPT_PARAMETER_TYPE)
10669 return;
10670 CString tmp_name = CreateScriptGlobalCtrName(child_data->int_val);
10671 cfprintf(CurrentOutputFile, "%s", tmp_name.GetBuffer(0));
10672 return;
10673 }
10674
10675 // Write out the function name
10676 cfprintf(CurrentOutputFile, "%s(", m_QueryDatabase[data->ID].func);
10677
10678 // Write out the parameter arguments
10679 HTREEITEM param_node;
10680
10681 param_node = m_ScriptTree.GetChildItem(query_node);
10682 while (param_node != NULL) {
10683 WriteFunctionParameter(param_node);
10684 param_node = m_ScriptTree.GetNextSiblingItem(param_node);
10685 if (param_node != NULL)
10686 cfprintf(CurrentOutputFile, ", ");
10687 }
10688 cfprintf(CurrentOutputFile, ")");
10689 }
10690
10691 // Writes out the code body for an action header block (the block to immediately follow an IF statement)
10692 void CDallasMainDlg::WriteActionCodeBlock(HTREEITEM action_header_node) {
10693 HTREEITEM child_node;
10694 tTreeNodeData *header_data, *data;
10695
10696 if (action_header_node == NULL)
10697 return;
10698
10699 header_data = (tTreeNodeData *)m_ScriptTree.GetItemData(action_header_node);
10700 if (header_data == NULL || header_data->type != ACTIONS_HEADER_NODE)
10701 return;
10702
10703 // Write out starting brace
10704 TabOver();
10705 if (header_data->ID == NESTED && header_data->subID == ELSE_CLAUSE)
10706 O(("else {"));
10707 else
10708 O(("{"));
10709
10710 CurrentTabLevel++;
10711
10712 child_node = m_ScriptTree.GetChildItem(action_header_node);
10713 while (child_node != NULL) {
10714
10715 // Get the type of child node this is
10716 data = (tTreeNodeData *)m_ScriptTree.GetItemData(child_node);
10717 if (data != NULL) {
10718 if (data->type == ACTION_STATEMENT_NODE) {
10719 WriteActionFunctionCall(child_node);
10720 } else if (data->type == CONDITIONAL_HEADER_NODE) {
10721 WriteConditionalCodeBlock(child_node);
10722 } else if (data->type == ACTIONS_HEADER_NODE) {
10723 WriteActionCodeBlock(child_node);
10724 }
10725 }
10726
10727 // Get the next node
10728 child_node = m_ScriptTree.GetNextSiblingItem(child_node);
10729 }
10730
10731 // If it's a top level action header node, increment the global counter
10732 if (header_data->ID == TOP_LEVEL) {
10733 CString tmp_name = CreateScriptGlobalCtrName(GetScriptID(action_header_node));
10734
10735 TabOver();
10736 O((""));
10737 TabOver();
10738 O(("// Increment the script action counter"));
10739 TabOver();
10740 O(("if(%s < MAX_ACTION_CTR_VALUE) %s++;", tmp_name.GetBuffer(0), tmp_name.GetBuffer(0)));
10741
10742 // If user wants to break script chain, do it here
10743 if (header_data->int_val == BREAK_SCRIPT_CHAIN) {
10744 TabOver();
10745 O((""));
10746 TabOver();
10747 O(("return CONTINUE_DEFAULT;"));
10748 }
10749 }
10750
10751 CurrentTabLevel--;
10752
10753 // Write out closing brace
10754 TabOver();
10755 O(("}"));
10756 }
10757
10758 // Writes out an action function call
10759 void CDallasMainDlg::WriteActionFunctionCall(HTREEITEM action_node) {
10760 tTreeNodeData *data;
10761
10762 if (CurrentOutputFile == NULL || action_node == NULL)
10763 return;
10764
10765 data = (tTreeNodeData *)m_ScriptTree.GetItemData(action_node);
10766 if (data == NULL || data->type != ACTION_STATEMENT_NODE)
10767 return;
10768
10769 // Check Action ID validity
10770 if (data->ID < 0 || data->ID >= m_NumActions) {
10771 if (data->ID != DO_NOTHING_ID) {
10772 TabOver();
10773 O(("// ERROR: Invalid Action Function Encountered!!!"));
10774 }
10775 return;
10776 }
10777
10778 // Write out the function name
10779 TabOver();
10780 cfprintf(CurrentOutputFile, "%s(", m_ActionDatabase[data->ID].func);
10781
10782 // Write out the parameter arguments
10783 HTREEITEM param_node;
10784
10785 param_node = m_ScriptTree.GetChildItem(action_node);
10786 while (param_node != NULL) {
10787 WriteFunctionParameter(param_node);
10788 param_node = m_ScriptTree.GetNextSiblingItem(param_node);
10789 if (param_node != NULL)
10790 cfprintf(CurrentOutputFile, ", ");
10791 }
10792 O((");"));
10793 }
10794
10795 // Writes out an action function call
10796 void CDallasMainDlg::WriteFunctionParameter(HTREEITEM param_node) {
10797 tTreeNodeData *data;
10798 int index;
10799
10800 if (CurrentOutputFile == NULL || param_node == NULL)
10801 return;
10802
10803 data = (tTreeNodeData *)m_ScriptTree.GetItemData(param_node);
10804 if (data == NULL || (data->type != PARAMETER_NODE && data->type != EXPRESSION_NODE))
10805 return;
10806
10807 // If it's a query, write out the query function
10808 if (data->type == EXPRESSION_NODE) {
10809 WriteQueryFunctionCall(param_node);
10810 return;
10811 }
10812
10813 // Output the parameter values
10814 switch (data->ID) {
10815 case DOOR_PARAMETER_TYPE:
10816 if (data->subID == USE_IT_HANDLE)
10817 cfprintf(CurrentOutputFile, "event_data->it_handle");
10818 else if (data->subID == USE_ME_HANDLE)
10819 cfprintf(CurrentOutputFile, "data->me_handle");
10820 else {
10821 int index = FindDoorInList(data->str_val);
10822 if (index < 0 || strlen(data->str_val) == 0)
10823 cfprintf(CurrentOutputFile, "%d", OBJECT_HANDLE_NONE);
10824 else
10825 cfprintf(CurrentOutputFile, "Door_handles[%d]", index);
10826 }
10827 break;
10828 case OBJECT_PARAMETER_TYPE:
10829 if (data->subID == USE_IT_HANDLE)
10830 cfprintf(CurrentOutputFile, "event_data->it_handle");
10831 else if (data->subID == USE_ME_HANDLE)
10832 cfprintf(CurrentOutputFile, "data->me_handle");
10833 else {
10834 int index = FindObjectInList(data->str_val);
10835 if (index < 0 || strlen(data->str_val) == 0)
10836 cfprintf(CurrentOutputFile, "%d", OBJECT_HANDLE_NONE);
10837 else
10838 cfprintf(CurrentOutputFile, "Object_handles[%d]", index);
10839 }
10840 break;
10841 case ROOM_PARAMETER_TYPE:
10842 index = FindRoomInList(data->str_val);
10843 if (index < 0 || strlen(data->str_val) == 0)
10844 cfprintf(CurrentOutputFile, "%d", -1);
10845 else
10846 cfprintf(CurrentOutputFile, "Room_indexes[%d]", index);
10847 break;
10848 case TRIGGER_PARAMETER_TYPE:
10849 index = FindTriggerInList(data->str_val);
10850 if (index < 0 || strlen(data->str_val) == 0)
10851 cfprintf(CurrentOutputFile, "%d", -1);
10852 else
10853 cfprintf(CurrentOutputFile, "Trigger_indexes[%d]", index);
10854 break;
10855 case INT_PARAMETER_TYPE:
10856 cfprintf(CurrentOutputFile, "%d", data->int_val);
10857 break;
10858 case BOOL_PARAMETER_TYPE:
10859 cfprintf(CurrentOutputFile, "%d", data->int_val);
10860 break;
10861 case FLOAT_PARAMETER_TYPE:
10862 cfprintf(CurrentOutputFile, "%ff", data->float_val1);
10863 break;
10864 case VECTOR_PARAMETER_TYPE:
10865 cfprintf(CurrentOutputFile, "NO VECTOR YET");
10866 break;
10867 case STRING_PARAMETER_TYPE:
10868 index = FindMessageNameInList(data->str_val);
10869 if (index < 0 || strlen(data->str_val) == 0)
10870 cfprintf(CurrentOutputFile, "\"*MESSAGE_ERROR*\"");
10871 else
10872 cfprintf(CurrentOutputFile, "Message_strings[%d]", index);
10873 break;
10874 case PERCENTAGE_PARAMETER_TYPE:
10875 cfprintf(CurrentOutputFile, "%ff", data->float_val1);
10876 break;
10877 case ENUM_PARAMETER_TYPE:
10878 if (data->subID == USE_GOALID_VALUE)
10879 cfprintf(CurrentOutputFile, "event_data->goal_uid");
10880 else if (data->subID == USE_TIMERID_VALUE)
10881 cfprintf(CurrentOutputFile, "event_data->id");
10882 else if (data->subID == USE_MATCENID_VALUE)
10883 cfprintf(CurrentOutputFile, "event_data->id");
10884 else {
10885 cfprintf(CurrentOutputFile, "%d", data->int_val);
10886 }
10887 break;
10888 case SCRIPT_PARAMETER_TYPE:
10889 cfprintf(CurrentOutputFile, "%d", data->int_val);
10890 break;
10891 case SOUND_PARAMETER_TYPE:
10892 index = FindSoundInList(data->str_val);
10893 if (index < 0 || strlen(data->str_val) == 0)
10894 cfprintf(CurrentOutputFile, "%d", -1);
10895 else
10896 cfprintf(CurrentOutputFile, "Sound_indexes[%d]", index);
10897 break;
10898 case SPECNAME_PARAMETER_TYPE:
10899 cfprintf(CurrentOutputFile, "\"%s\"", data->str_val);
10900 break;
10901 case TEXTURE_PARAMETER_TYPE:
10902 index = FindTextureInList(data->str_val);
10903 if (index < 0 || strlen(data->str_val) == 0)
10904 cfprintf(CurrentOutputFile, "%d", -1);
10905 else
10906 cfprintf(CurrentOutputFile, "Texture_indexes[%d]", index);
10907 break;
10908 case FLAG_PARAMETER_TYPE:
10909 cfprintf(CurrentOutputFile, "%d", data->int_val);
10910 break;
10911 case PATH_PARAMETER_TYPE:
10912 index = FindPathInList(data->str_val);
10913 if (index < 0 || strlen(data->str_val) == 0)
10914 cfprintf(CurrentOutputFile, "%d", -1);
10915 else
10916 cfprintf(CurrentOutputFile, "Path_indexes[%d]", index);
10917 break;
10918 case MATCEN_PARAMETER_TYPE:
10919 if (data->subID == USE_MATCEN_EVENT_ID) {
10920 cfprintf(CurrentOutputFile, "event_data->id");
10921 } else {
10922 index = FindMatcenInList(data->str_val);
10923 if (index < 0 || strlen(data->str_val) == 0)
10924 cfprintf(CurrentOutputFile, "%d", -1);
10925 else
10926 cfprintf(CurrentOutputFile, "Matcen_indexes[%d]", index);
10927 }
10928 break;
10929 case LEVEL_GOAL_PARAMETER_TYPE:
10930 if (data->subID == USE_LEVEL_GOAL_ID) {
10931 cfprintf(CurrentOutputFile, "event_data->level_goal_index");
10932 } else {
10933 index = FindGoalInList(data->str_val);
10934 if (index < 0 || strlen(data->str_val) == 0)
10935 cfprintf(CurrentOutputFile, "%d", -1);
10936 else
10937 cfprintf(CurrentOutputFile, "Goal_indexes[%d]", index);
10938 }
10939 break;
10940 case STRM_AUDIO_PARAMETER_TYPE:
10941 cfprintf(CurrentOutputFile, "\"%s\"", data->str_val);
10942 break;
10943 default:
10944 break;
10945 }
10946 }
10947
10948 // Creates the tree block (for saving scripts)
10949 void CDallasMainDlg::WriteScriptSaveBlock(void) {
10950 if (CurrentOutputFile == NULL)
10951 return;
10952
10953 // Create the header
10954 O((" "));
10955 O((" "));
10956 O(("/*********************************************************"));
10957 O(("Script Save Block: DO NOT TOUCH ANYTHING IN THIS BLOCK!!! "));
10958 O(("**********************************************************"));
10959 O(("%s", SCRIPT_BLOCK_START_TAG));
10960 O((" "));
10961 O(("VERSION %d", DALLAS_SAVE_VERSION));
10962 O(("NEXT_ID %d", m_NextScriptID));
10963 O((" "));
10964 O(("// UserType value blocks"));
10965
10966 // Writes out the name lists
10967 WriteUserTypeVals();
10968
10969 O((" "));
10970 O(("// Name Lists"));
10971 // Writes out the name lists
10972 WriteNameLists();
10973
10974 O((" "));
10975 O(("// Script Tree Dump"));
10976
10977 // Write out the list of nodes
10978 WriteScriptTreeDump();
10979
10980 O((" "));
10981 O(("%s", SCRIPT_BLOCK_END_TAG));
10982 O(("*********************************************************/"));
10983 }
10984
10985 // Writes out the UserType value blocks
10986 void CDallasMainDlg::WriteUserTypeVals(void) {
10987 int j, k;
10988
10989 if (CurrentOutputFile == NULL)
10990 return;
10991
10992 for (j = 0; j < m_NumEnums; j++) {
10993 if (m_EnumDatabase[j].is_user_type) {
10994 O(("%s %s", USERTYPE_VALS_START_TAG, m_EnumDatabase[j].name));
10995 for (k = 0; k < m_EnumDatabase[j].num_values; k++) {
10996 tEnumValueEntry *value_entry = &m_EnumDatabase[j].values[k];
10997 if (value_entry->value != -1)
10998 O(("%d:%s", value_entry->value, value_entry->name));
10999 }
11000 O(("%s", USERTYPE_VALS_END_TAG));
11001 O((" "));
11002 }
11003 }
11004 }
11005
11006 // Writes out the name lists
11007 void CDallasMainDlg::WriteNameLists(void) {
11008 int j;
11009
11010 if (CurrentOutputFile == NULL)
11011 return;
11012
11013 // Write out the door list
11014 O(("%s", DOOR_LIST_START_TAG));
11015 for (j = 0; j < m_DoorListSize; j++)
11016 O(("%s", m_DoorList[j]));
11017 O(("%s", DOOR_LIST_END_TAG));
11018 O((" "));
11019
11020 // Write out the object list
11021 O(("%s", OBJECT_LIST_START_TAG));
11022 for (j = 0; j < m_ObjectListSize; j++)
11023 O(("%s", m_ObjectList[j]));
11024 O(("%s", OBJECT_LIST_END_TAG));
11025 O((" "));
11026
11027 // Write out the room list
11028 O(("%s", ROOM_LIST_START_TAG));
11029 for (j = 0; j < m_RoomListSize; j++)
11030 O(("%s", m_RoomList[j]));
11031 O(("%s", ROOM_LIST_END_TAG));
11032 O((" "));
11033
11034 // Write out the trigger list
11035 O(("%s", TRIGGER_LIST_START_TAG));
11036 for (j = 0; j < m_TriggerListSize; j++)
11037 O(("%s", m_TriggerList[j]));
11038 O(("%s", TRIGGER_LIST_END_TAG));
11039 O((" "));
11040
11041 // Write out the sound list
11042 O(("%s", SOUND_LIST_START_TAG));
11043 for (j = 0; j < m_SoundListSize; j++)
11044 O(("%s", m_SoundList[j]));
11045 O(("%s", SOUND_LIST_END_TAG));
11046 O((" "));
11047
11048 // Write out the texture list
11049 O(("%s", TEXTURE_LIST_START_TAG));
11050 for (j = 0; j < m_TextureListSize; j++)
11051 O(("%s", m_TextureList[j]));
11052 O(("%s", TEXTURE_LIST_END_TAG));
11053 O((" "));
11054
11055 // Write out the specname list
11056 O(("%s", SPECNAME_LIST_START_TAG));
11057 for (j = 0; j < m_SpecnameListSize; j++)
11058 O(("%s", m_SpecnameList[j]));
11059 O(("%s", SPECNAME_LIST_END_TAG));
11060 O((" "));
11061
11062 // Write out the Path list
11063 O(("%s", PATH_LIST_START_TAG));
11064 for (j = 0; j < m_PathListSize; j++)
11065 O(("%s", m_PathList[j]));
11066 O(("%s", PATH_LIST_END_TAG));
11067 O((" "));
11068
11069 // Write out the Matcen list
11070 O(("%s", MATCEN_LIST_START_TAG));
11071 for (j = 0; j < m_MatcenListSize; j++)
11072 O(("%s", m_MatcenList[j]));
11073 O(("%s", MATCEN_LIST_END_TAG));
11074 O((" "));
11075
11076 // Write out the Goal list
11077 O(("%s", GOAL_LIST_START_TAG));
11078 for (j = 0; j < m_GoalListSize; j++)
11079 O(("%s", m_GoalList[j]));
11080 O(("%s", GOAL_LIST_END_TAG));
11081 O((" "));
11082
11083 // Write out the StrmAudio list
11084 O(("%s", STRM_AUDIO_LIST_START_TAG));
11085 for (j = 0; j < m_StrmAudioListSize; j++)
11086 O(("%s", m_StrmAudioList[j]));
11087 O(("%s", STRM_AUDIO_LIST_END_TAG));
11088 O((" "));
11089 }
11090
11091 // Writes out the name list arrays in the code
11092 void CDallasMainDlg::WriteNameListArrays(void) {
11093 int j;
11094
11095 if (CurrentOutputFile == NULL)
11096 return;
11097
11098 O((" "));
11099 O(("//======================"));
11100 O(("// Name List Arrays "));
11101 O(("//======================"));
11102 O((" "));
11103
11104 // Write out the door list
11105 O(("#define NUM_DOOR_NAMES %d", m_DoorListSize));
11106 if (m_DoorListSize > 0) {
11107 O(("const char *Door_names[NUM_DOOR_NAMES] = {"));
11108 for (j = 0; j < (m_DoorListSize - 1); j++)
11109 O((" \"%s\",", m_DoorList[j]));
11110 O((" \"%s\"", m_DoorList[j]));
11111 O(("};"));
11112 O(("int Door_handles[NUM_DOOR_NAMES];"));
11113 } else {
11114 O(("const char **Door_names=NULL;"));
11115 O(("int *Door_handles=NULL;"));
11116 }
11117 O((" "));
11118
11119 // Write out the object list
11120 O(("#define NUM_OBJECT_NAMES %d", m_ObjectListSize));
11121 if (m_ObjectListSize > 0) {
11122 O(("const char *Object_names[NUM_OBJECT_NAMES] = {"));
11123 for (j = 0; j < (m_ObjectListSize - 1); j++)
11124 O((" \"%s\",", m_ObjectList[j]));
11125 O((" \"%s\"", m_ObjectList[j]));
11126 O(("};"));
11127 O(("int Object_handles[NUM_OBJECT_NAMES];"));
11128 } else {
11129 O(("const char **Object_names=NULL;"));
11130 O(("int *Object_handles=NULL;"));
11131 }
11132 O((" "));
11133
11134 // Write out the room list
11135 O(("#define NUM_ROOM_NAMES %d", m_RoomListSize));
11136 if (m_RoomListSize > 0) {
11137 O(("const char *Room_names[NUM_ROOM_NAMES] = {"));
11138 for (j = 0; j < (m_RoomListSize - 1); j++)
11139 O((" \"%s\",", m_RoomList[j]));
11140 O((" \"%s\"", m_RoomList[j]));
11141 O(("};"));
11142 O(("int Room_indexes[NUM_ROOM_NAMES];"));
11143 } else {
11144 O(("const char **Room_names=NULL;"));
11145 O(("int *Room_indexes=NULL;"));
11146 }
11147 O((" "));
11148
11149 // Write out the Trigger list
11150 O(("#define NUM_TRIGGER_NAMES %d", m_TriggerListSize));
11151 if (m_TriggerListSize > 0) {
11152 O(("const char *Trigger_names[NUM_TRIGGER_NAMES] = {"));
11153 for (j = 0; j < (m_TriggerListSize - 1); j++)
11154 O((" \"%s\",", m_TriggerList[j]));
11155 O((" \"%s\"", m_TriggerList[j]));
11156 O(("};"));
11157 O(("int Trigger_indexes[NUM_TRIGGER_NAMES];"));
11158 O(("int Trigger_faces[NUM_TRIGGER_NAMES];"));
11159 O(("int Trigger_rooms[NUM_TRIGGER_NAMES];"));
11160 } else {
11161 O(("const char **Trigger_names=NULL;"));
11162 O(("int *Trigger_indexes=NULL;"));
11163 O(("int *Trigger_faces=NULL;"));
11164 O(("int *Trigger_rooms=NULL;"));
11165 }
11166 O((" "));
11167
11168 // Write out the sound list
11169 O(("#define NUM_SOUND_NAMES %d", m_SoundListSize));
11170 if (m_SoundListSize > 0) {
11171 O(("const char *Sound_names[NUM_SOUND_NAMES] = {"));
11172 for (j = 0; j < (m_SoundListSize - 1); j++)
11173 O((" \"%s\",", m_SoundList[j]));
11174 O((" \"%s\"", m_SoundList[j]));
11175 O(("};"));
11176 O(("int Sound_indexes[NUM_SOUND_NAMES];"));
11177 } else {
11178 O(("const char **Sound_names=NULL;"));
11179 O(("int *Sound_indexes=NULL;"));
11180 }
11181 O((" "));
11182
11183 // Write out the texture list
11184 O(("#define NUM_TEXTURE_NAMES %d", m_TextureListSize));
11185 if (m_TextureListSize > 0) {
11186 O(("const char *Texture_names[NUM_TEXTURE_NAMES] = {"));
11187 for (j = 0; j < (m_TextureListSize - 1); j++)
11188 O((" \"%s\",", m_TextureList[j]));
11189 O((" \"%s\"", m_TextureList[j]));
11190 O(("};"));
11191 O(("int Texture_indexes[NUM_TEXTURE_NAMES];"));
11192 } else {
11193 O(("const char **Texture_names=NULL;"));
11194 O(("int *Texture_indexes=NULL;"));
11195 }
11196 O((" "));
11197
11198 // Write out the Path list
11199 O(("#define NUM_PATH_NAMES %d", m_PathListSize));
11200 if (m_PathListSize > 0) {
11201 O(("const char *Path_names[NUM_PATH_NAMES] = {"));
11202 for (j = 0; j < (m_PathListSize - 1); j++)
11203 O((" \"%s\",", m_PathList[j]));
11204 O((" \"%s\"", m_PathList[j]));
11205 O(("};"));
11206 O(("int Path_indexes[NUM_PATH_NAMES];"));
11207 } else {
11208 O(("const char **Path_names=NULL;"));
11209 O(("int *Path_indexes=NULL;"));
11210 }
11211 O((" "));
11212
11213 // Write out the Matcen list
11214 O(("#define NUM_MATCEN_NAMES %d", m_MatcenListSize));
11215 if (m_MatcenListSize > 0) {
11216 O(("const char *Matcen_names[NUM_MATCEN_NAMES] = {"));
11217 for (j = 0; j < (m_MatcenListSize - 1); j++)
11218 O((" \"%s\",", m_MatcenList[j]));
11219 O((" \"%s\"", m_MatcenList[j]));
11220 O(("};"));
11221 O(("int Matcen_indexes[NUM_MATCEN_NAMES];"));
11222 } else {
11223 O(("const char **Matcen_names=NULL;"));
11224 O(("int *Matcen_indexes=NULL;"));
11225 }
11226 O((" "));
11227
11228 // Write out the Goal list
11229 O(("#define NUM_GOAL_NAMES %d", m_GoalListSize));
11230 if (m_GoalListSize > 0) {
11231 O(("const char *Goal_names[NUM_GOAL_NAMES] = {"));
11232 for (j = 0; j < (m_GoalListSize - 1); j++)
11233 O((" \"%s\",", m_GoalList[j]));
11234 O((" \"%s\"", m_GoalList[j]));
11235 O(("};"));
11236 O(("int Goal_indexes[NUM_GOAL_NAMES];"));
11237 } else {
11238 O(("const char **Goal_names=NULL;"));
11239 O(("int *Goal_indexes=NULL;"));
11240 }
11241 O((" "));
11242
11243 // Write out the message name list
11244 O(("#define NUM_MESSAGE_NAMES %d", m_MessageNameListSize));
11245 if (m_MessageNameListSize > 0) {
11246 O(("const char *Message_names[NUM_MESSAGE_NAMES] = {"));
11247 for (j = 0; j < (m_MessageNameListSize - 1); j++)
11248 O((" \"%s\",", m_MessageNameList[j]));
11249 O((" \"%s\"", m_MessageNameList[j]));
11250 O(("};"));
11251 O(("const char *Message_strings[NUM_MESSAGE_NAMES];"));
11252 } else {
11253 O(("const char **Message_names=NULL;"));
11254 O(("const char **Message_strings=NULL;"));
11255 }
11256 O((" "));
11257 }
11258
11259 // Writes out the name list lookup code
11260 void CDallasMainDlg::WriteNameArrayLookupCode(void) {
11261 O((" int j;"));
11262 O((" "));
11263 O((" // Do Door Index lookups"));
11264 O((" for(j=0;j<NUM_DOOR_NAMES;j++) "));
11265 O((" Door_handles[j]=Scrpt_FindDoorName(Door_names[j]);"));
11266 O((" "));
11267 O((" // Do Object Index lookups"));
11268 O((" for(j=0;j<NUM_OBJECT_NAMES;j++) "));
11269 O((" Object_handles[j]=Scrpt_FindObjectName(Object_names[j]);"));
11270 O((" "));
11271 O((" // Do Room Index lookups"));
11272 O((" for(j=0;j<NUM_ROOM_NAMES;j++) "));
11273 O((" Room_indexes[j]=Scrpt_FindRoomName(Room_names[j]);"));
11274 O((" "));
11275 O((" // Do Trigger Index lookups"));
11276 O((" for(j=0;j<NUM_TRIGGER_NAMES;j++) {"));
11277 O((" Trigger_indexes[j]=Scrpt_FindTriggerName(Trigger_names[j]);"));
11278 O((" Trigger_faces[j]=Scrpt_GetTriggerFace(Trigger_indexes[j]);"));
11279 O((" Trigger_rooms[j]=Scrpt_GetTriggerRoom(Trigger_indexes[j]);"));
11280 O((" }"));
11281 O((" "));
11282 O((" // Do Sound Index lookups"));
11283 O((" for(j=0;j<NUM_SOUND_NAMES;j++) "));
11284 O((" Sound_indexes[j]=Scrpt_FindSoundName(Sound_names[j]);"));
11285 O((" "));
11286 O((" // Do Texture Index lookups"));
11287 O((" for(j=0;j<NUM_TEXTURE_NAMES;j++) "));
11288 O((" Texture_indexes[j]=Scrpt_FindTextureName(Texture_names[j]);"));
11289 O((" "));
11290 O((" // Do Path Index lookups"));
11291 O((" for(j=0;j<NUM_PATH_NAMES;j++) "));
11292 O((" Path_indexes[j]=Scrpt_FindPathName(Path_names[j]);"));
11293 O((" "));
11294 O((" // Do Matcen Index lookups"));
11295 O((" for(j=0;j<NUM_MATCEN_NAMES;j++) "));
11296 O((" Matcen_indexes[j]=Scrpt_FindMatcenName(Matcen_names[j]);"));
11297 O((" "));
11298 O((" // Do Goal Index lookups"));
11299 O((" for(j=0;j<NUM_GOAL_NAMES;j++) "));
11300 O((" Goal_indexes[j]=Scrpt_FindLevelGoalName(Goal_names[j]);"));
11301 O((" "));
11302 O((" // Do Message Name lookups"));
11303 O((" for(j=0;j<NUM_MESSAGE_NAMES;j++) "));
11304 O((" Message_strings[j]=GetMessage(Message_names[j]);"));
11305 }
11306
11307 // Writes out a coded version of all the script nodes in the tree
11308 void CDallasMainDlg::WriteScriptTreeDump(void) {
11309 HTREEITEM node;
11310 tTreeNodeData *data;
11311
11312 if (CurrentOutputFile == NULL)
11313 return;
11314
11315 CurrentTabLevel = 0;
11316
11317 // Write out each script node (and any children)
11318 node = m_ScriptTree.GetChildItem(TVI_ROOT);
11319 while (node != NULL) {
11320 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
11321 if (data != NULL && data->type == SCRIPT_HEADER_NODE) {
11322 if (DALLAS_SAVE_VERSION >= 1)
11323 WriteScriptNodeDump_v1U(node);
11324 else
11325 WriteScriptNodeDump_v0(node);
11326
11327 WriteScriptChildrenDump(node);
11328 }
11329
11330 node = m_ScriptTree.GetNextSiblingItem(node);
11331 }
11332 }
11333
11334 // Writes out codes versions of all children of the given node
11335 void CDallasMainDlg::WriteScriptChildrenDump(HTREEITEM parent, bool filter_on /*=FALSE*/) {
11336 HTREEITEM child_node;
11337
11338 if (CurrentOutputFile == NULL || parent == NULL)
11339 return;
11340
11341 // Make sure the parent has at least one child
11342 child_node = m_ScriptTree.GetChildItem(parent);
11343 if (child_node == NULL)
11344 return;
11345
11346 // Write out each child node (and any of their children)
11347 CurrentTabLevel++;
11348 TabOver();
11349 O(("%s", CHILD_BLOCK_START_TAG));
11350 while (child_node != NULL) {
11351
11352 if (DALLAS_SAVE_VERSION >= 1)
11353 WriteScriptNodeDump_v1U(child_node, filter_on);
11354 else
11355 WriteScriptNodeDump_v0(child_node);
11356
11357 WriteScriptChildrenDump(child_node, filter_on);
11358 child_node = m_ScriptTree.GetNextSiblingItem(child_node);
11359 }
11360 TabOver();
11361 O(("%s", CHILD_BLOCK_END_TAG));
11362 CurrentTabLevel--;
11363 }
11364
11365 // VERSION 0: Writes out a coded version of the given script node
11366 void CDallasMainDlg::WriteScriptNodeDump_v0(HTREEITEM node) {
11367 tTreeNodeData *data;
11368 CString tmp_name;
11369 int index;
11370 char goal_name[_MAX_PATH + 1];
11371
11372 if (CurrentOutputFile == NULL || node == NULL)
11373 return;
11374
11375 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
11376 if (data == NULL)
11377 return;
11378
11379 TabOver();
11380 switch (data->type) {
11381 case SCRIPT_HEADER_NODE:
11382 cfprintf(CurrentOutputFile, "%02d:%d:%s", data->type, data->ID, data->name);
11383 break;
11384 case SCRIPT_OWNER_NODE:
11385 cfprintf(CurrentOutputFile, "%02d:%d:%d", data->type, data->ID, data->int_val);
11386 break;
11387 case SCRIPT_EVENT_NODE:
11388 cfprintf(CurrentOutputFile, "%02d:%d", data->type, data->ID);
11389 break;
11390 case CONDITIONAL_HEADER_NODE:
11391 cfprintf(CurrentOutputFile, "%02d:%d", data->type, data->ID);
11392 break;
11393 case ACTIONS_HEADER_NODE:
11394 cfprintf(CurrentOutputFile, "%02d:%d:%d", data->type, data->ID, data->subID);
11395 break;
11396 case CONDITIONAL_STATEMENT_NODE:
11397 cfprintf(CurrentOutputFile, "%02d:%d", data->type, data->ID);
11398 break;
11399 case EXPRESSION_NODE:
11400 cfprintf(CurrentOutputFile, "%02d:%s:%s", data->type, GetQueryFunc(data->ID), data->name);
11401 break;
11402 case EXPRESSION_OPERATOR_NODE:
11403 cfprintf(CurrentOutputFile, "%02d:%d:%d", data->type, data->ID, data->subID);
11404 break;
11405 case ACTION_STATEMENT_NODE:
11406 cfprintf(CurrentOutputFile, "%02d:%s", data->type, GetActionFunc(data->ID));
11407 break;
11408 case LOGICAL_OPERATOR_NODE:
11409 cfprintf(CurrentOutputFile, "%02d:%d", data->type, data->ID);
11410 break;
11411 case PARAMETER_NODE:
11412 // Get image type based upon what kind of parameter it is
11413 switch (data->ID) {
11414 case DOOR_PARAMETER_TYPE:
11415 cfprintf(CurrentOutputFile, "%02d:%d:%d:%d:%s", data->type, data->ID, data->subID, data->int_val, data->name);
11416 break;
11417 case OBJECT_PARAMETER_TYPE:
11418 cfprintf(CurrentOutputFile, "%02d:%d:%d:%d:%s", data->type, data->ID, data->subID, data->int_val, data->name);
11419 break;
11420 case ROOM_PARAMETER_TYPE:
11421 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, data->int_val, data->name);
11422 break;
11423 case TRIGGER_PARAMETER_TYPE:
11424 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, data->int_val, data->name);
11425 break;
11426 case INT_PARAMETER_TYPE:
11427 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, data->int_val, data->name);
11428 break;
11429 case BOOL_PARAMETER_TYPE:
11430 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, data->int_val, data->name);
11431 break;
11432 case FLOAT_PARAMETER_TYPE:
11433 cfprintf(CurrentOutputFile, "%02d:%d:%f:%s", data->type, data->ID, data->float_val1, data->name);
11434 break;
11435 case VECTOR_PARAMETER_TYPE:
11436 cfprintf(CurrentOutputFile, "%02d:%d:%f:%f:%f:%s", data->type, data->ID, data->float_val1, data->float_val2,
11437 data->float_val3, data->name);
11438 break;
11439 case STRING_PARAMETER_TYPE:
11440 cfprintf(CurrentOutputFile, "%02d:%d:%s:%s", data->type, data->ID, data->str_val, data->name);
11441 break;
11442 case PERCENTAGE_PARAMETER_TYPE:
11443 cfprintf(CurrentOutputFile, "%02d:%d:%f:%s", data->type, data->ID, data->float_val1, data->name);
11444 break;
11445 case ENUM_PARAMETER_TYPE:
11446 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, data->int_val, data->name);
11447 break;
11448 case SCRIPT_PARAMETER_TYPE:
11449 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, data->int_val, data->name);
11450 break;
11451 case SOUND_PARAMETER_TYPE:
11452 if (data->int_val == NOT_SPECIFIED_TYPE)
11453 index = -1;
11454 else
11455 index = FindSoundInList(Sounds[data->int_val].name);
11456 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, index, data->name);
11457 break;
11458 case SPECNAME_PARAMETER_TYPE:
11459 cfprintf(CurrentOutputFile, "%02d:%d:%s:%s", data->type, data->ID, data->str_val, data->name);
11460 break;
11461 case TEXTURE_PARAMETER_TYPE:
11462 if (data->int_val == NOT_SPECIFIED_TYPE)
11463 index = -1;
11464 else
11465 index = FindTextureInList(GameTextures[data->int_val].name);
11466 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, index, data->name);
11467 break;
11468 case FLAG_PARAMETER_TYPE:
11469 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, data->int_val, data->name);
11470 break;
11471 case PATH_PARAMETER_TYPE:
11472 if (data->int_val == NOT_SPECIFIED_TYPE)
11473 index = -1;
11474 else
11475 index = FindPathInList(GamePaths[data->int_val].name);
11476 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, index, data->name);
11477 break;
11478 case MATCEN_PARAMETER_TYPE:
11479 if (data->subID == USE_MATCEN_VALUE) {
11480 if (data->int_val == NOT_SPECIFIED_TYPE || !MatcenValid(data->int_val))
11481 index = -1;
11482 else {
11483 char matcen_name[MAX_MATCEN_NAME_LEN + 1];
11484 Matcen[data->int_val]->GetName(matcen_name);
11485 index = FindMatcenInList(matcen_name);
11486 }
11487 } else
11488 index = data->int_val;
11489 cfprintf(CurrentOutputFile, "%02d:%d:%d:%d:%s", data->type, data->ID, data->subID, index, data->name);
11490 break;
11491 case LEVEL_GOAL_PARAMETER_TYPE:
11492 if (data->subID == USE_LEVEL_GOAL_VALUE) {
11493 if (data->int_val == NOT_SPECIFIED_TYPE || Level_goals.GoalGetName(data->int_val, goal_name, _MAX_PATH) < 0)
11494 index = -1;
11495 else {
11496 index = FindGoalInList(goal_name);
11497 }
11498 } else
11499 index = data->int_val;
11500 cfprintf(CurrentOutputFile, "%02d:%d:%d:%d:%s", data->type, data->ID, data->subID, index, data->name);
11501 break;
11502 case STRM_AUDIO_PARAMETER_TYPE:
11503 if (strlen(data->str_val) == 0)
11504 index = NOT_SPECIFIED_TYPE;
11505 else
11506 index = FindStrmAudioInList(data->str_val);
11507 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, index, data->name);
11508 break;
11509 default:
11510 cfprintf(CurrentOutputFile, "%02d:%d:%s", data->type, data->ID, data->name);
11511 break;
11512 }
11513 break;
11514 case PARAMETER_OPERATOR_NODE:
11515 cfprintf(CurrentOutputFile, "%02d:%d", data->type, data->ID);
11516 break;
11517 case UNKNOWN_NODE:
11518 cfprintf(CurrentOutputFile, "%02d:%d", data->type, data->ID);
11519 break;
11520 default:
11521 cfprintf(CurrentOutputFile, "%02d:%d", UNKNOWN_NODE, data->ID);
11522 break;
11523 }
11524 O((" "));
11525 }
11526
11527 // VERSION 1: Writes out a coded version of the given script node
11528 void CDallasMainDlg::WriteScriptNodeDump_v1U(HTREEITEM node, bool filter_on /*=FALSE*/) {
11529 tTreeNodeData *data;
11530 CString tmp_name;
11531 int index;
11532
11533 if (CurrentOutputFile == NULL || node == NULL)
11534 return;
11535
11536 data = (tTreeNodeData *)m_ScriptTree.GetItemData(node);
11537 if (data == NULL)
11538 return;
11539
11540 TabOver();
11541 switch (data->type) {
11542 case SCRIPT_HEADER_NODE:
11543 cfprintf(CurrentOutputFile, "%02d:%d:%s", data->type, data->ID, data->name);
11544 break;
11545 case SCRIPT_OWNER_NODE:
11546 if (data->ID == OBJECT_TYPE) {
11547 if (filter_on || data->int_val == OBJECT_HANDLE_NONE || strlen(data->str_val) == 0)
11548 index = OBJECT_NONE_HANDLE;
11549 else
11550 index = FindObjectInList(data->str_val);
11551 } else if (data->ID == TRIGGER_TYPE) {
11552 if (filter_on || data->int_val == NOT_SPECIFIED_TYPE || strlen(data->str_val) == 0)
11553 index = NOT_SPECIFIED_TYPE;
11554 else
11555 index = FindTriggerInList(data->str_val);
11556 } else
11557 index = data->int_val;
11558 cfprintf(CurrentOutputFile, "%02d:%d:%d", data->type, data->ID, index);
11559 break;
11560 case SCRIPT_EVENT_NODE:
11561 cfprintf(CurrentOutputFile, "%02d:%d", data->type, data->ID);
11562 break;
11563 case CONDITIONAL_HEADER_NODE:
11564 cfprintf(CurrentOutputFile, "%02d:%d", data->type, data->ID);
11565 break;
11566 case ACTIONS_HEADER_NODE:
11567 if (DALLAS_SAVE_VERSION >= 3) {
11568 cfprintf(CurrentOutputFile, "%02d:%d:%d:%d", data->type, data->ID, data->int_val, data->subID);
11569 } else {
11570 cfprintf(CurrentOutputFile, "%02d:%d:%d", data->type, data->ID, data->subID);
11571 }
11572 break;
11573 case CONDITIONAL_STATEMENT_NODE:
11574 cfprintf(CurrentOutputFile, "%02d:%d", data->type, data->ID);
11575 break;
11576 case EXPRESSION_NODE:
11577 cfprintf(CurrentOutputFile, "%02d:%s:%s", data->type, GetQueryFunc(data->ID), data->name);
11578 break;
11579 case EXPRESSION_OPERATOR_NODE:
11580 cfprintf(CurrentOutputFile, "%02d:%d:%d", data->type, data->ID, data->subID);
11581 break;
11582 case ACTION_STATEMENT_NODE:
11583 cfprintf(CurrentOutputFile, "%02d:%s", data->type, GetActionFunc(data->ID));
11584 break;
11585 case LOGICAL_OPERATOR_NODE:
11586 cfprintf(CurrentOutputFile, "%02d:%d", data->type, data->ID);
11587 break;
11588 case PARAMETER_NODE:
11589 // Get image type based upon what kind of parameter it is
11590 switch (data->ID) {
11591 case DOOR_PARAMETER_TYPE:
11592 if (data->subID == USE_OBJECT_HANDLE) {
11593 if (filter_on || data->int_val == OBJECT_HANDLE_NONE || strlen(data->str_val) == 0)
11594 index = OBJECT_NONE_HANDLE;
11595 else
11596 index = FindDoorInList(data->str_val);
11597 } else
11598 index = data->int_val;
11599 cfprintf(CurrentOutputFile, "%02d:%d:%d:%d:%s", data->type, data->ID, data->subID, index, data->name);
11600 break;
11601 case OBJECT_PARAMETER_TYPE:
11602 if (data->subID == USE_OBJECT_HANDLE) {
11603 if (filter_on || data->int_val == OBJECT_HANDLE_NONE || strlen(data->str_val) == 0)
11604 index = OBJECT_NONE_HANDLE;
11605 else
11606 index = FindObjectInList(data->str_val);
11607 } else
11608 index = data->int_val;
11609 cfprintf(CurrentOutputFile, "%02d:%d:%d:%d:%s", data->type, data->ID, data->subID, index, data->name);
11610 break;
11611 case ROOM_PARAMETER_TYPE:
11612 if (filter_on || data->int_val == NOT_SPECIFIED_TYPE || strlen(data->str_val) == 0)
11613 index = NOT_SPECIFIED_TYPE;
11614 else
11615 index = FindRoomInList(data->str_val);
11616 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, index, data->name);
11617 break;
11618 case TRIGGER_PARAMETER_TYPE:
11619 if (filter_on || data->int_val == NOT_SPECIFIED_TYPE || strlen(data->str_val) == 0)
11620 index = NOT_SPECIFIED_TYPE;
11621 else
11622 index = FindTriggerInList(data->str_val);
11623 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, index, data->name);
11624 break;
11625 case INT_PARAMETER_TYPE:
11626 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, data->int_val, data->name);
11627 break;
11628 case BOOL_PARAMETER_TYPE:
11629 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, data->int_val, data->name);
11630 break;
11631 case FLOAT_PARAMETER_TYPE:
11632 cfprintf(CurrentOutputFile, "%02d:%d:%f:%s", data->type, data->ID, data->float_val1, data->name);
11633 break;
11634 case VECTOR_PARAMETER_TYPE:
11635 cfprintf(CurrentOutputFile, "%02d:%d:%f:%f:%f:%s", data->type, data->ID, data->float_val1, data->float_val2,
11636 data->float_val3, data->name);
11637 break;
11638 case STRING_PARAMETER_TYPE:
11639 if (filter_on || strlen(data->str_val) == 0)
11640 tmp_name = NOT_SPECIFIED_MSG;
11641 else
11642 tmp_name = data->str_val;
11643 cfprintf(CurrentOutputFile, "%02d:%d:%s:%s", data->type, data->ID, tmp_name.GetBuffer(0), data->name);
11644 break;
11645 case PERCENTAGE_PARAMETER_TYPE:
11646 cfprintf(CurrentOutputFile, "%02d:%d:%f:%s", data->type, data->ID, data->float_val1, data->name);
11647 break;
11648 case ENUM_PARAMETER_TYPE:
11649 if (DALLAS_SAVE_VERSION >= 2) {
11650 cfprintf(CurrentOutputFile, "%02d:%d:%d:%d:%s", data->type, data->ID, data->subID, data->int_val, data->name);
11651 } else {
11652 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, data->int_val, data->name);
11653 }
11654 break;
11655 case SCRIPT_PARAMETER_TYPE:
11656 if (filter_on)
11657 index = NOT_SPECIFIED_TYPE;
11658 else
11659 index = data->int_val;
11660 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, index, data->name);
11661 break;
11662 case SOUND_PARAMETER_TYPE:
11663 if (filter_on || data->int_val == NOT_SPECIFIED_TYPE || strlen(data->str_val) == 0)
11664 index = NOT_SPECIFIED_TYPE;
11665 else
11666 index = FindSoundInList(data->str_val);
11667 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, index, data->name);
11668 break;
11669 case SPECNAME_PARAMETER_TYPE:
11670 if (filter_on || strlen(data->str_val) == 0)
11671 index = NOT_SPECIFIED_TYPE;
11672 else
11673 index = FindSpecnameInList(data->str_val);
11674 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, index, data->name);
11675 break;
11676 case TEXTURE_PARAMETER_TYPE:
11677 if (filter_on || data->int_val == NOT_SPECIFIED_TYPE || strlen(data->str_val) == 0)
11678 index = NOT_SPECIFIED_TYPE;
11679 else
11680 index = FindTextureInList(data->str_val);
11681 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, index, data->name);
11682 break;
11683 case FLAG_PARAMETER_TYPE:
11684 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, data->int_val, data->name);
11685 break;
11686 case PATH_PARAMETER_TYPE:
11687 if (filter_on || data->int_val == NOT_SPECIFIED_TYPE || strlen(data->str_val) == 0)
11688 index = NOT_SPECIFIED_TYPE;
11689 else
11690 index = FindPathInList(data->str_val);
11691 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, index, data->name);
11692 break;
11693 case MATCEN_PARAMETER_TYPE:
11694 if (data->subID == USE_MATCEN_VALUE) {
11695 if (filter_on || data->int_val == NOT_SPECIFIED_TYPE || strlen(data->str_val) == 0)
11696 index = NOT_SPECIFIED_TYPE;
11697 else
11698 index = FindMatcenInList(data->str_val);
11699 } else
11700 index = data->int_val;
11701 cfprintf(CurrentOutputFile, "%02d:%d:%d:%d:%s", data->type, data->ID, data->subID, index, data->name);
11702 break;
11703 case LEVEL_GOAL_PARAMETER_TYPE:
11704 if (data->subID == USE_LEVEL_GOAL_VALUE) {
11705 if (filter_on || data->int_val == NOT_SPECIFIED_TYPE || strlen(data->str_val) == 0)
11706 index = NOT_SPECIFIED_TYPE;
11707 else {
11708 index = FindGoalInList(data->str_val);
11709 }
11710 } else
11711 index = data->int_val;
11712 cfprintf(CurrentOutputFile, "%02d:%d:%d:%d:%s", data->type, data->ID, data->subID, index, data->name);
11713 break;
11714 case STRM_AUDIO_PARAMETER_TYPE:
11715 if (filter_on || strlen(data->str_val) == 0)
11716 index = NOT_SPECIFIED_TYPE;
11717 else
11718 index = FindStrmAudioInList(data->str_val);
11719 cfprintf(CurrentOutputFile, "%02d:%d:%d:%s", data->type, data->ID, index, data->name);
11720 break;
11721 default:
11722 cfprintf(CurrentOutputFile, "%02d:%d:%s", data->type, data->ID, data->name);
11723 break;
11724 }
11725 break;
11726 case PARAMETER_OPERATOR_NODE:
11727 cfprintf(CurrentOutputFile, "%02d:%d", data->type, data->ID);
11728 break;
11729 case UNKNOWN_NODE:
11730 cfprintf(CurrentOutputFile, "%02d:%d", data->type, data->ID);
11731 break;
11732 default:
11733 cfprintf(CurrentOutputFile, "%02d:%d", UNKNOWN_NODE, data->ID);
11734 break;
11735 }
11736 O((" "));
11737 }
11738
11739 /////////////////////////////////////////////////////////////////////////////
11740 // Object Handle List Functions
11741 /////////////////////////////////////////////////////////////////////////////
11742
11743 // Sets up the object handle list
11744 void CDallasMainDlg::InitObjectHandleList(void) { m_NumObjectHandles = 0; }
11745
11746 // Clears the object handle list
11747 void CDallasMainDlg::ClearObjectHandleList(void) { m_NumObjectHandles = 0; }
11748
11749 // Adds a handle to the list
11750 int CDallasMainDlg::AddToObjectHandleList(int handle) {
11751 // Is list full?
11752 if (m_NumObjectHandles == MAX_NAMED_OBJECTS)
11753 return 0;
11754
11755 m_ObjectHandleList[m_NumObjectHandles] = handle;
11756 m_NumObjectHandles++;
11757
11758 return (m_NumObjectHandles - 1);
11759 }
11760
11761 /////////////////////////////////////////////////////////////////////////////
11762 // Floating Menu Creation Functions
11763 /////////////////////////////////////////////////////////////////////////////
11764
11765 // Fills up the given menu with the object categories
11766 // NOTE: Command ID's of objects items start at the given command_offset
11767 void CDallasMainDlg::FillObjectMenu(CMenu *object_menu, int command_offset, bool show_other) {
11768 CMenu powerup_submenu, robot_submenu, clutter_submenu, building_submenu, door_submenu, other_submenu;
11769 int powerups_added, robots_added, clutter_added, buildings_added, doors_added, others_added;
11770 int i;
11771 object *objp;
11772
11773 // Create the category submenus
11774 powerup_submenu.CreatePopupMenu();
11775 robot_submenu.CreatePopupMenu();
11776 clutter_submenu.CreatePopupMenu();
11777 building_submenu.CreatePopupMenu();
11778 door_submenu.CreatePopupMenu();
11779 other_submenu.CreatePopupMenu();
11780
11781 // Before filling with objects, reset the object handle list
11782 m_NumObjectHandles = 0;
11783
11784 // Set the object counts
11785 powerups_added = 0;
11786 robots_added = 0;
11787 clutter_added = 0;
11788 buildings_added = 0;
11789 doors_added = 0;
11790 others_added = 0;
11791
11792 // Fill the menus with objects that have custom names
11793 for (i = 0, objp = Objects; i <= Highest_object_index; i++, objp++) {
11794 if ((m_NumObjectHandles < MAX_NAMED_OBJECTS) && (objp->name) &&
11795 (objp->type != OBJ_NONE) /*&& (objp->type != OBJ_PLAYER)*/) {
11796
11797 // Add the object handle to the handle list
11798 m_ObjectHandleList[m_NumObjectHandles] = objp->handle;
11799
11800 // Add menu item to appropriate submenu
11801 switch (objp->type) {
11802 case OBJ_POWERUP:
11803 powerup_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + m_NumObjectHandles,
11804 objp->name);
11805 powerups_added++;
11806 break;
11807 case OBJ_ROBOT:
11808 robot_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + m_NumObjectHandles,
11809 objp->name);
11810 robots_added++;
11811 break;
11812 case OBJ_CLUTTER:
11813 clutter_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + m_NumObjectHandles,
11814 objp->name);
11815 clutter_added++;
11816 break;
11817 case OBJ_BUILDING:
11818 building_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + m_NumObjectHandles,
11819 objp->name);
11820 buildings_added++;
11821 break;
11822 case OBJ_DOOR:
11823 door_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + m_NumObjectHandles, objp->name);
11824 doors_added++;
11825 break;
11826 default:
11827 other_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + m_NumObjectHandles,
11828 objp->name);
11829 others_added++;
11830 break;
11831 }
11832 m_NumObjectHandles++;
11833 }
11834 }
11835
11836 // Add the powerup submenu
11837 ColumnizePopupMenu(&powerup_submenu);
11838 if (powerups_added == 0)
11839 object_menu->AppendMenu(MF_POPUP | MF_GRAYED, (UINT_PTR)powerup_submenu.Detach(), "Powerup");
11840 else
11841 object_menu->AppendMenu(MF_POPUP, (UINT_PTR)powerup_submenu.Detach(), "Powerup");
11842
11843 // Add the robot submenu
11844 ColumnizePopupMenu(&robot_submenu);
11845 if (robots_added == 0)
11846 object_menu->AppendMenu(MF_POPUP | MF_GRAYED, (UINT_PTR)robot_submenu.Detach(), "Robot");
11847 else
11848 object_menu->AppendMenu(MF_POPUP, (UINT_PTR)robot_submenu.Detach(), "Robot");
11849
11850 // Add the clutter submenu
11851 ColumnizePopupMenu(&clutter_submenu);
11852 if (clutter_added == 0)
11853 object_menu->AppendMenu(MF_POPUP | MF_GRAYED, (UINT_PTR)clutter_submenu.Detach(), "Clutter");
11854 else
11855 object_menu->AppendMenu(MF_POPUP, (UINT_PTR)clutter_submenu.Detach(), "Clutter");
11856
11857 // Add the building submenu
11858 ColumnizePopupMenu(&building_submenu);
11859 if (buildings_added == 0)
11860 object_menu->AppendMenu(MF_POPUP | MF_GRAYED, (UINT_PTR)building_submenu.Detach(), "Building");
11861 else
11862 object_menu->AppendMenu(MF_POPUP, (UINT_PTR)building_submenu.Detach(), "Building");
11863
11864 // Add the door submenu
11865 ColumnizePopupMenu(&door_submenu);
11866 if (doors_added == 0)
11867 object_menu->AppendMenu(MF_POPUP | MF_GRAYED, (UINT_PTR)door_submenu.Detach(), "Door");
11868 else
11869 object_menu->AppendMenu(MF_POPUP, (UINT_PTR)door_submenu.Detach(), "Door");
11870
11871 // Add the other submenu
11872 ColumnizePopupMenu(&other_submenu);
11873 if (!show_other || others_added == 0)
11874 object_menu->AppendMenu(MF_POPUP | MF_GRAYED, (UINT_PTR)other_submenu.Detach(), "Other");
11875 else
11876 object_menu->AppendMenu(MF_POPUP, (UINT_PTR)other_submenu.Detach(), "Other");
11877 }
11878
11879 // Fills up the given menu with the named objects of the specified type
11880 // NOTE: Command ID's of objects items start at the given command_offset
11881 int CDallasMainDlg::FillObjectTypeMenu(CMenu *object_menu, int command_offset, int obj_type) {
11882 int objects_added;
11883 int i;
11884 object *objp;
11885
11886 // Before filling with objects, reset the object handle list
11887 m_NumObjectHandles = 0;
11888
11889 // Set the object counts
11890 objects_added = 0;
11891
11892 // Fill the menus with objects that have custom names
11893 for (i = 0, objp = Objects; i <= Highest_object_index; i++, objp++) {
11894 if ((m_NumObjectHandles < MAX_NAMED_OBJECTS) && (objp->name) && (objp->type == obj_type)) {
11895
11896 // Add the object handle to the handle list
11897 m_ObjectHandleList[m_NumObjectHandles] = objp->handle;
11898
11899 // Add the menu item
11900 object_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + m_NumObjectHandles, objp->name);
11901 objects_added++;
11902 m_NumObjectHandles++;
11903 }
11904 }
11905
11906 return (objects_added);
11907 }
11908
11909 // Fills up the given menu with the named rooms
11910 // NOTE: Command ID's of objects items start at the given command_offset
11911 int CDallasMainDlg::FillRoomMenu(CMenu *room_menu, int command_offset) {
11912 int rooms_added;
11913 int i;
11914 room *rp;
11915
11916 // Set the room count
11917 rooms_added = 0;
11918
11919 // Fill the menus with objects that have custom names
11920 for (i = 0, rp = Rooms; i <= Highest_room_index; i++, rp++) {
11921 if ((rp->used) && (rp->name)) {
11922 room_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + i, rp->name);
11923 rooms_added++;
11924 }
11925 }
11926
11927 return (rooms_added);
11928 }
11929
11930 // Fills up the given menu with the trigger list
11931 // NOTE: Command ID's of objects items start at the given command_offset
11932 int CDallasMainDlg::FillTriggerMenu(CMenu *trigger_menu, int command_offset) {
11933 int t, triggers_added;
11934 trigger *tp;
11935
11936 // Scan the list, adding triggers to the list
11937 triggers_added = 0;
11938
11939 for (t = 0, tp = Triggers; (t < Num_triggers && t < MAX_NAMED_TRIGGERS); t++, tp++) {
11940 if (strlen(tp->name) > 0) {
11941 trigger_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + t, tp->name);
11942 triggers_added++;
11943 }
11944 }
11945
11946 return (triggers_added);
11947 }
11948
11949 // Fills up the given menu with the path list
11950 // NOTE: Command ID's of objects items start at the given command_offset
11951 int CDallasMainDlg::FillPathMenu(CMenu *path_menu, int command_offset) {
11952 int p, paths_added;
11953
11954 // Scan the list, adding triggers to the list
11955 paths_added = 0;
11956
11957 for (p = 0; p < MAX_GAME_PATHS; p++) {
11958 if (GamePaths[p].used && strlen(GamePaths[p].name) > 0) {
11959 path_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + p, GamePaths[p].name);
11960 paths_added++;
11961 }
11962 }
11963
11964 return (paths_added);
11965 }
11966
11967 // Fills up the given menu with the matcen list
11968 // NOTE: Command ID's of objects items start at the given command_offset
11969 int CDallasMainDlg::FillMatcenMenu(CMenu *matcen_menu, int command_offset) {
11970 int p, matcens_added;
11971
11972 // Scan the list, adding triggers to the list
11973 matcens_added = 0;
11974
11975 for (p = 0; p < MAX_MATCENS; p++) {
11976 if (MatcenValid(p)) {
11977 char matcen_name[MAX_MATCEN_NAME_LEN + 1];
11978 Matcen[p]->GetName(matcen_name);
11979 matcen_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + p, matcen_name);
11980 matcens_added++;
11981 }
11982 }
11983
11984 return (matcens_added);
11985 }
11986
11987 // Fills up the given menu with the level goal list
11988 // NOTE: Command ID's of objects items start at the given command_offset
11989 int CDallasMainDlg::FillLevelGoalMenu(CMenu *level_goal_menu, int command_offset) {
11990 int p, goals_added, num_goals;
11991
11992 // Scan the list, adding triggers to the list
11993 goals_added = 0;
11994
11995 num_goals = Level_goals.GetNumGoals();
11996 for (p = 0; p < num_goals; p++) {
11997 char goal_name[_MAX_PATH + 1];
11998 if (Level_goals.GoalGetName(p, goal_name, _MAX_PATH) >= 0) {
11999 level_goal_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + p, goal_name);
12000 goals_added++;
12001 }
12002 }
12003
12004 return (goals_added);
12005 }
12006
12007 // Fills up the given menu with the Script ID List
12008 // NOTE: Command ID's of objects items start at the given command_offset
12009 #define MAX_SCRIPT_MENU_NAME_LEN 32
12010 int CDallasMainDlg::FillScriptMenu(CMenu *script_menu, int command_offset) {
12011 HTREEITEM script_node;
12012 tTreeNodeData *data;
12013 int scripts_added, child_pos;
12014
12015 // Scan the list, adding each script to the list
12016 scripts_added = 0;
12017 child_pos = 0;
12018
12019 script_node = m_ScriptTree.GetChildItem(TVI_ROOT);
12020 while (script_node != NULL) {
12021 data = (tTreeNodeData *)m_ScriptTree.GetItemData(script_node);
12022 if (data->type == SCRIPT_HEADER_NODE) {
12023 CString menu_string;
12024 FormatTreeText(menu_string, data);
12025
12026 // Truncate the name (if necessary) so that more will fit
12027 char menu_name[MAX_SCRIPT_MENU_NAME_LEN + 3 + 1];
12028 strncpy(menu_name, menu_string.GetBuffer(0), MAX_SCRIPT_MENU_NAME_LEN);
12029 menu_name[MAX_SCRIPT_MENU_NAME_LEN] = '\0';
12030 if (menu_string.GetLength() > MAX_SCRIPT_MENU_NAME_LEN) {
12031 strcat(menu_name, "...");
12032 }
12033
12034 script_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + child_pos, menu_name);
12035 scripts_added++;
12036 }
12037 script_node = m_ScriptTree.GetNextSiblingItem(script_node);
12038 child_pos++;
12039 }
12040
12041 return (scripts_added);
12042 }
12043
12044 // Fills up the given menu with the logical operations
12045 // NOTE: Command ID's of objects items start at the given command_offset
12046 int CDallasMainDlg::FillLogOpMenu(CMenu *log_op_menu, int command_offset) {
12047 int log_ops_added;
12048
12049 // Scan the list, adding triggers to the list
12050 log_ops_added = 0;
12051 log_op_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + AND_TYPE, "AND");
12052 log_op_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + OR_TYPE, "OR");
12053
12054 return (log_ops_added);
12055 }
12056
12057 // Fills up the given menu with the appropriate expression operators
12058 // NOTE: Command ID's of objects items start at the given command_offset
12059 int CDallasMainDlg::FillExpOpMenu(CMenu *exp_op_menu, int command_offset, int op_type) {
12060 int exp_ops_added = 0;
12061 int j;
12062
12063 // Scan the list, adding triggers to the list
12064 for (j = 0; expop_info[j].type >= 0; j++) {
12065 if (op_type == expop_info[j].op_type) {
12066 exp_op_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + expop_info[j].type,
12067 expop_info[j].menu_name);
12068 exp_ops_added++;
12069 } else
12070 exp_op_menu->AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, command_offset + expop_info[j].type,
12071 expop_info[j].menu_name);
12072 }
12073
12074 return (exp_ops_added);
12075 }
12076
12077 // Fills up the given menu with the literal's available
12078 // NOTE: Command ID's of objects items start at the given command_offset
12079 int CDallasMainDlg::FillLiteralMenu(CMenu *literal_menu, int command_offset, int enum_command_offset,
12080 int flag_command_offset, int valid_type, char *valid_name) {
12081 CMenu enum_submenu, flag_submenu;
12082 int literals_added, j;
12083
12084 // Create the enum/flag submenus
12085 enum_submenu.CreatePopupMenu();
12086 flag_submenu.CreatePopupMenu();
12087
12088 int types_added = FillEnumTypesMenu(&enum_submenu, enum_command_offset, valid_name);
12089 int flag_types_added = FillFlagTypesMenu(&flag_submenu, flag_command_offset, valid_name);
12090
12091 // Scan the list, adding literals
12092 literals_added = 0;
12093
12094 for (j = 0; param_menu_item[j].type >= 0; j++) {
12095 if (valid_type == ANY_PARAMETER_TYPE || valid_type == param_menu_item[j].type) {
12096 if (j == ENUM_PARAMETER_TYPE) {
12097 ColumnizePopupMenu(&enum_submenu);
12098 if (types_added > 0)
12099 literal_menu->AppendMenu(MF_POPUP, (UINT_PTR)enum_submenu.Detach(), param_menu_item[j].name);
12100 else
12101 literal_menu->AppendMenu(MF_GRAYED | MF_POPUP, (UINT_PTR)enum_submenu.Detach(), param_menu_item[j].name);
12102 } else if (j == FLAG_PARAMETER_TYPE) {
12103 ColumnizePopupMenu(&flag_submenu);
12104 if (flag_types_added > 0)
12105 literal_menu->AppendMenu(MF_POPUP, (UINT_PTR)flag_submenu.Detach(), param_menu_item[j].name);
12106 else
12107 literal_menu->AppendMenu(MF_GRAYED | MF_POPUP, (UINT_PTR)flag_submenu.Detach(), param_menu_item[j].name);
12108 } else
12109 literal_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + param_menu_item[j].type,
12110 param_menu_item[j].name);
12111 literals_added++;
12112 } else
12113 literal_menu->AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, command_offset + param_menu_item[j].type,
12114 param_menu_item[j].name);
12115 }
12116
12117 return (literals_added);
12118 }
12119
12120 // Fills up the given menu with the Condition options
12121 // NOTE: Command ID's of objects items start at the given command_offset
12122 void CDallasMainDlg::FillConditionMenu(CMenu *condition_menu, int command_offset) {
12123 int qbin_cmd_offset, qcomp_cmd_offset;
12124 CMenu qbin_submenu, qcomp_submenu;
12125
12126 if (command_offset == ADD_CONDITION_ID_RANGE_START) {
12127 qbin_cmd_offset = ADD_COND_QBIN_ID_RANGE_START;
12128 qcomp_cmd_offset = ADD_COND_QCOMP_ID_RANGE_START;
12129 } else {
12130 qbin_cmd_offset = REPLACE_COND_QBIN_ID_RANGE_START;
12131 qcomp_cmd_offset = REPLACE_COND_QCOMP_ID_RANGE_START;
12132 }
12133
12134 qbin_submenu.CreatePopupMenu();
12135 FillQueryMenu(&qbin_submenu, qbin_cmd_offset, BOOL_PARAMETER_TYPE, "");
12136
12137 qcomp_submenu.CreatePopupMenu();
12138 FillQueryMenu(&qcomp_submenu, qcomp_cmd_offset, ANY_PARAMETER_TYPE, "");
12139
12140 // Add basic condition types to the list
12141 condition_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + ALWAYS_STATEMENT, ALWAYS_STRING);
12142 condition_menu->AppendMenu(MF_SEPARATOR, 0, "");
12143 condition_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + BINARY_STATEMENT,
12144 "Default Binary Statement");
12145 condition_menu->AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, command_offset + COMPARISON_STATEMENT,
12146 "Default Comparison Statement");
12147 condition_menu->AppendMenu(MF_SEPARATOR, 0, "");
12148
12149 ColumnizePopupMenu(&qbin_submenu);
12150 condition_menu->AppendMenu(MF_POPUP, (UINT_PTR)qbin_submenu.Detach(), "Binary Statement with Query");
12151 ColumnizePopupMenu(&qcomp_submenu);
12152 condition_menu->AppendMenu(MF_POPUP, (UINT_PTR)qcomp_submenu.Detach(), "Comparison Statement with Query");
12153 }
12154
12155 // Creates the Popup menu for the Script Header node
12156 void CDallasMainDlg::DisplayScriptHeaderNodeMenu(POINT *point) {
12157 // Create the popup menu
12158 CMenu main_menu;
12159 main_menu.CreatePopupMenu();
12160 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_SPECIFIC_VALUE_ID, "Enter Script Description...");
12161 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12162 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, CANCEL_COMMAND_ID, "Cancel");
12163 ColumnizePopupMenu(&main_menu);
12164 main_menu.TrackPopupMenu(0, point->x, point->y, this);
12165 main_menu.DestroyMenu();
12166 }
12167
12168 // Creates the Popup menu for the Script Owner node
12169 void CDallasMainDlg::DisplayScriptOwnerNodeMenu(POINT *point) {
12170 // Create the popup menu
12171 int triggers_added;
12172 CMenu main_menu, object_submenu, trigger_submenu;
12173 main_menu.CreatePopupMenu();
12174
12175 // Fill the object menu
12176 object_submenu.CreatePopupMenu();
12177 FillObjectMenu(&object_submenu, ASSIGN_OBJECT_ID_RANGE_START, TRUE);
12178 ColumnizePopupMenu(&object_submenu);
12179 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)object_submenu.Detach(), "Object");
12180
12181 trigger_submenu.CreatePopupMenu();
12182 triggers_added = FillTriggerMenu(&trigger_submenu, ASSIGN_TRIGGER_ID_RANGE_START);
12183 ColumnizePopupMenu(&trigger_submenu);
12184 if (triggers_added == 0)
12185 main_menu.AppendMenu(MF_POPUP | MF_GRAYED, (UINT_PTR)trigger_submenu.Detach(), "Trigger");
12186 else
12187 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)trigger_submenu.Detach(), "Trigger");
12188
12189 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_LEVEL_ID, "Level");
12190 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12191 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, CANCEL_COMMAND_ID, "Cancel");
12192 ColumnizePopupMenu(&main_menu);
12193 main_menu.TrackPopupMenu(0, point->x, point->y, this);
12194 main_menu.DestroyMenu();
12195 }
12196
12197 // Creates the Popup menu for the Script Event node
12198 void CDallasMainDlg::DisplayScriptEventNodeMenu(POINT *point, int owner_type, bool has_a_door_me) {
12199 int j;
12200
12201 // Create the popup menu
12202 CMenu main_menu;
12203 main_menu.CreatePopupMenu();
12204
12205 for (j = 0; event_info[j].type >= 0; j++) {
12206 if ((owner_type == OBJECT_TYPE && (event_info[j].flags & OBJECT_MASK)) ||
12207 (owner_type == TRIGGER_TYPE && (event_info[j].flags & TRIGGER_MASK)) ||
12208 (owner_type == LEVEL_TYPE && (event_info[j].flags & LEVEL_MASK)) ||
12209 (has_a_door_me && (event_info[j].flags & DOOR_OBJECT_MASK)))
12210 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_EVENT_ID_RANGE_START + event_info[j].type,
12211 event_info[j].name);
12212 else
12213 main_menu.AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, ASSIGN_EVENT_ID_RANGE_START + event_info[j].type,
12214 event_info[j].name);
12215 }
12216
12217 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12218 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, CANCEL_COMMAND_ID, "Cancel");
12219
12220 ColumnizePopupMenu(&main_menu);
12221 main_menu.TrackPopupMenu(0, point->x, point->y, this);
12222 main_menu.DestroyMenu();
12223 }
12224
12225 // Creates the Popup menu for the Logical Operator node
12226 void CDallasMainDlg::DisplayLogicalOperatorNodeMenu(POINT *point) {
12227 // Create the popup menu
12228 CMenu main_menu, insert_logop_submenu, condition_submenu, add_logop_submenu;
12229 CMenu replace_logop_submenu, replace_condition_submenu;
12230
12231 insert_logop_submenu.CreatePopupMenu();
12232 FillLogOpMenu(&insert_logop_submenu, INSERT_LOGOP_ID_RANGE_START);
12233
12234 condition_submenu.CreatePopupMenu();
12235 FillConditionMenu(&condition_submenu, ADD_CONDITION_ID_RANGE_START);
12236
12237 add_logop_submenu.CreatePopupMenu();
12238 FillLogOpMenu(&add_logop_submenu, ADD_LOGOP_ID_RANGE_START);
12239
12240 replace_condition_submenu.CreatePopupMenu();
12241 FillConditionMenu(&replace_condition_submenu, REPLACE_CONDITION_ID_RANGE_START);
12242
12243 replace_logop_submenu.CreatePopupMenu();
12244 FillLogOpMenu(&replace_logop_submenu, REPLACE_LOGOP_ID_RANGE_START);
12245
12246 main_menu.CreatePopupMenu();
12247 ColumnizePopupMenu(&insert_logop_submenu);
12248 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)insert_logop_submenu.Detach(), "Insert Logical Operator");
12249 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12250 ColumnizePopupMenu(&condition_submenu);
12251 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)condition_submenu.Detach(), "Add a New Condition");
12252 ColumnizePopupMenu(&add_logop_submenu);
12253 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)add_logop_submenu.Detach(), "Add Logical Operator");
12254 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12255 ColumnizePopupMenu(&replace_condition_submenu);
12256 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)replace_condition_submenu.Detach(), "Replace with a Condition");
12257 ColumnizePopupMenu(&replace_logop_submenu);
12258 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)replace_logop_submenu.Detach(), "Replace with a New Logical Operator");
12259 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12260 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, DELETE_ALL_ID, "Delete this Operator");
12261 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12262 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, CANCEL_COMMAND_ID, "Cancel");
12263
12264 ColumnizePopupMenu(&main_menu);
12265 main_menu.TrackPopupMenu(0, point->x, point->y, this);
12266 main_menu.DestroyMenu();
12267 }
12268
12269 // Creates the Popup menu for the Conditional Statement node
12270 void CDallasMainDlg::DisplayConditionalStatementNodeMenu(POINT *point) {
12271 // Create the popup menu
12272 CMenu main_menu, log_op_submenu;
12273 CMenu replace_logop_submenu, replace_condition_submenu;
12274
12275 log_op_submenu.CreatePopupMenu();
12276 FillLogOpMenu(&log_op_submenu, INSERT_LOGOP_ID_RANGE_START);
12277
12278 replace_condition_submenu.CreatePopupMenu();
12279 FillConditionMenu(&replace_condition_submenu, REPLACE_CONDITION_ID_RANGE_START);
12280
12281 replace_logop_submenu.CreatePopupMenu();
12282 FillLogOpMenu(&replace_logop_submenu, REPLACE_LOGOP_ID_RANGE_START);
12283
12284 main_menu.CreatePopupMenu();
12285 ColumnizePopupMenu(&log_op_submenu);
12286 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)log_op_submenu.Detach(), "Insert Logical Operator");
12287 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12288 ColumnizePopupMenu(&replace_condition_submenu);
12289 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)replace_condition_submenu.Detach(), "Replace with a New Condition");
12290 ColumnizePopupMenu(&replace_logop_submenu);
12291 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)replace_logop_submenu.Detach(), "Replace with a Logical Operator");
12292 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12293 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, DELETE_ALL_ID, "Delete this Condition");
12294 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12295 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, CANCEL_COMMAND_ID, "Cancel");
12296
12297 ColumnizePopupMenu(&main_menu);
12298 main_menu.TrackPopupMenu(0, point->x, point->y, this);
12299 main_menu.DestroyMenu();
12300 }
12301
12302 // Creates the Popup menu for the Expression node
12303 void CDallasMainDlg::DisplayExpressionNodeMenu(POINT *point, int valid_return_type, char *valid_return_name) {
12304 CMenu main_menu, replace_with_query_submenu, replace_with_literal_submenu;
12305
12306 replace_with_query_submenu.CreatePopupMenu();
12307 FillQueryMenu(&replace_with_query_submenu, REPLACE_QUERY_ID_RANGE_START, valid_return_type, valid_return_name);
12308
12309 replace_with_literal_submenu.CreatePopupMenu();
12310 FillLiteralMenu(&replace_with_literal_submenu, REPLACE_LITERAL_ID_RANGE_START, REPLACE_LIT_ENUM_ID_RANGE_START,
12311 REPLACE_LIT_FLAG_ID_RANGE_START, valid_return_type, valid_return_name);
12312
12313 main_menu.CreatePopupMenu();
12314 ColumnizePopupMenu(&replace_with_query_submenu);
12315 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)replace_with_query_submenu.Detach(), "Replace with Query");
12316 ColumnizePopupMenu(&replace_with_literal_submenu);
12317 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)replace_with_literal_submenu.Detach(), "Replace with Literal");
12318
12319 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12320 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, CANCEL_COMMAND_ID, "Cancel");
12321 ColumnizePopupMenu(&main_menu);
12322 main_menu.TrackPopupMenu(0, point->x, point->y, this);
12323 main_menu.DestroyMenu();
12324 }
12325
12326 // Creates the Popup menu for the Expression Operator node
12327 void CDallasMainDlg::DisplayExpressionOperatorNodeMenu(POINT *point, int op_type) {
12328 CMenu main_menu;
12329 main_menu.CreatePopupMenu();
12330
12331 FillExpOpMenu(&main_menu, ASSIGN_EXPOP_ID_RANGE_START, op_type);
12332
12333 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12334 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, CANCEL_COMMAND_ID, "Cancel");
12335 ColumnizePopupMenu(&main_menu);
12336 main_menu.TrackPopupMenu(0, point->x, point->y, this);
12337 main_menu.DestroyMenu();
12338 }
12339
12340 // Creates the Popup menu for the Action Statement node
12341 void CDallasMainDlg::DisplayActionStatementNodeMenu(POINT *point) {
12342 // Create the popup menu
12343 CMenu main_menu;
12344 CMenu insert_actions_submenu, replace_actions_submenu;
12345
12346 insert_actions_submenu.CreatePopupMenu();
12347 insert_actions_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ADD_DO_NOTHING_ACTION_ID, DO_NOTHING_STRING);
12348 insert_actions_submenu.AppendMenu(MF_SEPARATOR, 0, "");
12349 FillActionMenu(&insert_actions_submenu, ADD_ACTION_ID_RANGE_START);
12350
12351 replace_actions_submenu.CreatePopupMenu();
12352 replace_actions_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, REPLACE_DO_NOTHING_ACTION_ID,
12353 DO_NOTHING_STRING);
12354 replace_actions_submenu.AppendMenu(MF_SEPARATOR, 0, "");
12355 FillActionMenu(&replace_actions_submenu, REPLACE_ACTION_ID_RANGE_START);
12356
12357 main_menu.CreatePopupMenu();
12358 ColumnizePopupMenu(&insert_actions_submenu);
12359 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)insert_actions_submenu.Detach(), "Insert a New Action");
12360 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ADD_IF_THEN_CLAUSE_ID, "Insert a Nested IF-THEN Clause");
12361 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ADD_IF_THEN_ELSE_CLAUSE_ID,
12362 "Insert a Nested IF-THEN-ELSE Clause");
12363 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12364 ColumnizePopupMenu(&replace_actions_submenu);
12365 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)replace_actions_submenu.Detach(), "Replace with a Different Action");
12366 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12367 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, DELETE_ALL_ID, "Delete");
12368 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12369 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, CANCEL_COMMAND_ID, "Cancel");
12370
12371 ColumnizePopupMenu(&main_menu);
12372 main_menu.TrackPopupMenu(0, point->x, point->y, this);
12373 main_menu.DestroyMenu();
12374 }
12375
12376 // Creates the Popup menu for the Action Header node
12377 void CDallasMainDlg::DisplayActionHeaderNodeMenu(POINT *point, int level_type, int clause_type, bool can_add_else) {
12378 // Create the popup menu
12379 CMenu main_menu, add_actions_submenu, select_extimes_submenu, select_chain_submenu;
12380
12381 add_actions_submenu.CreatePopupMenu();
12382 add_actions_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ADD_DO_NOTHING_ACTION_ID, DO_NOTHING_STRING);
12383 add_actions_submenu.AppendMenu(MF_SEPARATOR, 0, "");
12384 FillActionMenu(&add_actions_submenu, ADD_ACTION_ID_RANGE_START);
12385
12386 select_extimes_submenu.CreatePopupMenu();
12387 select_extimes_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING,
12388 ASSIGN_EXEC_TIME_ID_RANGE_START + ENTER_EXEC_TIMES, "Enter number of times...");
12389 select_extimes_submenu.AppendMenu(MF_SEPARATOR, 0, "");
12390 select_extimes_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING,
12391 ASSIGN_EXEC_TIME_ID_RANGE_START + EXECUTE_INFINITELY, "Run Infinitely");
12392 select_extimes_submenu.AppendMenu(MF_SEPARATOR, 0, "");
12393 select_extimes_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING,
12394 ASSIGN_EXEC_TIME_ID_RANGE_START + EXECUTE_ONCE, "Once");
12395 select_extimes_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING,
12396 ASSIGN_EXEC_TIME_ID_RANGE_START + EXECUTE_TWICE, "Twice");
12397
12398 select_chain_submenu.CreatePopupMenu();
12399 select_chain_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING,
12400 ASSIGN_CHAIN_ID_RANGE_START + CONTINUE_SCRIPT_CHAIN,
12401 "Continue the Script Chain (DEFAULT)");
12402 select_chain_submenu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING,
12403 ASSIGN_CHAIN_ID_RANGE_START + BREAK_SCRIPT_CHAIN, "Break the Script Chain");
12404
12405 main_menu.CreatePopupMenu();
12406 ColumnizePopupMenu(&select_extimes_submenu);
12407 if (level_type == TOP_LEVEL)
12408 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)select_extimes_submenu.Detach(), "Select Max Times to Execute");
12409 else
12410 main_menu.AppendMenu(MF_GRAYED | MF_POPUP, (UINT_PTR)select_extimes_submenu.Detach(),
12411 "Select Max Times to Execute");
12412 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12413 if (level_type == TOP_LEVEL)
12414 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)select_chain_submenu.Detach(), "Select Script Chaining Option");
12415 else
12416 main_menu.AppendMenu(MF_GRAYED | MF_POPUP, (UINT_PTR)select_chain_submenu.Detach(),
12417 "Select Script Chaining Option");
12418 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12419 ColumnizePopupMenu(&add_actions_submenu);
12420 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)add_actions_submenu.Detach(), "Add a New Action");
12421 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ADD_IF_THEN_CLAUSE_ID, "Add a Nested IF-THEN Clause");
12422 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ADD_IF_THEN_ELSE_CLAUSE_ID,
12423 "Add a Nested IF-THEN-ELSE Clause");
12424 if (can_add_else)
12425 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ADD_ELSE_CLAUSE_ID, "Append an ELSE to this Clause");
12426 else
12427 main_menu.AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, ADD_ELSE_CLAUSE_ID, "Append an ELSE to this Clause");
12428 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12429 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, DELETE_CHILDREN_ONLY_ID,
12430 "Delete all Child Actions and Clauses");
12431 if (level_type == TOP_LEVEL)
12432 main_menu.AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, DELETE_ALL_ID, "Delete this Entire IF-THEN Clause");
12433 else {
12434 if (clause_type == THEN_CLAUSE)
12435 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, DELETE_ALL_ID, "Delete this Entire IF-THEN Clause");
12436 else
12437 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, DELETE_ALL_ID, "Delete this Else Clause");
12438 }
12439 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12440 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, CANCEL_COMMAND_ID, "Cancel");
12441
12442 ColumnizePopupMenu(&main_menu);
12443 main_menu.TrackPopupMenu(0, point->x, point->y, this);
12444 main_menu.DestroyMenu();
12445 }
12446
12447 // Displays the popup menus for the various parameter types
12448 void CDallasMainDlg::DisplayParameterNodeMenu(POINT *point, int param_type, char *param_name, int valid_return_type,
12449 char *valid_return_name, bool has_an_it, bool has_a_me,
12450 bool has_a_door_me, bool has_a_goalID, bool has_a_timerID,
12451 bool has_a_matcenID, bool has_a_levgoalID) {
12452 CMenu main_menu, replace_with_query_submenu, replace_with_literal_submenu;
12453
12454 replace_with_query_submenu.CreatePopupMenu();
12455 FillQueryMenu(&replace_with_query_submenu, REPLACE_QUERY_ID_RANGE_START, valid_return_type, valid_return_name);
12456
12457 replace_with_literal_submenu.CreatePopupMenu();
12458 FillLiteralMenu(&replace_with_literal_submenu, REPLACE_LITERAL_ID_RANGE_START, REPLACE_LIT_ENUM_ID_RANGE_START,
12459 REPLACE_LIT_FLAG_ID_RANGE_START, valid_return_type, valid_return_name);
12460
12461 main_menu.CreatePopupMenu();
12462
12463 switch (param_type) {
12464 case DOOR_PARAMETER_TYPE: {
12465 if (has_a_door_me)
12466 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_OBJECT_ME_ID, "OWNER");
12467 else
12468 main_menu.AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, ASSIGN_OBJECT_ME_ID, "OWNER");
12469
12470 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12471 FillObjectTypeMenu(&main_menu, ASSIGN_OBJECT_ID_RANGE_START, OBJ_DOOR);
12472 } break;
12473 case OBJECT_PARAMETER_TYPE: {
12474 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_OBJECT_NONE_ID, NONE_STRING);
12475 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12476
12477 if (has_a_me)
12478 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_OBJECT_ME_ID, "OWNER");
12479 else
12480 main_menu.AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, ASSIGN_OBJECT_ME_ID, "OWNER");
12481
12482 if (has_an_it)
12483 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_OBJECT_IT_ID, "IT");
12484 else
12485 main_menu.AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, ASSIGN_OBJECT_IT_ID, "IT");
12486
12487 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12488 FillObjectMenu(&main_menu, ASSIGN_OBJECT_ID_RANGE_START, TRUE);
12489 } break;
12490 case ROOM_PARAMETER_TYPE: {
12491 FillRoomMenu(&main_menu, ASSIGN_ROOM_ID_RANGE_START);
12492 } break;
12493 case TRIGGER_PARAMETER_TYPE: {
12494 FillTriggerMenu(&main_menu, ASSIGN_TRIGGER_ID_RANGE_START);
12495 } break;
12496 case INT_PARAMETER_TYPE: {
12497 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_SPECIFIC_VALUE_ID, "Enter Integer Value...");
12498 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12499 } break;
12500 case BOOL_PARAMETER_TYPE: {
12501 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_TRUE_ID, "TRUE");
12502 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_FALSE_ID, "FALSE");
12503 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12504 } break;
12505 case FLOAT_PARAMETER_TYPE: {
12506 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_SPECIFIC_VALUE_ID, "Enter Float Value...");
12507 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12508 } break;
12509 case VECTOR_PARAMETER_TYPE: {
12510 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_SPECIFIC_VALUE_ID, "Enter Vector Values...");
12511 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12512 } break;
12513 case STRING_PARAMETER_TYPE: {
12514 int j, num_msgs;
12515
12516 // Fill list with Message ID Names
12517 num_msgs = m_MessageList.GetCount();
12518 for (j = 0; j < num_msgs; j++) {
12519 CString msg_name;
12520 m_MessageList.GetText(j, msg_name);
12521 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_MESSAGE_ID_RANGE_START + j,
12522 msg_name.GetBuffer(0));
12523 }
12524 } break;
12525 case PERCENTAGE_PARAMETER_TYPE: {
12526 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_SPECIFIC_VALUE_ID, "Enter Percentage Value...");
12527 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12528 } break;
12529 case ENUM_PARAMETER_TYPE: {
12530 if (strcmp(param_name, "GoalID") == 0) {
12531 if (has_a_goalID)
12532 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_ENUM_GOAL_ID, "GOAL ID");
12533 else
12534 main_menu.AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, ASSIGN_ENUM_GOAL_ID, "GOAL ID");
12535 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12536 }
12537
12538 if (strcmp(param_name, "TimerID") == 0) {
12539 if (has_a_timerID)
12540 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_ENUM_TIMER_ID, "TIMER ID");
12541 else
12542 main_menu.AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, ASSIGN_ENUM_TIMER_ID, "TIMER ID");
12543 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12544 }
12545
12546 if (strcmp(param_name, "MatcenID") == 0) {
12547 if (has_a_matcenID)
12548 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_ENUM_MATCEN_ID, "MATCEN ID");
12549 else
12550 main_menu.AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, ASSIGN_ENUM_MATCEN_ID, "MATCEN ID");
12551 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12552 }
12553
12554 FillEnumValuesMenu(&main_menu, ASSIGN_ENUM_VALUE_ID_RANGE_START, param_name);
12555 } break;
12556 case SCRIPT_PARAMETER_TYPE: {
12557 FillScriptMenu(&main_menu, ASSIGN_SCRIPT_ID_RANGE_START);
12558 } break;
12559 case SOUND_PARAMETER_TYPE: {
12560 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_SPECIFIC_VALUE_ID,
12561 "Select a Different Sound...");
12562 } break;
12563 case SPECNAME_PARAMETER_TYPE: {
12564 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_SPECIFIC_VALUE_ID, "Enter a Specific Name...");
12565 } break;
12566 case TEXTURE_PARAMETER_TYPE: {
12567 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_SPECIFIC_VALUE_ID,
12568 "Select a Different Texture...");
12569 } break;
12570 case FLAG_PARAMETER_TYPE: {
12571 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_SPECIFIC_VALUE_ID, "Select the Flags to Set...");
12572 } break;
12573 case PATH_PARAMETER_TYPE: {
12574 FillPathMenu(&main_menu, ASSIGN_PATH_ID_RANGE_START);
12575 } break;
12576 case MATCEN_PARAMETER_TYPE: {
12577 if (has_a_matcenID)
12578 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_MATCEN_EVENT_ID, "MATCEN ID");
12579 else
12580 main_menu.AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, ASSIGN_MATCEN_EVENT_ID, "MATCEN ID");
12581 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12582 FillMatcenMenu(&main_menu, ASSIGN_MATCEN_ID_RANGE_START);
12583 } break;
12584 case LEVEL_GOAL_PARAMETER_TYPE: {
12585 if (has_a_levgoalID)
12586 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_LEVEL_GOAL_ID, "LEVEL GOAL ID");
12587 else
12588 main_menu.AppendMenu(MF_GRAYED | MF_UNCHECKED | MF_STRING, ASSIGN_LEVEL_GOAL_ID, "LEVEL GOAL ID");
12589 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12590 FillLevelGoalMenu(&main_menu, ASSIGN_LEVEL_GOAL_ID_RANGE_START);
12591 } break;
12592 case STRM_AUDIO_PARAMETER_TYPE: {
12593 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, ASSIGN_SPECIFIC_VALUE_ID,
12594 "Select the Streaming Audio File...");
12595 } break;
12596 default:
12597 break;
12598 }
12599
12600 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12601 ColumnizePopupMenu(&replace_with_query_submenu);
12602 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)replace_with_query_submenu.Detach(), "Replace with Query");
12603 ColumnizePopupMenu(&replace_with_literal_submenu);
12604 main_menu.AppendMenu(MF_POPUP, (UINT_PTR)replace_with_literal_submenu.Detach(), "Replace with Literal");
12605
12606 main_menu.AppendMenu(MF_SEPARATOR, 0, "");
12607 main_menu.AppendMenu(MF_ENABLED | MF_UNCHECKED | MF_STRING, CANCEL_COMMAND_ID, "Cancel");
12608 ColumnizePopupMenu(&main_menu);
12609 main_menu.TrackPopupMenu(0, point->x, point->y, this);
12610 main_menu.DestroyMenu();
12611 }
12612
12613 // Takes the given popup menu and breaks it into columns
12614 void CDallasMainDlg::ColumnizePopupMenu(CMenu *menu) {
12615 int screen_height, menu_item_height;
12616 int item_count;
12617 int items_per_column;
12618 int pos;
12619
12620 if (menu == NULL)
12621 return;
12622
12623 item_count = menu->GetMenuItemCount();
12624 if (item_count == 0)
12625 return;
12626
12627 screen_height = GetSystemMetrics(SM_CYSCREEN);
12628 menu_item_height = GetSystemMetrics(SM_CYMENU);
12629 if (menu_item_height > 0)
12630 items_per_column = screen_height / menu_item_height;
12631 else
12632 items_per_column = 25;
12633
12634 // Clip the items per column to a min and max if necessary
12635 if (items_per_column < 25)
12636 items_per_column = 25;
12637 if (items_per_column > 40)
12638 items_per_column = 40;
12639
12640 pos = items_per_column;
12641 while (pos < item_count) {
12642 CString name;
12643 UINT id;
12644 UINT flags;
12645 UINT state;
12646
12647 // Get the name of the item
12648 menu->GetMenuString(pos, name, MF_BYPOSITION);
12649
12650 // Set the default flags
12651 flags = MF_BYPOSITION | MF_MENUBARBREAK;
12652
12653 state = menu->GetMenuState(pos, MF_BYPOSITION);
12654 if (state & MF_GRAYED)
12655 flags |= MF_GRAYED;
12656 if (state & MF_ENABLED)
12657 flags |= MF_ENABLED;
12658 if (state & MF_UNCHECKED)
12659 flags |= MF_UNCHECKED;
12660
12661 // Get the item ID
12662 id = menu->GetMenuItemID(pos);
12663 if (id == 0) { // is it a separator?
12664 flags |= MF_SEPARATOR;
12665 id = 0;
12666 } else if (id == -1) { // is it a popup?
12667 CMenu *submenu;
12668
12669 submenu = menu->GetSubMenu(pos);
12670 if (submenu != NULL) {
12671 id = (uint32_t)submenu->Detach();
12672 flags |= MF_POPUP;
12673 }
12674 }
12675
12676 if (name.IsEmpty())
12677 menu->ModifyMenu(pos, flags, id);
12678 else
12679 menu->ModifyMenu(pos, flags, id, name.GetBuffer(0));
12680
12681 pos += items_per_column;
12682 }
12683 }
12684
12685 /////////////////////////////////////////////////////////////////////////////
12686 // Functions to Assign Values To Data Nodes
12687 /////////////////////////////////////////////////////////////////////////////
12688
12689 // Obtains the appropriate script ID
12690 void CDallasMainDlg::AssignScriptID(int pos) {
12691 HTREEITEM selected_node;
12692 tTreeNodeData *data;
12693
12694 // Obtain the currently selected node
12695 selected_node = m_ScriptTree.GetSelectedItem();
12696 if (selected_node == NULL)
12697 return;
12698
12699 // Get the node's data
12700 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
12701 if (data == NULL)
12702 return;
12703
12704 // Handle entering Script Header node descriptions
12705 if (data->type == PARAMETER_NODE && data->ID == SCRIPT_PARAMETER_TYPE) {
12706 HTREEITEM script_node;
12707 script_node = GetNthChild(TVI_ROOT, pos + 1);
12708 if (script_node == NULL)
12709 return;
12710
12711 data->int_val = GetScriptID(script_node);
12712 UpdateAllParentNodesText(selected_node);
12713 SetModified(TRUE);
12714 }
12715 }
12716
12717 // Obtains the appropriate data through popup dialogs
12718 void CDallasMainDlg::AssignExecTime(int ID) {
12719 HTREEITEM selected_node;
12720 tTreeNodeData *data;
12721
12722 // Obtain the currently selected node
12723 selected_node = m_ScriptTree.GetSelectedItem();
12724 if (selected_node == NULL)
12725 return;
12726
12727 // Get the node's data
12728 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
12729 if (data == NULL)
12730 return;
12731
12732 // Handle entering Script Header node descriptions
12733 if (data->type == ACTIONS_HEADER_NODE && data->ID == TOP_LEVEL) {
12734 switch (ID) {
12735 case ENTER_EXEC_TIMES: {
12736 CDallasGenericPromptDlg dlg;
12737
12738 // Display the prompt dialog
12739 dlg.m_DialogTitle = "Maximum Execution Times Prompt";
12740 dlg.m_PromptText = "Enter the maximum times to execute script:";
12741 dlg.m_PromptData.Format("%d", data->subID);
12742 dlg.m_MaxDataLength = MAX_NDATA_NAME_LEN;
12743
12744 if (dlg.DoModal() == IDCANCEL)
12745 return;
12746
12747 data->subID = atoi(dlg.m_PromptData.GetBuffer(0));
12748 } break;
12749 case EXECUTE_INFINITELY:
12750 data->subID = 0;
12751 break;
12752 case EXECUTE_ONCE:
12753 data->subID = 1;
12754 break;
12755 case EXECUTE_TWICE:
12756 data->subID = 2;
12757 break;
12758 }
12759 UpdateNodeText(selected_node);
12760 SetModified(TRUE);
12761 }
12762 }
12763
12764 // Sets the chain option for the action header
12765 void CDallasMainDlg::AssignChainOption(int ID) {
12766 HTREEITEM selected_node;
12767 tTreeNodeData *data;
12768
12769 // Obtain the currently selected node
12770 selected_node = m_ScriptTree.GetSelectedItem();
12771 if (selected_node == NULL)
12772 return;
12773
12774 // Get the node's data
12775 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
12776 if (data == NULL)
12777 return;
12778
12779 // Handle entering Script Header node descriptions
12780 if (data->type == ACTIONS_HEADER_NODE && data->ID == TOP_LEVEL) {
12781 data->int_val = ID;
12782 UpdateNodeText(selected_node);
12783 SetModified(TRUE);
12784 }
12785 }
12786
12787 // Obtains the appropriate data through popup dialogs
12788 void CDallasMainDlg::AssignSpecificValue(void) {
12789 HTREEITEM selected_node;
12790 tTreeNodeData *data;
12791
12792 // Obtain the currently selected node
12793 selected_node = m_ScriptTree.GetSelectedItem();
12794 if (selected_node == NULL)
12795 return;
12796
12797 // Get the node's data
12798 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
12799 if (data == NULL)
12800 return;
12801
12802 // Handle entering Script Header node descriptions
12803 if (data->type == SCRIPT_HEADER_NODE) {
12804
12805 CDallasGenericPromptDlg dlg;
12806
12807 // Display the prompt dialog
12808 dlg.m_DialogTitle = "Script Description Prompt";
12809 dlg.m_PromptText = "Enter the new script description:";
12810 dlg.m_PromptData = data->name;
12811 dlg.m_MaxDataLength = MAX_NDATA_NAME_LEN;
12812
12813 if (dlg.DoModal() == IDCANCEL)
12814 return;
12815
12816 strncpy(data->name, dlg.m_PromptData.GetBuffer(0), MAX_NDATA_NAME_LEN);
12817 data->name[MAX_NDATA_NAME_LEN] = '\0';
12818 UpdateNodeText(selected_node);
12819 SetModified(TRUE);
12820 return;
12821 }
12822
12823 // Handle entering a Parameter Int value
12824 if (data->type == PARAMETER_NODE && data->ID == INT_PARAMETER_TYPE) {
12825
12826 CDallasGenericPromptDlg dlg;
12827
12828 // Display the prompt dialog
12829 dlg.m_DialogTitle = "Integer Value Prompt";
12830 dlg.m_PromptText.Format("Enter value for %s (integer):", data->name);
12831 dlg.m_PromptData.Format("%d", data->int_val);
12832 dlg.m_MaxDataLength = MAX_NDATA_NAME_LEN;
12833
12834 if (dlg.DoModal() == IDCANCEL)
12835 return;
12836
12837 int value = atoi(dlg.m_PromptData.GetBuffer(0));
12838
12839 // If a range is specified, verify that entered value is in it
12840 CString name_text, default_text, range_text;
12841 int n, param_type;
12842 n = GetChildPosition(selected_node);
12843 param_type = ParseNthParam(m_ScriptTree.GetParentItem(selected_node), n, name_text, default_text, range_text);
12844 if (param_type >= 0 && !range_text.IsEmpty()) {
12845 if (!VerifyIntegerRange(value, range_text.GetBuffer(0))) {
12846 CString msg;
12847 msg.Format("That value is outside the legal range (%s) for this parameter!", range_text);
12848 MessageBox(msg, "Invalid Value Entered", MB_OK | MB_ICONEXCLAMATION);
12849 return;
12850 }
12851 }
12852
12853 data->int_val = value;
12854 UpdateAllParentNodesText(selected_node);
12855 SetModified(TRUE);
12856 return;
12857 }
12858
12859 // Handle entering a Parameter Float value
12860 if (data->type == PARAMETER_NODE && data->ID == FLOAT_PARAMETER_TYPE) {
12861
12862 CDallasGenericPromptDlg dlg;
12863
12864 // Display the prompt dialog
12865 dlg.m_DialogTitle = "Float Value Prompt";
12866 dlg.m_PromptText.Format("Enter value for %s (float):", data->name);
12867 dlg.m_PromptData.Format("%f", data->float_val1);
12868 dlg.m_MaxDataLength = MAX_NDATA_NAME_LEN;
12869
12870 if (dlg.DoModal() == IDCANCEL)
12871 return;
12872
12873 float value = atof(dlg.m_PromptData.GetBuffer(0));
12874
12875 // If a range is specified, verify that entered value is in it
12876 CString name_text, default_text, range_text;
12877 int n, param_type;
12878 n = GetChildPosition(selected_node);
12879 param_type = ParseNthParam(m_ScriptTree.GetParentItem(selected_node), n, name_text, default_text, range_text);
12880 if (param_type >= 0 && !range_text.IsEmpty()) {
12881 if (!VerifyFloatRange(value, range_text.GetBuffer(0))) {
12882 CString msg;
12883 msg.Format("That value is outside the legal range (%s) for this parameter!", range_text);
12884 MessageBox(msg, "Invalid Value Entered", MB_OK | MB_ICONEXCLAMATION);
12885 return;
12886 }
12887 }
12888
12889 data->float_val1 = value;
12890 UpdateAllParentNodesText(selected_node);
12891 SetModified(TRUE);
12892 return;
12893 }
12894
12895 // Handle entering a Parameter Vector value
12896 if (data->type == PARAMETER_NODE && data->ID == VECTOR_PARAMETER_TYPE) {
12897
12898 CDallasVectorPromptDialog dlg;
12899
12900 // Display the prompt dialog
12901 dlg.m_PromptData1 = data->float_val1;
12902 dlg.m_PromptData2 = data->float_val2;
12903 dlg.m_PromptData3 = data->float_val3;
12904
12905 if (dlg.DoModal() == IDCANCEL)
12906 return;
12907
12908 data->float_val1 = dlg.m_PromptData1;
12909 data->float_val2 = dlg.m_PromptData2;
12910 data->float_val3 = dlg.m_PromptData3;
12911 UpdateAllParentNodesText(selected_node);
12912 SetModified(TRUE);
12913 return;
12914 }
12915
12916 // Handle entering a Sound value
12917 if (data->type == PARAMETER_NODE && data->ID == SOUND_PARAMETER_TYPE) {
12918
12919 CDallasSoundDlg dlg;
12920
12921 // Display the prompt dialog
12922 if (data->int_val >= 0 && data->int_val < MAX_SOUNDS && Sounds[data->int_val].used)
12923 dlg.m_SoundName = Sounds[data->int_val].name;
12924
12925 if (dlg.DoModal() == IDCANCEL)
12926 return;
12927
12928 if (dlg.m_SoundIndex >= 0 && dlg.m_SoundIndex < MAX_SOUNDS && Sounds[dlg.m_SoundIndex].used) {
12929 data->int_val = dlg.m_SoundIndex;
12930 strncpy(data->str_val, Sounds[data->int_val].name, MAX_MESSAGE_NAME_LEN);
12931 data->str_val[MAX_MESSAGE_NAME_LEN] = '\0';
12932 }
12933
12934 UpdateAllParentNodesText(selected_node);
12935 SetModified(TRUE);
12936 return;
12937 }
12938
12939 // Handle entering a Streaming Audio value
12940 if (data->type == PARAMETER_NODE && data->ID == STRM_AUDIO_PARAMETER_TYPE) {
12941
12942 CDallasStrmAudioDlg dlg;
12943
12944 // Display the prompt dialog
12945 if (strlen(data->str_val) > 0)
12946 dlg.m_Filename = data->str_val;
12947
12948 if (dlg.DoModal() == IDCANCEL)
12949 return;
12950
12951 if (!dlg.m_Filename.IsEmpty()) {
12952 strncpy(data->str_val, dlg.m_Filename.GetBuffer(0), MAX_MESSAGE_NAME_LEN);
12953 data->str_val[MAX_MESSAGE_NAME_LEN] = '\0';
12954 }
12955
12956 UpdateAllParentNodesText(selected_node);
12957 SetModified(TRUE);
12958 return;
12959 }
12960
12961 // Handle entering a Texture value
12962 if (data->type == PARAMETER_NODE && data->ID == TEXTURE_PARAMETER_TYPE) {
12963
12964 CDallasTextureDlg dlg;
12965
12966 // Display the prompt dialog
12967 if (data->int_val >= 0 && data->int_val < MAX_TEXTURES && GameTextures[data->int_val].used)
12968 dlg.m_TextureName = GameTextures[data->int_val].name;
12969
12970 if (dlg.DoModal() == IDCANCEL)
12971 return;
12972
12973 if (dlg.m_TextureIndex >= 0 && dlg.m_TextureIndex < MAX_TEXTURES && GameTextures[dlg.m_TextureIndex].used) {
12974 data->int_val = dlg.m_TextureIndex;
12975 strncpy(data->str_val, GameTextures[data->int_val].name, MAX_MESSAGE_NAME_LEN);
12976 data->str_val[MAX_MESSAGE_NAME_LEN] = '\0';
12977 }
12978
12979 UpdateAllParentNodesText(selected_node);
12980 SetModified(TRUE);
12981 return;
12982 }
12983
12984 // Handle entering a Flag value
12985 if (data->type == PARAMETER_NODE && data->ID == FLAG_PARAMETER_TYPE) {
12986
12987 CDallasFlagDlg dlg;
12988
12989 // Display the prompt dialog
12990 dlg.m_FlagsValue = data->int_val;
12991 dlg.m_FlagsName = data->name;
12992
12993 // Get the range (contains valid flags mask)
12994 CString name_text, default_text, range_text;
12995 int n, param_type;
12996 n = GetChildPosition(selected_node);
12997 param_type = ParseNthParam(m_ScriptTree.GetParentItem(selected_node), n, name_text, default_text, range_text);
12998 if (param_type >= 0 && !range_text.IsEmpty()) {
12999 dlg.m_ValidFlagsMask = atoi(range_text.GetBuffer(0));
13000 }
13001
13002 if (dlg.DoModal() == IDCANCEL)
13003 return;
13004
13005 data->int_val = dlg.m_FlagsValue;
13006
13007 UpdateAllParentNodesText(selected_node);
13008 SetModified(TRUE);
13009 return;
13010 }
13011
13012 // Handle entering a Specific Name
13013 if (data->type == PARAMETER_NODE && data->ID == SPECNAME_PARAMETER_TYPE) {
13014
13015 CDallasGenericPromptDlg dlg;
13016
13017 // Display the prompt dialog
13018 dlg.m_DialogTitle = "Specific Name Prompt";
13019 dlg.m_PromptText.Format("Enter the specific name for %s:", data->name);
13020 dlg.m_PromptData = data->str_val;
13021 dlg.m_MaxDataLength = MAX_MESSAGE_NAME_LEN;
13022
13023 if (dlg.DoModal() == IDCANCEL)
13024 return;
13025
13026 // Check if the message name is valid
13027 char *newname = dlg.m_PromptData.GetBuffer(0);
13028 if (strlen(newname) == 0)
13029 return;
13030 for (uint32_t j = 0; j < strlen(newname); j++)
13031 if (newname[j] == '"' || newname[j] == ':') {
13032 MessageBox("That specific name is invalid!\n\nNo quotes or colons are allowed.", "Invalid Message ID Error",
13033 MB_OK | MB_ICONEXCLAMATION);
13034 return;
13035 }
13036
13037 // Copy in the new name
13038 strncpy(data->str_val, newname, MAX_MESSAGE_NAME_LEN);
13039 data->str_val[MAX_MESSAGE_NAME_LEN] = '\0';
13040 UpdateAllParentNodesText(selected_node);
13041 SetModified(TRUE);
13042 return;
13043 }
13044
13045 // Handle entering a Parameter Vector value
13046 if (data->type == PARAMETER_NODE && data->ID == PERCENTAGE_PARAMETER_TYPE) {
13047
13048 CDallasGenericPromptDlg dlg;
13049
13050 // Display the prompt dialog
13051 dlg.m_DialogTitle = "Percent Value Prompt";
13052 dlg.m_PromptText.Format("Enter data for %s (as a percentage):", data->name);
13053 dlg.m_PromptData.Format("%f", data->float_val1 * 100.0);
13054 dlg.m_MaxDataLength = MAX_NDATA_NAME_LEN;
13055
13056 if (dlg.DoModal() == IDCANCEL)
13057 return;
13058
13059 float value = atof(dlg.m_PromptData.GetBuffer(0)) / 100.0;
13060
13061 // If a range is specified, verify that entered value is in it
13062 CString name_text, default_text, range_text;
13063 int n, param_type;
13064 n = GetChildPosition(selected_node);
13065 param_type = ParseNthParam(m_ScriptTree.GetParentItem(selected_node), n, name_text, default_text, range_text);
13066 if (param_type >= 0 && !range_text.IsEmpty()) {
13067 if (!VerifyFloatRange(value, range_text.GetBuffer(0))) {
13068 CString msg;
13069 msg.Format("That value is outside the legal range (%s) for this parameter!", range_text);
13070 MessageBox(msg, "Invalid Value Entered", MB_OK | MB_ICONEXCLAMATION);
13071 return;
13072 }
13073 }
13074
13075 data->float_val1 = value;
13076 UpdateAllParentNodesText(selected_node);
13077 SetModified(TRUE);
13078 return;
13079 }
13080
13081 // If we're here, then no popup dialog could be displayed,
13082 // so, instead, display the popup menu for the selected node
13083 RECT rect;
13084 if (m_ScriptTree.GetItemRect(selected_node, &rect, TRUE)) {
13085 POINT pt;
13086
13087 pt.x = rect.left;
13088 pt.y = (rect.top + rect.bottom) / 2;
13089 m_ScriptTree.ClientToScreen(&pt);
13090
13091 DisplayFloatingPopupMenu(selected_node, pt);
13092 }
13093 }
13094
13095 // Assigns an owner to a Script Owner Node
13096 void CDallasMainDlg::AssignNamedValue(int type, int handle) {
13097 HTREEITEM selected_node;
13098 tTreeNodeData *data;
13099
13100 // Obtain the currently selected node
13101 selected_node = m_ScriptTree.GetSelectedItem();
13102 if (selected_node == NULL)
13103 return;
13104
13105 // Get the node's data
13106 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
13107 if (data == NULL)
13108 return;
13109
13110 // If it's a script event node, then process accordingly
13111 if (data->type == SCRIPT_OWNER_NODE) {
13112 int old_type = data->ID;
13113 data->ID = type;
13114 switch (type) {
13115 case LEVEL_TYPE:
13116 data->int_val = handle;
13117 if (old_type != LEVEL_TYPE)
13118 SetScriptEventType(selected_node, LEVEL_START_EVENT_TYPE);
13119 break;
13120 case OBJECT_TYPE:
13121 if (handle == OBJECT_NONE_HANDLE) {
13122 data->int_val = OBJECT_HANDLE_NONE;
13123 data->subID = USE_OBJECT_HANDLE;
13124 strcpy(data->str_val, "");
13125 } else {
13126 data->int_val = m_ObjectHandleList[handle];
13127 data->subID = USE_OBJECT_HANDLE;
13128 object *objp = ObjGet(data->int_val);
13129 if (objp != NULL && objp->name != NULL) {
13130 strncpy(data->str_val, objp->name, MAX_MESSAGE_NAME_LEN);
13131 data->str_val[MAX_MESSAGE_NAME_LEN] = '\0';
13132 } else
13133 strcpy(data->str_val, "");
13134 if (old_type != OBJECT_TYPE)
13135 SetScriptEventType(selected_node, COLLIDE_EVENT_TYPE);
13136 }
13137 break;
13138 case TRIGGER_TYPE:
13139 data->int_val = handle;
13140 if (data->int_val < 0 || data->int_val >= Num_triggers)
13141 strcpy(data->str_val, "");
13142 else {
13143 strncpy(data->str_val, Triggers[data->int_val].name, MAX_MESSAGE_NAME_LEN);
13144 data->str_val[MAX_MESSAGE_NAME_LEN] = '\0';
13145 }
13146 if (old_type != TRIGGER_TYPE)
13147 SetScriptEventType(selected_node, ACTIVATED_EVENT_TYPE);
13148 break;
13149 }
13150 UpdateNodeText(selected_node);
13151 SetModified(TRUE);
13152 HighlightScript(selected_node);
13153 }
13154
13155 // If it's a parameter node, then process accordingly
13156 if (data->type == PARAMETER_NODE) {
13157 switch (type) {
13158 case OBJECT_TYPE:
13159 if (data->ID == OBJECT_PARAMETER_TYPE) {
13160 if (handle == OBJECT_NONE_HANDLE) {
13161 data->int_val = OBJECT_HANDLE_NONE;
13162 data->subID = USE_OBJECT_HANDLE;
13163 strcpy(data->str_val, "");
13164 } else if (handle == OBJECT_ME_HANDLE) {
13165 data->int_val = OBJECT_HANDLE_NONE;
13166 data->subID = USE_ME_HANDLE;
13167 strcpy(data->str_val, "");
13168 } else if (handle == OBJECT_IT_HANDLE) {
13169 data->int_val = OBJECT_HANDLE_NONE;
13170 data->subID = USE_IT_HANDLE;
13171 strcpy(data->str_val, "");
13172 } else {
13173 data->int_val = m_ObjectHandleList[handle];
13174 data->subID = USE_OBJECT_HANDLE;
13175 object *objp = ObjGet(data->int_val);
13176 if (objp != NULL && objp->name != NULL) {
13177 strncpy(data->str_val, objp->name, MAX_MESSAGE_NAME_LEN);
13178 data->str_val[MAX_MESSAGE_NAME_LEN] = '\0';
13179 } else
13180 strcpy(data->str_val, "");
13181 }
13182 } else if (data->ID == DOOR_PARAMETER_TYPE) {
13183 if (handle == OBJECT_NONE_HANDLE) {
13184 data->int_val = OBJECT_HANDLE_NONE;
13185 data->subID = USE_OBJECT_HANDLE;
13186 strcpy(data->str_val, "");
13187 } else if (handle == OBJECT_ME_HANDLE) {
13188 data->int_val = OBJECT_HANDLE_NONE;
13189 data->subID = USE_ME_HANDLE;
13190 strcpy(data->str_val, "");
13191 } else {
13192 data->int_val = m_ObjectHandleList[handle];
13193 data->subID = USE_OBJECT_HANDLE;
13194 object *objp = ObjGet(data->int_val);
13195 if (objp != NULL && objp->name != NULL) {
13196 strncpy(data->str_val, objp->name, MAX_MESSAGE_NAME_LEN);
13197 data->str_val[MAX_MESSAGE_NAME_LEN] = '\0';
13198 } else
13199 strcpy(data->str_val, "");
13200 }
13201 }
13202 break;
13203 case TRIGGER_TYPE:
13204 if (data->ID == TRIGGER_PARAMETER_TYPE) {
13205 data->int_val = handle;
13206 if (data->int_val < 0 || data->int_val >= Num_triggers)
13207 strcpy(data->str_val, "");
13208 else {
13209 strncpy(data->str_val, Triggers[data->int_val].name, MAX_MESSAGE_NAME_LEN);
13210 data->str_val[MAX_MESSAGE_NAME_LEN] = '\0';
13211 }
13212 }
13213 break;
13214 case ROOM_TYPE:
13215 if (data->ID == ROOM_PARAMETER_TYPE) {
13216 data->int_val = handle;
13217 if (data->int_val < 0 || data->int_val > Highest_room_index)
13218 strcpy(data->str_val, "");
13219 else {
13220 strncpy(data->str_val, Rooms[data->int_val].name, MAX_MESSAGE_NAME_LEN);
13221 data->str_val[MAX_MESSAGE_NAME_LEN] = '\0';
13222 }
13223 }
13224 break;
13225 case PATH_TYPE:
13226 if (data->ID == PATH_PARAMETER_TYPE) {
13227 data->int_val = handle;
13228 if (data->int_val < 0 || data->int_val >= MAX_GAME_PATHS || !GamePaths[data->int_val].used)
13229 strcpy(data->str_val, "");
13230 else {
13231 strncpy(data->str_val, GamePaths[data->int_val].name, MAX_MESSAGE_NAME_LEN);
13232 data->str_val[MAX_MESSAGE_NAME_LEN] = '\0';
13233 }
13234 }
13235 break;
13236 case MATCEN_TYPE:
13237 if (data->ID == MATCEN_PARAMETER_TYPE) {
13238 if (handle == MATCEN_ID_VALUE) {
13239 data->subID = USE_MATCEN_EVENT_ID;
13240 data->int_val = 0;
13241 strcpy(data->str_val, "");
13242 } else {
13243 data->subID = USE_MATCEN_VALUE;
13244 data->int_val = handle;
13245 if (!MatcenValid(data->int_val))
13246 strcpy(data->str_val, "");
13247 else {
13248 char matcen_name[MAX_MATCEN_NAME_LEN + 1];
13249 Matcen[data->int_val]->GetName(matcen_name);
13250 strncpy(data->str_val, matcen_name, MAX_MESSAGE_NAME_LEN);
13251 data->str_val[MAX_MESSAGE_NAME_LEN] = '\0';
13252 }
13253 }
13254 }
13255 break;
13256 case LEVEL_GOAL_TYPE:
13257 if (data->ID == LEVEL_GOAL_PARAMETER_TYPE) {
13258 if (handle == LEVEL_GOAL_ID_VALUE) {
13259 data->subID = USE_LEVEL_GOAL_ID;
13260 data->int_val = 0;
13261 strcpy(data->str_val, "");
13262 } else {
13263 char goal_name[_MAX_PATH + 1];
13264 data->subID = USE_LEVEL_GOAL_VALUE;
13265 data->int_val = handle;
13266 if (Level_goals.GoalGetName(data->int_val, goal_name, _MAX_PATH) < 0)
13267 strcpy(data->str_val, "");
13268 else {
13269 strncpy(data->str_val, goal_name, MAX_MESSAGE_NAME_LEN);
13270 data->str_val[MAX_MESSAGE_NAME_LEN] = '\0';
13271 }
13272 }
13273 }
13274 break;
13275 }
13276 UpdateAllParentNodesText(selected_node);
13277 SetModified(TRUE);
13278 }
13279 }
13280
13281 // Assigns an event type to a Script Event Node
13282 void CDallasMainDlg::AssignEventType(int type) {
13283 HTREEITEM selected_node;
13284 tTreeNodeData *data;
13285
13286 // Obtain the currently selected node
13287 selected_node = m_ScriptTree.GetSelectedItem();
13288 if (selected_node == NULL)
13289 return;
13290
13291 // Get the node's data
13292 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
13293 if (data == NULL)
13294 return;
13295
13296 // Make sure it's a script event node
13297 if (data->type == SCRIPT_EVENT_NODE) {
13298 data->ID = type;
13299 UpdateNodeText(selected_node);
13300 SetModified(TRUE);
13301 }
13302 }
13303
13304 // Assigns a boolean type to a Bool parameter
13305 void CDallasMainDlg::AssignBooleanValue(int type) {
13306 HTREEITEM selected_node;
13307 tTreeNodeData *data;
13308
13309 // Obtain the currently selected node
13310 selected_node = m_ScriptTree.GetSelectedItem();
13311 if (selected_node == NULL)
13312 return;
13313
13314 // Get the node's data
13315 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
13316 if (data == NULL)
13317 return;
13318
13319 // Make sure it's a boolean parameter node
13320 if (data->type == PARAMETER_NODE && data->ID == BOOL_PARAMETER_TYPE) {
13321 data->int_val = type;
13322 UpdateAllParentNodesText(selected_node);
13323 SetModified(TRUE);
13324 }
13325 }
13326
13327 // Assigns a message name
13328 void CDallasMainDlg::AssignMessageName(int msg_ID) {
13329 HTREEITEM selected_node;
13330 tTreeNodeData *data;
13331
13332 // Obtain the currently selected node
13333 selected_node = m_ScriptTree.GetSelectedItem();
13334 if (selected_node == NULL)
13335 return;
13336
13337 // Get the node's data
13338 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
13339 if (data == NULL)
13340 return;
13341
13342 // Make sure it's a boolean parameter node
13343 if (data->type == PARAMETER_NODE && data->ID == STRING_PARAMETER_TYPE) {
13344 CString msg_name;
13345 m_MessageList.GetText(msg_ID, msg_name);
13346 strncpy(data->str_val, msg_name.GetBuffer(0), MAX_MESSAGE_NAME_LEN);
13347 data->str_val[MAX_MESSAGE_NAME_LEN] = '\0';
13348 UpdateAllParentNodesText(selected_node);
13349 SetModified(TRUE);
13350 }
13351 }
13352
13353 // Assigns an expression operator type
13354 void CDallasMainDlg::AssignExpOpType(int type) {
13355 HTREEITEM selected_node;
13356 tTreeNodeData *data;
13357
13358 // Obtain the currently selected node
13359 selected_node = m_ScriptTree.GetSelectedItem();
13360 if (selected_node == NULL)
13361 return;
13362
13363 // Get the node's data
13364 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
13365 if (data == NULL)
13366 return;
13367
13368 // Make sure it's a script event node
13369 if (data->type == EXPRESSION_OPERATOR_NODE) {
13370 data->subID = type;
13371 UpdateAllParentNodesText(selected_node);
13372 SetModified(TRUE);
13373 }
13374 }
13375
13376 // Assigns an expression operator type
13377 void CDallasMainDlg::AssignEnumValueType(int type) {
13378 HTREEITEM selected_node;
13379 tTreeNodeData *data;
13380
13381 // Obtain the currently selected node
13382 selected_node = m_ScriptTree.GetSelectedItem();
13383 if (selected_node == NULL)
13384 return;
13385
13386 // Get the node's data
13387 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
13388 if (data == NULL)
13389 return;
13390
13391 // Make sure it's a parameter-enum node
13392 if (data->type == PARAMETER_NODE && data->ID == ENUM_PARAMETER_TYPE) {
13393
13394 if (type == ENUM_GOALID_VALUE) {
13395 data->subID = USE_GOALID_VALUE;
13396 data->int_val = 0;
13397 } else if (type == ENUM_TIMERID_VALUE) {
13398 data->subID = USE_TIMERID_VALUE;
13399 data->int_val = 0;
13400 } else if (type == ENUM_MATCENID_VALUE) {
13401 data->subID = USE_MATCENID_VALUE;
13402 data->int_val = 0;
13403 } else {
13404 int DBslot;
13405
13406 DBslot = GetEnumID(data->name);
13407 if (DBslot == INVALID_ENUM)
13408 return;
13409
13410 if (type < 0 || type >= m_EnumDatabase[DBslot].num_values)
13411 return;
13412 data->int_val = m_EnumDatabase[DBslot].values[type].value;
13413 data->subID = USE_ENUM_VALUE;
13414 }
13415
13416 UpdateAllParentNodesText(selected_node);
13417 SetModified(TRUE);
13418 }
13419 }
13420
13421 /////////////////////////////////////////////////////////////////////////////
13422 // Functions to Add Tree Nodes (specific types)
13423 /////////////////////////////////////////////////////////////////////////////
13424
13425 // Adds nested IF-THEN Clause
13426 void CDallasMainDlg::AddNestedIfThenClause(void) {
13427 HTREEITEM selected_node;
13428 tTreeNodeData *data;
13429
13430 // Obtain the currently selected node
13431 selected_node = m_ScriptTree.GetSelectedItem();
13432 if (selected_node == NULL)
13433 return;
13434
13435 // Get the node's data
13436 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
13437 if (data == NULL)
13438 return;
13439
13440 // Add node appropriately with respect to selected node
13441 if (data->type == ACTIONS_HEADER_NODE) {
13442 CreateDefaultIfThenClause(selected_node, TVI_LAST, NESTED);
13443 m_ScriptTree.Expand(selected_node, TVE_EXPAND);
13444 } else {
13445 CreateDefaultIfThenClause(m_ScriptTree.GetParentItem(selected_node), selected_node, NESTED);
13446 m_ScriptTree.Expand(m_ScriptTree.GetParentItem(selected_node), TVE_EXPAND);
13447 }
13448 SetModified(TRUE);
13449 }
13450
13451 // Adds nested ELSE Clause
13452 void CDallasMainDlg::AddNestedElseClause(void) {
13453 HTREEITEM selected_node, next_node;
13454
13455 // Obtain the currently selected node
13456 selected_node = m_ScriptTree.GetSelectedItem();
13457 if (selected_node == NULL)
13458 return;
13459
13460 // Add node appropriately with respect to selected node
13461 if (!CanAppendElseToNode(selected_node))
13462 return;
13463
13464 // See if there is a node after this one
13465 next_node = m_ScriptTree.GetNextSiblingItem(selected_node);
13466
13467 if (next_node == NULL)
13468 CreateDefaultElseClause(m_ScriptTree.GetParentItem(selected_node), TVI_LAST);
13469 else
13470 CreateDefaultElseClause(m_ScriptTree.GetParentItem(next_node), next_node);
13471 SetModified(TRUE);
13472 }
13473
13474 // Adds nested IF-THEN-ELSE Clause
13475 void CDallasMainDlg::AddNestedIfThenElseClause(void) {
13476 HTREEITEM selected_node;
13477 tTreeNodeData *data;
13478
13479 // Obtain the currently selected node
13480 selected_node = m_ScriptTree.GetSelectedItem();
13481 if (selected_node == NULL)
13482 return;
13483
13484 // Get the node's data
13485 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
13486 if (data == NULL)
13487 return;
13488
13489 // Add node appropriately with respect to selected node
13490 if (data->type == ACTIONS_HEADER_NODE) {
13491 CreateDefaultIfThenClause(selected_node, TVI_LAST, NESTED);
13492 CreateDefaultElseClause(selected_node, TVI_LAST);
13493 m_ScriptTree.Expand(selected_node, TVE_EXPAND);
13494 } else {
13495 CreateDefaultIfThenClause(m_ScriptTree.GetParentItem(selected_node), selected_node, NESTED);
13496 CreateDefaultElseClause(m_ScriptTree.GetParentItem(selected_node), selected_node);
13497 m_ScriptTree.Expand(m_ScriptTree.GetParentItem(selected_node), TVE_EXPAND);
13498 }
13499 SetModified(TRUE);
13500 }
13501
13502 // Adds a conditional statement node
13503 void CDallasMainDlg::AddConditionalStatementNode(int type, int query_id /*=-1*/) {
13504 HTREEITEM selected_node, new_condition_node;
13505 tTreeNodeData *data;
13506
13507 // Check the ID validity
13508 if (type < 0 || type >= MAX_CONDITION_TYPES)
13509 return;
13510
13511 // Obtain the currently selected node
13512 selected_node = m_ScriptTree.GetSelectedItem();
13513 if (selected_node == NULL)
13514 return;
13515
13516 // Get the node's data
13517 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
13518 if (data == NULL)
13519 return;
13520
13521 // Make sure this node is valid for adding a conditional statement
13522 if (data->type == LOGICAL_OPERATOR_NODE) {
13523 tTreeNodeData node_data;
13524
13525 // Fill in the data appropriately for the new condition node
13526 node_data.type = CONDITIONAL_STATEMENT_NODE;
13527 node_data.ID = type;
13528
13529 // Add node appropriately with respect to selected node
13530 new_condition_node = AddNodeToTree(selected_node, TVI_LAST, &node_data, TRUE);
13531
13532 // Create default subnodes for a binary condition
13533 CreateDefaultConditionalStatementSubtree(new_condition_node, type, query_id);
13534
13535 // Update the new condition node's text to include the expressions
13536 UpdateNodeText(new_condition_node);
13537 SetModified(TRUE);
13538 if (new_condition_node != NULL)
13539 m_ScriptTree.Expand(new_condition_node, TVE_EXPAND);
13540 }
13541 }
13542
13543 // Inserts a logical operator node as parent of current node
13544 void CDallasMainDlg::InsertLogicalOperatorNode(int type) {
13545 HTREEITEM selected_node, new_logop_node;
13546 tTreeNodeData *data;
13547
13548 // Check the ID validity
13549 if (type < 0 || type >= MAX_LOGICAL_OPERATORS)
13550 return;
13551
13552 // Obtain the currently selected node
13553 selected_node = m_ScriptTree.GetSelectedItem();
13554 if (selected_node == NULL)
13555 return;
13556
13557 // Get the node's data
13558 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
13559 if (data == NULL)
13560 return;
13561
13562 // Make sure this node is valid for inserting a logical operator
13563 if (data->type == LOGICAL_OPERATOR_NODE || data->type == CONDITIONAL_STATEMENT_NODE) {
13564 tTreeNodeData node_data;
13565
13566 // Fill in the data appropriately for the new condition node
13567 node_data.type = LOGICAL_OPERATOR_NODE;
13568 node_data.ID = type;
13569
13570 // Add node appropriately with respect to selected node
13571 new_logop_node = AddNodeToTree(m_ScriptTree.GetParentItem(selected_node), selected_node, &node_data, TRUE);
13572
13573 // Now copy the selected item tree over to the new logop
13574 CopyTree(new_logop_node, TVI_LAST, selected_node);
13575 m_ScriptTree.Expand(new_logop_node, TVE_EXPAND);
13576
13577 // Add a default ALWAYS so that the logical operator has TWO children
13578 CreateDefaultConditionalStatementNode(new_logop_node);
13579
13580 // Now delete the selected item tree
13581 m_ScriptTree.SelectItem(new_logop_node);
13582 FreeTreeItem(selected_node);
13583
13584 SetModified(TRUE);
13585 }
13586 }
13587
13588 // Adds a logical operator subtree to the end of selected node's children
13589 void CDallasMainDlg::AddLogicalOperatorNode(int type) {
13590 HTREEITEM selected_node, new_logop_node;
13591 tTreeNodeData *data;
13592
13593 // Check the ID validity
13594 if (type < 0 || type >= MAX_LOGICAL_OPERATORS)
13595 return;
13596
13597 // Obtain the currently selected node
13598 selected_node = m_ScriptTree.GetSelectedItem();
13599 if (selected_node == NULL)
13600 return;
13601
13602 // Get the node's data
13603 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
13604 if (data == NULL)
13605 return;
13606
13607 // Make sure this node is valid for inserting a logical operator
13608 if (data->type == LOGICAL_OPERATOR_NODE) {
13609 tTreeNodeData node_data;
13610
13611 // Fill in the data appropriately for the new condition node
13612 node_data.type = LOGICAL_OPERATOR_NODE;
13613 node_data.ID = type;
13614
13615 // Add node appropriately with respect to selected node
13616 new_logop_node = AddNodeToTree(selected_node, TVI_LAST, &node_data, TRUE);
13617
13618 // Add a pair of default ALWAYS's so that the logical operator has TWO children
13619 CreateDefaultConditionalStatementNode(new_logop_node);
13620 CreateDefaultConditionalStatementNode(new_logop_node);
13621
13622 if (new_logop_node != NULL)
13623 m_ScriptTree.Expand(new_logop_node, TVE_EXPAND);
13624
13625 SetModified(TRUE);
13626 }
13627 }
13628
13629 // Adds an action statement node
13630 void CDallasMainDlg::AddActionStatementNode(int action_ID) {
13631 HTREEITEM selected_node, new_action_node;
13632 tTreeNodeData *data;
13633
13634 // Check the ID validity
13635 if ((action_ID < 0 || action_ID >= MAX_ACTIONS) && action_ID != DO_NOTHING_ID)
13636 return;
13637
13638 // Obtain the currently selected node
13639 selected_node = m_ScriptTree.GetSelectedItem();
13640 if (selected_node == NULL)
13641 return;
13642
13643 // Get the node's data
13644 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
13645 if (data == NULL)
13646 return;
13647
13648 // Make sure this node is valid for adding an Action
13649 if (data->type == ACTIONS_HEADER_NODE || data->type == ACTION_STATEMENT_NODE) {
13650 tTreeNodeData node_data;
13651
13652 // Fill in the data appropriately for the new Action node
13653 node_data.type = ACTION_STATEMENT_NODE;
13654 node_data.ID = action_ID;
13655
13656 // Add node appropriately with respect to selected node
13657 if (data->type == ACTIONS_HEADER_NODE)
13658 new_action_node = AddNodeToTree(selected_node, TVI_LAST, &node_data, TRUE);
13659 else
13660 new_action_node = AddNodeToTree(m_ScriptTree.GetParentItem(selected_node), selected_node, &node_data, TRUE);
13661
13662 // If it's a real Action, add in the parameters with appropriate defaults
13663 AddActionParameterNodes(new_action_node);
13664
13665 // Update the new action node's text to include the parameters
13666 UpdateNodeText(new_action_node);
13667 if (new_action_node != NULL)
13668 m_ScriptTree.Expand(new_action_node, TVE_EXPAND);
13669
13670 SetModified(TRUE);
13671 }
13672 }
13673
13674 // Adds all parameter nodes to the given action node
13675 void CDallasMainDlg::AddActionParameterNodes(HTREEITEM action_node) {
13676 CString name_text, default_text, range_text;
13677 tTreeNodeData *data;
13678 char *desc;
13679
13680 // Make sure node is valid
13681 if (action_node == NULL)
13682 return;
13683
13684 // Get the node's data
13685 data = (tTreeNodeData *)m_ScriptTree.GetItemData(action_node);
13686 if (data == NULL)
13687 return;
13688
13689 // Make sure it's a valid action
13690 if (data->type != ACTION_STATEMENT_NODE || data->ID < 0 || data->ID >= MAX_ACTIONS)
13691 return;
13692
13693 // Get the action description
13694 desc = GetActionDesc(data->ID);
13695 if (desc == NULL)
13696 return;
13697
13698 // Parse the description, adding default parameter nodes appropriately
13699 while ((*desc) != '\0') {
13700
13701 if ((*desc) == '[') { // Note the start of a parameter block
13702 int param_type = ParseParamBlock(desc, name_text, default_text, range_text);
13703 if (param_type >= 0 && param_type != UNKNOWN_PARAMETER_TYPE)
13704 CreateDefaultParameterNode(action_node, TVI_LAST, param_type, name_text.GetBuffer(0),
13705 default_text.GetBuffer(0));
13706 } else {
13707 desc++;
13708 }
13709 }
13710 SetModified(TRUE);
13711 }
13712
13713 /* OLD VERSION
13714 // Adds all parameter nodes to the given action node
13715 void CDallasMainDlg::AddActionParameterNodes(HTREEITEM action_node)
13716 {
13717 tTreeNodeData *data;
13718 char *desc, *desc_copy;
13719 int param_type_char, param_type;
13720 char *param_name;
13721 bool start_block_found;
13722 bool type_delim_found;
13723 int j;
13724
13725 // Make sure node is valid
13726 if(action_node==NULL) return;
13727
13728 // Get the node's data
13729 data=(tTreeNodeData *)m_ScriptTree.GetItemData(action_node);
13730 if(data==NULL) return;
13731
13732 // Make sure it's a valid action
13733 if(data->type!=ACTION_STATEMENT_NODE || data->ID<0 || data->ID>=MAX_ACTIONS) return;
13734
13735 // Get the action description
13736 desc=GetActionDesc(data->ID);
13737 if(desc==NULL) return;
13738
13739 // Make a copy of description (so null chars can be added)
13740 desc_copy=(char *)mem_malloc(strlen(desc)+1);
13741 if(desc_copy==NULL) {
13742 MessageBox("ERROR: Out of memory adding action parameter node!","Out of Memory
13743 Error!",MB_OK|MB_ICONEXCLAMATION); return;
13744 }
13745 strcpy(desc_copy,desc);
13746
13747 // Parse the description, adding default parameter nodes appropriately
13748 j=0;
13749 start_block_found=FALSE;
13750 type_delim_found=FALSE;
13751 param_name=NULL;
13752 param_type_char=-1;
13753
13754 while(desc_copy[j]!='\0') {
13755
13756 if(desc_copy[j]=='[') { // Note the start of a parameter block
13757 start_block_found=TRUE;
13758 }
13759 else if(desc_copy[j]==':' && start_block_found) { // Note the end of parameter type field
13760 type_delim_found=TRUE;
13761 }
13762 else if(desc_copy[j]==']') { // If end of block, add the parameter
13763
13764 if(param_type_char!=-1 && param_name!=NULL) {
13765
13766 desc_copy[j]='\0'; // mark the end of the variable name
13767
13768 // Get the parameter type
13769 param_type=ConvertParamCharToType(param_type_char);
13770
13771 if(param_type!=UNKNOWN_PARAMETER_TYPE)
13772 CreateDefaultParameterNode(action_node,TVI_LAST,param_type,param_name);
13773 }
13774
13775 start_block_found=FALSE;
13776 type_delim_found=FALSE;
13777 param_name=NULL;
13778 param_type_char=-1;
13779 }
13780 else if(start_block_found && param_type_char==-1) {
13781 param_type_char=desc_copy[j];
13782 }
13783 else if(type_delim_found && param_name==NULL) {
13784 param_name=&desc_copy[j];
13785 }
13786
13787 j++;
13788 }
13789
13790 // Free up the copy memory
13791 mem_free(desc_copy);
13792 }
13793 */
13794
13795 // Adds all parameter nodes to the given expression (query) node
13796 void CDallasMainDlg::AddQueryParameterNodes(HTREEITEM query_node) {
13797 CString name_text, default_text, range_text;
13798 tTreeNodeData *data;
13799 char *desc;
13800
13801 // Make sure node is valid
13802 if (query_node == NULL)
13803 return;
13804
13805 // Get the node's data
13806 data = (tTreeNodeData *)m_ScriptTree.GetItemData(query_node);
13807 if (data == NULL)
13808 return;
13809
13810 // Make sure it's a valid action
13811 if (data->type != EXPRESSION_NODE || data->ID < 0 || data->ID >= MAX_QUERIES)
13812 return;
13813
13814 // Get the action description
13815 desc = GetQueryDesc(data->ID);
13816 if (desc == NULL)
13817 return;
13818
13819 // Parse the description, adding default parameter nodes appropriately
13820 while ((*desc) != '\0') {
13821
13822 if ((*desc) == '[') { // Note the start of a parameter block
13823 int param_type = ParseParamBlock(desc, name_text, default_text, range_text);
13824 if (param_type >= 0 && param_type != UNKNOWN_PARAMETER_TYPE)
13825 CreateDefaultParameterNode(query_node, TVI_LAST, param_type, name_text.GetBuffer(0), default_text.GetBuffer(0));
13826 } else {
13827 desc++;
13828 }
13829 }
13830 SetModified(TRUE);
13831 }
13832
13833 /*
13834 // Adds all parameter nodes to the given expression (query) node
13835 void CDallasMainDlg::AddQueryParameterNodes(HTREEITEM query_node)
13836 {
13837 tTreeNodeData *data;
13838 char *desc, *desc_copy;
13839 int param_type_char, param_type;
13840 char *param_name;
13841 bool start_block_found;
13842 bool type_delim_found;
13843 int j;
13844
13845 // Make sure node is valid
13846 if(query_node==NULL) return;
13847
13848 // Get the node's data
13849 data=(tTreeNodeData *)m_ScriptTree.GetItemData(query_node);
13850 if(data==NULL) return;
13851
13852 // Make sure it's a valid action
13853 if(data->type!=EXPRESSION_NODE || data->ID<0 || data->ID>=MAX_QUERIES) return;
13854
13855 // Get the action description
13856 desc=GetQueryDesc(data->ID);
13857 if(desc==NULL) return;
13858
13859 // Make a copy of description (so null chars can be added)
13860 desc_copy=(char *)mem_malloc(strlen(desc)+1);
13861 if(desc_copy==NULL) {
13862 MessageBox("ERROR: Out of memory adding query parameter node!","Out of Memory
13863 Error!",MB_OK|MB_ICONEXCLAMATION); return;
13864 }
13865 strcpy(desc_copy,desc);
13866
13867 // Parse the description, adding default parameter nodes appropriately
13868 j=0;
13869 start_block_found=FALSE;
13870 type_delim_found=FALSE;
13871 param_name=NULL;
13872 param_type_char=-1;
13873
13874 while(desc_copy[j]!='\0') {
13875
13876 if(desc_copy[j]=='[') { // Note the start of a parameter block
13877 start_block_found=TRUE;
13878 }
13879 else if(desc_copy[j]==':' && start_block_found) { // Note the end of parameter type field
13880 type_delim_found=TRUE;
13881 }
13882 else if(desc_copy[j]==']') { // If end of block, add the parameter
13883
13884 if(param_type_char!=-1 && param_name!=NULL) {
13885
13886 desc_copy[j]='\0'; // mark the end of the variable name
13887
13888 // Get the parameter type
13889 param_type=ConvertParamCharToType(param_type_char);
13890
13891 if(param_type!=UNKNOWN_PARAMETER_TYPE)
13892 CreateDefaultParameterNode(query_node,TVI_LAST,param_type,param_name);
13893 }
13894
13895 start_block_found=FALSE;
13896 type_delim_found=FALSE;
13897 param_name=NULL;
13898 param_type_char=-1;
13899 }
13900 else if(start_block_found && param_type_char==-1) {
13901 param_type_char=desc_copy[j];
13902 }
13903 else if(type_delim_found && param_name==NULL) {
13904 param_name=&desc_copy[j];
13905 }
13906
13907 j++;
13908 }
13909
13910 // Free up the copy memory
13911 mem_free(desc_copy);
13912 }
13913 */
13914
13915 ///////////////////////////////////
13916 // Functions to Replace Tree Nodes
13917 ///////////////////////////////////
13918
13919 // Replaces the currently selected node with a new query
13920 void CDallasMainDlg::ReplaceWithQueryNode(int query_ID) {
13921 HTREEITEM selected_node, new_query_node;
13922 tTreeNodeData *data;
13923 int query_return_type;
13924 CString query_return_name;
13925
13926 // Check the ID validity
13927 if (query_ID < 0 || query_ID >= MAX_QUERIES)
13928 return;
13929
13930 // Obtain the currently selected node
13931 selected_node = m_ScriptTree.GetSelectedItem();
13932 if (selected_node == NULL)
13933 return;
13934
13935 // Get the node's data
13936 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
13937 if (data == NULL)
13938 return;
13939
13940 // Make sure this node is valid for adding a query
13941 if (data->type == EXPRESSION_NODE || data->type == PARAMETER_NODE) {
13942 tTreeNodeData node_data;
13943
13944 // Fill in the data appropriately for the new query node
13945 node_data.type = EXPRESSION_NODE;
13946 node_data.ID = query_ID;
13947
13948 query_return_type = GetQueryReturnType(query_ID, query_return_name);
13949 if (query_return_type == ENUM_PARAMETER_TYPE || query_return_type == FLAG_PARAMETER_TYPE)
13950 strcpy(node_data.name, query_return_name.GetBuffer(0));
13951 else if (GetNodeType(m_ScriptTree.GetParentItem(selected_node)) == CONDITIONAL_STATEMENT_NODE)
13952 strcpy(node_data.name, GetLiteralName(query_return_type));
13953 else
13954 strcpy(node_data.name, data->name);
13955
13956 // Add new query node before current node, then delete the current node
13957 new_query_node = AddNodeToTree(m_ScriptTree.GetParentItem(selected_node), selected_node, &node_data, TRUE);
13958
13959 // Add in the parameters with appropriate defaults
13960 AddQueryParameterNodes(new_query_node);
13961
13962 // Now delete the selected item tree
13963 m_ScriptTree.SelectItem(new_query_node);
13964 FreeTreeItem(selected_node);
13965
13966 // Update the new query node's text to include the parameters
13967 UpdateAllParentNodesText(new_query_node);
13968
13969 // If this node is the first of a comparison conditional, make sure third node's type matches
13970 DoComparisonMatchup(new_query_node);
13971
13972 if (new_query_node != NULL)
13973 m_ScriptTree.Expand(new_query_node, TVE_EXPAND);
13974
13975 SetModified(TRUE);
13976 }
13977 }
13978
13979 // Replaces the currently selected node with a literal (given a default value)
13980 void CDallasMainDlg::ReplaceWithLiteralNode(int literal_type, int index) {
13981 HTREEITEM selected_node, new_literal_node;
13982 tTreeNodeData *data;
13983
13984 // Check the ID validity
13985 if (literal_type < 0 || literal_type >= MAX_LITERALS)
13986 return;
13987
13988 // Obtain the currently selected node
13989 selected_node = m_ScriptTree.GetSelectedItem();
13990 if (selected_node == NULL)
13991 return;
13992
13993 // Get the node's data
13994 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
13995 if (data == NULL)
13996 return;
13997
13998 // Make sure this node is valid for adding a query
13999 if (data->type == EXPRESSION_NODE || data->type == PARAMETER_NODE) {
14000
14001 CString tmp_str;
14002 if (literal_type == ENUM_PARAMETER_TYPE)
14003 tmp_str = m_EnumDatabase[index].name;
14004 else if (literal_type == FLAG_PARAMETER_TYPE)
14005 tmp_str = m_FlagDatabase[index].name;
14006 else if (GetNodeType(m_ScriptTree.GetParentItem(selected_node)) == CONDITIONAL_STATEMENT_NODE)
14007 tmp_str = GetLiteralName(literal_type);
14008 else
14009 tmp_str = data->name;
14010
14011 // Create a default parameter node for the chosen literal
14012 CString name_text, default_text, range_text;
14013 int n, param_type;
14014 n = GetChildPosition(selected_node);
14015 param_type = ParseNthParam(m_ScriptTree.GetParentItem(selected_node), n, name_text, default_text, range_text);
14016 if (param_type >= 0)
14017 new_literal_node = CreateDefaultParameterNode(m_ScriptTree.GetParentItem(selected_node), selected_node,
14018 literal_type, tmp_str.GetBuffer(0), default_text.GetBuffer(0));
14019 else
14020 new_literal_node = CreateDefaultParameterNode(m_ScriptTree.GetParentItem(selected_node), selected_node,
14021 literal_type, tmp_str.GetBuffer(0));
14022
14023 // Now delete the selected item tree
14024 m_ScriptTree.SelectItem(new_literal_node);
14025 FreeTreeItem(selected_node);
14026
14027 // Update the new literal nodes text
14028 UpdateAllParentNodesText(new_literal_node);
14029
14030 // If this node is the first of a comparison conditional, make sure third node's type matches
14031 DoComparisonMatchup(new_literal_node);
14032
14033 SetModified(TRUE);
14034 }
14035 }
14036
14037 // If this node is the first of a comparison conditional, make sure third node's type matches
14038 // If they don't match, remove the third node and replace it with a default param that does match
14039 void CDallasMainDlg::DoComparisonMatchup(HTREEITEM node) {
14040 int node_type, onode_type;
14041 CString node_name, onode_name;
14042 HTREEITEM other_node, new_param_node;
14043
14044 if (node == NULL)
14045 return;
14046
14047 // If it's not the first node of a comparison conditional, nothing need be done
14048 if (!ParentIsComparisonConditional(node) || GetChildPosition(node) != 1)
14049 return;
14050
14051 // ok, it is, so now we need to get the other node being compared
14052 other_node = GetNthChild(m_ScriptTree.GetParentItem(node), 3);
14053 if (other_node == NULL)
14054 return;
14055
14056 // Get the other node's data
14057 onode_type = GetParamType(other_node, onode_name);
14058
14059 // Get this node's data
14060 node_type = GetParamType(node, node_name);
14061 if (node_type < 0)
14062 return;
14063
14064 // Do the node types match? If they do, get out of here
14065 if (node_type == onode_type) {
14066 if (node_type == ENUM_PARAMETER_TYPE || node_type == FLAG_PARAMETER_TYPE) {
14067 if (node_name.IsEmpty())
14068 return;
14069 else if (strcmp(node_name.GetBuffer(0), onode_name.GetBuffer(0)) == 0)
14070 return;
14071 } else
14072 return;
14073 }
14074
14075 // If we're here, then the nodes don't match... so create a matching default param
14076 CString tmp_str;
14077 if (node_type == ENUM_PARAMETER_TYPE || node_type == FLAG_PARAMETER_TYPE)
14078 tmp_str = node_name;
14079 else
14080 tmp_str = GetLiteralName(node_type);
14081
14082 new_param_node =
14083 CreateDefaultParameterNode(m_ScriptTree.GetParentItem(other_node), other_node, node_type, tmp_str.GetBuffer(0));
14084
14085 // Now delete the old param node
14086 FreeTreeItem(other_node);
14087
14088 // Update the new literal nodes text
14089 UpdateAllParentNodesText(new_param_node);
14090
14091 SetModified(TRUE);
14092 }
14093
14094 // Replaces the currently selected node with a new action
14095 void CDallasMainDlg::ReplaceWithActionNode(int action_ID) {
14096 HTREEITEM selected_node, new_action_node;
14097 tTreeNodeData *data;
14098
14099 // Check the ID validity
14100 if ((action_ID < 0 || action_ID >= MAX_ACTIONS) && action_ID != DO_NOTHING_ID)
14101 return;
14102
14103 // Obtain the currently selected node
14104 selected_node = m_ScriptTree.GetSelectedItem();
14105 if (selected_node == NULL)
14106 return;
14107
14108 // Get the node's data
14109 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
14110 if (data == NULL)
14111 return;
14112
14113 // Make sure this node is valid for adding an Action
14114 if (data->type == ACTION_STATEMENT_NODE) {
14115 tTreeNodeData node_data;
14116
14117 // Fill in the data appropriately for the new Action node
14118 node_data.type = ACTION_STATEMENT_NODE;
14119 node_data.ID = action_ID;
14120
14121 // Add node appropriately with respect to selected node
14122 new_action_node = AddNodeToTree(m_ScriptTree.GetParentItem(selected_node), selected_node, &node_data, TRUE);
14123
14124 // If it's a real Action, add in the parameters with appropriate defaults
14125 AddActionParameterNodes(new_action_node);
14126
14127 // Now delete the selected item tree
14128 m_ScriptTree.SelectItem(new_action_node);
14129 FreeTreeItem(selected_node);
14130
14131 // Update the new action node's text to include the parameters
14132 UpdateNodeText(new_action_node);
14133 if (new_action_node != NULL)
14134 m_ScriptTree.Expand(new_action_node, TVE_EXPAND);
14135 SetModified(TRUE);
14136 }
14137 }
14138
14139 // Replaces the currently selected node with a new logical operation
14140 void CDallasMainDlg::ReplaceWithLogOpNode(int type) {
14141 HTREEITEM selected_node, new_logop_node;
14142 tTreeNodeData *data;
14143
14144 // Check the ID validity
14145 if (type < 0 || type >= MAX_LOGICAL_OPERATORS)
14146 return;
14147
14148 // Obtain the currently selected node
14149 selected_node = m_ScriptTree.GetSelectedItem();
14150 if (selected_node == NULL)
14151 return;
14152
14153 // Get the node's data
14154 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
14155 if (data == NULL)
14156 return;
14157
14158 // If this node IS a logical operator, just change its data
14159 if (data->type == LOGICAL_OPERATOR_NODE) {
14160 data->ID = type;
14161 UpdateAllParentNodesText(selected_node);
14162 SetModified(TRUE);
14163 return;
14164 }
14165
14166 // Make sure this node is valid for inserting a logical operator
14167 if (data->type == LOGICAL_OPERATOR_NODE || data->type == CONDITIONAL_STATEMENT_NODE) {
14168 tTreeNodeData node_data;
14169
14170 // Fill in the data appropriately for the new condition node
14171 node_data.type = LOGICAL_OPERATOR_NODE;
14172 node_data.ID = type;
14173
14174 // Add node appropriately with respect to selected node
14175 new_logop_node = AddNodeToTree(m_ScriptTree.GetParentItem(selected_node), selected_node, &node_data, TRUE);
14176
14177 // Add a pair of default ALWAYS's so that the logical operator has TWO children
14178 CreateDefaultConditionalStatementNode(new_logop_node);
14179 CreateDefaultConditionalStatementNode(new_logop_node);
14180
14181 // Now delete the selected item tree
14182 m_ScriptTree.SelectItem(new_logop_node);
14183 FreeTreeItem(selected_node);
14184
14185 if (new_logop_node != NULL)
14186 m_ScriptTree.Expand(new_logop_node, TVE_EXPAND);
14187 SetModified(TRUE);
14188 }
14189 }
14190
14191 // Replaces the currently selected node with a new condition
14192 void CDallasMainDlg::ReplaceWithConditionNode(int type, int query_id /*=-1*/) {
14193 HTREEITEM selected_node, new_condition_node;
14194 tTreeNodeData *data;
14195
14196 // Check the ID validity
14197 if (type < 0 || type >= MAX_CONDITION_TYPES)
14198 return;
14199
14200 // Obtain the currently selected node
14201 selected_node = m_ScriptTree.GetSelectedItem();
14202 if (selected_node == NULL)
14203 return;
14204
14205 // Get the node's data
14206 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
14207 if (data == NULL)
14208 return;
14209
14210 // Make sure this node is valid for adding a conditional statement
14211 if (data->type == LOGICAL_OPERATOR_NODE || data->type == CONDITIONAL_STATEMENT_NODE) {
14212 tTreeNodeData node_data;
14213
14214 // Fill in the data appropriately for the new condition node
14215 node_data.type = CONDITIONAL_STATEMENT_NODE;
14216 node_data.ID = type;
14217
14218 // Add node appropriately with respect to selected node
14219 new_condition_node = AddNodeToTree(m_ScriptTree.GetParentItem(selected_node), selected_node, &node_data, TRUE);
14220
14221 // Create default subnodes for a binary condition
14222 CreateDefaultConditionalStatementSubtree(new_condition_node, type, query_id);
14223
14224 // Now delete the selected item tree
14225 m_ScriptTree.SelectItem(new_condition_node);
14226 FreeTreeItem(selected_node);
14227
14228 // Update the new condition node's text to include the expressions
14229 UpdateNodeText(new_condition_node);
14230
14231 if (new_condition_node != NULL)
14232 m_ScriptTree.Expand(new_condition_node, TVE_EXPAND);
14233 SetModified(TRUE);
14234 }
14235 }
14236
14237 /////////////////////////////////////////////////////////////////////////////
14238 // Functions to Create (and Add) default Tree Nodes
14239 /////////////////////////////////////////////////////////////////////////////
14240
14241 // Inserts a default script tree before the specified node (or at the end if NULL)
14242 HTREEITEM CDallasMainDlg::CreateDefaultScriptTree(int script_ID, HTREEITEM insert_before /*=NULL*/) {
14243 HTREEITEM ib_node, parent;
14244 tTreeNodeData node_data;
14245
14246 ib_node = GetParentNodeOfType(insert_before, SCRIPT_HEADER_NODE);
14247 if (ib_node != NULL && m_ScriptTree.GetParentItem(ib_node) != NULL)
14248 ib_node = m_ClipboardNode;
14249 if (ib_node == NULL) {
14250 if (m_ClipboardNode != NULL)
14251 ib_node = m_ClipboardNode;
14252 else
14253 ib_node = TVI_LAST;
14254 }
14255
14256 // Create the default Script Header node
14257 node_data.type = SCRIPT_HEADER_NODE;
14258 node_data.ID = script_ID;
14259 strcpy(node_data.name, DEFAULT_SCRIPT_HEADER_STRING);
14260 parent = AddNodeToTree(TVI_ROOT, ib_node, &node_data);
14261
14262 // Create the default Script owner node
14263 node_data.type = SCRIPT_OWNER_NODE;
14264 node_data.ID = NOT_SPECIFIED_TYPE;
14265 node_data.int_val = 0;
14266 AddNodeToTree(parent, TVI_LAST, &node_data);
14267
14268 // Create the default Event Type Node
14269 node_data.type = SCRIPT_EVENT_NODE;
14270 node_data.ID = COLLIDE_EVENT_TYPE;
14271 AddNodeToTree(parent, TVI_LAST, &node_data);
14272
14273 CreateDefaultIfThenClause(parent, TVI_LAST, TOP_LEVEL);
14274
14275 if (parent != NULL)
14276 m_ScriptTree.Expand(parent, TVE_EXPAND);
14277 SetModified(TRUE);
14278
14279 return (parent);
14280 }
14281
14282 // Create default IF-THEN Clause
14283 HTREEITEM CDallasMainDlg::CreateDefaultIfThenClause(HTREEITEM parent, HTREEITEM insert_before, int type) {
14284 HTREEITEM header;
14285 tTreeNodeData node_data;
14286
14287 if (parent == NULL || insert_before == NULL)
14288 return NULL;
14289
14290 // Create the default Conditional header Node
14291 node_data.type = CONDITIONAL_HEADER_NODE;
14292 node_data.ID = type;
14293 header = AddNodeToTree(parent, insert_before, &node_data);
14294 if (header == NULL)
14295 return (NULL);
14296
14297 // Create the default conditional statement Node
14298 CreateDefaultConditionalStatementNode(header);
14299 if (header != NULL)
14300 m_ScriptTree.Expand(header, TVE_EXPAND);
14301
14302 // Create the default Action header Node
14303 node_data.type = ACTIONS_HEADER_NODE;
14304 node_data.ID = type;
14305 if (type == TOP_LEVEL) {
14306 node_data.subID = 0;
14307 node_data.int_val = CONTINUE_SCRIPT_CHAIN;
14308 } else {
14309 node_data.subID = THEN_CLAUSE;
14310 node_data.int_val = 0;
14311 }
14312 header = AddNodeToTree(parent, insert_before, &node_data);
14313
14314 // Create the default action statement Node
14315 CreateDefaultActionStatementNode(header);
14316 if (header != NULL)
14317 m_ScriptTree.Expand(header, TVE_EXPAND);
14318 SetModified(TRUE);
14319
14320 return (header);
14321 }
14322
14323 // Create default IF-THEN Clause
14324 HTREEITEM CDallasMainDlg::CreateDefaultElseClause(HTREEITEM parent, HTREEITEM insert_before) {
14325 HTREEITEM header;
14326 tTreeNodeData node_data;
14327
14328 if (parent == NULL || insert_before == NULL)
14329 return NULL;
14330
14331 // Create the default Action header Node
14332 node_data.type = ACTIONS_HEADER_NODE;
14333 node_data.ID = NESTED;
14334 node_data.subID = ELSE_CLAUSE;
14335 node_data.int_val = 0;
14336 header = AddNodeToTree(parent, insert_before, &node_data);
14337
14338 // Create the default action statement Node
14339 CreateDefaultActionStatementNode(header);
14340 if (header != NULL)
14341 m_ScriptTree.Expand(header, TVE_EXPAND);
14342 SetModified(TRUE);
14343
14344 return (header);
14345 }
14346
14347 // Create default conditional statement node
14348 HTREEITEM CDallasMainDlg::CreateDefaultConditionalStatementNode(HTREEITEM parent) {
14349 tTreeNodeData node_data;
14350
14351 if (parent == NULL)
14352 return NULL;
14353
14354 node_data.type = CONDITIONAL_STATEMENT_NODE;
14355 node_data.ID = ALWAYS_STATEMENT;
14356 SetModified(TRUE);
14357
14358 return (AddNodeToTree(parent, TVI_LAST, &node_data));
14359 }
14360
14361 // Create default conditional statement node
14362 HTREEITEM CDallasMainDlg::CreateDefaultConditionalStatementSubtree(HTREEITEM parent, int type, int query_id /*=-1*/) {
14363 HTREEITEM last_added_node, first_parm_node;
14364
14365 if (parent == NULL)
14366 return NULL;
14367 if (type == ALWAYS_STATEMENT)
14368 return NULL;
14369
14370 // Add default binary subtree
14371 if (type == BINARY_STATEMENT) {
14372 first_parm_node = CreateDefaultParameterNode(parent, TVI_LAST, BOOL_PARAMETER_TYPE, "Literal");
14373 last_added_node = CreateDefaultExpressionOperatorNode(parent, BINARY_OPERATOR_TYPE);
14374 }
14375
14376 // Add default comparison subtree
14377 if (type == COMPARISON_STATEMENT) {
14378 first_parm_node = CreateDefaultParameterNode(parent, TVI_LAST, FLOAT_PARAMETER_TYPE, "Literal");
14379 last_added_node = CreateDefaultExpressionOperatorNode(parent, COMPARISON_OPERATOR_TYPE);
14380 last_added_node = CreateDefaultParameterNode(parent, TVI_LAST, FLOAT_PARAMETER_TYPE, "Literal");
14381 }
14382
14383 // Replace first node with a query if necessary
14384 if (first_parm_node != NULL && query_id >= 0 && query_id < MAX_QUERIES) {
14385
14386 // Get the node's data
14387 tTreeNodeData *data = (tTreeNodeData *)m_ScriptTree.GetItemData(first_parm_node);
14388
14389 // Make sure this node is valid for adding a query
14390 if (data != NULL && (data->type == EXPRESSION_NODE || data->type == PARAMETER_NODE)) {
14391 tTreeNodeData node_data;
14392 int query_return_type;
14393 HTREEITEM new_query_node;
14394 CString query_return_name;
14395
14396 // Fill in the data appropriately for the new query node
14397 node_data.type = EXPRESSION_NODE;
14398 node_data.ID = query_id;
14399
14400 query_return_type = GetQueryReturnType(query_id, query_return_name);
14401 if (query_return_type == ENUM_PARAMETER_TYPE || query_return_type == FLAG_PARAMETER_TYPE)
14402 strcpy(node_data.name, query_return_name.GetBuffer(0));
14403 else if (GetNodeType(m_ScriptTree.GetParentItem(first_parm_node)) == CONDITIONAL_STATEMENT_NODE)
14404 strcpy(node_data.name, GetLiteralName(query_return_type));
14405 else
14406 strcpy(node_data.name, data->name);
14407
14408 // Add new query node before current node, then delete the current node
14409 new_query_node = AddNodeToTree(m_ScriptTree.GetParentItem(first_parm_node), first_parm_node, &node_data, TRUE);
14410
14411 // Add in the parameters with appropriate defaults
14412 AddQueryParameterNodes(new_query_node);
14413
14414 // Now delete the selected item tree
14415 FreeTreeItem(first_parm_node);
14416
14417 // Update the new query node's text to include the parameters
14418 UpdateAllParentNodesText(new_query_node);
14419
14420 // If this node is the first of a comparison conditional, make sure third node's type matches
14421 DoComparisonMatchup(new_query_node);
14422
14423 if (new_query_node != NULL)
14424 m_ScriptTree.Expand(new_query_node, TVE_EXPAND);
14425 }
14426 }
14427
14428 SetModified(TRUE);
14429
14430 return (last_added_node);
14431 }
14432
14433 // Create default expression operator node
14434 HTREEITEM CDallasMainDlg::CreateDefaultExpressionOperatorNode(HTREEITEM parent, int type) {
14435 tTreeNodeData node_data;
14436
14437 if (parent == NULL)
14438 return NULL;
14439 if (type != BINARY_OPERATOR_TYPE && type != COMPARISON_OPERATOR_TYPE)
14440 return NULL;
14441
14442 node_data.type = EXPRESSION_OPERATOR_NODE;
14443 node_data.ID = type;
14444
14445 if (type == BINARY_OPERATOR_TYPE)
14446 node_data.subID = IS_TRUE;
14447 else
14448 node_data.subID = EQUAL_TO;
14449
14450 SetModified(TRUE);
14451
14452 return (AddNodeToTree(parent, TVI_LAST, &node_data));
14453 }
14454
14455 // Create default action statement node
14456 HTREEITEM CDallasMainDlg::CreateDefaultActionStatementNode(HTREEITEM parent) {
14457 tTreeNodeData node_data;
14458
14459 if (parent == NULL)
14460 return NULL;
14461
14462 node_data.type = ACTION_STATEMENT_NODE;
14463 node_data.ID = DO_NOTHING_ID;
14464
14465 SetModified(TRUE);
14466
14467 return (AddNodeToTree(parent, TVI_LAST, &node_data));
14468 }
14469
14470 // Create default parameter node, and assigns it an appropriate default value
14471 // based upon the parameter type
14472 HTREEITEM CDallasMainDlg::CreateDefaultParameterNode(HTREEITEM parent, HTREEITEM insert_before, int param_type,
14473 char *name, char *def_value /*=NULL*/) {
14474 tTreeNodeData node_data;
14475
14476 if (parent == NULL || insert_before == NULL || name == NULL)
14477 return NULL;
14478
14479 node_data.type = PARAMETER_NODE;
14480 node_data.ID = param_type;
14481 strcpy(node_data.name, name);
14482
14483 // Store default values
14484 switch (param_type) {
14485 case DOOR_PARAMETER_TYPE:
14486 node_data.int_val = OBJECT_HANDLE_NONE;
14487 node_data.subID = USE_OBJECT_HANDLE;
14488 strcpy(node_data.str_val, "");
14489 break;
14490 case OBJECT_PARAMETER_TYPE:
14491 if (def_value != NULL && strlen(def_value) != 0) {
14492 if (strcmp(def_value, "ME") == 0) {
14493 node_data.int_val = OBJECT_HANDLE_NONE;
14494 node_data.subID = USE_ME_HANDLE;
14495 strcpy(node_data.str_val, "");
14496 break;
14497 }
14498 if (strcmp(def_value, "IT") == 0) {
14499 node_data.int_val = OBJECT_HANDLE_NONE;
14500 node_data.subID = USE_IT_HANDLE;
14501 strcpy(node_data.str_val, "");
14502 break;
14503 }
14504 }
14505 node_data.int_val = OBJECT_HANDLE_NONE;
14506 node_data.subID = USE_OBJECT_HANDLE;
14507 strcpy(node_data.str_val, "");
14508 break;
14509 case ROOM_PARAMETER_TYPE:
14510 node_data.int_val = NOT_SPECIFIED_TYPE;
14511 strcpy(node_data.str_val, "");
14512 break;
14513 case TRIGGER_PARAMETER_TYPE:
14514 node_data.int_val = NOT_SPECIFIED_TYPE;
14515 strcpy(node_data.str_val, "");
14516 break;
14517 case INT_PARAMETER_TYPE:
14518 if (def_value == NULL || strlen(def_value) == 0)
14519 node_data.int_val = 0;
14520 else
14521 node_data.int_val = atoi(def_value);
14522 break;
14523 case BOOL_PARAMETER_TYPE:
14524 if (def_value == NULL || strlen(def_value) == 0)
14525 node_data.int_val = TRUE;
14526 else {
14527 if (stricmp(def_value, "false") == 0)
14528 node_data.int_val = FALSE;
14529 else
14530 node_data.int_val = TRUE;
14531 }
14532 break;
14533 case FLOAT_PARAMETER_TYPE:
14534 if (def_value == NULL || strlen(def_value) == 0)
14535 node_data.float_val1 = 0.0;
14536 else
14537 node_data.float_val1 = atof(def_value);
14538 break;
14539 case VECTOR_PARAMETER_TYPE:
14540 node_data.float_val1 = 0.0;
14541 node_data.float_val2 = 0.0;
14542 node_data.float_val3 = 0.0;
14543 break;
14544 case STRING_PARAMETER_TYPE:
14545 strcpy(node_data.str_val, "");
14546 break;
14547 case PERCENTAGE_PARAMETER_TYPE:
14548 if (def_value == NULL || strlen(def_value) == 0)
14549 node_data.float_val1 = 0.0;
14550 else
14551 node_data.float_val1 = atof(def_value);
14552 break;
14553 case ENUM_PARAMETER_TYPE: {
14554 if (def_value != NULL && strlen(def_value) > 0) {
14555 if (GetEnumValue(name, def_value, node_data.int_val)) {
14556 node_data.subID = USE_ENUM_VALUE;
14557 break;
14558 }
14559 }
14560
14561 int DBslot;
14562 DBslot = GetEnumID(name);
14563 node_data.subID = USE_ENUM_VALUE;
14564 if (DBslot != INVALID_ENUM && m_EnumDatabase[DBslot].num_values > 0)
14565 node_data.int_val = m_EnumDatabase[DBslot].values[0].value;
14566 else
14567 node_data.int_val = 0;
14568 } break;
14569 case SCRIPT_PARAMETER_TYPE:
14570 node_data.int_val = GetScriptID(parent);
14571 if (node_data.int_val < 0)
14572 node_data.int_val = 0;
14573 break;
14574 case SOUND_PARAMETER_TYPE:
14575 node_data.int_val = NOT_SPECIFIED_TYPE;
14576 strcpy(node_data.str_val, "");
14577 break;
14578 case SPECNAME_PARAMETER_TYPE:
14579 strcpy(node_data.str_val, "");
14580 break;
14581 case TEXTURE_PARAMETER_TYPE:
14582 node_data.int_val = NOT_SPECIFIED_TYPE;
14583 strcpy(node_data.str_val, "");
14584 break;
14585 case FLAG_PARAMETER_TYPE:
14586 if (def_value == NULL || strlen(def_value) == 0)
14587 node_data.int_val = 0;
14588 else
14589 node_data.int_val = atoi(def_value);
14590 break;
14591 case PATH_PARAMETER_TYPE:
14592 node_data.int_val = NOT_SPECIFIED_TYPE;
14593 strcpy(node_data.str_val, "");
14594 break;
14595 case MATCEN_PARAMETER_TYPE:
14596 node_data.subID = USE_MATCEN_VALUE;
14597 node_data.int_val = NOT_SPECIFIED_TYPE;
14598 strcpy(node_data.str_val, "");
14599 break;
14600 case LEVEL_GOAL_PARAMETER_TYPE:
14601 node_data.subID = USE_LEVEL_GOAL_VALUE;
14602 node_data.int_val = NOT_SPECIFIED_TYPE;
14603 strcpy(node_data.str_val, "");
14604 break;
14605 case STRM_AUDIO_PARAMETER_TYPE:
14606 strcpy(node_data.str_val, "");
14607 break;
14608 default:
14609 break;
14610 }
14611
14612 SetModified(TRUE);
14613
14614 return (AddNodeToTree(parent, insert_before, &node_data));
14615 }
14616
14617 // Creates the clipboard node and puts it into the tree
14618 HTREEITEM CDallasMainDlg::CreateDefaultClipboardNode(void) {
14619 tTreeNodeData node_data;
14620
14621 if (m_ClipboardNode != NULL) {
14622 FreeTreeItem(m_ClipboardNode);
14623 m_ClipboardNode = NULL;
14624 }
14625
14626 node_data.type = CLIPBOARD_HEADER_NODE;
14627 SetModified(TRUE);
14628
14629 m_ClipboardNode = AddNodeToTree(TVI_ROOT, TVI_LAST, &node_data);
14630 return (m_ClipboardNode);
14631 }
14632
14633 ///////////////////////////////////
14634 // Functions to Handle Copy/Paste
14635 ///////////////////////////////////
14636
14637 // Copies the selected script into the clipboard
14638 void CDallasMainDlg::PerformScriptCopy(void) {
14639 HTREEITEM selected_node;
14640 HTREEITEM script_header_node;
14641 HTREEITEM new_script_node;
14642
14643 // Make sure we have a clipboard
14644 if (m_ClipboardNode == NULL)
14645 return;
14646
14647 // Get the selected tree node
14648 selected_node = m_ScriptTree.GetSelectedItem();
14649 if (selected_node == NULL)
14650 return;
14651
14652 // If it's a conditional statement node, let it be the header
14653 if (GetNodeType(selected_node) == CONDITIONAL_STATEMENT_NODE) {
14654 PerformConditionalCopy(selected_node);
14655 return;
14656 }
14657
14658 // If it's a logical operator node, let it be the header
14659 if (GetNodeType(selected_node) == LOGICAL_OPERATOR_NODE) {
14660 PerformLogOpCopy(selected_node);
14661 return;
14662 }
14663
14664 // If it's an action node, let it be the header
14665 if (GetNodeType(selected_node) == ACTION_STATEMENT_NODE) {
14666 PerformActionCopy(selected_node);
14667 return;
14668 }
14669
14670 // If it's a nested IF clause, let it be the header
14671 if (NodeIsIfClause(selected_node)) {
14672 PerformClauseCopy(selected_node);
14673 return;
14674 }
14675
14676 // If it's not a script header node, then it can't be copied
14677 if (GetNodeType(selected_node) != SCRIPT_HEADER_NODE) {
14678 MessageBox("Copy/Paste is not supported for the currently selected script item.", "Invalid Copy/Paste", MB_OK);
14679 return;
14680 }
14681
14682 // Get the script header node
14683 script_header_node = GetParentNodeOfType(selected_node, SCRIPT_HEADER_NODE);
14684 if (script_header_node == NULL)
14685 return;
14686
14687 // If the script header has a parent, then it must be a clipboard node
14688 if (m_ScriptTree.GetParentItem(script_header_node) != NULL)
14689 return;
14690
14691 // If the clipboard, has a script already, kill the old one
14692 FreeTreeItemChildren(m_ClipboardNode);
14693
14694 // Now copy the script over to the clipboard
14695 new_script_node = CopyTree(m_ClipboardNode, TVI_LAST, script_header_node);
14696 if (new_script_node != NULL) {
14697 UpdateAllParentNodesText(new_script_node);
14698 m_ScriptTree.Expand(m_ClipboardNode, TVE_COLLAPSE);
14699 }
14700 }
14701
14702 // Copies the selected script action into the clipboard
14703 void CDallasMainDlg::PerformActionCopy(HTREEITEM action_node) {
14704 HTREEITEM script_header_node;
14705 HTREEITEM new_script_node;
14706
14707 // Make sure we have a clipboard
14708 if (m_ClipboardNode == NULL)
14709 return;
14710
14711 // Get the selected tree node
14712 if (action_node == NULL)
14713 return;
14714
14715 // If it's an action node, let it be the header
14716 if (GetNodeType(action_node) != ACTION_STATEMENT_NODE)
14717 return;
14718
14719 // Get the script header node
14720 script_header_node = GetParentNodeOfType(action_node, SCRIPT_HEADER_NODE);
14721 if (script_header_node == NULL)
14722 return;
14723
14724 // If the script header has a parent, then it must be a clipboard node
14725 if (m_ScriptTree.GetParentItem(script_header_node) != NULL)
14726 return;
14727
14728 // If the clipboard, has a script already, kill the old one
14729 FreeTreeItemChildren(m_ClipboardNode);
14730
14731 // Now copy the action over to the clipboard
14732 new_script_node = CopyTree(m_ClipboardNode, TVI_LAST, action_node);
14733 if (new_script_node != NULL) {
14734 UpdateAllParentNodesText(new_script_node);
14735 m_ScriptTree.Expand(m_ClipboardNode, TVE_COLLAPSE);
14736 }
14737 }
14738
14739 // Copies the selected script conditional statement into the clipboard
14740 void CDallasMainDlg::PerformConditionalCopy(HTREEITEM conditional_node) {
14741 HTREEITEM script_header_node;
14742 HTREEITEM new_script_node;
14743
14744 // Make sure we have a clipboard
14745 if (m_ClipboardNode == NULL)
14746 return;
14747
14748 // Get the selected tree node
14749 if (conditional_node == NULL)
14750 return;
14751
14752 // If it's an action node, let it be the header
14753 if (GetNodeType(conditional_node) != CONDITIONAL_STATEMENT_NODE)
14754 return;
14755
14756 // Get the script header node
14757 script_header_node = GetParentNodeOfType(conditional_node, SCRIPT_HEADER_NODE);
14758 if (script_header_node == NULL)
14759 return;
14760
14761 // If the script header has a parent, then it must be a clipboard node
14762 if (m_ScriptTree.GetParentItem(script_header_node) != NULL)
14763 return;
14764
14765 // If the clipboard, has a script already, kill the old one
14766 FreeTreeItemChildren(m_ClipboardNode);
14767
14768 // Now copy the conditional statement over to the clipboard
14769 new_script_node = CopyTree(m_ClipboardNode, TVI_LAST, conditional_node);
14770 if (new_script_node != NULL) {
14771 UpdateAllParentNodesText(new_script_node);
14772 m_ScriptTree.Expand(m_ClipboardNode, TVE_COLLAPSE);
14773 }
14774 }
14775
14776 // Copies the selected script logical operator into the clipboard
14777 void CDallasMainDlg::PerformLogOpCopy(HTREEITEM logop_node) {
14778 HTREEITEM script_header_node;
14779 HTREEITEM new_script_node;
14780
14781 // Make sure we have a clipboard
14782 if (m_ClipboardNode == NULL)
14783 return;
14784
14785 // Get the selected tree node
14786 if (logop_node == NULL)
14787 return;
14788
14789 // If it's a logop node, let it be the header
14790 if (GetNodeType(logop_node) != LOGICAL_OPERATOR_NODE)
14791 return;
14792
14793 // Get the script header node
14794 script_header_node = GetParentNodeOfType(logop_node, SCRIPT_HEADER_NODE);
14795 if (script_header_node == NULL)
14796 return;
14797
14798 // If the script header has a parent, then it must be a clipboard node
14799 if (m_ScriptTree.GetParentItem(script_header_node) != NULL)
14800 return;
14801
14802 // If the clipboard, has a script already, kill the old one
14803 FreeTreeItemChildren(m_ClipboardNode);
14804
14805 // Now copy the logical operator over to the clipboard
14806 new_script_node = CopyTree(m_ClipboardNode, TVI_LAST, logop_node);
14807 if (new_script_node != NULL) {
14808 UpdateAllParentNodesText(new_script_node);
14809 m_ScriptTree.Expand(m_ClipboardNode, TVE_COLLAPSE);
14810 }
14811 }
14812
14813 // Copies the selected script if-then-else clause into the clipboard
14814 void CDallasMainDlg::PerformClauseCopy(HTREEITEM clause_node) {
14815 HTREEITEM script_header_node;
14816 HTREEITEM new_script_node;
14817 HTREEITEM if_node, then_node, else_node;
14818
14819 // Make sure we have a clipboard
14820 if (m_ClipboardNode == NULL)
14821 return;
14822
14823 // Get the selected tree node
14824 if (clause_node == NULL)
14825 return;
14826
14827 // Make sure it's an IF header
14828 if (!NodeIsIfClause(clause_node))
14829 return;
14830
14831 // Get the script header node
14832 script_header_node = GetParentNodeOfType(clause_node, SCRIPT_HEADER_NODE);
14833 if (script_header_node == NULL)
14834 return;
14835
14836 // If the script header has a parent, then it must be a clipboard node
14837 if (m_ScriptTree.GetParentItem(script_header_node) != NULL)
14838 return;
14839
14840 // Get the then clause node
14841 if_node = clause_node;
14842 then_node = m_ScriptTree.GetNextSiblingItem(if_node);
14843 if (!NodeIsClauseOfType(then_node, THEN_CLAUSE))
14844 return;
14845
14846 // Get the else clause node
14847 else_node = m_ScriptTree.GetNextSiblingItem(then_node);
14848 if (!NodeIsClauseOfType(else_node, ELSE_CLAUSE))
14849 else_node = NULL;
14850
14851 // If the clipboard, has a script already, kill the old one
14852 FreeTreeItemChildren(m_ClipboardNode);
14853
14854 // Now copy the IF clause over to the clipboard
14855 new_script_node = CopyTree(m_ClipboardNode, TVI_LAST, if_node);
14856 if (new_script_node != NULL) {
14857 UpdateAllParentNodesText(new_script_node);
14858 m_ScriptTree.Expand(m_ClipboardNode, TVE_COLLAPSE);
14859 }
14860
14861 // Now copy the THEN clause over to the clipboard
14862 new_script_node = CopyTree(m_ClipboardNode, TVI_LAST, then_node);
14863 if (new_script_node != NULL) {
14864 UpdateAllParentNodesText(new_script_node);
14865 m_ScriptTree.Expand(m_ClipboardNode, TVE_COLLAPSE);
14866 }
14867
14868 // Now copy the ELSE clause over (if one exists)
14869 if (else_node != NULL) {
14870 new_script_node = CopyTree(m_ClipboardNode, TVI_LAST, else_node);
14871 if (new_script_node != NULL) {
14872 UpdateAllParentNodesText(new_script_node);
14873 m_ScriptTree.Expand(m_ClipboardNode, TVE_COLLAPSE);
14874 }
14875 }
14876 }
14877
14878 // Inserts the clipboard script before the selected script (or clipboard)
14879 void CDallasMainDlg::PerformScriptPaste(void) {
14880 HTREEITEM selected_node;
14881 HTREEITEM src_script_header_node;
14882 HTREEITEM dest_insert_before;
14883 HTREEITEM new_script_header;
14884
14885 // Make sure we have a clipboard
14886 if (m_ClipboardNode == NULL)
14887 return;
14888
14889 // Get the clipboard child script
14890 src_script_header_node = m_ScriptTree.GetChildItem(m_ClipboardNode);
14891 if (src_script_header_node == NULL)
14892 return;
14893
14894 // See if the clipboard has a conditional statement
14895 if (GetNodeType(src_script_header_node) == CONDITIONAL_STATEMENT_NODE) {
14896 PerformConditionalPaste(src_script_header_node);
14897 return;
14898 }
14899
14900 // See if the clipboard has a logical operator
14901 if (GetNodeType(src_script_header_node) == LOGICAL_OPERATOR_NODE) {
14902 PerformLogOpPaste(src_script_header_node);
14903 return;
14904 }
14905
14906 // See if the clipboard has an action
14907 if (GetNodeType(src_script_header_node) == ACTION_STATEMENT_NODE) {
14908 PerformActionPaste(src_script_header_node);
14909 return;
14910 }
14911
14912 // See if the clipboard has an IF clause
14913 if (NodeIsIfClause(src_script_header_node)) {
14914 PerformClausePaste(src_script_header_node);
14915 return;
14916 }
14917
14918 // If the clipboard doesn't have a script header, get outta here
14919 if (GetNodeType(src_script_header_node) != SCRIPT_HEADER_NODE)
14920 return;
14921
14922 // Get the selected tree node
14923 selected_node = m_ScriptTree.GetSelectedItem();
14924 if (selected_node == NULL)
14925 return;
14926
14927 if (selected_node == m_ClipboardNode)
14928 dest_insert_before = m_ClipboardNode;
14929 else {
14930 dest_insert_before = GetParentNodeOfType(selected_node, SCRIPT_HEADER_NODE);
14931 if (dest_insert_before == NULL)
14932 return;
14933
14934 // If the script header has a parent, then it must be a clipboard node
14935 if (m_ScriptTree.GetParentItem(dest_insert_before) != NULL)
14936 dest_insert_before = m_ClipboardNode;
14937 }
14938
14939 // Now copy the script over to the clipboard
14940 new_script_header = CopyTree(TVI_ROOT, dest_insert_before, src_script_header_node);
14941 if (new_script_header == NULL)
14942 return;
14943
14944 // Change the script ID for the new node
14945 tTreeNodeData *data = (tTreeNodeData *)m_ScriptTree.GetItemData(new_script_header);
14946 if (data == NULL)
14947 return;
14948
14949 int new_id = GetLowestUnusedScriptID();
14950 data->ID = new_id;
14951 UpdateNodeText(new_script_header);
14952 HighlightScript(new_script_header);
14953
14954 if (new_id == m_NextScriptID)
14955 m_NextScriptID++;
14956
14957 m_ScriptTree.SelectItem(new_script_header);
14958 AssignSpecificValue();
14959 SetModified(TRUE);
14960 }
14961
14962 // Inserts the clipboard action before the selected node (or to end of children)
14963 void CDallasMainDlg::PerformActionPaste(HTREEITEM src_action_node) {
14964 HTREEITEM selected_node;
14965 HTREEITEM new_action_node;
14966 tTreeNodeData *data;
14967
14968 // Make sure we have a clipboard
14969 if (m_ClipboardNode == NULL)
14970 return;
14971
14972 // See if the clipboard has an action
14973 if (GetNodeType(src_action_node) != ACTION_STATEMENT_NODE)
14974 return;
14975
14976 // Get the selected tree node
14977 selected_node = m_ScriptTree.GetSelectedItem();
14978 if (selected_node == NULL)
14979 return;
14980
14981 // Make sure it's not the same node!
14982 if (selected_node == src_action_node)
14983 return;
14984
14985 // Make sure it's not in the clipboard
14986 if (NodeIsInClipboard(selected_node))
14987 return;
14988
14989 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
14990 if (data == NULL)
14991 return;
14992
14993 if (data->type == ACTION_STATEMENT_NODE || (data->type == CONDITIONAL_HEADER_NODE && data->ID == NESTED))
14994 new_action_node = CopyTree(m_ScriptTree.GetParentItem(selected_node), selected_node, src_action_node);
14995 else if (data->type == ACTIONS_HEADER_NODE) {
14996 new_action_node = CopyTree(selected_node, TVI_LAST, src_action_node);
14997 } else {
14998 return;
14999 }
15000
15001 // Now copy the script over to the clipboard
15002 if (new_action_node == NULL)
15003 return;
15004
15005 UpdateAllParentNodesText(new_action_node);
15006 SetModified(TRUE);
15007 }
15008
15009 // Replaces selected node with the clipboard conditional statement
15010 void CDallasMainDlg::PerformConditionalPaste(HTREEITEM src_conditional_node) {
15011 HTREEITEM selected_node;
15012 HTREEITEM new_conditional_node;
15013 HTREEITEM parent;
15014 tTreeNodeData *data;
15015
15016 // Make sure we have a clipboard
15017 if (m_ClipboardNode == NULL)
15018 return;
15019
15020 // See if the clipboard has a conditional statement
15021 if (GetNodeType(src_conditional_node) != CONDITIONAL_STATEMENT_NODE)
15022 return;
15023
15024 // Get the selected tree node
15025 selected_node = m_ScriptTree.GetSelectedItem();
15026 if (selected_node == NULL)
15027 return;
15028
15029 // Make sure it's not the same node!
15030 if (selected_node == src_conditional_node)
15031 return;
15032
15033 // Make sure it's not in the clipboard
15034 if (NodeIsInClipboard(selected_node))
15035 return;
15036
15037 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
15038 if (data == NULL)
15039 return;
15040
15041 if (data->type == CONDITIONAL_STATEMENT_NODE || data->type == LOGICAL_OPERATOR_NODE) {
15042 new_conditional_node = CopyTree(m_ScriptTree.GetParentItem(selected_node), selected_node, src_conditional_node);
15043 m_ScriptTree.SelectItem(new_conditional_node);
15044
15045 // Delete the old conditional
15046 parent = m_ScriptTree.GetParentItem(selected_node);
15047 FreeTreeItem(selected_node);
15048
15049 ConfirmAfterDelete(parent);
15050 SetModified(TRUE);
15051 } else {
15052 return;
15053 }
15054
15055 // Now copy the script over to the clipboard
15056 if (new_conditional_node == NULL)
15057 return;
15058
15059 UpdateAllParentNodesText(new_conditional_node);
15060 }
15061
15062 // Replaces selected node with the clipboard logical operator node
15063 void CDallasMainDlg::PerformLogOpPaste(HTREEITEM src_logop_node) {
15064 HTREEITEM selected_node;
15065 HTREEITEM new_logop_node;
15066 HTREEITEM parent;
15067 tTreeNodeData *data;
15068
15069 // Make sure we have a clipboard
15070 if (m_ClipboardNode == NULL)
15071 return;
15072
15073 // See if the clipboard has a logical operator
15074 if (GetNodeType(src_logop_node) != LOGICAL_OPERATOR_NODE)
15075 return;
15076
15077 // Get the selected tree node
15078 selected_node = m_ScriptTree.GetSelectedItem();
15079 if (selected_node == NULL)
15080 return;
15081
15082 // Make sure it's not the same node!
15083 if (selected_node == src_logop_node)
15084 return;
15085
15086 // Make sure it's not in the clipboard
15087 if (NodeIsInClipboard(selected_node))
15088 return;
15089
15090 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
15091 if (data == NULL)
15092 return;
15093
15094 if (data->type == CONDITIONAL_STATEMENT_NODE || data->type == LOGICAL_OPERATOR_NODE) {
15095 new_logop_node = CopyTree(m_ScriptTree.GetParentItem(selected_node), selected_node, src_logop_node);
15096 m_ScriptTree.SelectItem(new_logop_node);
15097
15098 // Delete the old conditional
15099 parent = m_ScriptTree.GetParentItem(selected_node);
15100 FreeTreeItem(selected_node);
15101
15102 ConfirmAfterDelete(parent);
15103 SetModified(TRUE);
15104 } else {
15105 return;
15106 }
15107
15108 // Now copy the script over to the clipboard
15109 if (new_logop_node == NULL)
15110 return;
15111
15112 UpdateAllParentNodesText(new_logop_node);
15113 }
15114
15115 // Inserts the clipboard action before the selected node (or to end of children)
15116 void CDallasMainDlg::PerformClausePaste(HTREEITEM src_clause_node) {
15117 HTREEITEM selected_node;
15118 HTREEITEM new_clause_node;
15119 HTREEITEM if_node, then_node, else_node;
15120 tTreeNodeData *data;
15121
15122 // Make sure we have a clipboard
15123 if (m_ClipboardNode == NULL)
15124 return;
15125
15126 // See if the clipboard has an IF clause
15127 if (!NodeIsIfClause(src_clause_node))
15128 return;
15129
15130 // Get the then clause node
15131 if_node = src_clause_node;
15132 then_node = m_ScriptTree.GetNextSiblingItem(if_node);
15133 if (!NodeIsClauseOfType(then_node, THEN_CLAUSE))
15134 return;
15135
15136 // Get the else clause node
15137 else_node = m_ScriptTree.GetNextSiblingItem(then_node);
15138 if (!NodeIsClauseOfType(else_node, ELSE_CLAUSE))
15139 else_node = NULL;
15140
15141 // Get the selected tree node
15142 selected_node = m_ScriptTree.GetSelectedItem();
15143 if (selected_node == NULL)
15144 return;
15145
15146 // Make sure it's not the same node!
15147 if (selected_node == src_clause_node)
15148 return;
15149
15150 // Make sure it's not in the clipboard
15151 if (NodeIsInClipboard(selected_node))
15152 return;
15153
15154 data = (tTreeNodeData *)m_ScriptTree.GetItemData(selected_node);
15155 if (data == NULL)
15156 return;
15157
15158 if (data->type == ACTION_STATEMENT_NODE || (data->type == CONDITIONAL_HEADER_NODE && data->ID == NESTED)) {
15159 // Copy over IF clause
15160 new_clause_node = CopyTree(m_ScriptTree.GetParentItem(selected_node), selected_node, if_node);
15161 UpdateAllParentNodesText(new_clause_node);
15162
15163 // Copy over THEN clause
15164 new_clause_node = CopyTree(m_ScriptTree.GetParentItem(selected_node), selected_node, then_node);
15165 UpdateAllParentNodesText(new_clause_node);
15166
15167 // Copy over ELSE clause (if one exists)
15168 if (else_node != NULL) {
15169 new_clause_node = CopyTree(m_ScriptTree.GetParentItem(selected_node), selected_node, else_node);
15170 UpdateAllParentNodesText(new_clause_node);
15171 }
15172 } else if (data->type == ACTIONS_HEADER_NODE) {
15173 // Copy over IF clause
15174 new_clause_node = CopyTree(selected_node, TVI_LAST, if_node);
15175 UpdateAllParentNodesText(new_clause_node);
15176
15177 // Copy over THEN clause
15178 new_clause_node = CopyTree(selected_node, TVI_LAST, then_node);
15179 UpdateAllParentNodesText(new_clause_node);
15180
15181 // Copy over ELSE clause (if one exists)
15182 if (else_node != NULL) {
15183 new_clause_node = CopyTree(selected_node, TVI_LAST, else_node);
15184 UpdateAllParentNodesText(new_clause_node);
15185 }
15186 } else {
15187 return;
15188 }
15189
15190 // Now copy the script over to the clipboard
15191 if (new_clause_node == NULL)
15192 return;
15193
15194 SetModified(TRUE);
15195 }
15196
15197 // Checks to see if the given node is a child of the clipboard header
15198 bool CDallasMainDlg::NodeIsInClipboard(HTREEITEM node) {
15199 HTREEITEM parent;
15200
15201 parent = GetParentNodeOfType(node, CLIPBOARD_HEADER_NODE);
15202
15203 if (parent == NULL)
15204 return FALSE;
15205 else
15206 return TRUE;
15207 }
15208
15209 ///////////////////////////////////////////////
15210 // Functions to search tree and replace values
15211 ///////////////////////////////////////////////
15212
15213 // Goes through the tree, and changes old messageID's to the new one
15214 int CDallasMainDlg::UpdateStringParams(HTREEITEM root, char *old_name, char *new_name) {
15215 HTREEITEM child;
15216 tTreeNodeData *data;
15217 int num_changed;
15218
15219 if (root == NULL)
15220 return 0;
15221
15222 // Process the children
15223 num_changed = 0;
15224 child = m_ScriptTree.GetChildItem(root);
15225 while (child != NULL) {
15226 num_changed += UpdateStringParams(child, old_name, new_name);
15227
15228 // Check this child to see if it's a string parameter in need of updating
15229 data = (tTreeNodeData *)m_ScriptTree.GetItemData(child);
15230 if (data != NULL && data->type == PARAMETER_NODE && data->ID == STRING_PARAMETER_TYPE) {
15231 if (strcmp(data->str_val, old_name) == 0) {
15232 strcpy(data->str_val, new_name);
15233 UpdateAllParentNodesText(child);
15234 num_changed++;
15235 }
15236 }
15237
15238 // Get the next child
15239 child = m_ScriptTree.GetNextSiblingItem(child);
15240 }
15241
15242 if (num_changed > 0)
15243 SetModified(TRUE);
15244
15245 return (num_changed);
15246 }
15247
15248 ///////////////////////////////////////////////////////////////////
15249 // Functions to Handle Script Drag-n-Drop
15250 ///////////////////////////////////////////////////////////////////
15251
15252 bool CDallasMainDlg::IsDropSource(HTREEITEM item) {
15253 if (item == NULL)
15254 return FALSE;
15255
15256 // See if it's an action node
15257 if (GetNodeType(item) == ACTION_STATEMENT_NODE) {
15258 HTREEITEM parent;
15259
15260 // Make sure it's not in the clipboard
15261 parent = GetParentNodeOfType(item, SCRIPT_HEADER_NODE);
15262 if (parent == NULL)
15263 return FALSE;
15264
15265 if (m_ScriptTree.GetParentItem(parent) != NULL)
15266 return FALSE;
15267
15268 return TRUE;
15269 }
15270
15271 // Make sure it's a script header node
15272 if (GetNodeType(item) != SCRIPT_HEADER_NODE)
15273 return FALSE;
15274
15275 // Make sure it's not in the Clipboard
15276 if (m_ScriptTree.GetParentItem(item) != NULL)
15277 return FALSE;
15278
15279 return TRUE;
15280 }
15281
15282 HTREEITEM CDallasMainDlg::GetDropTarget(HTREEITEM item) {
15283 HTREEITEM target_item, parent_item;
15284
15285 if (item == NULL || m_hitemDrag == NULL)
15286 return NULL;
15287
15288 // See if the dragged node is an action
15289 if (GetNodeType(m_hitemDrag) == ACTION_STATEMENT_NODE) {
15290 tTreeNodeData *data;
15291 HTREEITEM parent;
15292
15293 // Make sure it's not in the clipboard
15294 parent = GetParentNodeOfType(item, SCRIPT_HEADER_NODE);
15295 if (parent == NULL)
15296 return NULL;
15297
15298 if (m_ScriptTree.GetParentItem(parent) != NULL)
15299 return NULL;
15300
15301 // Make sure it's a valid drop node
15302 data = (tTreeNodeData *)m_ScriptTree.GetItemData(item);
15303 if (data == NULL)
15304 return NULL;
15305
15306 if (data->type == ACTION_STATEMENT_NODE || (data->type == CONDITIONAL_HEADER_NODE && data->ID == NESTED))
15307 return (item);
15308
15309 if (data->type == ACTIONS_HEADER_NODE)
15310 return (item);
15311
15312 return NULL;
15313 }
15314
15315 // See if it's the clipboard
15316 if (GetNodeType(item) == CLIPBOARD_HEADER_NODE)
15317 return (item);
15318
15319 // Get the script header for the selected node
15320 target_item = GetParentNodeOfType(item, SCRIPT_HEADER_NODE);
15321 if (target_item == NULL)
15322 return NULL;
15323
15324 parent_item = m_ScriptTree.GetParentItem(target_item);
15325 if (m_ScriptTree.GetParentItem(target_item) == NULL)
15326 return (target_item);
15327
15328 if (GetNodeType(parent_item) == CLIPBOARD_HEADER_NODE)
15329 return (parent_item);
15330
15331 return NULL;
15332 }
15333
15334 void CDallasMainDlg::OnBegindragEventTree(NMHDR *pNMHDR, LRESULT *pResult) {
15335 NM_TREEVIEW *pNMTreeView = (NM_TREEVIEW *)pNMHDR;
15336
15337 m_hitemDrag = pNMTreeView->itemNew.hItem;
15338 m_hitemDrop = NULL;
15339 m_ScriptTree.SelectItem(m_hitemDrag);
15340
15341 if (!IsDropSource(m_hitemDrag))
15342 return;
15343
15344 // get the image list for dragging
15345 m_pDragImage = m_ScriptTree.CreateDragImage(m_hitemDrag);
15346
15347 // CreateDragImage() returns NULL if no image list
15348 // associated with the tree view control
15349 if (!m_pDragImage)
15350 return;
15351
15352 m_bLDragging = TRUE;
15353 m_pDragImage->BeginDrag(0, CPoint(0, 0));
15354 POINT pt = pNMTreeView->ptDrag;
15355 m_ScriptTree.ClientToScreen(&pt);
15356 m_pDragImage->DragEnter(NULL, pt);
15357 SetCapture();
15358
15359 *pResult = 0;
15360 }
15361
15362 void CDallasMainDlg::OnMouseMove(UINT nFlags, CPoint point) {
15363 HTREEITEM hitem;
15364 UINT flags;
15365
15366 if (m_bLDragging) {
15367 POINT pt = point;
15368 ClientToScreen(&pt);
15369 POINT tree_pt = pt;
15370 m_ScriptTree.ScreenToClient(&tree_pt);
15371 CImageList::DragMove(pt);
15372 if ((hitem = m_ScriptTree.HitTest(tree_pt, &flags)) != NULL) {
15373 CImageList::DragShowNolock(FALSE);
15374 m_hitemDrop = GetDropTarget(hitem);
15375 m_ScriptTree.SelectDropTarget(m_hitemDrop);
15376 CImageList::DragShowNolock(TRUE);
15377 } else {
15378 CImageList::DragShowNolock(FALSE);
15379 m_hitemDrop = NULL;
15380 m_ScriptTree.SelectDropTarget(m_hitemDrop);
15381 CImageList::DragShowNolock(TRUE);
15382 }
15383 }
15384
15385 CDialog::OnMouseMove(nFlags, point);
15386 }
15387
15388 void CDallasMainDlg::OnLButtonUp(UINT nFlags, CPoint point) {
15389 if (m_bLDragging) {
15390 m_bLDragging = FALSE;
15391 CImageList::DragLeave(this);
15392 CImageList::EndDrag();
15393 ReleaseCapture();
15394 delete m_pDragImage;
15395
15396 // Remove drop target highlighting
15397 m_ScriptTree.SelectDropTarget(NULL);
15398
15399 if ((m_hitemDrag == m_hitemDrop) || m_hitemDrop == NULL)
15400 return;
15401
15402 // See if the dragged node is an action
15403 if (GetNodeType(m_hitemDrag) == ACTION_STATEMENT_NODE) {
15404 HTREEITEM new_action_node, parent;
15405 tTreeNodeData *data;
15406
15407 data = (tTreeNodeData *)m_ScriptTree.GetItemData(m_hitemDrop);
15408 if (data == NULL)
15409 return;
15410
15411 if (data->type == ACTION_STATEMENT_NODE || (data->type == CONDITIONAL_HEADER_NODE && data->ID == NESTED))
15412 new_action_node = CopyTree(m_ScriptTree.GetParentItem(m_hitemDrop), m_hitemDrop, m_hitemDrag);
15413 else if (data->type == ACTIONS_HEADER_NODE) {
15414 new_action_node = CopyTree(m_hitemDrop, TVI_LAST, m_hitemDrag);
15415 }
15416
15417 if (new_action_node == NULL)
15418 return;
15419 UpdateAllParentNodesText(new_action_node);
15420 m_ScriptTree.SelectItem(new_action_node);
15421
15422 // Delete the old action
15423 parent = m_ScriptTree.GetParentItem(m_hitemDrag);
15424 FreeTreeItem(m_hitemDrag);
15425
15426 ConfirmAfterDelete(parent);
15427 SetModified(TRUE);
15428
15429 return;
15430 }
15431
15432 // Copy the tree to its new location (and select it)
15433 HTREEITEM new_script_header = CopyTree(TVI_ROOT, m_hitemDrop, m_hitemDrag);
15434 if (new_script_header == NULL)
15435 return;
15436 UpdateAllParentNodesText(new_script_header);
15437 m_ScriptTree.SelectItem(new_script_header);
15438
15439 // Delete the old tree
15440 FreeTreeItem(m_hitemDrag);
15441 SetModified(TRUE);
15442 }
15443
15444 CDialog::OnLButtonUp(nFlags, point);
15445 }
15446
15447 ///////////////////////////////////////////////////////////////////
15448 // Functions to Handle Highlight Interface
15449 ///////////////////////////////////////////////////////////////////
15450
15451 void CDallasMainDlg::ClearHighlightRadioButtons(void) {
15452 ((CButton *)GetDlgItem(IDC_NONE_RADIO))->SetCheck(0);
15453 ((CButton *)GetDlgItem(IDC_SPECIFIC_RADIO))->SetCheck(0);
15454 ((CButton *)GetDlgItem(IDC_LEVEL_RADIO))->SetCheck(0);
15455 ((CButton *)GetDlgItem(IDC_ALLOBJ_RADIO))->SetCheck(0);
15456 ((CButton *)GetDlgItem(IDC_ALLTRIG_RADIO))->SetCheck(0);
15457 }
15458
15459 void CDallasMainDlg::FillHighlightEventList(void) {
15460 int i, index;
15461
15462 m_EventList.ResetContent();
15463
15464 // Add the "all events" type
15465 index = m_EventList.AddString("All Event Types");
15466 if (index != LB_ERR) {
15467 m_EventList.SetItemData(index, ALL_EVENT_TYPES);
15468 }
15469
15470 // Fill the list with the event types
15471 for (i = 0; event_info[i].type >= 0; i++) {
15472 index = m_EventList.AddString(event_info[i].name);
15473 if (index != LB_ERR) {
15474 m_EventList.SetItemData(index, event_info[i].type);
15475 }
15476 }
15477
15478 SetHighlightedEvent(ALL_EVENT_TYPES);
15479 }
15480
15481 int CDallasMainDlg::GetHighlightedEvent(void) {
15482 int index = m_EventList.GetCurSel();
15483 if (index == LB_ERR)
15484 return ALL_EVENT_TYPES;
15485
15486 return (m_EventList.GetItemData(index));
15487 }
15488
15489 void CDallasMainDlg::SetHighlightedEvent(int type) {
15490 int index, total;
15491
15492 total = m_EventList.GetCount();
15493 for (index = 0; index < total; index++) {
15494 int data = m_EventList.GetItemData(index);
15495 if (data == type) {
15496 m_EventList.SetCurSel(index);
15497 break;
15498 }
15499 }
15500 }
15501
15502 void CDallasMainDlg::OnAllobjRadio() {
15503 m_ScriptOwnerType = ALL_OBJECTS_TYPE;
15504 m_ScriptOwnerHandle = 0;
15505 // SetHighlightedEvent(ALL_EVENT_TYPES);
15506
15507 HighlightAllScripts();
15508 }
15509
15510 void CDallasMainDlg::OnAlltrigRadio() {
15511 m_ScriptOwnerType = ALL_TRIGGERS_TYPE;
15512 m_ScriptOwnerHandle = 0;
15513
15514 HighlightAllScripts();
15515 }
15516
15517 void CDallasMainDlg::OnNoneRadio() {
15518 m_ScriptOwnerType = NONE_TYPE;
15519 m_ScriptOwnerHandle = 0;
15520
15521 HighlightAllScripts();
15522 }
15523
15524 void CDallasMainDlg::OnSpecificRadio() { OnHighlightButton(); }
15525
15526 void CDallasMainDlg::OnLevelRadio() {
15527 m_ScriptOwnerType = LEVEL_TYPE;
15528 m_ScriptOwnerHandle = 0;
15529
15530 HighlightAllScripts();
15531 }
15532
15533 void CDallasMainDlg::OnEventRadio() {
15534 m_ScriptOwnerType = ALL_OWNERS_TYPE;
15535 m_ScriptOwnerHandle = 0;
15536
15537 HighlightAllScripts();
15538 }
15539
15540 void CDallasMainDlg::OnSelchangeEventCombo() { HighlightAllScripts(); }
15541
15542 ///////////////////////////////////////////////////////////////////
15543 // Functions to Handle Import/Export
15544 ///////////////////////////////////////////////////////////////////
15545
15546 // Display a script library file selection dialog
15547 bool CDallasMainDlg::ScriptLibraryFilePrompt(CString &filename, bool use_import_msg) {
15548 static CString last_path = "";
15549 CString filter;
15550 char *default_fname;
15551 CString title;
15552 bool dlg_type;
15553
15554 if (use_import_msg) {
15555 title = "Import Script from what Library File?";
15556 dlg_type = TRUE;
15557 } else {
15558 title = "Export Script to what Library File?";
15559 dlg_type = FALSE;
15560 }
15561
15562 if (last_path.IsEmpty())
15563 default_fname = NULL;
15564 else
15565 default_fname = last_path.GetBuffer(0);
15566
15567 filename = "";
15568 filter = "Dallas Script Library Files (*.dsl)|*.dsl|All Files (*.*)|*.*||";
15569 CFileDialog dlg_open(dlg_type, NULL, default_fname, OFN_FILEMUSTEXIST, (LPCTSTR)filter, this);
15570 dlg_open.m_ofn.lpstrTitle = title.GetBuffer(0);
15571 if (dlg_open.DoModal() == IDCANCEL) {
15572 return FALSE;
15573 }
15574
15575 filename = dlg_open.GetPathName();
15576 if (filename.Find('.') < 0)
15577 filename += ".dsl";
15578 last_path = filename;
15579
15580 return TRUE;
15581 }
15582
15583 // Scans given .dsl file for given name, and imports it
15584 bool CDallasMainDlg::ImportScriptFromFile(char *filename, char *script_name) {
15585 CFILE *infile;
15586 char linebuf[2048];
15587 char tempbuf[256];
15588 char *line;
15589 int linenum;
15590 int valid_lines_read, version;
15591 int rc;
15592
15593 HTREEITEM last_node_added, current_parent, insert_before, returned_node;
15594 HTREEITEM selected_node, initial_insert_before, new_script_header;
15595 bool skip_children;
15596 int skip_depth;
15597 bool last_node_childless;
15598 bool ScriptToImportFound;
15599
15600 // Determine the initial insert before script header node
15601 selected_node = m_ScriptTree.GetSelectedItem();
15602 if (selected_node == NULL)
15603 return FALSE;
15604 if (GetNodeType(selected_node) == CLIPBOARD_HEADER_NODE)
15605 initial_insert_before = selected_node;
15606 else {
15607 initial_insert_before = GetParentNodeOfType(selected_node, SCRIPT_HEADER_NODE);
15608 if (initial_insert_before == NULL)
15609 return FALSE;
15610 if (m_ScriptTree.GetParentItem(initial_insert_before) != NULL)
15611 return FALSE;
15612 }
15613
15614 CurrentParsingFilename = filename;
15615 new_script_header = NULL;
15616
15617 // Try to open the file for loading
15618 infile = cfopen(filename, "rt");
15619 if (!infile) {
15620 CString msg;
15621 msg.Format("Unable to open \"%s\"!", filename);
15622 MessageBox(msg, "Script Library File Not Found!", MB_OK | MB_ICONEXCLAMATION);
15623
15624 return FALSE;
15625 }
15626
15627 linenum = 0;
15628 ScriptToImportFound = FALSE;
15629
15630 // Read in and parse each line of the file
15631 while (!cfeof(infile) && !ScriptToImportFound) {
15632
15633 // Clear the buffer
15634 strcpy(linebuf, "");
15635
15636 // Read in a line from the file
15637 cf_ReadString(linebuf, sizeof(linebuf), infile);
15638 linenum++;
15639
15640 // Remove whitespace padding at start and end of line
15641 RemoveTrailingWhitespace(linebuf);
15642 line = SkipInitialWhitespace(linebuf);
15643
15644 // Check for Start of Script Block Section
15645 if (strncmp(line, SCRIPT_START_TAG, strlen(SCRIPT_START_TAG)) == 0) {
15646 bool done = false;
15647
15648 // Clear out the name lists
15649 ClearNameLists();
15650
15651 // Set valid line counter to track whether we're reading header info or tree nodes
15652 valid_lines_read = 0;
15653
15654 // Set tree node trackers so we know where we are in the actual tree
15655 last_node_added = NULL;
15656 current_parent = TVI_ROOT;
15657
15658 // Set variables that allow child nodes to be skipped over
15659 // when a bad Action or Query node is read in (invalid function name)
15660 skip_children = FALSE;
15661 skip_depth = 0;
15662 last_node_childless = FALSE;
15663
15664 // Read all the lines in the block
15665 while (!done && !cfeof(infile)) {
15666
15667 strcpy(linebuf, "");
15668 cf_ReadString(linebuf, sizeof(linebuf), infile);
15669 linenum++;
15670
15671 // Remove whitespace padding at start and end of line
15672 RemoveTrailingWhitespace(linebuf);
15673 line = SkipInitialWhitespace(linebuf);
15674
15675 // If it's an empty line or a comment, skip it
15676 if (strlen(line) == 0 || strncmp(line, "//", 2) == 0)
15677 continue;
15678
15679 // Check for End of Script Block Section
15680 if (strncmp(line, SCRIPT_END_TAG, strlen(SCRIPT_END_TAG)) == 0) {
15681 done = true;
15682 continue;
15683 }
15684
15685 // Is it the start of a child block?
15686 if (strncmp(line, CHILD_BLOCK_START_TAG, strlen(CHILD_BLOCK_START_TAG)) == 0) {
15687 last_node_childless = FALSE;
15688 if (!skip_children) {
15689 current_parent = last_node_added;
15690 if (current_parent == NULL)
15691 current_parent = TVI_ROOT;
15692 } else {
15693 skip_depth++;
15694 }
15695 continue;
15696 }
15697
15698 // Handles Validation of childless function nodes
15699 if (last_node_added != NULL && last_node_childless) {
15700 ValidateFunctionNode(last_node_added, linenum);
15701
15702 // Need this to update node text that depends on subnodes
15703 UpdateNodeText(last_node_added);
15704
15705 last_node_childless = FALSE;
15706 }
15707
15708 // Is it the end of a child block?
15709 if (strncmp(line, CHILD_BLOCK_END_TAG, strlen(CHILD_BLOCK_END_TAG)) == 0) {
15710 if (!skip_children || skip_depth <= 0) {
15711
15712 skip_children = FALSE;
15713 skip_depth = 0;
15714
15715 last_node_added = current_parent;
15716 if (last_node_added == TVI_ROOT)
15717 last_node_added = NULL;
15718 else {
15719 // Need this to validate a function node once all of its params have been added
15720 ValidateFunctionNode(last_node_added, linenum);
15721
15722 // Need this to update node text that depends on subnodes
15723 UpdateNodeText(last_node_added);
15724 }
15725
15726 if (current_parent != TVI_ROOT)
15727 current_parent = m_ScriptTree.GetParentItem(current_parent);
15728 if (current_parent == NULL)
15729 current_parent = TVI_ROOT;
15730 } else
15731 skip_depth--;
15732
15733 continue;
15734 }
15735
15736 // If we're skipping children, but the depth is still zero here,
15737 // then must not be any children to skip!
15738 if (skip_children && skip_depth <= 0) {
15739 skip_children = FALSE;
15740 skip_depth = 0;
15741 }
15742
15743 // See if it should be the script name line
15744 if (valid_lines_read == 0) {
15745 if (stricmp(line, script_name) == 0)
15746 ScriptToImportFound = TRUE;
15747 else
15748 ScriptToImportFound = FALSE;
15749 valid_lines_read++;
15750 continue;
15751 }
15752
15753 // See if it should be the save version line
15754 if (valid_lines_read == 1) {
15755 rc = sscanf(line, "%s %d", tempbuf, &version);
15756 if (rc == 2 && strcmp(tempbuf, "VERSION") == 0)
15757 valid_lines_read++;
15758 continue;
15759 }
15760
15761 // It must be a node then,
15762 // so (if we're not skipping children) parse it and add it to the tree
15763 if (!skip_children && ScriptToImportFound) {
15764
15765 if (initial_insert_before != NULL) {
15766 insert_before = initial_insert_before;
15767 initial_insert_before = NULL;
15768 } else
15769 insert_before = TVI_LAST;
15770
15771 if (version >= 1)
15772 returned_node =
15773 ParseScriptNodeLine_v1U(line, linenum, current_parent, skip_children, version, insert_before);
15774 else
15775 returned_node = ParseScriptNodeLine_v0(line, linenum, current_parent, skip_children, insert_before);
15776
15777 if (returned_node != NULL) {
15778 if (new_script_header == NULL)
15779 new_script_header = returned_node;
15780 last_node_added = returned_node;
15781 last_node_childless = TRUE;
15782 UpdateNodeText(last_node_added);
15783 } else
15784 ScriptFileParseError(INVALID_NODE_ERR, linenum, 0, NULL);
15785
15786 if (returned_node == NULL || skip_children) {
15787 skip_children = TRUE;
15788 skip_depth = 0;
15789 }
15790 }
15791 }
15792
15793 if (!done)
15794 ScriptFileParseError(UEOS_ERR, linenum, 0, NULL);
15795 }
15796 }
15797
15798 cfclose(infile);
15799
15800 // Change the script ID for the new script
15801 if (new_script_header != NULL) {
15802 tTreeNodeData *data = (tTreeNodeData *)m_ScriptTree.GetItemData(new_script_header);
15803 if (data != NULL && data->type == SCRIPT_HEADER_NODE) {
15804 int new_id = GetLowestUnusedScriptID();
15805 data->ID = new_id;
15806 UpdateNodeText(new_script_header);
15807 HighlightScript(new_script_header);
15808
15809 if (new_id == m_NextScriptID)
15810 m_NextScriptID++;
15811
15812 m_ScriptTree.SelectItem(new_script_header);
15813 AssignSpecificValue();
15814 SetModified(TRUE);
15815 }
15816 }
15817
15818 return TRUE;
15819 }
15820
15821 #define TEMP_EXPORT_FNAME "DExport.tmp"
15822
15823 // Adds selected script to specified library file
15824 bool CDallasMainDlg::ExportScriptToFile(char *filename, char *script_name) {
15825 CFILE *infile;
15826 char linebuf[2048];
15827 char *line;
15828 int linenum;
15829 int valid_lines_read;
15830 HTREEITEM selected_node, script_header_node;
15831 bool ReplacingScript;
15832 bool ScriptReplaced;
15833
15834 CurrentParsingFilename = filename;
15835
15836 // Make sure the selected item is valid for exporting
15837 selected_node = m_ScriptTree.GetSelectedItem();
15838 if (selected_node == NULL)
15839 return FALSE;
15840 script_header_node = GetParentNodeOfType(selected_node, SCRIPT_HEADER_NODE);
15841 if (script_header_node == NULL)
15842 return FALSE;
15843
15844 // Make sure library file can be written to
15845 if (_access(filename, 0) != -1) {
15846 if ((_access(filename, 2)) == -1) {
15847 CString msg;
15848 msg.Format("The library file \"%s\" is read-only!", filename);
15849 MessageBox(msg, "Script Library File Not Writeable!", MB_OK | MB_ICONEXCLAMATION);
15850 return FALSE;
15851 }
15852 }
15853
15854 // Try to open the file for reading
15855 infile = cfopen(filename, "rt");
15856
15857 // Try to open the temp file for writing
15858 CurrentOutputFile = cfopen(TEMP_EXPORT_FNAME, "wt");
15859 if (CurrentOutputFile == NULL) {
15860 CString msg, title;
15861 msg.Format("ERROR: Unable to open %s for output.", TEMP_EXPORT_FNAME);
15862 title.Format("Temp File Save Error!");
15863 MessageBox(msg, title, MB_OK | MB_ICONEXCLAMATION);
15864 if (infile != NULL)
15865 cfclose(infile);
15866 return FALSE;
15867 }
15868
15869 // If file doesn't exist, Write out the header info
15870 if (infile == NULL) {
15871 O(("/////////////////////////////////////////////////////////////////////"));
15872 O(("// D.A.L.L.A.S. Generated Script Library File "));
15873 O(("/////////////////////////////////////////////////////////////////////"));
15874 O((" "));
15875 }
15876
15877 linenum = 0;
15878 ReplacingScript = FALSE;
15879 ScriptReplaced = FALSE;
15880
15881 // Read in and parse each line of the file
15882 while (infile != NULL && !cfeof(infile)) {
15883
15884 // Clear the buffer
15885 strcpy(linebuf, "");
15886
15887 // Read in a line from the file
15888 cf_ReadString(linebuf, sizeof(linebuf), infile);
15889 linenum++;
15890
15891 // Remove whitespace padding at start and end of line
15892 RemoveTrailingWhitespace(linebuf);
15893 line = SkipInitialWhitespace(linebuf);
15894
15895 // Check for Start of Script Block Section
15896 if (strncmp(line, SCRIPT_START_TAG, strlen(SCRIPT_START_TAG)) == 0) {
15897 bool done = false;
15898
15899 // Write out the start tag
15900 O(("%s", linebuf));
15901
15902 // Set valid line counter to track whether we're reading header info or tree nodes
15903 valid_lines_read = 0;
15904
15905 // Read all the lines in the block
15906 while (!done && !cfeof(infile)) {
15907
15908 strcpy(linebuf, "");
15909 cf_ReadString(linebuf, sizeof(linebuf), infile);
15910 linenum++;
15911
15912 // Remove whitespace padding at start and end of line
15913 RemoveTrailingWhitespace(linebuf);
15914 line = SkipInitialWhitespace(linebuf);
15915
15916 // If it's an empty line or a comment, skip it
15917 if (strlen(line) == 0 || strncmp(line, "//", 2) == 0) {
15918 if (!ReplacingScript)
15919 O(("%s", linebuf));
15920 continue;
15921 }
15922
15923 // Check for End of Script Block Section
15924 if (strncmp(line, SCRIPT_END_TAG, strlen(SCRIPT_END_TAG)) == 0) {
15925 if (ReplacingScript) {
15926 ScriptReplaced = TRUE;
15927 ReplacingScript = FALSE;
15928 }
15929 O(("%s", linebuf));
15930 done = true;
15931 continue;
15932 }
15933
15934 // See if this script's name matches the given name
15935 if (valid_lines_read == 0) {
15936 if (stricmp(line, script_name) == 0) {
15937 CString msg, title;
15938
15939 msg.Format("A script named '%s' already exists in this library.\n\nWould you like to replace it with your "
15940 "new script?",
15941 script_name);
15942 title.Format("Duplicate Script Name Encountered");
15943
15944 // Prompt user to see if it should be replaced
15945 if (MessageBox(msg, title, MB_YESNO | MB_ICONQUESTION) == IDNO) {
15946 cfclose(infile);
15947 cfclose(CurrentOutputFile);
15948 CurrentOutputFile = NULL;
15949 ddio_DeleteFile(TEMP_EXPORT_FNAME);
15950 return FALSE;
15951 }
15952
15953 // Copy the new script into it's place
15954 O(("%s", script_name));
15955 O(("VERSION %d", DALLAS_SAVE_VERSION));
15956
15957 CurrentTabLevel = 0;
15958 if (DALLAS_SAVE_VERSION >= 1)
15959 WriteScriptNodeDump_v1U(script_header_node, TRUE);
15960 else
15961 WriteScriptNodeDump_v0(script_header_node);
15962 WriteScriptChildrenDump(script_header_node, TRUE);
15963
15964 ReplacingScript = TRUE;
15965 } else
15966 O(("%s", linebuf));
15967
15968 valid_lines_read++;
15969 continue;
15970 }
15971
15972 if (!ReplacingScript)
15973 O(("%s", linebuf));
15974 }
15975
15976 if (!done)
15977 ScriptFileParseError(UEOS_ERR, linenum, 0, NULL);
15978 } else
15979 O(("%s", linebuf));
15980 }
15981
15982 // If the script wasn't replaced, add it at the end
15983 if (!ScriptReplaced) {
15984 O(("%s", SCRIPT_START_TAG));
15985 O(("%s", script_name));
15986 O(("VERSION %d", DALLAS_SAVE_VERSION));
15987
15988 CurrentTabLevel = 0;
15989 if (DALLAS_SAVE_VERSION >= 1)
15990 WriteScriptNodeDump_v1U(script_header_node, TRUE);
15991 else
15992 WriteScriptNodeDump_v0(script_header_node);
15993 WriteScriptChildrenDump(script_header_node, TRUE);
15994
15995 O(("%s", SCRIPT_END_TAG));
15996 O((" "));
15997 }
15998
15999 if (infile != NULL)
16000 cfclose(infile);
16001
16002 cfclose(CurrentOutputFile);
16003 CurrentOutputFile = NULL;
16004
16005 // Now delete the library input file, and replace it with the temp file
16006 ddio_DeleteFile(filename);
16007 if (!CopyFile(TEMP_EXPORT_FNAME, filename, FALSE)) {
16008 CString msg, title;
16009 msg.Format("ERROR: Could not copy over temporary library file.\n\nThe export failed.");
16010 title.Format("Script Export Error!");
16011 MessageBox(msg, title, MB_OK | MB_ICONEXCLAMATION);
16012 } else {
16013 CString msg, title;
16014 msg.Format("The script was exported successfully!");
16015 title.Format("Script Export Successful");
16016 MessageBox(msg, title, MB_OK | MB_ICONINFORMATION);
16017 }
16018
16019 ddio_DeleteFile(TEMP_EXPORT_FNAME);
16020
16021 return TRUE;
16022 }
16023
16024 // Imports a script from a specified Library file
16025 void CDallasMainDlg::OnImportButton() {
16026 HTREEITEM selected_node, initial_insert_before;
16027 CString library_filename;
16028
16029 // Make sure the selected item is valid for importing
16030 selected_node = m_ScriptTree.GetSelectedItem();
16031 if (selected_node == NULL)
16032 return;
16033 if (GetNodeType(selected_node) == CLIPBOARD_HEADER_NODE)
16034 initial_insert_before = selected_node;
16035 else {
16036 initial_insert_before = GetParentNodeOfType(selected_node, SCRIPT_HEADER_NODE);
16037 if (initial_insert_before == NULL)
16038 return;
16039 if (m_ScriptTree.GetParentItem(initial_insert_before) != NULL)
16040 return;
16041 }
16042
16043 // Display file selection dlg
16044 if (!ScriptLibraryFilePrompt(library_filename, TRUE))
16045 return;
16046
16047 // Scan the file and display scripts that can be imported
16048 CDallasImportDlg dlg;
16049 dlg.m_Filename = library_filename;
16050 if (dlg.DoModal() == IDCANCEL)
16051 return;
16052 if (dlg.m_ScriptName.IsEmpty())
16053 return;
16054
16055 // Try to import the selected script
16056 ImportScriptFromFile(library_filename.GetBuffer(0), dlg.m_ScriptName.GetBuffer(0));
16057 }
16058
16059 // Exports a script to a specified Library file
16060 void CDallasMainDlg::OnExportButton() {
16061 HTREEITEM selected_node, script_header_node;
16062 CString library_filename;
16063
16064 // Make sure the selected item is valid for exporting
16065 selected_node = m_ScriptTree.GetSelectedItem();
16066 if (selected_node == NULL)
16067 return;
16068 script_header_node = GetParentNodeOfType(selected_node, SCRIPT_HEADER_NODE);
16069 if (script_header_node == NULL)
16070 return;
16071
16072 // Display the enter name prompt
16073 CDallasGenericPromptDlg dlg;
16074 dlg.m_DialogTitle = "Exported Script Name Prompt";
16075 dlg.m_PromptText = "Enter the name for this exported script:";
16076 dlg.m_PromptData = "";
16077 dlg.m_MaxDataLength = 256;
16078
16079 if (dlg.DoModal() == IDCANCEL)
16080 return;
16081 if (dlg.m_PromptData.IsEmpty())
16082 return;
16083
16084 // Display file selection dlg
16085 if (!ScriptLibraryFilePrompt(library_filename, FALSE))
16086 return;
16087
16088 // Try to export the selected script to the specified library file
16089 ExportScriptToFile(library_filename.GetBuffer(0), dlg.m_PromptData.GetBuffer(0));
16090 }
16091
16092 CDallasMainDlg *GetDallasDialogPtr(void) {
16093 #ifdef NEWEDITOR
16094 CNewEditorApp *editor_app;
16095 editor_app = (CNewEditorApp *)AfxGetApp();
16096 #else
16097 CEditorApp *editor_app;
16098 editor_app = &theApp;
16099 #endif
16100
16101 return editor_app->m_DallasModelessDlgPtr;
16102 }