--- deliantra/server/socket/info.C 2007/03/11 02:12:45 1.35 +++ deliantra/server/socket/info.C 2007/05/03 10:39:46 1.41 @@ -88,81 +88,51 @@ esrv_print_msg (pl->contr->ns, colr, (char *) tmp); } -/** - * Prints out the contents of specified buffer structures, - * and clears the string. - */ -void -flush_output_element (const object *pl, Output_Buf * outputs) +bool +client::msg_suppressed (const char *msg) { - char tbuf[MAX_BUF]; + if (!pl) + return false; - if (outputs->buf == NULL) - return; - if (outputs->count > 1) - { - snprintf (tbuf, MAX_BUF, "%d times %s", outputs->count, &outputs->buf); - print_message (NDI_BLACK, pl, tbuf); - } - else - print_message (NDI_BLACK, pl, &outputs->buf); + if (pl->outputs_count <= 1 || !pl->outputs_sync) + return false; - outputs->buf = NULL; - outputs->first_update = 0; /* This way, it will be reused */ -} + int len = strlen (msg); -/** - * Sends message to player through output buffers. - * \param pl player to send message - * \param buf message to send - * - * If player's output_count is 1, sends message directly. - * - * Else checks output buffers for specified message. - * - * If found, checks if message should be sent now. - * - * If message not already in buffers, flushes olders buffer, - * and adds message to queue. - */ -static void -check_output_buffers (const object *pl, const char *buf) -{ - int i, oldest = 0; + if (len > MSG_BUF_SIZE) + return false; - if (pl->contr->outputs_count < 2) + msg_buf *lru = msgbuf; + for (msg_buf *buf = msgbuf; buf < msgbuf + MSG_BUF_COUNT; ++buf) { - print_message (NDI_BLACK, pl, buf); - return; - } - else - { - for (i = 0; i < NUM_OUTPUT_BUFS; i++) + if (len == buf->len && !memcmp (msg, buf->msg, len)) { - if (pl->contr->outputs[i].buf && !strcmp (buf, pl->contr->outputs[i].buf)) - break; - else if (pl->contr->outputs[i].first_update < pl->contr->outputs[oldest].first_update) - oldest = i; - } - /* We found a match */ - if (i < NUM_OUTPUT_BUFS) - { - pl->contr->outputs[i].count++; - if (pl->contr->outputs[i].count >= pl->contr->outputs_count) + // found matching buf, see if expired + if (buf->expire <= pticks || !buf->count) { - flush_output_element (pl, &pl->contr->outputs[i]); + // yes, take over matching buffer, print + buf->expire = pticks + pl->outputs_sync; + buf->count = pl->outputs_count; + + return false; } - } - /* No match - flush the oldest, and put the new one in */ - else - { - flush_output_element (pl, &pl->contr->outputs[oldest]); - pl->contr->outputs[oldest].first_update = pticks; - pl->contr->outputs[oldest].count = 1; - pl->contr->outputs[oldest].buf = buf; + // no, suppress + --buf->count; + return true; } + + if (lru->expire > buf->expire) + lru = buf; } + + // new message, evoke oldest buffer + lru->expire = pticks + pl->outputs_sync; + lru->count = pl->outputs_count; + lru->len = len; + memcpy (lru->msg, msg, len); + + return false; } /** @@ -181,28 +151,24 @@ * If message is black, and not NDI_UNIQUE, gets sent through output buffers. * */ - void -new_draw_info (int flags, int pri, const object *pl, const char *buf) +new_draw_info (int flags, int pri, const object *op, const char *buf) { if (flags & NDI_ALL) + for_all_players (pl) + new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf); + else { - for_all_players (pl) - new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf); + if (!op || !op->contr || !op->contr->ns) + return; - return; - } - - if (!pl || pl->type != PLAYER || !pl->contr || !pl->contr->ns) - return; + if (pri >= op->contr->listening) + return; - if (pri >= pl->contr->listening) - return; - - if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) - check_output_buffers (pl, buf); - else - print_message (flags & NDI_COLOR_MASK, pl, buf); + if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK + || !op->contr->ns->msg_suppressed (buf)) + print_message (flags & NDI_COLOR_MASK, op, buf); + } } /** @@ -335,80 +301,6 @@ } /** - * Get player's current range attack in obuf. - */ -void -rangetostring (object *pl, char *obuf) -{ - switch (pl->contr->shoottype) - { - case range_none: - strcpy (obuf, "Range: nothing"); - break; - - case range_bow: - { - object *op; - - for (op = pl->inv; op; op = op->below) - if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) - break; - - if (op == NULL) - break; - - sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); - } - break; - - case range_magic: - if (settings.casting_time == TRUE) - { - if (pl->casting_time > -1) - { - if (pl->casting_time == 0) - sprintf (obuf, "Range: Holding spell (%s)", &pl->spell->name); - else - sprintf (obuf, "Range: Casting spell (%s)", &pl->spell->name); - } - else - sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); - } - else - sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); - break; - - case range_misc: - sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none"); - break; - - /* range_scroll is only used for controlling golems. If the - * the player does not have a golem, reset some things. - */ - case range_golem: - if (pl->contr->ranges[range_golem] != NULL) - sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name); - else - { - pl->contr->shoottype = range_none; - strcpy (obuf, "Range: nothing"); - } - break; - - case range_skill: - sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none"); - break; - - case range_builder: - sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0)); - break; - - default: - strcpy (obuf, "Range: illegal"); - } -} - -/** * Sets player title. */ void @@ -421,6 +313,16 @@ sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title); } +// formerly a macro, used only by magic map, so optimised it out +static inline faceidx +GET_MAP_FACE (maptile *m, int x, int y, int layer) +{ + if (object *op = GET_MAP_FACE_OBJ (m, x, y, layer)) + return op->face; + else + return 0; +} + /** * Helper for magic map creation. *