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 GLubyte bloodText[512 * 512 * 3] = { 0 };
84 static std::vector<PersonType> types;
88 class Person : public enable_shared_from_this<Person>
94 static std::vector<std::shared_ptr<Person>> players;
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?
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.
119 float parriedrecently;
123 int lastattack, lastattack2, lastattack3;
125 XYZ currentoffset, targetoffset, offset;
134 //~ XYZ proportionhead;
135 //~ XYZ proportionlegs;
136 //~ XYZ proportionarms;
137 //~ XYZ proportionbody;
139 float unconscioustime;
157 bool rabbitkickenabled;
166 float damagetolerance;
168 float permanentdamage;
169 float superpermanentdamage;
171 /* Seems to be 0 = alive, 1 = unconscious, 2 = dead */
184 float bleedx, bleedy;
186 float texupdatedelay;
188 float headyaw, headpitch;
189 float targetheadyaw, targetheadpitch;
196 std::shared_ptr<Person> victim;
200 float normalsupdatedelay;
205 bool forwardstogglekeydown;
210 bool jumptogglekeydown;
212 bool crouchtogglekeydown;
214 bool drawtogglekeydown;
216 bool throwtogglekeydown;
222 float crouchkeydowntime;
223 float jumpkeydowntime;
231 float losupdatedelay;
238 float whichdirectiondelay;
241 float blooddimamount;
248 float lefthandmorphness;
249 float righthandmorphness;
251 float chestmorphness;
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;
264 float weaponmissdelay;
265 float highreversaldelay;
266 float lowreversaldelay;
279 float protectionhead;
280 float protectionhigh;
290 char clothes[10][256];
291 float clothestintr[10];
292 float clothestintg[10];
293 float clothestintb[10];
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 */
312 /* 0 or 1 to say if weapon is stuck in the front or the back */
313 int weaponstuckwhere;
317 int waypointtype[90];
323 XYZ finalfinaltarget;
325 int finalpathfindpoint;
326 int targetpathfindpoint;
327 int lastpathfindpoint;
328 int lastpathfindpoint2;
329 int lastpathfindpoint3;
330 int lastpathfindpoint4;
339 float runninghowlong;
346 float neckspurtdelay;
347 float neckspurtparticledelay;
348 float neckspurtamount;
351 bool rabbitkickragdoll;
353 Animation tempanimation;
358 Person(FILE*, int, unsigned);
360 void skeletonLoad(bool clothes = false);
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); }
369 void setProportions(float, float, float, float);
370 XYZ getProportion(int part) const;
374 void DoBlood(float howmuch, int which);
375 void DoBloodBig(float howmuch, int which);
376 bool DoBloodBigWhere(float howmuch, int which, XYZ where);
378 bool wasIdle() { return animation_bits[animCurrent] & ab_idle; }
379 bool isIdle() { return animation_bits[animTarget] & ab_idle; }
382 bool isSitting() { return animation_bits[animTarget] & ab_sit; }
384 bool isSleeping() { return animation_bits[animTarget] & ab_sleep; }
386 bool wasCrouch() { return animation_bits[animCurrent] & ab_crouch; }
387 bool isCrouch() { return animation_bits[animTarget] & ab_crouch; }
390 bool wasStop() { return animation_bits[animCurrent] & ab_stop; }
391 bool isStop() { return animation_bits[animTarget] & ab_stop; }
398 bool wasRun() { return animation_bits[animCurrent] & ab_run; }
399 bool isRun() { return animation_bits[animTarget] & ab_run; }
402 bool wasLanding() { return animation_bits[animCurrent] & ab_land; }
403 bool isLanding() { return animation_bits[animTarget] & ab_land; }
406 bool wasLandhard() { return animation_bits[animCurrent] & ab_landhard; }
407 bool isLandhard() { return animation_bits[animTarget] & ab_landhard; }
410 bool wasFlip() { return animation_bits[animCurrent] & ab_flip; }
411 bool isFlip() { return animation_bits[animTarget] & ab_flip; }
413 bool isWallJump() { return animation_bits[animTarget] & ab_walljump; }
415 void DoDamage(float howmuch);
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]);
423 int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model);
425 void Puff(int whichlabel);
426 void FootLand(bodypart whichfoot, float opacity);
428 void setTargetAnimation(int);
430 void RagDoll(bool checkcollision);
432 void takeWeapon (int weaponId);
434 bool addClothes(const int& clothesId);
440 const int maxplayers = 10;