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