1 | // SuperTux |
2 | // Copyright (C) 2006 Matthias Braun <matze@braunis.de> |
3 | // |
4 | // This program is free software: you can redistribute it and/or modify |
5 | // it under the terms of the GNU General Public License as published by |
6 | // the Free Software Foundation, either version 3 of the License, or |
7 | // (at your option) any later version. |
8 | // |
9 | // This program is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | // GNU General Public License for more details. |
13 | // |
14 | // You should have received a copy of the GNU General Public License |
15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | |
17 | #ifndef HEADER_SUPERTUX_BADGUY_DISPENSER_HPP |
18 | #define |
19 | |
20 | #include "badguy/badguy.hpp" |
21 | #include "scripting/dispenser.hpp" |
22 | #include "squirrel/exposed_object.hpp" |
23 | |
24 | class Dispenser final : public BadGuy, |
25 | public ExposedObject<Dispenser, scripting::Dispenser> |
26 | { |
27 | private: |
28 | enum class DispenserType { |
29 | DROPPER, ROCKETLAUNCHER, CANNON, POINT |
30 | }; |
31 | |
32 | static DispenserType DispenserType_from_string(const std::string& type_string); |
33 | static std::string DispenserType_to_string(DispenserType type); |
34 | |
35 | public: |
36 | Dispenser(const ReaderMapping& reader); |
37 | |
38 | virtual void draw(DrawingContext& context) override; |
39 | virtual void activate() override; |
40 | virtual void deactivate() override; |
41 | virtual void active_update(float dt_sec) override; |
42 | |
43 | virtual void freeze() override; |
44 | virtual void unfreeze() override; |
45 | virtual bool is_freezable() const override; |
46 | virtual bool is_flammable() const override; |
47 | virtual std::string get_class() const override { return "dispenser" ; } |
48 | virtual std::string get_display_name() const override { return _("Dispenser" ); } |
49 | |
50 | virtual ObjectSettings get_settings() override; |
51 | virtual void after_editor_set() override; |
52 | |
53 | void notify_dead() { |
54 | if (m_limit_dispensed_badguys) { |
55 | m_current_badguys--; |
56 | } |
57 | } |
58 | |
59 | protected: |
60 | virtual bool collision_squished(GameObject& object) override; |
61 | virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override; |
62 | void launch_badguy(); |
63 | |
64 | private: |
65 | void set_correct_action(); |
66 | |
67 | private: |
68 | float m_cycle; |
69 | std::vector<std::string> m_badguys; |
70 | unsigned int m_next_badguy; |
71 | Timer m_dispense_timer; |
72 | bool m_autotarget; |
73 | bool m_swivel; |
74 | bool m_broken; |
75 | bool m_random; |
76 | |
77 | DispenserType m_type; |
78 | std::string m_type_str; |
79 | |
80 | /** Do we need to limit the number of dispensed badguys? */ |
81 | bool m_limit_dispensed_badguys; |
82 | |
83 | /** Maximum concurrent number of badguys to be dispensed */ |
84 | int m_max_concurrent_badguys; |
85 | |
86 | /** Current amount of spawned badguys */ |
87 | int m_current_badguys; |
88 | |
89 | private: |
90 | Dispenser(const Dispenser&) = delete; |
91 | Dispenser& operator=(const Dispenser&) = delete; |
92 | }; |
93 | |
94 | #endif |
95 | |
96 | /* EOF */ |
97 | |