Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3497
Modified Files:
baseregion.h commands.cpp persistentbroker.cpp
pythonscript.cpp pythonscript.h spawnregions.cpp
spawnregions.h wolf.dsp wolfpack.pro
Log Message:
initial implementation for scripted spawn regions ( bug id 154 )
few clean ups
Index: spawnregions.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/spawnregions.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** spawnregions.h 3 Jun 2004 14:42:59 -0000 1.25
--- spawnregions.h 27 Jul 2004 04:15:20 -0000 1.26
***************
*** 34,38 ****
#include <map>
- #include <vector>
class cSpawnRegion : public cBaseRegion
--- 34,37 ----
***************
*** 62,86 ****
// Getters
! QString name( void )
{
return name_;
}
! unsigned int npcs( void )
{
return npcs_.count();
}
! unsigned int items( void )
{
return items_.count();
}
! UI16 maxNpcs( void )
{
return maxNpcAmt_;
}
! UI16 maxItems( void )
{
return maxItemAmt_;
}
QStringList rectangles( void )
{
--- 61,109 ----
// Getters
! QString name( void ) const
{
return name_;
}
!
! unsigned int npcs( void ) const
{
return npcs_.count();
}
!
! unsigned int items( void ) const
{
return items_.count();
}
!
! UI16 maxNpcs( void ) const
{
return maxNpcAmt_;
}
!
! UI16 maxItems( void ) const
{
return maxItemAmt_;
}
+ QStringList npcSections() const
+ {
+ return npcSections_;
+ }
+
+ QStringList itemSections() const
+ {
+ return itemSections_;
+ }
+
+ QPtrList<cUObject> spawnedItems() const
+ {
+ return items_;
+ }
+
+ QPtrList<cUObject> spawnedNpcs() const
+ {
+ return npcs_;
+ }
+
QStringList rectangles( void )
{
***************
*** 95,100 ****
--- 118,127 ----
return rectList;
}
+
private:
virtual void processNode( const cElement* Tag );
+ void spawnSingleNPC();
+ void spawnSingleItem();
+ void onSpawn(cUObject*);
private:
Index: persistentbroker.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/persistentbroker.cpp,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -d -r1.39 -r1.40
*** persistentbroker.cpp 2 Jun 2004 15:04:06 -0000 1.39
--- persistentbroker.cpp 27 Jul 2004 04:15:20 -0000 1.40
***************
*** 246,250 ****
{
if ( s == QString::null )
! return "";
if ( d->sqlite )
--- 246,250 ----
{
if ( s == QString::null )
! return QString("");
if ( d->sqlite )
Index: wolf.dsp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/wolf.dsp,v
retrieving revision 1.266
retrieving revision 1.267
diff -C2 -d -r1.266 -r1.267
*** wolf.dsp 23 May 2004 11:26:28 -0000 1.266
--- wolf.dsp 27 Jul 2004 04:15:20 -0000 1.267
***************
*** 207,211 ****
# Begin Source File
! SOURCE=.\maps\maps.cpp
# End Source File
# Begin Source File
--- 207,211 ----
# Begin Source File
! SOURCE=.\muls\maps.cpp
# End Source File
# Begin Source File
***************
*** 255,262 ****
# Begin Source File
- SOURCE=.\resources.cpp
- # End Source File
- # Begin Source File
-
SOURCE=.\scriptmanager.cpp
# End Source File
--- 255,258 ----
***************
*** 295,303 ****
# Begin Source File
! SOURCE=.\timing.cpp
# End Source File
# Begin Source File
! SOURCE=.\timers.cpp
# End Source File
# Begin Source File
--- 291,299 ----
# Begin Source File
! SOURCE=.\timers.cpp
# End Source File
# Begin Source File
! SOURCE=.\timing.cpp
# End Source File
# Begin Source File
***************
*** 548,551 ****
--- 544,552 ----
# Begin Source File
+ SOURCE=.\targetrequest.h
+ # PROP Ignore_Default_Tool 1
+ # End Source File
+ # Begin Source File
+
SOURCE=.\targetrequests.h
# PROP Ignore_Default_Tool 1
***************
*** 562,571 ****
# Begin Source File
! SOURCE=.\timing.h
# End Source File
# Begin Source File
! SOURCE=.\timers.h
! # PROP Ignore_Default_Tool 1
# End Source File
# Begin Source File
--- 563,572 ----
# Begin Source File
! SOURCE=.\timers.h
! # PROP Ignore_Default_Tool 1
# End Source File
# Begin Source File
! SOURCE=.\timing.h
# End Source File
# Begin Source File
***************
*** 598,606 ****
SOURCE=.\world.h
# End Source File
- # Begin Source File
-
- SOURCE=.\targetrequest.h
- # PROP Ignore_Default_Tool 1
- # End Source File
# End Group
# Begin Group "Resource Files"
--- 599,602 ----
Index: commands.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/commands.cpp,v
retrieving revision 1.250
retrieving revision 1.251
diff -C2 -d -r1.250 -r1.251
*** commands.cpp 17 Jul 2004 12:56:51 -0000 1.250
--- commands.cpp 27 Jul 2004 04:15:19 -0000 1.251
***************
*** 72,76 ****
{
socket->sysMessage( tr( "Access to command '%1' was denied" ).arg( pCommand.lower() ) );
! socket->log( QString( "Access to command '%1' was denied\n" ).arg( pCommand.lower() ) );
return;
}
--- 72,76 ----
{
socket->sysMessage( tr( "Access to command '%1' was denied" ).arg( pCommand.lower() ) );
! socket->log( tr( "Access to command '%1' was denied\n" ).arg( pCommand.lower() ) );
return;
}
***************
*** 78,82 ****
// Dispatch the command
if ( dispatch( socket, pCommand, pArgs ) )
! socket->log( QString( "Used command '%1'.\n" ).arg( command ) );
}
--- 78,82 ----
// Dispatch the command
if ( dispatch( socket, pCommand, pArgs ) )
! socket->log( tr( "Used command '%1'.\n" ).arg( command ) );
}
***************
*** 211,215 ****
if ( args.size() < 1 )
{
! socket->sysMessage( "Usage: set <key> <value>" );
return;
}
--- 211,215 ----
if ( args.size() < 1 )
{
! socket->sysMessage( tr("Usage: set <key> <value>") );
return;
}
***************
*** 536,545 ****
Server::instance()->reload( "accounts" );
}
! if ( subCommand == "python" )
{
Server::instance()->reload( "scripts" );
}
!
! if ( subCommand == "scripts" )
{
Server::instance()->reload( "definitions" );
--- 536,544 ----
Server::instance()->reload( "accounts" );
}
! else if ( subCommand == "python" )
{
Server::instance()->reload( "scripts" );
}
! else if ( subCommand == "scripts" )
{
Server::instance()->reload( "definitions" );
Index: pythonscript.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/pythonscript.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** pythonscript.h 21 Jul 2004 12:42:55 -0000 1.34
--- pythonscript.h 27 Jul 2004 04:15:20 -0000 1.35
***************
*** 84,87 ****
--- 84,88 ----
EVENT_CONTEXTCHECKVISIBLE,
EVENT_CONTEXTCHECKENABLED,
+ EVENT_SPAWN,
EVENT_COUNT,
};
***************
*** 246,251 ****
return object->getPyObject();
} else {
! Py_INCREF(Py_None);
! return Py_None;
}
}
--- 247,251 ----
return object->getPyObject();
} else {
! Py_RETURN_NONE;
}
}
***************
*** 255,260 ****
return PyGetRegionObject(object);
} else {
! Py_INCREF(Py_None);
! return Py_None;
}
}
--- 255,259 ----
return PyGetRegionObject(object);
} else {
! Py_RETURN_NONE;
}
}
***************
*** 264,269 ****
return PyGetAccountObject(object);
} else {
! Py_INCREF(Py_None);
! return Py_None;
}
}
--- 263,267 ----
return PyGetAccountObject(object);
} else {
! Py_RETURN_NONE;
}
}
***************
*** 275,283 ****
inline PyObject *createPyObject(bool value) {
if (value) {
! Py_INCREF(Py_True);
! return Py_True;
} else {
! Py_INCREF(Py_False);
! return Py_False;
}
}
--- 273,279 ----
inline PyObject *createPyObject(bool value) {
if (value) {
! Py_RETURN_TRUE;
} else {
! Py_RETURN_FALSE;
}
}
Index: wolfpack.pro
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/wolfpack.pro,v
retrieving revision 1.198
retrieving revision 1.199
diff -C2 -d -r1.198 -r1.199
*** wolfpack.pro 20 Jul 2004 04:40:51 -0000 1.198
--- wolfpack.pro 27 Jul 2004 04:15:20 -0000 1.199
***************
*** 209,212 ****
--- 209,213 ----
python/pycoord.cpp \
python/pypacket.cpp \
+ python/pyspawnregion.cpp \
python/pyregion.cpp \
python/pytooltip.cpp \
Index: spawnregions.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/spawnregions.cpp,v
retrieving revision 1.63
retrieving revision 1.64
diff -C2 -d -r1.63 -r1.64
*** spawnregions.cpp 19 Jul 2004 14:30:18 -0000 1.63
--- spawnregions.cpp 27 Jul 2004 04:15:20 -0000 1.64
***************
*** 27,32 ****
#include "spawnregions.h"
- #include "definitions.h"
#include "items.h"
#include "defines.h"
--- 27,32 ----
#include "spawnregions.h"
+ #include "definitions.h"
#include "items.h"
#include "defines.h"
***************
*** 40,47 ****
#include "sectors.h"
#include "config.h"
using namespace std;
! // cSpawnRegions
void cSpawnRegion::init( void )
--- 40,52 ----
#include "sectors.h"
#include "config.h"
+ #include "inlines.h"
+ #include "scriptmanager.h"
+ #include "python/pyspawnregion.h"
using namespace std;
! /*****************************************************************************
! cSpawnRegion member functions
! *****************************************************************************/
void cSpawnRegion::init( void )
***************
*** 205,209 ****
bool cSpawnRegion::findValidSpot(Coord_cl& pos) {
// Try up to 100 times.
! for(unsigned int i = 0; i < 100; ++i) {
int rndRectNum = RandomNum( 0, this->rectangles_.size() - 1 );
pos.x = RandomNum( this->rectangles_[rndRectNum].x1, this->rectangles_[rndRectNum].x2 );
--- 210,215 ----
bool cSpawnRegion::findValidSpot(Coord_cl& pos) {
// Try up to 100 times.
! for(unsigned int i = 0; i < 100; ++i)
! {
int rndRectNum = RandomNum( 0, this->rectangles_.size() - 1 );
pos.x = RandomNum( this->rectangles_[rndRectNum].x1, this->rectangles_[rndRectNum].x2 );
***************
*** 254,307 ****
}
! Console::instance()->log( LOG_WARNING, QString( "A problem has occured in spawnregion %1. Couldn't find valid spot." ).arg( this->name_ ) );
return false;
}
! // do one spawn and reset the timer
! void cSpawnRegion::reSpawn( void )
{
! unsigned int i = 0;
! for (i = 0; i < npcsPerCycle_; ++i) {
! if (npcs() < maxNpcAmt_) {
! // spawn a random npc
! // first find a valid position for the npc
! Coord_cl pos;
! if (findValidSpot(pos))
{
! QString NpcSect = this->npcSections_[RandomNum( 1, this->npcSections_.size() ) - 1];
! P_NPC pc = cNPC::createFromScript( NpcSect, pos );
! if (pc)
! {
! pc->setSpawnregion(this);
! if (pc->wanderType() == enFreely)
! {
! pc->setWanderType(enWanderSpawnregion);
! }
! pc->update();
! }
}
}
}
! for ( i = 0; i < this->itemsPerCycle_; i++ )
{
! if ( items() < this->maxItemAmt_ )
{
! // spawn a random item
! // first find a valid position for the item
! Coord_cl pos;
! if ( this->findValidSpot( pos ) )
! {
! QString ItemSect = this->itemSections_[RandomNum( 1, this->itemSections_.size() ) - 1];
! P_ITEM pi = cItem::createFromScript( ItemSect );
! if ( pi != NULL )
! {
! pi->moveTo(pos, true);
! pi->setSpawnregion(this);
! pi->update();
! }
! }
}
}
this->nextTime_ = Server::instance()->time() + RandomNum( this->minTime_, this->maxTime_ ) * MY_CLOCKS_PER_SEC;
--- 260,329 ----
}
! Console::instance()->log( LOG_WARNING, tr( "A problem has occured in spawnregion %1. Couldn't find valid spot." ).arg( this->name_ ) );
return false;
}
! void cSpawnRegion::spawnSingleNPC()
{
! Coord_cl pos;
! if (findValidSpot(pos))
! {
! QString NpcSect = this->npcSections_[RandomNum( 1, this->npcSections_.size() ) - 1];
! P_NPC pc = cNPC::createFromScript( NpcSect, pos );
! if (pc)
! {
! pc->setSpawnregion(this);
! if (pc->wanderType() == enFreely)
{
! pc->setWanderType(enWanderSpawnregion);
}
+ pc->update();
+ onSpawn( pc );
}
}
+ }
! void cSpawnRegion::spawnSingleItem()
! {
! Coord_cl pos;
! if ( findValidSpot( pos ) )
{
! QString ItemSect = this->itemSections_[RandomNum( 1, this->itemSections_.size() ) - 1];
! P_ITEM pi = cItem::createFromScript( ItemSect );
! if ( pi )
{
! pi->moveTo(pos, true);
! pi->setSpawnregion(this);
! pi->update();
! onSpawn( pi );
}
}
+ }
+
+ void cSpawnRegion::onSpawn(cUObject* obj)
+ {
+ cPythonScript* global = ScriptManager::instance()->getGlobalHook( EVENT_CREATE );
+
+ if ( global )
+ {
+ PyObject* args = Py_BuildValue( "NN", PyGetSpawnRegionObject(this), PyGetObjectObject(obj) );
+
+ global->callEventHandler( EVENT_SPAWN, args );
+
+ Py_DECREF( args );
+ }
+ }
+
+ // do one spawn and reset the timer
+ void cSpawnRegion::reSpawn( void )
+ {
+ unsigned int i = 0;
+ for (i = 0; i < npcsPerCycle_; ++i)
+ if (npcs() < maxNpcAmt_)
+ spawnSingleNPC(); // spawn a random npc
+
+ for ( i = 0; i < this->itemsPerCycle_; i++ )
+ if ( items() < this->maxItemAmt_ )
+ spawnSingleItem(); // spawn a random item
this->nextTime_ = Server::instance()->time() + RandomNum( this->minTime_, this->maxTime_ ) * MY_CLOCKS_PER_SEC;
***************
*** 311,351 ****
{
while ( npcs() < maxNpcAmt_ )
! {
! // spawn a random npc
! // first find a valid position for the npc
! Coord_cl pos;
! if ( findValidSpot( pos ) )
! {
! QString NpcSect = npcSections_[RandomNum( 1, static_cast<uint>( this->npcSections_.size() ) ) - 1];
! P_NPC pc = cNPC::createFromScript( NpcSect, pos );
! if ( pc != NULL )
! {
! pc->setSpawnregion(this);
! if (pc->wanderType() == enFreely)
! {
! pc->setWanderType(enWanderSpawnregion);
! }
! pc->update();
! }
! }
! }
while (items() < maxItemAmt_)
! {
! // spawn a random item
! // first find a valid position for the item
! Coord_cl pos;
! if ( findValidSpot( pos ) )
! {
! QString ItemSect = this->itemSections_[RandomNum( 1, this->itemSections_.size() ) - 1];
! P_ITEM pi = cItem::createFromScript( ItemSect );
! if ( pi )
! {
! pi->moveTo(pos, true);
! pi->setSpawnregion(this);
! pi->update();
! }
! }
! }
this->nextTime_ = Server::instance()->time() + RandomNum( this->minTime_, this->maxTime_ ) * MY_CLOCKS_PER_SEC;
--- 333,340 ----
{
while ( npcs() < maxNpcAmt_ )
! spawnSingleNPC();
while (items() < maxItemAmt_)
! spawnSingleItem();
this->nextTime_ = Server::instance()->time() + RandomNum( this->minTime_, this->maxTime_ ) * MY_CLOCKS_PER_SEC;
***************
*** 377,380 ****
--- 366,375 ----
}
+
+ /*****************************************************************************
+ cAllSpawnRegions member functions
+ *****************************************************************************/
+
+
void cAllSpawnRegions::check( void )
{
Index: pythonscript.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/pythonscript.cpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -d -r1.43 -r1.44
*** pythonscript.cpp 21 Jul 2004 12:42:55 -0000 1.43
--- pythonscript.cpp 27 Jul 2004 04:15:20 -0000 1.44
***************
*** 501,504 ****
--- 501,512 ----
"onContextCheckEnabled",
+ /*
+ \event onSpawn
+ \param region The spawn region that generated the object.
+ \param object The object just spawned.
+ \condition Triggered when a spawnregion creates a new object, either NPC or item.
+ */
+ "onSpawn",
+
0
};
Index: baseregion.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/baseregion.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** baseregion.h 2 Jun 2004 15:04:03 -0000 1.24
--- baseregion.h 27 Jul 2004 04:15:08 -0000 1.25
***************
*** 57,61 ****
cBaseRegion() : parent_( 0 )
{
! ;}
cBaseRegion( const cElement* tag, cBaseRegion* pParent )
--- 57,61 ----
cBaseRegion() : parent_( 0 )
{
! }
cBaseRegion( const cElement* tag, cBaseRegion* pParent )
|