Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1992b6cde1 | |||
| c82be79bb8 | |||
| 35a8d45fa4 |
+1
-1
Submodule assets updated: 85d96f6f3d...298641b1af
@@ -27,9 +27,12 @@ private:
|
||||
std::random_device m_RandomDevice;
|
||||
std::mt19937 m_RandomEngine;
|
||||
|
||||
|
||||
|
||||
// Weapon functions
|
||||
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);
|
||||
|
||||
// Utility
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<DefenderWeapon xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="DefenderWeapon.xsd">
|
||||
<Slot><Primary/></Slot>
|
||||
<MagazineAmmo>8</MagazineAmmo>
|
||||
<MagazineAmmo>9999</MagazineAmmo>
|
||||
<MagazineSize>8</MagazineSize>
|
||||
<Ammo>64</Ammo>
|
||||
<MaxAmmo>64</MaxAmmo>
|
||||
<BaseDamage>90</BaseDamage>
|
||||
<SpreadAngle>0.174533</SpreadAngle> <!-- 0.174533 = 10 degrees -->
|
||||
<SpreadAngle>10</SpreadAngle>
|
||||
<MaxTravelAngle>0.174533</MaxTravelAngle> <!-- 0.174533 = 10 degrees -->
|
||||
<NumPellets>10</NumPellets>
|
||||
<NumPellets>9</NumPellets>
|
||||
<RPM>120</RPM>
|
||||
<ViewPunch>0.03</ViewPunch>
|
||||
<ViewReturnSpeed>0.2</ViewReturnSpeed>
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<xs:annotation><xs:documentation>Damage dealt if all shotgun pellets hit</xs:documentation></xs:annotation>
|
||||
</xs:element>
|
||||
<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 name="MaxTravelAngle" type="t:float" minOccurs="0">
|
||||
<xs:annotation><xs:documentation>Maximum vertical aim travel angle in radians</xs:documentation></xs:annotation>
|
||||
|
||||
@@ -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>
|
||||
@@ -1,25 +1,39 @@
|
||||
<?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>
|
||||
<c:Transform>
|
||||
<Position X="1.70262027" Y="0.261695802" Z="-3.26634645"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
|
||||
<Children>
|
||||
<Entity name="Back">
|
||||
<Components>
|
||||
<c:Blend>
|
||||
<Pose1>Deploy</Pose1>
|
||||
<Pose2>Idle</Pose2>
|
||||
<Weight>0</Weight>
|
||||
</c:Blend>
|
||||
<c:Shielded/>
|
||||
<c:Model>
|
||||
<Resource>Models/Characters/Defender/DefenderShield.mesh</Resource>
|
||||
<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/>
|
||||
</Components>
|
||||
|
||||
<Children>
|
||||
<Entity name="Deploy">
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>ActivateDeactiveShieldF</AnimationName>
|
||||
<Time>1</Time>
|
||||
<Speed>1</Speed>
|
||||
<Play>true</Play>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
@@ -29,12 +43,54 @@
|
||||
<Components>
|
||||
<c:Animation>
|
||||
<AnimationName>ShieldFrontF</AnimationName>
|
||||
<Speed>1</Speed>
|
||||
</c:Animation>
|
||||
<c:Transform/>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
<Entity name="Front">
|
||||
<Components>
|
||||
<c:Blend>
|
||||
<Pose1>Deploy</Pose1>
|
||||
<Pose2>Idle</Pose2>
|
||||
<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/>
|
||||
</Components>
|
||||
<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>
|
||||
</Children>
|
||||
|
||||
</Entity>
|
||||
|
||||
@@ -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>
|
||||
@@ -103,7 +103,7 @@
|
||||
<Color A="1" B="1" G="0.254901975" R="0"/>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="-0.600000024" Y="0" Z="0"/>
|
||||
<Position X="0.800000012" Y="0" Z="0"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
@@ -116,7 +116,7 @@
|
||||
<Color A="1" B="1" G="0.254901975" R="0"/>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="0.800000012" Y="0" Z="0"/>
|
||||
<Position X="-0.600000024" Y="0" Z="0.549540162"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
@@ -157,8 +157,98 @@
|
||||
<Resource>Models/Weapons/Blue/DefenderWeaponBlue.mesh</Resource>
|
||||
</c:Model>
|
||||
<c:Transform>
|
||||
<Position X="0.00681143999" Y="-0.204994932" Z="-0.209244296"/>
|
||||
<Orientation X="-0.581807375" Y="0.562133908" Z="-0.0719003305"/>
|
||||
<Orientation X="0" Y="-0" Z="0"/>
|
||||
</c:Transform>
|
||||
</Components>
|
||||
<Children/>
|
||||
</Entity>
|
||||
</Children>
|
||||
</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/>
|
||||
@@ -166,5 +256,7 @@
|
||||
</Children>
|
||||
</Entity>
|
||||
</Children>
|
||||
</Entity>
|
||||
</Children>
|
||||
|
||||
</Entity>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
<Components>
|
||||
<c:Lifetime>
|
||||
<Lifetime>0.10000000149011612</Lifetime>
|
||||
<Lifetime>10</Lifetime>
|
||||
</c:Lifetime>
|
||||
<c:Transform>
|
||||
<Scale X="0" Y="1" Z="1"/>
|
||||
|
||||
@@ -27,7 +27,7 @@ void EntityWrapper::AttachComponent(const char* componentName)
|
||||
|
||||
EntityWrapper EntityWrapper::Parent()
|
||||
{
|
||||
if (this->World == nullptr || this->ID == EntityID_Invalid) {
|
||||
if (!Valid()) {
|
||||
return EntityWrapper::Invalid;
|
||||
} else {
|
||||
return EntityWrapper(this->World, this->World->GetParent(this->ID));
|
||||
@@ -36,6 +36,10 @@ EntityWrapper EntityWrapper::Parent()
|
||||
|
||||
EntityWrapper EntityWrapper::FirstParentByName(const std::string& parentEntityName)
|
||||
{
|
||||
if (!Valid()) {
|
||||
return EntityWrapper::Invalid;
|
||||
}
|
||||
|
||||
EntityWrapper entity = *this;
|
||||
while (entity.Parent().Valid()) {
|
||||
entity = entity.Parent();
|
||||
@@ -48,6 +52,10 @@ EntityWrapper EntityWrapper::FirstParentByName(const std::string& parentEntityNa
|
||||
|
||||
EntityWrapper EntityWrapper::FirstChildByName(const std::string& name)
|
||||
{
|
||||
if (!Valid()) {
|
||||
return EntityWrapper::Invalid;
|
||||
}
|
||||
|
||||
return firstChildByNameRecursive(name, this->ID);
|
||||
}
|
||||
|
||||
@@ -78,6 +86,10 @@ EntityWrapper EntityWrapper::FirstLevelChildByName(const std::string& name)
|
||||
|
||||
EntityWrapper EntityWrapper::FirstParentWithComponent(const std::string& componentType)
|
||||
{
|
||||
if (!Valid()) {
|
||||
return EntityWrapper::Invalid;
|
||||
}
|
||||
|
||||
EntityWrapper entity = *this;
|
||||
while (entity.Parent().Valid()) {
|
||||
entity = entity.Parent();
|
||||
|
||||
@@ -1232,7 +1232,7 @@ void DrawFinalPass::DrawToDepthStencilBuffer(std::list<std::shared_ptr<RenderJob
|
||||
} else {
|
||||
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 {
|
||||
if (lastShader != m_FillDepthStencilBufferProgram->GetHandle()) {
|
||||
|
||||
@@ -190,60 +190,50 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
|
||||
magAmmo -= 1;
|
||||
}
|
||||
|
||||
int numPellets = cWeapon["NumPellets"];
|
||||
float spreadAngle = cWeapon["SpreadAngle"];
|
||||
std::uniform_real_distribution<float> randomSpreadAngle(-spreadAngle, spreadAngle);
|
||||
|
||||
// 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)));
|
||||
// We can't really do any valuable calculations without a valid camera
|
||||
if (!m_CurrentCamera.Valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
if (IsClient) {
|
||||
EntityWrapper camera = wi.Player.FirstChildByName("Camera");
|
||||
if (camera.Valid()) {
|
||||
glm::vec3& cameraOrientation = camera["Transform"]["Orientation"];
|
||||
float viewPunch = cWeapon["ViewPunch"];
|
||||
float maxTravelAngle = cWeapon["MaxTravelAngle"];
|
||||
float& currentTravel = cWeapon["CurrentTravel"];
|
||||
if (currentTravel < maxTravelAngle) {
|
||||
float change = viewPunch;
|
||||
if (currentTravel + change > maxTravelAngle) {
|
||||
change = maxTravelAngle - currentTravel;
|
||||
}
|
||||
cameraOrientation.x += 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);
|
||||
}
|
||||
}
|
||||
//if (IsClient) {
|
||||
// EntityWrapper camera = wi.Player.FirstChildByName("Camera");
|
||||
// if (camera.Valid()) {
|
||||
// glm::vec3& cameraOrientation = camera["Transform"]["Orientation"];
|
||||
// float viewPunch = cWeapon["ViewPunch"];
|
||||
// float maxTravelAngle = cWeapon["MaxTravelAngle"];
|
||||
// float& currentTravel = cWeapon["CurrentTravel"];
|
||||
// if (currentTravel < maxTravelAngle) {
|
||||
// float change = viewPunch;
|
||||
// if (currentTravel + change > maxTravelAngle) {
|
||||
// change = maxTravelAngle - currentTravel;
|
||||
// }
|
||||
// cameraOrientation.x += change;
|
||||
// currentTravel += change;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
// Play animation
|
||||
playAnimationAndReturn(wi.FirstPersonEntity, "FinalBlend", "Fire");
|
||||
@@ -255,7 +245,35 @@ void DefenderWeaponBehaviour::fireShell(ComponentWrapper cWeapon, WeaponInfo& wi
|
||||
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
|
||||
if (!IsClient) {
|
||||
@@ -272,46 +290,75 @@ void DefenderWeaponBehaviour::dealDamage(ComponentWrapper cWeapon, WeaponInfo& w
|
||||
return;
|
||||
}
|
||||
|
||||
glm::vec3 maxRange = direction * 2.f;
|
||||
EntityWrapper camera = wi.Player.FirstChildByName("Camera");
|
||||
glm::vec3 cameraPosition = Transform::AbsolutePosition(camera);
|
||||
if (!camera.Valid()) {
|
||||
return;
|
||||
}
|
||||
Rectangle screenResolution = m_Renderer->GetViewportSize();
|
||||
glm::vec2 centerScreen = glm::vec2(screenResolution.Width / 2, screenResolution.Height / 2);
|
||||
glm::vec2 screenCoords = cameraFromEntity(m_CurrentCamera).WorldToScreen(cameraPosition + maxRange, m_Renderer->GetViewportSize());
|
||||
PickData pickData = m_Renderer->Pick(centerScreen + screenCoords);
|
||||
EntityWrapper victim(m_World, pickData.Entity);
|
||||
// Convert the spread angle to screen coordinates, taking FOV into account
|
||||
Rectangle res = m_Renderer->GetViewportSize();
|
||||
float spreadAngle = glm::radians((float)cWeapon["SpreadAngle"]);
|
||||
float nearClip = (double)m_CurrentCamera["Camera"]["NearClip"];
|
||||
float farClip = (double)m_CurrentCamera["Camera"]["FarClip"];
|
||||
float yFOV = glm::radians((double)m_CurrentCamera["Camera"]["FOV"]);
|
||||
//float yRefFOV = glm::radians(59.f);
|
||||
//float yRef = glm::tan(yRefFOV) * nearClip;
|
||||
//float yRatio = yRef / (glm::tan(yFOV) * nearClip);
|
||||
//float yMax = (yRatio / 2.f) * spreadAngle * (res.Height / 2.f);
|
||||
float yRefFOV = glm::radians(59.f);
|
||||
float yRef = glm::tan(yRefFOV) * nearClip;
|
||||
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()) {
|
||||
return;
|
||||
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) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only care about players being hit
|
||||
if (!victim.HasComponent("Player")) {
|
||||
victim = victim.FirstParentWithComponent("Player");
|
||||
}
|
||||
if (!victim.Valid()) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for friendly fire
|
||||
if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)wi.Player["Team"]["Team"]) {
|
||||
return;
|
||||
// TODO: Ammo sharing
|
||||
continue;
|
||||
}
|
||||
|
||||
damageSum[victim] += pelletDamage;
|
||||
((glm::vec3&)hit["Model"]["Color"]).b = 1.f;
|
||||
}
|
||||
|
||||
// Deal damage!
|
||||
for (auto& kv : damageSum) {
|
||||
// Deal damage!
|
||||
Events::PlayerDamage ePlayerDamage;
|
||||
ePlayerDamage.Inflictor = wi.Player;
|
||||
ePlayerDamage.Victim = victim;
|
||||
ePlayerDamage.Damage = damage;
|
||||
ePlayerDamage.Victim = kv.first;
|
||||
ePlayerDamage.Damage = kv.second;
|
||||
m_EventBroker->Publish(ePlayerDamage);
|
||||
LOG_DEBUG("Damage: %f", damage);
|
||||
LOG_DEBUG("Dealt %f damage to #%i", kv.second, kv.first.ID);
|
||||
}
|
||||
}
|
||||
|
||||
bool DefenderWeaponBehaviour::canFire(ComponentWrapper cWeapon, WeaponInfo& wi)
|
||||
|
||||
Reference in New Issue
Block a user