1 /*
2 ===========================================================================
3 Copyright (C) 2000 - 2013, Raven Software, Inc.
4 Copyright (C) 2001 - 2013, Activision, Inc.
5 Copyright (C) 2013 - 2015, OpenJK contributors
6 
7 This file is part of the OpenJK source code.
8 
9 OpenJK is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License version 2 as
11 published by the Free Software Foundation.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 ===========================================================================
21 */
22 
23 // Filename:-	g_functions.cpp
24 //
25 
26 // This file contains the 8 (so far) function calls that replace the 8 function ptrs in the gentity_t structure
27 
28 #include "g_local.h"
29 #include "../cgame/cg_local.h"
30 #include "g_functions.h"
31 
GEntity_ThinkFunc(gentity_t * self)32 void GEntity_ThinkFunc(gentity_t *self)
33 {
34 #define THINKCASE(blah) case thinkF_ ## blah: blah(self); break;
35 
36 	switch (self->e_ThinkFunc)
37 	{
38 	case thinkF_NULL:
39 		break;
40 
41 	THINKCASE( funcBBrushDieGo )
42 	THINKCASE( ExplodeDeath )
43 	THINKCASE( RespawnItem )
44 	THINKCASE( G_FreeEntity )
45 	THINKCASE( FinishSpawningItem )
46 	THINKCASE( locateCamera )
47 	THINKCASE( G_RunObject )
48 	THINKCASE( ReturnToPos1 )
49 	THINKCASE( Use_BinaryMover_Go )
50 	THINKCASE( Think_MatchTeam )
51 	THINKCASE( Think_BeginMoving )
52 	THINKCASE( Think_SetupTrainTargets )
53 	THINKCASE( Think_SpawnNewDoorTrigger )
54 	THINKCASE( ref_link )
55 	THINKCASE( Think_Target_Delay )
56 	THINKCASE( target_laser_think )
57 	THINKCASE( target_laser_start )
58 	THINKCASE( target_location_linkup )
59 	THINKCASE( scriptrunner_run )
60 	THINKCASE( multi_wait )
61 	THINKCASE( multi_trigger_run )
62 	THINKCASE( trigger_always_think )
63 	THINKCASE( AimAtTarget )
64 	THINKCASE( func_timer_think )
65 	THINKCASE( NPC_RemoveBody )
66 	THINKCASE( Disappear )
67 	THINKCASE( NPC_Think )
68 	THINKCASE( NPC_Spawn_Go )
69 	THINKCASE( NPC_Begin )
70 	THINKCASE( moverCallback )
71 	THINKCASE( anglerCallback )
72 	// This RemoveOwner need to exist here anymore???
73 	THINKCASE( RemoveOwner )
74 	THINKCASE( MakeOwnerInvis )
75 	THINKCASE( MakeOwnerEnergy )
76 	THINKCASE( func_usable_think )
77 	THINKCASE( misc_dlight_think )
78 	THINKCASE( health_think )
79 	THINKCASE( ammo_think )
80 	THINKCASE( trigger_teleporter_find_closest_portal )
81 	THINKCASE( thermalDetonatorExplode )
82 	THINKCASE( WP_ThermalThink )
83 	THINKCASE( trigger_hurt_reset )
84 	THINKCASE( turret_base_think )
85 	THINKCASE( turret_head_think )
86 	THINKCASE( laser_arm_fire )
87 	THINKCASE( laser_arm_start )
88 	THINKCASE( trigger_visible_check_player_visibility )
89 	THINKCASE( target_relay_use_go )
90 	THINKCASE( trigger_cleared_fire )
91 	THINKCASE( MoveOwner )
92 	THINKCASE( SolidifyOwner )
93 	THINKCASE( cycleCamera )
94 	THINKCASE( spawn_ammo_crystal_trigger )
95 	THINKCASE( NPC_ShySpawn )
96 	THINKCASE( func_wait_return_solid )
97 	THINKCASE( InflateOwner )
98 	THINKCASE( mega_ammo_think )
99 	THINKCASE( misc_replicator_item_finish_spawn )
100 	THINKCASE( fx_runner_link )
101 	THINKCASE( fx_runner_think )
102 	THINKCASE( fx_rain_think ) // delay flagging entities as portal entities (for sky portals)
103 	THINKCASE( removeBoltSurface)
104 	THINKCASE( set_MiscAnim)
105 	THINKCASE( LimbThink )
106 	THINKCASE( laserTrapThink )
107 	THINKCASE( TieFighterThink )
108 	THINKCASE( TieBomberThink )
109 	THINKCASE( rocketThink )
110 	THINKCASE( prox_mine_think )
111 	THINKCASE( emplaced_blow )
112 	THINKCASE( WP_Explode )
113 	THINKCASE( pas_think )	// personal assault sentry
114 	THINKCASE( ion_cannon_think )
115 	THINKCASE( maglock_link )
116 	THINKCASE( WP_flechette_alt_blow )
117 	THINKCASE( WP_prox_mine_think )
118 	THINKCASE( camera_aim )
119 	THINKCASE( fx_explosion_trail_link )
120 	THINKCASE( fx_explosion_trail_think )
121 	THINKCASE( fx_target_beam_link )
122 	THINKCASE( fx_target_beam_think )
123 	THINKCASE( spotlight_think )
124 	THINKCASE( spotlight_link )
125 	THINKCASE( trigger_push_checkclear )
126 	THINKCASE( DEMP2_AltDetonate )
127 	THINKCASE( DEMP2_AltRadiusDamage )
128 	THINKCASE( panel_turret_think )
129 	THINKCASE( welder_think )
130 	THINKCASE( gas_random_jet )
131 	THINKCASE( poll_converter ) // dumb loop sound handling
132 	THINKCASE( spawn_rack_goods ) // delay spawn of goods to help on ents
133 	THINKCASE( NoghriGasCloudThink )
134 
135 	THINKCASE( G_PortalifyEntities ) // delay flagging entities as portal entities (for sky portals)
136 
137 	THINKCASE( misc_weapon_shooter_aim )
138 	THINKCASE( misc_weapon_shooter_fire )
139 
140 	THINKCASE( beacon_think )
141 
142 	default:
143 		Com_Error(ERR_DROP, "GEntity_ThinkFunc: case %d not handled!\n",self->e_ThinkFunc);
144 		break;
145 	}
146 }
147 
148 // note different switch-case code for CEntity as opposed to GEntity (CEntity goes through parent GEntity first)...
149 //
CEntity_ThinkFunc(centity_s * cent)150 void CEntity_ThinkFunc(centity_s *cent)
151 {
152 #define CLTHINKCASE(blah) case clThinkF_ ## blah: blah(cent); break;
153 
154 	switch (cent->gent->e_clThinkFunc)
155 	{
156 	case clThinkF_NULL:
157 		break;
158 
159 	CLTHINKCASE( CG_DLightThink )
160 	CLTHINKCASE( CG_MatrixEffect )
161 	CLTHINKCASE( CG_Limb )
162 
163 	default:
164 		Com_Error(ERR_DROP, "CEntity_ThinkFunc: case %d not handled!\n",cent->gent->e_clThinkFunc);
165 		break;
166 	}
167 }
168 
169 
GEntity_ReachedFunc(gentity_t * self)170 void GEntity_ReachedFunc(gentity_t *self)
171 {
172 #define REACHEDCASE(blah) case reachedF_ ## blah: blah(self); break;
173 
174 	switch (self->e_ReachedFunc)
175 	{
176 	case reachedF_NULL:
177 		break;
178 
179 	REACHEDCASE( Reached_BinaryMover )
180 	REACHEDCASE( Reached_Train )
181 	REACHEDCASE( moverCallback )
182 	REACHEDCASE( moveAndRotateCallback )
183 
184 	default:
185 		Com_Error(ERR_DROP, "GEntity_ReachedFunc: case %d not handled!\n",self->e_ReachedFunc);
186 		break;
187 	}
188 }
189 
190 
191 
GEntity_BlockedFunc(gentity_t * self,gentity_t * other)192 void GEntity_BlockedFunc(gentity_t *self, gentity_t *other)
193 {
194 #define BLOCKEDCASE(blah) case blockedF_ ## blah: blah(self,other); break;
195 
196 	switch (self->e_BlockedFunc)
197 	{
198 	case blockedF_NULL:
199 		break;
200 
201 	BLOCKEDCASE( Blocked_Door )
202 	BLOCKEDCASE( Blocked_Mover )
203 
204 	default:
205 		Com_Error(ERR_DROP, "GEntity_BlockedFunc: case %d not handled!\n",self->e_BlockedFunc);
206 		break;
207 	}
208 }
209 
GEntity_TouchFunc(gentity_t * self,gentity_t * other,trace_t * trace)210 void GEntity_TouchFunc(gentity_t *self, gentity_t *other, trace_t *trace)
211 {
212 #define TOUCHCASE(blah) case touchF_ ## blah: blah(self,other,trace); break;
213 
214 	switch (self->e_TouchFunc)
215 	{
216 	case touchF_NULL:
217 		break;
218 
219 	TOUCHCASE( Touch_Item )
220 	TOUCHCASE( teleporter_touch )
221 	TOUCHCASE( charge_stick )
222 	TOUCHCASE( Touch_DoorTrigger )
223 	TOUCHCASE( Touch_PlatCenterTrigger )
224 	TOUCHCASE( Touch_Plat )
225 	TOUCHCASE( Touch_Button )
226 	TOUCHCASE( Touch_Multi )
227 	TOUCHCASE( trigger_push_touch )
228 	TOUCHCASE( trigger_teleporter_touch )
229 	TOUCHCASE( hurt_touch )
230 	TOUCHCASE( NPC_Touch )
231 	TOUCHCASE( touch_ammo_crystal_tigger )
232 	TOUCHCASE( funcBBrushTouch )
233 	TOUCHCASE( touchLaserTrap )
234 	TOUCHCASE( prox_mine_stick )
235 	TOUCHCASE( func_rotating_touch )
236 	TOUCHCASE( TouchTieBomb )
237 
238 	default:
239 		Com_Error(ERR_DROP, "GEntity_TouchFunc: case %d not handled!\n",self->e_TouchFunc);
240 	}
241 }
242 
GEntity_UseFunc(gentity_t * self,gentity_t * other,gentity_t * activator)243 void GEntity_UseFunc(gentity_t *self, gentity_t *other, gentity_t *activator)
244 {
245 	if ( !self || (self->svFlags&SVF_INACTIVE) )
246 	{
247 		return;
248 	}
249 #define USECASE(blah) case useF_ ## blah: blah(self,other,activator); break;
250 
251 	switch (self->e_UseFunc)
252 	{
253 	case useF_NULL:
254 		break;
255 
256 	USECASE( funcBBrushUse )
257 	USECASE( misc_model_use )
258 	USECASE( Use_Item )
259 	USECASE( Use_Shooter )
260 	USECASE( GoExplodeDeath )
261 	USECASE( Use_BinaryMover )
262 	USECASE( use_wall )
263 	USECASE( Use_Target_Give )
264 	USECASE( Use_Target_Delay )
265 	USECASE( Use_Target_Score )
266 	USECASE( Use_Target_Print )
267 	USECASE( Use_Target_Speaker )
268 	USECASE( target_laser_use )
269 	USECASE( target_relay_use )
270 	USECASE( target_kill_use )
271 	USECASE( target_counter_use )
272 	USECASE( target_random_use )
273 	USECASE( target_scriptrunner_use )
274 	USECASE( target_gravity_change_use )
275 	USECASE( target_friction_change_use )
276 	USECASE( target_teleporter_use )
277 	USECASE( Use_Multi )
278 	USECASE( Use_target_push )
279 	USECASE( hurt_use )
280 	USECASE( func_timer_use )
281 	USECASE( trigger_entdist_use )
282 	USECASE( func_usable_use )
283 	USECASE( target_activate_use )
284 	USECASE( target_deactivate_use )
285 	USECASE( NPC_Use )
286 	USECASE( NPC_Spawn )
287 	USECASE( misc_dlight_use )
288 	USECASE( health_use )
289 	USECASE( ammo_use )
290 	USECASE( mega_ammo_use )
291 	USECASE( target_level_change_use )
292 	USECASE( target_change_parm_use )
293 	USECASE( turret_base_use )
294 	USECASE( laser_arm_use )
295 	USECASE( func_static_use )
296 	USECASE( target_play_music_use )
297 	USECASE( misc_model_useup )
298 	USECASE( misc_portal_use )
299 	USECASE( target_autosave_use )
300 	USECASE( switch_models )
301 	USECASE( misc_replicator_item_spawn )
302 	USECASE( misc_replicator_item_remove )
303 	USECASE( target_secret_use)
304 	USECASE( func_bobbing_use )
305 	USECASE( func_rotating_use )
306 	USECASE( fx_runner_use )
307 	USECASE( funcGlassUse )
308 	USECASE( TrainUse )
309 	USECASE( misc_trip_mine_activate )
310 	USECASE( emplaced_gun_use )
311 	USECASE( shield_power_converter_use )
312 	USECASE( ammo_power_converter_use )
313 	USECASE( bomb_planted_use )
314 	USECASE( beacon_use )
315 	USECASE( security_panel_use )
316 	USECASE( ion_cannon_use )
317 	USECASE( camera_use )
318 	USECASE( fx_explosion_trail_use )
319 	USECASE( fx_target_beam_use )
320 	USECASE( sentry_use )
321 	USECASE( spotlight_use )
322 	USECASE( misc_atst_use )
323 	USECASE( panel_turret_use )
324 	USECASE( welder_use )
325 	USECASE( jabba_cam_use )
326 	USECASE( misc_use )
327 	USECASE( pas_use )
328 	USECASE( item_spawn_use )
329 	USECASE( NPC_VehicleSpawnUse )
330 	USECASE( misc_weapon_shooter_use )
331 	USECASE( eweb_use )
332 	USECASE( TieFighterUse );
333 
334 	default:
335 		Com_Error(ERR_DROP, "GEntity_UseFunc: case %d not handled!\n",self->e_UseFunc);
336 	}
337 }
338 
GEntity_PainFunc(gentity_t * self,gentity_t * inflictor,gentity_t * attacker,const vec3_t point,int damage,int mod,int hitLoc)339 void GEntity_PainFunc(gentity_t *self, gentity_t *inflictor, gentity_t *attacker, const vec3_t point, int damage, int mod,int hitLoc)
340 {
341 #define PAINCASE(blah) case painF_ ## blah: blah(self,inflictor,attacker,point,damage,mod,hitLoc); break;
342 
343 	switch (self->e_PainFunc)
344 	{
345 	case painF_NULL:
346 		break;
347 
348 	PAINCASE( funcBBrushPain )
349 	PAINCASE( misc_model_breakable_pain	)
350 	PAINCASE( NPC_Pain )
351 	PAINCASE( station_pain )
352 	PAINCASE( func_usable_pain )
353 	PAINCASE( NPC_ATST_Pain )
354 	PAINCASE( NPC_ST_Pain )
355 	PAINCASE( NPC_Jedi_Pain )
356 	PAINCASE( NPC_Droid_Pain )
357 	PAINCASE( NPC_Probe_Pain )
358 	PAINCASE( NPC_MineMonster_Pain )
359 	PAINCASE( NPC_Howler_Pain )
360 	PAINCASE( NPC_Rancor_Pain )
361 	PAINCASE( NPC_Wampa_Pain )
362 	PAINCASE( NPC_SandCreature_Pain )
363 	PAINCASE( NPC_Seeker_Pain )
364 	PAINCASE( NPC_Remote_Pain )
365 	PAINCASE( emplaced_gun_pain )
366 	PAINCASE( NPC_Mark1_Pain )
367 	PAINCASE( NPC_Sentry_Pain )
368 	PAINCASE( NPC_Mark2_Pain )
369 	PAINCASE( PlayerPain )
370 	PAINCASE( GasBurst )
371 	PAINCASE( CrystalCratePain )
372 	PAINCASE( TurretPain )
373 	PAINCASE( eweb_pain )
374 
375 	default:
376 		Com_Error(ERR_DROP, "GEntity_PainFunc: case %d not handled!\n",self->e_PainFunc);
377 	}
378 }
379 
380 
GEntity_DieFunc(gentity_t * self,gentity_t * inflictor,gentity_t * attacker,int damage,int mod,int dFlags,int hitLoc)381 void GEntity_DieFunc(gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int mod, int dFlags, int hitLoc)
382 {
383 #define DIECASE(blah) case dieF_ ## blah: blah(self,inflictor,attacker,damage,mod,dFlags,hitLoc); break;
384 
385 	switch (self->e_DieFunc)
386 	{
387 	case dieF_NULL:
388 		break;
389 
390 	DIECASE( funcBBrushDie )
391 	DIECASE( misc_model_breakable_die )
392 	DIECASE( misc_model_cargo_die )
393 	DIECASE( func_train_die )
394 	DIECASE( player_die )
395 	DIECASE( ExplodeDeath_Wait )
396 	DIECASE( ExplodeDeath )
397 	DIECASE( func_usable_die )
398 	DIECASE( turret_die )
399 	DIECASE( funcGlassDie )
400 //	DIECASE( laserTrapDelayedExplode )
401 	DIECASE( emplaced_gun_die )
402 	DIECASE( WP_ExplosiveDie )
403 	DIECASE( ion_cannon_die )
404 	DIECASE( maglock_die )
405 	DIECASE( camera_die )
406 	DIECASE( Mark1_die )
407 	DIECASE( Interrogator_die )
408 	DIECASE( misc_atst_die )
409 	DIECASE( misc_panel_turret_die )
410 	DIECASE( thermal_die )
411 	DIECASE( eweb_die )
412 
413 	default:
414 		Com_Error(ERR_DROP, "GEntity_DieFunc: case %d not handled!\n",self->e_DieFunc);
415 	}
416 }
417 
418 //////////////////// eof /////////////////////
419 
420