Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2651
Modified Files:
ChangeLog basedef.cpp basedef.h
Log Message:
Carve
Index: ChangeLog
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/ChangeLog,v
retrieving revision 1.70
retrieving revision 1.71
diff -C2 -d -r1.70 -r1.71
*** ChangeLog 20 Sep 2004 14:54:03 -0000 1.70
--- ChangeLog 21 Sep 2004 05:28:04 -0000 1.71
***************
*** 40,43 ****
--- 40,47 ----
- Console will show which unicode format was compiled in Python UCS2 or UCS4
- Fixed compile error on FreeBSD.
+ - Exposed the base definition class to python.
+ - Added wolfpack.bodyinfo(id)
+ - Added/Changed wolfpack.itembase(def), wolfpack.charbase(def)
+ - Fixed a base definition bug related to property not loading the base definition.
Wolfpack 12.9.10 Beta (10. September 2004)
Index: basedef.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basedef.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** basedef.cpp 19 Sep 2004 23:41:00 -0000 1.21
--- basedef.cpp 21 Sep 2004 05:28:04 -0000 1.22
***************
*** 493,494 ****
--- 493,683 ----
}
}
+
+ // Python Interface
+ const char* cBaseDef::className() const {
+ return "basedef";
+ }
+
+ bool cBaseDef::implements( const QString& name ) const {
+ if (name == "basedef") {
+ return true;
+ } else {
+ return cPythonScriptable::implements(name);
+ }
+ }
+
+ /*
+ \object basedef
+ \description This object type reprsents the base definitions of items and characters.
+ */
+ struct wpBasedef
+ {
+ PyObject_HEAD;
+ cBaseDef* basedef;
+ };
+
+ static PyObject* wpBasedef_getAttr( wpBasedef* self, char* name );
+ static int wpBasedef_compare( PyObject* a, PyObject* b );
+
+ PyTypeObject wpBasedefType =
+ {
+ PyObject_HEAD_INIT( NULL )
+ 0,
+ "basedef",
+ sizeof( wpBasedefType ),
+ 0,
+ wpDealloc,
+ 0,
+ ( getattrfunc ) wpBasedef_getAttr,
+ 0,
+ wpBasedef_compare,
+ 0,
+ };
+
+ /*
+ \method basedef.getintproperty
+ \description Get an integer property from this definition.
+ \param name The name of the property. This name is not case sensitive.
+ \param default The default value that is returned if this property doesnt
+ exist. Defaults to 0.
+ \return The property value or the given default value.
+ */
+ PyObject *wpBasedef_getintproperty(wpBasedef *self, PyObject *args) {
+ unsigned int def = 0;
+ PyObject *pyname;
+
+ if (!PyArg_ParseTuple(args, "O|i:basedef.getintproperty(name, def)", &pyname, &def)) {
+ return 0;
+ }
+
+ QString name = Python2QString(pyname);
+ return PyInt_FromLong( self->basedef->getIntProperty( name, def ) );
+ }
+
+ /*
+ \method basedef.getstrproperty
+ \description Get a string property from this definition.
+ \param name The name of the property. This name is not case sensitive.
+ \param default The default value that is returned if this property doesnt
+ exist. Defaults to an empty string.
+ \return The property value or the given default value.
+ */
+ static PyObject* wpBasedef_getstrproperty( wpBasedef* self, PyObject* args )
+ {
+ PyObject *pydef = 0;
+ PyObject *pyname;
+
+ if (!PyArg_ParseTuple(args, "O|O:basedef.getstrproperty(name, def)", &pyname, &pydef)) {
+ return 0;
+ }
+
+ QString name = Python2QString(pyname);
+ QString def = Python2QString(pydef);
+
+ return QString2Python( self->basedef->getStrProperty( name, def ) );
+ }
+
+ /*
+ \method basedef.hasstrproperty
+ \description Checks if this definition has a string property with the given name.
+ \param name The name of the property. This name is not case sensitive.
+ \return True if the definition has the property, False otherwise.
+ */
+ static PyObject* wpBasedef_hasstrproperty( wpBasedef* self, PyObject* args )
+ {
+ PyObject *pyname;
+
+ if (!PyArg_ParseTuple(args, "O:char.hasstrproperty(name)", &pyname)) {
+ return 0;
+ }
+
+ QString name = Python2QString(pyname);
+
+ if (self->basedef->hasStrProperty(name)) {
+ Py_RETURN_TRUE;
+ } else {
+ Py_RETURN_FALSE;
+ }
+ }
+
+ /*
+ \method basedef.hasintproperty
+ \description Checks if this definition has an integer property with the given name.
+ \param name The name of the property. This name is not case sensitive.
+ \return True if the definition has the property, False otherwise.
+ */
+ static PyObject* wpBasedef_hasintproperty( wpBasedef* self, PyObject* args )
+ {
+ PyObject *pyname;
+
+ if (!PyArg_ParseTuple(args, "O:basedef.hasintproperty(name)", &pyname)) {
+ return 0;
+ }
+
+ QString name = Python2QString(pyname);
+
+ if (self->basedef->hasIntProperty(name)) {
+ Py_RETURN_TRUE;
+ } else {
+ Py_RETURN_FALSE;
+ }
+ }
+
+ static PyMethodDef wpBasedefMethods[] = {
+ {"getintproperty", ( getattrofunc ) wpBasedef_getintproperty, METH_VARARGS, 0},
+ {"getstrproperty", ( getattrofunc ) wpBasedef_getstrproperty, METH_VARARGS, 0},
+ {"hasintproperty", ( getattrofunc ) wpBasedef_hasintproperty, METH_VARARGS, 0},
+ {"hasstrproperty", ( getattrofunc ) wpBasedef_hasstrproperty, METH_VARARGS, 0},
+ {0, 0, 0, 0}
+ };
+
+ PyObject* cBaseDef::getPyObject() {
+ wpBasedef * returnVal = PyObject_New( wpBasedef, &wpBasedefType );
+ returnVal->basedef = this;
+ return ( PyObject * ) returnVal;
+ }
+
+ static PyObject* wpBasedef_getAttr( wpBasedef* self, char* name ) {
+ PyObject *result = self->basedef->getProperty( name );
+
+ if (result) {
+ return result;
+ }
+
+ return Py_FindMethod( wpBasedefMethods, (PyObject*) self, name );
+ }
+
+ static int wpBasedef_compare( PyObject* a, PyObject* b )
+ {
+ if ( a->ob_type != &wpBasedefType || b->ob_type != &wpBasedefType )
+ return -1;
+
+ return !( ( ( wpBasedef * ) a )->basedef == ( ( wpBasedef * ) b )->basedef );
+ }
+
+ PyObject* cBaseDef::getProperty( const QString& name ) {
+ PY_PROPERTY("id", id()) // \rproperty basedef.id The definition id of this base definition.
+ PY_PROPERTY("basescripts", baseScriptList()) // \rproperty basedef.basescripts The names of all basescripts assigned to this base definition.
+ PY_PROPERTY("bindmenu", bindmenu()) // \rproperty basedef.bindmenu The id of the context menu assigned to this base definition.
+ return cPythonScriptable::getProperty(name);
+ }
+
+ PyObject *cCharBaseDef::getProperty( const QString& name ) {
+ PY_PROPERTY("controlslots", controlSlots()) // \rproperty basedef.controlslots The amount of controlslots consumed by this npc.
+ PY_PROPERTY("criticalhealth", criticalHealth()) // \rproperty basedef.criticalhealth The percentage of health this NPC will start fleeing at.
+ PY_PROPERTY("mindamage", minDamage()) // \rproperty basedef.mindamage The mindamage for this npc.
+ PY_PROPERTY("mintaming", minTaming()) // \rproperty basedef.mintaming The minimum taming skill required for this npc.
+ PY_PROPERTY("lootpacks", lootPacks()) // \rproperty basedef.lootpacks The lootpacks for this npc.
+ return cBaseDef::getProperty(name);
+ }
+
+ PyObject *cItemBaseDef::getProperty( const QString& name ) {
+ PY_PROPERTY("decaydelay", decaydelay()) // \rproperty basedef.decaydelay The delay until this item will decay when its dropped to ground.
+ PY_PROPERTY("weight", weight()) // \rproperty basedef.weight The weight of this item.
+ PY_PROPERTY("sellprice", sellprice()) // \rproperty basedef.sellprice The sellprice of this item.
+ PY_PROPERTY("buyprice", buyprice()) // \rproperty basedef.buyprice The buyprice for this item.
+ PY_PROPERTY("type", type()) // \rproperty basedef.type The type of this item.
+ PY_PROPERTY("lightsource", lightsource()) // \rproperty.lightsource The lightmap id for this item.
+ PY_PROPERTY("watersource", isWaterSource()) // \rproperty.watersource Indicates whether this item is a source of water.
+ return cBaseDef::getProperty(name);
+ }
Index: basedef.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basedef.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** basedef.h 14 Sep 2004 00:00:37 -0000 1.17
--- basedef.h 21 Sep 2004 05:28:04 -0000 1.18
***************
*** 31,34 ****
--- 31,35 ----
#include "definable.h"
#include "singleton.h"
+ #include "pythonscript.h"
#include <qmap.h>
#include <qptrlist.h>
***************
*** 39,43 ****
class cPythonScript;
! class cBaseDef : public cDefinable {
protected:
// Our id
--- 40,44 ----
class cPythonScript;
! class cBaseDef : public cDefinable, public cPythonScriptable {
protected:
// Our id
***************
*** 59,62 ****
--- 60,64 ----
inline unsigned int getIntProperty(const QString &name, unsigned int def = 0) {
+ load();
QMap<QString, unsigned int>::const_iterator it = intproperties.find(name);
if (it == intproperties.end()) {
***************
*** 68,75 ****
--- 70,79 ----
inline bool hasIntProperty(const QString &name) {
+ load();
return intproperties.contains(name);
}
inline const QString &getStrProperty(const QString &name, const QString &def = QString::null) {
+ load();
QMap<QString, QString>::const_iterator it = properties.find(name);
if (it == properties.end()) {
***************
*** 81,84 ****
--- 85,89 ----
inline bool hasStrProperty(const QString &name) {
+ load();
return properties.contains(name);
}
***************
*** 106,109 ****
--- 111,120 ----
return bindmenu_;
}
+
+ // Python Scriptable
+ const char* className() const;
+ PyObject* getPyObject();
+ bool implements(const QString& name) const;
+ PyObject *getProperty( const QString& name );
};
***************
*** 193,196 ****
--- 204,209 ----
return lootPacks_;
}
+
+ PyObject *getProperty( const QString& name );
};
***************
*** 323,326 ****
--- 336,341 ----
return ( flags_ & 0x01 ) != 0;
}
+
+ PyObject *getProperty( const QString& name );
};
|