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 |
#include <cfpython_party_private.h> |
32 |
|
33 |
static PyObject* Crossfire_Party_GetName( Crossfire_Party* partyptr, void* closure) |
34 |
{ |
35 |
return Py_BuildValue("s",cf_party_get_name(partyptr->party)); |
36 |
} |
37 |
|
38 |
static PyObject* Crossfire_Party_GetPassword( Crossfire_Party* partyptr, void* closure) |
39 |
{ |
40 |
return Py_BuildValue("s",cf_party_get_password(partyptr->party)); |
41 |
} |
42 |
|
43 |
static PyObject* Crossfire_Party_GetNext( Crossfire_Party* party, PyObject* args ) |
44 |
{ |
45 |
return Crossfire_Party_wrap(cf_party_get_next(party->party)); |
46 |
} |
47 |
|
48 |
static PyObject* Crossfire_Party_GetPlayers( Crossfire_Party* party, PyObject* args ) |
49 |
{ |
50 |
PyObject* list; |
51 |
player* pl; |
52 |
|
53 |
list = PyList_New(0); |
54 |
pl = cf_party_get_first_player(party->party); |
55 |
while (pl) |
56 |
{ |
57 |
PyList_Append(list,Crossfire_Object_wrap(pl->ob)); |
58 |
pl = cf_party_get_next_player(party->party,pl); |
59 |
} |
60 |
return list; |
61 |
} |
62 |
|
63 |
PyObject *Crossfire_Party_wrap(partylist *what) |
64 |
{ |
65 |
Crossfire_Party *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_Party, &Crossfire_PartyType); |
74 |
if(wrapper != NULL) |
75 |
wrapper->party = what; |
76 |
return (PyObject *)wrapper; |
77 |
} |
78 |
|
79 |
static int Crossfire_Party_InternalCompare(Crossfire_Party* left, Crossfire_Party* right) |
80 |
{ |
81 |
return (left->party < right->party ? -1 : ( left->party == right->party ? 0 : 1 ) ); |
82 |
} |