--- deliantra/server/socket/info.C 2007/11/08 19:43:29 1.47
+++ deliantra/server/socket/info.C 2009/11/06 13:07:28 1.56
@@ -1,22 +1,23 @@
/*
* This file is part of Deliantra, the Roguelike Realtime MMORPG.
*
- * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
+ * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
* Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
* Copyright (©) 1992,2007 Frank Tore Johansen
*
- * Deliantra is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * Deliantra is free software: you can redistribute it and/or modify it under
+ * the terms of the Affero GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
+ * You should have received a copy of the Affero GNU General Public License
+ * and the GNU General Public License along with this program. If not, see
+ * .
*
* The authors can be reached via e-mail to
*/
@@ -141,10 +142,7 @@
*
* flags is various flags - mostly color, plus a few specials.
*
- * pri is priority. It is a little odd - the lower the value, the more
- * important it is. Thus, 0 gets sent no matter what. Otherwise, the
- * value must be less than the listening level that the player has set.
- * Unfortunately, there is no clear guideline on what each level does what.
+ * pri is unused.
*
* pl can be passed as NULL - in fact, this will be done if NDI_ALL is set
* in the flags.
@@ -158,16 +156,13 @@
if (flags & NDI_ALL)
{
for_all_players (pl)
- new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf);
+ new_draw_info (flags & ~NDI_ALL, 0, pl->ob, buf);
}
else
{
if (!op || !op->contr || !op->contr->ns)
return;
- if (pri >= op->contr->listening)
- return;
-
if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK
|| !op->contr->ns->msg_suppressed (buf))
print_message (flags & NDI_COLOR_MASK, op, buf);
@@ -185,26 +180,18 @@
void
new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...)
{
- char buf[HUGE_BUF];
-
va_list ap;
va_start (ap, format);
- vsnprintf (buf, HUGE_BUF, format, ap);
+ new_draw_info (flags, pri, pl, vformat (format, ap));
va_end (ap);
-
- new_draw_info (flags, pri, pl, buf);
}
void
draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
{
-
if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
return;
- if (pri >= pl->contr->listening)
- return;
-
if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
{
char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1);
@@ -226,57 +213,47 @@
void
draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...)
{
- char buf[HUGE_BUF];
-
- if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
- return;
+ va_list ap;
+ va_start (ap, new_format);
- if (pri >= pl->contr->listening)
+ if (!pl || !pl->is_player ())
return;
+ // TODO: just assume, and rip out?
if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
{
- va_list ap;
-
LOG (llevDebug, "Non supported extension text type for client.\n");
- va_start (ap, new_format);
- vsnprintf (buf, HUGE_BUF, old_format, ap);
- va_end (ap);
- new_draw_info (flags, pri, pl, buf);
- return;
+ new_draw_info (flags, pri, pl, vformat (old_format, ap));
}
else
{
- va_list ap;
-
- va_start (ap, new_format);
- vsnprintf (buf, HUGE_BUF, new_format, ap);
- va_end (ap);
+ char *buf = vformat (new_format, ap);
strip_media_tag (buf);
esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf);
}
+
+ va_end (ap);
}
/**
* Writes to everyone on the map *except* op. This is useful for emotions.
*/
-
void
new_info_map_except (int color, maptile * map, object *op, const char *str)
{
for_all_players (pl)
- if (pl->ob != NULL && pl->ob->map == map && pl->ob != op)
+ if (pl->ob->map == map && pl->ob != op)
new_draw_info (color, 0, pl->ob, str);
}
/**
* Writes to everyone on the map except op1 and op2
*/
-void
+static void
new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str)
{
for_all_players (pl)
- if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2)
+ if (pl->ob->map == map && pl->ob != op1 && pl->ob != op2)
new_draw_info (color, 0, pl->ob, str);
}
@@ -287,7 +264,7 @@
new_info_map (int color, maptile * map, const char *str)
{
for_all_players (pl)
- if (pl->ob != NULL && pl->ob->map == map)
+ if (pl->ob->map == map)
new_draw_info (color, 0, pl->ob, str);
}
@@ -306,9 +283,9 @@
// 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)
+GET_MAP_FACE (mapspace &ms, int layer)
{
- if (object *op = GET_MAP_FACE_OBJ (m, x, y, layer))
+ if (object *op = ms.faces_obj [layer])
return op->face;
else
return 0;
@@ -328,36 +305,34 @@
static void
magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py)
{
- int x, y, dx, dy, mflags;
- sint16 nx, ny;
- maptile *mp;
-
- for (dx = -1; dx <= 1; dx++)
+ for (int dx = -1; dx <= 1; dx++)
{
- for (dy = -1; dy <= 1; dy++)
+ for (int dy = -1; dy <= 1; dy++)
{
- x = px + dx;
- y = py + dy;
+ int x = px + dx;
+ int y = py + dy;
- if (FABS (x) >= MAGIC_MAP_HALF || FABS (y) >= MAGIC_MAP_HALF)
+ if (abs (x) >= MAGIC_MAP_HALF || abs (y) >= MAGIC_MAP_HALF)
continue;
- mp = pl->map;
- nx = pl->x + x;
- ny = pl->y + y;
+ mapxy pos (pl);
+ pos.move (x, y);
- mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny);
- if (mflags & P_OUT_OF_MAP)
+ if (!pos.normalise ())
continue;
+ mapspace &ms = pos.ms ();
+
if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0)
{
- int f = GET_MAP_FACE (mp, nx, ny, 0);
+ int mflags = ms.flags ();
+
+ int f = GET_MAP_FACE (ms, 0);
if (f == blank_face)
{
- f = GET_MAP_FACE (mp, nx, ny, 1);
+ f = GET_MAP_FACE (ms, 1);
if (f == blank_face)
- f = GET_MAP_FACE (mp, nx, ny, 2);
+ f = GET_MAP_FACE (ms, 2);
}
int magicmap = faces [f].magicmap;
@@ -380,43 +355,41 @@
/**
* Creates magic map for player.
*
- * Note: For improved magic mapping display, the space that blocks
- * the view is now marked with value 2. Any dependencies of map_mark
- * being nonzero have been changed to check for 1. Also, since
+ * Note: For improved magic mapping display, the space that blocks
+ * the view is now marked with value 2. Any dependencies of map_mark
+ * being nonzero have been changed to check for 1. Also, since
* map_mark is a char value, putting 2 in should cause no problems.
*
* This function examines the map the player is on, and determines what
- * is visible. 2 is set for walls or objects that blocks view. 1
- * is for open spaces. map_mark should already have been initialised
+ * is visible. 2 is set for walls or objects that blocks view. 1
+ * is for open spaces. map_mark should already have been initialised
* to zero before this is called.
* strength is an initial strength*2 rectangular area that we automatically
* see in/penetrate through.
*/
-void
+static void
magic_mapping_mark (object *pl, char *map_mark, int strength)
{
- int x, y, mflags;
- sint16 nx, ny;
- maptile *mp;
-
- for (x = -strength; x < strength; x++)
+ for (int x = -strength; x < strength; x++)
{
- for (y = -strength; y < strength; y++)
+ for (int y = -strength; y < strength; y++)
{
- mp = pl->map;
- nx = pl->x + x;
- ny = pl->y + y;
+ mapxy pos (pl);
+ pos.move (x, y);
- mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny);
- if (mflags & P_OUT_OF_MAP)
+ if (!pos.normalise ())
continue;
- int f = GET_MAP_FACE (mp, nx, ny, 0);
+ mapspace &ms = pos.ms ();
+
+ int mflags = ms.flags ();
+
+ int f = GET_MAP_FACE (ms, 0);
if (f == blank_face)
{
- f = GET_MAP_FACE (mp, nx, ny, 1);
+ f = GET_MAP_FACE (ms, 1);
if (f == blank_face)
- f = GET_MAP_FACE (mp, nx, ny, 2);
+ f = GET_MAP_FACE (ms, 2);
}
int magicmap = faces [f].magicmap;
@@ -488,20 +461,3 @@
free (map_mark);
}
-/**
- * Send a kill log record to sockets
- */
-void
-Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType)
-{
- size_t len;
- char buf[MAX_BUF];
-
- if (With != NULL)
- snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType);
- else
- snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType);
-
- len = strlen (buf);
-}
-