mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-07 03:12:36 +01:00
Make it possible to fire weapons again
This commit is contained in:
parent
46621093f9
commit
07f7b19ca2
@ -102,12 +102,6 @@ public:
|
||||
|
||||
virtual glm::vec3 getTargetPosition() = 0;
|
||||
|
||||
/**
|
||||
* Uses the character's active item.
|
||||
* @param primary use the primary action.
|
||||
*/
|
||||
void useItem(bool active, bool primary = true);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @return Returns the Character Object
|
||||
|
@ -28,6 +28,8 @@ struct CharacterState
|
||||
uint32_t lastFireTimeMS;
|
||||
bool primaryActive;
|
||||
bool secondaryActive;
|
||||
uint32_t primaryStartTime;
|
||||
uint32_t primaryEndTime;
|
||||
};
|
||||
|
||||
class VehicleObject;
|
||||
@ -177,6 +179,12 @@ public:
|
||||
InventoryItem* getActiveItem();
|
||||
void removeFromInventory( int slot );
|
||||
|
||||
/**
|
||||
* Uses the character's active item.
|
||||
* @param primary use the primary action.
|
||||
*/
|
||||
void useItem(bool active, bool primary = true);
|
||||
|
||||
void cycleInventory( bool up );
|
||||
};
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <data/Model.hpp>
|
||||
#include <engine/Animator.hpp>
|
||||
#include <items/WeaponItem.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <rw/defines.hpp>
|
||||
|
||||
bool CharacterController::updateActivity()
|
||||
{
|
||||
@ -170,18 +170,6 @@ void CharacterController::update(float dt)
|
||||
}
|
||||
}
|
||||
|
||||
void CharacterController::useItem(bool active, bool primary)
|
||||
{
|
||||
if( character->getActiveItem() ) {
|
||||
if( primary ) {
|
||||
character->getCurrentState().primaryActive = active;
|
||||
}
|
||||
else {
|
||||
character->getCurrentState().secondaryActive = active;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CharacterObject *CharacterController::getCharacter() const
|
||||
{
|
||||
return character;
|
||||
@ -455,6 +443,11 @@ bool Activities::ShootWeapon::update(CharacterObject *character, CharacterContro
|
||||
character->animator->setAnimation(throwanim, false);
|
||||
}
|
||||
}
|
||||
else if( wepdata->fireType == WeaponData::MELEE ) {
|
||||
RW_CHECK(wepdata->fireType != WeaponData::MELEE, "Melee attacks not implemented");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -105,13 +105,13 @@ void WeaponItem::fireProjectile(CharacterObject* owner)
|
||||
// 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().lastFireTimeMS/1000.f;
|
||||
float throwTime = owner->engine->getGameTime() - owner->getCurrentState().primaryStartTime/1000.f;
|
||||
float forceFactor = throwTime;
|
||||
#if 0
|
||||
if( _fireStop > 0.f ) {
|
||||
forceFactor = _fireStop - _fireStart;
|
||||
if (owner->getCurrentState().primaryEndTime >= owner->getCurrentState().primaryStartTime) {
|
||||
uint32_t heldTime = owner->getCurrentState().primaryEndTime - owner->getCurrentState().primaryStartTime;
|
||||
forceFactor = (heldTime)/1000.f;
|
||||
}
|
||||
forceFactor /= throwTime;
|
||||
forceFactor = std::max(0.1f, forceFactor / throwTime);
|
||||
|
||||
auto projectile = new ProjectileObject(owner->engine, fireOrigin,
|
||||
{
|
||||
@ -124,20 +124,15 @@ void WeaponItem::fireProjectile(CharacterObject* owner)
|
||||
|
||||
auto& pool = owner->engine->getTypeObjectPool( projectile );
|
||||
pool.insert(projectile);
|
||||
#endif
|
||||
owner->engine->allObjects.push_back(projectile);
|
||||
}
|
||||
|
||||
void WeaponItem::primary(CharacterObject* owner)
|
||||
{
|
||||
#if 0
|
||||
if( active ) {
|
||||
_fireStart = owner->engine->getGameTime();
|
||||
_fireStop = -1.f;
|
||||
|
||||
if( owner->getCurrentState().primaryActive ) {
|
||||
// ShootWeapon will call ::fire() on us at the appropriate time.
|
||||
owner->controller->setNextActivity(new Activities::ShootWeapon(this));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void WeaponItem::secondary(CharacterObject* owner)
|
||||
|
@ -126,18 +126,6 @@ void CharacterObject::tick(float dt)
|
||||
animator->tick(dt);
|
||||
updateCharacter(dt);
|
||||
|
||||
// Update the item if we're using it
|
||||
if (currentState.primaryActive) {
|
||||
if (getActiveItem()) {
|
||||
getActiveItem()->primary(this);
|
||||
}
|
||||
}
|
||||
if (currentState.secondaryActive) {
|
||||
if (getActiveItem()) {
|
||||
getActiveItem()->secondary(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the character doesn't need to be reset
|
||||
if(getPosition().z < -100.f) {
|
||||
resetToAINode();
|
||||
@ -523,3 +511,20 @@ void CharacterObject::cycleInventory(bool up)
|
||||
}
|
||||
}
|
||||
|
||||
void CharacterObject::useItem(bool active, bool primary)
|
||||
{
|
||||
if( getActiveItem() ) {
|
||||
if( primary ) {
|
||||
if (active)
|
||||
currentState.primaryStartTime = engine->getGameTime() * 1000.f;
|
||||
else
|
||||
currentState.primaryEndTime = engine->getGameTime() * 1000.f;
|
||||
currentState.primaryActive = active;
|
||||
getActiveItem()->primary(this);
|
||||
}
|
||||
else {
|
||||
currentState.secondaryActive = active;
|
||||
getActiveItem()->secondary(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ void IngameState::handlePlayerInput(const sf::Event& event)
|
||||
case sf::Event::MouseButtonPressed:
|
||||
switch(event.mouseButton.button) {
|
||||
case sf::Mouse::Left:
|
||||
player->useItem(true, true);
|
||||
player->getCharacter()->useItem(true, true);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
@ -360,7 +360,7 @@ void IngameState::handlePlayerInput(const sf::Event& event)
|
||||
case sf::Event::MouseButtonReleased:
|
||||
switch(event.mouseButton.button) {
|
||||
case sf::Mouse::Left:
|
||||
player->useItem(false, true);
|
||||
player->getCharacter()->useItem(false, true);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user