2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 02.06.2021.
|
|
|
|
//
|
|
|
|
|
2021-10-09 13:41:12 +03:00
|
|
|
#include "../engine/ResourceManager.h"
|
2021-09-13 15:53:43 +03:00
|
|
|
#include "Shotgun.h"
|
2021-10-09 13:41:12 +03:00
|
|
|
#include "../engine/animation/AColor.h"
|
|
|
|
#include "../engine/animation/AFunction.h"
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
Shotgun::Shotgun(int ammo, const std::string& weaponName) : Weapon(weaponName, "obj/shotgun.obj", "obj/shotgun_mat.txt", Vec3D{3, 3, 3}, Vec3D{-0.95, 1.3, -0.6}, Vec3D{0, Consts::PI, 0}) {
|
2021-10-09 13:41:12 +03:00
|
|
|
fireSound.setBuffer(*ResourceManager::loadSoundBuffer("sound/weapons/shotgun.ogg"));
|
|
|
|
reloadSound.setBuffer(*ResourceManager::loadSoundBuffer("sound/weapons/reload_shotgun.ogg"));
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
//reloadSound.setVolume(30);
|
|
|
|
_initialPack = 15;
|
|
|
|
_clipCapacity = 1; // how much ammo can be stored in one clipx
|
|
|
|
_stockAmmo = ammo - _clipCapacity; // how much ammo do you have in stock
|
|
|
|
_clipAmmo = _clipCapacity; // how much ammo do you have in current clip
|
|
|
|
_reloadTime = 1;
|
|
|
|
_fireDelay = 1; // time delay between fires
|
|
|
|
_damage = 400;
|
|
|
|
_spreading = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<std::string, double>
|
2021-10-12 17:12:47 +03:00
|
|
|
Shotgun::processFire(std::function<std::pair<Vec3D, std::string>(const Vec3D&, const Vec3D&)> rayCastFunction, const Vec3D& pos, const Vec3D& direction) {
|
2021-09-13 15:53:43 +03:00
|
|
|
std::map<std::string, double> damagedPlayers;
|
|
|
|
|
|
|
|
for(int i = 0; i < 15; i++) {
|
|
|
|
//generate random vector
|
2021-10-12 17:12:47 +03:00
|
|
|
Vec3D randV(10*_spreading*(1.0 - 2.0*(double)rand()/RAND_MAX), 10*_spreading*(1.0 - 2.0*(double)rand()/RAND_MAX), 10*_spreading*(1.0 - 2.0*(double)rand()/RAND_MAX));
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
// damage player
|
2021-10-02 20:36:07 +03:00
|
|
|
auto rayCast = rayCastFunction(pos, pos + direction * 1000 + randV);
|
2021-10-16 16:14:51 +03:00
|
|
|
if (rayCast.second.find("Enemy") != std::string::npos) {
|
2021-10-02 20:36:07 +03:00
|
|
|
damagedPlayers[rayCast.second] += _damage / (1.0 + (pos - rayCast.first).abs());
|
2021-09-13 15:53:43 +03:00
|
|
|
}
|
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
Vec3D to = rayCast.first == Vec3D(0) ? pos + direction * 1000 + randV: rayCast.first;
|
|
|
|
Vec3D from = position() + Vec3D(triangles().back()[0]);
|
2021-10-02 20:36:07 +03:00
|
|
|
_addTraceCallBack(from, to);
|
2021-09-13 15:53:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return damagedPlayers;
|
|
|
|
}
|