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