TRIGGER.H (9644B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 /* $Header: F:\projects\c&c\vcs\code\trigger.h_v 2.15 16 Oct 1995 16:46:32 JOE_BOSTIC $ */ 17 /*********************************************************************************************** 18 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S *** 19 *********************************************************************************************** 20 * * 21 * Project Name : Command & Conquer * 22 * * 23 * File Name : TRIGGER.H * 24 * * 25 * Programmer : Joe L. Bostic * 26 * * 27 * Start Date : 11/12/94 * 28 * * 29 * Last Update : November 12, 1994 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 34 35 #ifndef TRIGGER_H 36 #define TRIGGER_H 37 38 typedef enum EventType : char { 39 EVENT_NONE=-1, 40 41 /* 42 .......................... Cell-specific events .......................... 43 */ 44 EVENT_PLAYER_ENTERED, // player enters this square 45 EVENT_CELLFIRST = EVENT_PLAYER_ENTERED, 46 47 /* 48 ......................... Object-specific events ......................... 49 */ 50 EVENT_DISCOVERED, // player discovers this object 51 EVENT_OBJECTFIRST = EVENT_DISCOVERED, 52 EVENT_ATTACKED, // player attacks this object 53 EVENT_DESTROYED, // player destroys this object 54 EVENT_ANY, // Any object event will cause the trigger. 55 56 /* 57 ......................... House-specific events .......................... 58 */ 59 EVENT_HOUSE_DISCOVERED, // any object in this house discovered 60 EVENT_HOUSEFIRST = EVENT_HOUSE_DISCOVERED, 61 EVENT_UNITS_DESTROYED, // all house's units destroyed 62 EVENT_BUILDINGS_DESTROYED, // all house's buildings destroyed 63 EVENT_ALL_DESTROYED, // all house's units & buildings destroyed 64 EVENT_CREDITS, // house reaches this many credits 65 EVENT_TIME, // time elapses for this house 66 EVENT_NBUILDINGS_DESTROYED, // Number of buildings destroyed. 67 EVENT_NUNITS_DESTROYED, // Number of units destroyed. 68 EVENT_NOFACTORIES, // No factories left. 69 EVENT_EVAC_CIVILIAN, // Civilian has been evacuated. 70 EVENT_BUILD, // If specified building has been built. 71 72 EVENT_COUNT, 73 EVENT_FIRST=0 74 } EventType; 75 76 77 class TriggerClass { 78 public: 79 typedef enum ActionType { 80 ACTION_NONE=-1, 81 82 ACTION_WIN, // player wins! 83 ACTION_LOSE, // player loses. 84 ACTION_BEGIN_PRODUCTION, // computer begins production 85 ACTION_CREATE_TEAM, // computer creates a certain type of team 86 ACTION_DESTROY_TEAM, 87 ACTION_ALL_HUNT, // all enemy units go into hunt mode (teams destroyed). 88 ACTION_REINFORCEMENTS, // player gets reinforcements 89 // (house that gets them is determined by 90 // the Reinforcement instance) 91 ACTION_DZ, // Deploy drop zone smoke. 92 ACTION_AIRSTRIKE, // Enable airstrike. 93 ACTION_NUKE, // Enable nuke for computer. 94 ACTION_ION, // Give ion cannon to computer. 95 ACTION_DESTROY_XXXX, // Destroy trigger XXXX. 96 ACTION_DESTROY_YYYY, // Destroy trigger YYYY. 97 ACTION_DESTROY_ZZZZ, // Destroy trigger ZZZZ. 98 ACTION_AUTOCREATE, // Computer to autocreat teams. 99 ACTION_WINLOSE, // Win if captured, lose if destroyed. 100 ACTION_ALLOWWIN, // Allows winning if triggered. 101 102 ACTION_COUNT, 103 ACTION_FIRST=0 104 } ActionType; 105 106 typedef enum PersistantType { 107 VOLATILE = 0, 108 SEMIPERSISTANT = 1, 109 PERSISTANT = 2, 110 } PersistantType; 111 112 /* 113 ** Functions: 114 ** 115 ** Constructor/Destructor 116 */ 117 TriggerClass(void); 118 ~TriggerClass(void); 119 120 /* 121 ** Initialization: clears all triggers in preparation for new scenario 122 */ 123 static void Init(void); 124 125 /* 126 ** Processing routines 127 */ 128 bool Spring(EventType event, ObjectClass * object); // object-based 129 bool Spring(EventType event, CELL cell); // cell-based 130 bool Spring(EventType event, HousesType house, long data=0); // house-based 131 bool Remove(void); 132 133 /* 134 ** File I/O routines 135 */ 136 static void Read_INI (char *buffer); 137 void Fill_In(char *name, char *entry); 138 static void Write_INI (char *buffer, bool refresh); 139 static char * INI_Name(void) {return "Triggers";}; 140 bool Load(FileClass & file); 141 bool Save(FileClass & file); 142 void Code_Pointers(void); 143 void Decode_Pointers(void); 144 145 /* 146 ** As_Pointer gets a pointer to the trigger object give the mnemonic 147 */ 148 static TriggerClass * As_Pointer(char const * name); 149 150 /* 151 ** Data Access routines 152 */ 153 // EventType Get_Event(void) const {return (Event);} 154 // void Set_Event(EventType event) {Event = event;} 155 // ActionType Get_Action(void) const {return (Action);} 156 // void Set_Action(ActionType action) {Action = action;} 157 // HousesType Get_House(void) const {return(House);} 158 // void Set_House(HousesType house) {House = house;} 159 // long Get_Data(void) const {return(Data);} 160 // void Set_Data(long credits) {Data = credits;} 161 char const * Get_Name(void) const {return (Name);} 162 void Set_Name(char const *buf) {strncpy(Name, buf, sizeof(Name)); Name[sizeof(Name)-1] = '\0';} 163 164 /* 165 ** Utility routines 166 */ 167 TARGET As_Target(void) const; 168 static bool Event_Need_Object(EventType event); 169 static bool Event_Need_House(EventType event); 170 static bool Event_Need_Data(EventType event); 171 static bool Action_Need_Team(ActionType action); 172 static EventType Event_From_Name(char const *name); 173 static char const *Name_From_Event(EventType event); 174 static ActionType Action_From_Name(char const *name); 175 static char const *Name_From_Action(ActionType action); 176 177 /* 178 ** Overloaded operators 179 */ 180 static void * operator new(size_t size); 181 static void operator delete(void *ptr); 182 183 /* 184 ** Dee-buggin' support. 185 */ 186 int Validate(void) const; 187 188 /* 189 ** This is the pointer to the team that gets created or destroyed when 190 ** a team-related trigger goes off, or for reinforcements. The house 191 ** for reinforcements is determined by the house for that team. 192 */ 193 TeamTypeClass *Team; 194 195 /* 196 ** If this trigger object is active, then this flag will be true. Trigger 197 ** objects that are not active are either not yet created or have been 198 ** deleted after fulfilling their action. 199 */ 200 unsigned IsActive:1; 201 202 /* 203 ** This flag controls whether the trigger destroys itself after it goes 204 ** off. 205 ** 0 = trigger destroys itself immediately after going off, and removes 206 ** itself from all objects it's attached to 207 ** 1 = trigger is "Semi-Persistent"; it maintains a count of all objects 208 ** it's attached to, and only actually "springs" after its been 209 ** triggered from all the objects; then, it removes itself. 210 ** 2 = trigger is Fully Persistent; it just won't go away. 211 */ 212 PersistantType IsPersistant; 213 214 /* 215 ** This value tells how many objects or cells this trigger is attached 216 ** to. The Read_INI routine for all classes that point to a trigger must 217 ** increment this value! 218 */ 219 int AttachCount; 220 221 /* 222 ** Each trigger must have an event which activates it. This is the event that is 223 ** used to activate this trigger. 224 */ 225 EventType Event; 226 227 /* 228 ** This is the action to perform when the trigger event occurs. 229 */ 230 ActionType Action; 231 232 /* 233 ** For house-specific events, this is the house for that event. 234 */ 235 HousesType House; 236 237 /* 238 ** For credit-related triggers, this is the number of credits that 239 ** generate the trigger. For time-based triggers, this is the number 240 ** of minutes that must elapse. 241 */ 242 long Data; 243 long DataCopy; 244 245 private: 246 247 /* 248 ** Triggers can be referred to by their name, which can be up to 4 249 ** characters. 250 */ 251 char Name[5]; 252 253 /* 254 ** Some additional padding in case we need to add data to the class and maintain backwards compatibility for save/load 255 */ 256 unsigned char SaveLoadPadding[32]; 257 258 }; 259 260 261 #endif