00001 #ifndef __KX_ILOGICBRICK
00002 #define __KX_ILOGICBRICK
00003
00004 #include "Value.h"
00005 #include "SCA_IObject.h"
00006 #include "BoolValue.h"
00007 class SCA_ILogicBrick : public CValue
00008 {
00009 Py_Header;
00010 int m_Execute_Priority;
00011 int m_Execute_Ueber_Priority;
00012
00013 CValue* m_eventval;
00014 bool m_bActive;
00015 CCString m_text;
00016 CCString m_name;
00017
00018 SCA_IObject* m_gameobj;
00019 protected:
00020
00021
00022
00023 void RegisterEvent(CValue* eventval) {
00024 if (m_eventval)
00025 m_eventval->Release();
00026 m_eventval = eventval->AddRef();
00027 }
00028 void RemoveEvent()
00029 {
00030 if (m_eventval) {
00031 m_eventval->Release();
00032 m_eventval=NULL;
00033 }
00034
00035 }
00036
00037 CValue* GetEvent()
00038 {
00039 if (m_eventval)
00040 {
00041 return m_eventval->AddRef();
00042 }
00043 return NULL;
00044 }
00045 public:
00046 SCA_ILogicBrick(SCA_IObject* gameobj,PyTypeObject* T ) :
00047 CValue(T), m_gameobj(gameobj),m_Execute_Priority(0),m_Execute_Ueber_Priority(0),m_bActive(false),m_eventval(0) {
00048 m_text = "KX_LogicBrick";
00049 }
00050
00051 virtual ~SCA_ILogicBrick()
00052 {
00053 RemoveEvent();
00054 }
00055
00056
00057 void SetExecutePriority(int execute_Priority)
00058 {
00059 m_Execute_Priority = execute_Priority;
00060 }
00061 void SetUeberExecutePriority(int execute_Priority)
00062 {
00063 m_Execute_Ueber_Priority = execute_Priority;
00064 }
00065
00066
00067
00068 SCA_IObject* GetParent() { return m_gameobj;}
00069 virtual void ReParent(SCA_IObject* parent) { m_gameobj = parent;}
00070
00071
00072 virtual CValue* Calc(VALUE_OPERATOR op, CValue *val) {
00073 CValue* temp = new CBoolValue(false,"");
00074 CValue* result = temp->Calc(op,val);
00075 temp->Release();
00076 return result;
00077 };
00078 virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) {
00079
00080 CValue* temp = new CBoolValue(false,"");
00081 CValue* result = temp->CalcFinal(dtype,op,val);
00082 temp->Release();
00083 return result;
00084 }
00085
00086 virtual const CCString & GetText() {
00087 if (m_name.Length())
00088 return m_name;
00089 return m_text;
00090 };
00091 virtual float GetNumber() {return -1;};
00092 virtual CCString GetName() { return m_name;}
00093 virtual void SetName(CCString name) { m_name = name;};
00094 virtual void ReplicaSetName(CCString name) {m_name = name;};
00095
00096
00097 bool IsActive() {return m_bActive;}
00098 void SetActive(bool active) ;
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 virtual PyObject* _getattr(char *attr);
00122
00123 static class SCA_LogicManager* m_sCurrentLogicManager;
00124
00125 PyObject* PyGetOwner(PyObject* self,
00126 PyObject* args,
00127 PyObject* kwds)
00128 {
00129 CValue* parent = GetParent();
00130 if (parent)
00131 {
00132 parent->AddRef();
00133 return parent;
00134 }
00135
00136 printf("ERROR: Python scriptblock without owner\n");
00137 Py_INCREF(Py_None);
00138 return Py_None;
00139 }
00140 static PyObject* sPyGetOwner(PyObject* self,
00141 PyObject* args,
00142 PyObject* kwds)
00143 {
00144
00145 return ((SCA_ILogicBrick*) self)->PyGetOwner(self, args, kwds);
00146 }
00147
00148 enum KX_BOOL_TYPE {
00149 KX_BOOL_NODEF = 0,
00150 KX_TRUE,
00151 KX_FALSE,
00152 KX_BOOL_MAX
00153 };
00154
00155 };
00156
00157
00158
00159
00160
00161
00162
00163 struct SCACompare {
00164
00165 bool operator() (const SCA_ILogicBrick* i1, const SCA_ILogicBrick* i2) const {
00166 return (i1->m_Execute_Ueber_Priority <
00167 i2->m_Execute_Ueber_Priority) || ((i1->m_Execute_Ueber_Priority == i2->m_Execute_Ueber_Priority) &&
00168 (i1->m_Execute_Priority < i2->m_Execute_Priority));
00169 }
00170 };
00171
00172
00173 #endif