2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, 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 * head.c: Print headlines of the Empire News
29 * Known contributors to this file:
43 static char *head_meanwhile(int val);
44 static void head_describe(struct histstr *, int, char *, char *);
45 static int head_printscoop(struct histstr (*hist)[MAXNOC], natid ano,
47 static int head_findscoop(struct histstr (*hist)[MAXNOC],
48 natid maxcnum, natid *ano, natid *vno);
60 struct histstr hist[MAXNOC][MAXNOC];
65 struct nstr_item nstr;
69 natp = getnatp(player->cnum);
70 if (player->argp[1] && *player->argp[1]) {
71 news_per = days(atoi(player->argp[1]));
72 if (news_per > days(3))
75 news_per = now - natp->nat_newstim;
76 pr("\n -=[ EMPIRE NEWS ]=-\n");
77 pr("::::::::::::::::::::::::::::::::::::::::::::::::::\n");
78 pr("! \"All the news that fits, we print.\" !\n");
79 pr("::::::::::::::::::::::::::::::::::::::::::::::::::\n");
80 pr(" %s", ctime(&now));
82 memset(hist, 0, sizeof(hist));
83 snxtitem_all(&nstr, EF_NEWS);
85 while (nxtitem(&nstr, &news)) {
86 if (!news.nws_vrb || CANT_HAPPEN(news.nws_vrb > N_MAX_VERB))
88 news_age = now - news.nws_when;
89 if (news_age > news_per)
91 if (news.nws_ano == news.nws_vno)
93 if ((i = rpt[(int)news.nws_vrb].r_good_will) == 0)
95 if (news_age > news_per / 2)
96 hist[news.nws_ano][news.nws_vno].h_past += i;
98 hist[news.nws_ano][news.nws_vno].h_recent += i;
99 if (maxcnum < news.nws_ano)
100 maxcnum = news.nws_ano;
101 if (maxcnum < news.nws_vno)
102 maxcnum = news.nws_vno;
104 for (n = 0; n < 5; n++) {
105 if ((scoop = head_findscoop(hist, maxcnum, &actor, &victim)) < 10)
107 head_printscoop(hist, actor, victim);
108 hp = &hist[actor][victim];
109 severity = hp->h_recent - hp->h_past;
110 if (severity <= -scoop / 2 || severity >= scoop / 2) {
111 pr("\t%s\n", head_meanwhile(severity));
112 (void)head_printscoop(hist, victim, actor);
116 pr("\nRelative calm prevails.\n");
121 head_printscoop(struct histstr (*hist)[MAXNOC], natid ano, natid vno)
126 hp = &hist[ano][vno];
127 severity = abs(hp->h_past) > abs(hp->h_recent) ? 1 : 0;
128 severity += (hp->h_past >= 0) ? 2 : 0;
129 severity += (hp->h_recent >= 0) ? 4 : 0;
130 head_describe(hp, severity, cname(ano), cname(vno));
138 head_meanwhile(int val)
144 return "On the other hand";
146 return "At the same time";
155 head_describe(struct histstr *hp, int what, char *aname, char *vname)
159 if (hp->h_recent > hp->h_past / 2)
160 pr("Bad relations between %s and %s worsen!", aname, vname);
162 pr("Carnage wrought by %s on %s continues unabated!",
166 if (hp->h_recent < -16)
167 pr("%s agression against %s has lessened slightly",
170 pr("Peace talks may occur between %s & %s", aname, vname);
173 if (hp->h_recent < -16) {
175 pr(" ! WAR ! Reversal of prior %s -- %s relations",
177 else if (hp->h_recent >= -25)
178 pr("VIOLENCE ERUPTS! -- %s wages war on %s", aname, vname);
180 pr("%s wreaks havoc on %s!", aname, vname);
182 pr("Breakdown in communication between %s & %s", aname, vname);
185 pr("FLASH! %s turns on former ally, %s!", aname, vname);
188 pr("%s \"makes friends\" with %s", aname, vname);
191 if (hp->h_past >= -25)
192 pr("%s seems to have forgotten earlier disagreement with %s",
195 pr("Tensions ease as %s attacks on %s seem at an end",
199 pr("%s good deeds further growing alliance with %s", aname, vname);
202 if (hp->h_recent - hp->h_past < 12)
203 pr("Honeymoon appears to be over between %s & %s",
206 pr("Friendly relations between %s & %s have cooled",
213 * returns 9 if no scoops were found
217 head_findscoop(struct histstr (*hist)[MAXNOC], natid maxcnum,
218 natid *ano, natid *vno)
227 for (i = 1; i < maxcnum; i++) {
228 for (j = 1; j < maxcnum; j++) {
230 k = abs(hp->h_recent / 2);
236 k = abs(hp->h_recent - hp->h_past);