1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-26 12:22:41 +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 * Instanciated once per item type
*/ */
class InventoryItem class InventoryItem {
{ int _itemID;
int _itemID; int _inventorySlot;
int _inventorySlot; int _modelID;
int _modelID;
protected: protected:
InventoryItem(int itemID, int invSlot, int model) InventoryItem(int itemID, int invSlot, int model)
: _itemID(itemID), _inventorySlot(invSlot), _modelID(model) : _itemID(itemID), _inventorySlot(invSlot), _modelID(model) {
{} }
public: public:
virtual ~InventoryItem() {} virtual ~InventoryItem() {
}
/** /**
* @brief getObject * @brief getObject
* @return The ID of the model associated with the item. * @return The ID of the model associated with the item.
*/ */
int getModelID() { return _modelID; } int getModelID() {
return _modelID;
}
/** /**
* @brief getItemID * @brief getItemID
* @return The index of this item in the item list * @return The index of this item in the item list
*/ */
int getItemID() { return _itemID; } int getItemID() {
return _itemID;
}
/** /**
* @brief getInventorySlot * @brief getInventorySlot
* @return The inventory slot number for this item * @return The inventory slot number for this item
*/ */
int getInventorySlot() const { return _inventorySlot; } int getInventorySlot() const {
return _inventorySlot;
}
/** /**
* @brief primary Implements mouse 1 action * @brief primary Implements mouse 1 action
* @param owner The character using this item * @param owner The character using this item
*/ */
virtual void primary(CharacterObject* owner) = 0; virtual void primary(CharacterObject* owner) = 0;
/** /**
* @see primary * @see primary
* @param owner The character using this item * @param owner The character using this item
*/ */
virtual void secondary(CharacterObject* owner) = 0; virtual void secondary(CharacterObject* owner) = 0;
constexpr static int NO_INVSLOT = -1; constexpr static int NO_INVSLOT = -1;
}; };
#endif #endif

View File

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

View File

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