vectozavr-shooter/weapon/Weapon.h

80 lines
2.9 KiB
C
Raw Normal View History

2021-09-13 15:53:43 +03:00
//
// Created by Иван Ильин on 01.06.2021.
//
#ifndef SHOOTER_WEAPON_H
#define SHOOTER_WEAPON_H
#include <string>
2023-05-21 16:34:55 +03:00
#include "../3dzavr/engine/World.h"
#include "../3dzavr/engine/Camera.h"
2021-09-13 15:53:43 +03:00
#include <SFML/Audio/Sound.hpp>
2023-05-21 16:34:55 +03:00
#include "../3dzavr/engine/Mesh.h"
#include "../3dzavr/engine/utils/Time.h"
#include "../3dzavr/engine/io/SoundController.h"
#include "../3dzavr/engine/Consts.h"
2021-09-13 15:53:43 +03:00
2021-10-28 16:58:02 +03:00
struct FireInformation final {
2021-10-22 19:42:32 +03:00
const std::map<ObjectNameTag, double> damagedPlayers;
const bool shot;
};
2021-10-02 20:36:07 +03:00
class Weapon : public RigidBody {
2021-10-28 16:58:02 +03:00
private:
const int _initialPack = 100; // how much ammo do you have when you find the weapon
const int _clipCapacity = 30; // how much ammo can be stored in one clip
int _stockAmmo; // how much ammo do you have in stock
int _clipAmmo; // how much ammo do you have in current clip
const double _reloadTime = 3.0;
const double _fireDelay = 0.1; // time delay between fires
const double _damage = 300;
const double _spreading = 2.0;
const std::string _fireSound;
const std::string _reloadSound;
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-31 11:39:08 +03:00
std::function<void(const Vec3D &, const Vec3D &)> _addTraceCallBack;
2021-11-01 17:08:36 +03:00
std::function<void()> _reloadCallBack;
2022-07-07 13:14:00 +03:00
std::function<void()> _fireCallBack;
2021-10-02 20:36:07 +03:00
2021-10-28 16:58:02 +03:00
protected:
2021-10-31 11:39:08 +03:00
std::map<ObjectNameTag, double>
2021-11-09 22:54:20 +03:00
fireABullet(std::function<IntersectionInformation(const Vec3D &, const Vec3D &)> rayCastFunction,
const Vec3D &position, const Vec3D &direction) const;
2021-10-31 11:39:08 +03:00
virtual std::map<ObjectNameTag, double>
processFire(std::function<IntersectionInformation(const Vec3D &, const Vec3D &)> rayCastFunction,
2021-11-09 22:54:20 +03:00
const Vec3D &position, const Vec3D &direction) const;
2021-09-13 15:53:43 +03:00
public:
2021-10-31 11:39:08 +03:00
Weapon(int initialPack, int clipCapacity, double reloadTime, double fireDelay, double damage, double spreading,
std::string fireSound, std::string reloadSound, ObjectNameTag weaponName, const std::string &objFileName,
const Vec3D &s, const Vec3D &t, const Vec3D &r);
FireInformation
2021-11-09 22:54:20 +03:00
fire(std::function<IntersectionInformation(const Vec3D &, const Vec3D &)> rayCastFunction, const Vec3D &cameraPosition,
2021-10-31 11:39:08 +03:00
const Vec3D &direction);
2021-09-13 15:53:43 +03:00
void reload();
2021-11-01 17:08:36 +03:00
[[nodiscard]] double reloadTime() const { return _reloadTime; }
2022-07-07 13:14:00 +03:00
[[nodiscard]] double fireDelay() const { return _fireDelay; }
2021-09-13 15:53:43 +03:00
2021-10-31 11:39:08 +03:00
[[nodiscard]] std::pair<double, double> balance() const { return std::make_pair(_clipAmmo, _stockAmmo); }
2021-09-13 15:53:43 +03:00
2021-10-28 16:58:02 +03:00
void setAddTraceCallBack(std::function<void(Vec3D, Vec3D)> add) { _addTraceCallBack = std::move(add); }
2021-11-01 17:08:36 +03:00
void setReloadCallBack(std::function<void()> reload) { _reloadCallBack = std::move(reload); }
2022-07-07 13:14:00 +03:00
void setFireCallBack(std::function<void()> fire) { _fireCallBack = std::move(fire); }
2021-11-01 17:08:36 +03:00
2021-09-13 15:53:43 +03:00
2021-11-09 22:54:20 +03:00
void addAPack() { _stockAmmo += initialPack(); }
2021-09-13 15:53:43 +03:00
2021-10-28 16:58:02 +03:00
[[nodiscard]] int initialPack() const { return _initialPack; }
2021-09-13 15:53:43 +03:00
};
#endif //SHOOTER_3DZAVR_WEAPON_H