Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1:/tmp/cvs-serv2528
Modified Files:
basechar.cpp basechar.h commands.cpp contextmenu.cpp
customtags.cpp globals.cpp globals.h items.cpp npc.cpp
player.cpp pythonscript.cpp pythonscript.h scriptmanager.cpp
scriptmanager.h skills.cpp speech.cpp targetrequests.cpp
uobject.cpp wolf.dsp wolfpack.cpp
Log Message:
Changed Python Interface
Changed behaviour of setGlobalHook and setCommandHook
Index: basechar.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basechar.cpp,v
retrieving revision 1.45
retrieving revision 1.46
diff -C2 -d -r1.45 -r1.46
*** basechar.cpp 16 Sep 2003 18:15:24 -0000 1.45
--- basechar.cpp 23 Sep 2003 12:40:17 -0000 1.46
***************
*** 1013,1276 ****
}
- // Shows the name of a character to someone else
- bool cBaseChar::onSingleClick( P_PLAYER Viewer )
- {
- // If we got ANY events process them in order
- if( scriptChain )
- {
- unsigned int i = 0;
- while( scriptChain[i] )
- {
- if( scriptChain[ i ]->onSingleClick( (P_PLAYER)this, (P_CHAR)Viewer ) )
- return true;
-
- ++i;
- }
- }
-
- // Try to process the hooks then
- QValueVector< cPythonScript* > hooks;
- QValueVector< cPythonScript* >::const_iterator it;
-
- hooks = ScriptManager->getGlobalHooks( OBJECT_CHAR, EVENT_SINGLECLICK );
- for( it = hooks.begin(); it != hooks.end(); ++it )
- if( (*it)->onSingleClick( (P_PLAYER)this, (P_CHAR)Viewer ) )
- return true;
-
- return false;
- }
-
- // Walks in a specific Direction
- bool cBaseChar::onWalk( UI08 Direction, UI08 Sequence )
- {
- // If we got ANY events process them in order
- if( scriptChain )
- {
- unsigned int i = 0;
- while( scriptChain[i] )
- {
- if( scriptChain[ i ]->onWalk( (P_CHAR)this, Direction, Sequence ) )
- return true;
- ++i;
- }
- }
-
- return false;
- }
-
- // The character says something
- bool cBaseChar::onTalk( char speechType, UI16 speechColor, UI16 speechFont, const QString &Text, const QString &Lang )
- {
- if( scriptChain )
- {
- unsigned int i = 0;
- while( scriptChain[i] )
- {
- if( scriptChain[ i ]->onTalk( (P_CHAR)this, speechType, speechColor, speechFont, Text, Lang ) )
- return true;
- ++i;
- }
- }
-
- return false;
- }
-
- // The character switches warmode
- bool cBaseChar::onWarModeToggle( bool War )
- {
- // If we got ANY events process them in order
- if( scriptChain )
- {
- unsigned int i = 0;
- while( scriptChain[i] )
- {
- if( scriptChain[ i ]->onWarModeToggle( this, War ) )
- return true;
-
- ++i;
- }
- }
-
- return false;
- }
-
- // The paperdoll of this character has been requested
- bool cBaseChar::onShowPaperdoll( P_CHAR pOrigin )
- {
- if( scriptChain )
- {
- unsigned int i = 0;
- while( scriptChain[i] )
- {
- if( scriptChain[ i ]->onShowPaperdoll( this, pOrigin ) )
- return true;
-
- ++i;
- }
- }
-
- return false;
- }
-
- bool cBaseChar::onShowSkillGump()
- {
- if( scriptChain )
- {
- unsigned int i = 0;
- while( scriptChain[i] )
- {
- if( scriptChain[ i ]->onShowSkillGump( this ) )
- return true;
-
- ++i;
- }
- }
-
- // Try to process the hooks then
- QValueVector< cPythonScript* > hooks;
- QValueVector< cPythonScript* >::const_iterator it;
-
- hooks = ScriptManager->getGlobalHooks( OBJECT_CHAR, EVENT_SHOWSKILLGUMP );
- for( it = hooks.begin(); it != hooks.end(); ++it )
- if( (*it)->onShowSkillGump( this ) )
- return true;
-
- return false;
- }
-
- // The character uses %Skill
- bool cBaseChar::onSkillUse( UI08 Skill )
- {
- // If we got ANY events process them in order
- if( scriptChain )
- {
- unsigned int i = 0;
- while( scriptChain[i] )
- {
- if( scriptChain[ i ]->onSkillUse( this, Skill ) )
- return true;
-
- ++i;
- }
- }
-
- // Try to process the hooks then
- QValueVector< cPythonScript* > hooks;
- QValueVector< cPythonScript* >::const_iterator it;
-
- hooks = ScriptManager->getGlobalHooks( OBJECT_CHAR, EVENT_SKILLUSE );
- for( it = hooks.begin(); it != hooks.end(); ++it )
- if( (*it)->onSkillUse( this, Skill ) )
- return true;
-
- return false;
- }
-
- bool cBaseChar::onDropOnChar( P_ITEM pItem )
- {
- // If we got ANY events process them in order
- if( scriptChain )
- {
- unsigned int i = 0;
- while( scriptChain[i] )
- {
- if( scriptChain[ i ]->onDropOnChar( this, pItem ) )
- return true;
-
- ++i;
- }
- }
-
- return false;
- }
-
- QString cBaseChar::onShowPaperdollName( P_CHAR pOrigin )
- {
- if( scriptChain )
- {
- unsigned int i = 0;
- while( scriptChain[i] )
- {
- QString result = scriptChain[ i ]->onShowPaperdollName( this, pOrigin );
-
- if( !result.isNull() )
- return result;
-
- ++i;
- }
- }
-
- return QString::null;
- }
-
- bool cBaseChar::onDeath()
- {
- // If we got ANY events process them in order
- if( scriptChain )
- {
- unsigned int i = 0;
- while( scriptChain[i] )
- {
- if( scriptChain[ i ]->onDeath( this ) )
- return true;
-
- ++i;
- }
- }
-
- return false;
- }
- bool cBaseChar::onCHLevelChange( uint level )
- {
- if( scriptChain )
- {
- unsigned int i = 0;
- while( scriptChain[i] )
- {
- if( scriptChain[ i ]->onCHLevelChange( this, level ) )
- return true;
-
- ++i;
- }
- }
-
- // Try to process the hooks then
- QValueVector< cPythonScript* > hooks;
- QValueVector< cPythonScript* >::const_iterator it;
-
- hooks = ScriptManager->getGlobalHooks( OBJECT_CHAR, EVENT_CHLEVELCHANGE );
- for( it = hooks.begin(); it != hooks.end(); ++it )
- if( (*it)->onCHLevelChange( this, level ) )
- return true;
-
-
- return false;
- }
- bool cBaseChar::onShowTooltip( P_PLAYER sender, cUOTxTooltipList* tooltip )
- {
- if( scriptChain )
- {
- unsigned int i = 0;
- while( scriptChain[i] )
- {
- if( scriptChain[ i ]->onShowToolTip( sender, this, tooltip ) )
- return true;
-
- ++i;
- }
- }
-
- // Try to process the hooks then
- QValueVector< cPythonScript* > hooks;
- QValueVector< cPythonScript* >::const_iterator it;
-
- hooks = ScriptManager->getGlobalHooks( OBJECT_CHAR, EVENT_SHOWTOOLTIP );
- for( it = hooks.begin(); it != hooks.end(); ++it )
- if( (*it)->onShowToolTip( sender, this, tooltip ) )
- return true;
-
- return false;
- }
-
void cBaseChar::processNode( const cElement *Tag )
{
--- 1013,1016 ----
***************
*** 1893,1950 ****
}
- bool cBaseChar::onSkillGain( UI08 Skill, SI32 min, SI32 max, bool success )
- {
- // If we got ANY events process them in order
- if( scriptChain )
- {
- unsigned int i = 0;
- while( scriptChain[i] )
- {
- if( scriptChain[ i ]->onSkillGain( this, Skill, min, max, success ) )
- return true;
-
- ++i;
- }
- }
-
- // Try to process the hooks then
- QValueVector< cPythonScript* > hooks;
- QValueVector< cPythonScript* >::const_iterator it;
-
- hooks = ScriptManager->getGlobalHooks( OBJECT_CHAR, EVENT_SKILLGAIN );
- for( it = hooks.begin(); it != hooks.end(); ++it )
- if( (*it)->onSkillGain( this, Skill, min, max, success ) )
- return true;
-
- return false;
- }
-
- bool cBaseChar::onStatGain( UI08 stat, SI08 amount )
- {
- // If we got ANY events process them in order
- if( scriptChain )
- {
- unsigned int i = 0;
- while( scriptChain[i] )
- {
- if( scriptChain[ i ]->onStatGain( this, stat, amount ) )
- return true;
-
- ++i;
- }
- }
-
- // Try to process the hooks then
- QValueVector< cPythonScript* > hooks;
- QValueVector< cPythonScript* >::const_iterator it;
-
- hooks = ScriptManager->getGlobalHooks( OBJECT_CHAR, EVENT_STATGAIN );
- for( it = hooks.begin(); it != hooks.end(); ++it )
- if( (*it)->onStatGain( this, stat,amount ) )
- return true;
-
- return false;
- }
-
unsigned int cBaseChar::damage( eDamageType type, unsigned int amount, cUObject *source )
{
--- 1633,1636 ----
***************
*** 1953,1973 ****
// to modify the damage if needed
//
-
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
{
! amount = scriptChain[ i ]->onDamage( this, type, amount, source );
! ++i;
! }
! }
! QValueVector< cPythonScript* > hooks;
! QValueVector< cPythonScript* >::const_iterator it;
! hooks = ScriptManager->getGlobalHooks( OBJECT_CHAR, EVENT_DAMAGE );
! for( it = hooks.begin(); it != hooks.end(); ++it )
! amount = (*it)->onDamage( this, type, amount, source );
// Invulnerable Targets don't take any damage at all
--- 1639,1663 ----
// to modify the damage if needed
//
if( scriptChain )
{
! PyObject *args;
!
! if( dynamic_cast< P_CHAR >( source ) != 0 )
! args = Py_BuildValue( "O&iiO&", PyGetCharObject, this, (unsigned int)type, amount, PyGetCharObject, source );
! else if( dynamic_cast< P_ITEM >( source ) )
! args = Py_BuildValue( "O&iiO&", PyGetCharObject, this, (unsigned int)type, amount, PyGetItemObject, source );
!
! PyObject *result = cPythonScript::callChainedEvent( EVENT_DAMAGE, scriptChain, args );
!
! if( result )
{
! if( PyInt_Check( result ) )
! amount = PyInt_AsLong( result );
! Py_DECREF( result );
! }
! Py_DECREF( args );
! }
// Invulnerable Targets don't take any damage at all
***************
*** 2128,2130 ****
--- 1818,2041 ----
source->sendContainer( getBackpack() );
};
+ }
+
+ /*
+ 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;
+ }
+
+ bool cBaseChar::onTalk( unsigned char type, unsigned short color, unsigned short font, const QString &text, const QString &lang )
+ {
+ 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;
+ }
+
+ bool cBaseChar::onWarModeToggle( bool war )
+ {
+ 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;
+ }
+
+ bool cBaseChar::onShowPaperdoll( P_CHAR pOrigin )
+ {
+ 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;
+ }
+
+ bool cBaseChar::onShowSkillGump()
+ {
+ return cPythonScript::callChainedEventHandler( EVENT_SHOWSKILLGUMP, scriptChain );
+ }
+
+ 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;
+ }
+
+ bool cBaseChar::onDropOnChar( P_ITEM pItem )
+ {
+ 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;
+ }
+
+ QString cBaseChar::onShowPaperdollName( P_CHAR pOrigin )
+ {
+ // I hate this event by the way (DarkStorm)
+ 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 )
+ {
+ // Strings and Unicode Objects gladly accepted
+ if( PyString_Check( result ) )
+ name = PyString_AsString( result );
+
+ if( PyUnicode_Check( result ) )
+ name = QString::fromUcs2( PyUnicode_AS_UNICODE( result ) );
+ }
+
+ Py_XDECREF( result );
+
+ Py_DECREF( args );
+ }
+
+ return name;
+ }
+
+ bool cBaseChar::onDeath()
+ {
+ bool result = false;
+
+ if( scriptChain )
+ {
+ PyObject *args = Py_BuildValue( "O&", PyGetCharObject, this );
+ result = cPythonScript::callChainedEventHandler( EVENT_DEATH, scriptChain, args );
+ Py_DECREF( args );
+ }
+
+ return result;
+ }
+ 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;
+ }
+
+ bool cBaseChar::onShowTooltip( P_PLAYER sender, cUOTxTooltipList* tooltip )
+ {
+ cPythonScript *global = ScriptManager::instance()->getGlobalHook( EVENT_SHOWTOOLTIP );
+ bool result = false;
+
+ if( scriptChain || global )
+ {
+ PyObject *args = Py_BuildValue( "O&O&O&", PyGetCharObject, sender, PyGetCharObject, this, PyGetTooltipObject, tooltip );
+
+ result = cPythonScript::callChainedEventHandler( EVENT_SHOWTOOLTIP, scriptChain, args );
+
+ if( !result && global )
+ result = global->callEventHandler( EVENT_SHOWTOOLTIP, args );
+
+ Py_DECREF( args );
+ }
+
+ return result;
+ }
+
+ 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;
+ }
+
+ bool cBaseChar::onStatGain( unsigned char stat )
+ {
+ cPythonScript *global = ScriptManager::instance()->getGlobalHook( EVENT_STATGAIN );
+ bool result = false;
+
+ if( scriptChain || global )
+ {
+ PyObject *args = Py_BuildValue( "O&b", PyGetCharObject, this, stat );
+
+ result = cPythonScript::callChainedEventHandler( EVENT_STATGAIN, scriptChain, args );
+
+ if( !result && global )
+ result = global->callEventHandler( EVENT_STATGAIN, args );
+
+ Py_DECREF( args );
+ }
+
+ return result;
}
Index: basechar.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basechar.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** basechar.h 20 Sep 2003 12:01:43 -0000 1.37
--- basechar.h 23 Sep 2003 12:40:18 -0000 1.38
***************
*** 159,176 ****
// Wrapper events
! virtual bool onSingleClick( P_PLAYER Viewer ); // Shows the name of a character to someone else
! virtual bool onWalk( UI08 Direction, UI08 Sequence ); // Walks in a specific Direction
! virtual bool onTalk( char speechType, UI16 speechColor, UI16 speechFont, const QString &Text, const QString &Lang ); // The character says something
virtual bool onWarModeToggle( bool War ); // The character switches warmode
virtual bool onShowPaperdoll( P_CHAR pOrigin ); // The paperdoll of this character is requested, there is no vice-versa call
virtual bool onShowSkillGump(); //Show Skillgump
virtual bool onSkillUse( UI08 Skill ); // The character uses %Skill
! bool onDeath();
! bool onDropOnChar( P_ITEM pItem );
! QString onShowPaperdollName( P_CHAR pOrigin ); // only change the viewed name
virtual bool onShowTooltip( P_PLAYER sender, cUOTxTooltipList* tooltip ); // Shows a tool tip for specific object
virtual bool onCHLevelChange( uint level ); // Fired when player moving trough levels
! bool onSkillGain( UI08 Skill, SI32 min, SI32 max, bool success );
! bool onStatGain( UI08 stat, SI08 amount );
// getters
--- 159,175 ----
// Wrapper events
! virtual bool onWalk( unsigned char dir, unsigned char sequence ); // Walks in a specific Direction
! virtual bool onTalk( unsigned char speechType, UI16 speechColor, UI16 speechFont, const QString &Text, const QString &Lang ); // The character says something
virtual bool onWarModeToggle( bool War ); // The character switches warmode
virtual bool onShowPaperdoll( P_CHAR pOrigin ); // The paperdoll of this character is requested, there is no vice-versa call
virtual bool onShowSkillGump(); //Show Skillgump
virtual bool onSkillUse( UI08 Skill ); // The character uses %Skill
! virtual bool onDeath();
! virtual bool onDropOnChar( P_ITEM pItem );
! virtual QString onShowPaperdollName( P_CHAR pOrigin ); // only change the viewed name
virtual bool onShowTooltip( P_PLAYER sender, cUOTxTooltipList* tooltip ); // Shows a tool tip for specific object
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 );
! virtual bool onStatGain( unsigned char stat );
// getters
Index: commands.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/commands.cpp,v
retrieving revision 1.205
retrieving revision 1.206
diff -C2 -d -r1.205 -r1.206
*** commands.cpp 20 Sep 2003 02:15:09 -0000 1.205
--- commands.cpp 23 Sep 2003 12:40:18 -0000 1.206
***************
*** 97,109 ****
// Check for custom commands
! cPythonScript *script = ScriptManager->getCommandHook( command );
! if( script )
{
QString argString = arguments.join( " " );
if( argString.isNull() )
argString = "";
! script->onCommand( socket, command, argString );
return;
}
--- 97,117 ----
// Check for custom commands
! PyObject *function = ScriptManager::instance()->getCommandHook( command.latin1() );
! if( function )
{
QString argString = arguments.join( " " );
+
if( argString.isNull() )
argString = "";
! PyObject *args = Py_BuildValue( "O&uu", PyGetSocketObject, socket, command.ucs2(), argString.ucs2() );
!
! PyObject *result = PyObject_CallObject( function, args );
! Py_XDECREF( result );
! reportPythonError();
!
! Py_DECREF( args );
!
return;
}
***************
*** 871,875 ****
{
Console::instance()->send( "Reloading python scripts\n" );
! ScriptManager->reload();
ContextMenus::instance()->reload();
}
--- 879,883 ----
{
Console::instance()->send( "Reloading python scripts\n" );
! ScriptManager::instance()->reload();
ContextMenus::instance()->reload();
}
***************
*** 889,893 ****
Resources::instance()->reload();
MakeMenus::instance()->reload();
! ScriptManager->reload(); // Reload Scripts
Skills->reload();
ContextMenus::instance()->reload();
--- 897,901 ----
Resources::instance()->reload();
MakeMenus::instance()->reload();
! ScriptManager::instance()->reload(); // Reload Scripts
Skills->reload();
ContextMenus::instance()->reload();
***************
*** 920,924 ****
Resources::instance()->reload();
MakeMenus::instance()->reload();
! ScriptManager->reload(); // Reload Scripts
ContextMenus::instance()->reload();
--- 928,932 ----
Resources::instance()->reload();
MakeMenus::instance()->reload();
! ScriptManager::instance()->reload(); // Reload Scripts
ContextMenus::instance()->reload();
***************
*** 963,967 ****
// No such event
! if( !ScriptManager->find( event ) )
{
socket->sysMessage( tr( "Invalid event: '%1'" ).arg( event ) );
--- 971,975 ----
// No such event
! if( !ScriptManager::instance()->find( event.latin1() ) )
{
socket->sysMessage( tr( "Invalid event: '%1'" ).arg( event ) );
Index: contextmenu.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/contextmenu.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** contextmenu.cpp 7 Sep 2003 19:07:46 -0000 1.15
--- contextmenu.cpp 23 Sep 2003 12:40:18 -0000 1.16
***************
*** 94,98 ****
for( ; myIter != eventList_.end(); ++myIter )
{
! cPythonScript *myScript = ScriptManager->find( *myIter );
// Script not found
--- 94,98 ----
for( ; myIter != eventList_.end(); ++myIter )
{
! cPythonScript *myScript = ScriptManager::instance()->find( (*myIter).latin1() );
// Script not found
***************
*** 110,117 ****
return false;
// If we got ANY events process them in order
for( UI08 i = 0; i < scriptChain.size(); i++ )
{
! if ( scriptChain[ i ]->onContextEntry( Caller, Target, Tag ) )
return true;
}
--- 110,119 ----
return false;
+ PyObject *args = Py_BuildValue( "O&O&h", PyGetCharObject, Caller, PyGetObjectObject, Target, Tag );
+
// If we got ANY events process them in order
for( UI08 i = 0; i < scriptChain.size(); i++ )
{
! if ( scriptChain[ i ]->callEventHandler( EVENT_CONTEXTENTRY, args ) )
return true;
}
Index: customtags.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/customtags.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** customtags.cpp 13 Sep 2003 13:27:26 -0000 1.31
--- customtags.cpp 23 Sep 2003 12:40:18 -0000 1.32
***************
*** 720,730 ****
tags_->clear();
! cDBResult result = persistentBroker->query( QString( "SELECT serial,name,type,value FROM tags WHERE serial = '%1'" ).arg( key ) );
while( result.fetchrow() )
{
! QString name = result.getString( 1 );
! QString type = result.getString( 2 );
! QString value = result.getString( 3 );
if( !tags_ )
--- 720,730 ----
tags_->clear();
! cDBResult result = persistentBroker->query( QString( "SELECT name,type,value FROM tags WHERE serial = '%1'" ).arg( key ) );
while( result.fetchrow() )
{
! QString name = result.getString( 0 );
! QString type = result.getString( 1 );
! QString value = result.getString( 2 );
if( !tags_ )
Index: globals.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/globals.cpp,v
retrieving revision 1.103
retrieving revision 1.104
diff -C2 -d -r1.103 -r1.104
*** globals.cpp 9 Sep 2003 23:09:30 -0000 1.103
--- globals.cpp 23 Sep 2003 12:40:18 -0000 1.104
***************
*** 34,38 ****
#include "verinfo.h"
#include "walking.h"
- #include "scriptmanager.h"
#include "wpdefmanager.h"
#include "wptargetrequests.h"
--- 34,37 ----
***************
*** 65,69 ****
cSkills *Skills;
cSpeech *Speech;
- cScriptManager *ScriptManager;
WPDefManager *DefManager;
PersistentBroker* persistentBroker;
--- 64,67 ----
Index: globals.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/globals.h,v
retrieving revision 1.77
retrieving revision 1.78
diff -C2 -d -r1.77 -r1.78
*** globals.h 9 Sep 2003 23:09:30 -0000 1.77
--- globals.h 23 Sep 2003 12:40:18 -0000 1.78
***************
*** 49,53 ****
// Forward Class Declaration
class QDateTime;
- class cScriptManager;
class WPDefManager;
--- 49,52 ----
***************
*** 82,86 ****
extern cSkills *Skills;
extern cSpeech *Speech;
- extern cScriptManager *ScriptManager;
extern WPDefManager *DefManager;
extern PersistentBroker *persistentBroker;
--- 81,84 ----
Index: items.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/items.cpp,v
retrieving revision 1.354
retrieving revision 1.355
diff -C2 -d -r1.354 -r1.355
*** items.cpp 23 Sep 2003 11:53:31 -0000 1.354
--- items.cpp 23 Sep 2003 12:40:18 -0000 1.355
***************
*** 78,81 ****
--- 78,82 ----
buyprice_( 0 ), restock_( 1 ), antispamtimer_( 0 )
{
+ spawnregion_ = QString::null;
Init( false );
};
***************
*** 549,554 ****
this->setOwnSerialOnly(-1);
this->visible_=0; // 0=Normally Visible, 1=Owner & GM Visible, 2=GM Visible
- this->spawnregion_=(char*)0;
- // Everything decays by default.
this->priv_ = 0; // Bit 0, nodecay off/on. Bit 1, newbie item off/on. Bit 2 Dispellable
this->poisoned_ = 0; //AntiChrist -- for poisoning skill
--- 550,553 ----
***************
*** 570,574 ****
// Update Top Objects
! setSpawnRegion( (char*)0 );
SetOwnSerial( -1 );
--- 569,573 ----
// Update Top Objects
! setSpawnRegion( QString::null );
SetOwnSerial( -1 );
***************
*** 862,1058 ****
bool cItem::onSingleClick( P_PLAYER Viewer )
{
!
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onSingleClick( this, Viewer ) )
! return true;
!
! ++i;
! }
}
! return false;
}
bool cItem::onDropOnItem( P_ITEM pItem )
{
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! // we are the item being dragged
! if( layer_ == 0x1E )
! {
! if( scriptChain[ i ]->onDropOnItem( pItem, this ) )
! return true;
! }
! else
! {
! if( scriptChain[ i ]->onDropOnItem( this, pItem ) )
! return true;
! }
!
! ++i;
! }
}
! return false;
}
bool cItem::onDropOnGround( const Coord_cl &pos )
{
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onDropOnGround( this, pos ) )
! return true;
!
! ++i;
! }
}
! return false;
}
bool cItem::onPickup( P_CHAR pChar )
{
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onPickup( pChar, this ) )
! return true;
!
! ++i;
! }
}
! return false;
}
bool cItem::onEquip( P_CHAR pChar, unsigned char layer )
{
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onEquip( pChar, this, layer ) )
! return true;
!
! ++i;
! }
}
! return false;
}
bool cItem::onBookUpdateInfo( P_CHAR pChar, const QString &author, const QString &title )
{
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onBookUpdateInfo( pChar, this, author, title ) )
! return true;
!
! ++i;
! }
}
! return false;
}
bool cItem::onBookRequestPage( P_CHAR pChar, unsigned short page )
{
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onBookRequestPage( pChar, this, page ) )
! return true;
!
! ++i;
! }
}
! return false;
}
bool cItem::onBookUpdatePage( P_CHAR pChar, unsigned short page, const QString &content )
{
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onBookUpdatePage( pChar, this, page, content ) )
! return true;
!
! ++i;
! }
}
! return false;
}
bool cItem::onUnequip( P_CHAR pChar, unsigned char layer )
{
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onUnequip( pChar, this, layer ) )
! return true;
!
! ++i;
! }
}
! return false;
}
bool cItem::onWearItem( P_PLAYER pPlayer, P_CHAR pChar, unsigned char layer )
{
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onWearItem( pPlayer, pChar, this, layer ) )
! return true;
!
! ++i;
! }
}
! return false;
}
bool cItem::onUse( P_CHAR pChar )
{
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onUse( pChar, this ) )
! return true;
!
! ++i;
! }
}
! return false;
}
--- 861,1014 ----
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;
}
bool cItem::onDropOnItem( P_ITEM pItem )
{
+ 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;
}
bool cItem::onDropOnGround( const Coord_cl &pos )
{
+ 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;
}
bool cItem::onPickup( P_CHAR pChar )
{
+ 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 );
}
! return result;
}
bool cItem::onEquip( P_CHAR pChar, unsigned char layer )
{
+ 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;
}
bool cItem::onBookUpdateInfo( P_CHAR pChar, const QString &author, const QString &title )
{
+ bool result = false;
+
if( scriptChain )
{
! PyObject *args = Py_BuildValue( "O&O&uu", PyGetCharObject, pChar, PyGetItemObject, this, author.ucs2(), title.ucs2() );
! result = cPythonScript::callChainedEventHandler( EVENT_BOOKUPDATEINFO, scriptChain, args );
! Py_DECREF( args );
}
! return result;
}
bool cItem::onBookRequestPage( P_CHAR pChar, unsigned short page )
{
+ bool result = false;
+
if( scriptChain )
{
! PyObject *args = Py_BuildValue( "O&O&h", PyGetCharObject, pChar, PyGetItemObject, this, page );
! result = cPythonScript::callChainedEventHandler( EVENT_BOOKREQUESTPAGE, scriptChain, args );
! Py_DECREF( args );
}
! return result;
}
bool cItem::onBookUpdatePage( P_CHAR pChar, unsigned short page, const QString &content )
{
+ bool result = false;
+
if( scriptChain )
{
! PyObject *args = Py_BuildValue( "O&O&hu", PyGetCharObject, pChar, PyGetItemObject, this, page, content.ucs2() );
! result = cPythonScript::callChainedEventHandler( EVENT_BOOKUPDATEPAGE, scriptChain, args );
! Py_DECREF( args );
}
! return result;
}
bool cItem::onUnequip( P_CHAR pChar, unsigned char layer )
{
+ 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;
}
bool cItem::onWearItem( P_PLAYER pPlayer, P_CHAR pChar, unsigned char layer )
{
+ 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;
}
***************
*** 1060,1121 ****
bool cItem::onCollide( P_CHAR pChar )
{
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onCollide( pChar, this ) )
! return true;
!
! ++i;
! }
}
! return false;
}
bool cItem::onDropOnChar( P_CHAR pChar )
{
! // If we got ANY events process them in order
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onDropOnChar( pChar, this ) )
! return true;
!
! ++i;
! }
}
! return false;
}
bool cItem::onShowTooltip( P_PLAYER sender, cUOTxTooltipList* tooltip )
{
!
! if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onShowToolTip( sender, this, tooltip ) )
! return true;
! ++i;
! }
! }
! // Try to process the hooks then
! QValueVector< cPythonScript* > hooks;
! QValueVector< cPythonScript* >::const_iterator it;
! hooks = ScriptManager->getGlobalHooks( OBJECT_ITEM, EVENT_SHOWTOOLTIP );
! for( it = hooks.begin(); it != hooks.end(); ++it )
! if( (*it)->onShowToolTip( sender, this, tooltip ) )
! return true;
! return false;
}
--- 1016,1063 ----
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;
}
bool cItem::onDropOnChar( P_CHAR pChar )
{
! 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;
}
bool cItem::onShowTooltip( P_PLAYER sender, cUOTxTooltipList* tooltip )
{
! cPythonScript *global = ScriptManager::instance()->getGlobalHook( EVENT_SHOWTOOLTIP );
! bool result = false;
!
! if( scriptChain || global )
{
! PyObject *args = Py_BuildValue( "O&O&O&", PyGetCharObject, sender, PyGetItemObject, this, PyGetTooltipObject, tooltip );
! result = cPythonScript::callChainedEventHandler( EVENT_SHOWTOOLTIP, scriptChain, args );
! if( !result && global )
! result = global->callEventHandler( EVENT_SHOWTOOLTIP, args );
! Py_DECREF( args );
! }
! return result;
}
***************
*** 1870,1877 ****
// Set the outside indices
! pi->setSpawnRegion( pi->spawnregion() );
! pi->SetOwnSerial( pi->ownSerial() );
!
! if( pi->maxhp() == 0)
pi->setMaxhp( pi->hp() );
}
--- 1812,1816 ----
// Set the outside indices
! if( pi->maxhp() == 0 )
pi->setMaxhp( pi->hp() );
}
Index: npc.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/npc.cpp,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** npc.cpp 20 Sep 2003 12:01:43 -0000 1.46
--- npc.cpp 23 Sep 2003 12:40:18 -0000 1.47
***************
*** 693,699 ****
return;
- if( onSingleClick( socket->player() ) )
- return;
-
QString charName = name();
--- 693,696 ----
Index: player.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/player.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -C2 -d -r1.42 -r1.43
*** player.cpp 23 Sep 2003 11:53:31 -0000 1.42
--- player.cpp 23 Sep 2003 12:40:18 -0000 1.43
***************
*** 842,848 ****
return;
- if( onSingleClick( socket->player() ) )
- return;
-
QString charName = name();
--- 842,845 ----
***************
*** 1304,1404 ****
bool cPlayer::onPickup( P_ITEM pItem )
{
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onPickup( this, pItem ) )
! return true;
!
! ++i;
! }
! }
! // Try to process the hooks then
! QValueVector< cPythonScript* > hooks;
! QValueVector< cPythonScript* >::const_iterator it;
! hooks = ScriptManager->getGlobalHooks( OBJECT_CHAR, EVENT_PICKUP );
! for( it = hooks.begin(); it != hooks.end(); ++it )
! if( (*it)->onPickup( this, pItem ) )
! return true;
! return false;
}
bool cPlayer::onLogin( void )
{
! if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onLogin( this ) )
! return true;
! ++i;
! }
! }
! // Try to process the hooks then
! QValueVector< cPythonScript* > hooks;
! QValueVector< cPythonScript* >::const_iterator it;
! hooks = ScriptManager->getGlobalHooks( OBJECT_CHAR, EVENT_LOGIN );
! for( it = hooks.begin(); it != hooks.end(); ++it )
! (*it)->onLogin( this );
! return false;
}
bool cPlayer::onCastSpell( unsigned int spell )
{
! if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onCastSpell( this, spell ) )
! return true;
! ++i;
! }
! }
! // Try to process the hooks then
! QValueVector< cPythonScript* > hooks;
! QValueVector< cPythonScript* >::const_iterator it;
! hooks = ScriptManager->getGlobalHooks( OBJECT_CHAR, EVENT_CASTSPELL );
! for( it = hooks.begin(); it != hooks.end(); ++it )
! (*it)->onCastSpell( this, spell );
! return false;
}
bool cPlayer::onLogout( void )
{
! if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onLogout( this ) )
! return true;
! ++i;
! }
! }
! // Try to process the hooks then
! QValueVector< cPythonScript* > hooks;
! QValueVector< cPythonScript* >::const_iterator it;
! hooks = ScriptManager->getGlobalHooks( OBJECT_CHAR, EVENT_LOGOUT );
! for( it = hooks.begin(); it != hooks.end(); ++it )
! (*it)->onLogout( this );
! return false;
}
--- 1301,1376 ----
bool cPlayer::onPickup( P_ITEM pItem )
{
+ bool result = false;
+
if( scriptChain )
{
! PyObject *args = Py_BuildValue( "O&O&", PyGetCharObject, this, PyGetItemObject, pItem );
! result = cPythonScript::callChainedEventHandler( EVENT_PICKUP, scriptChain, args );
! Py_DECREF( args );
! }
! return result;
}
bool cPlayer::onLogin( void )
{
! cPythonScript *global = ScriptManager::instance()->getGlobalHook( EVENT_LOGIN );
! bool result = false;
!
! if( scriptChain || global )
{
! PyObject *args = Py_BuildValue( "O&", PyGetCharObject, this );
! result = cPythonScript::callChainedEventHandler( EVENT_LOGIN, scriptChain, args );
! if( !result && global )
! result = global->callEventHandler( EVENT_LOGIN, args );
! Py_DECREF( args );
! }
! return result;
}
bool cPlayer::onCastSpell( unsigned int spell )
{
! cPythonScript *global = ScriptManager::instance()->getGlobalHook( EVENT_CASTSPELL );
! bool result = false;
!
! if( scriptChain || global )
{
! PyObject *args = Py_BuildValue( "O&i", PyGetCharObject, this, spell );
! result = cPythonScript::callChainedEventHandler( EVENT_CASTSPELL, scriptChain, args );
! if( !result && global )
! result = global->callEventHandler( EVENT_CASTSPELL, args );
! Py_DECREF( args );
! }
! return result;
}
bool cPlayer::onLogout( void )
{
! cPythonScript *global = ScriptManager::instance()->getGlobalHook( EVENT_LOGOUT );
! bool result = false;
!
! if( scriptChain || global )
{
! PyObject *args = Py_BuildValue( "O&", PyGetCharObject, this );
! result = cPythonScript::callChainedEventHandler( EVENT_LOGOUT, scriptChain, args );
! if( !result && global )
! result = global->callEventHandler( EVENT_LOGOUT, args );
! Py_DECREF( args );
! }
! return result;
}
***************
*** 1406,1432 ****
bool cPlayer::onHelp( void )
{
! // If we got ANY events process them in order
! if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onHelp( this ) )
! return true;
! ++i;
! }
! }
! // Try to process the hooks then
! QValueVector< cPythonScript* > hooks;
! QValueVector< cPythonScript* >::const_iterator it;
! hooks = ScriptManager->getGlobalHooks( OBJECT_CHAR, EVENT_HELP );
! for( it = hooks.begin(); it != hooks.end(); ++it )
! if( (*it)->onHelp( this ) )
! return true;
! return false;
}
--- 1378,1397 ----
bool cPlayer::onHelp( void )
{
! cPythonScript *global = ScriptManager::instance()->getGlobalHook( EVENT_HELP );
! bool result = false;
!
! if( scriptChain || global )
{
! PyObject *args = Py_BuildValue( "O&", PyGetCharObject, this );
! result = cPythonScript::callChainedEventHandler( EVENT_HELP, scriptChain, args );
! if( !result && global )
! result = global->callEventHandler( EVENT_HELP, args );
! Py_DECREF( args );
! }
! return result;
}
***************
*** 1434,1494 ****
bool cPlayer::onChat( void )
{
! // If we got ANY events process them in order
! if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onChat( this ) )
! return true;
! ++i;
! }
! }
! // Try to process the hooks then
! QValueVector< cPythonScript* > hooks;
! QValueVector< cPythonScript* >::const_iterator it;
! hooks = ScriptManager->getGlobalHooks( OBJECT_CHAR, EVENT_CHAT );
! for( it = hooks.begin(); it != hooks.end(); ++it )
! if( (*it)->onChat( this ) )
! return true;
! return false;
}
bool cPlayer::onShowContext( cUObject *object )
{
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onShowContextMenu( this, object ) )
! return true;
!
! ++i;
! }
}
! return false;
}
bool cPlayer::onUse( P_ITEM pItem )
{
if( scriptChain )
{
! unsigned int i = 0;
! while( scriptChain[i] )
! {
! if( scriptChain[ i ]->onUse( this, pItem ) )
! return true;
!
! ++i;
! }
}
! return false;
}
--- 1399,1446 ----
bool cPlayer::onChat( void )
{
! cPythonScript *global = ScriptManager::instance()->getGlobalHook( EVENT_CHAT );
! bool result = false;
!
! if( scriptChain || global )
{
! PyObject *args = Py_BuildValue( "O&", PyGetCharObject, this );
! result = cPythonScript::callChainedEventHandler( EVENT_CHAT, scriptChain, args );
! if( !result && global )
! result = global->callEventHandler( EVENT_CHAT, args );
! Py_DECREF( args );
! }
! return result;
}
bool cPlayer::onShowContext( cUObject *object )
{
+ bool result = false;
+
if( scriptChain )
{
! PyObject *args = Py_BuildValue( "O&O&", PyGetCharObject, this, PyGetObjectObject, object );
! result = cPythonScript::callChainedEventHandler( EVENT_SHOWCONTEXTMENU, scriptChain, args );
! Py_DECREF( args );
}
! return result;
}
bool cPlayer::onUse( P_ITEM pItem )
{
+ bool result = false;
+
if( scriptChain )
{
! PyObject *args = Py_BuildValue( "O&O&", PyGetCharObject, this, PyGetItemObject, pItem );
! result = cPythonScript::callChainedEventHandler( EVENT_USE, scriptChain, args );
! Py_DECREF( args );
}
! return result;
}
Index: pythonscript.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/pythonscript.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** pythonscript.cpp 20 Sep 2003 01:05:10 -0000 1.11
--- pythonscript.cpp 23 Sep 2003 12:40:18 -0000 1.12
***************
*** 50,118 ****
#include "python/target.h"
! void cPythonScript::addKeyword( UINT16 data )
! {
! speechKeywords_.push_back( data );
! }
!
! void cPythonScript::addWord( const QString &data )
! {
! speechWords_.push_back( data );
! }
!
! void cPythonScript::addRegexp( const QRegExp &data )
{
! speechRegexp_.push_back( data );
}
! bool cPythonScript::canHandleSpeech( const QString &text, const QValueVector< UINT16 >& keywords )
{
- // Check keywords first.
- for( QValueVector< UINT16 >::const_iterator iter1 = keywords.begin(); iter1 != keywords.end(); ++iter1 )
- for( QValueVector< UINT16 >::const_iterator iter2 = speechKeywords_.begin(); iter2 != speechKeywords_.end(); ++iter2 )
- {
- if( *iter1 == *iter2 )
- return true;
- }
-
- for( QValueVector< QString >::const_iterator iter3 = speechWords_.begin(); iter3 != speechWords_.end(); ++iter3 )
- if( text.contains( *iter3 ) )
- return true;
-
- for( QValueVector< QRegExp >::const_iterator iter4 = speechRegexp_.begin(); iter4 != speechRegexp_.end(); ++iter4 )
- if( text.contains( *iter4 ) )
- return true;
-
- return false;
}
void cPythonScript::unload( void )
{
! if( !codeModule )
! return;
!
! PyObject* method = PyObject_GetAttrString( codeModule, "onUnload" );
!
! if( !method )
{
! PyErr_Clear();
! Py_DECREF( codeModule );
! codeModule = 0;
! return;
}
! if ( !PyCallable_Check( method ) )
! {
! Py_DECREF( method );
! Py_DECREF( codeModule );
! codeModule = 0;
! }
!
! PyObject* result = PyObject_CallObject( method, NULL );
! reportPythonError( name_ );
! Py_XDECREF( result ); // void
! Py_DECREF( method );
! Py_DECREF( codeModule );
! codeModule = 0;
}
--- 50,80 ----
#include "python/target.h"
! cPythonScript::cPythonScript()
{
! codeModule = 0;
! for( unsigned int i = 0; i < EVENT_COUNT; ++i )
! events[i] = 0;
}
! cPythonScript::~cPythonScript()
{
}
void cPythonScript::unload( void )
{
! // Free Cached Events
! for( unsigned int i = 0; i < EVENT_COUNT; ++i )
{
! if( events[ i ] )
! {
! Py_XDECREF( events[ i ] );
! events[ i ] = 0;
! }
}
! callEventHandler( "onUnload" );
+ Py_XDECREF( codeModule );
+ codeModule = 0;
}
***************
*** 120,138 ****
bool cPythonScript::load( const cElement *element )
{
- // Initialize it
- codeModule = NULL;
- catchAllSpeech_ = false;
-
QString name = element->text();
! if( name.isNull() )
return false;
setName( name );
! if( name.isNull() || name.isEmpty() )
! return false;
!
! codeModule = PyImport_ImportModule( const_cast<char*>(name.latin1()) );
if( !codeModule )
--- 82,93 ----
bool cPythonScript::load( const cElement *element )
{
QString name = element->text();
! if( name.isEmpty() )
return false;
setName( name );
! codeModule = PyImport_ImportModule( const_cast< char* >( name.latin1() ) );
if( !codeModule )
***************
*** 144,721 ****
}
! // Call the load Function
! PyObject* method = PyObject_GetAttrString( codeModule, "onLoad" );
!
! if ( method )
! {
! if ( PyCallable_Check( method ) )
! {
! PyObject* result = PyObject_CallObject( method, NULL );
! if( PyErr_Occurred() )
! {
! Console::instance()->ProgressFail();
! reportPythonError( name );
! Console::instance()->PrepareProgress( "Continuing loading" );
! }
! Py_XDECREF( result );
! }
! Py_DECREF( method );
! }
!
! handleSpeech_ = PyObject_HasAttrString( codeModule, "onSpeech" );
! return true;
! }
!
! //========================== OVERRIDDEN DEFAULT EVENTS
! bool cPythonScript::onServerstart()
! {
! PyHasMethod( "onServerstart" )
! return PyEvalMethod( "onServerstart", PyTuple_New( 0 ) );
! }
!
! bool cPythonScript::onUse( P_CHAR User, P_ITEM Used )
! {
! PyHasMethod( "onUse" )
!
! // Create our args for the python function
! PyObject *tuple = PyTuple_New( 2 );
! PyTuple_SetItem( tuple, 0, PyGetCharObject( User ) );
! PyTuple_SetItem( tuple, 1, PyGetItemObject( Used ) );
!
! return PyEvalMethod( "onUse", tuple );
! }
!
! bool cPythonScript::onSingleClick( P_ITEM Item, P_CHAR Viewer )
! {
! PyHasMethod( "onSingleClick" )
!
! PyObject *tuple = PyTuple_New( 2 ); // Create our args for the python function
! PyTuple_SetItem( tuple, 0, PyGetItemObject( Item ) );
! PyTuple_SetItem( tuple, 1, PyGetCharObject( Viewer ) );
!
! return PyEvalMethod( "onSingleClick", tuple );
! }
!
! bool cPythonScript::onSingleClick( P_CHAR Character, P_CHAR Viewer )
! {
! PyHasMethod( "onSingleClick" )
!
! PyObject *tuple = PyTuple_New( 2 ); // Create our args for the python function
! PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! PyTuple_SetItem( tuple, 1, PyGetCharObject( Viewer ) );
!
! return PyEvalMethod( "onSingleClick", tuple );
! }
!
! bool cPythonScript::onLogout( P_CHAR Character )
! {
! PyHasMethod( "onLogout" )
!
! PyObject *tuple = PyTuple_New( 1 ); // Create our args for the python function
! PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
!
! return PyEvalMethod( "onLogout", tuple );
! }
!
! bool cPythonScript::onLogin( P_CHAR Character )
! {
! PyHasMethod( "onLogin" )
!
! PyObject *tuple = PyTuple_New( 1 ); // Create our args for the python function
! PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
!
! return PyEvalMethod( "onLogin", tuple );
! }
!
! bool cPythonScript::onCollide( P_CHAR Character, P_ITEM Obstacle )
! {
! PyHasMethod( "onCollide" )
!
! PyObject *tuple = PyTuple_New( 2 ); // Create our args for the python function
! PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! PyTuple_SetItem( tuple, 1, PyGetItemObject( Obstacle ) );
!
! return PyEvalMethod( "onCollide", tuple );
! }
!
! bool cPythonScript::onWalk( P_CHAR Character, UINT8 Direction, UINT8 Sequence )
! {
! PyHasMethod( "onWalk" )
!
! PyObject *tuple = PyTuple_New( 3 ); // Create our args for the python function
! PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! PyTuple_SetItem( tuple, 1, PyInt_FromLong( Direction ) );
! PyTuple_SetItem( tuple, 2, PyInt_FromLong( Sequence ) );
!
! return PyEvalMethod( "onWalk", tuple );
! }
!
! // if this events returns true (handeled) then we should not display the text
! bool cPythonScript::onTalk( P_CHAR Character, char speechType, UINT16 speechColor, UINT16 speechFont, const QString &Text, const QString &Lang )
! {
! PyHasMethod( "onTalk" )
!
! PyObject *tuple = PyTuple_New( 6 ); // Create our args for the python function
! PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! PyTuple_SetItem( tuple, 1, PyInt_FromLong( speechType ) );
! PyTuple_SetItem( tuple, 2, PyInt_FromLong( speechColor ) );
! PyTuple_SetItem( tuple, 3, PyInt_FromLong( speechFont ) );
! PyTuple_SetItem( tuple, 4, PyString_FromString( Text.ascii() ) );
! PyTuple_SetItem( tuple, 5, PyString_FromString( Lang.ascii() ) );
!
! return PyEvalMethod( "onTalk", tuple );
! }
!
! bool cPythonScript::onWarModeToggle( P_CHAR Character, bool War )
! {
! PyHasMethod( "onWarModeToggle" )
!
! PyObject *tuple = PyTuple_New( 2 ); // Create our args for the python function
! PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! PyTuple_SetItem( tuple, 1, ( War ? PyInt_FromLong( 1 ) : PyInt_FromLong( 0 ) ) );
!
! return PyEvalMethod( "onWarModeToggle", tuple );
! }
!
! bool cPythonScript::onHelp( P_CHAR Character )
! {
! PyHasMethod( "onHelp" )
!
! PyObject *tuple = PyTuple_New( 1 ); // Create our args for the python function
! PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
!
! return PyEvalMethod( "onHelp", tuple );
! }
!
!
! bool cPythonScript::onChat( P_CHAR Character )
! {
! PyHasMethod( "onChat" )
!
! PyObject *tuple = PyTuple_New( 1 ); // Create our args for the python function
! PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
!
! return PyEvalMethod( "onChat", tuple );
! }
!
!
! bool cPythonScript::onSkillUse( P_CHAR Character, UINT8 Skill )
! {
! PyHasMethod( "onSkillUse" )
!
! PyObject *tuple = PyTuple_New( 2 ); // Create our args for the python function
! PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! PyTuple_SetItem( tuple, 1, PyInt_FromLong( Skill ) );
!
! return PyEvalMethod( "onSkillUse", tuple );
! }
!
! bool cPythonScript::onSkillGain( P_CHAR Character, UINT8 Skill, INT32 min, INT32 max, bool success )
! {
! PyHasMethod( "onSkillGain" )
!
! PyObject *tuple = PyTuple_New( 5 );
! PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! PyTuple_SetItem( tuple, 1, PyInt_FromLong( Skill ) );
! PyTuple_SetItem( tuple, 2, PyInt_FromLong( min ) );
! PyTuple_SetItem( tuple, 3, PyInt_FromLong( max ) );
! PyTuple_SetItem( tuple, 4, PyInt_FromLong( success ) );
!
! return PyEvalMethod( "onSkillGain", tuple );
! }
!
! bool cPythonScript::onStatGain( P_CHAR Character, UINT8 stat, INT8 amount )
! {
! PyHasMethod( "onStatGain" )
!
! PyObject *tuple = PyTuple_New( 3 );
! PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! PyTuple_SetItem( tuple, 1, PyInt_FromLong( stat ) );
! PyTuple_SetItem( tuple, 2, PyInt_FromLong( amount ) );
!
! return PyEvalMethod( "onStatGain", tuple );
! }
!
! bool cPythonScript::onContextEntry( P_CHAR pChar, cUObject *pObject, UINT16 id )
! {
! PyHasMethod( "onContextEntry" )
!
! PyObject *tuple = PyTuple_New( 3 );
! PyTuple_SetItem( tuple, 0, PyGetCharObject( pChar ) );
!
! if( isItemSerial( pObject->serial() ) )
! PyTuple_SetItem( tuple, 1, PyGetItemObject( (P_ITEM)pObject ) );
! else if( isCharSerial( pObject->serial() ) )
! PyTuple_SetItem( tuple, 1, PyGetCharObject( (P_CHAR)pObject ) );
!
! PyTuple_SetItem( tuple, 2, PyInt_FromLong( id ) );
!
! return PyEvalMethod( "onContextEntry", tuple );
! }
!
! bool cPythonScript::onShowContextMenu( P_CHAR pChar, cUObject *pObject )
! {
! PyHasMethod( "onShowContextMenu" )
!
! PyObject *tuple = PyTuple_New( 2 );
! PyTuple_SetItem( tuple, 0, PyGetCharObject( pChar ) );
!
! if( isItemSerial( pObject->serial() ) )
! PyTuple_SetItem( tuple, 1, PyGetItemObject( (P_ITEM)pObject ) );
! else if( isCharSerial( pObject->serial() ) )
! PyTuple_SetItem( tuple, 1, PyGetCharObject( (P_CHAR)pObject ) );
!
! return PyEvalMethod( "onShowContextMenu", tuple );
! }
!
! bool cPythonScript::onShowToolTip( P_CHAR pChar, cUObject *pObject, cUOTxTooltipList* tooltip )
! {
! PyHasMethod( "onShowToolTip" )
!
! PyObject *tuple = PyTuple_New( 3 );
! PyTuple_SetItem( tuple, 0, PyGetCharObject( pChar ) );
!
! if( isItemSerial( pObject->serial() ) )
! PyTuple_SetItem( tuple, 1, PyGetItemObject( (P_ITEM)pObject ) );
! else if( isCharSerial( pObject->serial() ) )
! PyTuple_SetItem( tuple, 1, PyGetCharObject( (P_CHAR)pObject ) );
!
! PyTuple_SetItem( tuple, 2, PyGetTooltipObject( tooltip ) );
!
! return PyEvalMethod( "onShowToolTip", tuple );
! }
!
! bool cPythonScript::onCHLevelChange( P_CHAR pChar, uint level )
! {
! PyHasMethod( "onCHLevelChange" )
!
! PyObject *tuple = PyTuple_New( 2 );
! PyTuple_SetItem( tuple, 0, PyGetCharObject( pChar ) );
! PyTuple_SetItem( tuple, 1, PyInt_FromLong( level ) );
!
! return PyEvalMethod( "onCHLevelChange", tuple );
! }
!
!
! unsigned int cPythonScript::onDamage( P_CHAR pChar, unsigned char type, unsigned int amount, cUObject *source )
! {
! if( !codeModule )
! return amount;
!
! PyObject *method = PyObject_GetAttrString( codeModule, "onDamage" );
!
! if( !method )
! return amount;
! if ( !PyCallable_Check( method ) )
{
! Py_DECREF( method );
! return amount;
}
! PyObject *args = PyTuple_New( 4 );
!
! PyTuple_SetItem( args, 0, PyGetCharObject( pChar ) );
! PyTuple_SetItem( args, 1, PyInt_FromLong( type ) );
! PyTuple_SetItem( args, 2, PyInt_FromLong( amount ) );
!
! if( source && source->isItem() )
! PyTuple_SetItem( args, 3, PyGetItemObject( dynamic_cast< P_ITEM >( source ) ) );
! else
! PyTuple_SetItem( args, 3, PyGetCharObject( dynamic_cast< P_CHAR >( source ) ) );
!
!
! PyObject *returnValue = PyObject_CallObject( method, args );
!
! reportPythonError( name_ );
! Py_DECREF( args );
! Py_DECREF( method );
!
! if( !returnValue )
! return amount;
! if ( !PyInt_Check( returnValue ) )
{
! Py_DECREF( returnValue );
! return amount;
! }
!
! amount = PyInt_AsLong( returnValue );
! Py_DECREF( returnValue );
! return amount;
! }
!
! bool cPythonScript::onCastSpell( cPlayer *player, unsigned int spell )
! {
! PyHasMethod( "onCastSpell" )
!
! PyObject *tuple = PyTuple_New( 2 );
! PyTuple_SetItem( tuple, 0, PyGetCharObject( player) );
! PyTuple_SetItem( tuple, 1, PyInt_FromLong( spell ) );
!
! return PyEvalMethod( "onCastSpell", tuple );
! }
!
! bool cPythonScript::onCreate( cUObject *object, const QString &definition )
! {
! PyHasMethod( "onCreate" )
!
! PyObject *tuple = PyTuple_New( 2 );
!
! if( object->isChar() )
! PyTuple_SetItem( tuple, 0, PyGetCharObject( (P_CHAR)object ) );
! else if( object->isItem() )
! PyTuple_SetItem( tuple, 0, PyGetItemObject( (P_ITEM)object ) );
!
! PyTuple_SetItem( tuple, 1, PyString_FromString( definition.latin1() ) );
!
! return PyEvalMethod( "onCreate", tuple );
! }
!
! bool cPythonScript::onSpeech( cUObject *listener, P_CHAR talker, const QString &text, const QValueVector< UINT16 >& keywords )
! {
! PyHasMethod( "onSpeech" )
!
! PyObject *tuple = PyTuple_New( 4 ); // Create our args for the python function
! if( isItemSerial( listener->serial() ) )
! PyTuple_SetItem( tuple, 0, PyGetItemObject( (P_ITEM)listener ) );
! else
! PyTuple_SetItem( tuple, 0, PyGetCharObject( (P_CHAR)listener ) );
! PyTuple_SetItem( tuple, 1, PyGetCharObject( talker ) );
! PyTuple_SetItem( tuple, 2, PyString_FromString( text.latin1() ) );
!
! // Convert the keywords into a list
! PyObject *list = PyList_New( 0 );
! for( QValueVector< UINT16 >::const_iterator iter = keywords.begin(); iter != keywords.end(); ++iter )
! PyList_Append( list, PyInt_FromLong( *iter ) );
!
!
! PyTuple_SetItem( tuple, 3, list );
!
! return PyEvalMethod( "onSpeech", tuple );
! }
! bool cPythonScript::onDropOnChar( P_CHAR pChar, P_ITEM pItem )
! {
! PyHasMethod( "onDropOnChar" )
!
! PyObject *tuple = PyTuple_New( 2 );
! PyTuple_SetItem( tuple, 0, PyGetCharObject( pChar ) );
! PyTuple_SetItem( tuple, 1, PyGetItemObject( pItem ) );
! return PyEvalMethod( "onDropOnChar", tuple );
! }
! bool cPythonScript::onDropOnItem( P_ITEM pCont, P_ITEM pItem )
! {
! PyHasMethod( "onDropOnItem" )
!
! PyObject *tuple = PyTuple_New( 2 );
! PyTuple_SetItem( tuple, 0, PyGetItemObject( pCont ) );
! PyTuple_SetItem( tuple, 1, PyGetItemObject( pItem ) );
! return PyEvalMethod( "onDropOnItem", tuple );
}
! bool cPythonScript::onDropOnGround( P_ITEM pItem, const Coord_cl &pos )
{
! PyHasMethod( "onDropOnGround" )
!
! PyObject *tuple = PyTuple_New( 2 );
! PyTuple_SetItem( tuple, 0, PyGetItemObject( pItem ) );
! PyTuple_SetItem( tuple, 1, PyGetCoordObject( pos ) );
! return PyEvalMethod( "onDropOnGround", tuple );
! }
! bool cPythonScript::onPickup( P_CHAR pChar, P_ITEM pItem )
! {
! PyHasMethod( "onPickup" )
!
! PyObject *tuple = PyTuple_New( 2 );
! PyTuple_SetItem( tuple, 0, PyGetCharObject( pChar ) );
! PyTuple_SetItem( tuple, 1, PyGetItemObject( pItem ) );
! return PyEvalMethod( "onPickup", tuple );
}
! bool cPythonScript::onCommand( cUOSocket *socket, const QString &name, const QString &args )
{
! PyHasMethod( "onCommand" )
!
! // Create our args for the python function
! PyObject *tuple = PyTuple_New( 3 );
! PyTuple_SetItem( tuple, 0, PyGetSocketObject( socket ) );
! PyTuple_SetItem( tuple, 1, PyString_FromString( name.latin1() ) );
! PyTuple_SetItem( tuple, 2, PyString_FromString( args.latin1() ) );
!
! return PyEvalMethod( "onCommand", tuple );
! }
! bool cPythonScript::onShowPaperdoll( P_CHAR pChar, P_CHAR pOrigin )
! {
! PyHasMethod( "onShowPaperdoll" )
...
[truncated message content] |