1 /* 2 * This file is part of Dune Legacy. 3 * 4 * Dune Legacy 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 2 of the License, or 7 * (at your option) any later version. 8 * 9 * Dune Legacy 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 Dune Legacy. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef TRIGGERMANAGER_H 19 #define TRIGGERMANAGER_H 20 21 #include <Trigger/Trigger.h> 22 #include <misc/InputStream.h> 23 #include <misc/OutputStream.h> 24 25 #include <memory> 26 #include <list> 27 28 /** 29 This class manages triggers for the game play. A trigger is triggered at a specific game cycle. 30 */ 31 class TriggerManager { 32 public: 33 34 /// default constructor 35 TriggerManager(); 36 37 /// destructor 38 virtual ~TriggerManager(); 39 40 /** 41 Save all triggers to stream 42 \param stream the stream to save to 43 */ 44 void save(OutputStream& stream) const; 45 46 /** 47 Load triggers from stream. 48 \param stream the stream to load from 49 */ 50 void load(InputStream& stream); 51 52 /** 53 Triggers all triggers at CycleNumber 54 \param CycleNumber the current game cycle 55 */ 56 void trigger(Uint32 CycleNumber); 57 58 /** 59 Add a trigger to the trigger manager. 60 \param newTrigger shared pointer to the new trigger 61 */ 62 void addTrigger(std::shared_ptr<Trigger> newTrigger); 63 64 /** 65 This method returns a list of all the managed triggers. 66 \return a list of all the triggers 67 */ getTriggers()68 const std::list<std::shared_ptr<Trigger> >& getTriggers() const { return triggers; }; 69 70 private: 71 std::list<std::shared_ptr<Trigger> > triggers; ///< list of all triggers. sorted by the time when they shall be triggered. 72 73 typedef enum { 74 Type_ReinforcementTrigger = 1, ///< the trigger is of type ReinforcementTrigger 75 Type_TimeoutTrigger = 2 ///< the trigger is of type TimeoutTrigger 76 } TriggerType; 77 78 /** 79 Helper method for saving one trigger. 80 \param stream the stream to save to 81 \param t shared pointer to the trigger to save 82 */ 83 void saveTrigger(OutputStream& stream, const std::shared_ptr<Trigger>& t) const; 84 85 /** 86 Helper method for loading one trigger 87 \param stream stream to load from 88 \return a shared pointer to the loaded trigger 89 */ 90 std::shared_ptr<Trigger> loadTrigger(InputStream& stream); 91 }; 92 93 #endif // TRIGGERMANAGER_H 94