2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2016, 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:
30 * Markus Armbruster, 2006-2016
40 static void preport(struct nwsstr *np);
41 static int sectwon_cmp(const void *p, const void *q);
57 struct nstr_item nstr;
58 int page_has_news[N_MAX_PAGE + 1];
59 unsigned short sectors_taken[MAXNOC][MAXNOC];
62 struct sectwon *sectwon;
66 if (!snxtitem(&nstr, EF_NEWS, "*", NULL))
68 memset(sectors_taken, 0, sizeof(sectors_taken));
70 natp = getnatp(player->cnum);
71 then = natp->nat_newstim;
72 if (player->argp[1]) {
74 * We want to hide events before contact. Proper solution
75 * would be to timestamp the contact. Cheesy approximation:
78 if (opt_HIDDEN && !player->god) {
79 pr("Sorry, argument doesn't work with HIDDEN enabled\n");
82 delta = days(atoi(player->argp[1]));
85 natp->nat_newstim = now;
87 pr("\nThe details of Empire news since %s", ctime(&then));
90 memset(page_has_news, 0, sizeof(page_has_news));
93 for (page = 0; page <= N_MAX_PAGE; page++) {
94 if (!page_has_news[page])
96 snxtitem_rewind(&nstr);
97 while (nxtitem(&nstr, &nws)) {
98 if (CANT_HAPPEN(nws.nws_vrb > N_MAX_VERB))
100 if (nws.nws_when < then)
102 if (CANT_HAPPEN(nws.nws_ntm <= 0))
106 !(getcontact(getnatp(player->cnum), nws.nws_ano) &&
107 getcontact(getnatp(player->cnum), nws.nws_vno)))
110 page_has_news[rpt[nws.nws_vrb].r_newspage] = 1;
111 if (rpt[nws.nws_vrb].r_newspage != page)
113 if (heading != page) {
114 pr("\n\t === %s ===\n", page_headings[page].name);
117 if (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;
126 pr("\nNo news at the moment...\n");
131 for (i = 0; i < MAXNOC; ++i) {
132 for (j = 0; j < i; ++j)
133 n += !!(sectors_taken[i][j] - sectors_taken[j][i]);
135 sectwon = malloc(sizeof(*sectwon) * n);
138 for (i = 0; i < MAXNOC; ++i) {
139 for (j = 0; j < i; ++j) {
140 diff = sectors_taken[i][j] - sectors_taken[j][i];
144 sectwon[n].num = diff;
146 } else if (diff < 0) {
149 sectwon[n].num = -diff;
155 qsort(sectwon, n, sizeof(*sectwon), sectwon_cmp);
158 pr("\n\t === The Bottom Line ==\n");
159 for (k = 0; k < n; k++) {
160 if (sectwon[k].num == 1)
162 else if (sectwon[k].num < 4)
164 else if (sectwon[k].num < 8)
168 numstr(num, sectwon[k].num);
169 pr("%s %s %s sector%s from %s\n",
170 cname(sectwon[k].ano), verb, num, splur(sectwon[k].num),
171 cname(sectwon[k].vno));
180 preport(struct nwsstr *np)
189 sprintf(buf, "%-16.16s ", ctime(&np->nws_when));
191 ptr = numstr(num, np->nws_ntm);
193 * vary the order of the printing of "%d times "
195 if (roll0(4) == 0 && np->nws_ntm > 1) {
196 sprintf(cp, "%s times ", ptr);
200 strcpy(cp, cname(np->nws_ano));
203 sprintf(cp, rpt[(int)np->nws_vrb].r_newstory[roll0(NUM_RPTS)],
206 if (np->nws_ntm != 1) {
207 sprintf(cp, " %s times", ptr);
211 for (i = 80; --i > 60;)
215 pr("%s\n\t\t %s\n", buf, &buf[i + 1]);
224 sectwon_cmp(const void *p, const void *q)
226 const struct sectwon *a = p, *b = q;
229 cmp = b->num - a->num;
232 cmp = b->ano - a->ano;
235 return b->vno - a->vno;