2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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 * head.c: Print headlines of the Empire News
30 * Known contributors to this file:
44 static char *head_meanwhile(int val);
45 static void head_describe(struct histstr *, int, char *, char *);
46 static int head_printscoop(struct histstr (*hist)[MAXNOC], natid ano,
48 static int head_findscoop(struct histstr (*hist)[MAXNOC],
49 natid maxcnum, natid *ano, natid *vno);
61 struct histstr hist[MAXNOC][MAXNOC];
66 struct nstr_item nstr;
70 natp = getnatp(player->cnum);
71 if (player->argp[1] != 0 && *player->argp[1] != 0) {
72 news_per = days(atoi(player->argp[1]));
73 if (news_per > days(3))
76 news_per = now - natp->nat_newstim;
77 pr("\n -=[ EMPIRE NEWS ]=-\n");
78 pr("::::::::::::::::::::::::::::::::::::::::::::::::::\n");
79 pr("! \"All the news that fits, we print.\" !\n");
80 pr("::::::::::::::::::::::::::::::::::::::::::::::::::\n");
81 pr(" %s", ctime(&now));
83 memset(hist, 0, sizeof(hist));
84 snxtitem_all(&nstr, EF_NEWS);
86 while (nxtitem(&nstr, &news)) {
87 news_age = now - news.nws_when;
88 if (news_age > news_per)
90 if (news.nws_ano == news.nws_vno)
92 if ((i = rpt[(int)news.nws_vrb].r_good_will) == 0)
94 if (news_age > news_per / 2)
95 hist[news.nws_ano][news.nws_vno].h_past += i;
97 hist[news.nws_ano][news.nws_vno].h_recent += i;
98 if (maxcnum < news.nws_ano)
99 maxcnum = news.nws_ano;
100 if (maxcnum < news.nws_vno)
101 maxcnum = news.nws_vno;
103 for (n = 0; n < 5; n++) {
104 if ((scoop = head_findscoop(hist, maxcnum, &actor, &victim)) < 10)
106 severity = head_printscoop(hist, actor, victim);
107 hp = &hist[actor][victim];
108 severity = hp->h_recent - hp->h_past;
109 if (severity <= -scoop / 2 || severity >= scoop / 2) {
110 pr("\t%s\n", head_meanwhile(severity));
111 (void)head_printscoop(hist, victim, actor);
115 pr("\nRelative calm prevails.\n");
120 head_printscoop(struct histstr (*hist)[MAXNOC], natid ano, natid vno)
125 hp = &hist[ano][vno];
126 severity = abs(hp->h_past) > abs(hp->h_recent) ? 1 : 0;
127 severity += (hp->h_past >= 0) ? 2 : 0;
128 severity += (hp->h_recent >= 0) ? 4 : 0;
129 head_describe(hp, severity, cname(ano), cname(vno));
137 head_meanwhile(int val)
143 return "On the other hand";
145 return "At the same time";
154 head_describe(struct histstr *hp, int what, char *aname, char *vname)
158 if (hp->h_recent > hp->h_past / 2)
159 pr("Bad relations between %s and %s worsen!", aname, vname);
161 pr("Carnage wrought by %s on %s continues unabated!",
165 if (hp->h_recent < -16)
166 pr("%s agression against %s has lessened slightly",
169 pr("Peace talks may occur between %s & %s", aname, vname);
172 if (hp->h_recent < -16) {
174 pr(" ! WAR ! Reversal of prior %s -- %s relations",
176 else if (hp->h_recent >= -25)
177 pr("VIOLENCE ERUPTS! -- %s wages war on %s", aname, vname);
179 pr("%s wreaks havoc on %s!", aname, vname);
181 pr("Breakdown in communication between %s & %s", aname, vname);
184 pr("FLASH! %s turns on former ally, %s!", aname, vname);
187 pr("%s \"makes friends\" with %s", aname, vname);
190 if (hp->h_past >= -25)
191 pr("%s seems to have forgotten earlier disagreement with %s",
194 pr("Tensions ease as %s attacks on %s seem at an end",
198 pr("%s good deeds further growing alliance with %s", aname, vname);
201 if (hp->h_recent - hp->h_past < 12)
202 pr("Honeymoon appears to be over between %s & %s",
205 pr("Friendly relations between %s & %s have cooled",
212 * returns 9 if no scoops were found
216 head_findscoop(struct histstr (*hist)[MAXNOC], natid maxcnum,
217 natid *ano, natid *vno)
226 for (i = 1; i < maxcnum; i++) {
227 for (j = 1; j < maxcnum; j++) {
229 k = abs(hp->h_recent / 2);
235 k = abs(hp->h_recent - hp->h_past);