Update of /cvsroot/wpdev/wolfpack/python
In directory sc8-pr-cvs1:/tmp/cvs-serv21566/python
Modified Files:
global.cpp
Added Files:
worlditerator.cpp worlditerator.h
Log Message:
Added Item and Char iterators to python
--- NEW FILE: worlditerator.cpp ---
//==================================================================================
//
// Wolfpack Emu (WP)
// UO Server Emulation Program
//
// Copyright 2001-2003 by holders identified in authors.txt
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Palace - Suite 330, Boston, MA 02111-1307, USA.
//
// * In addition to that license, if you are running this program or modified
// * versions of it on a public system you HAVE TO make the complete source of
// * the version used by you available or provide people with a location to
// * download it.
//
//
//
// Wolfpack Homepage: http://wpdev.sf.net/
//==================================================================================
#include "worlditerator.h"
#include "../world.h"
typedef struct {
PyObject_HEAD;
cItemIterator *iter;
} wpItemIterator;
static void wpItemIteratorDealloc( PyObject* self )
{
delete ((wpItemIterator*)self)->iter;
PyObject_Del( self );
}
static PyObject *wpItemIterator_getAttr( wpItemIterator *self, char *name )
{
if( !strcmp( name, "first" ) )
return PyGetItemObject( self->iter->first() );
else if( !strcmp( name, "next" ) )
return PyGetItemObject( self->iter->next() );
return PyFalse;
}
static PyTypeObject wpItemIteratorType = {
PyObject_HEAD_INIT(NULL)
0,
"wpItemIterator",
sizeof(wpItemIteratorType),
0,
wpItemIteratorDealloc,
0,
(getattrfunc)wpItemIterator_getAttr,
0,
0,
0,
0,
0,
};
PyObject* PyGetItemIterator()
{
wpItemIterator *returnVal = PyObject_New( wpItemIterator, &wpItemIteratorType );
returnVal->iter = new cItemIterator;
return (PyObject*)returnVal;
}
/*
* Character Region Iterator
*/
typedef struct {
PyObject_HEAD;
cCharIterator *iter;
} wpCharIterator;
static void wpCharIteratorDealloc( PyObject* self )
{
delete ((wpCharIterator*)self)->iter;
PyObject_Del( self );
}
static PyObject *wpCharIterator_getAttr( wpCharIterator *self, char *name )
{
if( !strcmp( name, "first" ) )
return PyGetCharObject( self->iter->first() );
else if( !strcmp( name, "next" ) )
return PyGetCharObject( self->iter->next() );
return PyFalse;
}
static PyTypeObject wpCharIteratorType = {
PyObject_HEAD_INIT(NULL)
0,
"wpIteratorChars",
sizeof(wpCharIteratorType),
0,
wpCharIteratorDealloc,
0,
(getattrfunc)wpCharIterator_getAttr,
0,
0,
0,
0,
0,
};
PyObject* PyGetCharIterator()
{
wpCharIterator *returnVal = PyObject_New( wpCharIterator, &wpCharIteratorType );
returnVal->iter = new cCharIterator;
return (PyObject*)returnVal;
}
--- NEW FILE: worlditerator.h ---
//==================================================================================
//
// Wolfpack Emu (WP)
// UO Server Emulation Program
//
// Copyright 2001-2003 by holders identified in authors.txt
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Palace - Suite 330, Boston, MA 02111-1307, USA.
//
// * In addition to that license, if you are running this program or modified
// * versions of it on a public system you HAVE TO make the complete source of
// * the version used by you available or provide people with a location to
// * download it.
//
//
//
// Wolfpack Homepage: http://wpdev.sf.net/
//==================================================================================
#ifndef __WORLDITERATOR_H__
#define __WORLDITERATOR_H__
#include "utilities.h"
#include "../world.h"
PyObject* PyGetCharIterator();
PyObject* PyGetItemIterator();
#endif
Index: global.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/python/global.cpp,v
retrieving revision 1.83
retrieving revision 1.84
diff -C2 -d -r1.83 -r1.84
*** global.cpp 2 Sep 2003 02:06:34 -0000 1.83
--- global.cpp 2 Sep 2003 02:31:32 -0000 1.84
***************
*** 65,68 ****
--- 65,69 ----
#include "utilities.h"
#include "tempeffect.h"
+ #include "worlditerator.h"
// Library Includes
***************
*** 550,553 ****
--- 551,574 ----
/*!
+ Returns an iterator for all items in the world
+ */
+ static PyObject *wpAllItemsIterator( PyObject* self, PyObject* args )
+ {
+ Q_UNUSED(args);
+ Q_UNUSED(self);
+ return PyGetItemIterator();
+ }
+
+ /*!
+ Returns an iterator for all items in the world
+ */
+ static PyObject *wpAllCharsIterator( PyObject* self, PyObject* args )
+ {
+ Q_UNUSED(args);
+ Q_UNUSED(self);
+ return PyGetCharIterator();
+ }
+
+ /*!
Returns a list of all chars serials
*/
***************
*** 671,681 ****
Q_UNUSED(self);
// Minimum is x, y, map
! if( !checkArgInt( 0 ) || !checkArgInt( 1 ) || !checkArgInt( 2 ) )
! {
! PyErr_BadArgument();
return 0;
- }
! map_st mTile = Map->seekMap( Coord_cl( getArgInt( 0 ), getArgInt( 1 ), 0, getArgInt( 2 ) ) );
PyObject *dict = PyDict_New();
--- 692,700 ----
Q_UNUSED(self);
// Minimum is x, y, map
! uint x = 0, y = 0, map = 0;
! if ( !PyArg_ParseTuple( args, "iii:wolfpack.map", &x, &y, &map ) )
return 0;
! map_st mTile = Map->seekMap( Coord_cl( x, y, 0, map ) );
PyObject *dict = PyDict_New();
***************
*** 1106,1109 ****
--- 1125,1130 ----
{ "hasmap", wpHasMap, METH_VARARGS, "Returns true if the map specified is present" },
{ "items", wpItems, METH_VARARGS, "Returns a list of items in a specific sector." },
+ { "itemiterator", wpAllItemsIterator, METH_NOARGS, "Returns an iterator for all items in the world." },
+ { "chariterator", wpAllCharsIterator, METH_NOARGS, "Returns an iterator for all chars in the world." },
{ "chars", wpChars, METH_VARARGS, "Returns a list of chars in a specific sector." },
{ "allcharsserials", wpAllCharsSerials, METH_VARARGS, "Returns a list of all chars serials" },
|