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/gamegl.hpp"
28 #include "Graphic/Models.hpp"
29 #include "Graphic/Sprite.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 {
48 const char * what () const throw () {
49 return "Invalid weapon number";
53 class Person : public enable_shared_from_this<Person>
59 static std::vector<std::shared_ptr<Person>> players;
64 // animCurrent and animTarget are used to interpolate between different animations
65 // (and for a bunch of other things).
66 // animations interpolate with one another at various speeds.
67 // animTarget seems to determine the combat state?
71 // frameCurrent and frameTarget are used to interpolate between the frames of an animation
72 // (e.g. the crouched animation has only two frames, lerped back and forth slowly).
73 // animations advance at various speeds.
84 float parriedrecently;
88 int lastattack, lastattack2, lastattack3;
90 XYZ currentoffset, targetoffset, offset;
99 float unconscioustime;
117 bool rabbitkickenabled;
126 float damagetolerance;
128 float permanentdamage;
129 float superpermanentdamage;
131 /* Seems to be 0 = alive, 1 = unconscious, 2 = dead */
144 float bleedx, bleedy;
146 float texupdatedelay;
148 float headyaw, headpitch;
149 float targetheadyaw, targetheadpitch;
156 std::shared_ptr<Person> victim;
160 float normalsupdatedelay;
165 bool forwardstogglekeydown;
170 bool jumptogglekeydown;
172 bool crouchtogglekeydown;
174 bool drawtogglekeydown;
176 bool throwtogglekeydown;
182 float crouchkeydowntime;
183 float jumpkeydowntime;
191 float losupdatedelay;
198 float whichdirectiondelay;
201 float blooddimamount;
208 float lefthandmorphness;
209 float righthandmorphness;
211 float chestmorphness;
213 float targetlefthandmorphness;
214 float targetrighthandmorphness;
215 float targetheadmorphness;
216 float targetchestmorphness;
217 float targettailmorphness;
218 int lefthandmorphstart, lefthandmorphend;
219 int righthandmorphstart, righthandmorphend;
220 int headmorphstart, headmorphend;
221 int chestmorphstart, chestmorphend;
222 int tailmorphstart, tailmorphend;
224 float weaponmissdelay;
225 float highreversaldelay;
226 float lowreversaldelay;
239 float protectionhead;
240 float protectionhigh;
250 char clothes[10][256];
251 float clothestintr[10];
252 float clothestintg[10];
253 float clothestintb[10];
268 /* Key of weaponids which is the weapon in hand, if any. -1 otherwise.
269 * Always 0 or -1 as activeweapon is moved to position 0 when taken */
272 /* 0 or 1 to say if weapon is stuck in the front or the back */
273 int weaponstuckwhere;
277 int waypointtype[90];
283 XYZ finalfinaltarget;
285 int finalpathfindpoint;
286 int targetpathfindpoint;
287 int lastpathfindpoint;
288 int lastpathfindpoint2;
289 int lastpathfindpoint3;
290 int lastpathfindpoint4;
299 float runninghowlong;
306 float neckspurtdelay;
307 float neckspurtparticledelay;
308 float neckspurtamount;
311 bool rabbitkickragdoll;
313 Animation tempanimation;
318 Person(FILE*, int, unsigned);
320 void skeletonLoad(bool clothes = false);
322 // convenience functions
323 inline Joint& joint(int bodypart) { return skeleton.joints[skeleton.jointlabels[bodypart]]; }
324 inline XYZ& jointPos(int bodypart) { return joint(bodypart).position; }
325 inline XYZ& jointVel(int bodypart) { return joint(bodypart).velocity; }
326 inline AnimationFrame& currentFrame() { return Animation::animations.at(animCurrent).frames.at(frameCurrent); }
327 inline AnimationFrame& targetFrame() { return Animation::animations.at(animTarget).frames.at(frameTarget); }
329 void setProportions(float head, float body, float arms, float legs);
330 float getProportion(int part) const;
331 XYZ getProportionXYZ(int part) const;
335 void DoBlood(float howmuch, int which);
336 void DoBloodBig(float howmuch, int which);
337 bool DoBloodBigWhere(float howmuch, int which, XYZ where);
339 bool wasIdle() { return animation_bits[animCurrent] & ab_idle; }
340 bool isIdle() { return animation_bits[animTarget] & ab_idle; }
343 bool isSitting() { return animation_bits[animTarget] & ab_sit; }
345 bool isSleeping() { return animation_bits[animTarget] & ab_sleep; }
347 bool wasCrouch() { return animation_bits[animCurrent] & ab_crouch; }
348 bool isCrouch() { return animation_bits[animTarget] & ab_crouch; }
351 bool wasStop() { return animation_bits[animCurrent] & ab_stop; }
352 bool isStop() { return animation_bits[animTarget] & ab_stop; }
359 bool wasRun() { return animation_bits[animCurrent] & ab_run; }
360 bool isRun() { return animation_bits[animTarget] & ab_run; }
363 bool wasLanding() { return animation_bits[animCurrent] & ab_land; }
364 bool isLanding() { return animation_bits[animTarget] & ab_land; }
367 bool wasLandhard() { return animation_bits[animCurrent] & ab_landhard; }
368 bool isLandhard() { return animation_bits[animTarget] & ab_landhard; }
371 bool wasFlip() { return animation_bits[animCurrent] & ab_flip; }
372 bool isFlip() { return animation_bits[animTarget] & ab_flip; }
374 bool isWallJump() { return animation_bits[animTarget] & ab_walljump; }
376 void DoDamage(float howmuch);
379 skeleton.drawmodel.textureptr.bind();
380 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
381 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skeleton.skinsize, skeleton.skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0]);
384 int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model);
386 void Puff(int whichlabel);
387 void FootLand(bodypart whichfoot, float opacity);
389 void setTargetAnimation(int);
391 void RagDoll(bool checkcollision);
393 void takeWeapon (int weaponId);
395 bool addClothes(const int& clothesId);
401 const int maxplayers = 10;