Crossfire Server, Trunk
cfpython_archetype.cpp
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  (void)closure;
34  return Py_BuildValue("s", cf_archetype_get_name(whoptr->arch));
35 }
36 
37 static PyObject *Crossfire_Archetype_GetNext(Crossfire_Archetype *who, void *closure) {
38  (void)closure;
40 }
41 
42 static PyObject *Crossfire_Archetype_GetMore(Crossfire_Archetype *who, void *closure) {
43  (void)closure;
45 }
46 
47 static PyObject *Crossfire_Archetype_GetHead(Crossfire_Archetype *who, void *closure) {
48  (void)closure;
50 }
51 
52 static PyObject *Crossfire_Archetype_GetClone(Crossfire_Archetype *who, void *closure) {
53  (void)closure;
55 }
56 
58  (void)args;
60 }
61 
63  Crossfire_Archetype *wrapper;
64 
65  /* return None if no object was to be wrapped */
66  if (what == NULL) {
67  Py_INCREF(Py_None);
68  return Py_None;
69  }
70 
71  wrapper = PyObject_NEW(Crossfire_Archetype, &Crossfire_ArchetypeType);
72  if (wrapper != NULL)
73  wrapper->arch = what;
74  return (PyObject *)wrapper;
75 }
76 
78  return (left->arch < right->arch ? -1 : (left->arch == right->arch ? 0 : 1));
79 }
80 
82  int result;
83  if (!left
84  || !right
85  || !PyObject_TypeCheck((PyObject*)left, &Crossfire_ArchetypeType)
86  || !PyObject_TypeCheck((PyObject*)right, &Crossfire_ArchetypeType)) {
87  Py_INCREF(Py_NotImplemented);
88  return Py_NotImplemented;
89  }
91  /* Based on how Python 3.0 (GPL compatible) implements it for internal types: */
92  switch (op) {
93  case Py_EQ:
94  result = (result == 0);
95  break;
96  case Py_NE:
97  result = (result != 0);
98  break;
99  case Py_LE:
100  result = (result <= 0);
101  break;
102  case Py_GE:
103  result = (result >= 0);
104  break;
105  case Py_LT:
106  result = (result == -1);
107  break;
108  case Py_GT:
109  result = (result == 1);
110  break;
111  }
112  return PyBool_FromLong(result);
113 }
114 
115 static PyGetSetDef Archetype_getseters[] = {
116  { "Name", (getter)Crossfire_Archetype_GetName, NULL, NULL, NULL },
117  { "Next", (getter)Crossfire_Archetype_GetNext, NULL, NULL, NULL },
118  { "More", (getter)Crossfire_Archetype_GetMore, NULL, NULL, NULL },
119  { "Head", (getter)Crossfire_Archetype_GetHead, NULL, NULL, NULL },
120  { "Clone", (getter)Crossfire_Archetype_GetClone, NULL, NULL, NULL },
121  { NULL, NULL, NULL, NULL, NULL }
122 };
123 
124 static PyMethodDef ArchetypeMethods[] = {
125  { "NewObject", (PyCFunction)Crossfire_Archetype_GetNewObject, METH_NOARGS, NULL },
126  { NULL, NULL, 0, NULL }
127 };
128 
129 /* Our actual Python ArchetypeType */
131  NULL,
132  NULL,
133  PyObject_HashNotImplemented,
134  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
135  "Crossfire archetypes",
136  (richcmpfunc) Crossfire_Archetype_RichCompare,
139  NULL,
140  NULL
141  );
MimeUtils::Archetype
static const char * Archetype
Definition: MimeUtils.h:24
cf_archetype_get_name
sstring cf_archetype_get_name(archetype *arch)
Definition: plugin_common.cpp:1702
cf_create_object_by_name
object * cf_create_object_by_name(const char *name)
Definition: plugin_common.cpp:1093
Crossfire_Archetype_GetName
static PyObject * Crossfire_Archetype_GetName(Crossfire_Archetype *whoptr, void *closure)
Definition: cfpython_archetype.cpp:32
Crossfire_Archetype_GetClone
static PyObject * Crossfire_Archetype_GetClone(Crossfire_Archetype *who, void *closure)
Definition: cfpython_archetype.cpp:52
CF_PYTHON_OBJECT
CF_PYTHON_OBJECT(Archetype, NULL, NULL, PyObject_HashNotImplemented, Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, "Crossfire archetypes",(richcmpfunc) Crossfire_Archetype_RichCompare, ArchetypeMethods, Archetype_getseters, NULL, NULL)
Crossfire_Archetype_RichCompare
static PyObject * Crossfire_Archetype_RichCompare(Crossfire_Archetype *left, Crossfire_Archetype *right, int op)
Definition: cfpython_archetype.cpp:81
cf_archetype_get_clone
object * cf_archetype_get_clone(archetype *arch)
Definition: plugin_common.cpp:1767
Crossfire_Object_wrap
PyObject * Crossfire_Object_wrap(object *what)
Definition: cfpython_object.cpp:1606
autojail.who
who
Definition: autojail.py:3
cf_archetype_get_more
archetype * cf_archetype_get_more(archetype *arch)
Definition: plugin_common.cpp:1735
Crossfire_Archetype::arch
PyObject_HEAD archetype * arch
Definition: cfpython_archetype.h:35
Crossfire_Archetype_GetNewObject
static PyObject * Crossfire_Archetype_GetNewObject(Crossfire_Archetype *who, PyObject *args)
Definition: cfpython_archetype.cpp:57
make_face_from_files.args
args
Definition: make_face_from_files.py:37
rotate-tower.result
bool result
Definition: rotate-tower.py:13
Crossfire_Archetype_GetHead
static PyObject * Crossfire_Archetype_GetHead(Crossfire_Archetype *who, void *closure)
Definition: cfpython_archetype.cpp:47
cfpython.h
Crossfire_Archetype_GetMore
static PyObject * Crossfire_Archetype_GetMore(Crossfire_Archetype *who, void *closure)
Definition: cfpython_archetype.cpp:42
Crossfire_Archetype_wrap
PyObject * Crossfire_Archetype_wrap(archetype *what)
Definition: cfpython_archetype.cpp:62
archetype
Definition: object.h:483
Crossfire_Archetype
Definition: cfpython_archetype.h:33
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
cf_archetype_get_next
archetype * cf_archetype_get_next(archetype *arch)
Definition: plugin_common.cpp:1719
Crossfire_Archetype_GetNext
static PyObject * Crossfire_Archetype_GetNext(Crossfire_Archetype *who, void *closure)
Definition: cfpython_archetype.cpp:37
Archetype_getseters
static PyGetSetDef Archetype_getseters[]
Definition: cfpython_archetype.cpp:115
give.op
op
Definition: give.py:33
Crossfire_ArchetypeType
PyTypeObject Crossfire_ArchetypeType
Crossfire_Archetype_InternalCompare
static int Crossfire_Archetype_InternalCompare(Crossfire_Archetype *left, Crossfire_Archetype *right)
Definition: cfpython_archetype.cpp:77
ArchetypeMethods
static PyMethodDef ArchetypeMethods[]
Definition: cfpython_archetype.cpp:124
cf_archetype_get_head
archetype * cf_archetype_get_head(archetype *arch)
Definition: plugin_common.cpp:1751