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