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