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