ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/info.C
(Generate patch)

Comparing deliantra/server/socket/info.C (file contents):
Revision 1.50 by root, Tue May 6 16:55:26 2008 UTC vs.
Revision 1.56 by root, Fri Nov 6 13:07:28 2009 UTC

3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24/** 25/**
139/** 140/**
140 * Sends message to player(s). 141 * Sends message to player(s).
141 * 142 *
142 * flags is various flags - mostly color, plus a few specials. 143 * flags is various flags - mostly color, plus a few specials.
143 * 144 *
144 * pri is priority. It is a little odd - the lower the value, the more 145 * pri is unused.
145 * important it is. Thus, 0 gets sent no matter what. Otherwise, the
146 * value must be less than the listening level that the player has set.
147 * Unfortunately, there is no clear guideline on what each level does what.
148 * 146 *
149 * pl can be passed as NULL - in fact, this will be done if NDI_ALL is set 147 * pl can be passed as NULL - in fact, this will be done if NDI_ALL is set
150 * in the flags. 148 * in the flags.
151 * 149 *
152 * If message is black, and not NDI_UNIQUE, gets sent through output buffers. 150 * If message is black, and not NDI_UNIQUE, gets sent through output buffers.
156new_draw_info (int flags, int pri, const object *op, const char *buf) 154new_draw_info (int flags, int pri, const object *op, const char *buf)
157{ 155{
158 if (flags & NDI_ALL) 156 if (flags & NDI_ALL)
159 { 157 {
160 for_all_players (pl) 158 for_all_players (pl)
161 new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf); 159 new_draw_info (flags & ~NDI_ALL, 0, pl->ob, buf);
162 } 160 }
163 else 161 else
164 { 162 {
165 if (!op || !op->contr || !op->contr->ns) 163 if (!op || !op->contr || !op->contr->ns)
166 return;
167
168 if (pri >= op->contr->listening)
169 return; 164 return;
170 165
171 if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK 166 if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK
172 || !op->contr->ns->msg_suppressed (buf)) 167 || !op->contr->ns->msg_suppressed (buf))
173 print_message (flags & NDI_COLOR_MASK, op, buf); 168 print_message (flags & NDI_COLOR_MASK, op, buf);
183 * client/server bandwidth (client could keep track of various strings 178 * client/server bandwidth (client could keep track of various strings
184 */ 179 */
185void 180void
186new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...) 181new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...)
187{ 182{
188 char buf[HUGE_BUF];
189
190 va_list ap; 183 va_list ap;
191 va_start (ap, format); 184 va_start (ap, format);
192 vsnprintf (buf, HUGE_BUF, format, ap); 185 new_draw_info (flags, pri, pl, vformat (format, ap));
193 va_end (ap); 186 va_end (ap);
194
195 new_draw_info (flags, pri, pl, buf);
196} 187}
197 188
198void 189void
199draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage) 190draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
200{ 191{
201
202 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) 192 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
203 return;
204
205 if (pri >= pl->contr->listening)
206 return; 193 return;
207 194
208 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type)) 195 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
209 { 196 {
210 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); 197 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1);
224} 211}
225 212
226void 213void
227draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) 214draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...)
228{ 215{
229 char buf[HUGE_BUF]; 216 va_list ap;
217 va_start (ap, new_format);
230 218
231 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) 219 if (!pl || !pl->is_player ())
232 return; 220 return;
233 221
234 if (pri >= pl->contr->listening) 222 // TODO: just assume, and rip out?
235 return;
236
237 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type)) 223 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
238 { 224 {
239 va_list ap;
240
241 LOG (llevDebug, "Non supported extension text type for client.\n"); 225 LOG (llevDebug, "Non supported extension text type for client.\n");
242 va_start (ap, new_format);
243 vsnprintf (buf, HUGE_BUF, old_format, ap);
244 va_end (ap);
245 new_draw_info (flags, pri, pl, buf); 226 new_draw_info (flags, pri, pl, vformat (old_format, ap));
246 return;
247 } 227 }
248 else 228 else
249 { 229 {
250 va_list ap; 230 char *buf = vformat (new_format, ap);
251
252 va_start (ap, new_format);
253 vsnprintf (buf, HUGE_BUF, new_format, ap);
254 va_end (ap);
255 strip_media_tag (buf); 231 strip_media_tag (buf);
256 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf); 232 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf);
257 } 233 }
234
235 va_end (ap);
258} 236}
259 237
260/** 238/**
261 * Writes to everyone on the map *except* op. This is useful for emotions. 239 * Writes to everyone on the map *except* op. This is useful for emotions.
262 */ 240 */
263
264void 241void
265new_info_map_except (int color, maptile * map, object *op, const char *str) 242new_info_map_except (int color, maptile * map, object *op, const char *str)
266{ 243{
267 for_all_players (pl) 244 for_all_players (pl)
268 if (pl->ob->map == map && pl->ob != op) 245 if (pl->ob->map == map && pl->ob != op)
270} 247}
271 248
272/** 249/**
273 * Writes to everyone on the map except op1 and op2 250 * Writes to everyone on the map except op1 and op2
274 */ 251 */
275void 252static void
276new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) 253new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str)
277{ 254{
278 for_all_players (pl) 255 for_all_players (pl)
279 if (pl->ob->map == map && pl->ob != op1 && pl->ob != op2) 256 if (pl->ob->map == map && pl->ob != op1 && pl->ob != op2)
280 new_draw_info (color, 0, pl->ob, str); 257 new_draw_info (color, 0, pl->ob, str);
304 sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title); 281 sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title);
305} 282}
306 283
307// formerly a macro, used only by magic map, so optimised it out 284// formerly a macro, used only by magic map, so optimised it out
308static inline faceidx 285static inline faceidx
309GET_MAP_FACE (maptile *m, int x, int y, int layer) 286GET_MAP_FACE (mapspace &ms, int layer)
310{ 287{
311 if (object *op = GET_MAP_FACE_OBJ (m, x, y, layer)) 288 if (object *op = ms.faces_obj [layer])
312 return op->face; 289 return op->face;
313 else 290 else
314 return 0; 291 return 0;
315} 292}
316 293
326 * for various code values. 303 * for various code values.
327 */ 304 */
328static void 305static void
329magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) 306magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py)
330{ 307{
331 int x, y, dx, dy, mflags;
332 sint16 nx, ny;
333 maptile *mp;
334
335 for (dx = -1; dx <= 1; dx++) 308 for (int dx = -1; dx <= 1; dx++)
336 { 309 {
337 for (dy = -1; dy <= 1; dy++) 310 for (int dy = -1; dy <= 1; dy++)
338 { 311 {
339 x = px + dx; 312 int x = px + dx;
340 y = py + dy; 313 int y = py + dy;
341 314
342 if (FABS (x) >= MAGIC_MAP_HALF || FABS (y) >= MAGIC_MAP_HALF) 315 if (abs (x) >= MAGIC_MAP_HALF || abs (y) >= MAGIC_MAP_HALF)
343 continue; 316 continue;
344 317
345 mp = pl->map; 318 mapxy pos (pl);
346 nx = pl->x + x; 319 pos.move (x, y);
347 ny = pl->y + y;
348 320
349 mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); 321 if (!pos.normalise ())
350 if (mflags & P_OUT_OF_MAP)
351 continue; 322 continue;
323
324 mapspace &ms = pos.ms ();
352 325
353 if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0) 326 if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0)
354 { 327 {
328 int mflags = ms.flags ();
329
355 int f = GET_MAP_FACE (mp, nx, ny, 0); 330 int f = GET_MAP_FACE (ms, 0);
356 if (f == blank_face) 331 if (f == blank_face)
357 { 332 {
358 f = GET_MAP_FACE (mp, nx, ny, 1); 333 f = GET_MAP_FACE (ms, 1);
359 if (f == blank_face) 334 if (f == blank_face)
360 f = GET_MAP_FACE (mp, nx, ny, 2); 335 f = GET_MAP_FACE (ms, 2);
361 } 336 }
362 337
363 int magicmap = faces [f].magicmap; 338 int magicmap = faces [f].magicmap;
364 339
365 /* Should probably have P_NO_MAGIC here also, but then shops don't 340 /* Should probably have P_NO_MAGIC here also, but then shops don't
378} 353}
379 354
380/** 355/**
381 * Creates magic map for player. 356 * Creates magic map for player.
382 * 357 *
383 * Note: For improved magic mapping display, the space that blocks 358 * Note: For improved magic mapping display, the space that blocks
384 * the view is now marked with value 2. Any dependencies of map_mark 359 * the view is now marked with value 2. Any dependencies of map_mark
385 * being nonzero have been changed to check for 1. Also, since 360 * being nonzero have been changed to check for 1. Also, since
386 * map_mark is a char value, putting 2 in should cause no problems. 361 * map_mark is a char value, putting 2 in should cause no problems.
387 * 362 *
388 * This function examines the map the player is on, and determines what 363 * This function examines the map the player is on, and determines what
389 * is visible. 2 is set for walls or objects that blocks view. 1 364 * is visible. 2 is set for walls or objects that blocks view. 1
390 * is for open spaces. map_mark should already have been initialised 365 * is for open spaces. map_mark should already have been initialised
391 * to zero before this is called. 366 * to zero before this is called.
392 * strength is an initial strength*2 rectangular area that we automatically 367 * strength is an initial strength*2 rectangular area that we automatically
393 * see in/penetrate through. 368 * see in/penetrate through.
394 */ 369 */
395void 370static void
396magic_mapping_mark (object *pl, char *map_mark, int strength) 371magic_mapping_mark (object *pl, char *map_mark, int strength)
397{ 372{
398 int x, y, mflags;
399 sint16 nx, ny;
400 maptile *mp;
401
402 for (x = -strength; x < strength; x++) 373 for (int x = -strength; x < strength; x++)
403 { 374 {
404 for (y = -strength; y < strength; y++) 375 for (int y = -strength; y < strength; y++)
405 { 376 {
406 mp = pl->map; 377 mapxy pos (pl);
407 nx = pl->x + x; 378 pos.move (x, y);
408 ny = pl->y + y;
409 379
410 mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); 380 if (!pos.normalise ())
411 if (mflags & P_OUT_OF_MAP)
412 continue; 381 continue;
413 382
383 mapspace &ms = pos.ms ();
384
385 int mflags = ms.flags ();
386
414 int f = GET_MAP_FACE (mp, nx, ny, 0); 387 int f = GET_MAP_FACE (ms, 0);
415 if (f == blank_face) 388 if (f == blank_face)
416 { 389 {
417 f = GET_MAP_FACE (mp, nx, ny, 1); 390 f = GET_MAP_FACE (ms, 1);
418 if (f == blank_face) 391 if (f == blank_face)
419 f = GET_MAP_FACE (mp, nx, ny, 2); 392 f = GET_MAP_FACE (ms, 2);
420 } 393 }
421 394
422 int magicmap = faces [f].magicmap; 395 int magicmap = faces [f].magicmap;
423 396
424 if (mflags & P_BLOCKSVIEW) 397 if (mflags & P_BLOCKSVIEW)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines