]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Person.h
Stopped using Account pointers, and removed general difficulty setting (difficulty...
[lugaru.git] / Source / Person.h
index 56d4f5490b87fe0562558594702b723037d25f97..cb62622f0710f4984aa2e846e5797cde223dd139 100644 (file)
@@ -1,22 +1,21 @@
 /*
 Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
 
 This file is part of Lugaru.
 
-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.
+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.
 
-This program is distributed in the hope that it will be useful,
+Lugaru is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
-
-See the GNU General Public License for more details.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+along with Lugaru.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifndef _PERSON_H_
@@ -26,14 +25,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "gamegl.h"
 #include "Quaternions.h"
-#include "Skeleton.h"
+#include "Animation/Skeleton.h"
 #include "Models.h"
-#include "Constants.h"
 #include "Terrain.h"
 #include "Sprite.h"
 #include <cmath>
+#include <memory>
 #include "Weapons.h"
-#include "Animation.h"
+#include "Animation/Animation.h"
 
 #define passivetype 0
 #define guardtype 1
@@ -48,367 +47,357 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #define rabbittype 0
 #define wolftype 1
 
-class Person
+struct InvalidPersonException : public exception {
+   const char * what () const throw () {
+      return "Invalid weapon number";
+   }
+};
+
+class Person : public enable_shared_from_this<Person>
 {
-       public:
-               Person();
-               ~Person();
-
-               int whichpatchx;
-               int whichpatchz;
-               
-               int currentframe;
-               int targetframe;
-               int currentanimation;
-               int targetanimation;
-               int oldcurrentframe;
-               int oldtargetframe;
-               int oldcurrentanimation;
-               int oldtargetanimation;
-               
-               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 originalcoords;
-               XYZ velocity;
-               
-               XYZ proportionhead;
-               XYZ proportionlegs;
-               XYZ proportionarms;
-               XYZ proportionbody;
-               
-               float heightleft;
-               float heightright;
-               
-               float unconscioustime;
-               
-               bool immobile;
-               
-               float velspeed;
-               float targetrotation;
-               float targetrot;
-               float rot;
-               float oldrot;
-               float lookrotation;
-               float lookrotation2;
-               float rotation;
-               float rotation2;
-               float lowrotation;
-               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;
-               int dead;
-               
-               float jumppower;
-               bool onground;
-               int madskills;
-               
-               int wentforweapon;
-               
-               bool calcrot;
-               
-               bool backwardsanim;
-               
-               XYZ facing;
-               
-               float bleeding;
-               float bleedx,bleedy;
-               int direction;
-               float texupdatedelay;
-               
-               float headrotation,headrotation2;
-               float targetheadrotation,targetheadrotation2;
-               
-               bool onterrain;
-               bool pause;
-               
-               float grabdelay;
-               
-               Person *victim;
-               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;
-               int aitarget;
-               float aiupdatedelay;
-               float losupdatedelay;
-               int ally;
-               XYZ movetarget;
-               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;
-               float nocollidedelay;
-               
-               int creature;
-               
-               int id;
-               
-               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 fireduration;
-               
-               float flamedelay;
-               float updatestuffdelay;
-               
-               int playerdetail;
-               
-               int num_weapons;
-               int weaponids[4];
-               int weaponactive;
-               int weaponstuck;
-               int weaponstuckwhere;
-               int weaponwhere;
-               
-               int numwaypoints;
-               XYZ waypoints[90];
-               int waypointtype[90];
-               float pausetime;
-               bool hastempwaypoint;
-               XYZ tempwaypoint;
-               
-               XYZ headtarget;
-               float interestdelay;
-               
-               XYZ finalfinaltarget;
-               XYZ finaltarget;
-               int finalpathfindpoint;
-               int targetpathfindpoint;
-               int lastpathfindpoint;
-               int lastpathfindpoint2;
-               int lastpathfindpoint3;
-               int lastpathfindpoint4;
-               bool onpath;
-               
-               int waypoint;
-               bool jumppath;
-               
-               XYZ lastseen;
-               float lastseentime;
-               float lastchecktime;
-               float stunned;
-               float surprised;
-               float runninghowlong;           int lastoccluded;
-               int laststanding;
-               int escapednum;
-               
-               float speechdelay;
-               float neckspurtdelay;
-               float neckspurtparticledelay;
-               float neckspurtamount;
-               
-               int whichskin;
-               bool rabbitkickragdoll;
-               
-               XYZ averageloc;
-               XYZ oldaverageloc;
-               
-               Animation tempanimation;
-               
-               float occluded;
-               
-               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[currentanimation] & ab_idle;
-               }
-               bool isIdle()
-               {
-                 return animation_bits[targetanimation] & ab_idle;
-               }
-               int getIdle();
-               
-               bool isSitting()
-               {
-                 return animation_bits[targetanimation] & ab_sit;
-               }
-
-               bool isSleeping()
-               {
-                 return animation_bits[targetanimation] & ab_sleep;
-               }
-
-               bool wasCrouch()
-               {
-                 return animation_bits[currentanimation] & ab_crouch;
-               }
-               bool isCrouch()
-               {
-                 return animation_bits[targetanimation] & ab_crouch;
-               }
-               int getCrouch();
-               
-               bool wasStop()
-               {
-                 return animation_bits[currentanimation] & ab_stop;
-               }
-               bool isStop()
-               {
-                 return animation_bits[targetanimation] & ab_stop;
-               }
-               int getStop();
-               
-               bool wasSneak();
-               bool isSneak();
-               int getSneak();
-               
-               bool wasRun()
-               {
-                 return animation_bits[currentanimation] & ab_run;
-               }
-               bool isRun()
-               {
-                 return animation_bits[targetanimation] & ab_run;
-               }
-               int getRun();
-
-               bool wasLanding()
-               {
-                 return animation_bits[currentanimation] & ab_land;
-               }
-               bool isLanding()
-               {
-                 return animation_bits[targetanimation] & ab_land;
-               }
-               int getLanding();
-               
-               bool wasLandhard();
-               bool isLandhard();
-               int getLandhard();
-               
-               bool isFlip();
-               bool wasFlip();
-               
-               bool jumpclimb;
-               
-               bool isWallJump();
-               void Reverse();
-               void DoDamage(float howmuch);
-               void DoHead();
-               void DoMipmaps(int howmanylevels, float startx, float endx, float starty, float endy);
-               int SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate, Model *model);
-               int DrawSkeleton();
-               void Puff(int whichlabel);
-               void FootLand(int which, float opacity);
-               void DoStuff();
-               void DoAnimations();
-               void RagDoll(bool checkcollision);
+public:
+    static std::vector<std::shared_ptr<Person>> players;
+
+    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;
+
+    XYZ proportionhead;
+    XYZ proportionlegs;
+    XYZ proportionarms;
+    XYZ proportionbody;
+
+    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;
+    /* Seems to be 0 = alive, 1 = unconscious, 2 = dead */
+    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;
+
+    std::shared_ptr<Person> victim;
+    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;
+
+    unsigned id;
+
+    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];
+    /* 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 */
+    int weaponactive;
+    int weaponstuck;
+    /* 0 or 1 to say if weapon is stuck in the front or the back  */
+    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;
+    int occluded;
+    int lastoccluded;
+    int laststanding;
+    int escapednum;
+
+    float speechdelay;
+    float neckspurtdelay;
+    float neckspurtparticledelay;
+    float neckspurtamount;
+
+    int whichskin;
+    bool rabbitkickragdoll;
+
+    Animation tempanimation;
+
+    bool jumpclimb;
+
+    Person();
+    Person(FILE*, int, unsigned);
+
+    void skeletonLoad(bool clothes = false);
+
+    // 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; }
+    inline AnimationFrame& currentFrame() { return Animation::animations.at(animCurrent).frames.at(frameCurrent); }
+    inline AnimationFrame& targetFrame() { return Animation::animations.at(animTarget).frames.at(frameTarget); }
+
+
+    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);
+    void FootLand(bodypart whichfoot, float opacity);
+    void DoStuff();
+    void setAnimation(int);
+    void DoAnimations();
+    void RagDoll(bool checkcollision);
+
+    void takeWeapon (int weaponId);
+
+    bool addClothes(const int& clothesId);
+    void addClothes();
 };
 
-extern Person player[maxplayers];
+const int maxplayers = 10;
+
 #endif