| 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"cxx . . $ `<file>/Descent3/ObjScript.h`/ |
| 147 | |
| 148 | #include "object.h"cxx . . $ `<file>/Descent3/object.h`/ |
| 149 | #include "objinfo.h"cxx . . $ `<file>/Descent3/objinfo.h`/ |
| 150 | #include "Mission.h"cxx . . $ `<file>/Descent3/Mission.h`/ |
| 151 | #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/ |
| 152 | #include "trigger.h"cxx . . $ `<file>/Descent3/trigger.h`/ |
| 153 | #include "door.h"cxx . . $ `<file>/Descent3/door.h`/ |
| 154 | #include "game.h"cxx . . $ `<file>/Descent3/game.h`/ |
| 155 | #include "multi.h"cxx . . $ `<file>/Descent3/multi.h`/ |
| 156 | #include "osiris_dll.h"cxx . . $ `<file>/Descent3/osiris_dll.h`/ |
| 157 | |
| 158 | #include <string.h> |
| 159 | |
| 160 | void InitTriggerScriptcxx . . $ InitTriggerScript(b5f99d175f3c6885).(triggercxx . . $ trigger# *tp); |
| 161 | void FreeTriggerScriptcxx . . $ FreeTriggerScript(b5f99d175f3c6885).(triggercxx . . $ trigger# *tp); |
| 162 | |
| 163 | // We assign all the scripts needed for the level right here. |
| 164 | void AssignScriptsForLevelcxx . . $ AssignScriptsForLevel(49f6e7a06ebc5aa8).() { |
| 165 | int i; |
| 166 | |
| 167 | // Initialize scripts for the objects |
| 168 | for (i = 0; i <= Highest_object_indexcxx . . $ Highest_object_index.; i++) { |
| 169 | if (Objectscxx . . $ Objects.[i].typecxx . . $ object#type. != OBJ_NONEcxx . . $ `Descent3/object_external.h:159:9`! && Objectscxx . . $ Objects.[i].osiris_scriptcxx . . $ object#osiris_script. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 170 | InitObjectScriptscxx . . $ InitObjectScripts(674fac047436fc5b).(&Objectscxx . . $ Objects.[i]); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | // Initialize scripts for the triggers |
| 175 | for (i = 0; i < Num_triggerscxx . . $ Num_triggers.; i++) { |
| 176 | InitTriggerScriptcxx . . $ InitTriggerScript(b5f99d175f3c6885).(&Triggerscxx . . $ Triggers.[i]); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | // free scripts for a level |
| 181 | void FreeScriptsForLevelcxx . . $ FreeScriptsForLevel(49f6e7a06ebc5aa8).() { |
| 182 | int i; |
| 183 | |
| 184 | // Free scripts for the objects |
| 185 | for (i = 0; i <= Highest_object_indexcxx . . $ Highest_object_index.; i++) { |
| 186 | FreeObjectScriptscxx . . $ FreeObjectScripts(674fac047436fc5b).(&Objectscxx . . $ Objects.[i], true); |
| 187 | } |
| 188 | |
| 189 | // Free scripts for the triggers |
| 190 | for (i = 0; i < Num_triggerscxx . . $ Num_triggers.; i++) { |
| 191 | FreeTriggerScriptcxx . . $ FreeTriggerScript(2141560ee082416a).(&Triggerscxx . . $ Triggers.[i], true); |
| 192 | } |
| 193 | |
| 194 | FreeLevelScriptcxx . . $ FreeLevelScript(49f6e7a06ebc5aa8).(); |
| 195 | } |
| 196 | |
| 197 | // allocates and initializes the scripts for an object. |
| 198 | // robots, powerups, doors, etc. |
| 199 | void InitObjectScriptscxx . . $ InitObjectScripts(674fac047436fc5b).(objectcxx . . $ object# *objp, bool do_evt_created) { |
| 200 | // Bind scripts to the object |
| 201 | Osiris_BindScriptsToObjectcxx . . $ Osiris_BindScriptsToObject(39516aeee13ca5ab).(objp); |
| 202 | |
| 203 | if (do_evt_created) { |
| 204 | tOSIRISEventInfocxx . . $ tOSIRISEventInfo# ei; |
| 205 | if (objp->control_typecxx . . $ object#control_type. == CT_AIcxx . . $ `Descent3/object_external.h:217:9`!) { |
| 206 | Osiris_CallEventcxx . . $ Osiris_CallEvent(91e8d3045aa5549c).(objp, EVT_AI_INITcxx . . $ `scripts/osiris_common.h:372:9`!, &ei); |
| 207 | } |
| 208 | |
| 209 | Osiris_CallEventcxx . . $ Osiris_CallEvent(91e8d3045aa5549c).(objp, EVT_CREATEDcxx . . $ `scripts/osiris_common.h:367:9`!, &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 FreeObjectScriptscxx . . $ FreeObjectScripts(674fac047436fc5b).(objectcxx . . $ object# *objp, bool level_end) { |
| 228 | tOSIRISEventInfocxx . . $ tOSIRISEventInfo# ei; |
| 229 | ei.evt_destroycxx . . $ tOSIRISEventInfo#$anonymous_type_1#evt_destroy..is_dyingcxx . . $ tOSIRISEVTDESTROY#is_dying. = (level_end) ? 1 : 0; |
| 230 | |
| 231 | if (!level_end) |
| 232 | Osiris_CallEventcxx . . $ Osiris_CallEvent(91e8d3045aa5549c).(objp, EVT_DESTROYcxx . . $ `scripts/osiris_common.h:368:9`!, &ei); |
| 233 | |
| 234 | Osiris_DetachScriptsFromObjectcxx . . $ Osiris_DetachScriptsFromObject(419c470199a90a97).(objp); |
| 235 | } |
| 236 | |
| 237 | // allocates and initializes the script for a trigger |
| 238 | void InitTriggerScriptcxx . . $ InitTriggerScript(b5f99d175f3c6885).(triggercxx . . $ trigger# *tp) {} |
| 239 | |
| 240 | // frees the script for a trigger |
| 241 | void FreeTriggerScriptcxx . . $ FreeTriggerScript(2141560ee082416a).(triggercxx . . $ trigger# *tp, bool level_end) {} |