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 animation_type animFightIdle;
71 animation_type animBounceIdle;
72 animation_type animTalkIdle;
74 sound_type soundsAttack[4];
75 sound_type soundsTalk[2];
77 std::string figureFileName;
78 std::string lowFigureFileName;
79 std::string clothesFileName;
80 std::string modelFileNames[7];
81 std::string lowModelFileName;
82 std::string modelClothesFileName;
84 std::vector<std::string> skins;
86 GLubyte bloodText[512 * 512 * 3] = { 0 };
89 bool hasAnimTalkIdle();
91 static std::vector<PersonType> types;
95 class Person : public enable_shared_from_this<Person>
101 static std::vector<std::shared_ptr<Person>> players;
106 // animCurrent and animTarget are used to interpolate between different animations
107 // (and for a bunch of other things).
108 // animations interpolate with one another at various speeds.
109 // animTarget seems to determine the combat state?
113 // frameCurrent and frameTarget are used to interpolate between the frames of an animation
114 // (e.g. the crouched animation has only two frames, lerped back and forth slowly).
115 // animations advance at various speeds.
126 float parriedrecently;
130 int lastattack, lastattack2, lastattack3;
132 XYZ currentoffset, targetoffset, offset;
141 //~ XYZ proportionhead;
142 //~ XYZ proportionlegs;
143 //~ XYZ proportionarms;
144 //~ XYZ proportionbody;
146 float unconscioustime;
164 bool rabbitkickenabled;
173 float damagetolerance;
175 float permanentdamage;
176 float superpermanentdamage;
178 /* Seems to be 0 = alive, 1 = unconscious, 2 = dead */
191 float bleedx, bleedy;
193 float texupdatedelay;
195 float headyaw, headpitch;
196 float targetheadyaw, targetheadpitch;
203 std::shared_ptr<Person> victim;
207 float normalsupdatedelay;
212 bool forwardstogglekeydown;
217 bool jumptogglekeydown;
219 bool crouchtogglekeydown;
221 bool drawtogglekeydown;
223 bool throwtogglekeydown;
229 float crouchkeydowntime;
230 float jumpkeydowntime;
238 float losupdatedelay;
245 float whichdirectiondelay;
248 float blooddimamount;
255 float lefthandmorphness;
256 float righthandmorphness;
258 float chestmorphness;
260 float targetlefthandmorphness;
261 float targetrighthandmorphness;
262 float targetheadmorphness;
263 float targetchestmorphness;
264 float targettailmorphness;
265 int lefthandmorphstart, lefthandmorphend;
266 int righthandmorphstart, righthandmorphend;
267 int headmorphstart, headmorphend;
268 int chestmorphstart, chestmorphend;
269 int tailmorphstart, tailmorphend;
271 float weaponmissdelay;
272 float highreversaldelay;
273 float lowreversaldelay;
286 float protectionhead;
287 float protectionhigh;
297 char clothes[10][256];
298 float clothestintr[10];
299 float clothestintg[10];
300 float clothestintb[10];
315 /* Key of weaponids which is the weapon in hand, if any. -1 otherwise.
316 * Always 0 or -1 as activeweapon is moved to position 0 when taken */
319 /* 0 or 1 to say if weapon is stuck in the front or the back */
320 int weaponstuckwhere;
324 int waypointtype[90];
330 XYZ finalfinaltarget;
332 int finalpathfindpoint;
333 int targetpathfindpoint;
334 int lastpathfindpoint;
335 int lastpathfindpoint2;
336 int lastpathfindpoint3;
337 int lastpathfindpoint4;
346 float runninghowlong;
353 float neckspurtdelay;
354 float neckspurtparticledelay;
355 float neckspurtamount;
358 bool rabbitkickragdoll;
360 Animation tempanimation;
365 Person(FILE*, int, unsigned);
367 void skeletonLoad(bool clothes = false);
369 // convenience functions
370 inline Joint& joint(int bodypart) { return skeleton.joints[skeleton.jointlabels[bodypart]]; }
371 inline XYZ& jointPos(int bodypart) { return joint(bodypart).position; }
372 inline XYZ& jointVel(int bodypart) { return joint(bodypart).velocity; }
373 inline AnimationFrame& currentFrame() { return Animation::animations.at(animCurrent).frames.at(frameCurrent); }
374 inline AnimationFrame& targetFrame() { return Animation::animations.at(animTarget).frames.at(frameTarget); }
376 void setProportions(float, float, float, float);
377 XYZ getProportion(int part) const;
381 void DoBlood(float howmuch, int which);
382 void DoBloodBig(float howmuch, int which);
383 bool DoBloodBigWhere(float howmuch, int which, XYZ where);
385 bool wasIdle() { return animation_bits[animCurrent] & ab_idle; }
386 bool isIdle() { return animation_bits[animTarget] & ab_idle; }
389 bool isSitting() { return animation_bits[animTarget] & ab_sit; }
391 bool isSleeping() { return animation_bits[animTarget] & ab_sleep; }
393 bool wasCrouch() { return animation_bits[animCurrent] & ab_crouch; }
394 bool isCrouch() { return animation_bits[animTarget] & ab_crouch; }
397 bool wasStop() { return animation_bits[animCurrent] & ab_stop; }
398 bool isStop() { return animation_bits[animTarget] & ab_stop; }
405 bool wasRun() { return animation_bits[animCurrent] & ab_run; }
406 bool isRun() { return animation_bits[animTarget] & ab_run; }
409 bool wasLanding() { return animation_bits[animCurrent] & ab_land; }
410 bool isLanding() { return animation_bits[animTarget] & ab_land; }
413 bool wasLandhard() { return animation_bits[animCurrent] & ab_landhard; }
414 bool isLandhard() { return animation_bits[animTarget] & ab_landhard; }
417 bool wasFlip() { return animation_bits[animCurrent] & ab_flip; }
418 bool isFlip() { return animation_bits[animTarget] & ab_flip; }
420 bool isWallJump() { return animation_bits[animTarget] & ab_walljump; }
422 void DoDamage(float howmuch);
425 skeleton.drawmodel.textureptr.bind();
426 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
427 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skeleton.skinsize, skeleton.skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0]);
430 int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model);
432 void Puff(int whichlabel);
433 void FootLand(bodypart whichfoot, float opacity);
435 void setTargetAnimation(int);
437 void RagDoll(bool checkcollision);
439 void takeWeapon (int weaponId);
441 bool addClothes(const int& clothesId);
447 const int maxplayers = 10;