Crossfire Server, Trunk
cfpython_party.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_Party_GetName(Crossfire_Party *partyptr, void *closure) {
33  (void)closure;
34  return Py_BuildValue("s", cf_party_get_name(partyptr->party));
35 }
36 
37 static PyObject *Crossfire_Party_GetPassword(Crossfire_Party *partyptr, void *closure) {
38  (void)closure;
39  return Py_BuildValue("s", cf_party_get_password(partyptr->party));
40 }
41 
42 static PyObject *Crossfire_Party_GetNext(Crossfire_Party *party, void *closure) {
43  (void)closure;
45 }
46 
47 static PyObject *Crossfire_Party_GetPlayers(Crossfire_Party *party, PyObject *args) {
48  PyObject *list;
49  player *pl;
50  (void)args;
51 
52  list = PyList_New(0);
54  while (pl) {
55  PyList_Append(list, Crossfire_Object_wrap(pl->ob));
57  }
58  return list;
59 }
60 
61 PyObject *Crossfire_Party_wrap(partylist *what) {
62  Crossfire_Party *wrapper;
63 
64  /* return None if no object was to be wrapped */
65  if (what == NULL) {
66  Py_INCREF(Py_None);
67  return Py_None;
68  }
69 
70  wrapper = PyObject_NEW(Crossfire_Party, &Crossfire_PartyType);
71  if (wrapper != NULL)
72  wrapper->party = what;
73  return (PyObject *)wrapper;
74 }
75 
77  return (left->party < right->party ? -1 : (left->party == right->party ? 0 : 1));
78 }
79 
80 static PyObject *Crossfire_Party_RichCompare(Crossfire_Party *left, Crossfire_Party *right, int op) {
81  int result;
82  if (!left
83  || !right
84  || !PyObject_TypeCheck((PyObject*)left, &Crossfire_PartyType)
85  || !PyObject_TypeCheck((PyObject*)right, &Crossfire_PartyType)) {
86  Py_INCREF(Py_NotImplemented);
87  return Py_NotImplemented;
88  }
90  /* Based on how Python 3.0 (GPL compatible) implements it for internal types: */
91  switch (op) {
92  case Py_EQ:
93  result = (result == 0);
94  break;
95  case Py_NE:
96  result = (result != 0);
97  break;
98  case Py_LE:
99  result = (result <= 0);
100  break;
101  case Py_GE:
102  result = (result >= 0);
103  break;
104  case Py_LT:
105  result = (result == -1);
106  break;
107  case Py_GT:
108  result = (result == 1);
109  break;
110  }
111  return PyBool_FromLong(result);
112 }
113 
114 static PyGetSetDef Party_getseters[] = {
115  { "Name", (getter)Crossfire_Party_GetName, NULL, NULL, NULL },
116  { "Password", (getter)Crossfire_Party_GetPassword, NULL, NULL, NULL },
117  { "Next", (getter)Crossfire_Party_GetNext, NULL, NULL, NULL },
118  { NULL, NULL, NULL, NULL, NULL }
119 };
120 
121 static PyMethodDef PartyMethods[] = {
122  { "GetPlayers", (PyCFunction)Crossfire_Party_GetPlayers, METH_NOARGS, NULL },
123  { NULL, NULL, 0, NULL }
124 };
125 
126 /* Our actual Python PartyType */
127 CF_PYTHON_OBJECT(Party,
128  NULL,
129  NULL,
130  PyObject_HashNotImplemented,
131  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
132  "Crossfire parties",
133  (richcmpfunc) Crossfire_Party_RichCompare,
134  PartyMethods,
136  NULL,
137  NULL
138  );
cf_party_get_name
const char * cf_party_get_name(partylist *party)
Definition: plugin_common.c:1788
Crossfire_Party::party
PyObject_HEAD partylist * party
Definition: cfpython_party.h:35
Crossfire_Party
Definition: cfpython_party.h:33
pl
Definition: player.h:105
PartyMethods
static PyMethodDef PartyMethods[]
Definition: cfpython_party.c:121
guildoracle.list
list
Definition: guildoracle.py:87
Crossfire_Object_wrap
PyObject * Crossfire_Object_wrap(object *what)
Definition: cfpython_object.c:1609
cf_party_get_first_player
player * cf_party_get_first_player(partylist *party)
Definition: plugin_common.c:1836
Crossfire_Party_InternalCompare
static int Crossfire_Party_InternalCompare(Crossfire_Party *left, Crossfire_Party *right)
Definition: cfpython_party.c:76
pl::ob
object * ob
Definition: player.h:176
cf_party_get_next
partylist * cf_party_get_next(partylist *party)
Definition: plugin_common.c:1804
Crossfire_Party_RichCompare
static PyObject * Crossfire_Party_RichCompare(Crossfire_Party *left, Crossfire_Party *right, int op)
Definition: cfpython_party.c:80
CF_PYTHON_OBJECT
CF_PYTHON_OBJECT(Party, NULL, NULL, PyObject_HashNotImplemented, Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, "Crossfire parties",(richcmpfunc) Crossfire_Party_RichCompare, PartyMethods, Party_getseters, NULL, NULL)
Party_getseters
static PyGetSetDef Party_getseters[]
Definition: cfpython_party.c:114
make_face_from_files.args
args
Definition: make_face_from_files.py:31
rotate-tower.result
bool result
Definition: rotate-tower.py:13
cfpython.h
nlohmann::detail::void
j template void())
Definition: json.hpp:4099
party_struct
Definition: party.h:10
Crossfire_PartyType
PyTypeObject Crossfire_PartyType
Crossfire_Party_GetNext
static PyObject * Crossfire_Party_GetNext(Crossfire_Party *party, void *closure)
Definition: cfpython_party.c:42
Crossfire_Party_GetPassword
static PyObject * Crossfire_Party_GetPassword(Crossfire_Party *partyptr, void *closure)
Definition: cfpython_party.c:37
give.op
op
Definition: give.py:33
Crossfire_Party_wrap
PyObject * Crossfire_Party_wrap(partylist *what)
Definition: cfpython_party.c:61
Crossfire_Party_GetName
static PyObject * Crossfire_Party_GetName(Crossfire_Party *partyptr, void *closure)
Definition: cfpython_party.c:32
cf_party_get_password
const char * cf_party_get_password(partylist *party)
Definition: plugin_common.c:1820
cf_party_get_next_player
player * cf_party_get_next_player(partylist *party, player *op)
Definition: plugin_common.c:1854
altar_valkyrie.pl
pl
Definition: altar_valkyrie.py:28
Crossfire_Party_GetPlayers
static PyObject * Crossfire_Party_GetPlayers(Crossfire_Party *party, PyObject *args)
Definition: cfpython_party.c:47