Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1813
Modified Files:
ChangeLog basedef.cpp basedef.h
Log Message:
Added basedef properties.
Index: ChangeLog
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/ChangeLog,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** ChangeLog 5 Sep 2004 14:08:21 -0000 1.31
--- ChangeLog 5 Sep 2004 17:43:51 -0000 1.32
***************
*** 11,14 ****
--- 11,19 ----
- Fixed a bug where an error message for missing python gump
callbacks led to a crash.
+ - Added a property system bound to the definitions.
+ <intproperty name="..." value="..." /> and
+ <strproperty name="..." value="..." /> define properties that can be
+ accessed via the methods getstrproperty, getintproperty, hasstrproperty,
+ hasintproperty from items and chars.
Wolfpack 12.9.9 Beta (4. September 2004)
Index: basedef.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basedef.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** basedef.cpp 29 Aug 2004 16:39:30 -0000 1.15
--- basedef.cpp 5 Sep 2004 17:43:51 -0000 1.16
***************
*** 34,37 ****
--- 34,74 ----
#include <string.h>
+ void cBaseDef::processNode( const cElement* node ) {
+ if (node->name() == "intproperty") {
+ QString name = node->getAttribute("name");
+ if (!name.isEmpty()) {
+ QString value = node->getAttribute("value");
+ if (value.isNull()) {
+ value = node->text();
+ }
+ value = hex2dec(value); // Convert hexadecimal numbers accordingly
+
+ bool ok;
+ unsigned int intvalue = value.toInt(&ok);
+
+ if (!ok) {
+ Console::instance()->log(LOG_WARNING, QString("Basedef %1 has invalid integer property %2.\n").arg(id_).arg(name));
+ }
+
+ intproperties.insert(name.lower(), intvalue, true);
+ }
+ } else if (node->name() == "strproperty") {
+ QString name = node->getAttribute("name");
+ if (!name.isEmpty()) {
+ QString value = node->getAttribute("value");
+ if (value.isNull()) {
+ value = node->text();
+ }
+ properties.insert(name.lower(), value, true);
+ }
+ }
+ }
+
+ void cBaseDef::reset() {
+ loaded = false;
+ intproperties.clear();
+ properties.clear();
+ }
+
cCharBaseDef::cCharBaseDef( const QCString& id )
{
***************
*** 46,50 ****
void cCharBaseDef::reset()
{
! loaded = false;
basesound_ = 0;
soundmode_ = 0;
--- 83,87 ----
void cCharBaseDef::reset()
{
! cBaseDef::reset();
basesound_ = 0;
soundmode_ = 0;
***************
*** 121,124 ****
--- 158,165 ----
refreshScripts();
}
+ else
+ {
+ cBaseDef::processNode(node);
+ }
}
***************
*** 218,222 ****
void cItemBaseDef::reset()
{
! loaded = false;
weight_ = 0.0f;
decaydelay_ = 0;
--- 259,263 ----
void cItemBaseDef::reset()
{
! cBaseDef::reset();
weight_ = 0.0f;
decaydelay_ = 0;
***************
*** 281,284 ****
--- 322,329 ----
refreshScripts();
}
+ else
+ {
+ cBaseDef::processNode(node);
+ }
}
Index: basedef.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basedef.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** basedef.h 27 Aug 2004 14:41:15 -0000 1.12
--- basedef.h 5 Sep 2004 17:43:51 -0000 1.13
***************
*** 34,48 ****
#include <qptrlist.h>
#include <qcstring.h>
class cElement;
class cPythonScript;
! class cCharBaseDef : public cDefinable
! {
! friend class cCharBaseDefs;
protected:
// Our id
QCString id_;
// Sounds
unsigned short basesound_;
--- 34,94 ----
#include <qptrlist.h>
#include <qcstring.h>
+ #include <qstring.h>
class cElement;
class cPythonScript;
! #undef getIntProperty
! #undef getStrProperty
!
! class cBaseDef : public cDefinable {
protected:
// Our id
QCString id_;
+ QMap<QString, unsigned int> intproperties;
+ QMap<QString, QString> properties;
+
+ bool loaded;
+ virtual void reset();
+ public:
+ void processNode( const cElement* node );
+
+ inline unsigned int getIntProperty(const QString &name, unsigned int def = 0) {
+ QMap<QString, unsigned int>::const_iterator it = intproperties.find(name);
+ if (it == intproperties.end()) {
+ return def;
+ } else {
+ return *it;
+ }
+ }
+
+ inline bool hasIntProperty(const QString &name) {
+ return intproperties.contains(name);
+ }
+
+ inline const QString &getStrProperty(const QString &name, const QString &def = QString::null) {
+ QMap<QString, QString>::const_iterator it = properties.find(name);
+ if (it == properties.end()) {
+ return def;
+ } else {
+ return *it;
+ }
+ }
+
+ inline bool hasStrProperty(const QString &name) {
+ return properties.contains(name);
+ }
+
+ inline const QCString& id() const
+ {
+ return id_;
+ }
+ };
+
+ class cCharBaseDef : public cBaseDef
+ {
+ friend class cCharBaseDefs;
+ protected:
// Sounds
unsigned short basesound_;
***************
*** 63,67 ****
// Misc Properties
- bool loaded;
void load();
void reset();
--- 109,112 ----
***************
*** 97,105 ****
}
- inline const QCString& id() const
- {
- return id_;
- }
-
inline unsigned short basesound()
{
--- 142,145 ----
***************
*** 206,215 ****
static properties.
*/
! class cItemBaseDef : public cDefinable
{
friend class cItemBaseDefs;
protected:
- // Our id
- QCString id_;
float weight_;
unsigned int sellprice_;
--- 246,253 ----
static properties.
*/
! class cItemBaseDef : public cBaseDef
{
friend class cItemBaseDefs;
protected:
float weight_;
unsigned int sellprice_;
***************
*** 224,228 ****
// Misc Properties
- bool loaded;
void load();
void reset();
--- 262,265 ----
***************
*** 240,244 ****
}
}
-
public:
cItemBaseDef( const QCString& id );
--- 277,280 ----
***************
*** 259,267 ****
}
- inline const QCString& id() const
- {
- return id_;
- }
-
inline unsigned int decaydelay()
{
--- 295,298 ----
|