1 |
root |
1.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 |
|
|
#include <cfpython.h> |
29 |
|
|
#include <cfpython_map_private.h> |
30 |
|
|
|
31 |
|
|
static PyObject* Map_GetDifficulty(Crossfire_Map* whoptr, void* closure) |
32 |
|
|
{ |
33 |
|
|
return Py_BuildValue("i", cf_map_get_difficulty(whoptr->map)); |
34 |
|
|
} |
35 |
|
|
static PyObject* Map_GetPath(Crossfire_Map* whoptr, void* closure) |
36 |
|
|
{ |
37 |
|
|
return Py_BuildValue("s", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_PATH)); |
38 |
|
|
} |
39 |
|
|
static PyObject* Map_GetTempName(Crossfire_Map* whoptr, void* closure) |
40 |
|
|
{ |
41 |
|
|
return Py_BuildValue("s", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_TMPNAME)); |
42 |
|
|
} |
43 |
|
|
static PyObject* Map_GetName(Crossfire_Map* whoptr, void* closure) |
44 |
|
|
{ |
45 |
|
|
return Py_BuildValue("s", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_NAME)); |
46 |
|
|
} |
47 |
|
|
static PyObject* Map_GetResetTime(Crossfire_Map* whoptr, void* closure) |
48 |
|
|
{ |
49 |
|
|
return Py_BuildValue("i", cf_map_get_reset_time(whoptr->map)); |
50 |
|
|
} |
51 |
|
|
static PyObject* Map_GetResetTimeout(Crossfire_Map* whoptr, void* closure) |
52 |
|
|
{ |
53 |
|
|
return Py_BuildValue("i", cf_map_get_reset_timeout(whoptr->map)); |
54 |
|
|
} |
55 |
|
|
static PyObject* Map_GetPlayers(Crossfire_Map* whoptr, void* closure) |
56 |
|
|
{ |
57 |
|
|
return Py_BuildValue("i", cf_map_get_players(whoptr->map)); |
58 |
|
|
} |
59 |
|
|
static PyObject* Map_GetLight(Crossfire_Map* whoptr, void* closure) |
60 |
|
|
{ |
61 |
|
|
return Py_BuildValue("i", *(int*)cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_LIGHT)); |
62 |
|
|
} |
63 |
|
|
static PyObject* Map_GetDarkness(Crossfire_Map* whoptr, void* closure) |
64 |
|
|
{ |
65 |
|
|
return Py_BuildValue("i", cf_map_get_darkness(whoptr->map)); |
66 |
|
|
} |
67 |
|
|
static PyObject* Map_GetWidth(Crossfire_Map* whoptr, void* closure) |
68 |
|
|
{ |
69 |
|
|
return Py_BuildValue("i", cf_map_get_width(whoptr->map)); |
70 |
|
|
} |
71 |
|
|
static PyObject* Map_GetHeight(Crossfire_Map* whoptr, void* closure) |
72 |
|
|
{ |
73 |
|
|
return Py_BuildValue("i", cf_map_get_height(whoptr->map)); |
74 |
|
|
} |
75 |
|
|
static PyObject* Map_GetEnterX(Crossfire_Map* whoptr, void* closure) |
76 |
|
|
{ |
77 |
|
|
return Py_BuildValue("i", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_ENTER_X)); |
78 |
|
|
} |
79 |
|
|
static PyObject* Map_GetEnterY(Crossfire_Map* whoptr, void* closure) |
80 |
|
|
{ |
81 |
|
|
return Py_BuildValue("i", cf_map_get_enter_x(whoptr->map)); |
82 |
|
|
} |
83 |
|
|
static PyObject* Map_GetTemperature(Crossfire_Map* whoptr, void* closure) |
84 |
|
|
{ |
85 |
|
|
return Py_BuildValue("i", cf_map_get_temperature(whoptr->map)); |
86 |
|
|
} |
87 |
|
|
static PyObject* Map_GetPressure(Crossfire_Map* whoptr, void* closure) |
88 |
|
|
{ |
89 |
|
|
return Py_BuildValue("i", cf_map_get_pressure(whoptr->map)); |
90 |
|
|
} |
91 |
|
|
static PyObject* Map_GetHumidity(Crossfire_Map* whoptr, void* closure) |
92 |
|
|
{ |
93 |
|
|
return Py_BuildValue("i", cf_map_get_humidity(whoptr->map)); |
94 |
|
|
} |
95 |
|
|
static PyObject* Map_GetWindSpeed(Crossfire_Map* whoptr, void* closure) |
96 |
|
|
{ |
97 |
|
|
return Py_BuildValue("i", cf_map_get_windspeed(whoptr->map)); |
98 |
|
|
} |
99 |
|
|
static PyObject* Map_GetWindDir(Crossfire_Map* whoptr, void* closure) |
100 |
|
|
{ |
101 |
|
|
return Py_BuildValue("i", cf_map_get_winddir(whoptr->map)); |
102 |
|
|
} |
103 |
|
|
static PyObject* Map_GetSky(Crossfire_Map* whoptr, void* closure) |
104 |
|
|
{ |
105 |
|
|
return Py_BuildValue("i", cf_map_get_sky(whoptr->map)); |
106 |
|
|
} |
107 |
|
|
static PyObject* Map_GetWPartX(Crossfire_Map* whoptr, void* closure) |
108 |
|
|
{ |
109 |
|
|
return Py_BuildValue("i", cf_map_get_wpartx(whoptr->map)); |
110 |
|
|
} |
111 |
|
|
static PyObject* Map_GetWPartY(Crossfire_Map* whoptr, void* closure) |
112 |
|
|
{ |
113 |
|
|
return Py_BuildValue("i", cf_map_get_wparty(whoptr->map)); |
114 |
|
|
} |
115 |
|
|
static PyObject* Map_GetMessage(Crossfire_Map* whoptr, void* closure) |
116 |
|
|
{ |
117 |
|
|
return Py_BuildValue("s", cf_map_get_property(whoptr->map, CFAPI_MAP_PROP_MESSAGE)); |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
static PyObject* Map_GetRegion(Crossfire_Map* whoptr, void* closure) |
121 |
|
|
{ |
122 |
|
|
return Crossfire_Region_wrap(cf_map_get_property(whoptr->map,CFAPI_MAP_PROP_REGION)); |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
static PyObject* Map_Message(Crossfire_Map* map, PyObject* args) |
126 |
|
|
{ |
127 |
|
|
int color = NDI_BLUE|NDI_UNIQUE; |
128 |
|
|
char *message; |
129 |
|
|
|
130 |
|
|
if (!PyArg_ParseTuple(args,"s|i",&message,&color)) |
131 |
|
|
return NULL; |
132 |
|
|
|
133 |
|
|
cf_map_message(map->map, message, color); |
134 |
|
|
|
135 |
|
|
Py_INCREF(Py_None); |
136 |
|
|
return Py_None; |
137 |
|
|
} |
138 |
|
|
static PyObject* Map_GetFirstObjectAt(Crossfire_Map* map, PyObject* args) |
139 |
|
|
{ |
140 |
|
|
int x, y; |
141 |
|
|
object* val; |
142 |
|
|
|
143 |
|
|
if (!PyArg_ParseTuple(args,"ii",&x,&y)) |
144 |
|
|
return NULL; |
145 |
|
|
|
146 |
|
|
val = cf_map_get_object_at(map->map,x,y); |
147 |
|
|
return Crossfire_Object_wrap(val); |
148 |
|
|
} |
149 |
|
|
static PyObject* Map_CreateObject(Crossfire_Map* map, PyObject* args) |
150 |
|
|
{ |
151 |
|
|
char* txt; |
152 |
|
|
int x,y; |
153 |
|
|
object* op; |
154 |
|
|
if (!PyArg_ParseTuple(args,"sii",&txt,&x,&y)) |
155 |
|
|
return NULL; |
156 |
|
|
op = cf_create_object_by_name(txt); |
157 |
|
|
if (op == NULL) |
158 |
|
|
{ |
159 |
|
|
Py_INCREF(Py_None); |
160 |
|
|
return Py_None; |
161 |
|
|
} |
162 |
|
|
cf_map_insert_object(map->map,op,x,y); |
163 |
|
|
return Crossfire_Object_wrap(op); |
164 |
|
|
} |
165 |
|
|
static PyObject* Map_Check(Crossfire_Map* map, PyObject* args) |
166 |
|
|
{ |
167 |
|
|
char *what; |
168 |
|
|
int x, y; |
169 |
|
|
object* foundob; |
170 |
|
|
sint16 nx, ny; |
171 |
|
|
int mflags; |
172 |
|
|
|
173 |
|
|
if (!PyArg_ParseTuple(args,"s(ii)",&what,&x,&y)) |
174 |
|
|
return NULL; |
175 |
|
|
|
176 |
|
|
/* make sure the map is swapped in */ |
177 |
|
|
if (map->map->in_memory != MAP_IN_MEMORY) |
178 |
|
|
{ |
179 |
|
|
printf("MAP AIN'T READY !\n"); |
180 |
|
|
} |
181 |
|
|
|
182 |
|
|
mflags = cf_map_get_flags(map->map, &(map->map), (sint16)x, (sint16)y, &nx, &ny); |
183 |
|
|
if (mflags & P_OUT_OF_MAP) |
184 |
|
|
{ |
185 |
|
|
Py_INCREF(Py_None); |
186 |
|
|
return Py_None; |
187 |
|
|
} |
188 |
|
|
foundob = cf_map_present_arch_by_name(what, map->map, nx, ny); |
189 |
|
|
return Crossfire_Object_wrap(foundob); |
190 |
|
|
} |
191 |
|
|
static PyObject* Map_Next(Crossfire_Map* map, PyObject* args) |
192 |
|
|
{ |
193 |
|
|
return Crossfire_Map_wrap(cf_map_get_property(map->map,CFAPI_MAP_PROP_NEXT)); |
194 |
|
|
} |
195 |
|
|
|
196 |
|
|
static int Map_InternalCompare(Crossfire_Map* left, Crossfire_Map* right) |
197 |
|
|
{ |
198 |
|
|
return (int)left->map - (int)right->map; |
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
/* Legacy code: convert to long so that non-object functions work correctly */ |
202 |
|
|
static PyObject* Crossfire_Map_Long( PyObject* obj ) |
203 |
|
|
{ |
204 |
|
|
return Py_BuildValue("l", ((Crossfire_Object*)obj)->obj); |
205 |
|
|
} |
206 |
|
|
|
207 |
|
|
static PyObject* Crossfire_Map_Int( PyObject* obj ) |
208 |
|
|
{ |
209 |
|
|
return Py_BuildValue("i", ((Crossfire_Object*)obj)->obj); |
210 |
|
|
} |
211 |
|
|
|
212 |
|
|
/** |
213 |
|
|
* Python initialized. |
214 |
|
|
**/ |
215 |
|
|
static PyObject * |
216 |
|
|
Crossfire_Map_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
217 |
|
|
{ |
218 |
|
|
Crossfire_Map *self; |
219 |
|
|
|
220 |
|
|
self = (Crossfire_Map *)type->tp_alloc(type, 0); |
221 |
|
|
if(self) |
222 |
|
|
self->map = NULL; |
223 |
|
|
|
224 |
|
|
return (PyObject *)self; |
225 |
|
|
} |
226 |
|
|
|
227 |
|
|
PyObject *Crossfire_Map_wrap(mapstruct *what) |
228 |
|
|
{ |
229 |
|
|
Crossfire_Map *wrapper; |
230 |
|
|
|
231 |
|
|
/* return None if no object was to be wrapped */ |
232 |
|
|
if(what == NULL) { |
233 |
|
|
Py_INCREF(Py_None); |
234 |
|
|
return Py_None; |
235 |
|
|
} |
236 |
|
|
|
237 |
|
|
wrapper = PyObject_NEW(Crossfire_Map, &Crossfire_MapType); |
238 |
|
|
if(wrapper != NULL) |
239 |
|
|
wrapper->map = what; |
240 |
|
|
return (PyObject *)wrapper; |
241 |
|
|
} |
242 |
|
|
|