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