1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 18:32:44 +01:00

clang-format files in rwengine/src/items

This commit is contained in:
Daniel Evans 2016-09-09 21:13:19 +01:00
parent 80e6317c24
commit 305737cc3d
3 changed files with 137 additions and 130 deletions

View File

@ -10,49 +10,57 @@ class CharacterObject;
*
* Instanciated once per item type
*/
class InventoryItem
{
int _itemID;
int _inventorySlot;
int _modelID;
class InventoryItem {
int _itemID;
int _inventorySlot;
int _modelID;
protected:
InventoryItem(int itemID, int invSlot, int model)
: _itemID(itemID), _inventorySlot(invSlot), _modelID(model)
{}
InventoryItem(int itemID, int invSlot, int model)
: _itemID(itemID), _inventorySlot(invSlot), _modelID(model) {
}
public:
virtual ~InventoryItem() {}
virtual ~InventoryItem() {
}
/**
* @brief getObject
* @return The ID of the model associated with the item.
*/
int getModelID() { return _modelID; }
/**
* @brief getObject
* @return The ID of the model associated with the item.
*/
int getModelID() {
return _modelID;
}
/**
* @brief getItemID
* @return The index of this item in the item list
*/
int getItemID() { return _itemID; }
/**
* @brief getItemID
* @return The index of this item in the item list
*/
int getItemID() {
return _itemID;
}
/**
* @brief getInventorySlot
* @return The inventory slot number for this item
*/
int getInventorySlot() const { return _inventorySlot; }
/**
* @brief getInventorySlot
* @return The inventory slot number for this item
*/
int getInventorySlot() const {
return _inventorySlot;
}
/**
* @brief primary Implements mouse 1 action
* @param owner The character using this item
*/
virtual void primary(CharacterObject* owner) = 0;
/**
* @brief primary Implements mouse 1 action
* @param owner The character using this item
*/
virtual void primary(CharacterObject* owner) = 0;
/**
* @see primary
* @param owner The character using this item
*/
virtual void secondary(CharacterObject* owner) = 0;
/**
* @see primary
* @param owner The character using this item
*/
virtual void secondary(CharacterObject* owner) = 0;
constexpr static int NO_INVSLOT = -1;
constexpr static int NO_INVSLOT = -1;
};
#endif

View File

@ -1,38 +1,39 @@
#include <items/WeaponItem.hpp>
#include <objects/CharacterObject.hpp>
#include <ai/CharacterController.hpp>
#include <data/Model.hpp>
#include <engine/Animator.hpp>
#include <engine/GameWorld.hpp>
#include <objects/ProjectileObject.hpp>
#include <data/Skeleton.hpp>
#include <engine/Animator.hpp>
#include <engine/GameData.hpp>
#include <engine/GameWorld.hpp>
#include <items/WeaponItem.hpp>
#include <objects/CharacterObject.hpp>
#include <objects/ProjectileObject.hpp>
void WeaponItem::fireHitscan(CharacterObject* owner)
{
auto handFrame = owner->model->resource->findFrame("srhand");
glm::mat4 handMatrix;
if( handFrame ) {
while( handFrame->getParent() ) {
handMatrix = owner->skeleton->getMatrix(handFrame->getIndex()) * handMatrix;
handFrame = handFrame->getParent();
}
}
void WeaponItem::fireHitscan(CharacterObject* owner) {
auto handFrame = owner->model->resource->findFrame("srhand");
glm::mat4 handMatrix;
if (handFrame) {
while (handFrame->getParent()) {
handMatrix =
owner->skeleton->getMatrix(handFrame->getIndex()) * handMatrix;
handFrame = handFrame->getParent();
}
}
auto farTarget = owner->getPosition() +
owner->getRotation() * glm::vec3(0.f, _wepData->hitRange, 0.f);
auto handPos = glm::vec3(handMatrix * glm::vec4(0.f, 0.f, 0.f, 1.f));
auto fireOrigin = owner->getPosition() +
owner->getRotation() * handPos;
auto farTarget =
owner->getPosition() +
owner->getRotation() * glm::vec3(0.f, _wepData->hitRange, 0.f);
auto handPos = glm::vec3(handMatrix * glm::vec4(0.f, 0.f, 0.f, 1.f));
auto fireOrigin = owner->getPosition() + owner->getRotation() * handPos;
owner->engine->doWeaponScan(WeaponScan(_wepData->damage, fireOrigin, farTarget, _wepData.get()));
owner->engine->doWeaponScan(
WeaponScan(_wepData->damage, fireOrigin, farTarget, _wepData.get()));
// Particle FX involved:
// - smokeII emited around barrel
// - Some circle particle used for the tracer
// - smoke emited at hit point
// - gunflash
#if 0 // Should be merged into the VisualFX system
// Particle FX involved:
// - smokeII emited around barrel
// - Some circle particle used for the tracer
// - smoke emited at hit point
// - gunflash
#if 0 // Should be merged into the VisualFX system
auto flashDir = owner->getRotation() * glm::vec3{0.f, 0.f, 1.f};
auto flashUp = owner->getRotation() * glm::vec3{0.f, -1.f, 0.f};
@ -95,69 +96,65 @@ void WeaponItem::fireHitscan(CharacterObject* owner)
#endif
}
void WeaponItem::fireProjectile(CharacterObject* owner)
{
auto handPos = glm::vec3(0.f, 1.5f, 1.f);
auto fireOrigin = owner->getPosition() +
owner->getRotation() * handPos;
auto direction = owner->getRotation() * glm::normalize(glm::vec3{0.f, 1.f, 1.f});
void WeaponItem::fireProjectile(CharacterObject* owner) {
auto handPos = glm::vec3(0.f, 1.5f, 1.f);
auto fireOrigin = owner->getPosition() + owner->getRotation() * handPos;
auto direction =
owner->getRotation() * glm::normalize(glm::vec3{0.f, 1.f, 1.f});
auto pt = _wepData->name == "grenade" ? ProjectileObject::Grenade : ProjectileObject::Molotov;
auto pt = _wepData->name == "grenade" ? ProjectileObject::Grenade
: ProjectileObject::Molotov;
// Work out the velocity multiplier as a function of how long the player
// Was holding down the fire button. If _fireStop < 0.f then the player
// is still holding the button down.
float throwTime = owner->engine->getGameTime() - owner->getCurrentState().primaryStartTime/1000.f;
float forceFactor = throwTime;
if (owner->getCurrentState().primaryEndTime >= owner->getCurrentState().primaryStartTime) {
uint32_t heldTime = owner->getCurrentState().primaryEndTime - owner->getCurrentState().primaryStartTime;
forceFactor = (heldTime)/1000.f;
}
forceFactor = std::max(0.1f, forceFactor / throwTime);
// Work out the velocity multiplier as a function of how long the player
// Was holding down the fire button. If _fireStop < 0.f then the player
// is still holding the button down.
float throwTime = owner->engine->getGameTime() -
owner->getCurrentState().primaryStartTime / 1000.f;
float forceFactor = throwTime;
if (owner->getCurrentState().primaryEndTime >=
owner->getCurrentState().primaryStartTime) {
uint32_t heldTime = owner->getCurrentState().primaryEndTime -
owner->getCurrentState().primaryStartTime;
forceFactor = (heldTime) / 1000.f;
}
forceFactor = std::max(0.1f, forceFactor / throwTime);
auto projectile = new ProjectileObject(owner->engine, fireOrigin,
{
pt,
direction,
17.f * forceFactor, /// @todo pull a better velocity from somewhere
3.5f,
_wepData
});
auto projectile = new ProjectileObject(
owner->engine, fireOrigin,
{pt, direction,
17.f * forceFactor, /// @todo pull a better velocity from somewhere
3.5f, _wepData});
auto& pool = owner->engine->getTypeObjectPool( projectile );
pool.insert(projectile);
owner->engine->allObjects.push_back(projectile);
auto& pool = owner->engine->getTypeObjectPool(projectile);
pool.insert(projectile);
owner->engine->allObjects.push_back(projectile);
}
void WeaponItem::primary(CharacterObject* owner)
{
if( owner->getCurrentState().primaryActive ) {
// ShootWeapon will call ::fire() on us at the appropriate time.
owner->controller->setNextActivity(new Activities::ShootWeapon(this));
}
void WeaponItem::primary(CharacterObject* owner) {
if (owner->getCurrentState().primaryActive) {
// ShootWeapon will call ::fire() on us at the appropriate time.
owner->controller->setNextActivity(new Activities::ShootWeapon(this));
}
}
void WeaponItem::secondary(CharacterObject* owner)
{
RW_UNUSED(owner);
void WeaponItem::secondary(CharacterObject* owner) {
RW_UNUSED(owner);
}
void WeaponItem::fire(CharacterObject* owner)
{
switch( _wepData->fireType ) {
case WeaponData::INSTANT_HIT:
fireHitscan(owner);
break;
case WeaponData::PROJECTILE:
fireProjectile(owner);
break;
default:
/// @todo meele
break;
}
void WeaponItem::fire(CharacterObject* owner) {
switch (_wepData->fireType) {
case WeaponData::INSTANT_HIT:
fireHitscan(owner);
break;
case WeaponData::PROJECTILE:
fireProjectile(owner);
break;
default:
/// @todo meele
break;
}
}
bool WeaponItem::isFiring(CharacterObject* owner)
{
return owner->getCurrentState().primaryActive;
bool WeaponItem::isFiring(CharacterObject* owner) {
return owner->getCurrentState().primaryActive;
}

View File

@ -1,8 +1,8 @@
#pragma once
#ifndef _WEAPONITEM_HPP_
#define _WEAPONITEM_HPP_
#include <items/InventoryItem.hpp>
#include <data/WeaponData.hpp>
#include <items/InventoryItem.hpp>
#include <memory>
/**
@ -12,27 +12,29 @@
* This is instanciated once -per item type-, so state is shared between
* all instances of the same weapon. Timing is controlled by the CharacterState
*/
class WeaponItem : public InventoryItem
{
std::shared_ptr<WeaponData> _wepData;
class WeaponItem : public InventoryItem {
std::shared_ptr<WeaponData> _wepData;
void fireHitscan(CharacterObject* owner);
void fireProjectile(CharacterObject* owner);
void fireHitscan(CharacterObject* owner);
void fireProjectile(CharacterObject* owner);
public:
WeaponItem(int itemID, std::shared_ptr<WeaponData> data)
: InventoryItem(itemID, data->inventorySlot, data->modelID)
, _wepData(data)
{}
WeaponItem(int itemID, std::shared_ptr<WeaponData> data)
: InventoryItem(itemID, data->inventorySlot, data->modelID)
, _wepData(data) {
}
void primary(CharacterObject* owner);
void primary(CharacterObject* owner);
void secondary(CharacterObject* owner);
void secondary(CharacterObject* owner);
void fire(CharacterObject* owner);
void fire(CharacterObject* owner);
bool isFiring(CharacterObject* owner);
bool isFiring(CharacterObject* owner);
std::shared_ptr<WeaponData>& getWeaponData() { return _wepData; }
std::shared_ptr<WeaponData>& getWeaponData() {
return _wepData;
}
};
#endif