1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * This program 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 2 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, write to the Free Software |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | /** |
25 | /** |
26 | * \file |
26 | * \file |
27 | * Basic client output functions. |
27 | * Basic client output functions. |
… | |
… | |
36 | #include <sproto.h> |
36 | #include <sproto.h> |
37 | #include <stdarg.h> |
37 | #include <stdarg.h> |
38 | #include <spells.h> |
38 | #include <spells.h> |
39 | #include <skills.h> |
39 | #include <skills.h> |
40 | |
40 | |
|
|
41 | #include <cstring> |
|
|
42 | |
41 | /** |
43 | /** |
42 | * Draws a normal message on the client. It is pretty |
44 | * Draws a normal message on the client. It is pretty |
43 | * much the same thing as the draw_info above, but takes a color |
45 | * much the same thing as the draw_info above, but takes a color |
44 | * parameter. the esrv_drawinfo functions should probably be |
46 | * parameter. the esrv_drawinfo functions should probably be |
45 | * replaced with this, just using black as the color. |
47 | * replaced with this, just using black as the color. |
46 | */ |
48 | */ |
47 | static void |
49 | static void |
48 | esrv_print_msg (client *ns, int color, const char *str) |
50 | esrv_print_msg (client *ns, int color, const char *str) |
49 | { |
51 | { |
50 | ns->send_packet_printf ("drawinfo %d %s", color, str); |
52 | ns->send_msg (color, "info", str); |
51 | } |
|
|
52 | |
|
|
53 | /** |
|
|
54 | * Draws an extended message on the client. |
|
|
55 | * ns the socket to send message to |
|
|
56 | * color color informations (used mainly if client does not support message type) |
|
|
57 | * type, |
|
|
58 | * subtype type and subtype of text message |
|
|
59 | * intro Intro message to send with main message if client does not support the message type |
|
|
60 | * message The main message |
|
|
61 | */ |
|
|
62 | static void |
|
|
63 | esrv_print_ext_msg (client *ns, int color, uint8 type, uint8 subtype, const char *message) |
|
|
64 | { |
|
|
65 | ns->send_packet_printf ("drawextinfo %d %hhu %hhu %s", color, type, subtype, message); |
|
|
66 | } |
53 | } |
67 | |
54 | |
68 | /** |
55 | /** |
69 | * Frontend for esrv_print_msg |
56 | * Frontend for esrv_print_msg |
70 | * \param colr message color |
57 | * \param colr message color |
… | |
… | |
83 | |
70 | |
84 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
71 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
85 | return; |
72 | return; |
86 | |
73 | |
87 | if (pl->type == PLAYER) |
74 | if (pl->type == PLAYER) |
88 | esrv_print_msg (pl->contr->ns, colr, (char *) tmp); |
75 | esrv_print_msg (pl->contr->ns, colr, (char *)tmp); |
89 | } |
76 | } |
90 | |
77 | |
91 | bool |
78 | bool |
92 | client::msg_suppressed (const char *msg) |
79 | client::msg_suppressed (const char *msg) |
93 | { |
80 | { |
… | |
… | |
106 | for (msg_buf *buf = msgbuf; buf < msgbuf + MSG_BUF_COUNT; ++buf) |
93 | for (msg_buf *buf = msgbuf; buf < msgbuf + MSG_BUF_COUNT; ++buf) |
107 | { |
94 | { |
108 | if (len == buf->len && !memcmp (msg, buf->msg, len)) |
95 | if (len == buf->len && !memcmp (msg, buf->msg, len)) |
109 | { |
96 | { |
110 | // found matching buf, see if expired |
97 | // found matching buf, see if expired |
111 | if (buf->expire <= pticks || !buf->count) |
98 | if (buf->expire <= server_tick || !buf->count) |
112 | { |
99 | { |
113 | // yes, take over matching buffer, print |
100 | // yes, take over matching buffer, print |
114 | buf->expire = pticks + pl->outputs_sync; |
101 | buf->expire = server_tick + pl->outputs_sync; |
115 | buf->count = pl->outputs_count; |
102 | buf->count = pl->outputs_count; |
116 | |
103 | |
117 | return false; |
104 | return false; |
118 | } |
105 | } |
119 | |
106 | |
… | |
… | |
125 | if (lru->expire > buf->expire) |
112 | if (lru->expire > buf->expire) |
126 | lru = buf; |
113 | lru = buf; |
127 | } |
114 | } |
128 | |
115 | |
129 | // new message, evoke oldest buffer |
116 | // new message, evoke oldest buffer |
130 | lru->expire = pticks + pl->outputs_sync; |
117 | lru->expire = server_tick + pl->outputs_sync; |
131 | lru->count = pl->outputs_count; |
118 | lru->count = pl->outputs_count; |
132 | lru->len = len; |
119 | lru->len = len; |
133 | memcpy (lru->msg, msg, len); |
120 | memcpy (lru->msg, msg, len); |
134 | |
121 | |
135 | return false; |
122 | return false; |
… | |
… | |
138 | /** |
125 | /** |
139 | * Sends message to player(s). |
126 | * Sends message to player(s). |
140 | * |
127 | * |
141 | * flags is various flags - mostly color, plus a few specials. |
128 | * flags is various flags - mostly color, plus a few specials. |
142 | * |
129 | * |
143 | * pri is priority. It is a little odd - the lower the value, the more |
130 | * pri is unused. |
144 | * important it is. Thus, 0 gets sent no matter what. Otherwise, the |
|
|
145 | * value must be less than the listening level that the player has set. |
|
|
146 | * Unfortunately, there is no clear guideline on what each level does what. |
|
|
147 | * |
131 | * |
148 | * 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 |
149 | * in the flags. |
133 | * in the flags. |
150 | * |
134 | * |
151 | * 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. |
152 | * |
136 | * |
153 | */ |
137 | */ |
154 | void |
138 | void |
155 | new_draw_info (int flags, int pri, const object *pl, const char *buf) |
139 | new_draw_info (int flags, int pri, const object *op, const char *buf) |
156 | { |
140 | { |
157 | if (flags & NDI_ALL) |
141 | if (flags & NDI_ALL) |
158 | { |
142 | { |
159 | for_all_players (pl) |
143 | for_all_players (pl) |
160 | new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf); |
144 | new_draw_info (flags & ~NDI_ALL, 0, pl->ob, buf); |
161 | |
145 | } |
|
|
146 | else |
|
|
147 | { |
|
|
148 | if (!op || !op->contr || !op->contr->ns) |
162 | return; |
149 | return; |
163 | } |
|
|
164 | |
150 | |
165 | if (!pl || pl->type != PLAYER || !pl->contr || !pl->contr->ns) |
|
|
166 | return; |
|
|
167 | |
|
|
168 | if (pri >= pl->contr->listening) |
|
|
169 | return; |
|
|
170 | |
|
|
171 | if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK |
151 | if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK |
172 | || !pl->contr->ns->msg_suppressed (buf)) |
152 | || !op->contr->ns->msg_suppressed (buf)) |
173 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
153 | print_message (flags & NDI_COLOR_MASK, op, buf); |
|
|
154 | } |
174 | } |
155 | } |
175 | |
156 | |
176 | /** |
157 | /** |
177 | * Wrapper for new_draw_info printf-like. |
158 | * Wrapper for new_draw_info printf-like. |
178 | * |
159 | * |
… | |
… | |
182 | * client/server bandwidth (client could keep track of various strings |
163 | * client/server bandwidth (client could keep track of various strings |
183 | */ |
164 | */ |
184 | void |
165 | void |
185 | 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, ...) |
186 | { |
167 | { |
187 | char buf[HUGE_BUF]; |
|
|
188 | |
|
|
189 | va_list ap; |
168 | va_list ap; |
190 | va_start (ap, format); |
169 | va_start (ap, format); |
191 | vsnprintf (buf, HUGE_BUF, format, ap); |
170 | new_draw_info (flags, pri, pl, vformat (format, ap)); |
192 | va_end (ap); |
171 | va_end (ap); |
193 | |
|
|
194 | new_draw_info (flags, pri, pl, buf); |
|
|
195 | } |
|
|
196 | |
|
|
197 | void |
|
|
198 | draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage) |
|
|
199 | { |
|
|
200 | |
|
|
201 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
|
|
202 | return; |
|
|
203 | |
|
|
204 | if (pri >= pl->contr->listening) |
|
|
205 | return; |
|
|
206 | |
|
|
207 | if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type)) |
|
|
208 | { |
|
|
209 | char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); |
|
|
210 | |
|
|
211 | if (buf == NULL) |
|
|
212 | LOG (llevError, "info::draw_ext_info -> Out of memory!"); |
|
|
213 | else |
|
|
214 | { |
|
|
215 | strcpy (buf, oldmessage == NULL ? message : oldmessage); |
|
|
216 | strip_media_tag (buf); |
|
|
217 | new_draw_info (flags, pri, pl, buf); |
|
|
218 | free (buf); |
|
|
219 | } |
|
|
220 | } |
|
|
221 | else |
|
|
222 | esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, message); |
|
|
223 | } |
|
|
224 | |
|
|
225 | void |
|
|
226 | draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) |
|
|
227 | { |
|
|
228 | char buf[HUGE_BUF]; |
|
|
229 | |
|
|
230 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
|
|
231 | return; |
|
|
232 | |
|
|
233 | if (pri >= pl->contr->listening) |
|
|
234 | return; |
|
|
235 | |
|
|
236 | if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type)) |
|
|
237 | { |
|
|
238 | va_list ap; |
|
|
239 | |
|
|
240 | LOG (llevDebug, "Non supported extension text type for client.\n"); |
|
|
241 | va_start (ap, new_format); |
|
|
242 | vsnprintf (buf, HUGE_BUF, old_format, ap); |
|
|
243 | va_end (ap); |
|
|
244 | new_draw_info (flags, pri, pl, buf); |
|
|
245 | return; |
|
|
246 | } |
|
|
247 | else |
|
|
248 | { |
|
|
249 | va_list ap; |
|
|
250 | |
|
|
251 | va_start (ap, new_format); |
|
|
252 | vsnprintf (buf, HUGE_BUF, new_format, ap); |
|
|
253 | va_end (ap); |
|
|
254 | strip_media_tag (buf); |
|
|
255 | esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf); |
|
|
256 | } |
|
|
257 | } |
172 | } |
258 | |
173 | |
259 | /** |
174 | /** |
260 | * 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. |
261 | */ |
176 | */ |
262 | |
|
|
263 | void |
177 | void |
264 | 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) |
265 | { |
179 | { |
266 | for_all_players (pl) |
180 | for_all_players (pl) |
267 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) |
181 | if (pl->ob->map == map && pl->ob != op) |
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 map except op1 and op2 |
186 | * Writes to everyone on the specified map |
273 | */ |
187 | */ |
274 | |
|
|
275 | void |
188 | void |
276 | new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) |
189 | new_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) |
192 | if (pl->ob->map == map) |
280 | new_draw_info (color, 0, pl->ob, str); |
193 | new_draw_info (color, 0, pl->ob, str); |
281 | } |
|
|
282 | |
|
|
283 | /** |
|
|
284 | * Writes to everyone on the specified map |
|
|
285 | */ |
|
|
286 | |
|
|
287 | void |
|
|
288 | new_info_map (int color, maptile * map, const char *str) |
|
|
289 | { |
|
|
290 | for_all_players (pl) |
|
|
291 | if (pl->ob != NULL && pl->ob->map == map) |
|
|
292 | new_draw_info (color, 0, pl->ob, str); |
|
|
293 | } |
|
|
294 | |
|
|
295 | /** |
|
|
296 | * This does nothing now. However, in theory, we should probably send |
|
|
297 | * something to the client and let the client figure out how it might want |
|
|
298 | * to handle this |
|
|
299 | */ |
|
|
300 | void |
|
|
301 | clear_win_info (object *op) |
|
|
302 | { |
|
|
303 | } |
|
|
304 | |
|
|
305 | /** |
|
|
306 | * Get player's current range attack in obuf. |
|
|
307 | */ |
|
|
308 | void |
|
|
309 | rangetostring (object *pl, char *obuf) |
|
|
310 | { |
|
|
311 | switch (pl->contr->shoottype) |
|
|
312 | { |
|
|
313 | case range_none: |
|
|
314 | strcpy (obuf, "Range: nothing"); |
|
|
315 | break; |
|
|
316 | |
|
|
317 | case range_bow: |
|
|
318 | { |
|
|
319 | object *op; |
|
|
320 | |
|
|
321 | for (op = pl->inv; op; op = op->below) |
|
|
322 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
|
|
323 | break; |
|
|
324 | |
|
|
325 | if (op == NULL) |
|
|
326 | break; |
|
|
327 | |
|
|
328 | sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); |
|
|
329 | } |
|
|
330 | break; |
|
|
331 | |
|
|
332 | case range_magic: |
|
|
333 | if (settings.casting_time == TRUE) |
|
|
334 | { |
|
|
335 | if (pl->casting_time > -1) |
|
|
336 | { |
|
|
337 | if (pl->casting_time == 0) |
|
|
338 | sprintf (obuf, "Range: Holding spell (%s)", &pl->spell->name); |
|
|
339 | else |
|
|
340 | sprintf (obuf, "Range: Casting spell (%s)", &pl->spell->name); |
|
|
341 | } |
|
|
342 | else |
|
|
343 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
|
|
344 | } |
|
|
345 | else |
|
|
346 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
|
|
347 | break; |
|
|
348 | |
|
|
349 | case range_misc: |
|
|
350 | sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none"); |
|
|
351 | break; |
|
|
352 | |
|
|
353 | /* range_scroll is only used for controlling golems. If the |
|
|
354 | * the player does not have a golem, reset some things. |
|
|
355 | */ |
|
|
356 | case range_golem: |
|
|
357 | if (object *golem = pl->contr->ranges[range_golem]) |
|
|
358 | sprintf (obuf, "Range: golem (%s)", &golem->name); |
|
|
359 | else |
|
|
360 | { |
|
|
361 | pl->contr->shoottype = range_none; |
|
|
362 | strcpy (obuf, "Range: nothing"); |
|
|
363 | } |
|
|
364 | break; |
|
|
365 | |
|
|
366 | case range_skill: |
|
|
367 | sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none"); |
|
|
368 | break; |
|
|
369 | |
|
|
370 | case range_builder: |
|
|
371 | sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0)); |
|
|
372 | break; |
|
|
373 | |
|
|
374 | default: |
|
|
375 | strcpy (obuf, "Range: illegal"); |
|
|
376 | } |
|
|
377 | } |
194 | } |
378 | |
195 | |
379 | /** |
196 | /** |
380 | * Sets player title. |
197 | * Sets player title. |
381 | */ |
198 | */ |
… | |
… | |
389 | 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); |
390 | } |
207 | } |
391 | |
208 | |
392 | // 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 |
393 | static inline faceidx |
210 | static inline faceidx |
394 | GET_MAP_FACE (maptile *m, int x, int y, int layer) |
211 | GET_MAP_FACE (mapspace &ms, int layer) |
395 | { |
212 | { |
396 | if (object *op = GET_MAP_FACE_OBJ (m, x, y, layer)) |
213 | if (object *op = ms.faces_obj [layer]) |
397 | return op->face; |
214 | return op->face; |
398 | else |
215 | else |
399 | return 0; |
216 | return 0; |
400 | } |
217 | } |
401 | |
218 | |
… | |
… | |
411 | * for various code values. |
228 | * for various code values. |
412 | */ |
229 | */ |
413 | static void |
230 | static void |
414 | 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) |
415 | { |
232 | { |
416 | int x, y, dx, dy, mflags; |
|
|
417 | sint16 nx, ny; |
|
|
418 | maptile *mp; |
|
|
419 | |
|
|
420 | for (dx = -1; dx <= 1; dx++) |
233 | for (int dx = -1; dx <= 1; dx++) |
421 | { |
234 | { |
422 | for (dy = -1; dy <= 1; dy++) |
235 | for (int dy = -1; dy <= 1; dy++) |
423 | { |
236 | { |
424 | x = px + dx; |
237 | int x = px + dx; |
425 | y = py + dy; |
238 | int y = py + dy; |
426 | |
239 | |
427 | if (FABS (x) >= MAGIC_MAP_HALF || FABS (y) >= MAGIC_MAP_HALF) |
240 | if (abs (x) >= MAGIC_MAP_HALF || abs (y) >= MAGIC_MAP_HALF) |
428 | continue; |
241 | continue; |
429 | |
242 | |
430 | mp = pl->map; |
243 | mapxy pos (pl); |
431 | nx = pl->x + x; |
244 | pos.move (x, y); |
432 | ny = pl->y + y; |
|
|
433 | |
245 | |
434 | mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); |
246 | if (!pos.normalise ()) |
435 | if (mflags & P_OUT_OF_MAP) |
|
|
436 | continue; |
247 | continue; |
|
|
248 | |
|
|
249 | mapspace &ms = pos.ms (); |
437 | |
250 | |
438 | 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) |
439 | { |
252 | { |
|
|
253 | int mflags = ms.flags (); |
|
|
254 | |
440 | int f = GET_MAP_FACE (mp, nx, ny, 0); |
255 | int f = GET_MAP_FACE (ms, 0); |
441 | if (f == blank_face) |
256 | if (f == blank_face) |
442 | { |
257 | { |
443 | f = GET_MAP_FACE (mp, nx, ny, 1); |
258 | f = GET_MAP_FACE (ms, 1); |
444 | if (f == blank_face) |
259 | if (f == blank_face) |
445 | f = GET_MAP_FACE (mp, nx, ny, 2); |
260 | f = GET_MAP_FACE (ms, 2); |
446 | } |
261 | } |
447 | |
262 | |
448 | int magicmap = faces [f].magicmap; |
263 | int magicmap = faces [f].magicmap; |
449 | |
264 | |
450 | /* 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 |
… | |
… | |
463 | } |
278 | } |
464 | |
279 | |
465 | /** |
280 | /** |
466 | * Creates magic map for player. |
281 | * Creates magic map for player. |
467 | * |
282 | * |
468 | * Note: For improved magic mapping display, the space that blocks |
283 | * Note: For improved magic mapping display, the space that blocks |
469 | * 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 |
470 | * being nonzero have been changed to check for 1. Also, since |
285 | * being nonzero have been changed to check for 1. Also, since |
471 | * 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. |
472 | * |
287 | * |
473 | * 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 |
474 | * 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 |
475 | * is for open spaces. map_mark should already have been initialised |
290 | * is for open spaces. map_mark should already have been initialised |
476 | * to zero before this is called. |
291 | * to zero before this is called. |
477 | * strength is an initial strength*2 rectangular area that we automatically |
292 | * strength is an initial strength*2 rectangular area that we automatically |
478 | * see in/penetrate through. |
293 | * see in/penetrate through. |
479 | */ |
294 | */ |
480 | void |
295 | static void |
481 | magic_mapping_mark (object *pl, char *map_mark, int strength) |
296 | magic_mapping_mark (object *pl, char *map_mark, int strength) |
482 | { |
297 | { |
483 | int x, y, mflags; |
|
|
484 | sint16 nx, ny; |
|
|
485 | maptile *mp; |
|
|
486 | |
|
|
487 | for (x = -strength; x < strength; x++) |
298 | for (int x = -strength; x < strength; x++) |
488 | { |
299 | { |
489 | for (y = -strength; y < strength; y++) |
300 | for (int y = -strength; y < strength; y++) |
490 | { |
301 | { |
491 | mp = pl->map; |
302 | mapxy pos (pl); |
492 | nx = pl->x + x; |
303 | pos.move (x, y); |
493 | ny = pl->y + y; |
|
|
494 | |
304 | |
495 | mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); |
305 | if (!pos.normalise ()) |
496 | if (mflags & P_OUT_OF_MAP) |
|
|
497 | continue; |
306 | continue; |
498 | |
307 | |
|
|
308 | mapspace &ms = pos.ms (); |
|
|
309 | |
|
|
310 | int mflags = ms.flags (); |
|
|
311 | |
499 | int f = GET_MAP_FACE (mp, nx, ny, 0); |
312 | int f = GET_MAP_FACE (ms, 0); |
500 | if (f == blank_face) |
313 | if (f == blank_face) |
501 | { |
314 | { |
502 | f = GET_MAP_FACE (mp, nx, ny, 1); |
315 | f = GET_MAP_FACE (ms, 1); |
503 | if (f == blank_face) |
316 | if (f == blank_face) |
504 | f = GET_MAP_FACE (mp, nx, ny, 2); |
317 | f = GET_MAP_FACE (ms, 2); |
505 | } |
318 | } |
506 | |
319 | |
507 | int magicmap = faces [f].magicmap; |
320 | int magicmap = faces [f].magicmap; |
508 | |
321 | |
509 | if (mflags & P_BLOCKSVIEW) |
322 | if (mflags & P_BLOCKSVIEW) |
… | |
… | |
526 | * Mark Wedel |
339 | * Mark Wedel |
527 | */ |
340 | */ |
528 | void |
341 | void |
529 | draw_magic_map (object *pl) |
342 | draw_magic_map (object *pl) |
530 | { |
343 | { |
531 | char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
|
|
532 | int xmin, xmax, ymin, ymax; |
344 | int xmin, xmax, ymin, ymax; |
533 | |
345 | |
534 | if (pl->type != PLAYER) |
346 | if (pl->type != PLAYER) |
535 | { |
347 | { |
536 | LOG (llevError, "Non player object called draw_map.\n"); |
348 | LOG (llevError, "Non player object called draw_map.\n"); |
537 | return; |
349 | return; |
538 | } |
350 | } |
|
|
351 | |
|
|
352 | char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
|
|
353 | assert(("Out of memory!", map_mark != NULL)); |
539 | |
354 | |
540 | /* First, we figure out what spaces are 'reachable' by the player */ |
355 | /* First, we figure out what spaces are 'reachable' by the player */ |
541 | magic_mapping_mark (pl, map_mark, 3); |
356 | magic_mapping_mark (pl, map_mark, 3); |
542 | |
357 | |
543 | /* We now go through and figure out what spaces have been |
358 | /* We now go through and figure out what spaces have been |
… | |
… | |
571 | pl->contr->ns->send_packet (sl); |
386 | pl->contr->ns->send_packet (sl); |
572 | |
387 | |
573 | free (map_mark); |
388 | free (map_mark); |
574 | } |
389 | } |
575 | |
390 | |
576 | /** |
|
|
577 | * Send a kill log record to sockets |
|
|
578 | */ |
|
|
579 | void |
|
|
580 | Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) |
|
|
581 | { |
|
|
582 | size_t len; |
|
|
583 | char buf[MAX_BUF]; |
|
|
584 | |
|
|
585 | if (With != NULL) |
|
|
586 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
|
|
587 | else |
|
|
588 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
|
|
589 | |
|
|
590 | len = strlen (buf); |
|
|
591 | } |
|
|
592 | |
|
|