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.53 by root, Thu Oct 15 21:09:32 2009 UTC vs.
Revision 1.60 by root, Fri Mar 26 01:04:45 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
48 */ 48 */
49static void 49static void
50esrv_print_msg (client *ns, int color, const char *str) 50esrv_print_msg (client *ns, int color, const char *str)
51{ 51{
52 ns->send_msg (color, "info", str); 52 ns->send_msg (color, "info", str);
53}
54
55/**
56 * Draws an extended message on the client.
57 * ns the socket to send message to
58 * color color informations (used mainly if client does not support message type)
59 * type,
60 * subtype type and subtype of text message
61 * intro Intro message to send with main message if client does not support the message type
62 * message The main message
63 */
64static void
65esrv_print_ext_msg (client *ns, int color, uint8 type, uint8 subtype, const char *message)
66{
67 ns->send_packet_printf ("drawextinfo %d %u %u %s", color, type, subtype, message);
68} 53}
69 54
70/** 55/**
71 * Frontend for esrv_print_msg 56 * Frontend for esrv_print_msg
72 * \param colr message color 57 * \param colr message color
184 va_start (ap, format); 169 va_start (ap, format);
185 new_draw_info (flags, pri, pl, vformat (format, ap)); 170 new_draw_info (flags, pri, pl, vformat (format, ap));
186 va_end (ap); 171 va_end (ap);
187} 172}
188 173
189void
190draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
191{
192
193 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
194 return;
195
196 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
197 {
198 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1);
199
200 if (buf == NULL)
201 LOG (llevError, "info::draw_ext_info -> Out of memory!");
202 else
203 {
204 strcpy (buf, oldmessage == NULL ? message : oldmessage);
205 strip_media_tag (buf);
206 new_draw_info (flags, pri, pl, buf);
207 free (buf);
208 }
209 }
210 else
211 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, message);
212}
213
214void
215draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...)
216{
217 va_list ap;
218 va_start (ap, new_format);
219
220 if (!pl || !pl->is_player ())
221 return;
222
223 // TODO: just assume, and rip out?
224 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
225 {
226 LOG (llevDebug, "Non supported extension text type for client.\n");
227 new_draw_info (flags, pri, pl, vformat (old_format, ap));
228 }
229 else
230 {
231 char *buf = vformat (new_format, ap);
232 strip_media_tag (buf);
233 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf);
234 }
235
236 va_end (ap);
237}
238
239/** 174/**
240 * Writes to everyone on the map *except* op. This is useful for emotions. 175 * Writes to everyone on the map *except* op. This is useful for emotions.
241 */ 176 */
242
243void 177void
244new_info_map_except (int color, maptile * map, object *op, const char *str) 178new_info_map_except (int color, maptile * map, object *op, const char *str)
245{ 179{
246 for_all_players (pl) 180 for_all_players (pl)
247 if (pl->ob->map == map && pl->ob != op) 181 if (pl->ob->map == map && pl->ob != op)
248 new_draw_info (color, 0, pl->ob, str);
249}
250
251/**
252 * Writes to everyone on the map except op1 and op2
253 */
254void
255new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str)
256{
257 for_all_players (pl)
258 if (pl->ob->map == map && pl->ob != op1 && pl->ob != op2)
259 new_draw_info (color, 0, pl->ob, str); 182 new_draw_info (color, 0, pl->ob, str);
260} 183}
261 184
262/** 185/**
263 * Writes to everyone on the specified map 186 * Writes to everyone on the specified map
283 sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title); 206 sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title);
284} 207}
285 208
286// formerly a macro, used only by magic map, so optimised it out 209// formerly a macro, used only by magic map, so optimised it out
287static inline faceidx 210static inline faceidx
288GET_MAP_FACE (maptile *m, int x, int y, int layer) 211GET_MAP_FACE (mapspace &ms, int layer)
289{ 212{
290 if (object *op = GET_MAP_FACE_OBJ (m, x, y, layer)) 213 if (object *op = ms.faces_obj [layer])
291 return op->face; 214 return op->face;
292 else 215 else
293 return 0; 216 return 0;
294} 217}
295 218
305 * for various code values. 228 * for various code values.
306 */ 229 */
307static void 230static void
308magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) 231magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py)
309{ 232{
310 int x, y, dx, dy, mflags;
311 sint16 nx, ny;
312 maptile *mp;
313
314 for (dx = -1; dx <= 1; dx++) 233 for (int dx = -1; dx <= 1; dx++)
315 { 234 {
316 for (dy = -1; dy <= 1; dy++) 235 for (int dy = -1; dy <= 1; dy++)
317 { 236 {
318 x = px + dx; 237 int x = px + dx;
319 y = py + dy; 238 int y = py + dy;
320 239
321 if (FABS (x) >= MAGIC_MAP_HALF || FABS (y) >= MAGIC_MAP_HALF) 240 if (abs (x) >= MAGIC_MAP_HALF || abs (y) >= MAGIC_MAP_HALF)
322 continue; 241 continue;
323 242
324 mp = pl->map; 243 mapxy pos (pl);
325 nx = pl->x + x; 244 pos.move (x, y);
326 ny = pl->y + y;
327 245
328 mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); 246 if (!pos.normalise ())
329 if (mflags & P_OUT_OF_MAP)
330 continue; 247 continue;
248
249 mapspace &ms = pos.ms ();
331 250
332 if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0) 251 if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0)
333 { 252 {
253 int mflags = ms.flags ();
254
334 int f = GET_MAP_FACE (mp, nx, ny, 0); 255 int f = GET_MAP_FACE (ms, 0);
335 if (f == blank_face) 256 if (f == blank_face)
336 { 257 {
337 f = GET_MAP_FACE (mp, nx, ny, 1); 258 f = GET_MAP_FACE (ms, 1);
338 if (f == blank_face) 259 if (f == blank_face)
339 f = GET_MAP_FACE (mp, nx, ny, 2); 260 f = GET_MAP_FACE (ms, 2);
340 } 261 }
341 262
342 int magicmap = faces [f].magicmap; 263 int magicmap = faces [f].magicmap;
343 264
344 /* Should probably have P_NO_MAGIC here also, but then shops don't 265 /* Should probably have P_NO_MAGIC here also, but then shops don't
357} 278}
358 279
359/** 280/**
360 * Creates magic map for player. 281 * Creates magic map for player.
361 * 282 *
362 * Note: For improved magic mapping display, the space that blocks 283 * Note: For improved magic mapping display, the space that blocks
363 * the view is now marked with value 2. Any dependencies of map_mark 284 * the view is now marked with value 2. Any dependencies of map_mark
364 * being nonzero have been changed to check for 1. Also, since 285 * being nonzero have been changed to check for 1. Also, since
365 * map_mark is a char value, putting 2 in should cause no problems. 286 * map_mark is a char value, putting 2 in should cause no problems.
366 * 287 *
367 * This function examines the map the player is on, and determines what 288 * This function examines the map the player is on, and determines what
368 * is visible. 2 is set for walls or objects that blocks view. 1 289 * is visible. 2 is set for walls or objects that blocks view. 1
369 * is for open spaces. map_mark should already have been initialised 290 * is for open spaces. map_mark should already have been initialised
370 * to zero before this is called. 291 * to zero before this is called.
371 * strength is an initial strength*2 rectangular area that we automatically 292 * strength is an initial strength*2 rectangular area that we automatically
372 * see in/penetrate through. 293 * see in/penetrate through.
373 */ 294 */
374void 295static void
375magic_mapping_mark (object *pl, char *map_mark, int strength) 296magic_mapping_mark (object *pl, char *map_mark, int strength)
376{ 297{
377 int x, y, mflags;
378 sint16 nx, ny;
379 maptile *mp;
380
381 for (x = -strength; x < strength; x++) 298 for (int x = -strength; x < strength; x++)
382 { 299 {
383 for (y = -strength; y < strength; y++) 300 for (int y = -strength; y < strength; y++)
384 { 301 {
385 mp = pl->map; 302 mapxy pos (pl);
386 nx = pl->x + x; 303 pos.move (x, y);
387 ny = pl->y + y;
388 304
389 mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); 305 if (!pos.normalise ())
390 if (mflags & P_OUT_OF_MAP)
391 continue; 306 continue;
392 307
308 mapspace &ms = pos.ms ();
309
310 int mflags = ms.flags ();
311
393 int f = GET_MAP_FACE (mp, nx, ny, 0); 312 int f = GET_MAP_FACE (ms, 0);
394 if (f == blank_face) 313 if (f == blank_face)
395 { 314 {
396 f = GET_MAP_FACE (mp, nx, ny, 1); 315 f = GET_MAP_FACE (ms, 1);
397 if (f == blank_face) 316 if (f == blank_face)
398 f = GET_MAP_FACE (mp, nx, ny, 2); 317 f = GET_MAP_FACE (ms, 2);
399 } 318 }
400 319
401 int magicmap = faces [f].magicmap; 320 int magicmap = faces [f].magicmap;
402 321
403 if (mflags & P_BLOCKSVIEW) 322 if (mflags & P_BLOCKSVIEW)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines