Debian Codegraph @

plugins/cfpython/cfpython_region.c

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*****************************************************************************/
2 /* CFPython - A Python module for Crossfire RPG. */
3 /* Version: 2.0beta8 (also known as "Alexander") */
4 /* Contact: [email protected] */
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 return Py_BuildValue("s", cf_region_get_name(regionptr->reg));
34 }
35
36 static PyObject *Crossfire_Region_GetLongname(Crossfire_Region *regionptr, void *closure) {
37 return Py_BuildValue("s", cf_region_get_longname(regionptr->reg));
38 }
39
40 static PyObject *Crossfire_Region_GetMessage(Crossfire_Region *regionptr, void *closure) {
41 return Py_BuildValue("s", cf_region_get_message(regionptr->reg));
42 }
43
44 static PyObject *Crossfire_Region_GetNext(Crossfire_Region *party, void *closure) {
45 return Crossfire_Region_wrap(cf_region_get_next(party->reg));
46 }
47
48 static PyObject *Crossfire_Region_GetParent(Crossfire_Region *party, PyObject *args) {
49 return Crossfire_Region_wrap(cf_region_get_parent(party->reg));
50 }
51
52 static PyObject *Crossfire_Region_GetJailX(Crossfire_Region *regionptr, void *closure) {
53 return Py_BuildValue("i", cf_region_get_jail_x(regionptr->reg));
54 }
55
56 static PyObject *Crossfire_Region_GetJailY(Crossfire_Region *regionptr, void *closure) {
57 return Py_BuildValue("i", cf_region_get_jail_y(regionptr->reg));
58 }
59
60 static PyObject *Crossfire_Region_GetJailPath(Crossfire_Region *regionptr, void *closure) {
61 return Py_BuildValue("s", cf_region_get_jail_path(regionptr->reg));
62 }
63
64 PyObject *Crossfire_Region_wrap(region *what) {
65 Crossfire_Region *wrapper;
66
67 /* return None if no object was to be wrapped */
68 if (what == NULL) {
69 Py_INCREF(Py_None);
70 return Py_None;
71 }
72
73 wrapper = PyObject_NEW(Crossfire_Region, &Crossfire_RegionType);
74 if (wrapper != NULL)
75 wrapper->reg = what;
76 return (PyObject *)wrapper;
77 }
78
79 static int Crossfire_Region_InternalCompare(Crossfire_Region *left, Crossfire_Region *right) {
80 return (left->reg < right->reg ? -1 : (left->reg == right->reg ? 0 : 1));
81 }
82
83 static PyObject *Crossfire_Region_RichCompare(Crossfire_Region *left, Crossfire_Region *right, int op) {
84 int result;
85 if (!left
86 || !right
87 || !PyObject_TypeCheck((PyObject*)left, &Crossfire_RegionType)
88 || !PyObject_TypeCheck((PyObject*)right, &Crossfire_RegionType)) {
89 Py_INCREF(Py_NotImplemented);
90 return Py_NotImplemented;
91 }
92 result = Crossfire_Region_InternalCompare(left, right);
93 /* Based on how Python 3.0 (GPL compatible) implements it for internal types: */
94 switch (op) {
95 case Py_EQ:
96 result = (result == 0);
97 break;
98 case Py_NE:
99 result = (result != 0);
100 break;
101 case Py_LE:
102 result = (result <= 0);
103 break;
104 case Py_GE:
105 result = (result >= 0);
106 break;
107 case Py_LT:
108 result = (result == -1);
109 break;
110 case Py_GT:
111 result = (result == 1);
112 break;
113 }
114 return PyBool_FromLong(result);
115 }
116
117 static PyGetSetDef Region_getseters[] = {
118 { "Name", (getter)Crossfire_Region_GetName, NULL, NULL, NULL },
119 { "Longname", (getter)Crossfire_Region_GetLongname, NULL, NULL, NULL },
120 { "Message", (getter)Crossfire_Region_GetMessage, NULL, NULL, NULL },
121 { "Next", (getter)Crossfire_Region_GetNext, NULL, NULL, NULL },
122 { "JailX", (getter)Crossfire_Region_GetJailX, NULL, NULL, NULL },
123 { "JailY", (getter)Crossfire_Region_GetJailY, NULL, NULL, NULL },
124 { "JailPath", (getter)Crossfire_Region_GetJailPath, NULL, NULL, NULL },
125 { NULL, NULL, NULL, NULL, NULL }
126 };
127
128 static PyMethodDef RegionMethods[] = {
129 { "GetParent", (PyCFunction)Crossfire_Region_GetParent, METH_NOARGS, NULL },
130 { NULL, NULL, 0, NULL }
131 };
132
133 /* Our actual Python ArchetypeType */
134 PyTypeObject Crossfire_RegionType = {
135 #ifdef IS_PY3K
136 /* See http://bugs.python.org/issue4385 */
137 PyVarObject_HEAD_INIT(NULL, 0)
138 #else
139 PyObject_HEAD_INIT(NULL)
140 0, /* ob_size*/
141 #endif
142 "Crossfire.Region", /* tp_name*/
143 sizeof(Crossfire_Region), /* tp_basicsize*/
144 0, /* tp_itemsize*/
145 NULL, /* tp_dealloc*/
146 NULL, /* tp_print*/
147 NULL, /* tp_getattr*/
148 NULL, /* tp_setattr*/
149 #ifdef IS_PY3K
150 NULL, /* tp_reserved */
151 #else
152 (cmpfunc)Crossfire_Region_InternalCompare, /* tp_compare*/
153 #endif
154 NULL, /* tp_repr*/
155 NULL, /* tp_as_number*/
156 NULL, /* tp_as_sequence*/
157 NULL, /* tp_as_mapping*/
158 PyObject_HashNotImplemented, /* tp_hash */
159 NULL, /* tp_call*/
160 NULL, /* tp_str*/
161 PyObject_GenericGetAttr, /* tp_getattro*/
162 PyObject_GenericSetAttr, /* tp_setattro*/
163 NULL, /* tp_as_buffer*/
164 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags*/
165 "Crossfire regions", /* tp_doc */
166 NULL, /* tp_traverse */
167 NULL, /* tp_clear */
168 (richcmpfunc)Crossfire_Region_RichCompare, /* tp_richcompare */
169 0, /* tp_weaklistoffset */
170 NULL, /* tp_iter */
171 NULL, /* tp_iternext */
172 RegionMethods, /* tp_methods */
173 NULL, /* tp_members */
174 Region_getseters, /* tp_getset */
175 NULL, /* tp_base */
176 NULL, /* tp_dict */
177 NULL, /* tp_descr_get */
178 NULL, /* tp_descr_set */
179 0, /* tp_dictoffset */
180 NULL, /* tp_init */
181 NULL, /* tp_alloc */
182 NULL, /* tp_new */
183 NULL, /* tp_free */
184 NULL, /* tp_is_gc */
185 NULL, /* tp_bases */
186 NULL, /* tp_mro */
187 NULL, /* tp_cache */
188 NULL, /* tp_subclasses */
189 NULL, /* tp_weaklist */
190 NULL, /* tp_del */
191 };