#include <StdAfx.h>
#include "TRLara.h"

TRLara Lara; // global

#define NO_WATER 32512

//===================================================================//
//                    ADDRESS FOR LARA STRUCTURE                     //
//===================================================================//

#define LaraItemIndex                        VAR(0x0080DEC0, short) // Lara item_index :)
#define LaraGunStatus                        VAR(0x0080DEC2, short) // (LARA_HOLD_STATUS flags)
#define LaraGunType                          VAR(0x0080DEC4, short) // (LARA_HOLD flags)
#define LaraGunRequestType                   VAR(0x0080DEC6, short) // (LARA_HOLD flags)
#define LaraGunLastType                      VAR(0x0080DEC8, short) // (LARA_HOLD flags)
#define LaraCalcFallSpeed                    VAR(0x0080DECA, short)
#define LaraWaterStatus                      VAR(0x0080DECC, short) // (LARA_WATER_STATUS flags)
#define LaraClimbStatus                      VAR(0x0080DECE, int)   // (LARA_CLIMB_STATUS flags)
#define LaraPoseCount                        VAR(0x0080DED2, short)
#define LaraHitDirection                     VAR(0x0080DED4, short)
#define LaraAir                              VAR(0x0080DED6, short)
#define LaraDiveCount                        VAR(0x0080DED8, short)
#define LaraDeathCount                       VAR(0x0080DEDA, short)
#define LaraUnderwaterActive                 VAR(0x0080DEDC, short)
#define LaraUnderwaterVelocity               VAR(0x0080DEDE, PHD_VECTOR_SHORT) // underwater velocity
#define LaraSpazEffectCount                  VAR(0x0080DEE2, short)
#define LaraFlareAge                         VAR(0x0080DEE6, short)
#define LaraSkidoo                           VAR(0x0080DEE8, short)
#define LaraWeaponItem                       VAR(0x0080DEEA, short)
#define LaraWeaponBackItem                   VAR(0x0080DEEC, short)
///     LaraFlareFrame
#define LaraPoison1                          VAR(0x0080DEF0, short)
#define LaraPoison2                          VAR(0x0080DEF2, short)
#define LaraWet                              VAA(0x0080DEF4, BYTE, [15])
#define LaraFlags                            VAR(0x0080DF04, WORD) // (FLF_ flags)
#define LaraWaterSurfaceDist                 VAR(0x0080DF06, long) //80DF12 ?
#define LaraMeshEffects                      VAR(0x0080DF1A, int)
#define LaraMeshPtrs                         VAA(0x0080DF1E, StrMeshTr4*, [15])
#define LaraMeshTightRight                   VAR(0x0080DF22, StrMeshTr4*)
#define LaraMeshTightLeft                    VAR(0x0080DF2E, StrMeshTr4*)
#define LaraMeshCalf                         VAR(0x0080DF32, StrMeshTr4*)
#define LaraMeshTorso                        VAR(0x0080DF3A, StrMeshTr4*)
#define LaraMeshRightArm                     VAR(0x0080DF3E, StrMeshTr4*)
#define LaraMeshRightHand                    VAR(0x0080DF46, StrMeshTr4*)
#define LaraMeshLeftArm                      VAR(0x0080DF4A, StrMeshTr4*)
#define LaraMeshLeftHand                     VAR(0x0080DF52, StrMeshTr4*)
#define LaraMeshHead                         VAR(0x0080DF56, StrMeshTr4*)
#define LaraTarget                           VAR(0x0080DF5A, ITEM_INFO*)
#define LaraTargetAngleY                     VAR(0x0080DF5E, short)
#define LaraTargetAngleX                     VAR(0x0080DF60, short)
#define LaraTurnRate                         VAR(0x0080DF62, short)
#define LaraMoveAngle                        VAR(0x0080DF64, short)
#define LaraHeadYRot                         VAR(0x0080DF66, short)
#define LaraHeadXRot                         VAR(0x0080DF68, short)
#define LaraHeadZRot                         VAR(0x0080DF6A, short)
#define LaraTorsoYRot                        VAR(0x0080DF6C, short)
#define LaraTorsoXRot                        VAR(0x0080DF6E, short)
#define LaraTorsoZRot                        VAR(0x0080DF70, short)
#define LaraLeftArm                          VAR(0x0080DF72, LARA_ARM)
#define LaraRightArm                         VAR(0x0080DF84, LARA_ARM)
#define LaraUnknown2                         VAR(0x0080DF96, short)
#define LaraUnknown3                         VAR(0x0080DF98, int)
#define LaraCornerX                          VAR(0x0080DF9C, DWORD)
#define LaraCornerZ                          VAR(0x0080DFA0, DWORD)
#define LaraRopeVelocity                     VAR(0x0080DFA4, int)
#define LaraRopeStuff                        VAR(0x0080DFA8, short)
#define LaraRopeRocking                      VAR(0x0080DFAA, short)
#define LaraRopeOrientVelocity               VAR(0x0080DFAC, short)
#define LaraRopeAlwaysStuff                  VAR(0x0080DFAE, short)
#define LaraRopeFirstFrameAnim               VAR(0x0080DFB0, int)
#define LaraRopeAnchorFrameAnim              VAR(0x0080DFB4, int)
#define LaraRopeNextFrameAnim                VAR(0x0080DFB8, int)
#define LaraRopeIndex                        VAR(0x0080DFBC, int)
#define LaraGeneralPtr                       VAR(0x0080DFC0, void*) // LPVOID ?
#define LaraRope                             VAR(0x0080DFC4, int)
#define LaraIncreaseByRope                   VAR(0x0080DFC8, int)
#define LaraRopeTestStop                     VAR(0x0080DFCC, bool)
#define Lara90FramePause                     VAR(0x0080DFCD, char)
#define LaraPauseParRope                     VAR(0x0080DFCE, int)
#define LaraPistolTypeCarried                VAR(0x0080DFD2, char)
#define LaraUzisTypeCarried                  VAR(0x0080DFD3, char)
#define LaraShotgunTypeCarried               VAR(0x0080DFD4, char)
#define LaraCrossbowTypeCarried              VAR(0x0080DFD5, char)
#define LaraGrenadeGunTypeCarried            VAR(0x0080DFD6, char)
#define LaraRevolverTypeCarried              VAR(0x0080DFD7, char)
#define LaraLaserSightCarried                VAR(0x0080DFD8, char)
#define LaraBinocularsCarried                VAR(0x0080DFD9, char)
#define LaraCrowbarCarried                   VAR(0x0080DFDA, char)
#define LaraScarabCarried                    VAR(0x0080DFDB, char)
#define LaraSmallWaterBottleCarried          VAR(0x0080DFDC, char)
#define LaraExamine1Carried                  VAR(0x0080DFDE, char)
#define LaraExamine2Carried                  VAR(0x0080DFDF, char)
#define LaraExamine3Carried                  VAR(0x0080DFE0, char)
#define LaraPuzzle1Carried                   VAR(0x0080DFE1, char)
#define LaraPuzzle2Carried                   VAR(0x0080DFE2, char)
#define LaraPuzzle3Carried                   VAR(0x0080DFE3, char)
#define LaraPuzzle4Carried                   VAR(0x0080DFE4, char)
#define LaraPuzzle5Carried                   VAR(0x0080DFE5, char)
#define LaraPuzzle6Carried                   VAR(0x0080DFE6, char)
#define LaraPuzzle7Carried                   VAR(0x0080DFE7, char)
#define LaraPuzzle8Carried                   VAR(0x0080DFE8, char)
#define LaraPuzzle9Carried                   VAR(0x0080DFE9, char)
#define LaraPuzzle10Carried                  VAR(0x0080DFEA, char)
#define LaraPuzzle11Carried                  VAR(0x0080DFEB, char)
#define LaraPuzzle12Carried                  VAR(0x0080DFEC, char)
#define LaraPuzzleItemComboCarried           VAR(0x0080DFED, WORD)
#define LaraKeyItemCarried                   VAR(0x0080DFEF, WORD)
#define LaraKeyComboItemCarried              VAR(0x0080DFF1, WORD)
#define LaraPickupItemCarried                VAR(0x0080DFF3, WORD)
#define LaraPickupComboCarried               VAR(0x0080DFF5, WORD)
#define LaraQuestItemCarried                 VAR(0x0080DFF7, WORD)
#define LaraSmallMedikitCount                VAR(0x0080DFF9, short)
#define LaraBigMedikitCount                  VAR(0x0080DFFB, short)
#define LaraFlareCount                       VAR(0x0080DFFD, short)
#define LaraAmmoPistolCount                  VAR(0x0080DFFF, short)
#define LaraAmmoUziCount                     VAR(0x0080E001, short)
#define LaraAmmoRevolverCount                VAR(0x0080E003, short)
#define LaraAmmoShotgunNormalCount           VAR(0x0080E005, short)
#define LaraAmmoShotgunWideCount             VAR(0x0080E007, short)
#define LaraAmmoGrenadeNormalCount           VAR(0x0080E009, short)
#define LaraAmmoGrenadeSuperCount            VAR(0x0080E00B, short)
#define LaraAmmoGrenadeFlashCount            VAR(0x0080E00D, short)
#define LaraAmmoCrossbowNormalCount          VAR(0x0080E00F, short)
#define LaraAmmoCrossbowPoisonCount          VAR(0x0080E011, short)
#define LaraAmmoCrossbowExplodeCount         VAR(0x0080E013, short)

//===================================================================//
//                 GET FUNCTION FOR LARA STRUCTURE                   //
//===================================================================//

short TRLara::getItemIndex()
{
    return LaraItemIndex;
}

short TRLara::getGunStatus()
{
    return LaraGunStatus;
}

short TRLara::getGunType()
{
    return LaraGunType;
}

short TRLara::getGunRequestType()
{
    return LaraGunRequestType;
}

short TRLara::getGunLastType()
{
    return LaraGunLastType;
}

short TRLara::getCalcFallspeed()
{
    return LaraCalcFallSpeed;
}

short TRLara::getWaterStatus()
{
    return LaraWaterStatus;
}

int TRLara::getClimbStatus()
{
    return LaraClimbStatus;
}

short TRLara::getPoseCount()
{
    return LaraPoseCount;
}

short TRLara::getHitDirection()
{
    return LaraHitDirection;
}

short TRLara::getAir()
{
    return LaraAir;
}

short TRLara::getDiveCount()
{
    return LaraDiveCount;
}

short TRLara::getDeathCount()
{
    return LaraDeathCount;
}

short TRLara::getUnderwaterActive()
{
    return LaraUnderwaterActive;
}

short TRLara::getSpazEffectCount()
{
    return LaraSpazEffectCount;
}

short TRLara::getFlareAge()
{
    return LaraFlareAge;
}

short TRLara::getSkidoo()
{
    return LaraSkidoo;
}

short TRLara::getWeaponItem()
{
    return LaraWeaponItem;
}

short TRLara::getWeaponBackItem()
{
    return LaraWeaponBackItem;
}

short TRLara::getFlareFrame()
{
    return LaraFlareFrame;
}

short TRLara::getPoison1()
{
    return LaraPoison1;
}

short TRLara::getPoison2()
{
    return LaraPoison2;
}

BYTE TRLara::getWet(BYTE index)
{
    return LaraWet[index];
}

WORD TRLara::getFlags(WORD Flags)
{
    return (LaraFlags & Flags);
}

bool TRLara::isFlagsEnabled(WORD Flags)
{
    return (LaraFlags & Flags) != FALSE;
}

long TRLara::getWaterSurfaceDist()
{
    return DOUBLE_VALUE_VALUE(LaraWaterSurfaceDist, NO_WATER, 0, LaraWaterSurfaceDist);
}

int TRLara::getMeshEffects()
{
    return LaraMeshEffects;
}

StrMeshTr4* TRLara::getMeshPtrs(LARA_MESHES mesh)
{
    return LaraMeshPtrs[mesh];
}

StrMeshTr4* TRLara::getMeshTightRight()
{
    return LaraMeshTightRight;
}

StrMeshTr4* TRLara::getMeshTightLeft()
{
    return LaraMeshTightLeft;
}

StrMeshTr4* TRLara::getMeshCalf()
{
    return LaraMeshCalf;
}

StrMeshTr4* TRLara::getMeshTorso()
{
    return LaraMeshTorso;
}

StrMeshTr4* TRLara::getMeshRightArm()
{
    return LaraMeshRightArm;
}

StrMeshTr4* TRLara::getMeshRightHand()
{
    return LaraMeshRightHand;
}

StrMeshTr4* TRLara::getMeshLeftArm()
{
    return LaraMeshLeftArm;
}

StrMeshTr4* TRLara::getMeshLeftHand()
{
    return LaraMeshLeftHand;
}

StrMeshTr4* TRLara::getMeshHead()
{
    return LaraMeshHead;
}

ITEM_INFO* TRLara::getTarget()
{
    return LaraTarget;
}

short TRLara::getTargetAngleY()
{
    return LaraTargetAngleY;
}

short TRLara::getTargetAngleX()
{
    return LaraTargetAngleX;
}

short TRLara::getTurnRate()
{
    return LaraTurnRate;
}

short TRLara::getMoveAngle()
{
    return LaraMoveAngle;
}

short TRLara::getHeadX()
{
    return LaraHeadXRot;
}

short TRLara::getHeadY()
{
    return LaraHeadYRot;
}

short TRLara::getHeadZ()
{
    return LaraHeadZRot;
}

short TRLara::getTorsoX()
{
    return LaraTorsoXRot;
}

short TRLara::getTorsoY()
{
    return LaraTorsoYRot;
}

short TRLara::getTorsoZ()
{
    return LaraTorsoZRot;
}

LARA_ARM* TRLara::getLeftArm()
{
    return &LaraLeftArm;
}

LARA_ARM* TRLara::getRightArm()
{
    return &LaraRightArm;
}

bool TRLara::isPistolCarried()
{
    return (LaraPistolTypeCarried & 1);
}

bool TRLara::isUziCarried()
{
    return (LaraUzisTypeCarried & 1);
}

bool TRLara::isShotgunCarried()
{
    return (LaraShotgunTypeCarried & 1);
}

bool TRLara::isRevolverCarried()
{
    return (LaraRevolverTypeCarried & 1);
}

bool TRLara::isCrossbowCarried()
{
    return (LaraCrowbarCarried & 1);
}

bool TRLara::isGrenadeCarried()
{
    return (LaraGrenadeGunTypeCarried & 1);
}

bool TRLara::isMagnumCarried()
{
    return false;
}

bool TRLara::isAutopistolCarried()
{
    return false;
}

bool TRLara::isDesertEagleCarried()
{
    return false;
}

bool TRLara::isM16Carried()
{
    return false;
}

bool TRLara::isMP5Carried()
{
    return false;
}

bool TRLara::isRocketCarried()
{
    return false;
}

bool TRLara::isHarpoonCarried()
{
    return false;
}

bool TRLara::isFlareCarried()
{
    return (LaraFlareCount & 1);
}

bool TRLara::isFlareEmpty()
{
    return  LaraFlareCount == NO_ITEM;
}

bool TRLara::isFlareNotEmpty()
{
    return LaraFlareCount != NO_ITEM;
}

//===================================================================//
//                 SET FUNCTION FOR LARA STRUCTURE                   //
//===================================================================//

void TRLara::setGunStatus(short value)
{
    LaraGunStatus = value;
}

void TRLara::setGunType(short value)
{
    LaraGunType = value;
}

void TRLara::setGunRequestType(short value)
{
    LaraGunRequestType = value;
}

void TRLara::setGunLastType(short value)
{
    LaraGunLastType = value;
}

void TRLara::setCalcFallspeed(short value)
{
    LaraCalcFallSpeed = value;
}

void TRLara::setWaterStatus(LARA_WATER_STATUS value)
{
    LaraWaterStatus = value;
}

void TRLara::setClimbStatus(short value)
{
    LaraClimbStatus = value;
}

void TRLara::setPoseCount(short value)
{
    LaraPoseCount = value;
}

// -1 by default !
void TRLara::setHitDirection(short value)
{
    LaraHitDirection = value;
}

void TRLara::setAir(short value)
{
    LaraAir = value;
}

void TRLara::setDiveCount(short value)
{
    LaraDiveCount = value;
}

void TRLara::setDeathCount(short value)
{
    LaraDeathCount = value;
}

void TRLara::setUnderwaterActive(short value)
{
    LaraUnderwaterActive = value;
}

void TRLara::setSpazEffectCount(short value)
{
    LaraSpazEffectCount = value;
}

void TRLara::setFlareAge(short value)
{
    LaraFlareAge = value;
}

void TRLara::setSkidoo(short value)
{
    LaraSkidoo = value;
}

void TRLara::setWeaponItem(short value)
{
    LaraWeaponItem = value;
}

void TRLara::setWeaponBackItem(short value)
{
    LaraWeaponBackItem = value;
}

void TRLara::setFlareFrame(short value)
{
    LaraFlareFrame = value;
}

void TRLara::setPoison1(short value)
{
    LaraPoison1 = value;
}

void TRLara::setPoison2(short value)
{
    LaraPoison2 = value;
}

void TRLara::setWet(BYTE index, BYTE value)
{
    LaraWet[index] = value;
}

void TRLara::addFlags(WORD flags)
{
    LaraFlags |= flags;
}

void TRLara::deleteFlags(WORD flags)
{
    LaraFlags &= ~(flags);
}

void TRLara::setMeshPtrs(LARA_MESHES mesh_of_lara, short slots, LARA_MESHES mesh_of_slot)
{
    LaraMeshPtrs[mesh_of_lara] = Ptr_VetMeshes[Ptr_VetObjects[slots].mesh_index + mesh_of_slot * 2];
}

void TRLara::setMeshTightRight(short slots, LARA_MESHES meshes)
{
    LaraMeshTightRight = Ptr_VetMeshes[Ptr_VetObjects[slots].mesh_index + meshes * 2];
}

void TRLara::setMeshTightLeft(short slots, LARA_MESHES meshes)
{
    LaraMeshTightLeft = Ptr_VetMeshes[Ptr_VetObjects[slots].mesh_index + meshes * 2];
}

void TRLara::setMeshCalf(short slots, LARA_MESHES meshes)
{
    LaraMeshCalf = Ptr_VetMeshes[Ptr_VetObjects[slots].mesh_index + meshes * 2];
}

void TRLara::setMeshTorso(short slots, LARA_MESHES meshes)
{
    LaraMeshTorso = Ptr_VetMeshes[Ptr_VetObjects[slots].mesh_index + meshes * 2];
}

void TRLara::setMeshRightArm(short slots, LARA_MESHES meshes)
{
    LaraMeshRightArm = Ptr_VetMeshes[Ptr_VetObjects[slots].mesh_index + meshes * 2];
}

void TRLara::setMeshRightHand(short slots, LARA_MESHES meshes)
{
    LaraMeshRightHand = Ptr_VetMeshes[Ptr_VetObjects[slots].mesh_index + meshes * 2];
}

void TRLara::setMeshLeftArm(short slots, LARA_MESHES meshes)
{
    LaraMeshLeftArm = Ptr_VetMeshes[Ptr_VetObjects[slots].mesh_index + meshes * 2];
}

void TRLara::setMeshLeftHand(short slots, LARA_MESHES meshes)
{
    LaraMeshLeftHand = Ptr_VetMeshes[Ptr_VetObjects[slots].mesh_index + meshes * 2];
}

void TRLara::setMeshHead(short slots, LARA_MESHES meshes)
{
    LaraMeshHead = Ptr_VetMeshes[Ptr_VetObjects[slots].mesh_index + meshes * 2];
}

void TRLara::setTarget(ITEM_INFO* target)
{
    LaraTarget = target;
}

void TRLara::setTargetAngleY(short angle)
{
    LaraTargetAngleY = angle;
}

void TRLara::setTargetAngleX(short angle)
{
    LaraTargetAngleX = angle;
}

void TRLara::setTargetAngle(short y_angle, short x_angle)
{
    LaraTargetAngleY = y_angle;
    LaraTargetAngleX = x_angle;
}

void TRLara::setTurnRate(short rate)
{
    LaraTurnRate = rate;
}

void TRLara::setTurnRate(short rate, bool substract)
{
    if (!substract)
        LaraTurnRate += rate;
    else
        LaraTurnRate -= rate;
}

void TRLara::setMoveAngle(short angle)
{
    LaraMoveAngle = angle;
}

void TRLara::setMoveAngle(short angle, bool substract)
{
    if (!substract)
        LaraMoveAngle += angle;
    else
        LaraMoveAngle -= angle;
}

void TRLara::setHeadX(short angle)
{
    LaraHeadXRot = angle;
}

void TRLara::setHeadX(short angle, bool substract)
{
    if (!substract)
        LaraHeadXRot += angle;
    else
        LaraHeadXRot -= angle;
}

void TRLara::setHeadY(short angle)
{
    LaraHeadYRot = angle;
}

void TRLara::setHeadY(short angle, bool substract)
{
    if (!substract)
        LaraHeadYRot += angle;
    else
        LaraHeadYRot -= angle;
}

void TRLara::setHeadZ(short angle)
{
    LaraHeadZRot = angle;
}

void TRLara::setHeadZ(short angle, bool substract)
{
    if (!substract)
        LaraHeadZRot += angle;
    else
        LaraHeadZRot -= angle;
}

void TRLara::setTorsoX(short angle)
{
    LaraTorsoXRot = angle;
}

void TRLara::setTorsoX(short angle, bool substract)
{
    if (!substract)
        LaraTorsoXRot += angle;
    else
        LaraTorsoXRot -= angle;
}

void TRLara::setTorsoY(short angle)
{
    LaraTorsoYRot = angle;
}

void TRLara::setTorsoY(short angle, bool substract)
{
    if (!substract)
        LaraTorsoYRot += angle;
    else
        LaraTorsoYRot -= angle;
}

void TRLara::setTorsoZ(short angle)
{
    LaraTorsoZRot = angle;
}

void TRLara::setTorsoZ(short angle, bool substract)
{
    if (!substract)
        LaraTorsoZRot += angle;
    else
        LaraTorsoZRot -= angle;
}

void TRLara::setArmFrameBase(bool isLeft, short* frame_base)
{
    if (isLeft)
        LaraLeftArm.frame_base = frame_base;
    else
        LaraRightArm.frame_base = frame_base;
}

void TRLara::setArmAnim(bool isLeft, short anim)
{
    if (isLeft)
        LaraLeftArm.anim_number = anim;
    else
        LaraRightArm.anim_number = anim;
}

void TRLara::setArmFrame(bool isLeft, short frame)
{
    if (isLeft)
        LaraLeftArm.frame_number = frame;
    else
        LaraRightArm.frame_number = frame;
}

void TRLara::setArmLock(bool isLeft, bool isLocked)
{
    if (isLeft)
        LaraLeftArm.lock = isLocked;
    else
        LaraRightArm.lock = isLocked;
}

void TRLara::setArmDoubleLock(bool isLockL, bool isLockR)
{
    LaraLeftArm.lock = isLockL;
    LaraRightArm.lock = isLockR;
}

void TRLara::setArmRotY(bool isLeft, short y_rot)
{
    if (isLeft)
        LaraLeftArm.y_rot = y_rot;
    else
        LaraRightArm.y_rot = y_rot;
}

void TRLara::setArmRotX(bool isLeft, short x_rot)
{
    if (isLeft)
        LaraLeftArm.x_rot = x_rot;
    else
        LaraRightArm.x_rot = x_rot;
}

void TRLara::setArmRotZ(bool isLeft, short z_rot)
{
    if (isLeft)
        LaraLeftArm.z_rot = z_rot;
    else
        LaraRightArm.z_rot = z_rot;
}

void TRLara::setArmFlashGun(bool isLeft, short flash_time)
{
    if (isLeft)
        LaraLeftArm.flash_gun = flash_time;
    else
        LaraRightArm.flash_gun = flash_time;
}

void TRLara::decreaseFlare()
{
    --LaraFlareCount;
}
