00001 /* Link.h 00002 00003 Copyright (C) David C. J. Matthews 2004 dm at prolingua.co.uk 00004 00005 This program is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU General Public License 00007 as published by the Free Software Foundation; either version 2 00008 of the License, or (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 Or, point your browser to http://www.gnu.org/copyleft/gpl.html 00019 00020 */ 00021 00022 #if !defined(LINK_H) 00023 #define LINK_H 00024 00025 #include "Ingredients.h" 00026 #include "Root.h" 00027 #include "BaseClasses.h" 00028 #include "Actions.h" 00029 #include "BaseActions.h" 00030 00031 #include <QString> 00032 00033 class MHParseNode; 00034 00035 // Link - basically a guarded command. 00036 class MHLink : public MHIngredient 00037 { 00038 public: 00039 MHLink(); 00040 virtual const char *ClassName() { return "Link"; } 00041 virtual void Initialise(MHParseNode *p, MHEngine *engine); // Set this up from the parse tree. 00042 virtual void PrintMe(FILE *fd, int nTabs) const; 00043 // Look up the event type. Returns zero if it doesn't match. 00044 static int GetEventType(const char *str); 00045 // Print an event type. 00046 static QString EventTypeToString(enum EventType ev); 00047 00048 // Internal behaviours. 00049 virtual void Activation(MHEngine *engine); 00050 virtual void Deactivation(MHEngine *engine); 00051 00052 // Handle activation and deactivation 00053 virtual void Activate(bool f, MHEngine *engine); 00054 // Called when an event has been triggered and fires this link if it matches. 00055 virtual void MatchEvent(const MHObjectRef &sourceRef, enum EventType ev, const MHUnion &un, MHEngine *engine); 00056 00057 protected: 00058 MHObjectRef m_EventSource; 00059 enum EventType m_nEventType; 00060 MHUnion m_EventData; 00061 MHActionSequence m_LinkEffect; 00062 }; 00063 00064 // Actions. 00065 // Activate and deactivate actions. 00066 class MHActivate: public MHElemAction 00067 { 00068 public: 00069 MHActivate(const char *name, bool fActivate): MHElemAction(name), m_fActivate(fActivate) {} 00070 virtual void Perform(MHEngine *engine) { Target(engine)->Activate(m_fActivate, engine); } 00071 protected: 00072 bool m_fActivate; 00073 }; 00074 00075 #endif
1.6.3