1 // player animation data for this model
2 // each vector is as follows:
6 .vector anim_die1; // player dies
7 .vector anim_die2; // player dies differently
8 .vector anim_draw; // player pulls out a weapon
9 .vector anim_duckwalk; // player walking while crouching
10 .vector anim_duckjump; // player jumping from a crouch
11 .vector anim_duckidle; // player idling while crouching
12 .vector anim_idle; // player standing
13 .vector anim_jump; // player jump
14 .vector anim_pain1; // player flinches from pain
15 .vector anim_pain2; // player flinches from pain, differently
16 .vector anim_shoot; // player shoots
17 .vector anim_taunt; // player taunts others (FIXME: no code references this)
18 .vector anim_run; // player running forward
19 .vector anim_runbackwards; // player running backward
20 .vector anim_strafeleft; // player shuffling left quickly
21 .vector anim_straferight; // player shuffling right quickly
22 .vector anim_forwardright; // player running forward and right
23 .vector anim_forwardleft; // player running forward and left
24 .vector anim_backright; // player running backward and right
25 .vector anim_backleft; // player running back and left
26 .vector anim_melee; // player doing the melee action
27 .vector anim_duck; // player doing the melee action
28 .vector anim_duckwalkbackwards;
29 .vector anim_duckwalkstrafeleft;
30 .vector anim_duckwalkstraferight;
31 .vector anim_duckwalkforwardright;
32 .vector anim_duckwalkforwardleft;
33 .vector anim_duckwalkbackright;
34 .vector anim_duckwalkbackleft;
35 .float animdecide_modelindex;
37 void animdecide_init(entity e)
39 if(e.modelindex == e.animdecide_modelindex)
41 e.animdecide_modelindex = e.modelindex;
43 vector none = '0 0 0';
44 e.anim_die1 = animfixfps(e, '0 1 0.5', none); // 2 seconds
45 e.anim_die2 = animfixfps(e, '1 1 0.5', none); // 2 seconds
46 e.anim_draw = animfixfps(e, '2 1 3', none);
47 e.anim_duckwalk = animfixfps(e, '4 1 1', none);
48 e.anim_duckjump = animfixfps(e, '5 1 10', none);
49 e.anim_duckidle = animfixfps(e, '6 1 1', none);
50 e.anim_idle = animfixfps(e, '7 1 1', none);
51 e.anim_jump = animfixfps(e, '8 1 10', none);
52 e.anim_pain1 = animfixfps(e, '9 1 2', none); // 0.5 seconds
53 e.anim_pain2 = animfixfps(e, '10 1 2', none); // 0.5 seconds
54 e.anim_shoot = animfixfps(e, '11 1 5', none); // analyze models and set framerate
55 e.anim_taunt = animfixfps(e, '12 1 0.33', none);
56 e.anim_run = animfixfps(e, '13 1 1', none);
57 e.anim_runbackwards = animfixfps(e, '14 1 1', none);
58 e.anim_strafeleft = animfixfps(e, '15 1 1', none);
59 e.anim_straferight = animfixfps(e, '16 1 1', none);
60 e.anim_forwardright = animfixfps(e, '19 1 1', '16 1 1');
61 e.anim_forwardleft = animfixfps(e, '20 1 1', '15 1 1');
62 e.anim_backright = animfixfps(e, '21 1 1', '16 1 1');
63 e.anim_backleft = animfixfps(e, '22 1 1', '15 1 1');
64 e.anim_melee = animfixfps(e, '23 1 1', '11 1 1');
65 e.anim_duckwalkbackwards = animfixfps(e, '24 1 1', '4 1 1');
66 e.anim_duckwalkstrafeleft = animfixfps(e, '25 1 1', '4 1 1');
67 e.anim_duckwalkstraferight = animfixfps(e, '26 1 1', '4 1 1');
68 e.anim_duckwalkforwardright = animfixfps(e, '27 1 1', '4 1 1');
69 e.anim_duckwalkforwardleft = animfixfps(e, '28 1 1', '4 1 1');
70 e.anim_duckwalkbackright = animfixfps(e, '29 1 1', '4 1 1');
71 e.anim_duckwalkbackleft = animfixfps(e, '30 1 1', '4 1 1');
73 // these anims ought to stay until stopped explicitly by weaponsystem
74 e.anim_shoot_z = 0.001;
75 e.anim_melee_z = 0.001;
78 #define ANIMPRIO_IDLE 0
79 #define ANIMPRIO_ACTIVE 1
80 #define ANIMPRIO_CROUCH 2
81 #define ANIMPRIO_DEAD 3
83 vector animdecide_getupperanim(entity e)
86 if(e.anim_state & ANIMSTATE_FROZEN)
87 return vec3(e.anim_idle_x, e.anim_time, ANIMPRIO_DEAD);
88 if(e.anim_state & ANIMSTATE_DEAD1)
89 return vec3(e.anim_die1_x, e.anim_time, ANIMPRIO_DEAD);
90 if(e.anim_state & ANIMSTATE_DEAD2)
91 return vec3(e.anim_die2_x, e.anim_time, ANIMPRIO_DEAD);
93 // is there an action?
94 vector outframe = '-1 0 0';
96 if(e.anim_upper_time >= e.anim_upper_implicit_time)
98 a = e.anim_upper_action;
99 t = e.anim_upper_time;
103 a = e.anim_upper_implicit_action;
104 t = e.anim_upper_implicit_time;
108 case ANIMACTION_DRAW: outframe = e.anim_draw; break;
109 case ANIMACTION_PAIN1: outframe = e.anim_pain1; break;
110 case ANIMACTION_PAIN2: outframe = e.anim_pain2; break;
111 case ANIMACTION_SHOOT: outframe = e.anim_shoot; break;
112 case ANIMACTION_TAUNT: outframe = e.anim_taunt; break;
113 case ANIMACTION_MELEE: outframe = e.anim_melee; break;
117 if(time <= t + outframe_y / outframe_z)
119 // animation is running!
120 return vec3(outframe_x, t, ANIMPRIO_ACTIVE);
123 // or, decide the anim by state
124 t = max(e.anim_time, e.anim_implicit_time);
125 // but all states are for lower body!
126 return vec3(e.anim_idle_x, t, ANIMPRIO_IDLE);
129 vector animdecide_getloweranim(entity e)
132 if(e.anim_state & ANIMSTATE_FROZEN)
133 return vec3(e.anim_idle_x, e.anim_time, ANIMPRIO_DEAD);
134 if(e.anim_state & ANIMSTATE_DEAD1)
135 return vec3(e.anim_die1_x, e.anim_time, ANIMPRIO_DEAD);
136 if(e.anim_state & ANIMSTATE_DEAD2)
137 return vec3(e.anim_die2_x, e.anim_time, ANIMPRIO_DEAD);
139 // is there an action?
140 vector outframe = '-1 0 0';
142 if(e.anim_lower_time >= e.anim_lower_implicit_time)
144 a = e.anim_lower_action;
145 t = e.anim_lower_time;
149 a = e.anim_lower_implicit_action;
150 t = e.anim_lower_implicit_time;
154 case ANIMACTION_JUMP: if(e.anim_implicit_state & ANIMIMPLICITSTATE_INAIR) { if(e.anim_state & ANIMSTATE_DUCK) outframe = e.anim_duckjump; else outframe = e.anim_jump; } break;
158 if(time <= t + outframe_y / outframe_z)
160 // animation is running!
161 return vec3(outframe_x, t, ANIMPRIO_ACTIVE);
164 // or, decide the anim by state
165 t = max(e.anim_time, e.anim_implicit_time);
166 if(e.anim_state & ANIMSTATE_DUCK)
168 if(e.anim_implicit_state & ANIMIMPLICITSTATE_INAIR)
169 return vec3(e.anim_duckjump_x, 0, ANIMPRIO_CROUCH); // play the END of the jump anim
170 else switch(e.anim_implicit_state & (ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_LEFT | ANIMIMPLICITSTATE_RIGHT))
172 case ANIMIMPLICITSTATE_FORWARD:
173 return vec3(e.anim_duckwalk_x, t, ANIMPRIO_CROUCH);
174 case ANIMIMPLICITSTATE_BACKWARDS:
175 return vec3(e.anim_duckwalkbackwards_x, t, ANIMPRIO_CROUCH);
176 case ANIMIMPLICITSTATE_RIGHT:
177 return vec3(e.anim_duckwalkstraferight_x, t, ANIMPRIO_CROUCH);
178 case ANIMIMPLICITSTATE_LEFT:
179 return vec3(e.anim_duckwalkstrafeleft_x, t, ANIMPRIO_CROUCH);
180 case ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_RIGHT:
181 return vec3(e.anim_duckwalkforwardright_x, t, ANIMPRIO_CROUCH);
182 case ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_LEFT:
183 return vec3(e.anim_duckwalkforwardleft_x, t, ANIMPRIO_CROUCH);
184 case ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_RIGHT:
185 return vec3(e.anim_duckwalkbackright_x, t, ANIMPRIO_CROUCH);
186 case ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_LEFT:
187 return vec3(e.anim_duckwalkbackleft_x, t, ANIMPRIO_CROUCH);
189 return vec3(e.anim_duckidle_x, t, ANIMPRIO_CROUCH);
194 if(e.anim_implicit_state & ANIMIMPLICITSTATE_INAIR)
195 return vec3(e.anim_jump_x, 0, ANIMPRIO_ACTIVE); // play the END of the jump anim
196 else switch(e.anim_implicit_state & (ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_LEFT | ANIMIMPLICITSTATE_RIGHT))
198 case ANIMIMPLICITSTATE_FORWARD:
199 return vec3(e.anim_run_x, t, ANIMPRIO_ACTIVE);
200 case ANIMIMPLICITSTATE_BACKWARDS:
201 return vec3(e.anim_runbackwards_x, t, ANIMPRIO_ACTIVE);
202 case ANIMIMPLICITSTATE_RIGHT:
203 return vec3(e.anim_straferight_x, t, ANIMPRIO_ACTIVE);
204 case ANIMIMPLICITSTATE_LEFT:
205 return vec3(e.anim_strafeleft_x, t, ANIMPRIO_ACTIVE);
206 case ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_RIGHT:
207 return vec3(e.anim_forwardright_x, t, ANIMPRIO_ACTIVE);
208 case ANIMIMPLICITSTATE_FORWARD | ANIMIMPLICITSTATE_LEFT:
209 return vec3(e.anim_forwardleft_x, t, ANIMPRIO_ACTIVE);
210 case ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_RIGHT:
211 return vec3(e.anim_backright_x, t, ANIMPRIO_ACTIVE);
212 case ANIMIMPLICITSTATE_BACKWARDS | ANIMIMPLICITSTATE_LEFT:
213 return vec3(e.anim_backleft_x, t, ANIMPRIO_ACTIVE);
215 return vec3(e.anim_idle_x, t, ANIMPRIO_IDLE);
220 return vec3(e.anim_idle_x, t, ANIMPRIO_IDLE);
224 void animdecide_setimplicitstate(entity e, float onground)
229 makevectors(e.angles);
231 v_x = e.velocity * v_forward;
232 v_y = e.velocity * v_right;
235 // we want to match like this:
236 // the 8 directions shall be "evenly spaced"
237 // that means, the forward key includes anything from -67.5 to +67.5 degrees
238 // which then means x > |y| * cot(3pi/8)
240 // BUT, the engine's clip-movement-to-keyboard function uses 0.5 here,
241 // which would be an angle range from -63.43 to +63.43 degrees, making
242 // it slightly less likely to "hit two keys at once", so let's do this
247 if(v_x > fabs(v_y) * 0.5)
248 s |= ANIMIMPLICITSTATE_FORWARD;
249 if(v_x < -fabs(v_y) * 0.5)
250 s |= ANIMIMPLICITSTATE_BACKWARDS;
251 if(v_y > fabs(v_x) * 0.5)
252 s |= ANIMIMPLICITSTATE_RIGHT;
253 if(v_y < -fabs(v_x) * 0.5)
254 s |= ANIMIMPLICITSTATE_LEFT;
257 s |= ANIMIMPLICITSTATE_INAIR;
259 // detect some kinds of otherwise misdetected jumps (ground to air transition)
260 // NOTE: currently, in CSQC this is the only jump detection, as the explicit jump action is never called!
261 if(!(e.anim_implicit_state & ANIMIMPLICITSTATE_INAIR) && (s & ANIMIMPLICITSTATE_INAIR))
263 e.anim_lower_implicit_action = ANIMACTION_JUMP;
264 e.anim_lower_implicit_time = time;
267 if(s != e.anim_implicit_state)
269 e.anim_implicit_state = s;
270 e.anim_implicit_time = time;
273 void animdecide_setframes(entity e, float support_blending, .float fld_frame, .float fld_frame1time, .float fld_frame2, .float fld_frame2time)
278 vector upper = animdecide_getupperanim(e);
279 vector lower = animdecide_getloweranim(e);
280 //print("UPPER: ", vtos(upper), ", LOWER: ", vtos(lower), "\n");
283 if(upper_z && !lower_z)
285 else if(lower_z && !upper_z)
287 if(e.frame1time != upper_y || e.frame2time != lower_y)
288 BITXOR_ASSIGN(e.effects, EF_RESTARTANIM_BIT);
289 e.fld_frame = upper_x;
290 e.fld_frame1time = upper_y;
291 e.fld_frame2 = lower_x;
292 e.fld_frame2time = lower_y;
296 if(upper_z > lower_z)
298 else if(lower_z > upper_z)
300 if(e.frame1time != upper_y)
301 BITXOR_ASSIGN(e.effects, EF_RESTARTANIM_BIT);
302 e.fld_frame = upper_x;
303 e.fld_frame1time = upper_y;
307 void animdecide_setstate(entity e, float newstate, float restart)
310 if(newstate == e.anim_state)
312 e.anim_state = newstate;
315 void animdecide_setaction(entity e, float action, float restart)
320 if(action == e.anim_lower_action)
322 e.anim_lower_action = action;
323 e.anim_lower_time = time;
328 if(action == e.anim_upper_action)
330 e.anim_upper_action = action;
331 e.anim_upper_time = time;