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 std::vector<std::string> skins;
82 static std::vector<PersonType> types;
86 class Person : public enable_shared_from_this<Person>
92 static std::vector<std::shared_ptr<Person>> players;
97 // animCurrent and animTarget are used to interpolate between different animations
98 // (and for a bunch of other things).
99 // animations interpolate with one another at various speeds.
100 // animTarget seems to determine the combat state?
104 // frameCurrent and frameTarget are used to interpolate between the frames of an animation
105 // (e.g. the crouched animation has only two frames, lerped back and forth slowly).
106 // animations advance at various speeds.
117 float parriedrecently;
121 int lastattack, lastattack2, lastattack3;
123 XYZ currentoffset, targetoffset, offset;
132 //~ XYZ proportionhead;
133 //~ XYZ proportionlegs;
134 //~ XYZ proportionarms;
135 //~ XYZ proportionbody;
137 float unconscioustime;
155 bool rabbitkickenabled;
164 float damagetolerance;
166 float permanentdamage;
167 float superpermanentdamage;
169 /* Seems to be 0 = alive, 1 = unconscious, 2 = dead */
182 float bleedx, bleedy;
184 float texupdatedelay;
186 float headyaw, headpitch;
187 float targetheadyaw, targetheadpitch;
194 std::shared_ptr<Person> victim;
198 float normalsupdatedelay;
203 bool forwardstogglekeydown;
208 bool jumptogglekeydown;
210 bool crouchtogglekeydown;
212 bool drawtogglekeydown;
214 bool throwtogglekeydown;
220 float crouchkeydowntime;
221 float jumpkeydowntime;
229 float losupdatedelay;
236 float whichdirectiondelay;
239 float blooddimamount;
246 float lefthandmorphness;
247 float righthandmorphness;
249 float chestmorphness;
251 float targetlefthandmorphness;
252 float targetrighthandmorphness;
253 float targetheadmorphness;
254 float targetchestmorphness;
255 float targettailmorphness;
256 int lefthandmorphstart, lefthandmorphend;
257 int righthandmorphstart, righthandmorphend;
258 int headmorphstart, headmorphend;
259 int chestmorphstart, chestmorphend;
260 int tailmorphstart, tailmorphend;
262 float weaponmissdelay;
263 float highreversaldelay;
264 float lowreversaldelay;
277 float protectionhead;
278 float protectionhigh;
288 char clothes[10][256];
289 float clothestintr[10];
290 float clothestintg[10];
291 float clothestintb[10];
306 /* Key of weaponids which is the weapon in hand, if any. -1 otherwise.
307 * Always 0 or -1 as activeweapon is moved to position 0 when taken */
310 /* 0 or 1 to say if weapon is stuck in the front or the back */
311 int weaponstuckwhere;
315 int waypointtype[90];
321 XYZ finalfinaltarget;
323 int finalpathfindpoint;
324 int targetpathfindpoint;
325 int lastpathfindpoint;
326 int lastpathfindpoint2;
327 int lastpathfindpoint3;
328 int lastpathfindpoint4;
337 float runninghowlong;
344 float neckspurtdelay;
345 float neckspurtparticledelay;
346 float neckspurtamount;
349 bool rabbitkickragdoll;
351 Animation tempanimation;
356 Person(FILE*, int, unsigned);
358 void skeletonLoad(bool clothes = false);
360 // convenience functions
361 inline Joint& joint(int bodypart) { return skeleton.joints[skeleton.jointlabels[bodypart]]; }
362 inline XYZ& jointPos(int bodypart) { return joint(bodypart).position; }
363 inline XYZ& jointVel(int bodypart) { return joint(bodypart).velocity; }
364 inline AnimationFrame& currentFrame() { return Animation::animations.at(animCurrent).frames.at(frameCurrent); }
365 inline AnimationFrame& targetFrame() { return Animation::animations.at(animTarget).frames.at(frameTarget); }
367 void setProportions(float, float, float, float);
368 XYZ getProportion(int part) const;
372 void DoBlood(float howmuch, int which);
373 void DoBloodBig(float howmuch, int which);
374 bool DoBloodBigWhere(float howmuch, int which, XYZ where);
376 bool wasIdle() { return animation_bits[animCurrent] & ab_idle; }
377 bool isIdle() { return animation_bits[animTarget] & ab_idle; }
380 bool isSitting() { return animation_bits[animTarget] & ab_sit; }
382 bool isSleeping() { return animation_bits[animTarget] & ab_sleep; }
384 bool wasCrouch() { return animation_bits[animCurrent] & ab_crouch; }
385 bool isCrouch() { return animation_bits[animTarget] & ab_crouch; }
388 bool wasStop() { return animation_bits[animCurrent] & ab_stop; }
389 bool isStop() { return animation_bits[animTarget] & ab_stop; }
396 bool wasRun() { return animation_bits[animCurrent] & ab_run; }
397 bool isRun() { return animation_bits[animTarget] & ab_run; }
400 bool wasLanding() { return animation_bits[animCurrent] & ab_land; }
401 bool isLanding() { return animation_bits[animTarget] & ab_land; }
404 bool wasLandhard() { return animation_bits[animCurrent] & ab_landhard; }
405 bool isLandhard() { return animation_bits[animTarget] & ab_landhard; }
408 bool wasFlip() { return animation_bits[animCurrent] & ab_flip; }
409 bool isFlip() { return animation_bits[animTarget] & ab_flip; }
411 bool isWallJump() { return animation_bits[animTarget] & ab_walljump; }
413 void DoDamage(float howmuch);
416 skeleton.drawmodel.textureptr.bind();
417 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
418 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skeleton.skinsize, skeleton.skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0]);
421 int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model);
423 void Puff(int whichlabel);
424 void FootLand(bodypart whichfoot, float opacity);
426 void setTargetAnimation(int);
428 void RagDoll(bool checkcollision);
430 void takeWeapon (int weaponId);
432 bool addClothes(const int& clothesId);
438 const int maxplayers = 10;