Compare commits

...

3 Commits

Author SHA1 Message Date
Jace 1992b6cde1 WIP Defender tracers 2016-03-10 21:15:27 +01:00
Jace c82be79bb8 Functionally working defender weapon 2016-03-10 19:26:14 +01:00
Jace 35a8d45fa4 Fixed skinned models not being able to be shielded 2016-03-10 19:20:21 +01:00
12 changed files with 456 additions and 125 deletions
+1 -1
Submodule assets updated: 85d96f6f3d...298641b1af
@@ -27,9 +27,12 @@ private:
std::random_device m_RandomDevice; std::random_device m_RandomDevice;
std::mt19937 m_RandomEngine; std::mt19937 m_RandomEngine;
// Weapon functions // Weapon functions
void fireShell(ComponentWrapper cWeapon, WeaponInfo& wi); void fireShell(ComponentWrapper cWeapon, WeaponInfo& wi);
void dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, glm::vec3 direction, double damage); void dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, const std::vector<glm::vec2>& pattern);
void spawnTracers(ComponentWrapper cWeapon, WeaponInfo& wi, std::vector<glm::vec2> pattern);
bool canFire(ComponentWrapper cWeapon, WeaponInfo& wi); bool canFire(ComponentWrapper cWeapon, WeaponInfo& wi);
// Utility // Utility
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<DefenderWeapon xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="DefenderWeapon.xsd"> <DefenderWeapon xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="DefenderWeapon.xsd">
<Slot><Primary/></Slot> <Slot><Primary/></Slot>
<MagazineAmmo>8</MagazineAmmo> <MagazineAmmo>9999</MagazineAmmo>
<MagazineSize>8</MagazineSize> <MagazineSize>8</MagazineSize>
<Ammo>64</Ammo> <Ammo>64</Ammo>
<MaxAmmo>64</MaxAmmo> <MaxAmmo>64</MaxAmmo>
<BaseDamage>90</BaseDamage> <BaseDamage>90</BaseDamage>
<SpreadAngle>0.174533</SpreadAngle> <!-- 0.174533 = 10 degrees --> <SpreadAngle>10</SpreadAngle>
<MaxTravelAngle>0.174533</MaxTravelAngle> <!-- 0.174533 = 10 degrees --> <MaxTravelAngle>0.174533</MaxTravelAngle> <!-- 0.174533 = 10 degrees -->
<NumPellets>10</NumPellets> <NumPellets>9</NumPellets>
<RPM>120</RPM> <RPM>120</RPM>
<ViewPunch>0.03</ViewPunch> <ViewPunch>0.03</ViewPunch>
<ViewReturnSpeed>0.2</ViewReturnSpeed> <ViewReturnSpeed>0.2</ViewReturnSpeed>
@@ -36,7 +36,7 @@
<xs:annotation><xs:documentation>Damage dealt if all shotgun pellets hit</xs:documentation></xs:annotation> <xs:annotation><xs:documentation>Damage dealt if all shotgun pellets hit</xs:documentation></xs:annotation>
</xs:element> </xs:element>
<xs:element name="SpreadAngle" type="t:float" minOccurs="0"> <xs:element name="SpreadAngle" type="t:float" minOccurs="0">
<xs:annotation><xs:documentation>Spread angle in radians</xs:documentation></xs:annotation> <xs:annotation><xs:documentation>The spread angle radius.</xs:documentation></xs:annotation>
</xs:element> </xs:element>
<xs:element name="MaxTravelAngle" type="t:float" minOccurs="0"> <xs:element name="MaxTravelAngle" type="t:float" minOccurs="0">
<xs:annotation><xs:documentation>Maximum vertical aim travel angle in radians</xs:documentation></xs:annotation> <xs:annotation><xs:documentation>Maximum vertical aim travel angle in radians</xs:documentation></xs:annotation>
+94
View File
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform/>
</Components>
<Children>
<Entity name="RayBlue">
<Components>
<c:Transform>
<Orientation X="0" Y="0.174532995" Z="0"/>
<Scale X="0" Y="1" Z="100"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="-1.57099998" Z="0"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="4.71218538" Z="3.14199996"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="RayBlue">
<Components>
<c:Transform>
<Scale X="0" Y="1" Z="100"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="-1.57099998" Z="0"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="4.71218538" Z="3.14199996"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
+79 -23
View File
@@ -1,39 +1,95 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity name="Shield" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd"> <Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components> <Components>
<c:Blend> <c:Transform>
<Pose1>Deploy</Pose1> <Position X="1.70262027" Y="0.261695802" Z="-3.26634645"/>
<Pose2>Idle</Pose2> </c:Transform>
<Weight>0</Weight>
</c:Blend>
<c:Model>
<Resource>Models/Characters/Defender/DefenderShield.mesh</Resource>
</c:Model>
<c:Transform/>
</Components> </Components>
<Children> <Children>
<Entity name="Deploy"> <Entity name="Back">
<Components> <Components>
<c:Animation> <c:Blend>
<AnimationName>ActivateDeactiveShieldF</AnimationName> <Pose1>Deploy</Pose1>
<Time>1</Time> <Pose2>Idle</Pose2>
<Speed>1</Speed> <Weight>0</Weight>
</c:Animation> </c:Blend>
<c:Shielded/>
<c:Model>
<Resource>Models/Characters/Defender/DefenderShieldBack.mesh</Resource>
<Color A="0.219607845" B="3.92156863" G="1" R="1"/>
<Shadow>false</Shadow>
<Transparent>true</Transparent>
<NormalMap>false</NormalMap>
<DiffuseTexture>false</DiffuseTexture>
<SpecularMap>false</SpecularMap>
<GlowMap>false</GlowMap>
</c:Model>
<c:Transform/> <c:Transform/>
</Components> </Components>
<Children/> <Children>
<Entity name="Deploy">
<Components>
<c:Animation>
<AnimationName>ActivateDeactiveShieldF</AnimationName>
<Play>true</Play>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="Idle">
<Components>
<c:Animation>
<AnimationName>ShieldFrontF</AnimationName>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity> </Entity>
<Entity name="Idle"> <Entity name="Front">
<Components> <Components>
<c:Animation> <c:Blend>
<AnimationName>ShieldFrontF</AnimationName> <Pose1>Deploy</Pose1>
<Speed>1</Speed> <Pose2>Idle</Pose2>
</c:Animation> <Weight>0</Weight>
</c:Blend>
<c:Model>
<Resource>Models/Characters/Defender/DefenderShieldFront.mesh</Resource>
<Color A="0.219607845" B="3.92156863" G="1" R="1"/>
<Shadow>false</Shadow>
<Transparent>true</Transparent>
<NormalMap>false</NormalMap>
<DiffuseTexture>false</DiffuseTexture>
<SpecularMap>false</SpecularMap>
<GlowMap>false</GlowMap>
</c:Model>
<c:Transform/> <c:Transform/>
</Components> </Components>
<Children/> <Children>
<Entity name="Deploy">
<Components>
<c:Animation>
<AnimationName>ActivateDeactiveShieldF</AnimationName>
<Play>true</Play>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
<Entity name="Idle">
<Components>
<c:Animation>
<AnimationName>ShieldFrontF</AnimationName>
</c:Animation>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity> </Entity>
</Children> </Children>
+27
View File
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Lifetime>
<Lifetime>10</Lifetime>
</c:Lifetime>
<c:ExplosionEffect>
<Velocity X="2" Y="2.30000019" Z="0"/>
<ExplosionDuration>1</ExplosionDuration>
<Randomness>true</Randomness>
<ExponentialAccelaration>true</ExponentialAccelaration>
</c:ExplosionEffect>
<c:Model>
<Resource>Models/Core/UnitSphere.mesh</Resource>
<Color A="1" B="1" G="1" R="3.92156863"/>
<Shadow>false</Shadow>
<Transparent>true</Transparent>
</c:Model>
<c:Transform>
<Scale X="0.0500000007" Y="0.0500000007" Z="0.0500000007"/>
</c:Transform>
</Components>
<Children/>
</Entity>
+96 -4
View File
@@ -103,7 +103,7 @@
<Color A="1" B="1" G="0.254901975" R="0"/> <Color A="1" B="1" G="0.254901975" R="0"/>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="-0.600000024" Y="0" Z="0"/> <Position X="0.800000012" Y="0" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children/>
@@ -116,7 +116,7 @@
<Color A="1" B="1" G="0.254901975" R="0"/> <Color A="1" B="1" G="0.254901975" R="0"/>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="0.800000012" Y="0" Z="0"/> <Position X="-0.600000024" Y="0" Z="0.549540162"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children/>
@@ -157,14 +157,106 @@
<Resource>Models/Weapons/Blue/DefenderWeaponBlue.mesh</Resource> <Resource>Models/Weapons/Blue/DefenderWeaponBlue.mesh</Resource>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="0.00681143999" Y="-0.204994932" Z="-0.209244296"/> <Orientation X="0" Y="-0" Z="0"/>
<Orientation X="-0.581807375" Y="0.562133908" Z="-0.0719003305"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children/>
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
<Entity>
<Components>
<c:Transform>
<Position X="0.870232701" Y="0.640069604" Z="4.07769537"/>
<Orientation X="0" Y="4.71238565" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity name="RayBlue">
<Components>
<c:Transform>
<Orientation X="0" Y="0.174532995" Z="0"/>
<Scale X="0" Y="1" Z="100"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="-1.57099998" Z="0"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="4.71218538" Z="3.14199996"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity name="RayBlue">
<Components>
<c:Transform>
<Scale X="0" Y="1" Z="100"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="-1.57099998" Z="0"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Sprite>
<Model>Models/Core/UnitQuad.mesh</Model>
<GlowMap></GlowMap>
<DiffuseTexture>Textures/Effects/Ray.png</DiffuseTexture>
<Color A="0.419607848" B="3.92156863" G="0.270588249" R="0"/>
</c:Sprite>
<c:Transform>
<Position X="0" Y="0" Z="-0.5"/>
<Orientation X="0" Y="4.71218538" Z="3.14199996"/>
<Scale X="1" Y="0.0260000005" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children> </Children>
</Entity> </Entity>
+1 -1
View File
@@ -3,7 +3,7 @@
<Components> <Components>
<c:Lifetime> <c:Lifetime>
<Lifetime>0.10000000149011612</Lifetime> <Lifetime>10</Lifetime>
</c:Lifetime> </c:Lifetime>
<c:Transform> <c:Transform>
<Scale X="0" Y="1" Z="1"/> <Scale X="0" Y="1" Z="1"/>
+13 -1
View File
@@ -27,7 +27,7 @@ void EntityWrapper::AttachComponent(const char* componentName)
EntityWrapper EntityWrapper::Parent() EntityWrapper EntityWrapper::Parent()
{ {
if (this->World == nullptr || this->ID == EntityID_Invalid) { if (!Valid()) {
return EntityWrapper::Invalid; return EntityWrapper::Invalid;
} else { } else {
return EntityWrapper(this->World, this->World->GetParent(this->ID)); return EntityWrapper(this->World, this->World->GetParent(this->ID));
@@ -36,6 +36,10 @@ EntityWrapper EntityWrapper::Parent()
EntityWrapper EntityWrapper::FirstParentByName(const std::string& parentEntityName) EntityWrapper EntityWrapper::FirstParentByName(const std::string& parentEntityName)
{ {
if (!Valid()) {
return EntityWrapper::Invalid;
}
EntityWrapper entity = *this; EntityWrapper entity = *this;
while (entity.Parent().Valid()) { while (entity.Parent().Valid()) {
entity = entity.Parent(); entity = entity.Parent();
@@ -48,6 +52,10 @@ EntityWrapper EntityWrapper::FirstParentByName(const std::string& parentEntityNa
EntityWrapper EntityWrapper::FirstChildByName(const std::string& name) EntityWrapper EntityWrapper::FirstChildByName(const std::string& name)
{ {
if (!Valid()) {
return EntityWrapper::Invalid;
}
return firstChildByNameRecursive(name, this->ID); return firstChildByNameRecursive(name, this->ID);
} }
@@ -78,6 +86,10 @@ EntityWrapper EntityWrapper::FirstLevelChildByName(const std::string& name)
EntityWrapper EntityWrapper::FirstParentWithComponent(const std::string& componentType) EntityWrapper EntityWrapper::FirstParentWithComponent(const std::string& componentType)
{ {
if (!Valid()) {
return EntityWrapper::Invalid;
}
EntityWrapper entity = *this; EntityWrapper entity = *this;
while (entity.Parent().Valid()) { while (entity.Parent().Valid()) {
entity = entity.Parent(); entity = entity.Parent();
+1 -1
View File
@@ -1232,7 +1232,7 @@ void DrawFinalPass::DrawToDepthStencilBuffer(std::list<std::shared_ptr<RenderJob
} else { } else {
frameBones = modelJob->Skeleton->GetTPose(); frameBones = modelJob->Skeleton->GetTPose();
} }
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
} else { } else {
if (lastShader != m_FillDepthStencilBufferProgram->GetHandle()) { if (lastShader != m_FillDepthStencilBufferProgram->GetHandle()) {
@@ -190,60 +190,50 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
magAmmo -= 1; magAmmo -= 1;
} }
int numPellets = cWeapon["NumPellets"]; // We can't really do any valuable calculations without a valid camera
float spreadAngle = cWeapon["SpreadAngle"]; if (!m_CurrentCamera.Valid()) {
std::uniform_real_distribution<float> randomSpreadAngle(-spreadAngle, spreadAngle); return;
// Calculate pellet angles
// HACK: Random for now?
// TODO: Make distribution even for each quadrant
std::vector<glm::vec2> pelletAngles;
for (int i = 0; i < numPellets; i++) {
pelletAngles.push_back(glm::vec2(randomSpreadAngle(m_RandomEngine), randomSpreadAngle(m_RandomEngine)));
} }
double pelletDamage = (double)cWeapon["BaseDamage"] / numPellets; int numPellets = cWeapon["NumPellets"];
// Create a spread pattern
std::vector<glm::vec2> pattern;
// The first pellet is always centered
pattern.push_back(glm::vec2(0, 0));
// Any additional pellets form circles around the middle
int numOuterPellets = numPellets - 1;
float angleIncrement = glm::two_pi<float>() / numOuterPellets;
for (int i = 0; i < numOuterPellets; ++i) {
float angle = angleIncrement * i;
glm::vec2 pellet = glm::vec2(glm::cos(angle), glm::sin(angle));
pattern.push_back(pellet);
}
// Deal damage (clientside)
dealDamage(cWeapon, wi, pattern);
// Spawn tracers
spawnTracers(cWeapon, wi, pattern);
// View punch // View punch
if (IsClient) { //if (IsClient) {
EntityWrapper camera = wi.Player.FirstChildByName("Camera"); // EntityWrapper camera = wi.Player.FirstChildByName("Camera");
if (camera.Valid()) { // if (camera.Valid()) {
glm::vec3& cameraOrientation = camera["Transform"]["Orientation"]; // glm::vec3& cameraOrientation = camera["Transform"]["Orientation"];
float viewPunch = cWeapon["ViewPunch"]; // float viewPunch = cWeapon["ViewPunch"];
float maxTravelAngle = cWeapon["MaxTravelAngle"]; // float maxTravelAngle = cWeapon["MaxTravelAngle"];
float& currentTravel = cWeapon["CurrentTravel"]; // float& currentTravel = cWeapon["CurrentTravel"];
if (currentTravel < maxTravelAngle) { // if (currentTravel < maxTravelAngle) {
float change = viewPunch; // float change = viewPunch;
if (currentTravel + change > maxTravelAngle) { // if (currentTravel + change > maxTravelAngle) {
change = maxTravelAngle - currentTravel; // change = maxTravelAngle - currentTravel;
} // }
cameraOrientation.x += change; // cameraOrientation.x += change;
currentTravel += change; // currentTravel += change;
} // }
} // }
} //}
// Tracers
EntityWrapper weaponModelEntity;
if (wi.Player == LocalPlayer) {
weaponModelEntity = wi.FirstPersonEntity;
} else {
weaponModelEntity = wi.ThirdPersonEntity;
}
if (weaponModelEntity.Valid()) {
EntityWrapper spawner = weaponModelEntity.FirstChildByName("WeaponMuzzle");
for (auto& angles : pelletAngles) {
glm::vec3 direction = Transform::AbsoluteOrientation(spawner) * glm::quat(glm::vec3(angles, 0.f)) * glm::vec3(0, 0, -1);
float distance = traceRayDistance(Transform::AbsolutePosition(spawner), direction);
EntityWrapper ray = SpawnerSystem::Spawn(spawner);
((glm::vec3&)ray["Transform"]["Scale"]).z = (distance / 100.f);
glm::vec3& orientation = ray["Transform"]["Orientation"];
orientation.x += angles.x;
orientation.y += angles.y;
glm::vec3 trajectory = direction * distance;
dealDamage(cWeapon, wi, direction, pelletDamage);
}
}
// Play animation // Play animation
playAnimationAndReturn(wi.FirstPersonEntity, "FinalBlend", "Fire"); playAnimationAndReturn(wi.FirstPersonEntity, "FinalBlend", "Fire");
@@ -255,7 +245,35 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
m_EventBroker->Publish(e); m_EventBroker->Publish(e);
} }
void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, glm::vec3 direction, double damage) void DefenderWeaponBehaviour::spawnTracers(ComponentWrapper cWeapon, WeaponInfo& wi, std::vector<glm::vec2> pattern)
{
EntityWrapper muzzle = getRelevantWeaponEntity(wi).FirstChildByName("WeaponMuzzle");
if (!muzzle.Valid()) {
return;
}
float spreadAngle = glm::radians((float)cWeapon["SpreadAngle"]);
for (auto& pellet : pattern) {
glm::quat pelletRotation = glm::quat(Transform::AbsoluteOrientationEuler(wi.Player.FirstChildByName("Camera"))) * glm::quat(glm::vec3(pellet.y, pellet.x, 0) * spreadAngle);
glm::vec3 origin = Transform::AbsolutePosition(wi.Player.FirstChildByName("Camera"));
glm::vec3 direction = pelletRotation * glm::vec3(0, 0, -1);
float distance = traceRayDistance(origin, direction);
EntityWrapper ray = SpawnerSystem::Spawn(muzzle);
if (ray.Valid()) {
ComponentWrapper cTransform = ray["Transform"];
glm::vec3& position = cTransform["Position"];
glm::vec3& orientation = cTransform["Orientation"];
glm::vec3& scale = cTransform["Scale"];
position = Transform::AbsolutePosition(wi.Player.FirstChildByName("Camera"));
orientation = glm::eulerAngles(pelletRotation);
scale.z = distance;
}
}
}
void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& wi, const std::vector<glm::vec2>& pattern)
{ {
// Only deal damage client side // Only deal damage client side
if (!IsClient) { if (!IsClient) {
@@ -271,47 +289,76 @@ void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& w
if (!wi.Player.Valid()) { if (!wi.Player.Valid()) {
return; return;
} }
glm::vec3 maxRange = direction * 2.f; // Convert the spread angle to screen coordinates, taking FOV into account
EntityWrapper camera = wi.Player.FirstChildByName("Camera"); Rectangle res = m_Renderer->GetViewportSize();
glm::vec3 cameraPosition = Transform::AbsolutePosition(camera); float spreadAngle = glm::radians((float)cWeapon["SpreadAngle"]);
if (!camera.Valid()) { float nearClip = (double)m_CurrentCamera["Camera"]["NearClip"];
return; float farClip = (double)m_CurrentCamera["Camera"]["FarClip"];
} float yFOV = glm::radians((double)m_CurrentCamera["Camera"]["FOV"]);
Rectangle screenResolution = m_Renderer->GetViewportSize(); //float yRefFOV = glm::radians(59.f);
glm::vec2 centerScreen = glm::vec2(screenResolution.Width / 2, screenResolution.Height / 2); //float yRef = glm::tan(yRefFOV) * nearClip;
glm::vec2 screenCoords = cameraFromEntity(m_CurrentCamera).WorldToScreen(cameraPosition + maxRange, m_Renderer->GetViewportSize()); //float yRatio = yRef / (glm::tan(yFOV) * nearClip);
PickData pickData = m_Renderer->Pick(centerScreen + screenCoords); //float yMax = (yRatio / 2.f) * spreadAngle * (res.Height / 2.f);
EntityWrapper victim(m_World, pickData.Entity); float yRefFOV = glm::radians(59.f);
if (!victim.Valid()) { float yRef = glm::tan(yRefFOV) * nearClip;
return; float yRatio = yRef / (glm::tan(yFOV) * nearClip);
float yMax = yRatio * (glm::tan(spreadAngle) * farClip);
LOG_DEBUG("Ratio: %f", yRatio);
LOG_DEBUG("fatClip: %f", farClip);
LOG_DEBUG("yMax: %f", yMax);
double pelletDamage = (double)cWeapon["BaseDamage"] / pattern.size();
// Pick!
std::unordered_map<EntityWrapper, double> damageSum;
glm::vec2 screenCenter(res.Width / 2.f, res.Height / 2.f);
for (auto& pellet : pattern) {
glm::vec2 pickCoord = screenCenter + (pellet * glm::vec2(yMax, yMax));
PickData pick = m_Renderer->Pick(pickCoord);
EntityWrapper victim(m_World, pick.Entity);
if (!victim.Valid()) {
continue;
}
// Temp hit decal
EntityWrapper hit = ResourceManager::Load<EntityFile>("Schema/Entities/HitTest.xml")->MergeInto(m_World);
hit["Transform"]["Position"] = pick.Position;
// Don't let us shoot ourselves in the foot somehow
if (victim == LocalPlayer) {
continue;
}
// Only care about players being hit
if (!victim.HasComponent("Player")) {
victim = victim.FirstParentWithComponent("Player");
if (!victim.Valid()) {
continue;
}
}
// Check for friendly fire
if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)wi.Player["Team"]["Team"]) {
// TODO: Ammo sharing
continue;
}
damageSum[victim] += pelletDamage;
((glm::vec3&)hit["Model"]["Color"]).b = 1.f;
} }
// Don't let us shoot ourselves in the foot somehow // Deal damage!
if (victim == LocalPlayer) { for (auto& kv : damageSum) {
return; // Deal damage!
Events::PlayerDamage ePlayerDamage;
ePlayerDamage.Inflictor = wi.Player;
ePlayerDamage.Victim = kv.first;
ePlayerDamage.Damage = kv.second;
m_EventBroker->Publish(ePlayerDamage);
LOG_DEBUG("Dealt %f damage to #%i", kv.second, kv.first.ID);
} }
// Only care about players being hit
if (!victim.HasComponent("Player")) {
victim = victim.FirstParentWithComponent("Player");
}
if (!victim.Valid()) {
return;
}
// Check for friendly fire
if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)wi.Player["Team"]["Team"]) {
return;
}
// Deal damage!
Events::PlayerDamage ePlayerDamage;
ePlayerDamage.Inflictor = wi.Player;
ePlayerDamage.Victim = victim;
ePlayerDamage.Damage = damage;
m_EventBroker->Publish(ePlayerDamage);
LOG_DEBUG("Damage: %f", damage);
} }
bool DefenderWeaponBehaviour::canFire(ComponentWrapper cWeapon, WeaponInfo& wi) bool DefenderWeaponBehaviour::canFire(ComponentWrapper cWeapon, WeaponInfo& wi)