2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 01.06.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SHOOTER_WEAPON_H
|
|
|
|
#define SHOOTER_WEAPON_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <World.h>
|
|
|
|
#include <Camera.h>
|
|
|
|
#include <SFML/Audio/Sound.hpp>
|
2021-10-02 21:17:03 +03:00
|
|
|
#include <cmath>
|
2021-09-13 15:53:43 +03:00
|
|
|
#include "Mesh.h"
|
|
|
|
#include "utils/Time.h"
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
std::string _name = "Weapon_name";
|
|
|
|
|
|
|
|
double _lastFireTime = -INFINITY;
|
|
|
|
double _lastReloadTime = -INFINITY;
|
|
|
|
|
|
|
|
sf::Sound fireSound;
|
|
|
|
sf::Sound reloadSound;
|
|
|
|
sf::Sound noAmmoSound;
|
|
|
|
|
|
|
|
int fireTraces = 0;
|
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
std::function<void(const Point4D&, const Point4D&)> _addTraceCallBack;
|
|
|
|
|
|
|
|
virtual std::map<std::string, double> processFire(std::function<std::pair<Point4D, std::string>(const Point4D&, const Point4D&)> rayCastFunction, const Point4D& position, const Point4D& direction);
|
2021-09-13 15:53:43 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
Weapon(const std::string& weaponName, const std::string& objFileName, const std::string& matFileName, const Point4D& scale, const Point4D& translate, const Point4D& rotate);
|
|
|
|
|
2021-10-02 20:36:07 +03:00
|
|
|
std::map<std::string, double> fire(std::function<std::pair<Point4D, std::string>(const Point4D&, const Point4D&)> rayCastFunction, const Point4D& position, const Point4D& direction);
|
2021-09-13 15:53:43 +03:00
|
|
|
void reload();
|
|
|
|
|
|
|
|
[[nodiscard]] std::pair<double, double> balance() const{ return std::make_pair(_clipAmmo, _stockAmmo); }
|
|
|
|
|
|
|
|
void setAddTraceCallBack(std::function<void(Point4D, Point4D)> add) {
|
2021-10-02 20:36:07 +03:00
|
|
|
_addTraceCallBack = std::move(add);
|
2021-09-13 15:53:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] std::string name() const { return _name; }
|
|
|
|
|
|
|
|
void addAmmo(int ammoAdd) { _stockAmmo += ammoAdd; }
|
|
|
|
|
|
|
|
[[nodiscard]] int initialPack() const {return _initialPack; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //SHOOTER_3DZAVR_WEAPON_H
|