1 |
elmex |
1.1 |
/* |
2 |
root |
1.47 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
pippijn |
1.33 |
* |
4 |
root |
1.60 |
* Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
root |
1.59 |
* Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 |
|
|
* Copyright (©) 1992 Frank Tore Johansen |
7 |
pippijn |
1.33 |
* |
8 |
root |
1.52 |
* 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 |
10 |
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
11 |
|
|
* option) any later version. |
12 |
pippijn |
1.33 |
* |
13 |
root |
1.46 |
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
pippijn |
1.33 |
* |
18 |
root |
1.52 |
* 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 |
20 |
|
|
* <http://www.gnu.org/licenses/>. |
21 |
root |
1.43 |
* |
22 |
root |
1.47 |
* The authors can be reached via e-mail to <support@deliantra.net> |
23 |
pippijn |
1.33 |
*/ |
24 |
elmex |
1.1 |
|
25 |
|
|
/** |
26 |
|
|
* \file |
27 |
|
|
* Basic client output functions. |
28 |
|
|
* |
29 |
|
|
* \date 2003-12-02 |
30 |
|
|
* |
31 |
|
|
* This file implements some of the simpler output functions to the |
32 |
|
|
* client. Basically, things like sending text strings along |
33 |
|
|
*/ |
34 |
|
|
|
35 |
|
|
#include <global.h> |
36 |
|
|
#include <sproto.h> |
37 |
|
|
#include <stdarg.h> |
38 |
|
|
#include <spells.h> |
39 |
|
|
#include <skills.h> |
40 |
|
|
|
41 |
root |
1.45 |
#include <cstring> |
42 |
|
|
|
43 |
elmex |
1.1 |
/** |
44 |
|
|
* Draws a normal message on the client. It is pretty |
45 |
|
|
* much the same thing as the draw_info above, but takes a color |
46 |
|
|
* parameter. the esrv_drawinfo functions should probably be |
47 |
|
|
* replaced with this, just using black as the color. |
48 |
|
|
*/ |
49 |
root |
1.5 |
static void |
50 |
root |
1.22 |
esrv_print_msg (client *ns, int color, const char *str) |
51 |
elmex |
1.1 |
{ |
52 |
root |
1.45 |
ns->send_msg (color, "info", str); |
53 |
elmex |
1.1 |
} |
54 |
|
|
|
55 |
|
|
/** |
56 |
|
|
* Frontend for esrv_print_msg |
57 |
|
|
* \param colr message color |
58 |
|
|
* \param pl player to send to. Can be NULL |
59 |
|
|
* \param tmp message to send. Can be NULL |
60 |
|
|
* |
61 |
|
|
* If pl is NULL or without contr set, writes message to log. |
62 |
|
|
* |
63 |
|
|
* Else sends message to player via esrv_print_msg |
64 |
|
|
*/ |
65 |
root |
1.5 |
static void |
66 |
|
|
print_message (int colr, const object *pl, const char *tmp) |
67 |
|
|
{ |
68 |
root |
1.11 |
if (!tmp) |
69 |
|
|
tmp = "[NULL]"; |
70 |
elmex |
1.1 |
|
71 |
|
|
if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
72 |
|
|
return; |
73 |
|
|
|
74 |
root |
1.5 |
if (pl->type == PLAYER) |
75 |
root |
1.45 |
esrv_print_msg (pl->contr->ns, colr, (char *)tmp); |
76 |
elmex |
1.1 |
} |
77 |
|
|
|
78 |
root |
1.38 |
bool |
79 |
|
|
client::msg_suppressed (const char *msg) |
80 |
elmex |
1.1 |
{ |
81 |
root |
1.38 |
if (!pl) |
82 |
|
|
return false; |
83 |
elmex |
1.1 |
|
84 |
root |
1.38 |
if (pl->outputs_count <= 1 || !pl->outputs_sync) |
85 |
|
|
return false; |
86 |
elmex |
1.1 |
|
87 |
root |
1.38 |
int len = strlen (msg); |
88 |
elmex |
1.1 |
|
89 |
root |
1.38 |
if (len > MSG_BUF_SIZE) |
90 |
|
|
return false; |
91 |
elmex |
1.1 |
|
92 |
root |
1.38 |
msg_buf *lru = msgbuf; |
93 |
|
|
for (msg_buf *buf = msgbuf; buf < msgbuf + MSG_BUF_COUNT; ++buf) |
94 |
root |
1.5 |
{ |
95 |
root |
1.38 |
if (len == buf->len && !memcmp (msg, buf->msg, len)) |
96 |
root |
1.5 |
{ |
97 |
root |
1.38 |
// found matching buf, see if expired |
98 |
|
|
if (buf->expire <= pticks || !buf->count) |
99 |
root |
1.5 |
{ |
100 |
root |
1.38 |
// yes, take over matching buffer, print |
101 |
|
|
buf->expire = pticks + pl->outputs_sync; |
102 |
|
|
buf->count = pl->outputs_count; |
103 |
|
|
|
104 |
|
|
return false; |
105 |
root |
1.2 |
} |
106 |
root |
1.38 |
|
107 |
|
|
// no, suppress |
108 |
|
|
--buf->count; |
109 |
|
|
return true; |
110 |
root |
1.2 |
} |
111 |
root |
1.5 |
|
112 |
root |
1.38 |
if (lru->expire > buf->expire) |
113 |
|
|
lru = buf; |
114 |
elmex |
1.1 |
} |
115 |
root |
1.38 |
|
116 |
|
|
// new message, evoke oldest buffer |
117 |
|
|
lru->expire = pticks + pl->outputs_sync; |
118 |
|
|
lru->count = pl->outputs_count; |
119 |
|
|
lru->len = len; |
120 |
|
|
memcpy (lru->msg, msg, len); |
121 |
|
|
|
122 |
|
|
return false; |
123 |
elmex |
1.1 |
} |
124 |
root |
1.5 |
|
125 |
elmex |
1.1 |
/** |
126 |
|
|
* Sends message to player(s). |
127 |
|
|
* |
128 |
|
|
* flags is various flags - mostly color, plus a few specials. |
129 |
|
|
* |
130 |
root |
1.51 |
* pri is unused. |
131 |
elmex |
1.1 |
* |
132 |
|
|
* pl can be passed as NULL - in fact, this will be done if NDI_ALL is set |
133 |
|
|
* in the flags. |
134 |
|
|
* |
135 |
|
|
* If message is black, and not NDI_UNIQUE, gets sent through output buffers. |
136 |
|
|
* |
137 |
|
|
*/ |
138 |
root |
1.5 |
void |
139 |
root |
1.41 |
new_draw_info (int flags, int pri, const object *op, const char *buf) |
140 |
elmex |
1.1 |
{ |
141 |
root |
1.5 |
if (flags & NDI_ALL) |
142 |
root |
1.42 |
{ |
143 |
|
|
for_all_players (pl) |
144 |
root |
1.51 |
new_draw_info (flags & ~NDI_ALL, 0, pl->ob, buf); |
145 |
root |
1.42 |
} |
146 |
root |
1.41 |
else |
147 |
root |
1.5 |
{ |
148 |
root |
1.41 |
if (!op || !op->contr || !op->contr->ns) |
149 |
|
|
return; |
150 |
|
|
|
151 |
|
|
if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK |
152 |
|
|
|| !op->contr->ns->msg_suppressed (buf)) |
153 |
|
|
print_message (flags & NDI_COLOR_MASK, op, buf); |
154 |
elmex |
1.1 |
} |
155 |
|
|
} |
156 |
|
|
|
157 |
|
|
/** |
158 |
|
|
* Wrapper for new_draw_info printf-like. |
159 |
|
|
* |
160 |
|
|
* This is a pretty trivial function, but it allows us to use printf style |
161 |
|
|
* formatting, so instead of the calling function having to do it, we do |
162 |
|
|
* it here. It may also have advantages in the future for reduction of |
163 |
|
|
* client/server bandwidth (client could keep track of various strings |
164 |
|
|
*/ |
165 |
root |
1.5 |
void |
166 |
|
|
new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...) |
167 |
elmex |
1.1 |
{ |
168 |
root |
1.5 |
va_list ap; |
169 |
|
|
va_start (ap, format); |
170 |
root |
1.53 |
new_draw_info (flags, pri, pl, vformat (format, ap)); |
171 |
root |
1.5 |
va_end (ap); |
172 |
elmex |
1.1 |
} |
173 |
|
|
|
174 |
|
|
/** |
175 |
|
|
* Writes to everyone on the map *except* op. This is useful for emotions. |
176 |
|
|
*/ |
177 |
root |
1.5 |
void |
178 |
root |
1.8 |
new_info_map_except (int color, maptile * map, object *op, const char *str) |
179 |
root |
1.5 |
{ |
180 |
root |
1.24 |
for_all_players (pl) |
181 |
root |
1.49 |
if (pl->ob->map == map && pl->ob != op) |
182 |
root |
1.31 |
new_draw_info (color, 0, pl->ob, str); |
183 |
elmex |
1.1 |
} |
184 |
|
|
|
185 |
|
|
/** |
186 |
|
|
* Writes to everyone on the specified map |
187 |
|
|
*/ |
188 |
root |
1.5 |
void |
189 |
root |
1.8 |
new_info_map (int color, maptile * map, const char *str) |
190 |
root |
1.5 |
{ |
191 |
root |
1.24 |
for_all_players (pl) |
192 |
root |
1.49 |
if (pl->ob->map == map) |
193 |
root |
1.31 |
new_draw_info (color, 0, pl->ob, str); |
194 |
elmex |
1.1 |
} |
195 |
|
|
|
196 |
|
|
/** |
197 |
|
|
* Sets player title. |
198 |
|
|
*/ |
199 |
root |
1.5 |
void |
200 |
|
|
set_title (object *pl, char *buf) |
201 |
elmex |
1.1 |
{ |
202 |
root |
1.5 |
/* Eneq(@csd.uu.se): Let players define their own titles. */ |
203 |
|
|
if (pl->contr->own_title[0] == '\0') |
204 |
|
|
sprintf (buf, "Player: %s the %s", (const char *) pl->name, (const char *) pl->contr->title); |
205 |
|
|
else |
206 |
|
|
sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title); |
207 |
elmex |
1.1 |
} |
208 |
|
|
|
209 |
root |
1.36 |
// formerly a macro, used only by magic map, so optimised it out |
210 |
|
|
static inline faceidx |
211 |
root |
1.54 |
GET_MAP_FACE (mapspace &ms, int layer) |
212 |
root |
1.36 |
{ |
213 |
root |
1.54 |
if (object *op = ms.faces_obj [layer]) |
214 |
root |
1.36 |
return op->face; |
215 |
|
|
else |
216 |
|
|
return 0; |
217 |
|
|
} |
218 |
|
|
|
219 |
elmex |
1.1 |
/** |
220 |
|
|
* Helper for magic map creation. |
221 |
|
|
* |
222 |
|
|
* Takes a player, the map_mark array and an x and y starting position. |
223 |
|
|
* pl is the player. |
224 |
|
|
* px, py are offsets from the player. |
225 |
|
|
* |
226 |
|
|
* This function examines all the adjacant spaces next to px, py. |
227 |
|
|
* It updates the map_mark arrow with the color and high bits set |
228 |
|
|
* for various code values. |
229 |
|
|
*/ |
230 |
root |
1.5 |
static void |
231 |
|
|
magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) |
232 |
elmex |
1.1 |
{ |
233 |
root |
1.54 |
for (int dx = -1; dx <= 1; dx++) |
234 |
root |
1.5 |
{ |
235 |
root |
1.54 |
for (int dy = -1; dy <= 1; dy++) |
236 |
root |
1.5 |
{ |
237 |
root |
1.54 |
int x = px + dx; |
238 |
|
|
int y = py + dy; |
239 |
root |
1.5 |
|
240 |
root |
1.54 |
if (abs (x) >= MAGIC_MAP_HALF || abs (y) >= MAGIC_MAP_HALF) |
241 |
root |
1.5 |
continue; |
242 |
|
|
|
243 |
root |
1.54 |
mapxy pos (pl); |
244 |
|
|
pos.move (x, y); |
245 |
root |
1.5 |
|
246 |
root |
1.54 |
if (!pos.normalise ()) |
247 |
root |
1.5 |
continue; |
248 |
|
|
|
249 |
root |
1.54 |
mapspace &ms = pos.ms (); |
250 |
|
|
|
251 |
root |
1.5 |
if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0) |
252 |
|
|
{ |
253 |
root |
1.54 |
int mflags = ms.flags (); |
254 |
|
|
|
255 |
|
|
int f = GET_MAP_FACE (ms, 0); |
256 |
root |
1.5 |
if (f == blank_face) |
257 |
root |
1.35 |
{ |
258 |
root |
1.54 |
f = GET_MAP_FACE (ms, 1); |
259 |
root |
1.35 |
if (f == blank_face) |
260 |
root |
1.54 |
f = GET_MAP_FACE (ms, 2); |
261 |
root |
1.35 |
} |
262 |
|
|
|
263 |
|
|
int magicmap = faces [f].magicmap; |
264 |
root |
1.5 |
|
265 |
|
|
/* Should probably have P_NO_MAGIC here also, but then shops don't |
266 |
|
|
* work. |
267 |
|
|
*/ |
268 |
|
|
if (mflags & P_BLOCKSVIEW) |
269 |
root |
1.35 |
map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_WALL | magicmap; |
270 |
root |
1.5 |
else |
271 |
|
|
{ |
272 |
root |
1.35 |
map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | magicmap; |
273 |
root |
1.5 |
magic_mapping_mark_recursive (pl, map_mark, x, y); |
274 |
root |
1.2 |
} |
275 |
|
|
} |
276 |
|
|
} |
277 |
elmex |
1.1 |
} |
278 |
|
|
} |
279 |
|
|
|
280 |
|
|
/** |
281 |
|
|
* Creates magic map for player. |
282 |
|
|
* |
283 |
root |
1.54 |
* Note: For improved magic mapping display, the space that blocks |
284 |
|
|
* the view is now marked with value 2. Any dependencies of map_mark |
285 |
|
|
* being nonzero have been changed to check for 1. Also, since |
286 |
elmex |
1.1 |
* map_mark is a char value, putting 2 in should cause no problems. |
287 |
|
|
* |
288 |
|
|
* This function examines the map the player is on, and determines what |
289 |
root |
1.54 |
* is visible. 2 is set for walls or objects that blocks view. 1 |
290 |
|
|
* is for open spaces. map_mark should already have been initialised |
291 |
elmex |
1.1 |
* to zero before this is called. |
292 |
|
|
* strength is an initial strength*2 rectangular area that we automatically |
293 |
|
|
* see in/penetrate through. |
294 |
|
|
*/ |
295 |
root |
1.56 |
static void |
296 |
root |
1.5 |
magic_mapping_mark (object *pl, char *map_mark, int strength) |
297 |
elmex |
1.1 |
{ |
298 |
root |
1.54 |
for (int x = -strength; x < strength; x++) |
299 |
root |
1.5 |
{ |
300 |
root |
1.54 |
for (int y = -strength; y < strength; y++) |
301 |
root |
1.5 |
{ |
302 |
root |
1.54 |
mapxy pos (pl); |
303 |
|
|
pos.move (x, y); |
304 |
root |
1.35 |
|
305 |
root |
1.54 |
if (!pos.normalise ()) |
306 |
root |
1.5 |
continue; |
307 |
root |
1.35 |
|
308 |
root |
1.54 |
mapspace &ms = pos.ms (); |
309 |
|
|
|
310 |
|
|
int mflags = ms.flags (); |
311 |
|
|
|
312 |
|
|
int f = GET_MAP_FACE (ms, 0); |
313 |
root |
1.35 |
if (f == blank_face) |
314 |
root |
1.5 |
{ |
315 |
root |
1.54 |
f = GET_MAP_FACE (ms, 1); |
316 |
root |
1.5 |
if (f == blank_face) |
317 |
root |
1.54 |
f = GET_MAP_FACE (ms, 2); |
318 |
root |
1.2 |
} |
319 |
|
|
|
320 |
root |
1.35 |
int magicmap = faces [f].magicmap; |
321 |
|
|
|
322 |
root |
1.5 |
if (mflags & P_BLOCKSVIEW) |
323 |
root |
1.35 |
map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_WALL | magicmap; |
324 |
root |
1.5 |
else |
325 |
|
|
{ |
326 |
root |
1.35 |
map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | magicmap; |
327 |
root |
1.5 |
magic_mapping_mark_recursive (pl, map_mark, x, y); |
328 |
root |
1.2 |
} |
329 |
|
|
} |
330 |
elmex |
1.1 |
} |
331 |
|
|
} |
332 |
|
|
|
333 |
|
|
/** |
334 |
|
|
* Creates and sends magic map to player. |
335 |
|
|
* |
336 |
|
|
* The following function is a lot messier than it really should be, |
337 |
|
|
* but there is no real easy solution. |
338 |
|
|
* |
339 |
|
|
* Mark Wedel |
340 |
|
|
*/ |
341 |
root |
1.5 |
void |
342 |
|
|
draw_magic_map (object *pl) |
343 |
elmex |
1.1 |
{ |
344 |
root |
1.13 |
char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
345 |
root |
1.5 |
int xmin, xmax, ymin, ymax; |
346 |
|
|
|
347 |
|
|
if (pl->type != PLAYER) |
348 |
|
|
{ |
349 |
|
|
LOG (llevError, "Non player object called draw_map.\n"); |
350 |
|
|
return; |
351 |
|
|
} |
352 |
|
|
|
353 |
|
|
/* First, we figure out what spaces are 'reachable' by the player */ |
354 |
|
|
magic_mapping_mark (pl, map_mark, 3); |
355 |
|
|
|
356 |
|
|
/* We now go through and figure out what spaces have been |
357 |
|
|
* marked, and thus figure out rectangular region we send |
358 |
|
|
* to the client (eg, if only a 10x10 area is visible, we only |
359 |
|
|
* want to send those 100 spaces.) |
360 |
|
|
*/ |
361 |
|
|
xmin = MAGIC_MAP_SIZE; |
362 |
|
|
ymin = MAGIC_MAP_SIZE; |
363 |
|
|
xmax = 0; |
364 |
|
|
ymax = 0; |
365 |
root |
1.13 |
|
366 |
|
|
for (int x = 0; x < MAGIC_MAP_SIZE; x++) |
367 |
|
|
for (int y = 0; y < MAGIC_MAP_SIZE; y++) |
368 |
root |
1.25 |
if (map_mark[x + pl->map->width * y] | FACE_FLOOR) |
369 |
root |
1.5 |
{ |
370 |
root |
1.13 |
xmin = x < xmin ? x : xmin; |
371 |
|
|
xmax = x > xmax ? x : xmax; |
372 |
|
|
ymin = y < ymin ? y : ymin; |
373 |
|
|
ymax = y > ymax ? y : ymax; |
374 |
root |
1.2 |
} |
375 |
elmex |
1.1 |
|
376 |
root |
1.15 |
packet sl; |
377 |
root |
1.13 |
sl.printf ("magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), |
378 |
|
|
MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
379 |
|
|
|
380 |
|
|
for (int y = ymin; y <= ymax; y++) |
381 |
|
|
for (int x = xmin; x <= xmax; x++) |
382 |
|
|
sl << uint8 (map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR); |
383 |
|
|
|
384 |
root |
1.23 |
pl->contr->ns->send_packet (sl); |
385 |
root |
1.5 |
|
386 |
|
|
free (map_mark); |
387 |
elmex |
1.1 |
} |
388 |
|
|
|