]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/physics/movetypes/push.qc
Fix compile
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / physics / movetypes / push.qc
1 #include "push.qh"
2
3 void _Movetype_PushMove(entity this, float dt)  // SV_PushMove
4 {
5         if (this.move_velocity == '0 0 0' && this.move_avelocity == '0 0 0')
6         {
7                 this.move_ltime += dt;
8                 return;
9         }
10
11         switch (this.solid)
12         {
13                 // LordHavoc: valid pusher types
14                 case SOLID_BSP:
15                 case SOLID_BBOX:
16                 case SOLID_SLIDEBOX:
17                 case SOLID_CORPSE:  // LordHavoc: this would be weird...
18                         break;
19                 // LordHavoc: no collisions
20                 case SOLID_NOT:
21                 case SOLID_TRIGGER:
22                         this.move_origin = this.move_origin + dt * this.move_velocity;
23                         this.move_angles = this.move_angles + dt * this.move_avelocity;
24                         this.move_angles_x -= 360.0 * floor(this.move_angles.x * (1.0 / 360.0));
25                         this.move_angles_y -= 360.0 * floor(this.move_angles.y * (1.0 / 360.0));
26                         this.move_angles_z -= 360.0 * floor(this.move_angles.z * (1.0 / 360.0));
27                         this.move_ltime += dt;
28                         _Movetype_LinkEdict(this, true);
29                         return;
30                 default:
31                         LOG_TRACEF("_Movetype_PushMove: entity %e, unrecognized solid type %d\n", this, this.solid);
32                         return;
33         }
34
35         bool rotated = (this.move_angles * this.move_angles) + (this.move_avelocity * this.move_avelocity) > 0;
36
37         vector move1 = this.move_velocity * dt;
38         vector moveangle = this.move_avelocity * dt;
39
40         makevectors_matrix(-moveangle);
41
42 //      vector pushorig = this.move_origin;
43 //      vector pushang = this.move_angles;
44 //      float pushltime = this.move_ltime;
45
46 // move the pusher to its final position
47
48         this.move_origin = this.move_origin + dt * this.move_velocity;
49         this.move_angles = this.move_angles + dt * this.move_avelocity;
50
51         this.move_ltime += dt;
52         _Movetype_LinkEdict(this, true);
53
54         int savesolid = this.solid;
55
56         if (this.move_movetype != MOVETYPE_FAKEPUSH)
57         {
58                 for (entity check = findradius(0.5 * (this.absmin + this.absmax), 0.5 * vlen(this.absmax - this.absmin)); check; check = check.chain)
59                 {
60                         switch (check.move_movetype)
61                         {
62                                 case MOVETYPE_NONE:
63                                 case MOVETYPE_PUSH:
64                                 case MOVETYPE_FOLLOW:
65                                 case MOVETYPE_NOCLIP:
66                                 case MOVETYPE_FLY_WORLDONLY:
67                                         continue;
68                                 default:
69                                         break;
70                         }
71
72                         if (check.owner == this)
73                                 continue;
74
75                         if (this.owner == check)
76                                 continue;
77
78                         vector pivot = check.mins + 0.5 * (check.maxs - check.mins);
79                         vector move;
80                         if (rotated)
81                         {
82                                 vector org = (check.move_origin - this.move_origin) + pivot;
83                                 vector org2;
84                                 org2.x = org * v_forward;
85                                 org2.y = org * v_right;
86                                 org2.z = org * v_up;
87                                 move = (org2 - org) + move1;
88                         }
89                         else
90                         {
91                                 move = move1;
92                         }
93
94                         // physics objects need better collisions than this code can do
95                         if (check.move_movetype == 32)  // MOVETYPE_PHYSICS
96                         {
97                                 check.move_origin = check.move_origin + move;
98                                 WITH(entity, this, check, _Movetype_LinkEdict(this, true));
99                                 continue;
100                         }
101
102                         // try moving the contacted entity
103                         this.solid = SOLID_NOT;
104                         bool flag = false;
105                         WITH(entity, this, check, {
106                                 flag = _Movetype_PushEntity(this, move, true);
107                         });
108                         if (!flag)
109                         {
110                                 // entity "check" got teleported
111                                 check.move_angles_y += trace_fraction * moveangle.y;
112                                 this.solid = savesolid;
113                                 continue;  // pushed enough
114                         }
115                         // FIXME: turn players specially
116                         check.move_angles_y += trace_fraction * moveangle.y;
117                         this.solid = savesolid;
118
119                         // this trace.fraction < 1 check causes items to fall off of pushers
120                         // if they pass under or through a wall
121                         // the groundentity check causes items to fall off of ledges
122                         if (check.move_movetype != MOVETYPE_WALK && (trace_fraction < 1 || check.move_groundentity != this))
123                                 check.move_flags &= ~FL_ONGROUND;
124                 }
125         }
126
127         this.move_angles_x -= 360.0 * floor(this.move_angles.x * (1.0 / 360.0));
128         this.move_angles_y -= 360.0 * floor(this.move_angles.y * (1.0 / 360.0));
129         this.move_angles_z -= 360.0 * floor(this.move_angles.z * (1.0 / 360.0));
130 }
131
132 void _Movetype_Physics_Pusher(entity this, float dt)  // SV_Physics_Pusher
133 {
134         float oldltime = this.move_ltime;
135         float thinktime = this.move_nextthink;
136         float movetime;
137         if (thinktime < this.move_ltime + dt)
138         {
139                 movetime = thinktime - this.move_ltime;
140                 if (movetime < 0)
141                         movetime = 0;
142         }
143         else
144         {
145                 movetime = dt;
146         }
147
148         if (movetime)
149                 // advances this.move_ltime if not blocked
150                 _Movetype_PushMove(this, movetime);
151
152         if (thinktime > oldltime && thinktime <= this.move_ltime)
153         {
154                 this.move_nextthink = 0;
155                 this.move_time = time;
156                 other = world;
157                 WITH(entity, self, this, this.move_think());
158         }
159 }