00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "Root.h"
00023 #include "ParseNode.h"
00024 #include "BaseClasses.h"
00025 #include "Ingredients.h"
00026 #include "Engine.h"
00027 #include "Logging.h"
00028
00029
00030 void MHRoot::Initialise(MHParseNode *p, MHEngine *engine)
00031 {
00032 MHParseNode *pArg = p->GetArgN(0);
00033
00034 m_ObjectReference.Initialise(pArg, engine);
00035 }
00036
00037
00038 void MHRoot::PrintMe(FILE *fd, int nTabs) const
00039 {
00040 m_ObjectReference.PrintMe(fd, nTabs);
00041 fprintf(fd, "\n");
00042 }
00043
00044
00045 void MHRoot::InvalidAction(const char *actionName)
00046 {
00047 MHLOG(MHLogWarning, QString("Action \"%1\" is not understood by class \"%2\"").arg(actionName).arg(ClassName()));
00048 throw "Invalid Action";
00049 }
00050
00051
00052 void MHRoot::Preparation(MHEngine *engine)
00053 {
00054 if (m_fAvailable)
00055 {
00056 return;
00057 }
00058
00059
00060
00061 m_fAvailable = true;
00062 engine->EventTriggered(this, EventIsAvailable);
00063
00064
00065 ContentPreparation(engine);
00066 }
00067
00068
00069 void MHRoot::Activation(MHEngine *engine)
00070 {
00071 if (m_fRunning)
00072 {
00073 return;
00074 }
00075
00076 if (! m_fAvailable)
00077 {
00078 Preparation(engine);
00079 }
00080
00081
00082 }
00083
00084
00085 void MHRoot::Deactivation(MHEngine *engine)
00086 {
00087 if (! m_fRunning)
00088 {
00089 return;
00090 }
00091
00092 m_fRunning = false;
00093 engine->EventTriggered(this, EventIsStopped);
00094 }
00095
00096
00097 void MHRoot::Destruction(MHEngine *engine)
00098 {
00099 if (! m_fAvailable)
00100 {
00101 return;
00102 }
00103
00104 if (m_fRunning)
00105 {
00106 Deactivation(engine);
00107 }
00108
00109
00110 m_fAvailable = false;
00111 engine->EventTriggered(this, EventIsDeleted);
00112 }
00113
00114
00115 MHRoot *MHRoot::FindByObjectNo(int n)
00116 {
00117 if (n == m_ObjectReference.m_nObjectNo)
00118 {
00119 return this;
00120 }
00121 else
00122 {
00123 return NULL;
00124 }
00125 }
00126
00127 void MHGetAvailabilityStatus::Initialise(MHParseNode *p, MHEngine *engine)
00128 {
00129 MHElemAction::Initialise(p, engine);
00130 m_ResultVar.Initialise(p->GetArgN(1), engine);
00131 }
00132
00133 void MHGetAvailabilityStatus::Perform(MHEngine *engine)
00134 {
00135
00136 MHObjectRef target;
00137 m_Target.GetValue(target, engine);
00138 MHRoot *pObject = engine->FindObject(target, false);
00139 bool fResult = false;
00140
00141 if (pObject)
00142 {
00143 fResult = pObject->GetAvailabilityStatus();
00144 }
00145
00146 engine->FindObject(m_ResultVar)->SetVariableValue(fResult);
00147 }