| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "global.h" |
| 25 |
|
| 26 |
#include <stdarg.h> |
| 27 |
#include <string.h> |
| 28 |
|
| 29 |
#include "skills.h" |
| 30 |
#include "spells.h" |
| 31 |
#include "sproto.h" |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
void print_ext_msg(socket_struct *ns, int color, uint8_t type, uint8_t subtype, const char *message) { |
| 50 |
SockList sl; |
| 51 |
|
| 52 |
SockList_Init(&sl); |
| 53 |
SockList_AddPrintf(&sl, "drawextinfo %d %hhu %hhu %s", color, type, subtype, message); |
| 54 |
Send_With_Handling(ns, &sl); |
| 55 |
SockList_Term(&sl); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
void draw_ext_info( |
| 87 |
int flags, int pri, const object *pl, uint8_t type, |
| 88 |
uint8_t subtype, const char *message) { |
| 89 |
|
| 90 |
if ((flags&NDI_ALL) || (flags&NDI_ALL_DMS)) { |
| 91 |
player *tmppl; |
| 92 |
|
| 93 |
for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) { |
| 94 |
if ((flags&NDI_ALL_DMS) && !QUERY_FLAG(tmppl->ob, FLAG_WIZ)) |
| 95 |
continue; |
| 96 |
draw_ext_info((flags&~NDI_ALL&~NDI_ALL_DMS), pri, tmppl->ob, type, subtype, message); |
| 97 |
} |
| 98 |
|
| 99 |
LOG(llevInfo, "-- %s\n", message); |
| 100 |
return; |
| 101 |
} |
| 102 |
|
| 103 |
if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
| 104 |
return; |
| 105 |
if (pl->type != PLAYER) |
| 106 |
return; |
| 107 |
if (pri >= pl->contr->listening) |
| 108 |
return; |
| 109 |
|
| 110 |
print_ext_msg(&pl->contr->socket, flags&NDI_COLOR_MASK, type, subtype, message); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format, ...) { |
| 138 |
char buf[HUGE_BUF]; |
| 139 |
va_list ap; |
| 140 |
|
| 141 |
va_start(ap, format); |
| 142 |
vsnprintf(buf, HUGE_BUF, format, ap); |
| 143 |
va_end(ap); |
| 144 |
|
| 145 |
draw_ext_info(flags, pri, pl, type, subtype, buf); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
void ext_info_map(int color, const mapstruct *map, uint8_t type, uint8_t subtype, const char *str1) { |
| 162 |
player *pl; |
| 163 |
|
| 164 |
for (pl = first_player; pl != NULL; pl = pl->next) |
| 165 |
if (pl->ob != NULL && pl->ob->map == map) { |
| 166 |
draw_ext_info(color, 0, pl->ob, type, subtype, str1); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
void ext_info_map_except(int color, const mapstruct *map, const object *op, uint8_t type, uint8_t subtype, const char *str1) { |
| 186 |
player *pl; |
| 187 |
|
| 188 |
for (pl = first_player; pl != NULL; pl = pl->next) |
| 189 |
if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) { |
| 190 |
draw_ext_info(color, 0, pl->ob, type, subtype, str1); |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
void ext_info_map_except2(int color, const mapstruct *map, const object *op1, const object *op2, int type, int subtype, const char *str1) { |
| 212 |
player *pl; |
| 213 |
|
| 214 |
for (pl = first_player; pl != NULL; pl = pl->next) |
| 215 |
if (pl->ob != NULL && pl->ob->map == map |
| 216 |
&& pl->ob != op1 && pl->ob != op2) { |
| 217 |
draw_ext_info(color, 0, pl->ob, type, subtype, str1); |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
void rangetostring(const object *pl, char *obuf, size_t len) { |
| 231 |
char name[MAX_BUF]; |
| 232 |
|
| 233 |
switch (pl->contr->shoottype) { |
| 234 |
case range_none: |
| 235 |
strncpy(obuf, "Range: nothing", len); |
| 236 |
break; |
| 237 |
|
| 238 |
case range_bow: { |
| 239 |
object *op; |
| 240 |
|
| 241 |
for (op = pl->inv; op; op = op->below) |
| 242 |
if (op->type == BOW && QUERY_FLAG(op, FLAG_APPLIED)) |
| 243 |
break; |
| 244 |
if (op == NULL) |
| 245 |
break; |
| 246 |
|
| 247 |
query_base_name(op, 0, name, MAX_BUF); |
| 248 |
snprintf(obuf, len, "Range: %s (%s)", name, op->race ? op->race : "nothing"); |
| 249 |
} |
| 250 |
break; |
| 251 |
|
| 252 |
case range_magic: |
| 253 |
if (settings.casting_time == TRUE && pl->casting_time > -1) { |
| 254 |
if (pl->casting_time == 0) |
| 255 |
snprintf(obuf, len, "Range: Holding spell (%s)", pl->spell->name); |
| 256 |
else |
| 257 |
snprintf(obuf, len, "Range: Casting spell (%s)", pl->spell->name); |
| 258 |
} |
| 259 |
else |
| 260 |
snprintf(obuf, len, "Range: spell (%s)", pl->contr->ranges[range_magic]->name); |
| 261 |
break; |
| 262 |
|
| 263 |
case range_misc: |
| 264 |
if (pl->contr->ranges[range_misc]) |
| 265 |
query_base_name(pl->contr->ranges[range_misc], 0, name, MAX_BUF); |
| 266 |
else |
| 267 |
strncpy(name, "none", MAX_BUF); |
| 268 |
snprintf(obuf, len, "Range: %s", name); |
| 269 |
break; |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
case range_golem: |
| 275 |
if (pl->contr->ranges[range_golem] != NULL) |
| 276 |
snprintf(obuf, len, "Range: golem (%s)", pl->contr->ranges[range_golem]->name); |
| 277 |
else { |
| 278 |
pl->contr->shoottype = range_none; |
| 279 |
strncpy(obuf, "Range: nothing", len); |
| 280 |
} |
| 281 |
break; |
| 282 |
|
| 283 |
case range_skill: |
| 284 |
snprintf(obuf, len, "Skill: %s", pl->chosen_skill != NULL ? pl->chosen_skill->name : "none"); |
| 285 |
break; |
| 286 |
|
| 287 |
case range_builder: |
| 288 |
query_base_name(pl->contr->ranges[range_builder], 0, name, MAX_BUF); |
| 289 |
snprintf(obuf, len, "Builder: %s", name); |
| 290 |
break; |
| 291 |
|
| 292 |
default: |
| 293 |
strncpy(obuf, "Range: illegal", len); |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
void set_title(const object *pl, char *buf, size_t len) { |
| 301 |
char *p; |
| 302 |
|
| 303 |
snprintf(buf, len, "Player: %s ", pl->name); |
| 304 |
p = strchr(buf, '\0'); |
| 305 |
player_get_title(pl->contr, p, (buf+len)-p); |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
static void magic_mapping_mark_recursive(object *pl, char *map_mark, int px, int py) { |
| 326 |
int x, y, dx, dy, mflags, l; |
| 327 |
int16_t nx, ny; |
| 328 |
mapstruct *mp; |
| 329 |
const Face *f; |
| 330 |
object *ob; |
| 331 |
|
| 332 |
for (dx = -1; dx <= 1; dx++) { |
| 333 |
for (dy = -1; dy <= 1; dy++) { |
| 334 |
x = px+dx; |
| 335 |
y = py+dy; |
| 336 |
|
| 337 |
if (FABS(x) >= MAGIC_MAP_HALF || FABS(y) >= MAGIC_MAP_HALF) |
| 338 |
continue; |
| 339 |
|
| 340 |
mp = pl->map; |
| 341 |
nx = pl->x+x; |
| 342 |
ny = pl->y+y; |
| 343 |
|
| 344 |
mflags = get_map_flags(pl->map, &mp, nx, ny, &nx, &ny); |
| 345 |
if (mflags&P_OUT_OF_MAP) |
| 346 |
continue; |
| 347 |
|
| 348 |
if (map_mark[MAGIC_MAP_HALF+x+MAGIC_MAP_SIZE*(MAGIC_MAP_HALF+y)] == 0) { |
| 349 |
for (l = 0; l < MAP_LAYERS; l++) { |
| 350 |
ob = GET_MAP_FACE_OBJ(mp, nx, ny, l); |
| 351 |
if (ob && !ob->invisible && ob->face != blank_face) |
| 352 |
break; |
| 353 |
} |
| 354 |
if (ob) |
| 355 |
f = ob->face; |
| 356 |
else |
| 357 |
f = blank_face; |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
if (mflags&P_BLOCKSVIEW) |
| 363 |
map_mark[MAGIC_MAP_HALF+x+MAGIC_MAP_SIZE*(MAGIC_MAP_HALF+y)] = FACE_WALL|(f ? f->magicmap : 0); |
| 364 |
else { |
| 365 |
map_mark[MAGIC_MAP_HALF+x+MAGIC_MAP_SIZE*(MAGIC_MAP_HALF+y)] = FACE_FLOOR|(f ? f->magicmap : 0); |
| 366 |
magic_mapping_mark_recursive(pl, map_mark, x, y); |
| 367 |
} |
| 368 |
} |
| 369 |
} |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
void magic_mapping_mark(object *pl, char *map_mark, int strength) { |
| 394 |
int x, y, mflags, l; |
| 395 |
int16_t nx, ny; |
| 396 |
mapstruct *mp; |
| 397 |
const Face *f; |
| 398 |
object *ob; |
| 399 |
|
| 400 |
for (x = -strength; x < strength; x++) { |
| 401 |
for (y = -strength; y < strength; y++) { |
| 402 |
mp = pl->map; |
| 403 |
nx = pl->x+x; |
| 404 |
ny = pl->y+y; |
| 405 |
mflags = get_map_flags(pl->map, &mp, nx, ny, &nx, &ny); |
| 406 |
if (mflags&P_OUT_OF_MAP) |
| 407 |
continue; |
| 408 |
else { |
| 409 |
for (l = 0; l < MAP_LAYERS; l++) { |
| 410 |
ob = GET_MAP_FACE_OBJ(mp, nx, ny, l); |
| 411 |
if (ob && !ob->invisible && ob->face != blank_face) |
| 412 |
break; |
| 413 |
} |
| 414 |
if (ob) |
| 415 |
f = ob->face; |
| 416 |
else |
| 417 |
f = blank_face; |
| 418 |
} |
| 419 |
|
| 420 |
if (mflags&P_BLOCKSVIEW) |
| 421 |
map_mark[MAGIC_MAP_HALF+x+MAGIC_MAP_SIZE*(MAGIC_MAP_HALF+y)] = FACE_WALL|(f ? f->magicmap : 0); |
| 422 |
else { |
| 423 |
map_mark[MAGIC_MAP_HALF+x+MAGIC_MAP_SIZE*(MAGIC_MAP_HALF+y)] = FACE_FLOOR|(f ? f->magicmap : 0); |
| 424 |
magic_mapping_mark_recursive(pl, map_mark, x, y); |
| 425 |
} |
| 426 |
} |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
void draw_magic_map(object *pl) { |
| 441 |
int x, y; |
| 442 |
char map_mark[MAGIC_MAP_SIZE*MAGIC_MAP_SIZE]; |
| 443 |
int xmin, xmax, ymin, ymax; |
| 444 |
SockList sl; |
| 445 |
|
| 446 |
if (pl->type != PLAYER) { |
| 447 |
LOG(llevError, "Non player object called draw_map.\n"); |
| 448 |
return; |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
memset(map_mark, 0, MAGIC_MAP_SIZE*MAGIC_MAP_SIZE); |
| 453 |
magic_mapping_mark(pl, map_mark, 3); |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
xmin = MAGIC_MAP_SIZE; |
| 461 |
ymin = MAGIC_MAP_SIZE; |
| 462 |
xmax = 0; |
| 463 |
ymax = 0; |
| 464 |
for (x = 0; x < MAGIC_MAP_SIZE; x++) { |
| 465 |
for (y = 0; y < MAGIC_MAP_SIZE; y++) { |
| 466 |
if (map_mark[x+MAGIC_MAP_SIZE*y]&~FACE_FLOOR) { |
| 467 |
xmin = MIN(x, xmin); |
| 468 |
xmax = MAX(x, xmax); |
| 469 |
ymin = MIN(y, ymin); |
| 470 |
ymax = MAX(y, ymax); |
| 471 |
} |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
SockList_Init(&sl); |
| 476 |
SockList_AddPrintf(&sl, "magicmap %d %d %d %d ", xmin <= xmax ? xmax-xmin+1 : 0, ymin <= ymax ? ymax-ymin+1 : 0, MAGIC_MAP_HALF-xmin, MAGIC_MAP_HALF-ymin); |
| 477 |
|
| 478 |
for (y = ymin; y <= ymax; y++) { |
| 479 |
for (x = xmin; x <= xmax; x++) { |
| 480 |
SockList_AddChar(&sl, map_mark[x+MAGIC_MAP_SIZE*y]&~FACE_FLOOR); |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
Send_With_Handling(&pl->contr->socket, &sl); |
| 485 |
SockList_Term(&sl); |
| 486 |
} |