2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
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.
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.
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/>.
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"
41 #define attacktypecutoff 4
42 #define playercontrolled 5
44 #define getweapontype 7
45 #define pathfindtype 8
53 struct InvalidPersonException : public exception {
54 const char * what () const throw () {
55 return "Invalid weapon number";
62 // head, body, arms, legs
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];
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;
80 static std::vector<PersonType> types;
84 class Person : public enable_shared_from_this<Person>
90 static std::vector<std::shared_ptr<Person>> players;
95 // animCurrent and animTarget are used to interpolate between different animations
96 // (and for a bunch of other things).
97 // animations interpolate with one another at various speeds.
98 // animTarget seems to determine the combat state?
102 // frameCurrent and frameTarget are used to interpolate between the frames of an animation
103 // (e.g. the crouched animation has only two frames, lerped back and forth slowly).
104 // animations advance at various speeds.
115 float parriedrecently;
119 int lastattack, lastattack2, lastattack3;
121 XYZ currentoffset, targetoffset, offset;
130 //~ XYZ proportionhead;
131 //~ XYZ proportionlegs;
132 //~ XYZ proportionarms;
133 //~ XYZ proportionbody;
135 float unconscioustime;
153 bool rabbitkickenabled;
162 float damagetolerance;
164 float permanentdamage;
165 float superpermanentdamage;
167 /* Seems to be 0 = alive, 1 = unconscious, 2 = dead */
180 float bleedx, bleedy;
182 float texupdatedelay;
184 float headyaw, headpitch;
185 float targetheadyaw, targetheadpitch;
192 std::shared_ptr<Person> victim;
196 float normalsupdatedelay;
201 bool forwardstogglekeydown;
206 bool jumptogglekeydown;
208 bool crouchtogglekeydown;
210 bool drawtogglekeydown;
212 bool throwtogglekeydown;
218 float crouchkeydowntime;
219 float jumpkeydowntime;
227 float losupdatedelay;
234 float whichdirectiondelay;
237 float blooddimamount;
244 float lefthandmorphness;
245 float righthandmorphness;
247 float chestmorphness;
249 float targetlefthandmorphness;
250 float targetrighthandmorphness;
251 float targetheadmorphness;
252 float targetchestmorphness;
253 float targettailmorphness;
254 int lefthandmorphstart, lefthandmorphend;
255 int righthandmorphstart, righthandmorphend;
256 int headmorphstart, headmorphend;
257 int chestmorphstart, chestmorphend;
258 int tailmorphstart, tailmorphend;
260 float weaponmissdelay;
261 float highreversaldelay;
262 float lowreversaldelay;
275 float protectionhead;
276 float protectionhigh;
286 char clothes[10][256];
287 float clothestintr[10];
288 float clothestintg[10];
289 float clothestintb[10];
304 /* Key of weaponids which is the weapon in hand, if any. -1 otherwise.
305 * Always 0 or -1 as activeweapon is moved to position 0 when taken */
308 /* 0 or 1 to say if weapon is stuck in the front or the back */
309 int weaponstuckwhere;
313 int waypointtype[90];
319 XYZ finalfinaltarget;
321 int finalpathfindpoint;
322 int targetpathfindpoint;
323 int lastpathfindpoint;
324 int lastpathfindpoint2;
325 int lastpathfindpoint3;
326 int lastpathfindpoint4;
335 float runninghowlong;
342 float neckspurtdelay;
343 float neckspurtparticledelay;
344 float neckspurtamount;
347 bool rabbitkickragdoll;
349 Animation tempanimation;
354 Person(FILE*, int, unsigned);
356 void skeletonLoad(bool clothes = false);
358 // convenience functions
359 inline Joint& joint(int bodypart) { return skeleton.joints[skeleton.jointlabels[bodypart]]; }
360 inline XYZ& jointPos(int bodypart) { return joint(bodypart).position; }
361 inline XYZ& jointVel(int bodypart) { return joint(bodypart).velocity; }
362 inline AnimationFrame& currentFrame() { return Animation::animations.at(animCurrent).frames.at(frameCurrent); }
363 inline AnimationFrame& targetFrame() { return Animation::animations.at(animTarget).frames.at(frameTarget); }
365 void setProportions(float, float, float, float);
366 XYZ getProportion(int part) const;
370 void DoBlood(float howmuch, int which);
371 void DoBloodBig(float howmuch, int which);
372 bool DoBloodBigWhere(float howmuch, int which, XYZ where);
374 bool wasIdle() { return animation_bits[animCurrent] & ab_idle; }
375 bool isIdle() { return animation_bits[animTarget] & ab_idle; }
378 bool isSitting() { return animation_bits[animTarget] & ab_sit; }
380 bool isSleeping() { return animation_bits[animTarget] & ab_sleep; }
382 bool wasCrouch() { return animation_bits[animCurrent] & ab_crouch; }
383 bool isCrouch() { return animation_bits[animTarget] & ab_crouch; }
386 bool wasStop() { return animation_bits[animCurrent] & ab_stop; }
387 bool isStop() { return animation_bits[animTarget] & ab_stop; }
394 bool wasRun() { return animation_bits[animCurrent] & ab_run; }
395 bool isRun() { return animation_bits[animTarget] & ab_run; }
398 bool wasLanding() { return animation_bits[animCurrent] & ab_land; }
399 bool isLanding() { return animation_bits[animTarget] & ab_land; }
402 bool wasLandhard() { return animation_bits[animCurrent] & ab_landhard; }
403 bool isLandhard() { return animation_bits[animTarget] & ab_landhard; }
406 bool wasFlip() { return animation_bits[animCurrent] & ab_flip; }
407 bool isFlip() { return animation_bits[animTarget] & ab_flip; }
409 bool isWallJump() { return animation_bits[animTarget] & ab_walljump; }
411 void DoDamage(float howmuch);
414 skeleton.drawmodel.textureptr.bind();
415 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
416 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skeleton.skinsize, skeleton.skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0]);
419 int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model);
421 void Puff(int whichlabel);
422 void FootLand(bodypart whichfoot, float opacity);
424 void setTargetAnimation(int);
426 void RagDoll(bool checkcollision);
428 void takeWeapon (int weaponId);
430 bool addClothes(const int& clothesId);
436 const int maxplayers = 10;