[crossfire] Python bindings and forces
Mark Wedel
mwedel at sonic.net
Wed Jun 1 01:24:24 CDT 2005
I'm not sure, since I haven't played with the python stuff much.
But one thing to be aware - the python code is in a plugin shared library, and
the server loads that library from someplace where prefix points to.
So if you do what I often do, which is run the server directory from the build
directory and don't run make install, you'll continue to have the old plugin
code until you do a make install.
One other note on your change - if you are modifying the object speed, you
need to add a call to update_ob_speed, otherwise the object won't be processed
and do anything.
Alex Schultz wrote:
>
Hi,
>
>
Today I was tring to extend the "CreateInvisibleObjectInside" function
>
in the python bindings to also allow limited duration forces to be
>
created in the same manner that markers can do that. So I attempted to
>
add another optional parameter to allow the duration to set (in the same
>
measurement as the food parameter of marker objects). However when I try
>
to call it with:
>
>
force = CFPython.CreateInvisibleObjectInside(activator, forcename, 1.00)
>
>
the script crashes with:
>
>
TypeError: function takes exactly 2 arguments (3 given)
>
>
I've attached the modifications that I've tried to make to it here.
>
Anybody have any ideas?
>
>
Thanks,
>
Alex Schultz
>
>
>
>
------------------------------------------------------------------------
>
>
Index: plugin/plugin_python.c
>
===================================================================
>
RCS file: /cvsroot/crossfire/crossfire/plugin/plugin_python.c,v
>
retrieving revision 1.62
>
diff -C10 -r1.62 plugin_python.c
>
*** plugin/plugin_python.c 20 May 2005 19:28:02 -0000 1.62
>
--- plugin/plugin_python.c 1 Jun 2005 04:28:48 -0000
>
***************
>
*** 2362,2413 ****
>
{
>
if(tmp2->type == FORCE && tmp2->slaying && !strcmp(tmp2->slaying,id))
>
break;
>
};
>
>
return Py_BuildValue("l",(long)(tmp2));
>
};
>
>
/*****************************************************************************/
>
/* Name : CFCreateInvisibleObjectInside */
>
! /* Python : CFPython.CreateInvisibleObjectInside(object,string) */
>
/*****************************************************************************/
>
static PyObject* CFCreateInvisibleObjectInside(PyObject* self, PyObject* args)
>
{
>
long whereptr;
>
char* txt;
>
char txt2[6];
>
object *myob;
>
object *where;
>
CFParm* CFR;
>
>
! if (!PyArg_ParseTuple(args,"ls",&whereptr,&txt))
>
return NULL;
>
>
CHECK_OBJ(whereptr);
>
>
where = (object *)(whereptr);
>
>
strcpy(txt2,"force");
>
>
GCFP.Value[0] = (void *)(txt2);
>
CFR = (PlugHooks[HOOK_GETARCHETYPE])(&GCFP);
>
myob = (object *)(CFR->Value[0]);
>
PyFreeMemory( CFR );
>
>
if(strncmp(query_name(myob), "singluarity", 11) == 0)
>
{
>
PyFreeObject(myob);
>
set_exception("can't find archetype 'force'");
>
return NULL;
>
}
>
! myob->speed = 0.0;
>
GCFP.Value[0] = (void *)(myob);
>
(PlugHooks[HOOK_UPDATESPEED])(&GCFP);
>
>
if (myob->slaying != NULL)
>
DELETE_STRING(myob->slaying);
>
myob->slaying = add_string(txt);
>
myob = insert_ob_in_ob(myob, where);
>
>
GCFP.Value[0] = (void *)(where);
>
GCFP.Value[1] = (void *)(myob);
>
--- 2366,2422 ----
>
{
>
if(tmp2->type == FORCE && tmp2->slaying && !strcmp(tmp2->slaying,id))
>
break;
>
};
>
>
return Py_BuildValue("l",(long)(tmp2));
>
};
>
>
/*****************************************************************************/
>
/* Name : CFCreateInvisibleObjectInside */
>
! /* Python : CFPython.CreateInvisibleObjectInside(object,string[,food]) */
>
/*****************************************************************************/
>
static PyObject* CFCreateInvisibleObjectInside(PyObject* self, PyObject* args)
>
{
>
long whereptr;
>
char* txt;
>
char txt2[6];
>
+ double lspeed = 0;
>
object *myob;
>
object *where;
>
CFParm* CFR;
>
>
! if (!PyArg_ParseTuple(args,"ls|d",&whereptr,&txt,&lspeed))
>
return NULL;
>
>
CHECK_OBJ(whereptr);
>
>
where = (object *)(whereptr);
>
>
strcpy(txt2,"force");
>
>
GCFP.Value[0] = (void *)(txt2);
>
CFR = (PlugHooks[HOOK_GETARCHETYPE])(&GCFP);
>
myob = (object *)(CFR->Value[0]);
>
PyFreeMemory( CFR );
>
>
if(strncmp(query_name(myob), "singluarity", 11) == 0)
>
{
>
PyFreeObject(myob);
>
set_exception("can't find archetype 'force'");
>
return NULL;
>
}
>
! myob->speed = 0;
>
! if (lspeed) {
>
! myob->speed = 0.01;
>
! myob->speed_left = -(lspeed);
>
! }
>
GCFP.Value[0] = (void *)(myob);
>
(PlugHooks[HOOK_UPDATESPEED])(&GCFP);
>
>
if (myob->slaying != NULL)
>
DELETE_STRING(myob->slaying);
>
myob->slaying = add_string(txt);
>
myob = insert_ob_in_ob(myob, where);
>
>
GCFP.Value[0] = (void *)(where);
>
GCFP.Value[1] = (void *)(myob);
>
>
>
------------------------------------------------------------------------
>
>
_______________________________________________
>
crossfire mailing list
>
crossfire at metalforge.org
>
http://mailman.metalforge.org/mailman/listinfo/crossfire
More information about the crossfire
mailing list