]> git.jsancho.org Git - lugaru.git/blob - Source/Person.h
801553a394e363e83515e7ab37da14df5e0a3f38
[lugaru.git] / Source / Person.h
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
4
5 This file is part of Lugaru.
6
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _PERSON_H_
22 #define _PERSON_H_
23
24 /**> HEADER FILES <**/
25
26 #include "gamegl.h"
27 #include "Quaternions.h"
28 #include "Skeleton.h"
29 #include "Models.h"
30 #include "Terrain.h"
31 #include "Sprite.h"
32 #include <cmath>
33 #include <memory>
34 #include "Weapons.h"
35 #include "Animation.h"
36
37 #define passivetype 0
38 #define guardtype 1
39 #define searchtype 2
40 #define attacktype 3
41 #define attacktypecutoff 4
42 #define playercontrolled 5
43 #define gethelptype 6
44 #define getweapontype 7
45 #define pathfindtype 8
46
47 #define rabbittype 0
48 #define wolftype 1
49
50 class Person : public enable_shared_from_this<Person>
51 {
52 public:
53     static std::vector<std::shared_ptr<Person>> players;
54
55     int whichpatchx;
56     int whichpatchz;
57
58     // animCurrent and animTarget are used to interpolate between different animations
59     // (and for a bunch of other things).
60     // animations interpolate with one another at various speeds.
61     // animTarget seems to determine the combat state?
62     int animCurrent;
63     int animTarget;
64
65     // frameCurrent and frameTarget are used to interpolate between the frames of an animation
66     // (e.g. the crouched animation has only two frames, lerped back and forth slowly).
67     // animations advance at various speeds.
68     int frameCurrent;
69     int frameTarget;
70
71     int oldanimCurrent;
72     int oldanimTarget;
73     int oldframeCurrent;
74     int oldframeTarget;
75
76     int howactive;
77
78     float parriedrecently;
79
80     bool superruntoggle;
81
82     int lastattack, lastattack2, lastattack3;
83
84     XYZ currentoffset, targetoffset, offset;
85     float target;
86     float transspeed;
87
88     XYZ realoldcoords;
89     XYZ oldcoords;
90     XYZ coords;
91     XYZ originalcoords;
92     XYZ velocity;
93
94     XYZ proportionhead;
95     XYZ proportionlegs;
96     XYZ proportionarms;
97     XYZ proportionbody;
98
99     float unconscioustime;
100
101     bool immobile;
102
103     float velspeed;
104     float targetyaw;
105     float targetrot;
106     float rot;
107     float oldrot;
108     float lookyaw;
109     float lookpitch;
110     float yaw;
111     float pitch;
112     float lowyaw;
113     float tilt;
114     float targettilt;
115     float tilt2;
116     float targettilt2;
117     bool rabbitkickenabled;
118
119     float bloodloss;
120     float bleeddelay;
121     float skiddelay;
122     float skiddingdelay;
123     float deathbleeding;
124     float tempdeltav;
125
126     float damagetolerance;
127     float damage;
128     float permanentdamage;
129     float superpermanentdamage;
130     float lastcollide;
131     /* Seems to be 0 = alive, 1 = unconscious, 2 = dead */
132     int dead;
133
134     float jumppower;
135     bool onground;
136     int madskills;
137
138     int wentforweapon;
139
140     bool calcrot;
141
142     bool backwardsanim;
143
144     XYZ facing;
145
146     float bleeding;
147     float bleedx, bleedy;
148     int direction;
149     float texupdatedelay;
150
151     float headyaw, headpitch;
152     float targetheadyaw, targetheadpitch;
153
154     bool onterrain;
155     bool pause;
156
157     float grabdelay;
158
159     std::shared_ptr<Person> victim;
160     bool hasvictim;
161
162     float updatedelay;
163     float normalsupdatedelay;
164
165     bool jumpstart;
166
167     bool forwardkeydown;
168     bool forwardstogglekeydown;
169     bool rightkeydown;
170     bool leftkeydown;
171     bool backkeydown;
172     bool jumpkeydown;
173     bool jumptogglekeydown;
174     bool crouchkeydown;
175     bool crouchtogglekeydown;
176     bool drawkeydown;
177     bool drawtogglekeydown;
178     bool throwkeydown;
179     bool throwtogglekeydown;
180     bool attackkeydown;
181     bool feint;
182     bool lastfeint;
183     bool headless;
184
185     float crouchkeydowntime;
186     float jumpkeydowntime;
187     bool freefall;
188
189
190     float turnspeed;
191
192     int aitype;
193     float aiupdatedelay;
194     float losupdatedelay;
195     int ally;
196     XYZ movetarget;
197     float collide;
198     float collided;
199     float avoidcollided;
200     bool loaded;
201     bool whichdirection;
202     float whichdirectiondelay;
203     bool avoidsomething;
204     XYZ avoidwhere;
205     float blooddimamount;
206
207     float staggerdelay;
208     float blinkdelay;
209     float twitchdelay;
210     float twitchdelay2;
211     float twitchdelay3;
212     float lefthandmorphness;
213     float righthandmorphness;
214     float headmorphness;
215     float chestmorphness;
216     float tailmorphness;
217     float targetlefthandmorphness;
218     float targetrighthandmorphness;
219     float targetheadmorphness;
220     float targetchestmorphness;
221     float targettailmorphness;
222     int lefthandmorphstart, lefthandmorphend;
223     int righthandmorphstart, righthandmorphend;
224     int headmorphstart, headmorphend;
225     int chestmorphstart, chestmorphend;
226     int tailmorphstart, tailmorphend;
227
228     float weaponmissdelay;
229     float highreversaldelay;
230     float lowreversaldelay;
231     float nocollidedelay;
232
233     int creature;
234
235     unsigned id;
236
237     Skeleton skeleton;
238
239     float speed;
240     float scale;
241     float power;
242     float speedmult;
243
244     float protectionhead;
245     float protectionhigh;
246     float protectionlow;
247     float armorhead;
248     float armorhigh;
249     float armorlow;
250     bool metalhead;
251     bool metalhigh;
252     bool metallow;
253
254     int numclothes;
255     char clothes[10][256];
256     float clothestintr[10];
257     float clothestintg[10];
258     float clothestintb[10];
259
260     bool landhard;
261     bool bled;
262     bool spurt;
263     bool onfire;
264     float onfiredelay;
265     float burnt;
266     float fireduration;
267
268     float flamedelay;
269     float updatestuffdelay;
270
271     int playerdetail;
272
273     int num_weapons;
274     int weaponids[4];
275     /* Key of weaponids which is the weapon in hand, if any. -1 otherwise.
276      * Always 0 or -1 as activeweapon is moved to position 0 when taken */
277     int weaponactive;
278     int weaponstuck;
279     /* 0 or 1 to say if weapon is stuck in the front or the back  */
280     int weaponstuckwhere;
281
282     int numwaypoints;
283     XYZ waypoints[90];
284     int waypointtype[90];
285     float pausetime;
286     bool hastempwaypoint;
287     XYZ tempwaypoint;
288
289     XYZ headtarget;
290     float interestdelay;
291
292     XYZ finalfinaltarget;
293     XYZ finaltarget;
294     int finalpathfindpoint;
295     int targetpathfindpoint;
296     int lastpathfindpoint;
297     int lastpathfindpoint2;
298     int lastpathfindpoint3;
299     int lastpathfindpoint4;
300     bool onpath;
301
302     int waypoint;
303     bool jumppath;
304
305     XYZ lastseen;
306     float lastseentime;
307     float lastchecktime;
308     float stunned;
309     float surprised;
310     float runninghowlong;
311     int lastoccluded;
312     int laststanding;
313     int escapednum;
314
315     float speechdelay;
316     float neckspurtdelay;
317     float neckspurtparticledelay;
318     float neckspurtamount;
319
320     int whichskin;
321     bool rabbitkickragdoll;
322
323     XYZ averageloc;
324     XYZ oldaverageloc;
325
326     Animation tempanimation;
327
328     float occluded;
329
330     bool jumpclimb;
331
332
333
334     // convenience functions
335     inline Joint& joint(int bodypart) { return skeleton.joints[skeleton.jointlabels[bodypart]]; }
336     inline XYZ& jointPos(int bodypart) { return joint(bodypart).position; }
337     inline XYZ& jointVel(int bodypart) { return joint(bodypart).velocity; }
338
339
340     void CheckKick();
341     void CatchFire();
342     void DoBlood(float howmuch, int which);
343     void DoBloodBig(float howmuch, int which);
344     bool DoBloodBigWhere(float howmuch, int which, XYZ where);
345
346     bool wasIdle() { return animation_bits[animCurrent] & ab_idle; }
347     bool isIdle() { return animation_bits[animTarget] & ab_idle; }
348     int getIdle();
349
350     bool isSitting() { return animation_bits[animTarget] & ab_sit; }
351
352     bool isSleeping() { return animation_bits[animTarget] & ab_sleep; }
353
354     bool wasCrouch() { return animation_bits[animCurrent] & ab_crouch; }
355     bool isCrouch() { return animation_bits[animTarget] & ab_crouch; }
356     int getCrouch();
357
358     bool wasStop() { return animation_bits[animCurrent] & ab_stop; }
359     bool isStop() { return animation_bits[animTarget] & ab_stop; }
360     int getStop();
361
362     bool wasSneak();
363     bool isSneak();
364     int getSneak();
365
366     bool wasRun() { return animation_bits[animCurrent] & ab_run; }
367     bool isRun() { return animation_bits[animTarget] & ab_run; }
368     int getRun();
369
370     bool wasLanding() { return animation_bits[animCurrent] & ab_land; }
371     bool isLanding() { return animation_bits[animTarget] & ab_land; }
372     int getLanding();
373
374     bool wasLandhard() { return animation_bits[animCurrent] & ab_landhard; }
375     bool isLandhard() { return animation_bits[animTarget] & ab_landhard; }
376     int getLandhard();
377
378     bool wasFlip() { return animation_bits[animCurrent] & ab_flip; }
379     bool isFlip() { return animation_bits[animTarget] & ab_flip; }
380
381     bool isWallJump() { return animation_bits[animTarget] & ab_walljump; }
382     void Reverse();
383     void DoDamage(float howmuch);
384     void DoHead();
385     void DoMipmaps() {
386         skeleton.drawmodel.textureptr.bind();
387         glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
388         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skeleton.skinsize, skeleton.skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0]);
389     }
390
391     int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model);
392     int DrawSkeleton();
393     void Puff(int whichlabel);
394     void FootLand(int which, float opacity);
395     void DoStuff();
396     void setAnimation(int);
397     void DoAnimations();
398     void RagDoll(bool checkcollision);
399
400     void takeWeapon (int weaponId);
401
402     bool addClothes(const int& clothesId);
403     bool addClothes(const char* fileName);
404 };
405
406 const int maxplayers = 10;
407
408 #endif