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