2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * pr.c: Use to do output to a player
30 * Known contributors to this file:
31 * Dave Pare, 1986, 1989
32 * Steve McClure, 1998-2000
35 * The pr routine historically arranged for nonbuffered i/o
36 * because stdio didn't used to automatically flush stdout before
37 * it read something from stdin. Now pr() prepends an "output id"
38 * in front of each line of text, informing the user interface
39 * what sort of item it is seeing; prompt, noecho prompt,
40 * more input data, etc.
58 extern int update_pending;
59 #include "prototypes.h"
61 void outid(struct player *pl, int n);
65 pr(s_char *format, ...)
71 (void) vsprintf(buf, format, ap);
73 pr_player(player, C_DATA, buf);
79 pr_player(player, C_DATA, buf);
84 pr_id(struct player *p, int id, s_char *format, ...)
90 io_puts(p->iop, "\n");
94 (void) vsprintf(buf, format, ap);
96 pr_player(p, id, buf);
100 pr_flash(struct player *pl, s_char *format, ...)
105 if (pl->state != PS_PLAYING)
107 va_start(ap, format);
108 (void) vsprintf(buf, format, ap);
110 pr_player(pl, C_FLASH, buf);
111 io_output(pl->iop, IO_NOWAIT);
115 pr_inform(struct player *pl, s_char *format, ...)
120 if (pl->state != PS_PLAYING)
122 va_start(ap, format);
123 (void) vsprintf(buf, format, ap);
125 pr_player(pl, C_INFORM, buf);
126 io_output(pl->iop, IO_NOWAIT);
130 pr_wall(s_char *format, ...)
136 va_start(ap, format);
137 (void) vsprintf(buf, format, ap);
139 for (p = player_next(0); p; p = player_next(p)) {
140 if (p->state != PS_PLAYING)
142 pr_player(p, C_FLASH, buf);
143 io_output(p->iop, IO_NOWAIT);
148 pr_player(struct player *pl, int id, s_char *buf)
155 while (*bp != '\0') {
156 if (pl->curid != -1 && pl->curid != id) {
157 io_puts (pl->iop, "\n");
160 if (pl->curid == -1) {
166 if (pl->command && (pl->command->c_flags & C_MOD))
167 io_write(pl->iop, bp, len, IO_NOWAIT);
169 io_write(pl->iop, bp, len, IO_WAIT);
173 len = io_puts(pl->iop, bp);
180 * highlighted characters have hex 80 or'ed in
181 * with them to designate their highlightedness
184 pr_hilite(s_char *buf)
190 p = (s_char *)malloc(strlen(buf) + 1);
192 for (bp=p; 0 != (c = *bp); bp++)
200 * output hex code + space
203 outid(struct player *pl, int n)
209 logerror("outid: %d not valid code\n", n);
219 io_puts(pl->iop, buf);
224 prredir(s_char *redir)
226 pr_id(player, *redir == '>' ? C_REDIR : C_PIPE, "%s\n", redir);
232 pr_id(player, C_EXECUTE, "%s\n", file);
236 prprompt(int min, int btu)
238 pr_id(player, C_PROMPT, "%d %d\n", min, btu);
244 pr_id(player, C_INIT, "%d\n", vers);
248 prmptrd(s_char *prompt, s_char *str, int size)
252 pr_id(player, C_FLUSH, "%s\n", prompt);
253 if ((r = recvclient(str, size)) < 0)
255 time(&player->curup);
271 * print x,y formatting as country
274 prxy(s_char *format, coord x, coord y, natid country)
279 np = getnatp(country);
280 sprintf(buf, format, xrel(np, x), yrel(np, y));
286 PR(int cn, s_char *format, ...)
288 /* XXX should really do this on a per-nation basis */
289 static s_char longline[MAXNOC][512];
294 va_start(ap, format);
295 (void) vsprintf(buf, format, ap);
297 newline = strrchr(buf, '\n') ? 1 : 0;
298 strcat(longline[cn], buf);
300 if (update_pending || (cn && cn != player->cnum))
301 typed_wu(0, cn, longline[cn], TEL_BULLETIN);
303 pr_player(player, C_DATA, longline[cn]);
304 longline[cn][0] = '\0';
320 struct natstr *np = getnatp(player->cnum);
322 if (np->nat_flags & NF_BEEP)
327 mpr(int cn, s_char *format, ...)
332 va_start(ap, format);
333 (void) vsprintf(buf, format, ap);
336 if (update_pending || cn != player->cnum)
337 typed_wu(0, cn, buf, TEL_BULLETIN);
339 pr_player(player, C_DATA, buf);