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