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.52 by root, Mon Oct 12 14:00:59 2009 UTC vs.
Revision 1.66 by root, Mon Oct 29 23:55:57 2012 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,2011,2012 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.
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 Affero GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * 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>
23 */ 23 */
24 24
25/** 25/**
26 * \file 26 * \file
51{ 51{
52 ns->send_msg (color, "info", str); 52 ns->send_msg (color, "info", str);
53} 53}
54 54
55/** 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}
69
70/**
71 * Frontend for esrv_print_msg 56 * Frontend for esrv_print_msg
72 * \param colr message color 57 * \param colr message color
73 * \param pl player to send to. Can be NULL 58 * \param pl player to send to. Can be NULL
74 * \param tmp message to send. Can be NULL 59 * \param tmp message to send. Can be NULL
75 * 60 *
108 for (msg_buf *buf = msgbuf; buf < msgbuf + MSG_BUF_COUNT; ++buf) 93 for (msg_buf *buf = msgbuf; buf < msgbuf + MSG_BUF_COUNT; ++buf)
109 { 94 {
110 if (len == buf->len && !memcmp (msg, buf->msg, len)) 95 if (len == buf->len && !memcmp (msg, buf->msg, len))
111 { 96 {
112 // found matching buf, see if expired 97 // found matching buf, see if expired
113 if (buf->expire <= pticks || !buf->count) 98 if (buf->expire <= server_tick || !buf->count)
114 { 99 {
115 // yes, take over matching buffer, print 100 // yes, take over matching buffer, print
116 buf->expire = pticks + pl->outputs_sync; 101 buf->expire = server_tick + pl->outputs_sync;
117 buf->count = pl->outputs_count; 102 buf->count = pl->outputs_count;
118 103
119 return false; 104 return false;
120 } 105 }
121 106
127 if (lru->expire > buf->expire) 112 if (lru->expire > buf->expire)
128 lru = buf; 113 lru = buf;
129 } 114 }
130 115
131 // new message, evoke oldest buffer 116 // new message, evoke oldest buffer
132 lru->expire = pticks + pl->outputs_sync; 117 lru->expire = server_tick + pl->outputs_sync;
133 lru->count = pl->outputs_count; 118 lru->count = pl->outputs_count;
134 lru->len = len; 119 lru->len = len;
135 memcpy (lru->msg, msg, len); 120 memcpy (lru->msg, msg, len);
136 121
137 return false; 122 return false;
178 * client/server bandwidth (client could keep track of various strings 163 * client/server bandwidth (client could keep track of various strings
179 */ 164 */
180void 165void
181new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...) 166new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...)
182{ 167{
183 char buf[HUGE_BUF];
184
185 va_list ap; 168 va_list ap;
186 va_start (ap, format); 169 va_start (ap, format);
187 vsnprintf (buf, HUGE_BUF, format, ap); 170 new_draw_info (flags, pri, pl, vformat (format, ap));
188 va_end (ap); 171 va_end (ap);
189
190 new_draw_info (flags, pri, pl, buf);
191}
192
193void
194draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
195{
196
197 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
198 return;
199
200 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
201 {
202 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1);
203
204 if (buf == NULL)
205 LOG (llevError, "info::draw_ext_info -> Out of memory!");
206 else
207 {
208 strcpy (buf, oldmessage == NULL ? message : oldmessage);
209 strip_media_tag (buf);
210 new_draw_info (flags, pri, pl, buf);
211 free (buf);
212 }
213 }
214 else
215 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, message);
216}
217
218void
219draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...)
220{
221 char buf[HUGE_BUF];
222
223 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
224 return;
225
226 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
227 {
228 va_list ap;
229
230 LOG (llevDebug, "Non supported extension text type for client.\n");
231 va_start (ap, new_format);
232 vsnprintf (buf, HUGE_BUF, old_format, ap);
233 va_end (ap);
234 new_draw_info (flags, pri, pl, buf);
235 return;
236 }
237 else
238 {
239 va_list ap;
240
241 va_start (ap, new_format);
242 vsnprintf (buf, HUGE_BUF, new_format, ap);
243 va_end (ap);
244 strip_media_tag (buf);
245 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf);
246 }
247} 172}
248 173
249/** 174/**
250 * 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.
251 */ 176 */
252
253void 177void
254new_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)
255{ 179{
256 for_all_players (pl) 180 for_all_players (pl)
257 if (pl->ob->map == map && pl->ob != op) 181 if (pl->ob->map == map && pl->ob != op)
258 new_draw_info (color, 0, pl->ob, str);
259}
260
261/**
262 * Writes to everyone on the map except op1 and op2
263 */
264void
265new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str)
266{
267 for_all_players (pl)
268 if (pl->ob->map == map && pl->ob != op1 && pl->ob != op2)
269 new_draw_info (color, 0, pl->ob, str); 182 new_draw_info (color, 0, pl->ob, str);
270} 183}
271 184
272/** 185/**
273 * Writes to everyone on the specified map 186 * Writes to everyone on the specified map
293 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);
294} 207}
295 208
296// 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
297static inline faceidx 210static inline faceidx
298GET_MAP_FACE (maptile *m, int x, int y, int layer) 211GET_MAP_FACE (mapspace &ms, int layer)
299{ 212{
300 if (object *op = GET_MAP_FACE_OBJ (m, x, y, layer)) 213 if (object *op = ms.faces_obj [layer])
301 return op->face; 214 return op->face;
302 else 215 else
303 return 0; 216 return 0;
304} 217}
305 218
315 * for various code values. 228 * for various code values.
316 */ 229 */
317static void 230static void
318magic_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)
319{ 232{
320 int x, y, dx, dy, mflags;
321 sint16 nx, ny;
322 maptile *mp;
323
324 for (dx = -1; dx <= 1; dx++) 233 for (int dx = -1; dx <= 1; dx++)
325 { 234 {
326 for (dy = -1; dy <= 1; dy++) 235 for (int dy = -1; dy <= 1; dy++)
327 { 236 {
328 x = px + dx; 237 int x = px + dx;
329 y = py + dy; 238 int y = py + dy;
330 239
331 if (FABS (x) >= MAGIC_MAP_HALF || FABS (y) >= MAGIC_MAP_HALF) 240 if (abs (x) >= MAGIC_MAP_HALF || abs (y) >= MAGIC_MAP_HALF)
332 continue; 241 continue;
333 242
334 mp = pl->map; 243 mapxy pos (pl);
335 nx = pl->x + x; 244 pos.move (x, y);
336 ny = pl->y + y;
337 245
338 mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); 246 if (!pos.normalise ())
339 if (mflags & P_OUT_OF_MAP)
340 continue; 247 continue;
248
249 mapspace &ms = pos.ms ();
341 250
342 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)
343 { 252 {
253 int mflags = ms.flags ();
254
344 int f = GET_MAP_FACE (mp, nx, ny, 0); 255 int f = GET_MAP_FACE (ms, 0);
345 if (f == blank_face) 256 if (f == blank_face)
346 { 257 {
347 f = GET_MAP_FACE (mp, nx, ny, 1); 258 f = GET_MAP_FACE (ms, 1);
348 if (f == blank_face) 259 if (f == blank_face)
349 f = GET_MAP_FACE (mp, nx, ny, 2); 260 f = GET_MAP_FACE (ms, 2);
350 } 261 }
351 262
352 int magicmap = faces [f].magicmap; 263 int magicmap = faces [f].magicmap;
353 264
354 /* 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
367} 278}
368 279
369/** 280/**
370 * Creates magic map for player. 281 * Creates magic map for player.
371 * 282 *
372 * Note: For improved magic mapping display, the space that blocks 283 * Note: For improved magic mapping display, the space that blocks
373 * 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
374 * being nonzero have been changed to check for 1. Also, since 285 * being nonzero have been changed to check for 1. Also, since
375 * 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.
376 * 287 *
377 * 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
378 * 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
379 * is for open spaces. map_mark should already have been initialised 290 * is for open spaces. map_mark should already have been initialised
380 * to zero before this is called. 291 * to zero before this is called.
381 * strength is an initial strength*2 rectangular area that we automatically 292 * strength is an initial strength*2 rectangular area that we automatically
382 * see in/penetrate through. 293 * see in/penetrate through.
383 */ 294 */
384void 295static void
385magic_mapping_mark (object *pl, char *map_mark, int strength) 296magic_mapping_mark (object *pl, char *map_mark, int strength)
386{ 297{
387 int x, y, mflags;
388 sint16 nx, ny;
389 maptile *mp;
390
391 for (x = -strength; x < strength; x++) 298 for (int x = -strength; x < strength; x++)
392 { 299 {
393 for (y = -strength; y < strength; y++) 300 for (int y = -strength; y < strength; y++)
394 { 301 {
395 mp = pl->map; 302 mapxy pos (pl);
396 nx = pl->x + x; 303 pos.move (x, y);
397 ny = pl->y + y;
398 304
399 mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); 305 if (!pos.normalise ())
400 if (mflags & P_OUT_OF_MAP)
401 continue; 306 continue;
402 307
308 mapspace &ms = pos.ms ();
309
310 int mflags = ms.flags ();
311
403 int f = GET_MAP_FACE (mp, nx, ny, 0); 312 int f = GET_MAP_FACE (ms, 0);
404 if (f == blank_face) 313 if (f == blank_face)
405 { 314 {
406 f = GET_MAP_FACE (mp, nx, ny, 1); 315 f = GET_MAP_FACE (ms, 1);
407 if (f == blank_face) 316 if (f == blank_face)
408 f = GET_MAP_FACE (mp, nx, ny, 2); 317 f = GET_MAP_FACE (ms, 2);
409 } 318 }
410 319
411 int magicmap = faces [f].magicmap; 320 int magicmap = faces [f].magicmap;
412 321
413 if (mflags & P_BLOCKSVIEW) 322 if (mflags & P_BLOCKSVIEW)
430 * Mark Wedel 339 * Mark Wedel
431 */ 340 */
432void 341void
433draw_magic_map (object *pl) 342draw_magic_map (object *pl)
434{ 343{
435 char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1);
436 int xmin, xmax, ymin, ymax; 344 int xmin, xmax, ymin, ymax;
437 345
438 if (pl->type != PLAYER) 346 if (pl->type != PLAYER)
439 { 347 {
440 LOG (llevError, "Non player object called draw_map.\n"); 348 LOG (llevError, "Non player object called draw_map.\n");
441 return; 349 return;
442 } 350 }
351
352 char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1);
353 assert(("Out of memory!", map_mark != NULL));
443 354
444 /* First, we figure out what spaces are 'reachable' by the player */ 355 /* First, we figure out what spaces are 'reachable' by the player */
445 magic_mapping_mark (pl, map_mark, 3); 356 magic_mapping_mark (pl, map_mark, 3);
446 357
447 /* We now go through and figure out what spaces have been 358 /* We now go through and figure out what spaces have been

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines