version 1.9 | | version 1.10 |
---|
| | |
/* */ /*****************************************************************************/ | | /* */ /*****************************************************************************/ |
#include <cfpython.h> | | #include <cfpython.h> |
#include <cfpython_map_private.h> | | #include <cfpython_map_private.h> |
| | #include <hashtable.h> |
| | |
| | /* Table for keeping track of which PyObject goes with with Crossfire object */ |
| | static ptr_assoc_table map_assoc_table; |
| | |
| | /* Helper functions for dealing with object_assoc_table */ |
| | void init_map_assoc_table() { |
| | init_ptr_assoc_table(map_assoc_table); |
| | } |
| | static void add_map_assoc(mapstruct *key, Crossfire_Map *value) { |
| | add_ptr_assoc(map_assoc_table, key, value); |
| | } |
| | static PyObject *find_assoc_pymap(mapstruct *key) { |
| | return (PyObject*)find_assoc_value(map_assoc_table, key); |
| | } |
| | static void free_map_assoc(mapstruct *key) { |
| | free_ptr_assoc(map_assoc_table, key); |
| | } |
| | |
static PyObject* Map_GetDifficulty(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetDifficulty(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_difficulty(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_difficulty(whoptr->map)); |
} | | } |
static PyObject* Map_GetPath(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetPath(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("s", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_PATH)); | | return Py_BuildValue("s", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_PATH)); |
} | | } |
static PyObject* Map_GetTempName(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetTempName(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("s", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_TMPNAME)); | | return Py_BuildValue("s", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_TMPNAME)); |
} | | } |
static PyObject* Map_GetName(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetName(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("s", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_NAME)); | | return Py_BuildValue("s", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_NAME)); |
} | | } |
static PyObject* Map_GetResetTime(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetResetTime(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_reset_time(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_reset_time(whoptr->map)); |
} | | } |
static PyObject* Map_GetResetTimeout(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetResetTimeout(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_reset_timeout(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_reset_timeout(whoptr->map)); |
} | | } |
static PyObject* Map_GetPlayers(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetPlayers(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_players(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_players(whoptr->map)); |
} | | } |
static PyObject* Map_GetLight(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetLight(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", *(int*)cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_LIGHT)); | | return Py_BuildValue("i", *(int*)cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_LIGHT)); |
} | | } |
static PyObject* Map_GetDarkness(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetDarkness(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_darkness(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_darkness(whoptr->map)); |
} | | } |
static PyObject* Map_GetWidth(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetWidth(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_width(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_width(whoptr->map)); |
} | | } |
static PyObject* Map_GetHeight(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetHeight(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_height(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_height(whoptr->map)); |
} | | } |
static PyObject* Map_GetEnterX(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetEnterX(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_ENTER_X)); | | return Py_BuildValue("i", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_ENTER_X)); |
} | | } |
static PyObject* Map_GetEnterY(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetEnterY(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_enter_x(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_enter_x(whoptr->map)); |
} | | } |
static PyObject* Map_GetTemperature(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetTemperature(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_temperature(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_temperature(whoptr->map)); |
} | | } |
static PyObject* Map_GetPressure(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetPressure(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_pressure(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_pressure(whoptr->map)); |
} | | } |
static PyObject* Map_GetHumidity(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetHumidity(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_humidity(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_humidity(whoptr->map)); |
} | | } |
static PyObject* Map_GetWindSpeed(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetWindSpeed(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_windspeed(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_windspeed(whoptr->map)); |
} | | } |
static PyObject* Map_GetWindDir(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetWindDir(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_winddir(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_winddir(whoptr->map)); |
} | | } |
static PyObject* Map_GetSky(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetSky(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_sky(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_sky(whoptr->map)); |
} | | } |
static PyObject* Map_GetWPartX(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetWPartX(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_wpartx(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_wpartx(whoptr->map)); |
} | | } |
static PyObject* Map_GetWPartY(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetWPartY(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("i", cf_map_get_wparty(whoptr->map)); | | return Py_BuildValue("i", cf_map_get_wparty(whoptr->map)); |
} | | } |
static PyObject* Map_GetMessage(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetMessage(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Py_BuildValue("s", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_MESSAGE)); | | return Py_BuildValue("s", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_MESSAGE)); |
} | | } |
| | |
static PyObject* Map_GetRegion(Crossfire_Map* whoptr, void* closure) | | static PyObject* Map_GetRegion(Crossfire_Map* whoptr, void* closure) |
{ | | { |
| | MAPEXISTCHECK(whoptr); |
return Crossfire_Region_wrap(cf_map_get_property(whoptr->map,CFAPI_MAP_PROP_REGION)); | | return Crossfire_Region_wrap(cf_map_get_property(whoptr->map,CFAPI_MAP_PROP_REGION)); |
} | | } |
| | |
| | |
if (!PyArg_ParseTuple(args,"s|i",&message,&color)) | | if (!PyArg_ParseTuple(args,"s|i",&message,&color)) |
return NULL; | | return NULL; |
| | |
| | MAPEXISTCHECK(map); |
| | |
cf_map_message(map->map, message, color); | | cf_map_message(map->map, message, color); |
| | |
Py_INCREF(Py_None); | | Py_INCREF(Py_None); |
| | |
if (!PyArg_ParseTuple(args,"ii",&x,&y)) | | if (!PyArg_ParseTuple(args,"ii",&x,&y)) |
return NULL; | | return NULL; |
| | |
| | MAPEXISTCHECK(map); |
| | |
val = cf_map_get_object_at(map->map,x,y); | | val = cf_map_get_object_at(map->map,x,y); |
return Crossfire_Object_wrap(val); | | return Crossfire_Object_wrap(val); |
} | | } |
| | |
object* op; | | object* op; |
if (!PyArg_ParseTuple(args,"sii",&txt,&x,&y)) | | if (!PyArg_ParseTuple(args,"sii",&txt,&x,&y)) |
return NULL; | | return NULL; |
| | |
| | MAPEXISTCHECK(map); |
| | |
op = cf_create_object_by_name(txt); | | op = cf_create_object_by_name(txt); |
if (op == NULL) | | if (op == NULL) |
{ | | { |
| | |
if (!PyArg_ParseTuple(args,"s(ii)",&what,&x,&y)) | | if (!PyArg_ParseTuple(args,"s(ii)",&what,&x,&y)) |
return NULL; | | return NULL; |
| | |
| | MAPEXISTCHECK(map); |
| | |
/* make sure the map is swapped in */ | | /* make sure the map is swapped in */ |
if (map->map->in_memory != MAP_IN_MEMORY) | | if (map->map->in_memory != MAP_IN_MEMORY) |
{ | | { |
| | |
} | | } |
static PyObject* Map_Next(Crossfire_Map* map, PyObject* args) | | static PyObject* Map_Next(Crossfire_Map* map, PyObject* args) |
{ | | { |
| | MAPEXISTCHECK(map); |
return Crossfire_Map_wrap(cf_map_get_property(map->map,CFAPI_MAP_PROP_NEXT)); | | return Crossfire_Map_wrap(cf_map_get_property(map->map,CFAPI_MAP_PROP_NEXT)); |
} | | } |
| | |
| | |
if (!PyArg_ParseTuple(args,"O!ii", &Crossfire_ObjectType, &what, &x, &y)) | | if (!PyArg_ParseTuple(args,"O!ii", &Crossfire_ObjectType, &what, &x, &y)) |
return NULL; | | return NULL; |
| | |
| | MAPEXISTCHECK(map); |
| | |
return Crossfire_Object_wrap(cf_map_insert_object(map->map, what->obj, x, y)); | | return Crossfire_Object_wrap(cf_map_insert_object(map->map, what->obj, x, y)); |
} | | } |
| | |
static int Map_InternalCompare(Crossfire_Map* left, Crossfire_Map* right) | | static int Map_InternalCompare(Crossfire_Map* left, Crossfire_Map* right) |
{ | | { |
| | MAPEXISTCHECK_INT(left); |
| | MAPEXISTCHECK_INT(right); |
return left->map < right->map ? -1 : ( left->map == right->map ? 0 : 1 ); | | return left->map < right->map ? -1 : ( left->map == right->map ? 0 : 1 ); |
} | | } |
| | |
/* Legacy code: convert to long so that non-object functions work correctly */ | | /* Legacy code: convert to long so that non-object functions work correctly */ |
static PyObject* Crossfire_Map_Long( PyObject* obj ) | | static PyObject* Crossfire_Map_Long( PyObject* obj ) |
{ | | { |
return Py_BuildValue("l", ((Crossfire_Object*)obj)->obj); | | MAPEXISTCHECK((Crossfire_Map*)obj); |
| | return Py_BuildValue("l", ((Crossfire_Map*)obj)->map); |
} | | } |
| | |
static PyObject* Crossfire_Map_Int( PyObject* obj ) | | static PyObject* Crossfire_Map_Int( PyObject* obj ) |
{ | | { |
return Py_BuildValue("i", ((Crossfire_Object*)obj)->obj); | | MAPEXISTCHECK((Crossfire_Map*)obj); |
| | return Py_BuildValue("i", ((Crossfire_Map*)obj)->map); |
} | | } |
| | |
/** | | /** |
| | |
return (PyObject *)self; | | return (PyObject *)self; |
} | | } |
| | |
| | static void Crossfire_Map_dealloc(PyObject *obj) |
| | { |
| | Crossfire_Map *self; |
| | self = (Crossfire_Map *)obj; |
| | if(self) { |
| | if (self->map && self->valid) { |
| | free_map_assoc(self->map); |
| | } |
| | self->ob_type->tp_free(obj); |
| | } |
| | } |
| | |
| | void Handle_Map_Unload_Hook(Crossfire_Map *map) { |
| | map->valid = 0; |
| | free_map_assoc(map->map); |
| | } |
| | |
PyObject *Crossfire_Map_wrap(mapstruct *what) | | PyObject *Crossfire_Map_wrap(mapstruct *what) |
{ | | { |
Crossfire_Map *wrapper; | | Crossfire_Map *wrapper; |
| | |
return Py_None; | | return Py_None; |
} | | } |
| | |
| | wrapper = (Crossfire_Map*)find_assoc_pymap(what); |
| | if (!wrapper) { |
wrapper = PyObject_NEW(Crossfire_Map, &Crossfire_MapType); | | wrapper = PyObject_NEW(Crossfire_Map, &Crossfire_MapType); |
if(wrapper != NULL) | | if(wrapper != NULL) { |
wrapper->map = what; | | wrapper->map = what; |
| | wrapper->valid = 1; |
| | add_map_assoc(what, wrapper); |
| | } |
| | } else { |
| | Py_INCREF(wrapper); |
| | } |
| | |
return (PyObject *)wrapper; | | return (PyObject *)wrapper; |
} | | } |
| | |