-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsubs.qc
212 lines (173 loc) · 4.56 KB
/
subs.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
void (entity Goal, entity AP) DoGoalWork;
void (entity Goal, entity AP) DoGroupWork;
void () SUB_Null = {
};
void (entity et, float f) SUB_Null_pain = {
};
void () SUB_Remove = {
dremove(self);
};
void () SetMovedir = {
if (self.angles == '0 -1 0')
self.movedir = '0 0 1';
else if (self.angles == '0 -2 0')
self.movedir = '0 0 -1';
else {
makevectors(self.angles);
self.movedir = v_forward;
}
self.angles = '0 0 0';
};
void () InitTrigger = {
if (self.angles != '0 0 0')
SetMovedir();
self.solid = SOLID_TRIGGER;
setmodel(self, self.model);
self.movetype = MOVETYPE_NONE;
self.modelindex = 0;
self.model = "";
};
void (vector tdest, float tspeed, void ()func) SUB_CalcMove = {
local vector vdestdelta;
local float len;
local float traveltime;
if (!tspeed)
objerror("No speed is defined!");
self.think1 = func;
self.finaldest = tdest;
self.think = SUB_CalcMoveDone;
if (tdest == self.origin) {
self.velocity = '0 0 0';
self.nextthink = self.ltime + 0.1;
return;
}
vdestdelta = tdest - self.origin;
len = vlen(vdestdelta);
traveltime = len / tspeed;
if (traveltime < 0.03)
traveltime = 0.03;
self.nextthink = self.ltime + traveltime;
self.velocity = vdestdelta * (1 / traveltime);
};
void (entity ent, vector tdest, float tspeed,
void ()func) SUB_CalcMoveEnt = {
local entity stemp;
stemp = self;
self = ent;
SUB_CalcMove(tdest, tspeed, func);
self = stemp;
};
void () SUB_CalcMoveDone = {
setorigin(self, self.finaldest);
self.velocity = '0 0 0';
self.nextthink = -1;
if (self.think1)
self.think1();
};
void (vector destangle, float tspeed, void ()func) SUB_CalcAngleMove = {
local vector destdelta;
local float len;
local float traveltime;
if (!tspeed)
objerror("No speed is defined!");
destdelta = destangle - self.angles;
len = vlen(destdelta);
traveltime = len / tspeed;
self.nextthink = self.ltime + traveltime;
self.avelocity = destdelta * (1 / traveltime);
self.think1 = func;
self.finalangle = destangle;
self.think = SUB_CalcAngleMoveDone;
};
void (entity ent, vector destangle, float tspeed,
void ()func) SUB_CalcAngleMoveEnt = {
local entity stemp;
stemp = self;
self = ent;
SUB_CalcAngleMove(destangle, tspeed, func);
self = stemp;
};
void () SUB_CalcAngleMoveDone = {
self.angles = self.finalangle;
self.avelocity = '0 0 0';
self.nextthink = -1;
if (self.think1)
self.think1();
};
void () DelayThink = {
activator = self.enemy;
SUB_UseTargets();
dremove(self);
};
void () SUB_UseTargets = {
local entity t, stemp, otemp, act;
if (self.dont_do_triggerwork) {
self.dont_do_triggerwork = FALSE;
return;
}
if (self.delay) {
t = spawn();
t.classname = "DelayedUse";
t.nextthink = time + self.delay;
t.think = DelayThink;
t.enemy = activator;
t.message = self.message;
t.killtarget = self.killtarget;
t.target = self.target;
return;
}
if ((activator.classname == "player") && (self.message != "")) {
CenterPrint(activator, self.message);
if (!self.noise)
sound(activator, CHAN_VOICE, "misc/talk.wav", 1, ATTN_NORM);
}
if (activator.classname == "player") {
DoGroupWork(self, activator);
DoGoalWork(self, activator);
}
if (self.killtarget) {
t = world;
do {
t = find(t, targetname, self.killtarget);
if (!t)
return;
remove(t);
} while (TRUE);
}
if (self.target) {
act = activator;
t = world;
do {
t = find(t, targetname, self.target);
if (!t)
return;
stemp = self;
otemp = other;
self = t;
other = stemp;
if (self.use != SUB_Null) {
if (self.use)
self.use();
}
self = stemp;
other = otemp;
activator = act;
} while (TRUE);
}
};
void (float normal) SUB_AttackFinished = {
self.cnt = 0;
if (skill < 3)
self.attack_finished = time + normal;
};
float (entity targ) visible;
void (void ()thinkst) SUB_CheckRefire = {
if (skill < 3)
return;
if (self.cnt == 1)
return;
if (!visible(self.enemy))
return;
self.cnt = 1;
self.think = thinkst;
};