This repository has been archived by the owner on Sep 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gibs.cpp
301 lines (262 loc) · 6.66 KB
/
gibs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
//-----------------------------------------------------------------------------
//
// $Logfile:: /Quake 2 Engine/Sin/code/game/gibs.cpp $
// $Revision:: 21 $
// $Author:: Jimdose $
// $Date:: 11/19/98 9:29p $
//
// Copyright (C) 1998 by Ritual Entertainment, Inc.
// All rights reserved.
//
// This source is may not be distributed and/or modified without
// expressly written permission by Ritual Entertainment, Inc.
//
// $Log:: /Quake 2 Engine/Sin/code/game/gibs.cpp $
//
// 21 11/19/98 9:29p Jimdose
// gibs copy gravaxis
//
// 20 11/09/98 1:09a Aldie
// Changed fadesplat to fade in 30 secs
//
// 19 11/08/98 8:31p Aldie
// Added ability to not fade splats
//
// 18 10/22/98 9:30p Aldie
// Modified gib physics a little
//
// 17 10/07/98 11:51p Jimdose
// moved body_parts out of game structure
//
// 16 9/22/98 5:26p Markd
// fixed small gib bug
//
// 15 9/22/98 5:19p Markd
// Put in new consolidated gib function
//
// 14 9/20/98 5:11p Aldie
// Added blood trail to gib constructor
//
// 13 8/29/98 9:43p Jimdose
// Added call info to G_Trace
//
// 12 8/27/98 9:02p Jimdose
// Changed centroid to a variable
//
// 11 8/19/98 8:49p Aldie
// Increased gibbage velocity
//
// 10 8/10/98 6:52p Aldie
// Changed the gib throwing code
//
// 9 7/29/98 2:31p Aldie
// Changed health to a float
//
// 8 7/26/98 3:58p Aldie
// Reversed a logic bug
//
// 7 7/25/98 8:39p Aldie
// Bloodsplat only in single player
//
// 6 7/24/98 10:04p Aldie
// Changed the gibs layout
//
// 5 7/23/98 6:55p Aldie
// Fun with gibs
//
// 4 7/23/98 6:17p Aldie
// Updated damage system and fixed some damage related bugs. Also put tracers
// back to the way they were, and added gib event to funcscriptmodels
//
// 3 6/30/98 12:40p Aldie
// Changed bloodsplat scale.
//
// 2 5/27/98 5:03a Aldie
// First version of gibs
//
// DESCRIPTION:
// Gibs - nuff said
#include "gibs.h"
const char *body_parts[] =
{
"gib1.def", "gibtorso.def", "gibhead.def", "gibleg.def"
//"gib1.def", "gib2.def", "gibhead.def", "gibleg.def", "gibarm.def", "gibribs.def"
};
const int num_body_parts = ( sizeof( body_parts ) / sizeof( body_parts[ 0 ] ) );
CLASS_DECLARATION( Entity, Gib, "gib" );
Event EV_ThrowGib("throwgib");
ResponseDef Gib::Responses[] =
{
{ &EV_ThrowGib, ( Response )Gib::Throw },
{ &EV_Touch, ( Response )Gib::Splat },
{ NULL, NULL }
};
Gib::Gib
(
const char *name,
qboolean blood_trail
)
{
setSize("0 0 0", "0 0 0");
setModel(name);
setMoveType( MOVETYPE_BOUNCE );
setSolidType( SOLID_BBOX );
if ( blood_trail )
edict->s.effects |= EF_GIB;
sprayed = false;
fadesplat = true;
}
Gib::Gib()
{
setSize("0 0 0", "0 0 0");
setModel("gib1.def");
setMoveType( MOVETYPE_BOUNCE );
setSolidType( SOLID_BBOX );
edict->s.effects |= EF_GIB;
sprayed = false;
fadesplat = true;
}
void Gib::Splat
(
Event *ev
)
{
Vector end;
if (deathmatch->value)
return;
if (!sv_gore->value)
return;
if (sprayed)
return;
sprayed = true;
end = origin;
end.z -= 1024;
SprayBlood(origin, end, 25);
setSolidType(SOLID_NOT);
}
void Gib::SprayBlood
(
Vector start,
Vector end,
int damage
)
{
trace_t trace;
float dist;
float scale;
Entity *splat;
Vector norm;
trace = G_Trace( start, vec_zero, vec_zero, end, NULL, MASK_SOLIDNONFENCE, "Gib::SprayBlood" );
if ( HitSky( &trace ) || ( trace.ent->solid != SOLID_BSP ) )
{
return;
}
dist = ( Vector( trace.endpos ) - start ).length();
scale = ( float )damage / ( dist * 0.3 );
if ( scale > 0.6 )
{
scale = 0.6;
}
if ( scale < 0.02 )
{
return;
}
// Do a bloodsplat
splat = new Entity;
splat->setMoveType( MOVETYPE_NONE );
splat->setSolidType( SOLID_NOT );
splat->setModel( "sprites/bloodsplat.spr" );
splat->edict->s.frame = G_Random( 4 );
splat->setSize( "0 0 0", "0 0 0" );
splat->edict->s.scale = scale * this->edict->s.scale;
norm = trace.plane.normal;
norm.x = -norm.x;
norm.y = -norm.y;
splat->angles = norm.toAngles();
splat->angles.z = G_Random( 360 );
splat->setAngles( splat->angles );
splat->setOrigin( Vector( trace.endpos ) + ( Vector( trace.plane.normal ) * 0.2 ) );
if ( fadesplat )
splat->PostEvent( EV_FadeOut, 3 );
else
splat->PostEvent( EV_FadeOut, 30 );
}
void Gib::ClipGibVelocity
(
void
)
{
if (velocity[0] < -400)
velocity[0] = -400;
else if (velocity[0] > 400)
velocity[0] = 400;
if (velocity[1] < -400)
velocity[1] = -400;
else if (velocity[1] > 400)
velocity[1] = 400;
if (velocity[2] < 200)
velocity[2] = 200; // always some upwards
else if (velocity[2] > 600)
velocity[2] = 600;
}
void Gib::SetVelocity
(
float damage
)
{
velocity[0] = 100.0 * crandom();
velocity[1] = 100.0 * crandom();
velocity[2] = 200.0 + 100.0 * random();
avelocity = Vector( G_Random( 600 ), G_Random( 600 ), G_Random( 600 ) );
if ( ( damage < -150 ) && ( G_Random() > 0.95f ) )
velocity *= 2.0f;
else if ( damage < -100 )
velocity *= 1.5f;
ClipGibVelocity();
}
void Gib::Throw
(
Event *ev
)
{
Entity *ent;
ent = ev->GetEntity(1);
setOrigin(ent->centroid);
worldorigin.copyTo(edict->s.old_origin);
SetVelocity(ev->GetInteger(2));
edict->s.scale = ev->GetFloat(3);
PostEvent(EV_FadeOut, 10 + G_Random(5));
}
void CreateGibs
(
Entity * ent,
float damage,
float scale,
int num,
const char * modelname
)
{
int i;
Gib * gib;
assert( ent );
if ( !ent )
return;
ent->RandomGlobalSound( "impact_gib" );
for ( i = 0; i < num; i++ )
{
if ( modelname )
{
gib = new Gib( modelname );
}
else
{
gib = new Gib( body_parts[ i % num_body_parts ] );
}
gib->setOrigin(ent->centroid);
gib->worldorigin.copyTo(gib->edict->s.old_origin);
gib->SetVelocity( damage );
gib->edict->s.scale = scale + G_Random( scale * 0.3 );
gib->SetGravityAxis( ent->gravaxis );
gib->PostEvent(EV_FadeOut, 10 + G_Random(5));
}
}