Merge branch 'master' into Mario/stats_eloranking
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / animdecide.qh
1 #pragma once
2
3 // must be called at least once to initialize, or when modelindex is changed
4 void animdecide_load_if_needed(entity e);
5
6 // client side frame inferring
7 void animdecide_setimplicitstate(entity e, float onground);
8 void animdecide_setframes(entity e, bool support_blending, .int fld_frame, .int fld_frame1time, .int fld_frame2, .int fld_frame2time);
9
10 CLASS(Animation, Object)
11         ATTRIB(Animation, m_framenames, string);
12         STATIC_METHOD(Animation, getframe, int(Animation this, int mdlidx))
13         {
14                 FOREACH_WORD(this.m_framenames, true, {
15                         int f = frameforname(mdlidx, it);
16                         if (f != -1) return f;
17                 });
18 #ifdef CSQC
19                 LOG_DEBUGF("Missing animation for %s: %s", modelnameforindex(mdlidx), this.registered_id);
20 #endif
21                 return -1;
22         }
23 ENDCLASS(Animation)
24
25 REGISTRY(Animations, BITS(8))
26 REGISTER_REGISTRY(Animations)
27 #define Animations_from(id) _Animations_from(id, NULL)
28 #define WriteAnimation(to, it) WriteRegistered(Animations, to, it)
29 #define ReadAnimation() ReadRegistered(Animations)
30 #define REGISTER_ANIMATION(id, framenames) \
31         .vector anim_##id; \
32         REGISTER(Animations, ANIM_##id, m_id, NEW(Animation)) { \
33                 this.m_framenames = framenames; \
34         }
35
36 vector anim_vec(Animation anim, int mdlidx, int numframes, float framerate)
37 {
38         vector v;
39         v.x = Animation_getframe(anim, mdlidx);
40         v.y = numframes;
41         v.z = framerate;
42         return v;
43 }
44
45 // player animation data for this model
46 // each vector is as follows:
47 // _x = startframe
48 // _y = numframes
49 // _z = framerate
50 /** player dies */
51 REGISTER_ANIMATION(die1, "dieone groupified_0_anim");
52 /** player dies differently */
53 REGISTER_ANIMATION(die2, "dietwo groupified_1_anim");
54 /** player pulls out a weapon */
55 REGISTER_ANIMATION(draw, "draw groupified_2_anim");
56 REGISTER_ANIMATION(duck, "duck groupified_3_anim");
57 /** player walking while crouching */
58 REGISTER_ANIMATION(duckwalk, "duckwalk groupified_4_anim");
59 /** player jumping from a crouch */
60 REGISTER_ANIMATION(duckjump, "duckjump groupified_5_anim");
61 /** player idling while crouching */
62 REGISTER_ANIMATION(duckidle, "duckidle groupified_6_anim");
63 /** player standing */
64 REGISTER_ANIMATION(idle, "idle groupified_7_anim");
65 /** player jump */
66 REGISTER_ANIMATION(jump, "jump groupified_8_anim");
67 /** player flinches from pain */
68 REGISTER_ANIMATION(pain1, "painone groupified_9_anim");
69 /** player flinches from pain, differently */
70 REGISTER_ANIMATION(pain2, "paintwo groupified_10_anim");
71 /** player shoots */
72 REGISTER_ANIMATION(shoot, "shoot groupified_11_anim");
73 /** player taunts others (FIXME: no code references this) */
74 REGISTER_ANIMATION(taunt, "taunt groupified_12_anim");
75 /** player running forward */
76 REGISTER_ANIMATION(run, "run groupified_13_anim");
77 /** player running backward */
78 REGISTER_ANIMATION(runbackwards, "runbackwards groupified_14_anim");
79 /** player shuffling left quickly */
80 REGISTER_ANIMATION(strafeleft, "strafeleft groupified_15_anim");
81 /** player shuffling right quickly */
82 REGISTER_ANIMATION(straferight, "straferight groupified_16_anim");
83 /**  */
84 REGISTER_ANIMATION(dead1, "deadone groupified_17_anim");
85 /**  */
86 REGISTER_ANIMATION(dead2, "deadtwo groupified_18_anim");
87 /** player running forward and right */
88 REGISTER_ANIMATION(forwardright, "forwardright groupified_19_anim");
89 /** player running forward and left */
90 REGISTER_ANIMATION(forwardleft, "forwardleft groupified_20_anim");
91 /** player running backward and right */
92 REGISTER_ANIMATION(backright, "backright groupified_21_anim");
93 /** player running back and left */
94 REGISTER_ANIMATION(backleft, "backleft groupified_22_anim");
95 /** player doing the melee action */
96 REGISTER_ANIMATION(melee, "melee groupified_23_anim");
97 REGISTER_ANIMATION(duckwalkbackwards, "duckwalkbackwards groupified_24_anim");
98 REGISTER_ANIMATION(duckwalkstrafeleft, "duckwalkstrafeleft duckstrafeleft groupified_25_anim");
99 REGISTER_ANIMATION(duckwalkstraferight, "duckwalkstraferight duckstraferight groupified_26_anim");
100 REGISTER_ANIMATION(duckwalkforwardright, "duckwalkforwardright duckforwardright groupified_27_anim");
101 REGISTER_ANIMATION(duckwalkforwardleft, "duckwalkforwardleft groupified_28_anim");
102 REGISTER_ANIMATION(duckwalkbackright, "duckwalkbackright duckbackwardright groupified_29_anim");
103 REGISTER_ANIMATION(duckwalkbackleft, "duckwalkbackleft duckbackwardleft groupified_30_anim");
104 .float animdecide_modelindex;
105
106 // please network this one
107 .int anim_state;
108 .float anim_time;
109 .float anim_lower_action;
110 .float anim_lower_time;
111 .float anim_upper_action;
112 .float anim_upper_time;
113
114 // when copying entities, copy these too
115 .int anim_implicit_state;
116 .float anim_implicit_time;
117 .float anim_lower_implicit_action;
118 .float anim_lower_implicit_time;
119 .float anim_upper_implicit_action;
120 .float anim_upper_implicit_time;
121
122 // explicit anim states (networked)
123 void animdecide_setstate(entity e, int newstate, float restart);
124 const int ANIMSTATE_DEAD1 = BIT(0); // base frames: die1
125 const int ANIMSTATE_DEAD2 = BIT(1); // base frames: die2
126 const int ANIMSTATE_DUCK = BIT(2); // turns walk into duckwalk, jump into duckjump, etc.
127 const int ANIMSTATE_FROZEN = BIT(3); // force idle
128 const int ANIMSTATE_FOLLOW = BIT(4); // also force idle
129
130 // implicit anim states (inferred from velocity, etc.)
131 const int ANIMIMPLICITSTATE_INAIR = BIT(0);
132 const int ANIMIMPLICITSTATE_FORWARD = BIT(1);
133 const int ANIMIMPLICITSTATE_BACKWARDS = BIT(2);
134 const int ANIMIMPLICITSTATE_LEFT = BIT(3);
135 const int ANIMIMPLICITSTATE_RIGHT = BIT(4);
136 const int ANIMIMPLICITSTATE_JUMPRELEASED = BIT(5);
137
138 // explicit actions (networked); negative values are for lower body
139 void animdecide_setaction(entity e, float action, float restart);
140 const int ANIMACTION_JUMP = -1; // jump
141 const int ANIMACTION_DRAW = 1; // draw
142 const int ANIMACTION_PAIN1 = 2; // pain
143 const int ANIMACTION_PAIN2 = 3; // pain
144 const int ANIMACTION_SHOOT = 4; // shoot
145 const int ANIMACTION_TAUNT = 5; // taunt
146 const int ANIMACTION_MELEE = 6; // melee