2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * news.c: Show current Empire news
30 * Known contributors to this file:
40 static void preport(struct nwsstr *np);
51 struct nstr_item nstr;
52 int page_has_news[N_MAX_PAGE + 1];
53 int there_is_news = 0;
54 short sectors_taken[MAXNOC][MAXNOC];
59 int sectors_were_taken = 0;
64 if (!snxtitem(&nstr, EF_NEWS, "*"))
66 memset(page_has_news, 0, sizeof(page_has_news));
67 memset(sectors_taken, 0, sizeof(sectors_taken));
69 natp = getnatp(player->cnum);
70 then = natp->nat_newstim;
71 if (player->argp[1]) {
73 * We want to hide events before contact. Proper solution
74 * would be to timestamp the contact. Cheesy approximation:
77 if (opt_HIDDEN && !player->god) {
78 pr("Sorry, argument doesn't work with HIDDEN enabled\n");
81 delta = days(atoi(player->argp[1]));
84 natp->nat_newstim = now;
86 pr("\nThe details of Empire news since %s", ctime(&then));
87 while (nxtitem(&nstr, &nws)) {
88 if (nws.nws_when < then)
92 !(getcontact(getnatp(player->cnum), nws.nws_ano) &&
93 getcontact(getnatp(player->cnum), nws.nws_vno)))
96 ++page_has_news[rpt[(int)nws.nws_vrb].r_newspage];
99 for (page = 1; page <= N_MAX_PAGE; page++) {
100 if (!page_has_news[page])
102 pr("\n\t === %s ===\n", page_headings[page].name);
103 snxtitem_rewind(&nstr);
104 while (nxtitem(&nstr, &nws)) {
105 if (rpt[(int)nws.nws_vrb].r_newspage != page)
107 if (nws.nws_when < then)
109 if (nws.nws_ntm == 0)
113 !(getcontact(getnatp(player->cnum), nws.nws_ano) &&
114 getcontact(getnatp(player->cnum), nws.nws_vno)))
117 if (page == N_FRONT &&
118 (nws.nws_vrb == N_WON_SECT ||
119 nws.nws_vrb == N_AWON_SECT ||
120 nws.nws_vrb == N_PWON_SECT)) {
121 sectors_taken[nws.nws_ano][nws.nws_vno] += nws.nws_ntm;
122 sectors_were_taken += nws.nws_ntm;
127 if (sectors_were_taken) {
128 for (i = 0; i < MAXNOC; ++i) {
129 for (j = 0; j < i; ++j) {
130 sectors_delta = sectors_taken[i][j] - sectors_taken[j][i];
131 if (max_delta < abs(sectors_delta))
132 max_delta = abs(sectors_delta);
135 pr("\n\t === The Bottom Line ==\n");
136 for (k = max_delta; k > 0; --k) {
137 for (i = 0; i < MAXNOC; ++i) {
138 for (j = 0; j < i; ++j) {
139 sectors_delta = sectors_taken[i][j] -
141 abs_delta = abs(sectors_delta);
146 else if (abs_delta < 4)
148 else if (abs_delta < 8)
152 if (sectors_delta > 0) {
153 numstr(num, abs_delta);
154 pr("%s %s %s sector%s from %s\n", cname(i), verb,
155 num, splur(sectors_delta), cname(j));
156 } else if (sectors_delta < 0) {
157 numstr(num, abs_delta);
158 pr("%s %s %s sector%s from %s\n", cname(j), verb,
159 num, splur(-sectors_delta), cname(i));
166 pr("\nNo news at the moment...\n");
171 preport(struct nwsstr *np)
180 sprintf(buf, "%-16.16s ", ctime(&np->nws_when));
182 ptr = numstr(num, np->nws_ntm);
184 * vary the order of the printing of "%d times "
186 if ((random() & 3) == 0 && np->nws_ntm > 1) {
187 sprintf(cp, "%s times ", ptr);
191 strcpy(cp, cname(np->nws_ano));
194 if (np->nws_vrb < 1 || np->nws_vrb > N_MAX_VERB)
196 sprintf(cp, rpt[(int)np->nws_vrb].r_newstory[random() % NUM_RPTS],
199 if (np->nws_ntm != 1) {
200 sprintf(cp, " %s times", ptr);
203 if (*buf >= 'a' && *buf <= 'z')
206 for (i = 80; --i > 60;)
210 pr("%s\n\t\t %s\n", buf, &buf[i + 1]);