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 * news.c: Show current Empire news
30 * Known contributors to this file:
44 static void preport(register struct nwsstr *np);
55 struct nstr_item nstr;
56 int page_has_news[N_MAX_PAGE + 1];
57 int there_is_news = 0;
58 short sectors_taken[MAXNOC][MAXNOC];
63 int sectors_were_taken = 0;
68 memset(page_has_news, 0, sizeof(page_has_news));
69 memset(sectors_taken, 0, sizeof(sectors_taken));
72 natp = getnatp(player->cnum);
73 then = natp->nat_newstim;
75 if (player->argp[1] != 0 && isdigit(*player->argp[1])) {
76 delta = days(atoi(player->argp[1]));
80 natp->nat_newstim = now;
81 /* if (then < now - days(3))
84 snxtitem(&nstr, EF_NEWS, "*");
85 pr("\nThe details of Empire news since %s", ctime(&then));
86 while (nxtitem(&nstr, (s_char *)&nws)) {
87 if (nws.nws_when < then)
91 !(getcontact(getnatp(player->cnum), nws.nws_ano) &&
92 getcontact(getnatp(player->cnum), nws.nws_vno)))
95 ++page_has_news[rpt[(int)nws.nws_vrb].r_newspage];
98 for (page = 1; page <= N_MAX_PAGE; page++) {
99 if (!page_has_news[page])
101 pr("\n\t === %s ===\n", page_headings[page]);
102 snxtitem_rewind(&nstr);
103 while (nxtitem(&nstr, (s_char *)&nws)) {
104 if (rpt[(int)nws.nws_vrb].r_newspage != page)
106 if (nws.nws_when < then)
108 if (nws.nws_ntm == 0)
112 !(getcontact(getnatp(player->cnum), nws.nws_ano) &&
113 getcontact(getnatp(player->cnum), nws.nws_vno)))
116 if (page == N_FRONT &&
117 (nws.nws_vrb == N_WON_SECT ||
118 nws.nws_vrb == N_AWON_SECT ||
119 nws.nws_vrb == N_PWON_SECT)) {
120 sectors_taken[nws.nws_ano][nws.nws_vno] += nws.nws_ntm;
121 sectors_were_taken += nws.nws_ntm;
126 if (sectors_were_taken) {
127 for (i = 0; i < MAXNOC; ++i) {
128 for (j = 0; j < i; ++j) {
129 sectors_delta = sectors_taken[i][j] - sectors_taken[j][i];
130 if (max_delta < abs(sectors_delta))
131 max_delta = abs(sectors_delta);
134 pr("\n\t === The Bottom Line ==\n");
135 for (k = max_delta; k > 0; --k) {
136 for (i = 0; i < MAXNOC; ++i) {
137 for (j = 0; j < i; ++j) {
138 sectors_delta = sectors_taken[i][j] -
140 abs_delta = abs(sectors_delta);
145 else if (abs_delta < 4)
147 else if (abs_delta < 8)
151 if (sectors_delta > 0) {
152 numstr(num, abs_delta);
153 pr("%s %s %s sector%s from %s\n", cname(i), verb,
154 num, splur(sectors_delta), cname(j));
155 } else if (sectors_delta < 0) {
156 numstr(num, abs_delta);
157 pr("%s %s %s sector%s from %s\n", cname(j), verb,
158 num, splur(-sectors_delta), cname(i));
165 pr("\nNo news at the moment...\n");
170 preport(register struct nwsstr *np)
179 sprintf(buf, "%-16.16s ", ctime(&np->nws_when));
181 ptr = numstr(num, np->nws_ntm);
183 * vary the order of the printing of "%d times "
185 if ((random() & 3) == 0 && np->nws_ntm > 1) {
186 sprintf(cp, "%s times ", ptr);
190 strcpy(cp, cname(np->nws_ano));
193 if (np->nws_vrb < 1 || np->nws_vrb > N_MAX_VERB)
195 sprintf(cp, rpt[(int)np->nws_vrb].r_newstory[random() % NUM_RPTS],
198 if (np->nws_ntm != 1) {
199 sprintf(cp, " %s times", ptr);
202 if (*buf >= 'a' && *buf <= 'z')
205 for (i = 80; --i > 60;)
209 pr("%s\n\t\t %s\n", buf, &buf[i + 1]);