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