Crossfire Server, Trunk  R20513
cfpython_archetype.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_Archetype_GetName(Crossfire_Archetype *whoptr, void *closure) {
33  return Py_BuildValue("s", cf_archetype_get_name(whoptr->arch));
34 }
35 
36 static PyObject *Crossfire_Archetype_GetNext(Crossfire_Archetype *who, void *closure) {
38 }
39 
40 static PyObject *Crossfire_Archetype_GetMore(Crossfire_Archetype *who, void *closure) {
42 }
43 
44 static PyObject *Crossfire_Archetype_GetHead(Crossfire_Archetype *who, void *closure) {
46 }
47 
48 static PyObject *Crossfire_Archetype_GetClone(Crossfire_Archetype *who, void *closure) {
50 }
51 
52 static PyObject *Crossfire_Archetype_GetNewObject(Crossfire_Archetype *who, PyObject *args) {
54 }
55 
57  Crossfire_Archetype *wrapper;
58 
59  /* return None if no object was to be wrapped */
60  if (what == NULL) {
61  Py_INCREF(Py_None);
62  return Py_None;
63  }
64 
65  wrapper = PyObject_NEW(Crossfire_Archetype, &Crossfire_ArchetypeType);
66  if (wrapper != NULL)
67  wrapper->arch = what;
68  return (PyObject *)wrapper;
69 }
70 
72  return (left->arch < right->arch ? -1 : (left->arch == right->arch ? 0 : 1));
73 }
74 
76  int result;
77  if (!left
78  || !right
79  || !PyObject_TypeCheck((PyObject*)left, &Crossfire_ArchetypeType)
80  || !PyObject_TypeCheck((PyObject*)right, &Crossfire_ArchetypeType)) {
81  Py_INCREF(Py_NotImplemented);
82  return Py_NotImplemented;
83  }
84  result = Crossfire_Archetype_InternalCompare(left, right);
85  /* Based on how Python 3.0 (GPL compatible) implements it for internal types: */
86  switch (op) {
87  case Py_EQ:
88  result = (result == 0);
89  break;
90  case Py_NE:
91  result = (result != 0);
92  break;
93  case Py_LE:
94  result = (result <= 0);
95  break;
96  case Py_GE:
97  result = (result >= 0);
98  break;
99  case Py_LT:
100  result = (result == -1);
101  break;
102  case Py_GT:
103  result = (result == 1);
104  break;
105  }
106  return PyBool_FromLong(result);
107 }
108 
109 static PyGetSetDef Archetype_getseters[] = {
110  { "Name", (getter)Crossfire_Archetype_GetName, NULL, NULL, NULL },
111  { "Next", (getter)Crossfire_Archetype_GetNext, NULL, NULL, NULL },
112  { "More", (getter)Crossfire_Archetype_GetMore, NULL, NULL, NULL },
113  { "Head", (getter)Crossfire_Archetype_GetHead, NULL, NULL, NULL },
114  { "Clone", (getter)Crossfire_Archetype_GetClone, NULL, NULL, NULL },
115  { NULL, NULL, NULL, NULL, NULL }
116 };
117 
118 static PyMethodDef ArchetypeMethods[] = {
119  { "NewObject", (PyCFunction)Crossfire_Archetype_GetNewObject, METH_NOARGS, NULL },
120  { NULL, NULL, 0, NULL }
121 };
122 
123 /* Our actual Python ArchetypeType */
124 PyTypeObject Crossfire_ArchetypeType = {
125 #ifdef IS_PY3K
126  /* See http://bugs.python.org/issue4385 */
127  PyVarObject_HEAD_INIT(NULL, 0)
128 #else
129  PyObject_HEAD_INIT(NULL)
130  0, /* ob_size*/
131 #endif
132  "Crossfire.Archetype", /* tp_name*/
133  sizeof(Crossfire_Archetype), /* tp_basicsize*/
134  0, /* tp_itemsize*/
135  NULL, /* tp_dealloc*/
136  NULL, /* tp_print*/
137  NULL, /* tp_getattr*/
138  NULL, /* tp_setattr*/
139 #ifdef IS_PY3K
140  NULL, /* tp_reserved */
141 #else
142  (cmpfunc)Crossfire_Archetype_InternalCompare, /* tp_compare*/
143 #endif
144  NULL, /* tp_repr*/
145  NULL, /* tp_as_number*/
146  NULL, /* tp_as_sequence*/
147  NULL, /* tp_as_mapping*/
148  PyObject_HashNotImplemented, /* tp_hash */
149  NULL, /* tp_call*/
150  NULL, /* tp_str*/
151  PyObject_GenericGetAttr, /* tp_getattro*/
152  PyObject_GenericSetAttr, /* tp_setattro*/
153  NULL, /* tp_as_buffer*/
154  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags*/
155  "Crossfire archetypes", /* tp_doc */
156  NULL, /* tp_traverse */
157  NULL, /* tp_clear */
158  (richcmpfunc)Crossfire_Archetype_RichCompare, /* tp_richcompare */
159  0, /* tp_weaklistoffset */
160  NULL, /* tp_iter */
161  NULL, /* tp_iternext */
162  ArchetypeMethods, /* tp_methods */
163  NULL, /* tp_members */
164  Archetype_getseters, /* tp_getset */
165  NULL, /* tp_base */
166  NULL, /* tp_dict */
167  NULL, /* tp_descr_get */
168  NULL, /* tp_descr_set */
169  0, /* tp_dictoffset */
170  NULL, /* tp_init */
171  NULL, /* tp_alloc */
172  NULL, /* tp_new */
173  NULL, /* tp_free */
174  NULL, /* tp_is_gc */
175  NULL, /* tp_bases */
176  NULL, /* tp_mro */
177  NULL, /* tp_cache */
178  NULL, /* tp_subclasses */
179  NULL, /* tp_weaklist */
180  NULL, /* tp_del */
181 };
object * cf_archetype_get_clone(archetype *arch)
Get clone of archetype.
static PyObject * Crossfire_Archetype_GetClone(Crossfire_Archetype *who, void *closure)
PyObject_HEAD archetype * arch
static PyObject * Crossfire_Archetype_RichCompare(Crossfire_Archetype *left, Crossfire_Archetype *right, int op)
archetype * cf_archetype_get_next(archetype *arch)
Get next archetype in linked list.
static PyGetSetDef Archetype_getseters[]
archetype * cf_archetype_get_head(archetype *arch)
Get head of archetype.
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:465
static PyObject * Crossfire_Archetype_GetMore(Crossfire_Archetype *who, void *closure)
#define PyObject_HashNotImplemented
Definition: cfpython.h:73
static PyObject * Crossfire_Archetype_GetName(Crossfire_Archetype *whoptr, void *closure)
PyTypeObject Crossfire_ArchetypeType
static PyObject * Crossfire_Archetype_GetNewObject(Crossfire_Archetype *who, PyObject *args)
PyObject * Crossfire_Object_wrap(object *what)
Python initialized.
static PyMethodDef ArchetypeMethods[]
static PyObject * Crossfire_Archetype_GetNext(Crossfire_Archetype *who, void *closure)
static PyObject * Crossfire_Archetype_GetHead(Crossfire_Archetype *who, void *closure)
static int Crossfire_Archetype_InternalCompare(Crossfire_Archetype *left, Crossfire_Archetype *right)
archetype * cf_archetype_get_more(archetype *arch)
Get next part of archetype.
PyObject * Crossfire_Archetype_wrap(archetype *what)
sstring cf_archetype_get_name(archetype *arch)
Get archetype&#39;s name.
object * cf_create_object_by_name(const char *name)
Wrapper for create_archetype() and create_archetype_by_object_name().