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
/
g_phys.cpp
1740 lines (1501 loc) · 37 KB
/
g_phys.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-----------------------------------------------------------------------------
//
// $Logfile:: /Quake 2 Engine/Sin/code/game/g_phys.cpp $
// $Revision:: 61 $
// $Author:: Markd $
// $Date:: 11/20/98 7:17p $
//
// 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/g_phys.cpp $
//
// 61 11/20/98 7:17p Markd
// Took out G_SnapPosition
//
// 60 11/19/98 9:28p Jimdose
// fixed some more gravaxis issues
//
// 59 11/19/98 7:54p Jimdose
// Added G_SnapPosition. Fixes bug with player getting hurt when standing on
// some moving objects.
//
// 58 11/18/98 5:23a Jimdose
// G_Physics_Toss properly checks normal an alternate grav axis
//
// 57 11/16/98 9:43p Jimdose
// fixed sliding on alternate gravaxis
//
// 56 11/16/98 8:24p Markd
// fixed vehicles getting stuck
//
// 55 11/15/98 11:32p Markd
// change fat rocket behavior a bit
//
// 54 11/15/98 8:50p Jimdose
// added sv_fatrockets
// made SV_Physics_Toss do a fulltrace when sv_fatrockets is true, allowing you
// to shoot rockets and grenades through character's legs.
//
// 53 11/13/98 10:03p Jimdose
// added G_CheckWater
// G_Physics_Step now checks water
//
// 52 10/27/98 1:49a Markd
// made physics work better with waterlevel
//
// 51 10/25/98 11:57p Jimdose
// don't call animate during intermissions
//
// 50 10/18/98 8:43p Jimdose
// removed unnecessary setting or the origin and angles when bindmaster is set
// in G_RunEntity
//
// 49 10/16/98 2:21a Jimdose
// Made gravity different in water
//
// 48 10/16/98 2:09a Aldie
//
// 47 10/08/98 6:30p Markd
// Fixed TestEntityPosition
//
// 46 10/06/98 10:17p Markd
// fixed vehicle physics
//
// 45 10/04/98 10:28p Aldie
// Added multiple weapon changes. Damage, flashes, quantum stuff
//
// 44 9/22/98 10:21p Markd
// changed default vehicle clipmask
//
// 43 9/18/98 10:59p Jimdose
// made pointcontents test in G_Physics_Toss use worldorigin
//
// 42 9/15/98 3:49p Markd
// Put blocking functionality into MOVETYPE_VEHICLES
//
// 41 9/14/98 6:12p Markd
// Added MOVETYPE_VEHICLE
//
// 40 8/31/98 7:45p Aldie
// Updated surface data structure and removed surfinfo field
//
// 39 8/29/98 9:42p Jimdose
// Made all function names consistantly begin with G_
// Added call info to G_Trace
//
// 38 8/27/98 9:05p Jimdose
// Moved STEPSIZE definition to g_local.h
//
// 37 8/22/98 9:36p Jimdose
// Added support for alternate gravity axis
//
// 36 8/18/98 11:50p Jimdose
// Made G_PushEntity so that the entity doesn't touch itself
//
// 35 8/18/98 11:08p Markd
// Added new Alias System
//
// 34 7/25/98 8:38p Markd
// put in landing sound
//
// 33 7/18/98 8:27p Jimdose
// Fixed sliding bug with entities standing on rotating entities
//
// 32 7/11/98 8:23p Jimdose
// G_Push does one less setorigin
//
// 31 7/09/98 9:38p Jimdose
// Changed calls to getLocalVector to getParentVector
// Removed quantization of move to 1/8 of a unit from G_Push
//
// 30 7/02/98 7:58p Markd
// When MOVETYPE_BOUNCE We still rotate if avelocity is non-zero
//
// 29 6/27/98 2:16p Aldie
// Changed some sliding stuff
//
// 28 6/09/98 4:19p Jimdose
// worked on ai
//
// 27 6/08/98 11:35a Aldie
// Added some slide move stuff
//
// 26 5/26/98 1:54a Markd
// Put in default water transition sounds
//
// 25 5/25/98 6:47p Jimdose
// Made animateframe, prethink and posthink into functions built into the base
// entity class
//
// 24 5/24/98 8:46p Jimdose
// Made a lot of functions more str-friendly.
// Got rid of a lot of char * based strings
// Cleaned up get spawn arg functions and sound functions
// sound functions now use consistant syntax
//
// 23 5/22/98 7:18p Jimdose
// Working on ai stuff
//
// 22 5/14/98 10:12p Jimdose
// Added extended result information for G_Movestep
//
// 21 5/03/98 4:32p Jimdose
// Changed Vector class
//
// 20 5/02/98 12:02a Jimdose
// added groundplane, groundsurface, groundcontents
// added current and conveyors to non-player entities
//
// 19 4/30/98 4:48p Jimdose
// G_Push no longer gets blocked by SOLID_TRIGGER or SOLID_NOT
//
// 18 4/20/98 2:45p Jimdose
// working on ai
//
// 17 4/18/98 3:04p Jimdose
// Made G_Physics_Toss properly update angles using setAngles
// working on ai
//
// 16 4/16/98 2:03p Jimdose
// Added G_TestMovestep
//
// 15 4/10/98 4:56p Jimdose
// only play water transitition sound on ents with mass of 0 or spawntime older
// than FRAMETIME
//
// 14 4/09/98 3:32p Jimdose
// G_RunEntity now does a setOrigin and setAngle on bound entities to keep
// their worldorigin and worlangles up to date
//
// 13 4/04/98 6:04p Jimdose
// cleared out level.impact_trace after impact
//
// 12 3/31/98 1:04a Jimdose
// Added monster movement code
//
// 11 3/30/98 2:42p Jimdose
// Made stepmove take the animation delta into account
//
// 10 3/26/98 8:20p Jimdose
// Made groundentity an edict_t *
// Changed landing sound
//
// 9 3/24/98 7:35p Jimdose
// Made change to try to fix problem where non-solid entities were being
// blocked by solid ones.
//
// 8 3/23/98 1:31p Jimdose
// Revamped event and command system
//
// 7 3/18/98 7:15p Markd
// Changed sound code call in game.h
//
// 6 3/04/98 8:01p Aldie
// More support for damage surfaces.
//
// 5 2/21/98 1:15p Jimdose
// Added G_TestMove and G_TestStepMove for use in pathfinding code
//
// 4 2/16/98 2:25p Jimdose
// Added G_PushMove to allow non-physics functions to push an entity into
// place without having to use setOrigin or messing with velocities.
// Added hierarchial object binding. Lots of changes all over the place.
//
// 3 2/06/98 5:52p Jimdose
// Converted physics to be c++
//
// 2 2/03/98 11:05a Jimdose
// In process of converting to work with Sin progs
//
// 1 1/26/98 5:48p Jimdose
//
// 3 12/30/97 6:04p Jimdose
// Added header text
//
// DESCRIPTION:
//
#include "g_local.h"
#include "sentient.h"
#include "actor.h"
extern cvar_t *sv_fatrockets;
/*
pushmove objects do not obey gravity, and do not interact with each other or trigger fields, but block normal movement and push normal objects when they move.
onground is set for toss objects when they come to a complete rest. it is set for steping or walking objects
doors, plats, etc are SOLID_BSP, and MOVETYPE_PUSH
bonus items are SOLID_TRIGGER touch, and MOVETYPE_TOSS
corpses are SOLID_NOT and MOVETYPE_TOSS
crates are SOLID_BBOX and MOVETYPE_TOSS
walking monsters are SOLID_SLIDEBOX and MOVETYPE_STEP
flying/floating monsters are SOLID_SLIDEBOX and MOVETYPE_FLY
solid_edge items only clip against bsp models.
*/
typedef struct
{
Entity *ent;
Vector origin;
Vector worldorigin;
Vector angles;
Vector worldangles;
float deltayaw;
} pushed_t;
pushed_t pushed[ MAX_EDICTS ];
pushed_t *pushed_p;
Entity *obstacle;
/*
============
G_TestEntityPosition
============
*/
Entity *G_TestEntityPosition
(
Entity *ent
)
{
int mask;
trace_t trace;
mask = ent->edict->clipmask;
if ( !mask )
mask = MASK_SOLID;
trace = G_Trace( ent->worldorigin, ent->mins, ent->maxs, ent->worldorigin, ent, mask, "G_TestEntityPosition" );
if ( trace.startsolid )
{
//return g_edicts->entity;
assert( trace.ent->entity );
return trace.ent->entity;
}
return NULL;
}
/*
================
G_CheckVelocity
================
*/
void G_CheckVelocity
(
Entity *ent
)
{
int i;
//
// bound velocity
//
for( i = 0; i < 3; i++ )
{
if ( ent->velocity[ i ] > sv_maxvelocity->value )
{
ent->velocity[ i ] = sv_maxvelocity->value;
}
else if ( ent->velocity[ i ] < -sv_maxvelocity->value )
{
ent->velocity[ i ] = -sv_maxvelocity->value;
}
}
}
/*
==================
G_Impact
Two entities have touched, so run their touch functions
==================
*/
void G_Impact
(
Entity *e1,
trace_t *trace
)
{
edict_t *e2;
Event *ev;
qboolean doImpactDamage=false;
e2 = trace->ent;
if ( ( e1->movetype == MOVETYPE_HURL ) || ( e2->entity->movetype == MOVETYPE_HURL ) )
{
doImpactDamage = true;
}
//FIXME - this should be passed in the event.
level.impact_trace = *trace;
if ( e1->edict->solid != SOLID_NOT )
{
ev = new Event( EV_Touch );
ev->AddEntity( e2->entity );
e1->ProcessEvent( ev );
if ( doImpactDamage )
{
ev = new Event( EV_Sentient_ImpactDamage );
e1->ProcessEvent( ev );
}
}
if ( e2->entity && e2->solid != SOLID_NOT )
{
ev = new Event( EV_Touch );
ev->AddEntity( e1 );
e2->entity->ProcessEvent( ev );
if ( doImpactDamage )
{
ev = new Event( EV_Sentient_ImpactDamage );
e2->entity->ProcessEvent( ev );
}
}
memset( &level.impact_trace, 0, sizeof( level.impact_trace ) );
}
/*
=============
G_AddCurrents
=============
*/
void G_AddCurrents
(
Entity *ent,
Vector *basevel
)
{
float speed;
csurface_t *surface;
float angle;
Vector vel;
vel = vec_zero;
//
// add water currents
//
if ( ent->watertype & MASK_CURRENT )
{
speed = sv_waterspeed->value;
if ( ( ent->waterlevel == 1 ) && ( ent->groundentity ) )
{
speed /= 2;
}
if ( ent->watertype & CONTENTS_CURRENT_0 )
{
vel[ 0 ] += speed;
}
if ( ent->watertype & CONTENTS_CURRENT_90 )
{
vel[ 1 ] += speed;
}
if ( ent->watertype & CONTENTS_CURRENT_180 )
{
vel[ 0 ] -= speed;
}
if ( ent->watertype & CONTENTS_CURRENT_270 )
{
vel[ 1 ] -= speed;
}
if ( ent->watertype & CONTENTS_CURRENT_UP )
{
vel[ 2 ] += speed;
}
if ( ent->watertype & CONTENTS_CURRENT_DOWN )
{
vel[ 2 ] -= speed;
}
}
//
// add conveyor belt velocities
//
if ( ent->groundentity && ent->groundsurface )
{
surface = ent->groundsurface;
if ( ( surface->flags & SURF_CONVEYOR ) && ( surface->flags & SURF_TRANSLATE ) )
{
angle = surface->trans_angle * ( 3.14159 / 180.0 );
vel[ 0 ] += -cos( angle ) * surface->trans_mag;
vel[ 1 ] += sin( angle ) * surface->trans_mag;
}
}
*basevel = vel;
}
/*
==================
G_ClipVelocity
Slide off of the impacting object
returns the blocked flags (1 = floor, 2 = step / wall)
==================
*/
#define STOP_EPSILON 0.1
int G_ClipVelocity
(
Vector& in,
Vector& normal,
Vector& out,
float overbounce,
int gravaxis
)
{
int i;
int blocked;
float backoff;
blocked = 0;
if ( ( normal[ gravity_axis[ gravaxis ].z ] * gravity_axis[ gravaxis ].sign ) > 0 )
{
// floor
blocked |= 1;
}
if ( !normal[ gravity_axis[ gravaxis ].z ] )
{
// step
blocked |= 2;
}
backoff = ( in * normal ) * overbounce;
out = in - normal * backoff;
for( i = 0; i < 3; i++ )
{
if ( out[ i ] > -STOP_EPSILON && out[ i ] < STOP_EPSILON )
{
out[ i ] = 0;
}
}
return blocked;
}
/*
============
G_FlyMove
The basic solid body movement clip that slides along multiple planes
Returns the clipflags if the velocity was modified (hit something solid)
1 = floor
2 = wall / step
4 = dead stop
============
*/
#define MAX_CLIP_PLANES 5
int G_FlyMove
(
Entity *ent,
Vector basevel,
float time,
int mask
)
{
Entity *hit;
edict_t *edict;
int bumpcount, numbumps;
Vector dir;
float d;
int numplanes;
vec3_t planes[ MAX_CLIP_PLANES ];
Vector primal_velocity, original_velocity, new_velocity;
int i, j;
trace_t trace;
Vector end;
float time_left;
int blocked;
#if 0
Vector move;
Vector v;
#endif
edict = ent->edict;
numbumps = 4;
blocked = 0;
original_velocity = ent->velocity;
primal_velocity = ent->velocity;
numplanes = 0;
#if 1
time_left = time;
#else
time_left = 1.0;//time;
v = ent->total_delta;
v[ 1 ] = -v[ 1 ]; // sigh...
MatrixTransformVector( v.vec3(), ent->orientation, move.vec3() );
move += ent->velocity * time;
ent->total_delta = vec_zero;
#endif
ent->groundentity = NULL;
for( bumpcount = 0; bumpcount < numbumps; bumpcount++ )
{
#if 1
end = ent->worldorigin + time_left * ( ent->velocity + basevel );
#else
end = ent->worldorigin + time_left * move;
#endif
trace = G_Trace( ent->worldorigin, ent->mins, ent->maxs, end, ent, mask, "G_FlyMove" );
if (
( trace.allsolid ) ||
(
( trace.startsolid ) &&
( ent->movetype == MOVETYPE_VEHICLE )
)
)
{
// entity is trapped in another solid
ent->velocity = vec_zero;
return 3;
}
if ( trace.fraction > 0 )
{
// actually covered some distance
ent->setOrigin( trace.endpos );
original_velocity = ent->velocity;
numplanes = 0;
}
if ( trace.fraction == 1 )
{
// moved the entire distance
break;
}
hit = trace.ent->entity;
if ( trace.plane.normal[ 2 ] > 0.7 )
{
// floor
blocked |= 1;
if ( hit->getSolidType() == SOLID_BSP )
{
ent->groundentity = hit->edict;
ent->groundentity_linkcount = hit->edict->linkcount;
ent->groundplane = trace.plane;
ent->groundsurface = trace.surface;
ent->groundcontents = trace.contents;
}
}
if ( !trace.plane.normal[ 2 ] )
{
// step
blocked |= 2;
}
//
// run the impact function
//
G_Impact( ent, &trace );
if ( !edict->inuse )
{
break; // removed by the impact function
}
time_left -= time_left * trace.fraction;
// cliped to another plane
if ( numplanes >= MAX_CLIP_PLANES )
{
// this shouldn't really happen
ent->velocity = vec_zero;
return 3;
}
VectorCopy( trace.plane.normal, planes[ numplanes ] );
numplanes++;
//
// modify original_velocity so it parallels all of the clip planes
//
for( i = 0; i < numplanes; i++ )
{
G_ClipVelocity( original_velocity, Vector( planes[ i ] ), new_velocity, 1.01, ent->gravaxis );
for( j = 0; j < numplanes; j++ )
{
if ( j != i )
{
if ( ( new_velocity * planes[ j ] ) < 0 )
{
// not ok
break;
}
}
}
if ( j == numplanes )
{
break;
}
}
if ( i != numplanes )
{
// go along this plane
ent->velocity = new_velocity;
}
else
{
// go along the crease
if ( numplanes != 2 )
{
ent->velocity = vec_zero;
return 7;
}
CrossProduct( planes[ 0 ], planes[ 1 ], dir.vec3() );
d = dir * ent->velocity;
ent->velocity = dir * d;
}
//
// if original velocity is against the original velocity, stop dead
// to avoid tiny occilations in sloping corners
//
if ( ( ent->velocity * primal_velocity ) <= 0 )
{
ent->velocity = vec_zero;
return blocked;
}
}
return blocked;
}
/*
============
G_AddGravity
============
*/
void G_AddGravity
(
Entity *ent
)
{
float grav;
if ( ent->waterlevel > 2 )
{
grav = ent->gravity * 60 * FRAMETIME * gravity_axis[ ent->gravaxis ].sign;
}
else
{
grav = ent->gravity * sv_gravity->value * FRAMETIME * gravity_axis[ ent->gravaxis ].sign;
}
ent->velocity[ gravity_axis[ ent->gravaxis ].z ] -= grav;
}
/*
===============================================================================
PUSHMOVE
===============================================================================
*/
/*
============
G_PushEntity
Does not change the entities velocity at all
============
*/
trace_t G_PushEntity
(
Entity *ent,
Vector push
)
{
trace_t trace;
Vector start;
Vector end;
int mask;
edict_t *edict;
start = ent->worldorigin;
end = start + push;
retry:
if ( ent->edict->clipmask )
{
mask = ent->edict->clipmask;
}
else
{
mask = MASK_SOLID;
}
if ( !sv_fatrockets->value && ( ent->flags & FL_FATPROJECTILE ) )
{
trace = G_FullTrace( start, ent->mins, ent->maxs, end, ent->maxs.y, ent, mask, "G_PushEntity" );
}
else
{
trace = G_Trace( start, ent->mins, ent->maxs, end, ent, mask, "G_PushEntity" );
}
edict = ent->edict;
ent->setOrigin( trace.endpos );
if ( trace.fraction != 1.0 )
{
G_Impact( ent, &trace );
// if the pushed entity went away and the pusher is still there
if ( !trace.ent->inuse && edict->inuse )
{
// move the pusher back and try again
ent->setOrigin( start );
goto retry;
}
}
if ( edict && ( edict != ent->edict ) )
{
G_TouchTriggers( ent );
}
return trace;
}
/*
============
G_SlideEntity
============
*/
trace_t G_SlideEntity
(
Entity *ent,
Vector push
)
{
trace_t trace;
Vector start;
Vector end;
int mask;
edict_t *edict;
start = ent->worldorigin;
end = start + push;
if ( ent->edict->clipmask )
{
mask = ent->edict->clipmask;
}
else
{
mask = MASK_SOLID;
}
trace = G_Trace( start, ent->mins, ent->maxs, end, ent, mask, "G_SlideEntity" );
edict = ent->edict;
ent->setOrigin( trace.endpos );
return trace;
}
/*
================
G_SnapPosition
================
*/
/*
qboolean G_SnapPosition
(
Entity *ent
)
{
int x, y, z;
Vector offset( 0, -1, 1 );
Vector base;
base = ent->worldorigin;
for ( z = 0; z < 3; z++ )
{
ent->worldorigin.z = base.z + offset[ z ];
for ( y = 0; y < 3; y++ )
{
ent->worldorigin.y = base.y + offset[ y ];
for ( x = 0; x < 3; x++ )
{
ent->worldorigin.x = base.x + offset[ x ];
if ( G_TestEntityPosition( ent ) )
{
ent->origin.x += offset[ x ];
ent->origin.y += offset[ y ];
ent->origin.z += offset[ z ];
ent->setOrigin( ent->origin );
return true;
}
}
}
}
// can't find a good position, so put him back.
ent->worldorigin = base;
return false;
}
*/
/*
============
G_Push
Objects need to be moved back on a failed push,
otherwise riders would continue to slide.
============
*/
qboolean G_Push
(
Entity *pusher,
Vector pushermove,
Vector pusheramove
)
{
Entity *check, *block;
edict_t *edict, *next;
Vector move, amove;
Vector mins, maxs;
Vector save;
pushed_t *p;
Vector org, org2, move2;
float mat[ 3 ][ 3 ];
pushed_t *pusher_p;
// save the pusher's original position
pusher_p = pushed_p;
pushed_p->ent = pusher;
pushed_p->origin = pusher->origin;
pushed_p->worldorigin = pusher->worldorigin;
pushed_p->angles = pusher->angles;
pushed_p->worldangles = pusher->worldangles;
if ( pusher->client )
{
pushed_p->deltayaw = pusher->client->ps.pmove.delta_angles[ YAW ];
}
pushed_p++;
if ( pushed_p >= &pushed[ MAX_EDICTS ] )
{
gi.error( ERR_FATAL, "Pushed too many entities." );
}
// move the pusher to it's final position
pusher->setAngles( pusher->angles + pusheramove );
pusher->setOrigin( pusher->origin + pushermove );
if ( pusher->edict->solid == SOLID_NOT )
{
// Doesn't push anything
return true;
}
// change the move to worldspace
move = pusher->worldorigin - pusher_p->worldorigin;
amove = pusher->worldangles - pusher_p->worldangles;
// we need this for pushing things later
AnglesToMat( amove.vec3(), mat );
// find the bounding box
mins = pusher->absmin;
maxs = pusher->absmax;
// see if any solid entities are inside the final position
for( edict = g_edicts->next; edict != &active_edicts; edict = next )
{
assert( edict );
assert( edict->inuse );
assert( edict->entity );
next = edict->next;
check = edict->entity;
if ( check->movetype == MOVETYPE_PUSH ||
check->movetype == MOVETYPE_STOP ||
check->movetype == MOVETYPE_NONE ||
check->movetype == MOVETYPE_NOCLIP )
{
continue;
}
// if the entity is standing on the pusher, it will definitely be moved
if ( check->groundentity != pusher->edict )
{
// Only move triggers and non-solid objects if they're sitting on a moving object
if ( check->edict->solid == SOLID_TRIGGER || check->edict->solid == SOLID_NOT )
{
continue;
}
// see if the ent needs to be tested
if ( check->absmin[ 0 ] >= maxs[ 0 ] ||
check->absmin[ 1 ] >= maxs[ 1 ] ||
check->absmin[ 2 ] >= maxs[ 2 ] ||
check->absmax[ 0 ] <= mins[ 0 ] ||
check->absmax[ 1 ] <= mins[ 1 ] ||
check->absmax[ 2 ] <= mins[ 2 ] )
{
continue;
}
// see if the ent's bbox is inside the pusher's final position
if ( !G_TestEntityPosition( check ) )
{
continue;
}
}