Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23599
Modified Files:
ChangeLog basechar.cpp basechar.h basedef.cpp basedef.h
items.cpp items.h pythonscript.cpp pythonscript.h
scriptmanager.cpp uobject.cpp uobject.h
Log Message:
basescripts property
Index: uobject.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/uobject.cpp,v
retrieving revision 1.181
retrieving revision 1.182
diff -C2 -d -r1.181 -r1.182
*** uobject.cpp 25 Aug 2004 17:01:23 -0000 1.181
--- uobject.cpp 27 Aug 2004 14:41:16 -0000 1.182
***************
*** 157,161 ****
pos_.z = atoi( result[offset++] );
pos_.map = atoi( result[offset++] );
! QString scriptList = ( result[offset] == 0 ) ? QString::null : QString( result[offset] );
offset++;
bool havetags_ = atoi( result[offset++] );
--- 157,161 ----
pos_.z = atoi( result[offset++] );
pos_.map = atoi( result[offset++] );
! QCString scriptList = result[offset];
offset++;
bool havetags_ = atoi( result[offset++] );
***************
*** 227,231 ****
writer.writeByte( pos_.z );
writer.writeByte( pos_.map );
! writer.writeUtf8( scriptList() );
}
--- 227,231 ----
writer.writeByte( pos_.z );
writer.writeByte( pos_.map );
! writer.writeAscii( scriptList() );
}
***************
*** 239,243 ****
pos_.z = reader.readByte();
pos_.map = reader.readByte();
! setScriptList( reader.readUtf8() );
}
--- 239,243 ----
pos_.z = reader.readByte();
pos_.map = reader.readByte();
! setScriptList( reader.readAscii() );
}
***************
*** 312,316 ****
\sa addEvent
*/
! bool cUObject::hasScript( const QString& name ) const
{
if ( scriptChain )
--- 312,316 ----
\sa addEvent
*/
! bool cUObject::hasScript( const QCString &name )
{
if ( scriptChain )
***************
*** 385,389 ****
Removes an event handler from the object
*/
! void cUObject::removeScript( const QString& name )
{
if ( isScriptChainFrozen() )
--- 385,389 ----
Removes an event handler from the object
*/
! void cUObject::removeScript( const QCString& name )
{
if ( isScriptChainFrozen() )
***************
*** 520,524 ****
else if ( TagName == "scripts" )
{
! setScriptList( Value );
}
else
--- 520,524 ----
else if ( TagName == "scripts" )
{
! setScriptList( Value.latin1() );
}
else
***************
*** 914,932 ****
bool cUObject::onCreate( const QString& definition )
{
- cPythonScript* global = ScriptManager::instance()->getGlobalHook( EVENT_CREATE );
bool result = false;
!
! if ( scriptChain || global )
! {
! PyObject* args = Py_BuildValue( "(Ns)", getPyObject(), definition.latin1() );
!
! result = cPythonScript::callChainedEventHandler( EVENT_CREATE, scriptChain, args );
!
! if ( !result && global )
! result = global->callEventHandler( EVENT_CREATE, args );
!
Py_DECREF( args );
}
-
return result;
}
--- 914,923 ----
bool cUObject::onCreate( const QString& definition )
{
bool result = false;
! if (canHandleEvent(EVENT_CREATE)) {
! PyObject* args = Py_BuildValue("(Ns)", getPyObject(), definition.latin1());
! result = callEventHandler(EVENT_CREATE, args);
Py_DECREF( args );
}
return result;
}
***************
*** 935,946 ****
{
bool result = false;
!
! if ( scriptChain )
! {
! PyObject* args = Py_BuildValue( "NNN", PyGetCharObject( sender ), getPyObject(), PyGetTooltipObject( tooltip ) );
! result = cPythonScript::callChainedEventHandler( EVENT_SHOWTOOLTIP, scriptChain, args );
Py_DECREF( args );
}
-
return result;
}
--- 926,934 ----
{
bool result = false;
! if (canHandleEvent(EVENT_SHOWTOOLTIP)) {
! PyObject* args = Py_BuildValue( "(NNN)", PyGetCharObject( sender ), getPyObject(), PyGetTooltipObject( tooltip ) );
! result = callEventHandler(EVENT_SHOWTOOLTIP, args);
Py_DECREF( args );
}
return result;
}
***************
*** 975,979 ****
for ( unsigned int i = 1; i <= count; ++i )
{
! QCString* name = new QCString( scriptChain[i]->name().latin1() );
scriptChain[i] = reinterpret_cast<cPythonScript*>( name );
}
--- 963,967 ----
for ( unsigned int i = 1; i <= count; ++i )
{
! QCString* name = new QCString( scriptChain[i]->name() );
scriptChain[i] = reinterpret_cast<cPythonScript*>( name );
}
***************
*** 1023,1034 ****
}
! QString cUObject::scriptList() const
{
if ( !scriptChain )
{
! return QString::null;
}
! QString result;
unsigned int count = reinterpret_cast<unsigned int>( scriptChain[0] );
for ( unsigned int i = 1; i <= count; ++i )
--- 1011,1022 ----
}
! QCString cUObject::scriptList() const
{
if ( !scriptChain )
{
! return QCString();
}
! QCString result;
unsigned int count = reinterpret_cast<unsigned int>( scriptChain[0] );
for ( unsigned int i = 1; i <= count; ++i )
***************
*** 1048,1052 ****
}
! void cUObject::setScriptList( const QString& eventlist )
{
if ( isScriptChainFrozen() )
--- 1036,1040 ----
}
! void cUObject::setScriptList( const QCString& eventlist )
{
if ( isScriptChainFrozen() )
***************
*** 1094,1095 ****
--- 1082,1084 ----
tags_.save( serial_, writer );
}
+
Index: basechar.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basechar.cpp,v
retrieving revision 1.135
retrieving revision 1.136
diff -C2 -d -r1.135 -r1.136
*** basechar.cpp 21 Aug 2004 21:52:17 -0000 1.135
--- basechar.cpp 27 Aug 2004 14:41:15 -0000 1.136
***************
*** 2134,2137 ****
--- 2134,2143 ----
PY_PROPERTY( "controlslots", controlSlots() )
+ /*
+ \rproperty char.basescripts This is a comma separated list of scripts assigned to this item
+ via the baseid. They are called after the scripts assigned dynamically to the item.
+ */
+ PY_PROPERTY( "basescripts", basedef_ ? basedef_->baseScriptList() : "" );
+
if ( name.left( 6 ) == "skill." )
{
***************
*** 2502,2517 ****
Event Wrappers
*/
-
bool cBaseChar::onWalk( unsigned char direction, unsigned char sequence )
{
bool result = false;
!
! if ( scriptChain )
{
PyObject* args = Py_BuildValue( "O&bb", PyGetCharObject, this, direction, sequence );
! result = cPythonScript::callChainedEventHandler( EVENT_WALK, scriptChain, args );
Py_DECREF( args );
}
-
return result;
}
--- 2508,2520 ----
Event Wrappers
*/
bool cBaseChar::onWalk( unsigned char direction, unsigned char sequence )
{
bool result = false;
! if (canHandleEvent(EVENT_WALK))
{
PyObject* args = Py_BuildValue( "O&bb", PyGetCharObject, this, direction, sequence );
! result = callEventHandler(EVENT_WALK, args);
Py_DECREF( args );
}
return result;
}
***************
*** 2520,2531 ****
{
bool result = false;
!
! if ( scriptChain )
{
! PyObject* args = Py_BuildValue( "O&bhhuu", PyGetCharObject, this, type, color, font, text.ucs2(), lang.ucs2() );
! result = cPythonScript::callChainedEventHandler( EVENT_TALK, scriptChain, args );
Py_DECREF( args );
}
-
return result;
}
--- 2523,2532 ----
{
bool result = false;
! if (canHandleEvent(EVENT_TALK))
{
! PyObject* args = Py_BuildValue( "O&bhhNN", PyGetCharObject, this, type, color, font, QString2Python(text), QString2Python(lang) );
! result = callEventHandler(EVENT_TALK, args);
Py_DECREF( args );
}
return result;
}
***************
*** 2534,2545 ****
{
bool result = false;
!
! if ( scriptChain )
{
PyObject* args = Py_BuildValue( "O&i", PyGetCharObject, this, war ? 1 : 0 );
! result = cPythonScript::callChainedEventHandler( EVENT_WARMODETOGGLE, scriptChain, args );
Py_DECREF( args );
}
-
return result;
}
--- 2535,2544 ----
{
bool result = false;
! if (canHandleEvent(EVENT_WARMODETOGGLE))
{
PyObject* args = Py_BuildValue( "O&i", PyGetCharObject, this, war ? 1 : 0 );
! result = callEventHandler(EVENT_WARMODETOGGLE, args);
Py_DECREF( args );
}
return result;
}
***************
*** 2548,2559 ****
{
bool result = false;
!
! if ( scriptChain )
{
PyObject* args = Py_BuildValue( "O&O&", PyGetCharObject, this, PyGetCharObject, pOrigin );
! result = cPythonScript::callChainedEventHandler( EVENT_SHOWPAPERDOLL, scriptChain, args );
Py_DECREF( args );
}
-
return result;
}
--- 2547,2556 ----
{
bool result = false;
! if (canHandleEvent(EVENT_SHOWPAPERDOLL))
{
PyObject* args = Py_BuildValue( "O&O&", PyGetCharObject, this, PyGetCharObject, pOrigin );
! result = callEventHandler(EVENT_SHOWPAPERDOLL, args);
Py_DECREF( args );
}
return result;
}
***************
*** 2562,2573 ****
{
bool result = false;
!
! if ( scriptChain )
{
PyObject* args = Py_BuildValue( "(N)", getPyObject() );
! result = cPythonScript::callChainedEventHandler( EVENT_SHOWSKILLGUMP, scriptChain, args );
Py_DECREF( args );
}
-
return result;
}
--- 2559,2568 ----
{
bool result = false;
! if (canHandleEvent(EVENT_SHOWSKILLGUMP))
{
PyObject* args = Py_BuildValue( "(N)", getPyObject() );
! result = callEventHandler(EVENT_SHOWSKILLGUMP, args);
Py_DECREF( args );
}
return result;
}
***************
*** 2575,2593 ****
bool cBaseChar::onSkillUse( unsigned char skill )
{
- cPythonScript* global = ScriptManager::instance()->getGlobalHook( EVENT_SKILLUSE );
bool result = false;
!
! if ( scriptChain || global )
{
PyObject* args = Py_BuildValue( "O&b", PyGetCharObject, this, skill );
!
! result = cPythonScript::callChainedEventHandler( EVENT_SKILLUSE, scriptChain, args );
!
! if ( !result && global )
! result = global->callEventHandler( EVENT_SKILLUSE, args );
!
Py_DECREF( args );
}
-
return result;
}
--- 2570,2580 ----
bool cBaseChar::onSkillUse( unsigned char skill )
{
bool result = false;
! if (canHandleEvent(EVENT_SKILLUSE))
{
PyObject* args = Py_BuildValue( "O&b", PyGetCharObject, this, skill );
! result = callEventHandler(EVENT_SKILLUSE, args);
Py_DECREF( args );
}
return result;
}
***************
*** 2596,2607 ****
{
bool result = false;
!
! if ( scriptChain )
{
PyObject* args = Py_BuildValue( "O&O&", PyGetCharObject, this, PyGetItemObject, pItem );
! result = cPythonScript::callChainedEventHandler( EVENT_DROPONCHAR, scriptChain, args );
Py_DECREF( args );
}
-
return result;
}
--- 2583,2592 ----
{
bool result = false;
! if (canHandleEvent(EVENT_DROPONCHAR))
{
PyObject* args = Py_BuildValue( "O&O&", PyGetCharObject, this, PyGetItemObject, pItem );
! result = callEventHandler(EVENT_DROPONCHAR, args);
Py_DECREF( args );
}
return result;
}
***************
*** 2612,2627 ****
QString name = QString::null;
! if ( scriptChain )
{
PyObject* args = Py_BuildValue( "O&O&", PyGetCharObject, this, PyGetCharObject, pOrigin );
! PyObject* result = cPythonScript::callChainedEvent( EVENT_SHOWPAPERDOLLNAME, scriptChain, args );
! if ( result )
! {
! name = Python2QString( result );
}
! Py_XDECREF( result );
Py_DECREF( args );
}
--- 2597,2611 ----
QString name = QString::null;
! if ( canHandleEvent(EVENT_SHOWPAPERDOLLNAME) )
{
PyObject* args = Py_BuildValue( "O&O&", PyGetCharObject, this, PyGetCharObject, pOrigin );
! PyObject* result = callEvent(EVENT_SHOWPAPERDOLLNAME, args);
! if (result) {
! name = Python2QString(result);
}
! Py_XDECREF(result);
Py_DECREF( args );
}
***************
*** 2633,2652 ****
{
bool result = false;
! cPythonScript* global = ScriptManager::instance()->getGlobalHook( EVENT_DEATH );
!
! if ( scriptChain || global )
{
PyObject* args = Py_BuildValue( "(O&O&O&)", PyGetCharObject, this, PyGetObjectObject, source, PyGetItemObject, corpse );
! if ( global )
! {
! global->callEventHandler( EVENT_DEATH, args );
! }
! if ( scriptChain )
! {
! result = cPythonScript::callChainedEventHandler( EVENT_DEATH, scriptChain, args );
! }
Py_DECREF( args );
}
-
return result;
}
--- 2617,2626 ----
{
bool result = false;
! if (canHandleEvent(EVENT_DEATH))
{
PyObject* args = Py_BuildValue( "(O&O&O&)", PyGetCharObject, this, PyGetObjectObject, source, PyGetItemObject, corpse );
! result = callEventHandler(EVENT_DEATH, args);
Py_DECREF( args );
}
return result;
}
***************
*** 2654,2672 ****
bool cBaseChar::onCHLevelChange( unsigned int level )
{
- cPythonScript* global = ScriptManager::instance()->getGlobalHook( EVENT_CHLEVELCHANGE );
bool result = false;
!
! if ( scriptChain || global )
{
PyObject* args = Py_BuildValue( "O&i", PyGetCharObject, this, level );
!
! result = cPythonScript::callChainedEventHandler( EVENT_CHLEVELCHANGE, scriptChain, args );
!
! if ( !result && global )
! result = global->callEventHandler( EVENT_CHLEVELCHANGE, args );
!
Py_DECREF( args );
}
-
return result;
}
--- 2628,2638 ----
bool cBaseChar::onCHLevelChange( unsigned int level )
{
bool result = false;
! if (canHandleEvent(EVENT_CHLEVELCHANGE))
{
PyObject* args = Py_BuildValue( "O&i", PyGetCharObject, this, level );
! result = callEventHandler(EVENT_CHLEVELCHANGE, args);
Py_DECREF( args );
}
return result;
}
***************
*** 2674,2692 ****
bool cBaseChar::onSkillGain( unsigned char skill, unsigned short min, unsigned short max, bool success )
{
- cPythonScript* global = ScriptManager::instance()->getGlobalHook( EVENT_SKILLGAIN );
bool result = false;
!
! if ( scriptChain || global )
{
PyObject* args = Py_BuildValue( "O&bhhi", PyGetCharObject, this, skill, min, max, success ? 1 : 0 );
!
! result = cPythonScript::callChainedEventHandler( EVENT_SKILLGAIN, scriptChain, args );
!
! if ( !result && global )
! result = global->callEventHandler( EVENT_SKILLGAIN, args );
!
Py_DECREF( args );
}
-
return result;
}
--- 2640,2650 ----
bool cBaseChar::onSkillGain( unsigned char skill, unsigned short min, unsigned short max, bool success )
{
bool result = false;
! if (canHandleEvent(EVENT_SKILLGAIN))
{
PyObject* args = Py_BuildValue( "O&bhhi", PyGetCharObject, this, skill, min, max, success ? 1 : 0 );
! result = callEventHandler(EVENT_SKILLGAIN, args);
Py_DECREF( args );
}
return result;
}
***************
*** 3440,3441 ****
--- 3398,3488 ----
SectorMaps::instance()->add( this );
}
+
+ PyObject *cBaseChar::callEvent(ePythonEvent event, PyObject *args, bool ignoreErrors) {
+ PyObject *result = 0;
+
+ if (scriptChain) {
+ result = cPythonScript::callChainedEvent(event, scriptChain, args);
+
+ // Break if there has been a result already
+ if (result && PyObject_IsTrue(result)) {
+ return result;
+ }
+ }
+
+ // call the basescripts
+ if (basedef_) {
+ const QPtrList<cPythonScript> &list = basedef_->baseScripts();
+ QPtrList<cPythonScript>::const_iterator it(list.begin());
+ for (; it != list.end(); ++it) {
+ result = (*it)->callEvent(event, args, ignoreErrors);
+
+ if (result && PyObject_IsTrue(result)) {
+ return result;
+ }
+ }
+ }
+
+ // check for a global handler
+ cPythonScript *globalHook = ScriptManager::instance()->getGlobalHook(event);
+
+ if (globalHook) {
+ result = globalHook->callEvent(event, args, ignoreErrors);
+ }
+
+ return result;
+ }
+
+ bool cBaseChar::canHandleEvent(ePythonEvent event) {
+ // Is there a global event?
+ cPythonScript *globalHook = ScriptManager::instance()->getGlobalHook(event);
+
+ if (globalHook) {
+ return true;
+ }
+
+ if (cPythonScript::canChainHandleEvent(event, scriptChain)) {
+ return true;
+ }
+
+ if (basedef_) {
+ const QPtrList<cPythonScript> &list = basedef_->baseScripts();
+ QPtrList<cPythonScript>::const_iterator it(list.begin());
+ for (; it != list.end(); ++it) {
+ if ((*it)->canHandleEvent(event)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ bool cBaseChar::callEventHandler(ePythonEvent event, PyObject *args, bool ignoreErrors) {
+ PyObject *result = callEvent(event, args, ignoreErrors);
+
+ if (result) {
+ if (PyObject_IsTrue(result)) {
+ Py_DECREF(result);
+ return true;
+ } else {
+ Py_DECREF(result);
+ }
+ }
+ return false;
+ }
+
+ bool cBaseChar::hasScript( const QCString& name )
+ {
+ if (basedef_) {
+ const QPtrList<cPythonScript> &list = basedef_->baseScripts();
+ QPtrList<cPythonScript>::const_iterator it(list.begin());
+ for (; it != list.end(); ++it) {
+ if ((*it)->name() == name) {
+ return true;
+ }
+ }
+ }
+
+ return cUObject::hasScript(name);
+ }
Index: uobject.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/uobject.h,v
retrieving revision 1.107
retrieving revision 1.108
diff -C2 -d -r1.107 -r1.108
*** uobject.h 25 Aug 2004 17:01:23 -0000 1.107
--- uobject.h 27 Aug 2004 14:41:16 -0000 1.108
***************
*** 110,120 ****
void clearScripts();
void addScript( cPythonScript * script, bool append = false );
! void removeScript( const QString& Name );
! bool hasScript( const QString& Name ) const;
void freezeScriptChain();
void unfreezeScriptChain();
bool isScriptChainFrozen();
! void setScriptList( const QString& scripts );
! QString scriptList() const;
inline cPythonScript** getScripts()
{
--- 110,121 ----
void clearScripts();
void addScript( cPythonScript * script, bool append = false );
! void removeScript( const QCString &name );
! virtual bool hasScript(const QCString &name);
!
void freezeScriptChain();
void unfreezeScriptChain();
bool isScriptChainFrozen();
! void setScriptList( const QCString &scripts );
! QCString scriptList() const;
inline cPythonScript** getScripts()
{
***************
*** 234,237 ****
--- 235,252 ----
stError* setProperty( const QString& name, const cVariant& value );
PyObject* getProperty( const QString& name );
+
+ // Call an event handler for this object and take both the normal
+ // and the base script chain into account. This will also call the
+ // global handler.
+ virtual PyObject *callEvent(ePythonEvent event, PyObject *args = 0, bool ignoreErrors = false) = 0;
+
+ // Call a python event handler and return true if any of the
+ // events in the call chain returns an object that evaluates
+ // to true.
+ virtual bool callEventHandler(ePythonEvent event, PyObject *args = 0, bool ignoreErrors = false) = 0;
+
+ // Check if any of the scripts assigned to this object can handle the given event,
+ // this returns true even if there is a global handler for the event.
+ virtual bool canHandleEvent(ePythonEvent event) = 0;
};
#pragma pack()
Index: ChangeLog
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/ChangeLog,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** ChangeLog 23 Aug 2004 21:37:39 -0000 1.13
--- ChangeLog 27 Aug 2004 14:41:15 -0000 1.14
***************
*** 17,20 ****
--- 17,27 ----
- Binary backups can automatically be compressed using gzip.
- The number of backups kept can be limited.
+ - Allowed scripts to be attached to base definitions by using <basescripts>a,b,c</basescripts>.
+ Those scripts are attached to objects by using their baseid property. If you change the <basescripts>
+ tags in the definition, all objects using that definition will use the new scripts automatically.
+ - onDetach and onAttach are not called for those scripts.
+ - hasscript(a) will return true if a is in the basescripts.
+ - addscript now prepends a new script rather than appending it.
+
Wolfpack 12.9.8 Beta (19. August 2004)
Index: pythonscript.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/pythonscript.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** pythonscript.h 19 Aug 2004 05:28:21 -0000 1.38
--- pythonscript.h 27 Aug 2004 14:41:16 -0000 1.39
***************
*** 95,99 ****
{
protected:
! QString name_; // Important!
bool loaded;
PyObject* codeModule; // This object stores the compiled Python Module
--- 95,99 ----
{
protected:
! QCString name_; // Important!
bool loaded;
PyObject* codeModule; // This object stores the compiled Python Module
***************
*** 105,118 ****
// We need an identification value for the scripts
! void setName( const QString& value )
{
name_ = value;
}
! QString name() const
{
return name_;
}
! bool load( const QString& name );
void unload( void );
bool isLoaded() const;
--- 105,118 ----
// We need an identification value for the scripts
! void setName( const QCString& value )
{
name_ = value;
}
! const QCString &name() const
{
return name_;
}
! bool load( const QCString& name );
void unload( void );
bool isLoaded() const;
Index: items.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/items.cpp,v
retrieving revision 1.440
retrieving revision 1.441
diff -C2 -d -r1.440 -r1.441
*** items.cpp 25 Aug 2004 17:01:23 -0000 1.440
--- items.cpp 27 Aug 2004 14:41:15 -0000 1.441
***************
*** 62,180 ****
using namespace std;
- /*
- cItemBaseDef and cItemBaseDefs
- */
- cItemBaseDef::cItemBaseDef( const QCString& id )
- {
- id_ = id;
- reset();
- }
-
- cItemBaseDef::~cItemBaseDef()
- {
- }
-
- void cItemBaseDef::reset()
- {
- loaded = false;
- weight_ = 0.0f;
- decaydelay_ = 0;
- sellprice_ = 0;
- buyprice_ = 0;
- type_ = 0;
- lightsource_ = 0;
- flags_ = 0;
- }
-
- void cItemBaseDef::processNode( const cElement* node )
- {
- if ( node->name() == "weight" )
- {
- weight_ = node->text().toFloat();
- }
- else if ( node->name() == "buyprice" )
- {
- buyprice_ = node->value().toUInt();
- }
- else if ( node->name() == "sellprice" )
- {
- sellprice_ = node->value().toUInt();
- }
- else if ( node->name() == "type" )
- {
- type_ = node->value().toUShort();
- }
- else if ( node->name() == "bindmenu" )
- {
- bindmenu_ = node->text();
- }
- else if ( node->name() == "lightsource" )
- {
- lightsource_ = node->value().toUShort();
- }
- else if ( node->name() == "decaydelay" )
- {
- decaydelay_ = node->value().toUInt();
- }
- else if ( node->name() == "watersource" )
- {
- setWaterSource( node->value().toUInt() != 0 );
- }
- }
-
- // Load this definition from the scripts.
- void cItemBaseDef::load()
- {
- if ( !loaded )
- {
- loaded = true;
- const cElement* element = Definitions::instance()->getDefinition( WPDT_ITEM, id_ );
-
- if ( !element )
- {
- Console::instance()->log( LOG_WARNING, QString( "Missing item definition '%1'.\n" ).arg( id_ ) );
- return;
- }
-
- applyDefinition( element );
- }
- }
-
- cItemBaseDef* cItemBaseDefs::get( const QCString& id )
- {
- Iterator it = definitions.find( id );
-
- if ( it == definitions.end() )
- {
- cItemBaseDef* def = new cItemBaseDef( id );
- it = definitions.insert( id, def );
- }
-
- return it.data();
- }
-
- cItemBaseDefs::cItemBaseDefs()
- {
- }
-
- cItemBaseDefs::~cItemBaseDefs()
- {
- Iterator it;
- for ( it = definitions.begin(); it != definitions.end(); ++it )
- {
- delete it.data();
- }
- definitions.clear();
- }
-
- void cItemBaseDefs::reset()
- {
- Iterator it;
- for ( it = definitions.begin(); it != definitions.end(); ++it )
- {
- it.data()->reset();
- }
- }
-
/*****************************************************************************
* cItem member functions
--- 62,65 ----
***************
*** 688,702 ****
}
! bool cItem::onSingleClick( P_PLAYER Viewer )
! {
bool result = false;
!
! if ( scriptChain )
! {
! PyObject* args = Py_BuildValue( "O&O&", PyGetItemObject, this, PyGetCharObject, Viewer );
! result = cPythonScript::callChainedEventHandler( EVENT_SINGLECLICK, scriptChain, args );
! Py_DECREF( args );
}
-
return result;
}
--- 573,583 ----
}
! bool cItem::onSingleClick( P_PLAYER Viewer ) {
bool result = false;
! if (canHandleEvent(EVENT_SINGLECLICK)) {
! PyObject* args = Py_BuildValue("O&O&", PyGetItemObject, this, PyGetCharObject, Viewer);
! result = callEventHandler(EVENT_SINGLECLICK, args);
! Py_DECREF(args);
}
return result;
}
***************
*** 705,716 ****
{
bool result = false;
!
! if ( scriptChain )
! {
PyObject* args = Py_BuildValue( "O&O&", PyGetItemObject, layer_ == 0x1E ? pItem : this, PyGetItemObject, layer_ == 0x1E ? this : pItem );
! result = cPythonScript::callChainedEventHandler( EVENT_DROPONITEM, scriptChain, args );
! Py_DECREF( args );
}
-
return result;
}
--- 586,594 ----
{
bool result = false;
! if (canHandleEvent(EVENT_DROPONITEM)) {
PyObject* args = Py_BuildValue( "O&O&", PyGetItemObject, layer_ == 0x1E ? pItem : this, PyGetItemObject, layer_ == 0x1E ? this : pItem );
! result = callEventHandler(EVENT_DROPONITEM, args);
! Py_DECREF(args);
}
return result;
}
***************
*** 719,730 ****
{
bool result = false;
!
! if ( scriptChain )
! {
PyObject* args = Py_BuildValue( "O&N", PyGetItemObject, this, PyGetCoordObject( pos ) );
! result = cPythonScript::callChainedEventHandler( EVENT_DROPONGROUND, scriptChain, args );
! Py_DECREF( args );
}
-
return result;
}
--- 597,605 ----
{
bool result = false;
! if (canHandleEvent(EVENT_DROPONGROUND)) {
PyObject* args = Py_BuildValue( "O&N", PyGetItemObject, this, PyGetCoordObject( pos ) );
! result = callEventHandler(EVENT_DROPONGROUND, args);
! Py_DECREF(args);
}
return result;
}
***************
*** 734,742 ****
bool result = false;
! if ( scriptChain )
{
PyObject* args = Py_BuildValue( "O&O&", PyGetCharObject, pChar, PyGetItemObject, this );
! result = cPythonScript::callChainedEventHandler( EVENT_PICKUP, scriptChain, args );
! Py_DECREF( args );
}
--- 609,617 ----
bool result = false;
! if (canHandleEvent(EVENT_PICKUP))
{
PyObject* args = Py_BuildValue( "O&O&", PyGetCharObject, pChar, PyGetItemObject, this );
! result = callEventHandler(EVENT_PICKUP, args);
! Py_DECREF(args);
}
***************
*** 747,758 ****
{
bool result = false;
!
! if ( scriptChain )
! {
PyObject* args = Py_BuildValue( "O&O&b", PyGetCharObject, pChar, PyGetItemObject, this, layer );
! result = cPythonScript::callChainedEventHandler( EVENT_EQUIP, scriptChain, args );
! Py_DECREF( args );
}
-
return result;
}
--- 622,630 ----
{
bool result = false;
! if (canHandleEvent(EVENT_EQUIP)) {
PyObject* args = Py_BuildValue( "O&O&b", PyGetCharObject, pChar, PyGetItemObject, this, layer );
! result = callEventHandler(EVENT_EQUIP, args);
! Py_DECREF(args);
}
return result;
}
***************
*** 761,772 ****
{
bool result = false;
!
! if ( scriptChain )
! {
PyObject* args = Py_BuildValue( "O&O&b", PyGetCharObject, pChar, PyGetItemObject, this, layer );
! result = cPythonScript::callChainedEventHandler( EVENT_UNEQUIP, scriptChain, args );
! Py_DECREF( args );
}
-
return result;
}
--- 633,641 ----
{
bool result = false;
! if (canHandleEvent(EVENT_UNEQUIP)) {
PyObject* args = Py_BuildValue( "O&O&b", PyGetCharObject, pChar, PyGetItemObject, this, layer );
! result = callEventHandler(EVENT_UNEQUIP, args);
! Py_DECREF(args);
}
return result;
}
***************
*** 775,815 ****
{
bool result = false;
!
! if ( scriptChain )
! {
PyObject* args = Py_BuildValue( "O&O&O&b", PyGetCharObject, pPlayer, PyGetCharObject, pChar, PyGetItemObject, this, layer );
! result = cPythonScript::callChainedEventHandler( EVENT_WEARITEM, scriptChain, args );
! Py_DECREF( args );
}
-
return result;
}
! bool cItem::onUse( P_CHAR pChar )
! {
bool result = false;
!
! if ( scriptChain )
! {
PyObject* args = Py_BuildValue( "O&O&", PyGetCharObject, pChar, PyGetItemObject, this );
! result = cPythonScript::callChainedEventHandler( EVENT_USE, scriptChain, args );
! Py_DECREF( args );
}
-
return result;
}
!
! bool cItem::onCollide( P_CHAR pChar )
{
bool result = false;
!
! if ( scriptChain )
! {
PyObject* args = Py_BuildValue( "O&O&", PyGetCharObject, pChar, PyGetItemObject, this );
! result = cPythonScript::callChainedEventHandler( EVENT_COLLIDE, scriptChain, args );
! Py_DECREF( args );
}
-
return result;
}
--- 644,673 ----
{
bool result = false;
! if (canHandleEvent(EVENT_WEARITEM)) {
PyObject* args = Py_BuildValue( "O&O&O&b", PyGetCharObject, pPlayer, PyGetCharObject, pChar, PyGetItemObject, this, layer );
! result = callEventHandler(EVENT_WEARITEM, args);
! Py_DECREF(args);
}
return result;
}
! bool cItem::onUse(P_CHAR pChar) {
bool result = false;
! if (canHandleEvent(EVENT_USE)) {
PyObject* args = Py_BuildValue( "O&O&", PyGetCharObject, pChar, PyGetItemObject, this );
! result = callEventHandler(EVENT_USE, args);
! Py_DECREF(args);
}
return result;
}
! bool cItem::onCollide(P_CHAR pChar)
{
bool result = false;
! if (canHandleEvent(EVENT_COLLIDE)) {
PyObject* args = Py_BuildValue( "O&O&", PyGetCharObject, pChar, PyGetItemObject, this );
! result = callEventHandler(EVENT_COLLIDE, args);
! Py_DECREF(args);
}
return result;
}
***************
*** 818,829 ****
{
bool result = false;
!
! if ( scriptChain )
! {
PyObject* args = Py_BuildValue( "O&O&", PyGetCharObject, pChar, PyGetItemObject, this );
! result = cPythonScript::callChainedEventHandler( EVENT_DROPONCHAR, scriptChain, args );
! Py_DECREF( args );
}
-
return result;
}
--- 676,684 ----
{
bool result = false;
! if (canHandleEvent(EVENT_DROPONCHAR)) {
PyObject* args = Py_BuildValue( "O&O&", PyGetCharObject, pChar, PyGetItemObject, this );
! result = callEventHandler(EVENT_DROPONCHAR, args);
! Py_DECREF(args);
}
return result;
}
***************
*** 2040,2043 ****
--- 1895,1903 ----
*/
PY_PROPERTY( "watersource", isWaterSource() )
+ /*
+ \rproperty item.basescripts This is a comma separated list of scripts assigned to this item
+ via the baseid. They are called after the scripts assigned dynamically to the item.
+ */
+ PY_PROPERTY( "basescripts", basedef_ ? basedef_->baseScriptList() : "" );
return cUObject::getProperty( name );
***************
*** 2376,2377 ****
--- 2236,2326 ----
}
}
+
+ bool cItem::callEventHandler(ePythonEvent event, PyObject *args, bool ignoreErrors) {
+ PyObject *result = callEvent(event, args, ignoreErrors);
+
+ if (result) {
+ if (PyObject_IsTrue(result)) {
+ Py_DECREF(result);
+ return true;
+ } else {
+ Py_DECREF(result);
+ }
+ }
+ return false;
+ }
+
+ PyObject *cItem::callEvent(ePythonEvent event, PyObject *args, bool ignoreErrors) {
+ PyObject *result = 0;
+
+ if (scriptChain) {
+ result = cPythonScript::callChainedEvent(event, scriptChain, args);
+
+ // Break if there has been a result already
+ if (result && PyObject_IsTrue(result)) {
+ return result;
+ }
+ }
+
+ // call the basescripts
+ if (basedef_) {
+ const QPtrList<cPythonScript> &list = basedef_->baseScripts();
+ QPtrList<cPythonScript>::const_iterator it(list.begin());
+ for (; it != list.end(); ++it) {
+ result = (*it)->callEvent(event, args, ignoreErrors);
+
+ if (result && PyObject_IsTrue(result)) {
+ return result;
+ }
+ }
+ }
+
+ // check for a global handler
+ cPythonScript *globalHook = ScriptManager::instance()->getGlobalHook(event);
+
+ if (globalHook) {
+ result = globalHook->callEvent(event, args, ignoreErrors);
+ }
+
+ return result;
+ }
+
+ bool cItem::canHandleEvent(ePythonEvent event) {
+ // Is there a global event?
+ cPythonScript *globalHook = ScriptManager::instance()->getGlobalHook(event);
+
+ if (globalHook) {
+ return true;
+ }
+
+ if (cPythonScript::canChainHandleEvent(event, scriptChain)) {
+ return true;
+ }
+
+ if (basedef_) {
+ const QPtrList<cPythonScript> &list = basedef_->baseScripts();
+ QPtrList<cPythonScript>::const_iterator it(list.begin());
+ for (; it != list.end(); ++it) {
+ if ((*it)->canHandleEvent(event)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ bool cItem::hasScript( const QCString& name )
+ {
+ if (basedef_) {
+ const QPtrList<cPythonScript> &list = basedef_->baseScripts();
+ QPtrList<cPythonScript>::const_iterator it(list.begin());
+ for (; it != list.end(); ++it) {
+ if ((*it)->name() == name) {
+ return true;
+ }
+ }
+ }
+
+ return cUObject::hasScript(name);
+ }
Index: scriptmanager.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/scriptmanager.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** scriptmanager.cpp 6 Jun 2004 12:03:09 -0000 1.23
--- scriptmanager.cpp 27 Aug 2004 14:41:16 -0000 1.24
***************
*** 149,153 ****
cPythonScript* script = new cPythonScript;
scripts.replace( element->text().utf8(), script );
! script->load( element->text() );
++loaded;
}
--- 149,153 ----
cPythonScript* script = new cPythonScript;
scripts.replace( element->text().utf8(), script );
! script->load( element->text().latin1() );
++loaded;
}
Index: items.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/items.h,v
retrieving revision 1.214
retrieving revision 1.215
diff -C2 -d -r1.214 -r1.215
*** items.h 19 Aug 2004 01:55:56 -0000 1.214
--- items.h 27 Aug 2004 14:41:16 -0000 1.215
***************
*** 31,34 ****
--- 31,35 ----
// Wolfpack Includes
#include "uobject.h"
+ #include "basedef.h"
#include "defines.h"
#include "network/uotxpackets.h"
***************
*** 45,163 ****
/*
- This class represents an item definition and it's
- static properties.
- */
- class cItemBaseDef : public cDefinable
- {
- friend class cItemBaseDefs;
- protected:
- // Our id
- QCString id_;
- float weight_;
- unsigned int sellprice_;
- unsigned int buyprice_;
- unsigned short type_;
- QCString bindmenu_;
- unsigned char lightsource_;
- unsigned int decaydelay_;
- unsigned int flags_;
-
- // Misc Properties
- bool loaded;
- void load();
- void reset();
-
- inline void setWaterSource( bool data )
- {
- if ( data )
- {
- flags_ |= 0x01;
- }
- else
- {
- flags_ &= ~0x01;
- }
- }
- public:
- cItemBaseDef( const QCString& id );
- ~cItemBaseDef();
-
- void processNode( const cElement* node );
-
- inline const QCString& id() const
- {
- return id_;
- }
-
- inline unsigned int decaydelay()
- {
- load();
- return decaydelay_;
- }
-
- inline float weight()
- {
- load();
- return weight_;
- }
-
- inline unsigned int sellprice()
- {
- load();
- return sellprice_;
- }
-
- inline unsigned int buyprice()
- {
- load();
- return buyprice_;
- }
-
- inline unsigned short type()
- {
- load();
- return type_;
- }
-
- inline const QCString& bindmenu()
- {
- load();
- return bindmenu_;
- }
-
- inline unsigned char lightsource()
- {
- load();
- return lightsource_;
- }
-
- inline bool isWaterSource()
- {
- load();
- return ( flags_ & 0x01 ) != 0;
- }
- };
-
- class cItemBaseDefs
- {
- protected:
- typedef QMap<QCString, cItemBaseDef*> Container;
- typedef Container::iterator Iterator;
- Container definitions;
- public:
- cItemBaseDefs();
- ~cItemBaseDefs();
-
- // Get a base definition
- // This is guaranteed to return a basedef. Even if uninitialized.
- cItemBaseDef* get( const QCString& id );
-
- // When reset is called, all loaded basedefs are unflagged.
- void reset();
- };
-
- typedef SingletonHolder<cItemBaseDefs> ItemBaseDefs;
-
- /*
Notes for further memory footprint reduction:
--- 46,49 ----
***************
*** 180,183 ****
--- 66,74 ----
public:
+ PyObject *callEvent(ePythonEvent event, PyObject *args = 0, bool ignoreErrors = false);
+ bool callEventHandler(ePythonEvent event, PyObject *args = 0, bool ignoreErrors = false);
+ bool canHandleEvent(ePythonEvent event);
+ bool hasScript(const QCString &name);
+
cItem();
cItem( const cItem& src ); // Copy constructor
***************
*** 306,309 ****
--- 197,204 ----
return basedef_ ? basedef_->id() : 0;
}
+ inline cItemBaseDef *basedef() const
+ {
+ return basedef_;
+ }
inline void setBaseid( const QCString& id )
{
Index: pythonscript.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/pythonscript.cpp,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** pythonscript.cpp 22 Aug 2004 02:29:51 -0000 1.46
--- pythonscript.cpp 27 Aug 2004 14:41:16 -0000 1.47
***************
*** 432,437 ****
\event onAttach
\param object The object.
! \condition Triggered when a script is attached to an object.
! \notes This is even triggered when the item is loaded from a worldfile.
*/
"onAttach",
--- 432,438 ----
\event onAttach
\param object The object.
! \condition Triggered when a script is attached to an object.
! \notes This is even triggered when the item is loaded from a worldfile, but not
! for scripts in the objects basescripts list.
*/
"onAttach",
***************
*** 440,444 ****
\event onDetach
\param object The object.
! \condition Triggered when a script is removed from an object.
*/
"onDetach",
--- 441,446 ----
\event onDetach
\param object The object.
! \condition Triggered when a script is removed from an object, but not
! for scripts in the objects basescripts list.
*/
"onDetach",
***************
*** 558,562 ****
*/
// Find our module name
! bool cPythonScript::load( const QString& name )
{
if ( name.isEmpty() )
--- 560,564 ----
*/
// Find our module name
! bool cPythonScript::load( const QCString& name )
{
if ( name.isEmpty() )
***************
*** 567,571 ****
setName( name );
! codeModule = PyImport_ImportModule( const_cast<char*>( name.latin1() ) );
if ( !codeModule )
--- 569,573 ----
setName( name );
! codeModule = PyImport_ImportModule( const_cast<char*>( name.data() ) );
if ( !codeModule )
***************
*** 752,756 ****
result = copy[i]->callEvent( event, args );
! if ( result )
break;
}
--- 754,758 ----
result = copy[i]->callEvent( event, args );
! if ( result && PyObject_IsTrue( result ) )
break;
}
Index: basedef.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basedef.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** basedef.cpp 2 Jun 2004 15:04:03 -0000 1.10
--- basedef.cpp 27 Aug 2004 14:41:15 -0000 1.11
***************
*** 30,33 ****
--- 30,34 ----
#include "basedef.h"
#include "definitions.h"
+ #include "scriptmanager.h"
#include "basics.h"
#include <string.h>
***************
*** 115,118 ****
--- 116,136 ----
bindmenu_ = node->text();
}
+ else if ( node->name() == "basescripts" )
+ {
+ baseScriptList_ = node->text();
+ }
+ }
+
+ void cCharBaseDef::refreshScripts() {
+ if (loaded) {
+ QStringList scripts = QStringList::split(",", baseScriptList_);
+ QStringList::const_iterator it;
+ for (it = scripts.begin(); it != scripts.end(); ++it) {
+ cPythonScript *script = ScriptManager::instance()->find((*it).latin1());
+ if (script) {
+ baseScripts_.append(script);
+ }
+ }
+ }
}
***************
*** 170,171 ****
--- 188,341 ----
}
}
+
+ void cCharBaseDefs::refreshScripts()
+ {
+ Iterator it;
+ for ( it = definitions.begin(); it != definitions.end(); ++it )
+ {
+ it.data()->refreshScripts();
+ }
+ }
+
+
+ /*
+ cItemBaseDef and cItemBaseDefs
+ */
+ cItemBaseDef::cItemBaseDef( const QCString& id )
+ {
+ id_ = id;
+ reset();
+ }
+
+ cItemBaseDef::~cItemBaseDef()
+ {
+ }
+
+ void cItemBaseDef::reset()
+ {
+ loaded = false;
+ weight_ = 0.0f;
+ decaydelay_ = 0;
+ sellprice_ = 0;
+ buyprice_ = 0;
+ type_ = 0;
+ lightsource_ = 0;
+ flags_ = 0;
+ }
+
+ void cItemBaseDef::refreshScripts() {
+ if (loaded) {
+ QStringList scripts = QStringList::split(",", baseScriptList_);
+ QStringList::const_iterator it;
+ for (it = scripts.begin(); it != scripts.end(); ++it) {
+ cPythonScript *script = ScriptManager::instance()->find((*it).latin1());
+ if (script) {
+ baseScripts_.append(script);
+ }
+ }
+ }
+ }
+
+ void cItemBaseDef::processNode( const cElement* node )
+ {
+ if ( node->name() == "weight" )
+ {
+ weight_ = node->text().toFloat();
+ }
+ else if ( node->name() == "buyprice" )
+ {
+ buyprice_ = node->value().toUInt();
+ }
+ else if ( node->name() == "sellprice" )
+ {
+ sellprice_ = node->value().toUInt();
+ }
+ else if ( node->name() == "type" )
+ {
+ type_ = node->value().toUShort();
+ }
+ else if ( node->name() == "bindmenu" )
+ {
+ bindmenu_ = node->text();
+ }
+ else if ( node->name() == "lightsource" )
+ {
+ lightsource_ = node->value().toUShort();
+ }
+ else if ( node->name() == "decaydelay" )
+ {
+ decaydelay_ = node->value().toUInt();
+ }
+ else if ( node->name() == "watersource" )
+ {
+ setWaterSource( node->value().toUInt() != 0 );
+ }
+ else if ( node->name() == "basescripts" )
+ {
+ baseScriptList_ = node->text();
+ refreshScripts();
+ }
+ }
+
+ // Load this definition from the scripts.
+ void cItemBaseDef::load()
+ {
+ if ( !loaded )
+ {
+ loaded = true;
+ const cElement* element = Definitions::instance()->getDefinition( WPDT_ITEM, id_ );
+
+ if ( !element )
+ {
+ Console::instance()->log( LOG_WARNING, QString( "Missing item definition '%1'.\n" ).arg( id_ ) );
+ return;
+ }
+
+ applyDefinition( element );
+ }
+ }
+
+ cItemBaseDef* cItemBaseDefs::get( const QCString& id )
+ {
+ Iterator it = definitions.find( id );
+
+ if ( it == definitions.end() )
+ {
+ cItemBaseDef* def = new cItemBaseDef( id );
+ it = definitions.insert( id, def );
+ }
+
+ return it.data();
+ }
+
+ cItemBaseDefs::cItemBaseDefs()
+ {
+ }
+
+ cItemBaseDefs::~cItemBaseDefs()
+ {
+ Iterator it;
+ for ( it = definitions.begin(); it != definitions.end(); ++it )
+ {
+ delete it.data();
+ }
+ definitions.clear();
+ }
+
+ void cItemBaseDefs::reset()
+ {
+ Iterator it;
+ for ( it = definitions.begin(); it != definitions.end(); ++it )
+ {
+ it.data()->reset();
+ }
+ }
+
+ void cItemBaseDefs::refreshScripts()
+ {
+ Iterator it;
+ for ( it = definitions.begin(); it != definitions.end(); ++it )
+ {
+ it.data()->refreshScripts();
+ }
+ }
Index: basedef.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basedef.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** basedef.h 10 Aug 2004 03:15:56 -0000 1.11
--- basedef.h 27 Aug 2004 14:41:15 -0000 1.12
***************
*** 32,37 ****
--- 32,40 ----
#include "singleton.h"
#include <qmap.h>
+ #include <qptrlist.h>
+ #include <qcstring.h>
class cElement;
+ class cPythonScript;
class cCharBaseDef : public cDefinable
***************
*** 56,59 ****
--- 59,64 ----
unsigned char controlSlots_;
unsigned char criticalHealth_;
+ QPtrList<cPythonScript> baseScripts_;
+ QCString baseScriptList_;
// Misc Properties
***************
*** 61,69 ****
void load();
void reset();
public:
cCharBaseDef( const QCString& id );
~cCharBaseDef();
! void processNode( const cElement* node );
inline unsigned char controlSlots()
--- 66,87 ----
void load();
void reset();
+ void refreshScripts();
public:
cCharBaseDef( const QCString& id );
~cCharBaseDef();
! void processNode( const cElement* node );
!
! inline const QCString& baseScriptList()
! {
! load();
! return baseScriptList_;
! }
!
! inline const QPtrList<cPythonScript> &baseScripts()
! {
! load();
! return baseScripts_;
! }
inline unsigned char controlSlots()
***************
*** 179,185 ****
--- 197,336 ----
// When reset is called, all loaded basedefs are unflagged.
void reset();
+ void refreshScripts();
};
typedef SingletonHolder<cCharBaseDefs> CharBaseDefs;
+ /*
+ This class represents an item definition and it's
+ static properties.
+ */
+ class cItemBaseDef : public cDefinable
+ {
+ friend class cItemBaseDefs;
+ protected:
+ // Our id
+ QCString id_;
+ float weight_;
+ unsigned int sellprice_;
+ unsigned int buyprice_;
+ unsigned short type_;
+ QCString bindmenu_;
+ unsigned char lightsource_;
+ unsigned int decaydelay_;
+ unsigned int flags_;
+ QPtrList<cPythonScript> baseScripts_;
+ QCString baseScriptList_;
+
+ // Misc Properties
+ bool loaded;
+ void load();
+ void reset();
+ void refreshScripts();
+
+ inline void setWaterSource( bool data )
+ {
+ if ( data )
+ {
+ flags_ |= 0x01;
+ }
+ else
+ {
+ flags_ &= ~0x01;
+ }
+ }
+
+ public:
+ cItemBaseDef( const QCString& id );
+ ~cItemBaseDef();
+
+ void processNode( const cElement* node );
+
+ inline const QCString& baseScriptList()
+ {
+ load();
+ return baseScriptList_;
+ }
+
+ inline const QPtrList<cPythonScript> & baseScripts()
+ {
+ load();
+ return baseScripts_;
+ }
+
+ inline const QCString& id() const
+ {
+ return id_;
+ }
+
+ inline unsigned int decaydelay()
+ {
+ load();
+ return decaydelay_;
+ }
+
+ inline float weight()
+ {
+ load();
+ return weight_;
+ }
+
+ inline unsigned int sellprice()
+ {
+ load();
+ return sellprice_;
+ }
+
+ inline unsigned int buyprice()
+ {
+ load();
+ return buyprice_;
+ }
+
+ inline unsigned short type()
+ {
+ load();
+ return type_;
+ }
+
+ inline const QCString& bindmenu()
+ {
+ load();
+ return bindmenu_;
+ }
+
+ inline unsigned char lightsource()
+ {
+ load();
+ return lightsource_;
+ }
+
+ inline bool isWaterSource()
+ {
+ load();
+ return ( flags_ & 0x01 ) != 0;
+ }
+ };
+
+ class cItemBaseDefs
+ {
+ protected:
+ typedef QMap<QCString, cItemBaseDef*> Container;
+ typedef Container::iterator Iterator;
+ Container definitions;
+ public:
+ cItemBaseDefs();
+ ~cItemBaseDefs();
+
+ // Get a base definition
+ // This is guaranteed to return a basedef. Even if uninitialized.
+ cItemBaseDef* get( const QCString& id );
+
+ // When reset is called, all loaded basedefs are unflagged.
+ void reset();
+ void refreshScripts();
+ };
+
+ typedef SingletonHolder<cItemBaseDefs> ItemBaseDefs;
+
#endif
Index: basechar.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basechar.h,v
retrieving revision 1.80
retrieving revision 1.81
diff -C2 -d -r1.80 -r1.81
*** basechar.h 15 Aug 2004 02:17:39 -0000 1.80
--- basechar.h 27 Aug 2004 14:41:15 -0000 1.81
***************
*** 310,313 ****
--- 310,317 ----
virtual bool onCHLevelChange( uint level ); // Fired when player moving trough levels
virtual bool onSkillGain( unsigned char skill, unsigned short min, unsigned short max, bool success );
+ PyObject *callEvent(ePythonEvent event, PyObject *args = 0, bool ignoreErrors = false);
+ bool callEventHandler(ePythonEvent event, PyObject *args = 0, bool ignoreErrors = false);
+ bool canHandleEvent(ePythonEvent event);
+ bool hasScript(const QCString &name);
// Combat
***************
*** 337,340 ****
--- 341,349 ----
}
+ inline cCharBaseDef *basedef() const
+ {
+ return basedef_;
+ }
+
inline void setBaseid( const QCString& id )
{
|