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.
56 #include "prototypes.h"
58 static void outid(struct player *pl, int n);
62 pr(s_char *format, ...)
68 (void)vsprintf(buf, format, ap);
70 pr_player(player, C_DATA, buf);
76 pr_player(player, C_DATA, buf);
81 pr_id(struct player *p, int id, s_char *format, ...)
87 io_puts(p->iop, "\n");
91 (void)vsprintf(buf, format, ap);
93 pr_player(p, id, buf);
97 pr_flash(struct player *pl, s_char *format, ...)
102 if (pl->state != PS_PLAYING)
104 va_start(ap, format);
105 (void)vsprintf(buf, format, ap);
107 pr_player(pl, C_FLASH, buf);
108 io_output(pl->iop, IO_NOWAIT);
112 pr_inform(struct player *pl, s_char *format, ...)
117 if (pl->state != PS_PLAYING)
119 va_start(ap, format);
120 (void)vsprintf(buf, format, ap);
122 pr_player(pl, C_INFORM, buf);
123 io_output(pl->iop, IO_NOWAIT);
127 pr_wall(s_char *format, ...)
133 va_start(ap, format);
134 (void)vsprintf(buf, format, ap);
136 for (p = player_next(0); p; p = player_next(p)) {
137 if (p->state != PS_PLAYING)
139 pr_player(p, C_FLASH, buf);
140 io_output(p->iop, IO_NOWAIT);
145 pr_player(struct player *pl, int id, s_char *buf)
152 while (*bp != '\0') {
153 if (pl->curid != -1 && pl->curid != id) {
154 io_puts(pl->iop, "\n");
157 if (pl->curid == -1) {
160 p = strchr(bp, '\n');
163 if (pl->command && (pl->command->c_flags & C_MOD))
164 io_write(pl->iop, bp, len, IO_NOWAIT);
166 io_write(pl->iop, bp, len, IO_WAIT);
170 len = io_puts(pl->iop, bp);
177 * highlighted characters have hex 80 or'ed in
178 * with them to designate their highlightedness
181 pr_hilite(s_char *buf)
187 p = (s_char *)malloc(strlen(buf) + 1);
189 for (bp = p; 0 != (c = *bp); bp++)
197 * output hex code + space
200 outid(struct player *pl, int n)
206 logerror("outid: %d not valid code\n", n);
216 io_puts(pl->iop, buf);
221 prredir(s_char *redir)
223 pr_id(player, *redir == '>' ? C_REDIR : C_PIPE, "%s\n", redir);
229 pr_id(player, C_EXECUTE, "%s\n", file);
233 prprompt(int min, int btu)
235 pr_id(player, C_PROMPT, "%d %d\n", min, btu);
241 pr_id(player, C_INIT, "%d\n", vers);
245 prmptrd(s_char *prompt, s_char *str, int size)
249 pr_id(player, C_FLUSH, "%s\n", prompt);
250 if ((r = recvclient(str, size)) < 0)
252 time(&player->curup);
268 * print x,y formatting as country
271 prxy(s_char *format, coord x, coord y, natid country)
276 np = getnatp(country);
277 sprintf(buf, format, xrel(np, x), yrel(np, y));
283 PR(int cn, s_char *format, ...)
285 /* XXX should really do this on a per-nation basis */
286 static s_char longline[MAXNOC][512];
291 va_start(ap, format);
292 (void)vsprintf(buf, format, ap);
294 newline = strrchr(buf, '\n') ? 1 : 0;
295 strcat(longline[cn], buf);
297 if (update_pending || (cn && cn != player->cnum))
298 typed_wu(0, cn, longline[cn], TEL_BULLETIN);
300 pr_player(player, C_DATA, longline[cn]);
301 longline[cn][0] = '\0';
317 struct natstr *np = getnatp(player->cnum);
319 if (np->nat_flags & NF_BEEP)
324 mpr(int cn, s_char *format, ...)
329 va_start(ap, format);
330 (void)vsprintf(buf, format, ap);
333 if (update_pending || cn != player->cnum)
334 typed_wu(0, cn, buf, TEL_BULLETIN);
336 pr_player(player, C_DATA, buf);