forked from fabiolimamp/alkaline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove.qc
241 lines (176 loc) · 4.29 KB
/
move.qc
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
void() bumperThink = {
if (self.owner.nextbumper.classname != "bumper") {
remove(self);
return;
}
float wasonground = self.flags & FL_ONGROUND;
vector neworigin;
neworigin = self.owner.origin + self.view_ofs;
if (wasonground && self.owner.flags & FL_ONGROUND) {
neworigin_z = self.origin_z;
}
setorigin(self, neworigin);
if (wasonground) {
self.flags = self.flags | FL_ONGROUND;
//droptofloor();
}
self.nextthink = time + 0.05;
}
void(vector ofs, float fly) SUB_AddBumper = {
entity e, last;
e = spawn();
e.classname = "bumper";
e.owner = self;
e.movetype = MOVETYPE_STEP;
//e.solid = SOLID_BBOX;
e.flags = self.flags & (FL_FLY | FL_SWIM);
if (fly) e.flags = e.flags | FL_FLY;
e.view_ofs = ofs;
e.think = bumperThink;
e.nextthink = time + 0.05;
setorigin(e, self.origin + ofs);
last = self;
while (last.nextbumper)
last = last.nextbumper;
last.nextbumper = e;
};
void() SUB_ClearBumpers = {
entity e, eprev;
e = self.nextbumper;
while (e) {
eprev = e;
e = e.nextbumper;
remove(eprev);
}
self.nextbumper = world;
}
/*
======================
StepDirection
Turns to the movement direction, and walks the current distance if
facing it.
======================
*/
float(float yaw, float dist) walkmove2 = {
if (!self.nextbumper)
return walkmove(yaw, dist);
entity oself, bp;
float movefail;
bp = self;
while (bp) {
bp.oldorigin = bp.origin;
oself = self;
self = bp;
movefail = movefail | !walkmove(yaw, dist);
self = oself;
bp = bp.nextbumper;
}
if (movefail) {
bp = self;
while (bp) {
setorigin(bp, bp.oldorigin);
bp = bp.nextbumper;
}
return FALSE;
}
return TRUE;
}
float(float yaw, float dist) StepDirection = {
float delta;
self.ideal_yaw = yaw;
ChangeYaw();
delta = self.angles_y - self.ideal_yaw;
if (delta > 45 && delta < 315)
// not turned far enough, so don't take the step
return TRUE;
if (walkmove2(yaw, dist))
return TRUE;
return FALSE;
}
float DI_NODIR = -1;
void(entity enm, float dist) NewChaseDir = {
float deltax,deltay;
vector d;
float tdir, olddir, turnaround;
olddir = anglemod((self.ideal_yaw/45)*45);
turnaround = anglemod(olddir - 180);
deltax = enm.origin_x - self.origin_x;
deltay = enm.origin_y - self.origin_y;
if (deltax > 10)
d_x = 0;
else if (deltax < -10)
d_x = 180;
else
d_x = DI_NODIR;
if (deltay < -10)
d_y = 270;
else if (deltay > 10)
d_y = 90;
else
d_y = DI_NODIR;
// try direct route
if (d_x != DI_NODIR && d_y != DI_NODIR) {
if (d_x == 0)
tdir = d_y == 90 ? 45 : 315;
else
tdir = d_y == 90 ? 135 : 215;
if (tdir != turnaround && StepDirection(tdir, dist))
return;
}
// try other directions
if (random() < 0.333 || fabs(deltay) > fabs(deltax)) {
tdir = d_x;
d_x = d_y;
d_y = tdir;
}
if (d_x != DI_NODIR && d_x != turnaround && StepDirection(d_x, dist))
return;
if (d_y != DI_NODIR && d_y != turnaround && StepDirection(d_y, dist))
return;
/* there is no direct path to the player, so pick another direction */
if (olddir != DI_NODIR && StepDirection(olddir, dist))
return;
if (random() < 0.5) { /*randomly determine direction of search*/
for (tdir = 0; tdir <= 315; tdir += 45)
if (tdir != turnaround && StepDirection(tdir, dist)) return;
}
else {
for (tdir = 315 ; tdir >= 0 ; tdir -= 45)
if (tdir != turnaround && StepDirection(tdir, dist)) return;
}
if (turnaround != DI_NODIR && StepDirection(turnaround, dist) )
return;
self.ideal_yaw = olddir; // can't move
// if a bridge was pulled out from underneath a monster, it may not have
// a valid standing position at all
if (!checkbottom(self))
self.flags = self.flags & FL_PARTIALGROUND;
}
float(entity goal, float dist) CloseEnough = {
float i;
for (i = 0; i < 3; i++)
{
if (goal.absmin[i] > self.absmax[i] + dist)
return FALSE;
if (goal.absmax[i] < self.absmin[i] - dist)
return FALSE;
}
return TRUE;
}
void(float dist) movetogoal2 = {
if (!self.nextbumper) {
movetogoal(dist);
return;
}
entity goal;
goal = self.goalentity;
if (!(self.flags & (FL_ONGROUND|FL_FLY|FL_SWIM)))
return;
// if the next step hits the enemy, return immediately
if (self.enemy && CloseEnough(goal, dist))
return;
// bump around...
if ((random() < 0.333) || !StepDirection(self.ideal_yaw, dist)) {
NewChaseDir(goal, dist);
}
}