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:
50 static char *head_meanwhile(int val);
51 static void head_describe(struct histstr *, int, char *, char *);
52 static int head_printscoop(struct histstr (*hist)[MAXNOC], natid ano,
54 static int head_findscoop(struct histstr (*hist)[MAXNOC],
55 register natid maxcnum, natid *ano, natid *vno);
61 register struct histstr *hp;
62 register natid maxcnum;
68 struct histstr hist[MAXNOC][MAXNOC];
73 struct nstr_item nstr;
77 natp = getnatp(player->cnum);
78 if (player->argp[1] != 0 && *player->argp[1] != 0) {
79 news_per = days(atoi(player->argp[1]));
80 if (news_per > days(3))
83 news_per = now - natp->nat_newstim;
84 pr("\n -=[ EMPIRE NEWS ]=-\n");
85 pr("::::::::::::::::::::::::::::::::::::::::::::::::::\n");
86 pr("! \"All the news that fits, we print.\" !\n");
87 pr("::::::::::::::::::::::::::::::::::::::::::::::::::\n");
88 pr(" %s", ctime(&now));
90 memset(hist, 0, sizeof(hist));
91 snxtitem_all(&nstr, EF_NEWS);
93 while (nxtitem(&nstr, &news)) {
94 news_age = now - news.nws_when;
95 if (news_age > news_per)
97 if (news.nws_ano == news.nws_vno)
99 if ((i = rpt[(int)news.nws_vrb].r_good_will) == 0)
101 if (news_age > news_per / 2)
102 hist[news.nws_ano][news.nws_vno].h_past += i;
104 hist[news.nws_ano][news.nws_vno].h_recent += i;
105 if (maxcnum < news.nws_ano)
106 maxcnum = news.nws_ano;
107 if (maxcnum < news.nws_vno)
108 maxcnum = news.nws_vno;
110 for (n = 0; n < 5; n++) {
111 if ((scoop = head_findscoop(hist, maxcnum, &actor, &victim)) < 10)
113 severity = head_printscoop(hist, actor, victim);
114 hp = &hist[actor][victim];
115 severity = hp->h_recent - hp->h_past;
116 if (severity <= -scoop / 2 || severity >= scoop / 2) {
117 pr("\t%s\n", head_meanwhile(severity));
118 (void)head_printscoop(hist, victim, actor);
122 pr("\nRelative calm prevails.\n");
127 head_printscoop(struct histstr (*hist)[MAXNOC], natid ano, natid vno)
129 register struct histstr *hp;
132 hp = &hist[ano][vno];
133 severity = abs(hp->h_past) > abs(hp->h_recent) ? 1 : 0;
134 severity += (hp->h_past >= 0) ? 2 : 0;
135 severity += (hp->h_recent >= 0) ? 4 : 0;
136 head_describe(hp, severity, cname(ano), cname(vno));
144 head_meanwhile(int val)
150 return "On the other hand";
152 return "At the same time";
161 head_describe(struct histstr *hp, int what, char *aname, char *vname)
165 if (hp->h_recent > hp->h_past / 2)
166 pr("Bad relations between %s and %s worsen!", aname, vname);
168 pr("Carnage wrought by %s on %s continues unabated!",
172 if (hp->h_recent < -16)
173 pr("%s agression against %s has lessened slightly",
176 pr("Peace talks may occur between %s & %s", aname, vname);
179 if (hp->h_recent < -16) {
181 pr(" ! WAR ! Reversal of prior %s -- %s relations",
183 else if (hp->h_recent >= -25)
184 pr("VIOLENCE ERUPTS! -- %s wages war on %s", aname, vname);
186 pr("%s wreaks havoc on %s!", aname, vname);
188 pr("Breakdown in communication between %s & %s", aname, vname);
191 pr("FLASH! %s turns on former ally, %s!", aname, vname);
194 pr("%s \"makes friends\" with %s", aname, vname);
197 if (hp->h_past >= -25)
198 pr("%s seems to have forgotten earlier disagreement with %s",
201 pr("Tensions ease as %s attacks on %s seem at an end",
205 pr("%s good deeds further growing alliance with %s", aname, vname);
208 if (hp->h_recent - hp->h_past < 12)
209 pr("Honeymoon appears to be over between %s & %s",
212 pr("Friendly relations between %s & %s have cooled",
219 * returns 9 if no scoops were found
223 head_findscoop(struct histstr (*hist)[MAXNOC], register natid maxcnum,
224 natid *ano, natid *vno)
226 register struct histstr *hp;
237 for (i = 1; i < maxcnum; i++) {
238 for (j = 1; j < maxcnum; j++) {
240 k = abs(hp->h_recent / 2);
246 k = abs(hp->h_recent - hp->h_past);