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 "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"
41 #define attacktypecutoff 4
42 #define playercontrolled 5
44 #define getweapontype 7
45 #define pathfindtype 8
47 struct InvalidPersonException : public exception
49 const char* what() const throw()
51 return "Invalid weapon number";
55 class Person : public enable_shared_from_this<Person>
61 static std::vector<std::shared_ptr<Person>> players;
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?
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.
86 float parriedrecently;
90 int lastattack, lastattack2, lastattack3;
92 XYZ currentoffset, targetoffset, offset;
101 float unconscioustime;
119 bool rabbitkickenabled;
128 float damagetolerance;
130 float permanentdamage;
131 float superpermanentdamage;
133 /* Seems to be 0 = alive, 1 = unconscious, 2 = dead */
146 float bleedx, bleedy;
148 float texupdatedelay;
150 float headyaw, headpitch;
151 float targetheadyaw, targetheadpitch;
158 std::shared_ptr<Person> victim;
163 float normalsupdatedelay;
168 bool forwardstogglekeydown;
173 bool jumptogglekeydown;
175 bool crouchtogglekeydown;
177 bool drawtogglekeydown;
179 bool throwtogglekeydown;
185 float crouchkeydowntime;
186 float jumpkeydowntime;
193 float losupdatedelay;
200 float whichdirectiondelay;
203 float blooddimamount;
210 float lefthandmorphness;
211 float righthandmorphness;
213 float chestmorphness;
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;
226 float weaponmissdelay;
227 float highreversaldelay;
228 float lowreversaldelay;
241 float protectionhead;
242 float protectionhigh;
252 char clothes[10][256];
253 float clothestintr[10];
254 float clothestintg[10];
255 float clothestintb[10];
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 */
274 /* 0 or 1 to say if weapon is stuck in the front or the back */
275 int weaponstuckwhere;
279 int waypointtype[90];
285 XYZ finalfinaltarget;
287 int finalpathfindpoint;
288 int targetpathfindpoint;
289 int lastpathfindpoint;
290 int lastpathfindpoint2;
291 int lastpathfindpoint3;
292 int lastpathfindpoint4;
301 float runninghowlong;
308 float neckspurtdelay;
309 float neckspurtparticledelay;
310 float neckspurtamount;
313 bool rabbitkickragdoll;
315 Animation tempanimation;
320 Person(FILE*, int, unsigned);
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); }
331 void setProportions(float head, float body, float arms, float legs);
332 float getProportion(int part) const;
333 XYZ getProportionXYZ(int part) const;
335 void changeCreatureType(person_type type);
339 void DoBlood(float howmuch, int which);
340 void DoBloodBig(float howmuch, int which);
341 bool DoBloodBigWhere(float howmuch, int which, XYZ where);
343 bool wasIdle() { return animation_bits[animCurrent] & ab_idle; }
344 bool isIdle() { return animation_bits[animTarget] & ab_idle; }
347 bool isSitting() { return animation_bits[animTarget] & ab_sit; }
349 bool isSleeping() { return animation_bits[animTarget] & ab_sleep; }
351 bool wasCrouch() { return animation_bits[animCurrent] & ab_crouch; }
352 bool isCrouch() { return animation_bits[animTarget] & ab_crouch; }
355 bool wasStop() { return animation_bits[animCurrent] & ab_stop; }
356 bool isStop() { return animation_bits[animTarget] & ab_stop; }
363 bool wasRun() { return animation_bits[animCurrent] & ab_run; }
364 bool isRun() { return animation_bits[animTarget] & ab_run; }
367 bool wasLanding() { return animation_bits[animCurrent] & ab_land; }
368 bool isLanding() { return animation_bits[animTarget] & ab_land; }
371 bool wasLandhard() { return animation_bits[animCurrent] & ab_landhard; }
372 bool isLandhard() { return animation_bits[animTarget] & ab_landhard; }
375 bool wasFlip() { return animation_bits[animCurrent] & ab_flip; }
376 bool isFlip() { return animation_bits[animTarget] & ab_flip; }
378 bool isWallJump() { return animation_bits[animTarget] & ab_walljump; }
380 void DoDamage(float howmuch);
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]);
389 int SphereCheck(XYZ* p1, float radius, XYZ* p, XYZ* move, float* rotate, Model* model);
391 void Puff(int whichlabel);
392 void FootLand(bodypart whichfoot, float opacity);
394 void setTargetAnimation(int);
396 void RagDoll(bool checkcollision);
398 void takeWeapon(int weaponId);
400 bool addClothes(const int& clothesId);
407 bool hasWeapon() { return (weaponactive != -1); }
408 bool isPlayerControlled() { return (aitype == playercontrolled); }
409 bool isPlayerFriend() { return isplayerfriend; }
412 const int maxplayers = 10;