Person.hpp 10 KB
Newer Older
1 2
/*
Copyright (C) 2003, 2010 - Wolfire Games
3
Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
4 5 6

This file is part of Lugaru.

7 8 9 10
Lugaru is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
11

12
Lugaru is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14 15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
16 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/>.
19 20
*/

21 22
#ifndef _PERSON_HPP_
#define _PERSON_HPP_
Ryan C. Gordon's avatar
Ryan C. Gordon committed
23

24 25 26 27 28 29
#include "Animation/Animation.hpp"
#include "Animation/Skeleton.hpp"
#include "Environment/Terrain.hpp"
#include "Graphic/gamegl.hpp"
#include "Graphic/Models.hpp"
#include "Graphic/Sprite.hpp"
30
#include "Math/XYZ.hpp"
31
#include "Objects/PersonType.hpp"
32
#include "Objects/Weapons.hpp"
33 34

#include <cmath>
35
#include <memory>
Ryan C. Gordon's avatar
Ryan C. Gordon committed
36 37 38 39 40 41 42 43 44 45 46

#define passivetype 0
#define guardtype 1
#define searchtype 2
#define attacktype 3
#define attacktypecutoff 4
#define playercontrolled 5
#define gethelptype 6
#define getweapontype 7
#define pathfindtype 8

47 48 49 50 51 52
struct InvalidPersonException : public exception {
   const char * what () const throw () {
      return "Invalid weapon number";
   }
};

53
class Person : public enable_shared_from_this<Person>
Ryan C. Gordon's avatar
Ryan C. Gordon committed
54
{
55 56 57
private:
    float proportions[4];

sf17k's avatar
sf17k committed
58
public:
59 60
    static std::vector<std::shared_ptr<Person>> players;

sf17k's avatar
sf17k committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    int whichpatchx;
    int whichpatchz;

    // animCurrent and animTarget are used to interpolate between different animations
    // (and for a bunch of other things).
    // animations interpolate with one another at various speeds.
    // animTarget seems to determine the combat state?
    int animCurrent;
    int animTarget;

    // frameCurrent and frameTarget are used to interpolate between the frames of an animation
    // (e.g. the crouched animation has only two frames, lerped back and forth slowly).
    // animations advance at various speeds.
    int frameCurrent;
    int frameTarget;

    int oldanimCurrent;
    int oldanimTarget;
    int oldframeCurrent;
    int oldframeTarget;

    int howactive;

    float parriedrecently;

    bool superruntoggle;

    int lastattack, lastattack2, lastattack3;

    XYZ currentoffset, targetoffset, offset;
    float target;
    float transspeed;

    XYZ realoldcoords;
    XYZ oldcoords;
    XYZ coords;
    XYZ velocity;

99 100 101 102
    //~ XYZ proportionhead;
    //~ XYZ proportionlegs;
    //~ XYZ proportionarms;
    //~ XYZ proportionbody;
sf17k's avatar
sf17k committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135

    float unconscioustime;

    bool immobile;

    float velspeed;
    float targetyaw;
    float targetrot;
    float rot;
    float oldrot;
    float lookyaw;
    float lookpitch;
    float yaw;
    float pitch;
    float lowyaw;
    float tilt;
    float targettilt;
    float tilt2;
    float targettilt2;
    bool rabbitkickenabled;

    float bloodloss;
    float bleeddelay;
    float skiddelay;
    float skiddingdelay;
    float deathbleeding;
    float tempdeltav;

    float damagetolerance;
    float damage;
    float permanentdamage;
    float superpermanentdamage;
    float lastcollide;
136
    /* Seems to be 0 = alive, 1 = unconscious, 2 = dead */
sf17k's avatar
sf17k committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
    int dead;

    float jumppower;
    bool onground;

    int wentforweapon;

    bool calcrot;

    XYZ facing;

    float bleeding;
    float bleedx, bleedy;
    int direction;
    float texupdatedelay;

    float headyaw, headpitch;
    float targetheadyaw, targetheadpitch;

    bool onterrain;
    bool pause;

    float grabdelay;

161
    std::shared_ptr<Person> victim;
sf17k's avatar
sf17k committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
    bool hasvictim;

    float updatedelay;
    float normalsupdatedelay;

    bool jumpstart;

    bool forwardkeydown;
    bool forwardstogglekeydown;
    bool rightkeydown;
    bool leftkeydown;
    bool backkeydown;
    bool jumpkeydown;
    bool jumptogglekeydown;
    bool crouchkeydown;
    bool crouchtogglekeydown;
    bool drawkeydown;
    bool drawtogglekeydown;
    bool throwkeydown;
    bool throwtogglekeydown;
    bool attackkeydown;
    bool feint;
    bool lastfeint;
    bool headless;

    float crouchkeydowntime;
    float jumpkeydowntime;
    bool freefall;


    float turnspeed;

    int aitype;
    float aiupdatedelay;
    float losupdatedelay;
    int ally;
    float collide;
    float collided;
    float avoidcollided;
    bool loaded;
    bool whichdirection;
    float whichdirectiondelay;
    bool avoidsomething;
    XYZ avoidwhere;
    float blooddimamount;

    float staggerdelay;
    float blinkdelay;
    float twitchdelay;
    float twitchdelay2;
    float twitchdelay3;
    float lefthandmorphness;
    float righthandmorphness;
    float headmorphness;
    float chestmorphness;
    float tailmorphness;
    float targetlefthandmorphness;
    float targetrighthandmorphness;
    float targetheadmorphness;
    float targetchestmorphness;
    float targettailmorphness;
    int lefthandmorphstart, lefthandmorphend;
    int righthandmorphstart, righthandmorphend;
    int headmorphstart, headmorphend;
    int chestmorphstart, chestmorphend;
    int tailmorphstart, tailmorphend;

    float weaponmissdelay;
    float highreversaldelay;
    float lowreversaldelay;

    int creature;

MCMic's avatar
MCMic committed
235
    unsigned id;
sf17k's avatar
sf17k committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272

    Skeleton skeleton;

    float speed;
    float scale;
    float power;
    float speedmult;

    float protectionhead;
    float protectionhigh;
    float protectionlow;
    float armorhead;
    float armorhigh;
    float armorlow;
    bool metalhead;
    bool metalhigh;
    bool metallow;

    int numclothes;
    char clothes[10][256];
    float clothestintr[10];
    float clothestintg[10];
    float clothestintb[10];

    bool landhard;
    bool bled;
    bool spurt;
    bool onfire;
    float onfiredelay;
    float burnt;

    float flamedelay;

    int playerdetail;

    int num_weapons;
    int weaponids[4];
273 274
    /* Key of weaponids which is the weapon in hand, if any. -1 otherwise.
     * Always 0 or -1 as activeweapon is moved to position 0 when taken */
sf17k's avatar
sf17k committed
275 276
    int weaponactive;
    int weaponstuck;
277
    /* 0 or 1 to say if weapon is stuck in the front or the back  */
sf17k's avatar
sf17k committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
    int weaponstuckwhere;

    int numwaypoints;
    XYZ waypoints[90];
    int waypointtype[90];
    float pausetime;

    XYZ headtarget;
    float interestdelay;

    XYZ finalfinaltarget;
    XYZ finaltarget;
    int finalpathfindpoint;
    int targetpathfindpoint;
    int lastpathfindpoint;
    int lastpathfindpoint2;
    int lastpathfindpoint3;
    int lastpathfindpoint4;

    int waypoint;

    XYZ lastseen;
    float lastseentime;
    float lastchecktime;
    float stunned;
    float surprised;
    float runninghowlong;
305
    int occluded;
sf17k's avatar
sf17k committed
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
    int lastoccluded;
    int laststanding;
    int escapednum;

    float speechdelay;
    float neckspurtdelay;
    float neckspurtparticledelay;
    float neckspurtamount;

    int whichskin;
    bool rabbitkickragdoll;

    Animation tempanimation;

    bool jumpclimb;

322
    Person();
323
    Person(FILE*, int, unsigned);
sf17k's avatar
sf17k committed
324

325 326
    void skeletonLoad(bool clothes = false);

327 328 329 330
    // convenience functions
    inline Joint& joint(int bodypart) { return skeleton.joints[skeleton.jointlabels[bodypart]]; }
    inline XYZ& jointPos(int bodypart) { return joint(bodypart).position; }
    inline XYZ& jointVel(int bodypart) { return joint(bodypart).velocity; }
331 332
    inline AnimationFrame& currentFrame() { return Animation::animations.at(animCurrent).frames.at(frameCurrent); }
    inline AnimationFrame& targetFrame() { return Animation::animations.at(animTarget).frames.at(frameTarget); }
333

334 335 336
    void setProportions(float head, float body, float arms, float legs);
    float getProportion(int part) const;
    XYZ getProportionXYZ(int part) const;
sf17k's avatar
sf17k committed
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391

    void CheckKick();
    void CatchFire();
    void DoBlood(float howmuch, int which);
    void DoBloodBig(float howmuch, int which);
    bool DoBloodBigWhere(float howmuch, int which, XYZ where);

    bool wasIdle() { return animation_bits[animCurrent] & ab_idle; }
    bool isIdle() { return animation_bits[animTarget] & ab_idle; }
    int getIdle();

    bool isSitting() { return animation_bits[animTarget] & ab_sit; }

    bool isSleeping() { return animation_bits[animTarget] & ab_sleep; }

    bool wasCrouch() { return animation_bits[animCurrent] & ab_crouch; }
    bool isCrouch() { return animation_bits[animTarget] & ab_crouch; }
    int getCrouch();

    bool wasStop() { return animation_bits[animCurrent] & ab_stop; }
    bool isStop() { return animation_bits[animTarget] & ab_stop; }
    int getStop();

    bool wasSneak();
    bool isSneak();
    int getSneak();

    bool wasRun() { return animation_bits[animCurrent] & ab_run; }
    bool isRun() { return animation_bits[animTarget] & ab_run; }
    int getRun();

    bool wasLanding() { return animation_bits[animCurrent] & ab_land; }
    bool isLanding() { return animation_bits[animTarget] & ab_land; }
    int getLanding();

    bool wasLandhard() { return animation_bits[animCurrent] & ab_landhard; }
    bool isLandhard() { return animation_bits[animTarget] & ab_landhard; }
    int getLandhard();

    bool wasFlip() { return animation_bits[animCurrent] & ab_flip; }
    bool isFlip() { return animation_bits[animTarget] & ab_flip; }

    bool isWallJump() { return animation_bits[animTarget] & ab_walljump; }
    void Reverse();
    void DoDamage(float howmuch);
    void DoHead();
    void DoMipmaps() {
        skeleton.drawmodel.textureptr.bind();
        glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skeleton.skinsize, skeleton.skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0]);
    }

    int SphereCheck(XYZ *p1, float radius, XYZ *p, XYZ *move, float *rotate, Model *model);
    int DrawSkeleton();
    void Puff(int whichlabel);
392
    void FootLand(bodypart whichfoot, float opacity);
sf17k's avatar
sf17k committed
393
    void DoStuff();
MCMic's avatar
MCMic committed
394
    void setTargetAnimation(int);
sf17k's avatar
sf17k committed
395 396
    void DoAnimations();
    void RagDoll(bool checkcollision);
397 398

    void takeWeapon (int weaponId);
MCMic's avatar
MCMic committed
399 400

    bool addClothes(const int& clothesId);
401
    void addClothes();
MCMic's avatar
MCMic committed
402 403

    void doAI();
Ryan C. Gordon's avatar
Ryan C. Gordon committed
404 405
};

406
const int maxplayers = 10;
407

408
#endif