2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * news.c: Show current Empire news
29 * Known contributors to this file:
39 static void preport(struct nwsstr *np);
50 struct nstr_item nstr;
51 int page_has_news[N_MAX_PAGE + 1];
52 int there_is_news = 0;
53 short sectors_taken[MAXNOC][MAXNOC];
58 int sectors_were_taken = 0;
63 if (!snxtitem(&nstr, EF_NEWS, "*", NULL))
65 memset(page_has_news, 0, sizeof(page_has_news));
66 memset(sectors_taken, 0, sizeof(sectors_taken));
68 natp = getnatp(player->cnum);
69 then = natp->nat_newstim;
70 if (player->argp[1]) {
72 * We want to hide events before contact. Proper solution
73 * would be to timestamp the contact. Cheesy approximation:
76 if (opt_HIDDEN && !player->god) {
77 pr("Sorry, argument doesn't work with HIDDEN enabled\n");
80 delta = days(atoi(player->argp[1]));
83 natp->nat_newstim = now;
85 pr("\nThe details of Empire news since %s", ctime(&then));
86 while (nxtitem(&nstr, &nws)) {
87 if (!nws.nws_vrb || CANT_HAPPEN(nws.nws_vrb > N_MAX_VERB))
89 if (nws.nws_when < then)
93 !(getcontact(getnatp(player->cnum), nws.nws_ano) &&
94 getcontact(getnatp(player->cnum), nws.nws_vno)))
97 ++page_has_news[rpt[(int)nws.nws_vrb].r_newspage];
100 for (page = 1; page <= N_MAX_PAGE; page++) {
101 if (!page_has_news[page])
103 pr("\n\t === %s ===\n", page_headings[page].name);
104 snxtitem_rewind(&nstr);
105 while (nxtitem(&nstr, &nws)) {
106 if (CANT_HAPPEN(nws.nws_vrb > N_MAX_VERB))
108 if (rpt[(int)nws.nws_vrb].r_newspage != page)
110 if (nws.nws_when < then)
112 if (nws.nws_ntm == 0)
116 !(getcontact(getnatp(player->cnum), nws.nws_ano) &&
117 getcontact(getnatp(player->cnum), nws.nws_vno)))
120 if (page == N_FRONT &&
121 (nws.nws_vrb == N_WON_SECT ||
122 nws.nws_vrb == N_AWON_SECT ||
123 nws.nws_vrb == N_PWON_SECT)) {
124 sectors_taken[nws.nws_ano][nws.nws_vno] += nws.nws_ntm;
125 sectors_were_taken += nws.nws_ntm;
130 if (sectors_were_taken) {
131 for (i = 0; i < MAXNOC; ++i) {
132 for (j = 0; j < i; ++j) {
133 sectors_delta = sectors_taken[i][j] - sectors_taken[j][i];
134 if (max_delta < abs(sectors_delta))
135 max_delta = abs(sectors_delta);
138 pr("\n\t === The Bottom Line ==\n");
139 for (k = max_delta; k > 0; --k) {
140 for (i = 0; i < MAXNOC; ++i) {
141 for (j = 0; j < i; ++j) {
142 sectors_delta = sectors_taken[i][j] -
144 abs_delta = abs(sectors_delta);
149 else if (abs_delta < 4)
151 else if (abs_delta < 8)
155 if (sectors_delta > 0) {
156 numstr(num, abs_delta);
157 pr("%s %s %s sector%s from %s\n", cname(i), verb,
158 num, splur(sectors_delta), cname(j));
159 } else if (sectors_delta < 0) {
160 numstr(num, abs_delta);
161 pr("%s %s %s sector%s from %s\n", cname(j), verb,
162 num, splur(-sectors_delta), cname(i));
169 pr("\nNo news at the moment...\n");
174 preport(struct nwsstr *np)
183 sprintf(buf, "%-16.16s ", ctime(&np->nws_when));
185 ptr = numstr(num, np->nws_ntm);
187 * vary the order of the printing of "%d times "
189 if ((random() & 3) == 0 && np->nws_ntm > 1) {
190 sprintf(cp, "%s times ", ptr);
194 strcpy(cp, cname(np->nws_ano));
197 sprintf(cp, rpt[(int)np->nws_vrb].r_newstory[random() % NUM_RPTS],
200 if (np->nws_ntm != 1) {
201 sprintf(cp, " %s times", ptr);
205 for (i = 80; --i > 60;)
209 pr("%s\n\t\t %s\n", buf, &buf[i + 1]);