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 natid maxcnum, natid *ano, natid *vno);
67 struct histstr hist[MAXNOC][MAXNOC];
72 struct nstr_item nstr;
76 natp = getnatp(player->cnum);
77 if (player->argp[1] != 0 && *player->argp[1] != 0) {
78 news_per = days(atoi(player->argp[1]));
79 if (news_per > days(3))
82 news_per = now - natp->nat_newstim;
83 pr("\n -=[ EMPIRE NEWS ]=-\n");
84 pr("::::::::::::::::::::::::::::::::::::::::::::::::::\n");
85 pr("! \"All the news that fits, we print.\" !\n");
86 pr("::::::::::::::::::::::::::::::::::::::::::::::::::\n");
87 pr(" %s", ctime(&now));
89 memset(hist, 0, sizeof(hist));
90 snxtitem_all(&nstr, EF_NEWS);
92 while (nxtitem(&nstr, &news)) {
93 news_age = now - news.nws_when;
94 if (news_age > news_per)
96 if (news.nws_ano == news.nws_vno)
98 if ((i = rpt[(int)news.nws_vrb].r_good_will) == 0)
100 if (news_age > news_per / 2)
101 hist[news.nws_ano][news.nws_vno].h_past += i;
103 hist[news.nws_ano][news.nws_vno].h_recent += i;
104 if (maxcnum < news.nws_ano)
105 maxcnum = news.nws_ano;
106 if (maxcnum < news.nws_vno)
107 maxcnum = news.nws_vno;
109 for (n = 0; n < 5; n++) {
110 if ((scoop = head_findscoop(hist, maxcnum, &actor, &victim)) < 10)
112 severity = head_printscoop(hist, actor, victim);
113 hp = &hist[actor][victim];
114 severity = hp->h_recent - hp->h_past;
115 if (severity <= -scoop / 2 || severity >= scoop / 2) {
116 pr("\t%s\n", head_meanwhile(severity));
117 (void)head_printscoop(hist, victim, actor);
121 pr("\nRelative calm prevails.\n");
126 head_printscoop(struct histstr (*hist)[MAXNOC], natid ano, natid vno)
131 hp = &hist[ano][vno];
132 severity = abs(hp->h_past) > abs(hp->h_recent) ? 1 : 0;
133 severity += (hp->h_past >= 0) ? 2 : 0;
134 severity += (hp->h_recent >= 0) ? 4 : 0;
135 head_describe(hp, severity, cname(ano), cname(vno));
143 head_meanwhile(int val)
149 return "On the other hand";
151 return "At the same time";
160 head_describe(struct histstr *hp, int what, char *aname, char *vname)
164 if (hp->h_recent > hp->h_past / 2)
165 pr("Bad relations between %s and %s worsen!", aname, vname);
167 pr("Carnage wrought by %s on %s continues unabated!",
171 if (hp->h_recent < -16)
172 pr("%s agression against %s has lessened slightly",
175 pr("Peace talks may occur between %s & %s", aname, vname);
178 if (hp->h_recent < -16) {
180 pr(" ! WAR ! Reversal of prior %s -- %s relations",
182 else if (hp->h_recent >= -25)
183 pr("VIOLENCE ERUPTS! -- %s wages war on %s", aname, vname);
185 pr("%s wreaks havoc on %s!", aname, vname);
187 pr("Breakdown in communication between %s & %s", aname, vname);
190 pr("FLASH! %s turns on former ally, %s!", aname, vname);
193 pr("%s \"makes friends\" with %s", aname, vname);
196 if (hp->h_past >= -25)
197 pr("%s seems to have forgotten earlier disagreement with %s",
200 pr("Tensions ease as %s attacks on %s seem at an end",
204 pr("%s good deeds further growing alliance with %s", aname, vname);
207 if (hp->h_recent - hp->h_past < 12)
208 pr("Honeymoon appears to be over between %s & %s",
211 pr("Friendly relations between %s & %s have cooled",
218 * returns 9 if no scoops were found
222 head_findscoop(struct histstr (*hist)[MAXNOC], natid maxcnum,
223 natid *ano, natid *vno)
232 for (i = 1; i < maxcnum; i++) {
233 for (j = 1; j < maxcnum; j++) {
235 k = abs(hp->h_recent / 2);
241 k = abs(hp->h_recent - hp->h_past);