2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 01.06.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SHOOTER_WEAPON_H
|
|
|
|
#define SHOOTER_WEAPON_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
2021-10-09 13:41:12 +03:00
|
|
|
#include "../engine/World.h"
|
|
|
|
#include "../engine/Camera.h"
|
2021-09-13 15:53:43 +03:00
|
|
|
#include <SFML/Audio/Sound.hpp>
|
2021-10-09 13:41:12 +03:00
|
|
|
#include "../engine/Mesh.h"
|
|
|
|
#include "../engine/utils/Time.h"
|
2021-10-17 19:38:16 +03:00
|
|
|
#include "../engine/SoundController.h"
|
2021-10-09 13:41:12 +03:00
|
|
|
#include "../engine/Consts.h"
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-22 19:42:32 +03:00
|
|
|
struct FireInformation {
|
|
|
|
const std::map<ObjectNameTag, double> damagedPlayers;
|
|
|
|
const bool shot;
|
|
|
|
};
|
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
class Weapon : public RigidBody {
|
2021-09-13 15:53:43 +03:00
|
|
|
protected:
|
|
|
|
int _initialPack = 100; // how much ammo do you have when you find the weapon
|
|
|
|
|
|
|
|
int _clipCapacity = 30; // how much ammo can be stored in one clip
|
|
|
|
int _stockAmmo = _initialPack - _clipCapacity; // how much ammo do you have in stock
|
|
|
|
int _clipAmmo = _clipCapacity; // how much ammo do you have in current clip
|
|
|
|
|
|
|
|
double _reloadTime = 3;
|
|
|
|
double _fireDelay = 0.1; // time delay between fires
|
|
|
|
double _damage = 300;
|
|
|
|
|
|
|
|
double _spreading = 2.0;
|
|
|
|
|
2021-10-16 20:22:55 +03:00
|
|
|
std::string _name = "Weapon";
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-09 13:41:12 +03:00
|
|
|
double _lastFireTime = std::numeric_limits<double>::min();
|
|
|
|
double _lastReloadTime = std::numeric_limits<double>::min();
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-17 19:38:16 +03:00
|
|
|
std::string fireSound;
|
|
|
|
std::string reloadSound;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
std::function<void(const Vec3D&, const Vec3D&)> _addTraceCallBack;
|
2021-10-02 20:36:07 +03:00
|
|
|
|
2021-10-22 19:42:32 +03:00
|
|
|
std::map<ObjectNameTag, double> addTrace(std::function<IntersectionInformation(const Vec3D&, const Vec3D&)> rayCastFunction, const Vec3D& position, const Vec3D& direction);
|
2021-10-16 20:22:55 +03:00
|
|
|
|
2021-10-22 19:42:32 +03:00
|
|
|
virtual std::map<ObjectNameTag, double> processFire(std::function<IntersectionInformation(const Vec3D&, const Vec3D&)> rayCastFunction, const Vec3D& position, const Vec3D& direction);
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
public:
|
2021-10-17 20:52:21 +03:00
|
|
|
Weapon(const std::string& weaponName, const std::string& objFileName, const Vec3D& scale, const Vec3D& translate, const Vec3D& rotate);
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-22 19:42:32 +03:00
|
|
|
FireInformation fire(std::function<IntersectionInformation(const Vec3D&, const Vec3D&)> rayCastFunction, const Vec3D& position, const Vec3D& direction);
|
2021-09-13 15:53:43 +03:00
|
|
|
void reload();
|
|
|
|
|
|
|
|
[[nodiscard]] std::pair<double, double> balance() const{ return std::make_pair(_clipAmmo, _stockAmmo); }
|
|
|
|
|
2021-10-12 17:12:47 +03:00
|
|
|
void setAddTraceCallBack(std::function<void(Vec3D, Vec3D)> add) {
|
2021-10-02 20:36:07 +03:00
|
|
|
_addTraceCallBack = std::move(add);
|
2021-09-13 15:53:43 +03:00
|
|
|
}
|
|
|
|
|
2021-10-17 10:21:10 +03:00
|
|
|
[[nodiscard]] ObjectNameTag name() const { return ObjectNameTag(_name); }
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
void addAmmo(int ammoAdd) { _stockAmmo += ammoAdd; }
|
|
|
|
|
|
|
|
[[nodiscard]] int initialPack() const {return _initialPack; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //SHOOTER_3DZAVR_WEAPON_H
|