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.48 by root, Tue May 6 16:44:54 2008 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 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 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/**
47 */ 48 */
48static void 49static void
49esrv_print_msg (client *ns, int color, const char *str) 50esrv_print_msg (client *ns, int color, const char *str)
50{ 51{
51 ns->send_msg (color, "info", str); 52 ns->send_msg (color, "info", str);
52}
53
54/**
55 * Draws an extended message on the client.
56 * ns the socket to send message to
57 * color color informations (used mainly if client does not support message type)
58 * type,
59 * subtype type and subtype of text message
60 * intro Intro message to send with main message if client does not support the message type
61 * message The main message
62 */
63static void
64esrv_print_ext_msg (client *ns, int color, uint8 type, uint8 subtype, const char *message)
65{
66 ns->send_packet_printf ("drawextinfo %d %u %u %s", color, type, subtype, message);
67} 53}
68 54
69/** 55/**
70 * Frontend for esrv_print_msg 56 * Frontend for esrv_print_msg
71 * \param colr message color 57 * \param colr message color
139/** 125/**
140 * Sends message to player(s). 126 * Sends message to player(s).
141 * 127 *
142 * flags is various flags - mostly color, plus a few specials. 128 * flags is various flags - mostly color, plus a few specials.
143 * 129 *
144 * pri is priority. It is a little odd - the lower the value, the more 130 * 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 * 131 *
149 * pl can be passed as NULL - in fact, this will be done if NDI_ALL is set 132 * pl can be passed as NULL - in fact, this will be done if NDI_ALL is set
150 * in the flags. 133 * in the flags.
151 * 134 *
152 * If message is black, and not NDI_UNIQUE, gets sent through output buffers. 135 * 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) 139new_draw_info (int flags, int pri, const object *op, const char *buf)
157{ 140{
158 if (flags & NDI_ALL) 141 if (flags & NDI_ALL)
159 { 142 {
160 for_all_players (pl) 143 for_all_players (pl)
161 new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf); 144 new_draw_info (flags & ~NDI_ALL, 0, pl->ob, buf);
162 } 145 }
163 else 146 else
164 { 147 {
165 if (!op || !op->contr || !op->contr->ns) 148 if (!op || !op->contr || !op->contr->ns)
166 return;
167
168 if (pri >= op->contr->listening)
169 return; 149 return;
170 150
171 if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK 151 if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK
172 || !op->contr->ns->msg_suppressed (buf)) 152 || !op->contr->ns->msg_suppressed (buf))
173 print_message (flags & NDI_COLOR_MASK, op, buf); 153 print_message (flags & NDI_COLOR_MASK, op, buf);
183 * client/server bandwidth (client could keep track of various strings 163 * client/server bandwidth (client could keep track of various strings
184 */ 164 */
185void 165void
186new_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, ...)
187{ 167{
188 char buf[HUGE_BUF];
189
190 va_list ap; 168 va_list ap;
191 va_start (ap, format); 169 va_start (ap, format);
192 vsnprintf (buf, HUGE_BUF, format, ap); 170 new_draw_info (flags, pri, pl, vformat (format, ap));
193 va_end (ap); 171 va_end (ap);
194
195 new_draw_info (flags, pri, pl, buf);
196}
197
198void
199draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
200{
201
202 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
203 return;
204
205 if (pri >= pl->contr->listening)
206 return;
207
208 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
209 {
210 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1);
211
212 if (buf == NULL)
213 LOG (llevError, "info::draw_ext_info -> Out of memory!");
214 else
215 {
216 strcpy (buf, oldmessage == NULL ? message : oldmessage);
217 strip_media_tag (buf);
218 new_draw_info (flags, pri, pl, buf);
219 free (buf);
220 }
221 }
222 else
223 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, message);
224}
225
226void
227draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...)
228{
229 char buf[HUGE_BUF];
230
231 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
232 return;
233
234 if (pri >= pl->contr->listening)
235 return;
236
237 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
238 {
239 va_list ap;
240
241 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);
246 return;
247 }
248 else
249 {
250 va_list 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);
256 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf);
257 }
258} 172}
259 173
260/** 174/**
261 * 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.
262 */ 176 */
263
264void 177void
265new_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)
266{ 179{
267 for_all_players (pl) 180 for_all_players (pl)
268 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) 181 if (pl->ob->map == map && pl->ob != op)
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 map except op1 and op2 186 * Writes to everyone on the specified map
274 */ 187 */
275void 188void
276new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) 189new_info_map (int color, maptile * map, const char *str)
277{ 190{
278 for_all_players (pl) 191 for_all_players (pl)
279 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2)
280 new_draw_info (color, 0, pl->ob, str);
281}
282
283/**
284 * Writes to everyone on the specified map
285 */
286void
287new_info_map (int color, maptile * map, const char *str)
288{
289 for_all_players (pl)
290 if (pl->ob != NULL && pl->ob->map == map) 192 if (pl->ob->map == map)
291 new_draw_info (color, 0, pl->ob, str); 193 new_draw_info (color, 0, pl->ob, str);
292} 194}
293 195
294/** 196/**
295 * Sets player title. 197 * Sets player title.
304 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);
305} 207}
306 208
307// 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
308static inline faceidx 210static inline faceidx
309GET_MAP_FACE (maptile *m, int x, int y, int layer) 211GET_MAP_FACE (mapspace &ms, int layer)
310{ 212{
311 if (object *op = GET_MAP_FACE_OBJ (m, x, y, layer)) 213 if (object *op = ms.faces_obj [layer])
312 return op->face; 214 return op->face;
313 else 215 else
314 return 0; 216 return 0;
315} 217}
316 218
326 * for various code values. 228 * for various code values.
327 */ 229 */
328static void 230static void
329magic_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)
330{ 232{
331 int x, y, dx, dy, mflags;
332 sint16 nx, ny;
333 maptile *mp;
334
335 for (dx = -1; dx <= 1; dx++) 233 for (int dx = -1; dx <= 1; dx++)
336 { 234 {
337 for (dy = -1; dy <= 1; dy++) 235 for (int dy = -1; dy <= 1; dy++)
338 { 236 {
339 x = px + dx; 237 int x = px + dx;
340 y = py + dy; 238 int y = py + dy;
341 239
342 if (FABS (x) >= MAGIC_MAP_HALF || FABS (y) >= MAGIC_MAP_HALF) 240 if (abs (x) >= MAGIC_MAP_HALF || abs (y) >= MAGIC_MAP_HALF)
343 continue; 241 continue;
344 242
345 mp = pl->map; 243 mapxy pos (pl);
346 nx = pl->x + x; 244 pos.move (x, y);
347 ny = pl->y + y;
348 245
349 mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); 246 if (!pos.normalise ())
350 if (mflags & P_OUT_OF_MAP)
351 continue; 247 continue;
248
249 mapspace &ms = pos.ms ();
352 250
353 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)
354 { 252 {
253 int mflags = ms.flags ();
254
355 int f = GET_MAP_FACE (mp, nx, ny, 0); 255 int f = GET_MAP_FACE (ms, 0);
356 if (f == blank_face) 256 if (f == blank_face)
357 { 257 {
358 f = GET_MAP_FACE (mp, nx, ny, 1); 258 f = GET_MAP_FACE (ms, 1);
359 if (f == blank_face) 259 if (f == blank_face)
360 f = GET_MAP_FACE (mp, nx, ny, 2); 260 f = GET_MAP_FACE (ms, 2);
361 } 261 }
362 262
363 int magicmap = faces [f].magicmap; 263 int magicmap = faces [f].magicmap;
364 264
365 /* 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
378} 278}
379 279
380/** 280/**
381 * Creates magic map for player. 281 * Creates magic map for player.
382 * 282 *
383 * Note: For improved magic mapping display, the space that blocks 283 * Note: For improved magic mapping display, the space that blocks
384 * 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
385 * being nonzero have been changed to check for 1. Also, since 285 * 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. 286 * map_mark is a char value, putting 2 in should cause no problems.
387 * 287 *
388 * 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
389 * 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
390 * is for open spaces. map_mark should already have been initialised 290 * is for open spaces. map_mark should already have been initialised
391 * to zero before this is called. 291 * to zero before this is called.
392 * strength is an initial strength*2 rectangular area that we automatically 292 * strength is an initial strength*2 rectangular area that we automatically
393 * see in/penetrate through. 293 * see in/penetrate through.
394 */ 294 */
395void 295static void
396magic_mapping_mark (object *pl, char *map_mark, int strength) 296magic_mapping_mark (object *pl, char *map_mark, int strength)
397{ 297{
398 int x, y, mflags;
399 sint16 nx, ny;
400 maptile *mp;
401
402 for (x = -strength; x < strength; x++) 298 for (int x = -strength; x < strength; x++)
403 { 299 {
404 for (y = -strength; y < strength; y++) 300 for (int y = -strength; y < strength; y++)
405 { 301 {
406 mp = pl->map; 302 mapxy pos (pl);
407 nx = pl->x + x; 303 pos.move (x, y);
408 ny = pl->y + y;
409 304
410 mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); 305 if (!pos.normalise ())
411 if (mflags & P_OUT_OF_MAP)
412 continue; 306 continue;
413 307
308 mapspace &ms = pos.ms ();
309
310 int mflags = ms.flags ();
311
414 int f = GET_MAP_FACE (mp, nx, ny, 0); 312 int f = GET_MAP_FACE (ms, 0);
415 if (f == blank_face) 313 if (f == blank_face)
416 { 314 {
417 f = GET_MAP_FACE (mp, nx, ny, 1); 315 f = GET_MAP_FACE (ms, 1);
418 if (f == blank_face) 316 if (f == blank_face)
419 f = GET_MAP_FACE (mp, nx, ny, 2); 317 f = GET_MAP_FACE (ms, 2);
420 } 318 }
421 319
422 int magicmap = faces [f].magicmap; 320 int magicmap = faces [f].magicmap;
423 321
424 if (mflags & P_BLOCKSVIEW) 322 if (mflags & P_BLOCKSVIEW)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines