Compare commits

...

1 Commits

Author SHA1 Message Date
Jace cedcffcf97 WIP multi-weapon behaviours 2016-02-25 16:24:38 +01:00
14 changed files with 175 additions and 62 deletions
+2
View File
@@ -29,6 +29,7 @@ struct EntityWrapper
EntityWrapper Parent(); EntityWrapper Parent();
EntityWrapper FirstChildByName(const std::string& name); EntityWrapper FirstChildByName(const std::string& name);
EntityWrapper FirstParentWithComponent(const std::string& componentType); EntityWrapper FirstParentWithComponent(const std::string& componentType);
std::vector<EntityWrapper> ChildrenWithComponent(const std::string& componentType);
bool IsChildOf(EntityWrapper potentialParent); bool IsChildOf(EntityWrapper potentialParent);
bool Valid() const; bool Valid() const;
@@ -39,6 +40,7 @@ struct EntityWrapper
private: private:
EntityWrapper firstChildByNameRecursive(const std::string& name, EntityID parent); EntityWrapper firstChildByNameRecursive(const std::string& name, EntityID parent);
void childrenWithComponentRecursive(const std::string& componentType, EntityWrapper& entity, std::vector<EntityWrapper>& childrenWithComponent);
}; };
namespace std namespace std
@@ -1,13 +1,14 @@
#ifndef AssaultWeaponBehaviour_h__
#define AssaultWeaponBehaviour_h__
#include "Sound/EPlaySoundOnEntity.h" #include "Sound/EPlaySoundOnEntity.h"
#include "Collision/Collision.h" #include "Collision/Collision.h"
#include "Rendering/AnimationSystem.h"
#include "Core/ConfigFile.h" #include "Core/ConfigFile.h"
#include "WeaponBehaviour.h" #include "WeaponBehaviour.h"
#include "../SpawnerSystem.h" #include "../SpawnerSystem.h"
#include "Core/EPlayerDamage.h" #include "Core/EPlayerDamage.h"
#include "Core/EShoot.h" #include "Core/EShoot.h"
class AssaultWeaponBehaviour : public WeaponBehaviour class AssaultWeaponBehaviour : public WeaponBehaviour
{ {
public: public:
@@ -22,16 +23,13 @@ public:
private: private:
EntityWrapper m_FirstPersonModel; EntityWrapper m_FirstPersonModel;
EntityWrapper m_ThirdPersonModel; EntityWrapper m_ThirdPersonModel;
// State // State
bool m_Firing = false; bool m_Firing = false;
bool m_Reloading = false; bool m_Reloading = false;
double m_ReloadTimer = 0.0; double m_ReloadTimer = 0.0;
EntityWrapper m_FirstPersonReloadImpersonator;
EntityWrapper m_ThirdPersonReloadImpersonator;
double m_TimeSinceLastFire = 0.0; double m_TimeSinceLastFire = 0.0;
EntityWrapper m_FirstPersonReloadImpostor;
EventRelay<WeaponBehaviour, Events::AnimationComplete> m_EAnimationComplete;
bool OnAnimationComplete(Events::AnimationComplete& e);
bool hasAmmo(); bool hasAmmo();
void fireRound(); void fireRound();
@@ -47,3 +45,5 @@ private:
bool shoot(double damage); bool shoot(double damage);
void showHitMarker(); void showHitMarker();
}; };
#endif
@@ -0,0 +1,16 @@
#include "WeaponBehaviour.h"
class DefenderWeaponBehaviour : public WeaponBehaviour
{
public:
DefenderWeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree, EntityWrapper weaponEntity);
virtual void Fire() override;
//virtual void CeaseFire() override;
//virtual void Reload() override;
//virtual void Update(double dt) override;
private:
double m_TimeSinceLastFire = 0.0;
};
@@ -8,17 +8,21 @@
class WeaponBehaviour : public System class WeaponBehaviour : public System
{ {
friend class WeaponSystem;
public: public:
WeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree, EntityWrapper player) WeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree, EntityWrapper player, EntityWrapper firstPersonWeapon, EntityWrapper thirdPersonWeapon)
: System(systemParams) : System(systemParams)
, m_Renderer(renderer) , m_Renderer(renderer)
, m_CollisionOctree(collisionOctree) , m_CollisionOctree(collisionOctree)
, m_Player(player) , m_Player(player)
, m_FirstPerson(firstPersonWeapon)
, m_ThirdPerson(thirdPersonWeapon)
{ } { }
virtual ~WeaponBehaviour() = default; virtual ~WeaponBehaviour() = default;
WeaponBehaviour(const WeaponBehaviour&) = delete; WeaponBehaviour(const WeaponBehaviour&) = delete;
WeaponBehaviour& operator=(const WeaponBehaviour &) = delete; WeaponBehaviour& operator=(const WeaponBehaviour&) = delete;
virtual void Fire() = 0; virtual void Fire() = 0;
virtual void CeaseFire() { } virtual void CeaseFire() { }
@@ -29,6 +33,8 @@ protected:
IRenderer* m_Renderer; IRenderer* m_Renderer;
Octree<EntityAABB>* m_CollisionOctree; Octree<EntityAABB>* m_CollisionOctree;
EntityWrapper m_Player; EntityWrapper m_Player;
EntityWrapper m_FirstPerson;
EntityWrapper m_ThirdPerson;
}; };
#endif #endif
+1
View File
@@ -46,4 +46,5 @@
<xs:include schemaLocation="Components/Page.xsd"/> <xs:include schemaLocation="Components/Page.xsd"/>
<xs:include schemaLocation="Components/SpriteIndicator.xsd"/> <xs:include schemaLocation="Components/SpriteIndicator.xsd"/>
<xs:include schemaLocation="Components/Button.xsd"/> <xs:include schemaLocation="Components/Button.xsd"/>
<xs:include schemaLocation="Components/WeaponAttachment.xsd"/>
</xs:schema> </xs:schema>
-3
View File
@@ -1,3 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Trigger xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Trigger.xsd">
</Trigger>
-17
View File
@@ -1,17 +0,0 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="Weapon">
<xs:complexType>
<xs:all>
<xs:element name="MagSize" type="t:int" minOccurs="0"/>
<xs:element name="MaxAmmo" type="t:int" minOccurs="0"/>
<xs:element name="CurrentAmmoInMag" type="t:int" minOccurs="0"/>
<xs:element name="CurrentAmmo" type="t:int" minOccurs="0"/>
<xs:element name="RPM" type="t:double" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<WeaponAttachment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="WeaponAttachment.xsd">
<Person><FirstPerson/></Person>
</WeaponAttachment>
@@ -0,0 +1,37 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:complexType name="PersonEnum" mixed="true">
<xs:complexContent>
<xs:extension base="t:enum">
<xs:choice>
<xs:element name="FirstPerson" type="t:int" fixed="0" minOccurs="0"/>
<xs:element name="ThirdPerson" type="t:int" fixed="1" minOccurs="0"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="WeaponSlotEnum" mixed="true">
<xs:complexContent>
<xs:extension base="t:enum">
<xs:choice>
<xs:element name="Primary" type="t:int" fixed="1" minOccurs="0"/>
<xs:element name="Secondary" type="t:int" fixed="2" minOccurs="0"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="WeaponAttachment">
<xs:annotation><xs:documentation>Combine with a spawner to define a weapon attachment point</xs:documentation></xs:annotation>
<xs:complexType>
<xs:all>
<xs:element name="Person" type="PersonEnum" minOccurs="0"/>
<xs:element name="Slot" type="WeaponSlotEnum" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
+1
View File
@@ -50,6 +50,7 @@
<xs:element ref="c:Menu" minOccurs="0"/> <xs:element ref="c:Menu" minOccurs="0"/>
<xs:element ref="c:Page" minOccurs="0"/> <xs:element ref="c:Page" minOccurs="0"/>
<xs:element ref="c:Button" minOccurs="0"/> <xs:element ref="c:Button" minOccurs="0"/>
<xs:element ref="c:WeaponAttachment" minOccurs="0"/>
</xs:all> </xs:all>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
+22
View File
@@ -51,6 +51,13 @@ EntityWrapper EntityWrapper::FirstParentWithComponent(const std::string& compone
return EntityWrapper::Invalid; return EntityWrapper::Invalid;
} }
std::vector<EntityWrapper> EntityWrapper::ChildrenWithComponent(const std::string& componentType)
{
std::vector<EntityWrapper> childrenWithComponent;
childrenWithComponentRecursive(componentType, *this, childrenWithComponent);
return childrenWithComponent;
}
bool EntityWrapper::IsChildOf(EntityWrapper potentialParent) bool EntityWrapper::IsChildOf(EntityWrapper potentialParent)
{ {
EntityWrapper entity = *this; EntityWrapper entity = *this;
@@ -131,3 +138,18 @@ EntityWrapper EntityWrapper::firstChildByNameRecursive(const std::string& name,
return EntityWrapper::Invalid; return EntityWrapper::Invalid;
} }
void EntityWrapper::childrenWithComponentRecursive(const std::string& componentType, EntityWrapper& entity, std::vector<EntityWrapper>& childrenWithComponent)
{
auto itPair = this->World->GetChildren(entity.ID);
if (itPair.first == itPair.second) {
return;
}
for (auto it = itPair.first; it != itPair.second; ++it) {
if (entity.HasComponent(componentType)) {
childrenWithComponent.push_back(entity);
}
childrenWithComponentRecursive(componentType, entity, childrenWithComponent);
}
}
@@ -5,7 +5,6 @@ AssaultWeaponBehaviour::AssaultWeaponBehaviour(SystemParams systemParams, IRende
{ {
m_FirstPersonModel = m_Player.FirstChildByName("Hands"); m_FirstPersonModel = m_Player.FirstChildByName("Hands");
m_ThirdPersonModel = m_Player.FirstChildByName("PlayerModel"); m_ThirdPersonModel = m_Player.FirstChildByName("PlayerModel");
EVENT_SUBSCRIBE_MEMBER(m_EAnimationComplete, &AssaultWeaponBehaviour::OnAnimationComplete);
} }
void AssaultWeaponBehaviour::Fire() void AssaultWeaponBehaviour::Fire()
@@ -36,7 +35,7 @@ void AssaultWeaponBehaviour::Reload()
return; return;
} }
// Don't reload if we're completly out of ammo // Don't reload if we're completely out of ammo
if (ammo == 0) { if (ammo == 0) {
playEmptySound(); playEmptySound();
m_TimeSinceLastFire = -0.0f; // HACK: To make empty sound play with interval m_TimeSinceLastFire = -0.0f; // HACK: To make empty sound play with interval
@@ -56,14 +55,14 @@ void AssaultWeaponBehaviour::Update(double dt)
{ {
if (m_Reloading) { if (m_Reloading) {
m_ReloadTimer -= dt; m_ReloadTimer -= dt;
// Re-enable glow on reload impersonator half-way through the animation // Re-enable glow on reload impostor half-way through the animation
if (IsClient) { if (IsClient) {
if (m_ReloadTimer <= (double)m_Player["AssaultWeapon"]["ReloadTime"] / 2.0) { if (m_ReloadTimer <= (double)m_Player["AssaultWeapon"]["ReloadTime"] / 2.0) {
if (m_FirstPersonReloadImpersonator.Valid()) { if (m_FirstPersonReloadImpostor.Valid()) {
m_FirstPersonReloadImpersonator["Model"]["GlowMap"] = true; m_FirstPersonReloadImpostor["Model"]["GlowMap"] = true;
} }
if (m_ThirdPersonReloadImpersonator.Valid()) { if (m_ThirdPersonReloadImpostor.Valid()) {
m_ThirdPersonReloadImpersonator["Model"]["GlowMap"] = true; m_ThirdPersonReloadImpostor["Model"]["GlowMap"] = true;
} }
} }
} }
@@ -96,21 +95,6 @@ void AssaultWeaponBehaviour::Update(double dt)
} }
} }
bool AssaultWeaponBehaviour::OnAnimationComplete(Events::AnimationComplete& e)
{
if (e.Entity != m_FirstPersonModel) {
return false;
}
//if (e.Name == "ShootRifle") {
// if (!m_Firing) {
// playIdleAnimation();
// }
//}
return true;
}
bool AssaultWeaponBehaviour::hasAmmo() bool AssaultWeaponBehaviour::hasAmmo()
{ {
ComponentWrapper& cAssaultWeapon = m_Player["AssaultWeapon"]; ComponentWrapper& cAssaultWeapon = m_Player["AssaultWeapon"];
@@ -215,6 +199,12 @@ void AssaultWeaponBehaviour::playEmptySound()
void AssaultWeaponBehaviour::viewPunch() void AssaultWeaponBehaviour::viewPunch()
{ {
// Since we send absolute client orientations to server, running this server side would
// cause aim desync.
if (!IsClient) {
return;
}
EntityWrapper playerCamera = m_Player.FirstChildByName("Camera"); EntityWrapper playerCamera = m_Player.FirstChildByName("Camera");
if (!playerCamera.Valid()) { if (!playerCamera.Valid()) {
return; return;
@@ -323,8 +313,8 @@ void AssaultWeaponBehaviour::playReloadAnimation()
EntityWrapper firstPersonWeaponModel = m_Player.FirstChildByName("WeaponModel"); EntityWrapper firstPersonWeaponModel = m_Player.FirstChildByName("WeaponModel");
EntityWrapper reloadSpawner = m_Player.FirstChildByName("FirstPersonReloadSpawner"); EntityWrapper reloadSpawner = m_Player.FirstChildByName("FirstPersonReloadSpawner");
if (IsClient) { if (IsClient) {
m_FirstPersonReloadImpersonator = SpawnerSystem::Spawn(reloadSpawner, reloadSpawner); m_FirstPersonReloadImpostor = SpawnerSystem::Spawn(reloadSpawner, reloadSpawner);
firstPersonWeaponModel["Model"].Copy(m_FirstPersonReloadImpersonator["Model"]); firstPersonWeaponModel["Model"].Copy(m_FirstPersonReloadImpostor["Model"]);
} }
firstPersonWeaponModel["Model"]["Visible"] = false; firstPersonWeaponModel["Model"]["Visible"] = false;
} }
@@ -332,8 +322,8 @@ void AssaultWeaponBehaviour::playReloadAnimation()
EntityWrapper thirdPersonWeaponModel = m_Player.FirstChildByName("ThirdPersonWeaponModel"); EntityWrapper thirdPersonWeaponModel = m_Player.FirstChildByName("ThirdPersonWeaponModel");
EntityWrapper reloadSpawner = m_Player.FirstChildByName("ThirdPersonReloadSpawner"); EntityWrapper reloadSpawner = m_Player.FirstChildByName("ThirdPersonReloadSpawner");
if (IsClient) { if (IsClient) {
m_ThirdPersonReloadImpersonator = SpawnerSystem::Spawn(reloadSpawner, reloadSpawner); m_ThirdPersonReloadImpostor = SpawnerSystem::Spawn(reloadSpawner, reloadSpawner);
thirdPersonWeaponModel["Model"].Copy(m_ThirdPersonReloadImpersonator["Model"]); thirdPersonWeaponModel["Model"].Copy(m_ThirdPersonReloadImpostor["Model"]);
} }
thirdPersonWeaponModel["Model"]["Visible"] = false; thirdPersonWeaponModel["Model"]["Visible"] = false;
} }
@@ -371,7 +361,7 @@ bool AssaultWeaponBehaviour::shoot(double damage)
return false; return false;
} }
// Don't let us shoot ourselves in the foot // Don't let us shoot ourselves in the foot somehow
if (victim == LocalPlayer) { if (victim == LocalPlayer) {
return false; return false;
} }
@@ -0,0 +1,10 @@
#include "Systems/Weapon/DefenderWeaponBehaviour.h"
DefenderWeaponBehaviour::DefenderWeaponBehaviour(SystemParams systemParams, IRenderer* renderer, Octree<EntityAABB>* collisionOctree, EntityWrapper weaponEntity)
: WeaponBehaviour(systemParams, renderer, collisionOctree, weaponEntity) { }
void DefenderWeaponBehaviour::Fire()
{
}
+50 -6
View File
@@ -13,7 +13,7 @@ WeaponSystem::WeaponSystem(SystemParams params, IRenderer* renderer, Octree<Enti
void WeaponSystem::Update(double dt) void WeaponSystem::Update(double dt)
{ {
// TODO: Clear inactive weapons
} }
void WeaponSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cPlayer, double dt) void WeaponSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cPlayer, double dt)
@@ -72,20 +72,64 @@ bool WeaponSystem::OnInputCommand(Events::InputCommand& e)
void WeaponSystem::selectWeapon(EntityWrapper player, ComponentInfo::EnumType slot) void WeaponSystem::selectWeapon(EntityWrapper player, ComponentInfo::EnumType slot)
{ {
std::vector<EntityWrapper> weaponAttachments = player.ChildrenWithComponent("WeaponAttachment");
// Find the weapon attachments matching the slot selected
EntityWrapper firstPersonAttachment;
EntityWrapper thirdPersonAttachment;
for (auto& attachment : weaponAttachments) {
ComponentWrapper cWeaponAttachment = attachment["WeaponAttachment"];
if ((ComponentInfo::EnumType)cWeaponAttachment["Slot"] == slot) {
ComponentWrapper::SubscriptProxy person = cWeaponAttachment["Person"];
if (person == person.Enum("FirstPerson")) {
firstPersonAttachment = attachment;
} else if (person == person.Enum("ThirdPerson")) {
thirdPersonAttachment = attachment;
}
}
}
if (firstPersonAttachment.Valid() && thirdPersonAttachment.Valid()) {
LOG_WARNING("No weapon attachment found for slot %i of player #%i", slot, player.ID);
return;
}
// TODO: Delete old weapons
// Spawn the weapon(s)
EntityWrapper firstPersonWeapon;
EntityWrapper thirdPersonWeapon;
if (firstPersonAttachment.Valid()) {
firstPersonWeapon = SpawnerSystem::Spawn(firstPersonAttachment, firstPersonAttachment);
}
if (thirdPersonAttachment.Valid()) {
firstPersonWeapon = SpawnerSystem::Spawn(thirdPersonAttachment, thirdPersonAttachment);
}
// Create the correct behaviour
if (firstPersonWeapon.Valid()) {
if (firstPersonWeapon.HasComponent("AssaultWeapon") {
}
}
// Primary // Primary
if (slot == 1) { if (slot == 1) {
// TODO: if class... // TODO: if class...
if (m_ActiveWeapons.count(player) == 0) { nextBehaviour = std::make_shared<AssaultWeaponBehaviour>(m_SystemParams, m_Renderer, m_CollisionOctree, player);
m_ActiveWeapons.insert(std::make_pair(player, std::make_shared<AssaultWeaponBehaviour>(m_SystemParams, m_Renderer, m_CollisionOctree, player)));
} else {
//m_ActiveWeapons.erase(player);
}
} }
// Secondary // Secondary
if (slot == 2) { if (slot == 2) {
//m_ActiveWeapons[player] = std::make_shared<PistolWeaponBehaviour>(); //m_ActiveWeapons[player] = std::make_shared<PistolWeaponBehaviour>();
} }
if (nextBehaviour != nullptr) {
// TODO: Destroy previous behaviour and make new
if (m_ActiveWeapons.count(player) == 0) {
m_ActiveWeapons[player] = nextBehaviour;
}
}
} }
bool WeaponSystem::OnPlayerSpawned(Events::PlayerSpawned& e) bool WeaponSystem::OnPlayerSpawned(Events::PlayerSpawned& e)