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