Debian Codegraph @

Descent3/ObjScript.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/ObjScript.cpp $
21 * $Revision: 37 $
22 * $Date: 5/22/99 12:14a $
23 * $Author: Jeff $
24 *
25 * Object scripting
26 *
27 * $Log: /DescentIII/main/ObjScript.cpp $
28 *
29 * 37 5/22/99 12:14a Jeff
30 * don't init scripts if the object already has em
31 *
32 * 36 5/04/99 6:40p Chris
33 *
34 * 35 4/14/99 3:57a Jeff
35 * fixed case mismatch in #includes
36 *
37 * 34 4/02/99 2:13p Chris
38 *
39 * 33 1/13/99 2:27p Jeff
40 * added an is_dying flag for evt_destroy to determine whether the event
41 * is due to level end or because it really is dying
42 *
43 * 32 1/08/99 2:56p Samir
44 * Ripped out OSIRIS1.
45 *
46 * 31 12/31/98 7:34p Jeff
47 * call EVT_DESTROY from FreeObjectScripts (if a direct call to ObjDelete
48 * was called, it would never get the event)
49 *
50 * 30 12/17/98 12:08p Jeff
51 * first checkin of new implementation of OSIRIS (old OSIRIS no longer
52 * works)
53 *
54 * 29 10/18/98 2:59p Jason
55 * fixes for beta4
56 *
57 * 28 10/08/98 2:39p Chris
58 *
59 * 27 10/08/98 2:25p Chris
60 * Clutter and building can now have scripts
61 *
62 * 26 9/17/98 11:11a Chris
63 * Worked on goal system and improved integration with OSIRIS (better
64 * EVT_AI_INIT event calling)
65 *
66 * 25 8/26/98 1:30p Jason
67 * fixed client creation bugs
68 *
69 * 24 8/19/98 5:37p Samir
70 * fixed bug in ReinitTriggerScripts.
71 *
72 * 23 8/19/98 1:35p Samir
73 * added ReinitTrigger
74 *
75 * 22 8/19/98 12:22p Samir
76 * is_custom is now valid.
77 *
78 * 21 8/18/98 12:57a Samir
79 * created function to reinitialize scripts from savegame.
80 *
81 * 20 8/07/98 7:21p Samir
82 * changed references to level script exec.
83 *
84 * 19 7/28/98 5:44p Samir
85 * added hooks for level create and destroy
86 *
87 * 18 5/26/98 7:06p Samir
88 * is_custom added to determine if named script is custom of default.
89 *
90 * 17 3/19/98 12:57p Chris
91 * Changed '<Highest_object_index+1' to '<=Highest_object_index' like the
92 * rest of the code
93 *
94 * 16 1/23/98 6:11p Samir
95 * Addded some trigger functions.
96 *
97 * 15 1/23/98 3:06p Samir
98 * Cleaned up and enhanced script_info structure.
99 *
100 * 14 1/20/98 4:12p Samir
101 * New script housekeeping system.
102 *
103 * 13 1/20/98 11:13a Samir
104 * Door parameters work.
105 *
106 * 12 1/19/98 2:44p Samir
107 * Use one script per object and started parameter passing support.
108 *
109 * 11 10/07/97 3:12p Samir
110 * Fixed level script initialization thread problem.
111 *
112 * 10 10/06/97 4:10p Samir
113 * Initialize door default object scripts.
114 *
115 * 9 9/30/97 5:34p Samir
116 * Fixed initialization of custom scripts over default.
117 *
118 * 8 9/24/97 6:18p Samir
119 * Use script names instead of script id values to identify scripts.
120 *
121 * 7 9/22/97 6:00p Samir
122 * Added a name field to scripts, so we create threads using name instead
123 * of number
124 *
125 * 6 9/11/97 1:59p Matt
126 * Added code to initialize & free trigger scripts
127 *
128 * 5 9/10/97 3:59p Samir
129 * Run level script create event on initialization.
130 *
131 * 4 9/10/97 1:57p Samir
132 * Added code for initializing level scripts.
133 *
134 * 3 8/22/97 10:52a Samir
135 * Added call to script for creation.
136 *
137 * 2 8/21/97 5:56p Samir
138 * Took out script specific stuff from ObjInit and moved to ObjScript
139 *
140 * 3 6/02/97 1:06p Samir
141 * Added some more scripting functions.
142 *
143 * $NoKeywords: $
144 */
145
146 #include "ObjScript.h"
147
148 #include "object.h"
149 #include "objinfo.h"
150 #include "Mission.h"
151 #include "pserror.h"
152 #include "trigger.h"
153 #include "door.h"
154 #include "game.h"
155 #include "multi.h"
156 #include "osiris_dll.h"
157
158 #include <string.h>
159
160 void InitTriggerScript(trigger *tp);
161 void FreeTriggerScript(trigger *tp);
162
163 // We assign all the scripts needed for the level right here.
164 void AssignScriptsForLevel() {
165 int i;
166
167 // Initialize scripts for the objects
168 for (i = 0; i <= Highest_object_index; i++) {
169 if (Objects[i].type != OBJ_NONE && Objects[i].osiris_script == NULL) {
170 InitObjectScripts(&Objects[i]);
171 }
172 }
173
174 // Initialize scripts for the triggers
175 for (i = 0; i < Num_triggers; i++) {
176 InitTriggerScript(&Triggers[i]);
177 }
178 }
179
180 // free scripts for a level
181 void FreeScriptsForLevel() {
182 int i;
183
184 // Free scripts for the objects
185 for (i = 0; i <= Highest_object_index; i++) {
186 FreeObjectScripts(&Objects[i], true);
187 }
188
189 // Free scripts for the triggers
190 for (i = 0; i < Num_triggers; i++) {
191 FreeTriggerScript(&Triggers[i], true);
192 }
193
194 FreeLevelScript();
195 }
196
197 // allocates and initializes the scripts for an object.
198 // robots, powerups, doors, etc.
199 void InitObjectScripts(object *objp, bool do_evt_created) {
200 // Bind scripts to the object
201 Osiris_BindScriptsToObject(objp);
202
203 if (do_evt_created) {
204 tOSIRISEventInfo ei;
205 if (objp->control_type == CT_AI) {
206 Osiris_CallEvent(objp, EVT_AI_INIT, &ei);
207 }
208
209 Osiris_CallEvent(objp, EVT_CREATED, &ei);
210
211 /*
212 if (Game_mode & GM_MULTI && Netgame.local_role==LR_CLIENT)
213 D3XExecScript(objp, EVT_CLIENT_CREATED, objp);
214 else
215 {
216 D3XExecScript(objp, EVT_CREATED, objp);
217 if(objp->control_type == CT_AI)
218 {
219 D3XExecScript(objp, EVT_AI_INIT, NULL, REF_OBJTYPE, NULL);
220 }
221 }
222 */
223 }
224 }
225
226 // frees all scripts for an object.
227 void FreeObjectScripts(object *objp, bool level_end) {
228 tOSIRISEventInfo ei;
229 ei.evt_destroy.is_dying = (level_end) ? 1 : 0;
230
231 if (!level_end)
232 Osiris_CallEvent(objp, EVT_DESTROY, &ei);
233
234 Osiris_DetachScriptsFromObject(objp);
235 }
236
237 // allocates and initializes the script for a trigger
238 void InitTriggerScript(trigger *tp) {}
239
240 // frees the script for a trigger
241 void FreeTriggerScript(trigger *tp, bool level_end) {}