Debian Codegraph @

scripts/BossCamera.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
19 /////////////////////////////////////////////////////////////////////
20 // D.A.L.L.A.S. Generated Level Script - DLL Source File
21 //
22 // Filename: BossCamera.cpp
23 // Version: 3
24 /////////////////////////////////////////////////////////////////////
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <ctype.h>
29 #include "osiris_import.h"
30 #include "osiris_common.h"
31 #include "DallasFuncs.cpp"
32
33 #include "module.h"
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 DLLEXPORT char STDCALL InitializeDLL(tOSIRISModuleInit *func_list);
39 DLLEXPORT void STDCALL ShutdownDLL(void);
40 DLLEXPORT int STDCALL GetGOScriptID(const char *name, uint8_t is_door);
41 DLLEXPORT void STDCALLPTR CreateInstance(int id);
42 DLLEXPORT void STDCALL DestroyInstance(int id, void *ptr);
43 DLLEXPORT int16_t STDCALL CallInstanceEvent(int id, void *ptr, int event, tOSIRISEventInfo *data);
44 DLLEXPORT int STDCALL GetTriggerScriptID(int trigger_room, int trigger_face);
45 DLLEXPORT int STDCALL GetCOScriptList(int **list, int **id_list);
46 DLLEXPORT int STDCALL SaveRestoreState(void *file_ptr, uint8_t saving_state);
47 #ifdef __cplusplus
48 }
49 #endif
50
51 // =================
52 // Script ID Numbers
53 // =================
54 #define ID_LEVEL_0000 0x000
55
56 #define ID_TRIGGER_0000 0x001
57
58 // ========================
59 // Script Class Definitions
60 // ========================
61
62 class BaseScript {
63 public:
64 BaseScript();
65 ~BaseScript();
66 virtual int16_t CallEvent(int event, tOSIRISEventInfo *data);
67 };
68
69 class LevelScript_0000 : public BaseScript {
70 public:
71 int16_t CallEvent(int event, tOSIRISEventInfo *data);
72 };
73
74 class TriggerScript_0000 : public BaseScript {
75 public:
76 int16_t CallEvent(int event, tOSIRISEventInfo *data);
77 };
78
79 // ======================
80 // Global Action Counters
81 // ======================
82
83 #define MAX_ACTION_CTR_VALUE 100000
84
85 int ScriptActionCtr_000 = 0;
86
87 // ========================================
88 // Function to Clear Global Action Counters
89 // ========================================
90 void ClearGlobalActionCtrs(void) { ScriptActionCtr_000 = 0; }
91
92 // ========================================
93 // Function to Save Global Action Counters
94 // ========================================
95 void SaveGlobalActionCtrs(void *file_ptr) { File_WriteInt(ScriptActionCtr_000, file_ptr); }
96
97 // ===========================================
98 // Function to Restore Global Action Counters
99 // ===========================================
100 void RestoreGlobalActionCtrs(void *file_ptr) { ScriptActionCtr_000 = File_ReadInt(file_ptr); }
101
102 // ===============================================================
103 // Start of Custom Script Block - DO NOT EDIT ANYTHING BEFORE THIS
104 // ===============================================================
105 /**{CUSTOM_SCRIPT_BLOCK_START}** DO NOT EDIT! **/
106
107 // Enter your custom script code here
108
109 /**{CUSTOM_SCRIPT_BLOCK_END}**** DO NOT EDIT! **/
110 // ============================================================
111 // End of Custom Script Block - DO NOT EDIT ANYTHING AFTER THIS
112 // ============================================================
113
114 // =================
115 // Message File Data
116 // =================
117
118 #define MAX_SCRIPT_MESSAGES 256
119 #define MAX_MSG_FILEBUF_LEN 1024
120 #define NO_MESSAGE_STRING "*Message Not Found*"
121 #define INV_MSGNAME_STRING "*Message Name Invalid*"
122 #define WHITESPACE_CHARS " \t\r\n"
123
124 // Structure for storing a script message
125 struct tScriptMessage {
126 char *name; // the name of the message
127 char *message; // the actual message text
128 };
129
130 // Global storage for level script messages
131 tScriptMessage *message_list[MAX_SCRIPT_MESSAGES];
132 int num_messages;
133
134 // ======================
135 // Message File Functions
136 // ======================
137
138 // Initializes the Message List
139 void InitMessageList(void) {
140 for (int j = 0; j < MAX_SCRIPT_MESSAGES; j++)
141 message_list[j] = NULL;
142 num_messages = 0;
143 }
144
145 // Clear the Message List
146 void ClearMessageList(void) {
147 for (int j = 0; j < num_messages; j++) {
148 free(message_list[j]->name);
149 free(message_list[j]->message);
150 free(message_list[j]);
151 message_list[j] = NULL;
152 }
153 num_messages = 0;
154 }
155
156 // Adds a message to the list
157 int AddMessageToList(char *name, char *msg) {
158 int pos;
159
160 // Make sure there is room in the list
161 if (num_messages >= MAX_SCRIPT_MESSAGES)
162 return false;
163
164 // Allocate memory for this message entry
165 pos = num_messages;
166 message_list[pos] = (tScriptMessage *)malloc(sizeof(tScriptMessage));
167 if (message_list[pos] == NULL)
168 return false;
169
170 // Allocate memory for the message name
171 message_list[pos]->name = (char *)malloc(strlen(name) + 1);
172 if (message_list[pos]->name == NULL) {
173 free(message_list[pos]);
174 return false;
175 }
176 strcpy(message_list[pos]->name, name);
177
178 // Allocate memory for the message name
179 message_list[pos]->message = (char *)malloc(strlen(msg) + 1);
180 if (message_list[pos]->message == NULL) {
181 free(message_list[pos]->name);
182 free(message_list[pos]);
183 return false;
184 }
185 strcpy(message_list[pos]->message, msg);
186 num_messages++;
187
188 return true;
189 }
190
191 // Removes any whitespace padding from the end of a string
192 void RemoveTrailingWhitespace(char *s) {
193 int last_char_pos;
194
195 last_char_pos = strlen(s) - 1;
196 while (last_char_pos >= 0 && isspace(s[last_char_pos])) {
197 s[last_char_pos] = '\0';
198 last_char_pos--;
199 }
200 }
201
202 // Returns a pointer to the first non-whitespace char in given string
203 char *SkipInitialWhitespace(char *s) {
204 while ((*s) != '\0' && isspace(*s))
205 s++;
206
207 return (s);
208 }
209
210 // Read in the Messages
211 int ReadMessageFile(const char *filename) {
212 void *infile;
213 char filebuffer[MAX_MSG_FILEBUF_LEN + 1];
214 char *line, *msg_start;
215 int line_num;
216 bool next_msgid_found;
217
218 // Try to open the file for loading
219 infile = File_Open(filename, "rt");
220 if (!infile)
221 return false;
222
223 line_num = 0;
224 next_msgid_found = true;
225
226 // Clear the message list
227 ClearMessageList();
228
229 // Read in and parse each line of the file
230 while (!File_eof(infile)) {
231
232 // Clear the buffer
233 strcpy(filebuffer, "");
234
235 // Read in a line from the file
236 File_ReadString(filebuffer, MAX_MSG_FILEBUF_LEN, infile);
237 line_num++;
238
239 // Remove whitespace padding at start and end of line
240 RemoveTrailingWhitespace(filebuffer);
241 line = SkipInitialWhitespace(filebuffer);
242
243 // If line is a comment, or empty, discard it
244 if (strlen(line) == 0 || strncmp(line, "//", 2) == 0)
245 continue;
246
247 if (!next_msgid_found) { // Parse out the last message ID number
248
249 // Grab the first keyword, make sure it's valid
250 line = strtok(line, WHITESPACE_CHARS);
251 if (line == NULL)
252 continue;
253
254 // Grab the second keyword, and assign it as the next message ID
255 line = strtok(NULL, WHITESPACE_CHARS);
256 if (line == NULL)
257 continue;
258
259 next_msgid_found = true;
260 } else { // Parse line as a message line
261
262 // Find the start of message, and mark it
263 msg_start = strchr(line, '=');
264 if (msg_start == NULL)
265 continue;
266 msg_start[0] = '\0';
267 msg_start++;
268
269 // Add the message to the list
270 AddMessageToList(line, msg_start);
271 }
272 }
273 File_Close(infile);
274
275 return true;
276 }
277
278 // Find a message
279 const char *GetMessage(const char *name) {
280 // Make sure given name is valid
281 if (name == NULL)
282 return INV_MSGNAME_STRING;
283
284 // Search message list for name
285 for (int j = 0; j < num_messages; j++)
286 if (strcmp(message_list[j]->name, name) == 0)
287 return (message_list[j]->message);
288
289 // Couldn't find it
290 return NO_MESSAGE_STRING;
291 }
292
293 //======================
294 // Name List Arrays
295 //======================
296
297 #define NUM_DOOR_NAMES 0
298 const char **Door_names = NULL;
299 int *Door_handles = NULL;
300
301 #define NUM_OBJECT_NAMES 1
302 const char *Object_names[NUM_OBJECT_NAMES] = {"Boss"};
303 int Object_handles[NUM_OBJECT_NAMES];
304
305 #define NUM_ROOM_NAMES 0
306 const char **Room_names = NULL;
307 int *Room_indexes = NULL;
308
309 #define NUM_TRIGGER_NAMES 1
310 const char *Trigger_names[NUM_TRIGGER_NAMES] = {"EnterBigRoom"};
311 int Trigger_indexes[NUM_TRIGGER_NAMES];
312 int Trigger_faces[NUM_TRIGGER_NAMES];
313 int Trigger_rooms[NUM_TRIGGER_NAMES];
314
315 #define NUM_SOUND_NAMES 0
316 const char **Sound_names = NULL;
317 int *Sound_indexes = NULL;
318
319 #define NUM_TEXTURE_NAMES 0
320 const char **Texture_names = NULL;
321 int *Texture_indexes = NULL;
322
323 #define NUM_PATH_NAMES 1
324 const char *Path_names[NUM_PATH_NAMES] = {"BossPath"};
325 int Path_indexes[NUM_PATH_NAMES];
326
327 #define NUM_MATCEN_NAMES 0
328 const char **Matcen_names = NULL;
329 int *Matcen_indexes = NULL;
330
331 #define NUM_GOAL_NAMES 0
332 const char **Goal_names = NULL;
333 int *Goal_indexes = NULL;
334
335 #define NUM_MESSAGE_NAMES 1
336 const char *Message_names[NUM_MESSAGE_NAMES] = {"Message2"};
337 const char *Message_strings[NUM_MESSAGE_NAMES];
338
339 // ===============
340 // InitializeDLL()
341 // ===============
342 char STDCALL InitializeDLL(tOSIRISModuleInit *func_list) {
343 osicommon_Initialize((tOSIRISModuleInit *)func_list);
344 if (func_list->game_checksum != CHECKSUM) {
345 mprintf(0, "Game-Checksum FAIL!!! (%ul!=%ul)\n", func_list->game_checksum, CHECKSUM);
346 mprintf(0, "RECOMPILE YOUR SCRIPTS!!!\n");
347 return 0;
348 }
349
350 ClearGlobalActionCtrs();
351 dfInit();
352 InitMessageList();
353
354 // Build the filename of the message file
355 char filename[_MAX_PATH + 32];
356 int lang_type;
357 if (func_list->script_identifier != NULL) {
358 _splitpath(func_list->script_identifier, NULL, NULL, filename, NULL);
359 lang_type = Game_GetLanguage();
360 if (lang_type == LANGUAGE_FRENCH)
361 strcat(filename, "_FRN");
362 else if (lang_type == LANGUAGE_GERMAN)
363 strcat(filename, "_GER");
364 else if (lang_type == LANGUAGE_ITALIAN)
365 strcat(filename, "_ITN");
366 else if (lang_type == LANGUAGE_SPANISH)
367 strcat(filename, "_SPN");
368 strcat(filename, ".msg");
369 } else {
370 strcpy(filename, "BossCamera.msg");
371 lang_type = LANGUAGE_ENGLISH;
372 }
373 if (!ReadMessageFile(filename)) {
374 mprintf(0, "ERROR: Could not load message file - %s\n", filename);
375 }
376
377 int j;
378
379 // Do Door Index lookups
380 for (j = 0; j < NUM_DOOR_NAMES; j++)
381 Door_handles[j] = Scrpt_FindDoorName(Door_names[j]);
382
383 // Do Object Index lookups
384 for (j = 0; j < NUM_OBJECT_NAMES; j++)
385 Object_handles[j] = Scrpt_FindObjectName(Object_names[j]);
386
387 // Do Room Index lookups
388 for (j = 0; j < NUM_ROOM_NAMES; j++)
389 Room_indexes[j] = Scrpt_FindRoomName(Room_names[j]);
390
391 // Do Trigger Index lookups
392 for (j = 0; j < NUM_TRIGGER_NAMES; j++) {
393 Trigger_indexes[j] = Scrpt_FindTriggerName(Trigger_names[j]);
394 Trigger_faces[j] = Scrpt_GetTriggerFace(Trigger_indexes[j]);
395 Trigger_rooms[j] = Scrpt_GetTriggerRoom(Trigger_indexes[j]);
396 }
397
398 // Do Sound Index lookups
399 for (j = 0; j < NUM_SOUND_NAMES; j++)
400 Sound_indexes[j] = Scrpt_FindSoundName(Sound_names[j]);
401
402 // Do Texture Index lookups
403 for (j = 0; j < NUM_TEXTURE_NAMES; j++)
404 Texture_indexes[j] = Scrpt_FindTextureName(Texture_names[j]);
405
406 // Do Path Index lookups
407 for (j = 0; j < NUM_PATH_NAMES; j++)
408 Path_indexes[j] = Scrpt_FindPathName(Path_names[j]);
409
410 // Do Matcen Index lookups
411 for (j = 0; j < NUM_MATCEN_NAMES; j++)
412 Matcen_indexes[j] = Scrpt_FindMatcenName(Matcen_names[j]);
413
414 // Do Goal Index lookups
415 for (j = 0; j < NUM_GOAL_NAMES; j++)
416 Goal_indexes[j] = Scrpt_FindLevelGoalName(Goal_names[j]);
417
418 // Do Message Name lookups
419 for (j = 0; j < NUM_MESSAGE_NAMES; j++)
420 Message_strings[j] = GetMessage(Message_names[j]);
421
422 return 1;
423 }
424
425 // =============
426 // ShutdownDLL()
427 // =============
428 void STDCALL ShutdownDLL(void) { ClearMessageList(); }
429
430 // ===============
431 // GetGOScriptID()
432 // ===============
433 int STDCALL GetGOScriptID(const char *name, uint8_t isdoor) { return -1; }
434
435 // ================
436 // CreateInstance()
437 // ================
438 void STDCALLPTR CreateInstance(int id) {
439 switch (id) {
440 case ID_LEVEL_0000:
441 return new LevelScript_0000;
442 break;
443 case ID_TRIGGER_0000:
444 return new TriggerScript_0000;
445 break;
446 default:
447 mprintf(0, "SCRIPT: Illegal ID (%d)\n", id);
448 break;
449 }
450 return NULL;
451 }
452
453 // =================
454 // DestroyInstance()
455 // =================
456 void STDCALL DestroyInstance(int id, void *ptr) {
457 switch (id) {
458 case ID_LEVEL_0000:
459 delete ((LevelScript_0000 *)ptr);
460 break;
461 case ID_TRIGGER_0000:
462 delete ((TriggerScript_0000 *)ptr);
463 break;
464 default:
465 mprintf(0, "SCRIPT: Illegal ID (%d)\n", id);
466 break;
467 }
468 }
469
470 // ===================
471 // CallInstanceEvent()
472 // ===================
473 int16_t STDCALL CallInstanceEvent(int id, void *ptr, int event, tOSIRISEventInfo *data) {
474 switch (id) {
475 case ID_LEVEL_0000:
476 case ID_TRIGGER_0000:
477 return ((BaseScript *)ptr)->CallEvent(event, data);
478 break;
479 default:
480 mprintf(0, "SCRIPT: Illegal ID (%d)\n", id);
481 break;
482 }
483 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
484 }
485
486 // ==================
487 // SaveRestoreState()
488 // ==================
489 int STDCALL SaveRestoreState(void *file_ptr, uint8_t saving_state) { return 0; }
490
491 // ====================
492 // GetTriggerScriptID()
493 // ====================
494 int STDCALL GetTriggerScriptID(int trigger_room, int trigger_face) {
495 if (trigger_room == Trigger_rooms[0] && trigger_face == Trigger_faces[0])
496 return ID_TRIGGER_0000;
497
498 return -1;
499 }
500
501 // =================
502 // GetCOScriptList()
503 // =================
504 int STDCALL GetCOScriptList(int **list, int **id_list) {
505 static int *cust_handle_list = NULL;
506 static int *cust_id_list = NULL;
507
508 *list = cust_handle_list;
509 *id_list = cust_id_list;
510
511 return 0;
512 }
513
514 //=======================
515 // Script Implementation
516 //=======================
517
518 BaseScript::BaseScript() {}
519
520 BaseScript::~BaseScript() {}
521
522 int16_t BaseScript::CallEvent(int event, tOSIRISEventInfo *data) {
523 mprintf(0, "BaseScript::CallEvent()\n");
524 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
525 }
526
527 int16_t LevelScript_0000::CallEvent(int event, tOSIRISEventInfo *data) {
528 switch (event) {
529 case EVT_SAVESTATE: {
530 tOSIRISEVTSAVESTATE *event_data = &data->evt_savestate;
531
532 SaveGlobalActionCtrs(event_data->fileptr);
533 dfSave(event_data->fileptr);
534 } break;
535 case EVT_RESTORESTATE: {
536 tOSIRISEVTRESTORESTATE *event_data = &data->evt_restorestate;
537
538 RestoreGlobalActionCtrs(event_data->fileptr);
539 dfRestore(event_data->fileptr);
540 } break;
541 case EVT_LEVELSTART: {
542 tOSIRISEVTLEVELSTART *event_data = &data->evt_levelstart;
543
544 ClearGlobalActionCtrs();
545 dfInit();
546 } break;
547 }
548 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
549 }
550
551 int16_t TriggerScript_0000::CallEvent(int event, tOSIRISEventInfo *data) {
552 switch (event) {
553 case EVT_COLLIDE: {
554 tOSIRISEVTCOLLIDE *event_data = &data->evt_collide;
555
556 // Script 000: Script Description Goes Here
557 if (qObjIsPlayer(event_data->it_handle) == true) {
558 aCinematicSimple(Path_indexes[0], Message_strings[0], Object_handles[0], 10.000000f, 1);
559
560 // Increment the script action counter
561 if (ScriptActionCtr_000 < MAX_ACTION_CTR_VALUE)
562 ScriptActionCtr_000++;
563 }
564 } break;
565 }
566 return CONTINUE_CHAIN | CONTINUE_DEFAULT;
567 }
568
569 /*********************************************************
570 Script Save Block: DO NOT TOUCH ANYTHING IN THIS BLOCK!!!
571 **********************************************************
572 $$SCRIPT_BLOCK_START
573
574 VERSION 3
575 NEXT_ID 1
576
577 // UserType value blocks
578 $$UTYPE_VALS_START UserVar
579 $$UTYPE_VALS_END
580
581 $$UTYPE_VALS_START UserFlag
582 $$UTYPE_VALS_END
583
584 $$UTYPE_VALS_START SpewHandle
585 $$UTYPE_VALS_END
586
587 $$UTYPE_VALS_START TimerID
588 $$UTYPE_VALS_END
589
590 $$UTYPE_VALS_START SavedObjectSlot
591 $$UTYPE_VALS_END
592
593 $$UTYPE_VALS_START GoalID
594 $$UTYPE_VALS_END
595
596
597 // Name Lists
598 $$DOOR_LIST_START
599 $$DOOR_LIST_END
600
601 $$OBJECT_LIST_START
602 Boss
603 $$OBJECT_LIST_END
604
605 $$ROOM_LIST_START
606 $$ROOM_LIST_END
607
608 $$TRIGGER_LIST_START
609 EnterBigRoom
610 $$TRIGGER_LIST_END
611
612 $$SOUND_LIST_START
613 $$SOUND_LIST_END
614
615 $$TEXTURE_LIST_START
616 $$TEXTURE_LIST_END
617
618 $$SPECNAME_LIST_START
619 $$SPECNAME_LIST_END
620
621 $$PATH_LIST_START
622 BossPath
623 $$PATH_LIST_END
624
625 $$MATCEN_LIST_START
626 $$MATCEN_LIST_END
627
628 $$GOAL_LIST_START
629 $$GOAL_LIST_END
630
631 $$STRM_AUDIO_LIST_START
632 $$STRM_AUDIO_LIST_END
633
634
635 // Script Tree Dump
636 00:0:Script Description Goes Here
637 $$CHILD_BLOCK_START
638 01:0:0
639 02:1
640 03:0
641 $$CHILD_BLOCK_START
642 05:1
643 $$CHILD_BLOCK_START
644 06:qObjIsPlayer:Bool
645 $$CHILD_BLOCK_START
646 10:1:1:-1:Object
647 $$CHILD_BLOCK_END
648 07:0:6
649 $$CHILD_BLOCK_END
650 $$CHILD_BLOCK_END
651 04:0:0:0
652 $$CHILD_BLOCK_START
653 08:aCinematicSimple
654 $$CHILD_BLOCK_START
655 10:16:0:CameraPath
656 10:8:Message2:Text
657 10:1:0:0:Target
658 10:6:10.000000:Seconds
659 10:5:1:FadeIn
660 $$CHILD_BLOCK_END
661 $$CHILD_BLOCK_END
662 $$CHILD_BLOCK_END
663
664 $$SCRIPT_BLOCK_END
665 *********************************************************/