SuperTuxKart
projectile_manager.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2006-2015 Joerg Henrichs
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_PROJECTILEMANAGER_HPP
20 #define HEADER_PROJECTILEMANAGER_HPP
21 
22 #include <map>
23 #include <memory>
24 #include <unordered_set>
25 #include <vector>
26 
27 namespace irr
28 {
29  namespace scene { class IMesh; }
30 }
31 
32 #include "items/powerup_manager.hpp"
33 #include "utils/no_copy.hpp"
34 
35 class AbstractKart;
36 class Flyable;
37 class HitEffect;
38 class Rewinder;
39 class Track;
40 class Vec3;
41 
45 class ProjectileManager : public NoCopy
46 {
47 private:
48  typedef std::vector<HitEffect*> HitEffects;
49 
52  std::map<std::string, std::shared_ptr<Flyable> > m_active_projectiles;
53 
57 
58  std::string getUniqueIdentity(AbstractKart* kart,
59  PowerupManager::PowerupType type);
60  void updateServer(int ticks);
61 public:
63  ~ProjectileManager() {}
64  void loadData ();
65  void cleanup ();
66  void update (int ticks);
67  void updateGraphics (float dt);
68  void removeTextures ();
69  bool projectileIsClose(const AbstractKart * const kart,
70  float radius);
71 
72  int getNearbyProjectileCount(const AbstractKart * const kart,
73  float radius, PowerupManager::PowerupType type,
74  bool exclude_owned=false);
75  // ------------------------------------------------------------------------
78  void addHitEffect(HitEffect *hit_effect)
79  { m_active_hit_effects.push_back(hit_effect); }
80  // ------------------------------------------------------------------------
81  std::shared_ptr<Rewinder>
82  addRewinderFromNetworkState(const std::string& uid);
83  // ------------------------------------------------------------------------
84  std::shared_ptr<Flyable> newProjectile(AbstractKart *kart,
85  PowerupManager::PowerupType type);
86  // ------------------------------------------------------------------------
87  void addByUID(const std::string& uid, std::shared_ptr<Flyable> f)
88  { m_active_projectiles[uid] = f; }
89  // ------------------------------------------------------------------------
90  void removeByUID(const std::string& uid)
91  { m_active_projectiles.erase(uid); }
92 };
93 
94 extern ProjectileManager *projectile_manager;
95 
96 #endif
97 
98 /* EOF */
99 
void addHitEffect(HitEffect *hit_effect)
Adds a special hit effect to be shown.
Definition: projectile_manager.hpp:78
Definition: projectile_manager.hpp:45
void update(int ticks)
General projectile update call.
Definition: projectile_manager.cpp:79
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:34
Definition: rewinder.hpp:43
A small interface for effects to be used when a kart is hit.
Definition: hit_effect.hpp:32
void updateGraphics(float dt)
Called once per rendered frame.
Definition: projectile_manager.cpp:71
bool projectileIsClose(const AbstractKart *const kart, float radius)
Returns true if a projectile is within the given distance of the specified kart.
Definition: projectile_manager.cpp:188
int getNearbyProjectileCount(const AbstractKart *const kart, float radius, PowerupManager::PowerupType type, bool exclude_owned=false)
Returns an int containing the numbers of a given flyable in a given radius around the kart.
Definition: projectile_manager.cpp:211
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:25
std::shared_ptr< Flyable > newProjectile(AbstractKart *kart, PowerupManager::PowerupType type)
Creates a new projectile of the given type.
Definition: projectile_manager.cpp:143
void updateServer(int ticks)
Updates all rockets on the server (or no networking).
Definition: projectile_manager.cpp:108
HitEffects m_active_hit_effects
All active hit effects, i.e.
Definition: projectile_manager.hpp:56
Definition: flyable.hpp:47
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:61
std::map< std::string, std::shared_ptr< Flyable > > m_active_projectiles
The list of all active projectiles, i.e.
Definition: projectile_manager.hpp:52
Definition: track.hpp:96