2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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.
57 #include "prototypes.h"
59 static void outid(struct player *pl, int n);
63 pr(s_char *format, ...)
69 (void)vsprintf(buf, format, ap);
71 pr_player(player, C_DATA, buf);
77 pr_player(player, C_DATA, buf);
82 pr_id(struct player *p, int id, s_char *format, ...)
88 io_puts(p->iop, "\n");
92 (void)vsprintf(buf, format, ap);
94 pr_player(p, id, buf);
98 pr_flash(struct player *pl, s_char *format, ...)
103 if (pl->state != PS_PLAYING)
105 va_start(ap, format);
106 (void)vsprintf(buf, format, ap);
108 pr_player(pl, C_FLASH, buf);
109 io_output(pl->iop, IO_NOWAIT);
113 pr_inform(struct player *pl, s_char *format, ...)
118 if (pl->state != PS_PLAYING)
120 va_start(ap, format);
121 (void)vsprintf(buf, format, ap);
123 pr_player(pl, C_INFORM, buf);
124 io_output(pl->iop, IO_NOWAIT);
128 pr_wall(s_char *format, ...)
134 va_start(ap, format);
135 (void)vsprintf(buf, format, ap);
137 for (p = player_next(0); p; p = player_next(p)) {
138 if (p->state != PS_PLAYING)
140 pr_player(p, C_FLASH, buf);
141 io_output(p->iop, IO_NOWAIT);
146 pr_player(struct player *pl, int id, s_char *buf)
153 while (*bp != '\0') {
154 if (pl->curid != -1 && pl->curid != id) {
155 io_puts(pl->iop, "\n");
158 if (pl->curid == -1) {
161 p = strchr(bp, '\n');
164 if (pl->command && (pl->command->c_flags & C_MOD))
165 io_write(pl->iop, bp, len, IO_NOWAIT);
167 io_write(pl->iop, bp, len, IO_WAIT);
171 len = io_puts(pl->iop, bp);
178 * highlighted characters have hex 80 or'ed in
179 * with them to designate their highlightedness
182 pr_hilite(s_char *buf)
188 p = (s_char *)malloc(strlen(buf) + 1);
190 for (bp = p; 0 != (c = *bp); bp++)
198 * output hex code + space
201 outid(struct player *pl, int n)
207 logerror("outid: %d not valid code\n", n);
217 io_puts(pl->iop, buf);
222 prredir(s_char *redir)
224 pr_id(player, *redir == '>' ? C_REDIR : C_PIPE, "%s\n", redir);
230 pr_id(player, C_EXECUTE, "%s\n", file);
234 prprompt(int min, int btu)
236 pr_id(player, C_PROMPT, "%d %d\n", min, btu);
242 pr_id(player, C_INIT, "%d\n", vers);
246 prmptrd(s_char *prompt, s_char *str, int size)
250 pr_id(player, C_FLUSH, "%s\n", prompt);
251 if ((r = recvclient(str, size)) < 0)
253 time(&player->curup);
269 * print x,y formatting as country
272 prxy(s_char *format, coord x, coord y, natid country)
277 np = getnatp(country);
278 sprintf(buf, format, xrel(np, x), yrel(np, y));
284 PR(int cn, s_char *format, ...)
286 /* XXX should really do this on a per-nation basis */
287 static s_char longline[MAXNOC][512];
292 va_start(ap, format);
293 (void)vsprintf(buf, format, ap);
295 newline = strrchr(buf, '\n') ? 1 : 0;
296 strcat(longline[cn], buf);
298 if (update_pending || (cn && cn != player->cnum))
299 typed_wu(0, cn, longline[cn], TEL_BULLETIN);
301 pr_player(player, C_DATA, longline[cn]);
302 longline[cn][0] = '\0';
318 struct natstr *np = getnatp(player->cnum);
320 if (np->nat_flags & NF_BEEP)
325 mpr(int cn, s_char *format, ...)
330 va_start(ap, format);
331 (void)vsprintf(buf, format, ap);
334 if (update_pending || cn != player->cnum)
335 typed_wu(0, cn, buf, TEL_BULLETIN);
337 pr_player(player, C_DATA, buf);