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/Weapons.hpp"
40 #define attacktypecutoff 4
41 #define playercontrolled 5
43 #define getweapontype 7
44 #define pathfindtype 8
52 struct InvalidPersonException : public exception {
53 const char * what () const throw () {
54 return "Invalid weapon number";
61 // head, body, arms, legs
63 static std::vector<PersonType> types;
67 class Person : public enable_shared_from_this<Person>
73 static std::vector<std::shared_ptr<Person>> players;
78 // animCurrent and animTarget are used to interpolate between different animations
79 // (and for a bunch of other things).
80 // animations interpolate with one another at various speeds.
81 // animTarget seems to determine the combat state?
85 // frameCurrent and frameTarget are used to interpolate between the frames of an animation
86 // (e.g. the crouched animation has only two frames, lerped back and forth slowly).
87 // animations advance at various speeds.
98 float parriedrecently;
102 int lastattack, lastattack2, lastattack3;
104 XYZ currentoffset, targetoffset, offset;
113 //~ XYZ proportionhead;
114 //~ XYZ proportionlegs;
115 //~ XYZ proportionarms;
116 //~ XYZ proportionbody;
118 float unconscioustime;
136 bool rabbitkickenabled;
145 float damagetolerance;
147 float permanentdamage;
148 float superpermanentdamage;
150 /* Seems to be 0 = alive, 1 = unconscious, 2 = dead */
163 float bleedx, bleedy;
165 float texupdatedelay;
167 float headyaw, headpitch;
168 float targetheadyaw, targetheadpitch;
175 std::shared_ptr<Person> victim;
179 float normalsupdatedelay;
184 bool forwardstogglekeydown;
189 bool jumptogglekeydown;
191 bool crouchtogglekeydown;
193 bool drawtogglekeydown;
195 bool throwtogglekeydown;
201 float crouchkeydowntime;
202 float jumpkeydowntime;
210 float losupdatedelay;
217 float whichdirectiondelay;
220 float blooddimamount;
227 float lefthandmorphness;
228 float righthandmorphness;
230 float chestmorphness;
232 float targetlefthandmorphness;
233 float targetrighthandmorphness;
234 float targetheadmorphness;
235 float targetchestmorphness;
236 float targettailmorphness;
237 int lefthandmorphstart, lefthandmorphend;
238 int righthandmorphstart, righthandmorphend;
239 int headmorphstart, headmorphend;
240 int chestmorphstart, chestmorphend;
241 int tailmorphstart, tailmorphend;
243 float weaponmissdelay;
244 float highreversaldelay;
245 float lowreversaldelay;
258 float protectionhead;
259 float protectionhigh;
269 char clothes[10][256];
270 float clothestintr[10];
271 float clothestintg[10];
272 float clothestintb[10];
287 /* Key of weaponids which is the weapon in hand, if any. -1 otherwise.
288 * Always 0 or -1 as activeweapon is moved to position 0 when taken */
291 /* 0 or 1 to say if weapon is stuck in the front or the back */
292 int weaponstuckwhere;
296 int waypointtype[90];
302 XYZ finalfinaltarget;
304 int finalpathfindpoint;
305 int targetpathfindpoint;
306 int lastpathfindpoint;
307 int lastpathfindpoint2;
308 int lastpathfindpoint3;
309 int lastpathfindpoint4;
318 float runninghowlong;
325 float neckspurtdelay;
326 float neckspurtparticledelay;
327 float neckspurtamount;
330 bool rabbitkickragdoll;
332 Animation tempanimation;
337 Person(FILE*, int, unsigned);
339 void skeletonLoad(bool clothes = false);
341 // convenience functions
342 inline Joint& joint(int bodypart) { return skeleton.joints[skeleton.jointlabels[bodypart]]; }
343 inline XYZ& jointPos(int bodypart) { return joint(bodypart).position; }
344 inline XYZ& jointVel(int bodypart) { return joint(bodypart).velocity; }
345 inline AnimationFrame& currentFrame() { return Animation::animations.at(animCurrent).frames.at(frameCurrent); }
346 inline AnimationFrame& targetFrame() { return Animation::animations.at(animTarget).frames.at(frameTarget); }
348 void setProportions(float, float, float, float);
349 XYZ getProportion(int part) const;
353 void DoBlood(float howmuch, int which);
354 void DoBloodBig(float howmuch, int which);
355 bool DoBloodBigWhere(float howmuch, int which, XYZ where);
357 bool wasIdle() { return animation_bits[animCurrent] & ab_idle; }
358 bool isIdle() { return animation_bits[animTarget] & ab_idle; }
361 bool isSitting() { return animation_bits[animTarget] & ab_sit; }
363 bool isSleeping() { return animation_bits[animTarget] & ab_sleep; }
365 bool wasCrouch() { return animation_bits[animCurrent] & ab_crouch; }
366 bool isCrouch() { return animation_bits[animTarget] & ab_crouch; }
369 bool wasStop() { return animation_bits[animCurrent] & ab_stop; }
370 bool isStop() { return animation_bits[animTarget] & ab_stop; }
377 bool wasRun() { return animation_bits[animCurrent] & ab_run; }
378 bool isRun() { return animation_bits[animTarget] & ab_run; }
381 bool wasLanding() { return animation_bits[animCurrent] & ab_land; }
382 bool isLanding() { return animation_bits[animTarget] & ab_land; }
385 bool wasLandhard() { return animation_bits[animCurrent] & ab_landhard; }
386 bool isLandhard() { return animation_bits[animTarget] & ab_landhard; }
389 bool wasFlip() { return animation_bits[animCurrent] & ab_flip; }
390 bool isFlip() { return animation_bits[animTarget] & ab_flip; }
392 bool isWallJump() { return animation_bits[animTarget] & ab_walljump; }
394 void DoDamage(float howmuch);
397 skeleton.drawmodel.textureptr.bind();
398 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
399 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skeleton.skinsize, skeleton.skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0]);
402 int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model);
404 void Puff(int whichlabel);
405 void FootLand(bodypart whichfoot, float opacity);
407 void setTargetAnimation(int);
409 void RagDoll(bool checkcollision);
411 void takeWeapon (int weaponId);
413 bool addClothes(const int& clothesId);
419 const int maxplayers = 10;