OpenGTA/game_objects.h

233 lines
7.7 KiB
C
Raw Permalink Normal View History

2015-12-03 00:37:37 +00:00
/************************************************************************
* Copyright (c) 2005-2007 tok@openlinux.org.uk *
* *
* This software is provided as-is, without any express or implied *
* warranty. In no event will the authors be held liable for any *
* damages arising from the use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose, *
* including commercial applications, and to alter it and redistribute *
* it freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; you must *
* not claim that you wrote the original software. If you use this *
* software in a product, an acknowledgment in the product documentation *
* would be appreciated but is not required. *
* *
* 2. Altered source versions must be plainly marked as such, and must *
* not be misrepresented as being the original software. *
* *
* 3. This notice may not be removed or altered from any source *
* distribution. *
************************************************************************/
#ifndef GAME_OBJECTS_H
#define GAME_OBJECTS_H
#include "math3d.h"
#include "obox.h"
#include "animation.h"
#include "opengta.h"
#include "cell_iterator.h"
#include "entity_controller.h"
#include "OpenSteer/Proximity.h"
2015-12-03 00:38:22 +00:00
#include "util/set.h"
2018-09-23 05:57:34 +00:00
#include <list>
2015-12-03 00:37:37 +00:00
namespace OpenGTA {
struct GameObject_common;
typedef OpenSteer::AbstractTokenForProximityDatabase<GameObject_common*> ProximityToken;
typedef OpenSteer::AbstractProximityDatabase<GameObject_common*> ProximityDatabase;
2018-09-27 23:44:35 +00:00
2015-12-03 00:37:37 +00:00
struct GameObject_common {
2018-09-27 23:44:35 +00:00
PositionController& positionController;
float bSphereRadius = 0.1f;
float rot() const { return positionController.rot; }
Vector3D pos() const { return Vector3D(positionController.pos(0), positionController.pos(1), positionController.pos(2)); }
GameObject_common() = delete;
GameObject_common(PositionController& newPositionController) : positionController(newPositionController) {}
GameObject_common(const GameObject_common & o) = default;
2015-12-03 00:37:37 +00:00
float heightOverTerrain(const Vector3D &);
ProximityToken* proxToken;
};
2018-09-27 23:44:35 +00:00
2015-12-03 00:37:37 +00:00
class Sprite {
public:
struct Animation : public Util::Animation {
Animation();
Animation(const Animation & other);
Animation(Uint16 foff, Uint8 num);
Animation(Uint16 foff, Uint8 num, float speed);
Uint16 firstFrameOffset;
//Uint8 numFrames;
float moveSpeed;
};
Sprite();
Sprite(Uint16 sprN, Sint16 rem, GraphicsBase::SpriteNumbers::SpriteTypes sprT);
Sprite(const Sprite & o);
Uint16 sprNum;
Sint16 remap;
Animation anim;
Uint32 animId;
GraphicsBase::SpriteNumbers::SpriteTypes sprType;
Uint8 calcCurrentFrame(Uint32 ticks);
void switchToAnim(const Uint32 & newId);
};
class Pedestrian : public GameObject_common, public Sprite, public OBox {
public:
2018-09-27 23:44:35 +00:00
Pedestrian(Vector3D, const Vector3D &, uint32_t id, Sint16 remapId, PlayerPedController& newPlayerController);
2015-12-03 00:37:37 +00:00
Pedestrian(const Pedestrian & o);
uint32_t pedId;
inline uint32_t id() const { return pedId; }
void equip(uint8_t eq_id);
2018-09-27 23:44:35 +00:00
void giveItem(uint8_t id, uint32_t amount);
PlayerPedController& playerController;
//PedController m_control;
void update(Uint32 ticks);
2015-12-03 00:37:37 +00:00
Uint32 lastUpdateAt;
Uint32 lastWeaponTick;
Vector3D speedForces;
bool inGroundContact;
uint8_t isDead;
2015-12-03 00:38:22 +00:00
void getShot(uint32_t shooterId, uint32_t dmg, bool front = true);
2015-12-03 00:37:37 +00:00
void die();
2018-09-23 11:14:17 +00:00
void getInCar();
2015-12-03 00:38:22 +00:00
typedef std::map<uint8_t, uint32_t> InventoryMap;
InventoryMap inventory;
uint8_t activeWeapon;
uint32_t * activeAmmo;
2018-09-23 11:14:17 +00:00
uint32_t aiMode = 0;
2015-12-03 00:38:22 +00:00
static uint32_t fistAmmo;
struct AiData {
AiData() : id1(0), id2(0), pos1() {}
AiData(const AiData & o) : id1(o.id1), id2(o.id2), pos1(o.pos1) {}
uint32_t id1;
uint32_t id2;
Vector3D pos1;
};
AiData aiData;
Vector3D moveDelta;
2018-09-23 11:14:17 +00:00
//Xperimental -- Vladislav Khorev vladislav.khorev@fishrungames.com
uint32_t aimCarId = 0;
2015-12-03 00:38:22 +00:00
};
class CarSprite {
public:
class DoorDeltaAnimation : public Util::Animation {
public:
DoorDeltaAnimation(uint8_t dId, bool dOpen);
uint8_t doorId;
bool opening;
};
CarSprite();
CarSprite(Uint16 sprN, Sint16 rem, GraphicsBase::SpriteNumbers::SpriteTypes sprT);
CarSprite(const CarSprite & o);
Uint16 sprNum;
Sint16 remap;
GraphicsBase::SpriteNumbers::SpriteTypes sprType;
uint32_t delta;
Util::Set deltaSet;
Util::Set animState;
void setDamage(uint8_t k);
void openDoor(uint8_t k);
void closeDoor(uint8_t k);
void setSirenAnim(bool on);
bool assertDeltaById(uint8_t k);
void update(Uint32 ticks);
private:
typedef std::list<DoorDeltaAnimation> DoorAnimList;
DoorAnimList doorAnims;
Uint32 lt_siren;
2015-12-03 00:37:37 +00:00
};
2015-12-03 00:38:22 +00:00
class Car : public GameObject_common, public CarSprite, public OBox {
2015-12-03 00:37:37 +00:00
public:
Car(const Car & o);
2018-09-27 23:44:35 +00:00
Car(OpenGTA::Map::ObjectPosition&, uint32_t id, PositionController& positionController);
Car(const Vector3D & _pos, float _rot, uint32_t id, uint8_t _type, int16_t _remap, PositionController& positionController);
2015-12-03 00:37:37 +00:00
uint32_t carId;
inline uint32_t id() const { return carId; }
GraphicsBase::CarInfo & carInfo;
uint8_t type;
void update(Uint32 ticks);
2018-09-23 11:53:57 +00:00
Uint32 lastUpdateAt = 0;
2015-12-03 00:38:22 +00:00
void damageAt(const Vector3D & hit, uint32_t dmg);
void explode();
2018-09-23 11:14:17 +00:00
void tryMove(Vector3D nPos);
PedController m_control;
Vector3D moveDelta = Vector3D(0, 0, 0);
//Vector3D velocity = Vector3D(0, 0, 0);
float velocity = 0;
2018-09-23 11:53:57 +00:00
float gravitySpeed = 0;
int inGroundContact = 0;
2015-12-03 00:38:22 +00:00
private:
void fixSpriteType();
int32_t hitPoints;
2018-09-23 11:14:17 +00:00
2015-12-03 00:37:37 +00:00
};
class SpriteObject : public GameObject_common, public Sprite, public OBox {
public:
2018-09-27 23:44:35 +00:00
SpriteObject(OpenGTA::Map::ObjectPosition&, uint32_t id, PositionController& positionController);
SpriteObject(Vector3D pos, Uint16 spriteNum, GraphicsBase::SpriteNumbers::SpriteTypes st, PositionController& positionController);
2015-12-03 00:37:37 +00:00
SpriteObject(const SpriteObject & o);
uint32_t objId;
inline uint32_t id() const { return objId; }
void update(Uint32 ticks);
Uint32 lastUpdateAt;
bool isActive;
};
/*
class TrainSegment : public GameObject_common, public OBox {
public:
TrainSegment(uint32_t id, Util::CellIterator & cell);
TrainSegment(const TrainSegment & o);
uint32_t trainId;
inline uint32_t id() const { return trainId; }
};*/
class Projectile : public GameObject_common {
public:
2018-09-27 23:44:35 +00:00
Projectile(uint8_t, Vector3D, uint32_t, uint32_t, PositionController& positionController);
2015-12-03 00:37:37 +00:00
Projectile(const Projectile & other);
uint8_t typeId;
Vector3D delta;
uint32_t endsAtTick;
uint32_t owner;
void update(Uint32 ticks);
Uint32 lastUpdateAt;
2015-12-03 00:38:22 +00:00
bool testCollideBlock(Util::CellIterator &, Vector3D & newp);
bool testCollideBlock_flat(Util::CellIterator &, Vector3D & newp);
static uint32_t damageByType(const uint8_t & k);
2015-12-03 00:37:37 +00:00
};
}
#endif