Crossfire Server, Trunk
cfpython_region.c
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* CFPython - A Python module for Crossfire RPG. */
3 /* Version: 2.0beta8 (also known as "Alexander") */
4 /* Contact: yann.chachkoff@myrealbox.com */
5 /*****************************************************************************/
6 /* That code is placed under the GNU General Public Licence (GPL) */
7 /* (C)2001-2005 by Chachkoff Yann (Feel free to deliver your complaints) */
8 /*****************************************************************************/
9 /* CrossFire, A Multiplayer game for X-windows */
10 /* */
11 /* Copyright (C) 2000 Mark Wedel */
12 /* Copyright (C) 1992 Frank Tore Johansen */
13 /* */
14 /* This program is free software; you can redistribute it and/or modify */
15 /* it under the terms of the GNU General Public License as published by */
16 /* the Free Software Foundation; either version 2 of the License, or */
17 /* (at your option) any later version. */
18 /* */
19 /* This program is distributed in the hope that it will be useful, */
20 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
21 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
22 /* GNU General Public License for more details. */
23 /* */
24 /* You should have received a copy of the GNU General Public License */
25 /* along with this program; if not, write to the Free Software */
26 /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 /* */
28 /*****************************************************************************/
29 
30 #include <cfpython.h>
31 
32 static PyObject *Crossfire_Region_GetName(Crossfire_Region *regionptr, void *closure) {
33  (void)closure;
34  return Py_BuildValue("s", cf_region_get_name(regionptr->reg));
35 }
36 
37 static PyObject *Crossfire_Region_GetLongname(Crossfire_Region *regionptr, void *closure) {
38  (void)closure;
39  return Py_BuildValue("s", cf_region_get_longname(regionptr->reg));
40 }
41 
42 static PyObject *Crossfire_Region_GetMessage(Crossfire_Region *regionptr, void *closure) {
43  (void)closure;
44  return Py_BuildValue("s", cf_region_get_message(regionptr->reg));
45 }
46 
47 static PyObject *Crossfire_Region_GetNext(Crossfire_Region *party, void *closure) {
48  (void)closure;
50 }
51 
52 static PyObject *Crossfire_Region_GetParent(Crossfire_Region *party, PyObject *args) {
53  (void)args;
55 }
56 
57 static PyObject *Crossfire_Region_GetJailX(Crossfire_Region *regionptr, void *closure) {
58  (void)closure;
59  return Py_BuildValue("i", cf_region_get_jail_x(regionptr->reg));
60 }
61 
62 static PyObject *Crossfire_Region_GetJailY(Crossfire_Region *regionptr, void *closure) {
63  (void)closure;
64  return Py_BuildValue("i", cf_region_get_jail_y(regionptr->reg));
65 }
66 
67 static PyObject *Crossfire_Region_GetJailPath(Crossfire_Region *regionptr, void *closure) {
68  (void)closure;
69  return Py_BuildValue("s", cf_region_get_jail_path(regionptr->reg));
70 }
71 
72 PyObject *Crossfire_Region_wrap(region *what) {
73  Crossfire_Region *wrapper;
74 
75  /* return None if no object was to be wrapped */
76  if (what == NULL) {
77  Py_INCREF(Py_None);
78  return Py_None;
79  }
80 
81  wrapper = PyObject_NEW(Crossfire_Region, &Crossfire_RegionType);
82  if (wrapper != NULL)
83  wrapper->reg = what;
84  return (PyObject *)wrapper;
85 }
86 
88  return (left->reg < right->reg ? -1 : (left->reg == right->reg ? 0 : 1));
89 }
90 
91 static PyObject *Crossfire_Region_RichCompare(Crossfire_Region *left, Crossfire_Region *right, int op) {
92  int result;
93  if (!left
94  || !right
95  || !PyObject_TypeCheck((PyObject*)left, &Crossfire_RegionType)
96  || !PyObject_TypeCheck((PyObject*)right, &Crossfire_RegionType)) {
97  Py_INCREF(Py_NotImplemented);
98  return Py_NotImplemented;
99  }
101  /* Based on how Python 3.0 (GPL compatible) implements it for internal types: */
102  switch (op) {
103  case Py_EQ:
104  result = (result == 0);
105  break;
106  case Py_NE:
107  result = (result != 0);
108  break;
109  case Py_LE:
110  result = (result <= 0);
111  break;
112  case Py_GE:
113  result = (result >= 0);
114  break;
115  case Py_LT:
116  result = (result == -1);
117  break;
118  case Py_GT:
119  result = (result == 1);
120  break;
121  }
122  return PyBool_FromLong(result);
123 }
124 
125 static PyGetSetDef Region_getseters[] = {
126  { "Name", (getter)Crossfire_Region_GetName, NULL, NULL, NULL },
127  { "Longname", (getter)Crossfire_Region_GetLongname, NULL, NULL, NULL },
128  { "Message", (getter)Crossfire_Region_GetMessage, NULL, NULL, NULL },
129  { "Next", (getter)Crossfire_Region_GetNext, NULL, NULL, NULL },
130  { "JailX", (getter)Crossfire_Region_GetJailX, NULL, NULL, NULL },
131  { "JailY", (getter)Crossfire_Region_GetJailY, NULL, NULL, NULL },
132  { "JailPath", (getter)Crossfire_Region_GetJailPath, NULL, NULL, NULL },
133  { NULL, NULL, NULL, NULL, NULL }
134 };
135 
136 static PyMethodDef RegionMethods[] = {
137  { "GetParent", (PyCFunction)Crossfire_Region_GetParent, METH_NOARGS, NULL },
138  { NULL, NULL, 0, NULL }
139 };
140 
141 /* Our actual Python RegionType */
143  NULL,
144  NULL,
145  PyObject_HashNotImplemented,
146  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
147  "Crossfire regions",
148  (richcmpfunc) Crossfire_Region_RichCompare,
151  NULL,
152  NULL
153  );
Crossfire_Region_GetJailY
static PyObject * Crossfire_Region_GetJailY(Crossfire_Region *regionptr, void *closure)
Definition: cfpython_region.c:62
Crossfire_Region_RichCompare
static PyObject * Crossfire_Region_RichCompare(Crossfire_Region *left, Crossfire_Region *right, int op)
Definition: cfpython_region.c:91
cf_region_get_jail_y
int cf_region_get_jail_y(region *reg)
Definition: plugin_common.c:1979
Crossfire_Region_wrap
PyObject * Crossfire_Region_wrap(region *what)
Definition: cfpython_region.c:72
cf_region_get_jail_path
const char * cf_region_get_jail_path(region *reg)
Definition: plugin_common.c:1994
Crossfire_Region_GetJailPath
static PyObject * Crossfire_Region_GetJailPath(Crossfire_Region *regionptr, void *closure)
Definition: cfpython_region.c:67
Crossfire_Region_GetName
static PyObject * Crossfire_Region_GetName(Crossfire_Region *regionptr, void *closure)
Definition: cfpython_region.c:32
cf_region_get_next
region * cf_region_get_next(region *reg)
Definition: plugin_common.c:1900
Region
Definition: cfcitybell.cpp:39
Crossfire_Region_GetNext
static PyObject * Crossfire_Region_GetNext(Crossfire_Region *party, void *closure)
Definition: cfpython_region.c:47
CF_PYTHON_OBJECT
CF_PYTHON_OBJECT(Region, NULL, NULL, PyObject_HashNotImplemented, Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, "Crossfire regions",(richcmpfunc) Crossfire_Region_RichCompare, RegionMethods, Region_getseters, NULL, NULL)
cf_region_get_parent
region * cf_region_get_parent(region *reg)
Definition: plugin_common.c:1916
Crossfire_Region_GetParent
static PyObject * Crossfire_Region_GetParent(Crossfire_Region *party, PyObject *args)
Definition: cfpython_region.c:52
make_face_from_files.args
args
Definition: make_face_from_files.py:31
rotate-tower.result
bool result
Definition: rotate-tower.py:13
cf_region_get_longname
const char * cf_region_get_longname(region *reg)
Definition: plugin_common.c:1932
cfpython.h
Crossfire_Region
Definition: cfpython_region.h:33
RegionMethods
static PyMethodDef RegionMethods[]
Definition: cfpython_region.c:136
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
Crossfire_Region_GetMessage
static PyObject * Crossfire_Region_GetMessage(Crossfire_Region *regionptr, void *closure)
Definition: cfpython_region.c:42
cf_region_get_message
const char * cf_region_get_message(region *reg)
Definition: plugin_common.c:1948
Crossfire_Region_InternalCompare
static int Crossfire_Region_InternalCompare(Crossfire_Region *left, Crossfire_Region *right)
Definition: cfpython_region.c:87
cf_region_get_jail_x
int cf_region_get_jail_x(region *reg)
Definition: plugin_common.c:1964
Region_getseters
static PyGetSetDef Region_getseters[]
Definition: cfpython_region.c:125
cf_region_get_name
const char * cf_region_get_name(region *reg)
Definition: plugin_common.c:1884
give.op
op
Definition: give.py:33
Crossfire_Region_GetLongname
static PyObject * Crossfire_Region_GetLongname(Crossfire_Region *regionptr, void *closure)
Definition: cfpython_region.c:37
Crossfire_Region_GetJailX
static PyObject * Crossfire_Region_GetJailX(Crossfire_Region *regionptr, void *closure)
Definition: cfpython_region.c:57
Crossfire_RegionType
PyTypeObject Crossfire_RegionType
Crossfire_Region::reg
PyObject_HEAD region * reg
Definition: cfpython_region.h:35
regiondef
Definition: map.h:275