2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - 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
49 struct InvalidPersonException : public exception {
50 const char * what () const throw () {
51 return "Invalid weapon number";
55 class Person : public enable_shared_from_this<Person>
58 static std::vector<std::shared_ptr<Person>> players;
63 // animCurrent and animTarget are used to interpolate between different animations
64 // (and for a bunch of other things).
65 // animations interpolate with one another at various speeds.
66 // animTarget seems to determine the combat state?
70 // frameCurrent and frameTarget are used to interpolate between the frames of an animation
71 // (e.g. the crouched animation has only two frames, lerped back and forth slowly).
72 // animations advance at various speeds.
83 float parriedrecently;
87 int lastattack, lastattack2, lastattack3;
89 XYZ currentoffset, targetoffset, offset;
103 float unconscioustime;
121 bool rabbitkickenabled;
130 float damagetolerance;
132 float permanentdamage;
133 float superpermanentdamage;
135 /* Seems to be 0 = alive, 1 = unconscious, 2 = dead */
148 float bleedx, bleedy;
150 float texupdatedelay;
152 float headyaw, headpitch;
153 float targetheadyaw, targetheadpitch;
160 std::shared_ptr<Person> victim;
164 float normalsupdatedelay;
169 bool forwardstogglekeydown;
174 bool jumptogglekeydown;
176 bool crouchtogglekeydown;
178 bool drawtogglekeydown;
180 bool throwtogglekeydown;
186 float crouchkeydowntime;
187 float jumpkeydowntime;
195 float losupdatedelay;
202 float whichdirectiondelay;
205 float blooddimamount;
212 float lefthandmorphness;
213 float righthandmorphness;
215 float chestmorphness;
217 float targetlefthandmorphness;
218 float targetrighthandmorphness;
219 float targetheadmorphness;
220 float targetchestmorphness;
221 float targettailmorphness;
222 int lefthandmorphstart, lefthandmorphend;
223 int righthandmorphstart, righthandmorphend;
224 int headmorphstart, headmorphend;
225 int chestmorphstart, chestmorphend;
226 int tailmorphstart, tailmorphend;
228 float weaponmissdelay;
229 float highreversaldelay;
230 float lowreversaldelay;
243 float protectionhead;
244 float protectionhigh;
254 char clothes[10][256];
255 float clothestintr[10];
256 float clothestintg[10];
257 float clothestintb[10];
272 /* Key of weaponids which is the weapon in hand, if any. -1 otherwise.
273 * Always 0 or -1 as activeweapon is moved to position 0 when taken */
276 /* 0 or 1 to say if weapon is stuck in the front or the back */
277 int weaponstuckwhere;
281 int waypointtype[90];
287 XYZ finalfinaltarget;
289 int finalpathfindpoint;
290 int targetpathfindpoint;
291 int lastpathfindpoint;
292 int lastpathfindpoint2;
293 int lastpathfindpoint3;
294 int lastpathfindpoint4;
303 float runninghowlong;
310 float neckspurtdelay;
311 float neckspurtparticledelay;
312 float neckspurtamount;
315 bool rabbitkickragdoll;
317 Animation tempanimation;
322 Person(FILE*, int, unsigned);
324 void skeletonLoad(bool clothes = false);
326 // convenience functions
327 inline Joint& joint(int bodypart) { return skeleton.joints[skeleton.jointlabels[bodypart]]; }
328 inline XYZ& jointPos(int bodypart) { return joint(bodypart).position; }
329 inline XYZ& jointVel(int bodypart) { return joint(bodypart).velocity; }
330 inline AnimationFrame& currentFrame() { return Animation::animations.at(animCurrent).frames.at(frameCurrent); }
331 inline AnimationFrame& targetFrame() { return Animation::animations.at(animTarget).frames.at(frameTarget); }
336 void DoBlood(float howmuch, int which);
337 void DoBloodBig(float howmuch, int which);
338 bool DoBloodBigWhere(float howmuch, int which, XYZ where);
340 bool wasIdle() { return animation_bits[animCurrent] & ab_idle; }
341 bool isIdle() { return animation_bits[animTarget] & ab_idle; }
344 bool isSitting() { return animation_bits[animTarget] & ab_sit; }
346 bool isSleeping() { return animation_bits[animTarget] & ab_sleep; }
348 bool wasCrouch() { return animation_bits[animCurrent] & ab_crouch; }
349 bool isCrouch() { return animation_bits[animTarget] & ab_crouch; }
352 bool wasStop() { return animation_bits[animCurrent] & ab_stop; }
353 bool isStop() { return animation_bits[animTarget] & ab_stop; }
360 bool wasRun() { return animation_bits[animCurrent] & ab_run; }
361 bool isRun() { return animation_bits[animTarget] & ab_run; }
364 bool wasLanding() { return animation_bits[animCurrent] & ab_land; }
365 bool isLanding() { return animation_bits[animTarget] & ab_land; }
368 bool wasLandhard() { return animation_bits[animCurrent] & ab_landhard; }
369 bool isLandhard() { return animation_bits[animTarget] & ab_landhard; }
372 bool wasFlip() { return animation_bits[animCurrent] & ab_flip; }
373 bool isFlip() { return animation_bits[animTarget] & ab_flip; }
375 bool isWallJump() { return animation_bits[animTarget] & ab_walljump; }
377 void DoDamage(float howmuch);
380 skeleton.drawmodel.textureptr.bind();
381 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
382 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skeleton.skinsize, skeleton.skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0]);
385 int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model);
387 void Puff(int whichlabel);
388 void FootLand(bodypart whichfoot, float opacity);
390 void setTargetAnimation(int);
392 void RagDoll(bool checkcollision);
394 void takeWeapon (int weaponId);
396 bool addClothes(const int& clothesId);
402 const int maxplayers = 10;