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