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