1 /* 2 Copyright © 2013 Igor Paliychuk 3 Copyright © 2013-2016 Justin Jacobs 4 5 This file is part of FLARE. 6 7 FLARE is free software: you can redistribute it and/or modify it under the terms 8 of the GNU General Public License as published by the Free Software Foundation, 9 either version 3 of the License, or (at your option) any later version. 10 11 FLARE is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 13 PARTICULAR PURPOSE. See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License along with 16 FLARE. If not, see http://www.gnu.org/licenses/ 17 */ 18 19 /* 20 * class EventManager 21 */ 22 23 #ifndef EVENT_MANAGER_H 24 #define EVENT_MANAGER_H 25 26 #include "CommonIncludes.h" 27 #include "Utils.h" 28 29 class FileParser; 30 31 class EventComponent { 32 public: 33 enum { 34 NONE = 0, 35 TOOLTIP = 1, 36 POWER_PATH = 2, 37 POWER_DAMAGE = 3, 38 INTERMAP = 4, 39 INTRAMAP = 5, 40 MAPMOD = 6, 41 SOUNDFX = 7, 42 LOOT = 8, 43 LOOT_COUNT = 9, 44 MSG = 10, 45 SHAKYCAM = 11, 46 REQUIRES_STATUS = 12, 47 REQUIRES_NOT_STATUS = 13, 48 REQUIRES_LEVEL = 14, 49 REQUIRES_NOT_LEVEL = 15, 50 REQUIRES_CURRENCY = 16, 51 REQUIRES_NOT_CURRENCY = 17, 52 REQUIRES_ITEM = 18, 53 REQUIRES_NOT_ITEM = 19, 54 REQUIRES_CLASS = 20, 55 REQUIRES_NOT_CLASS = 21, 56 SET_STATUS = 22, 57 UNSET_STATUS = 23, 58 REMOVE_CURRENCY = 24, 59 REMOVE_ITEM = 25, 60 REWARD_XP = 26, 61 REWARD_CURRENCY = 27, 62 REWARD_ITEM = 28, 63 REWARD_LOOT = 29, 64 REWARD_LOOT_COUNT = 30, 65 RESTORE = 31, 66 POWER = 32, 67 SPAWN = 33, 68 STASH = 34, 69 NPC = 35, 70 MUSIC = 36, 71 CUTSCENE = 37, 72 REPEAT = 38, 73 SAVE_GAME = 39, 74 BOOK = 40, 75 SCRIPT = 41, 76 CHANCE_EXEC = 42, 77 RESPEC = 43, 78 SHOW_ON_MINIMAP = 44, 79 PARALLAX_LAYERS = 45, 80 NPC_ID = 46, 81 NPC_HOTSPOT = 47, 82 NPC_DIALOG_THEM = 48, 83 NPC_DIALOG_YOU = 49, 84 NPC_VOICE = 50, 85 NPC_DIALOG_TOPIC = 51, 86 NPC_DIALOG_GROUP = 52, 87 NPC_DIALOG_ID = 53, 88 NPC_DIALOG_RESPONSE = 54, 89 NPC_DIALOG_RESPONSE_ONLY = 55, 90 NPC_ALLOW_MOVEMENT = 56, 91 NPC_PORTRAIT_THEM = 57, 92 NPC_PORTRAIT_YOU = 58, 93 QUEST_TEXT = 59, 94 WAS_INSIDE_EVENT_AREA = 60, 95 NPC_TAKE_A_PARTY = 61 96 }; 97 98 int type; 99 std::string s; 100 StatusID status; 101 int x; 102 int y; 103 int z; 104 int a; 105 int b; 106 int c; 107 float f; 108 size_t id; 109 EventComponent()110 EventComponent() 111 : type(NONE) 112 , s("") 113 , status(0) 114 , x(0) 115 , y(0) 116 , z(0) 117 , a(0) 118 , b(0) 119 , c(0) 120 , f(0) 121 , id(0) { 122 } 123 }; 124 125 class Event { 126 public: 127 enum { 128 ACTIVATE_ON_TRIGGER = 0, 129 ACTIVATE_ON_INTERACT = 1, 130 ACTIVATE_ON_MAPEXIT = 2, 131 ACTIVATE_ON_LEAVE = 3, 132 ACTIVATE_ON_LOAD = 4, 133 ACTIVATE_ON_CLEAR = 5, 134 ACTIVATE_STATIC = 6 135 }; 136 137 std::string type; 138 int activate_type; 139 std::vector<EventComponent> components; 140 Rect location; 141 Rect hotspot; 142 Timer cooldown; // events that run multiple times pause this long in frames 143 Timer delay; 144 bool keep_after_trigger; // if this event has been triggered once, should this event be kept? If so, this event can be triggered multiple times. 145 FPoint center; 146 Rect reachable_from; 147 148 Event(); 149 ~Event(); 150 151 EventComponent* getComponent(const int _type); 152 void deleteAllComponents(const int _type); 153 }; 154 155 class EventManager { 156 public: 157 EventManager(); 158 ~EventManager(); 159 static void loadEvent(FileParser &infile, Event* evnt); 160 static void loadEventComponent(FileParser &infile, Event* evnt, EventComponent* ec); 161 static bool loadEventComponentString(std::string &key, std::string &val, Event* evnt, EventComponent* ec); 162 163 static bool executeEvent(Event &e); 164 static bool executeDelayedEvent(Event &e); 165 static bool isActive(const Event &e); 166 static void executeScript(const std::string& filename, float x, float y); 167 168 private: 169 static const bool SKIP_DELAY = true; 170 static bool executeEventInternal(Event &e, bool skip_delay); 171 static EventComponent getRandomMapFromFile(const std::string& fname); 172 173 }; 174 175 176 #endif 177