2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, 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] && *player->argp[1]) {
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 if (!news.nws_vrb || CANT_HAPPEN(news.nws_vrb > N_MAX_VERB))
89 news_age = now - news.nws_when;
90 if (news_age > news_per)
92 if (news.nws_ano == news.nws_vno)
94 if ((i = rpt[(int)news.nws_vrb].r_good_will) == 0)
96 if (news_age > news_per / 2)
97 hist[news.nws_ano][news.nws_vno].h_past += i;
99 hist[news.nws_ano][news.nws_vno].h_recent += i;
100 if (maxcnum < news.nws_ano)
101 maxcnum = news.nws_ano;
102 if (maxcnum < news.nws_vno)
103 maxcnum = news.nws_vno;
105 for (n = 0; n < 5; n++) {
106 if ((scoop = head_findscoop(hist, maxcnum, &actor, &victim)) < 10)
108 head_printscoop(hist, actor, victim);
109 hp = &hist[actor][victim];
110 severity = hp->h_recent - hp->h_past;
111 if (severity <= -scoop / 2 || severity >= scoop / 2) {
112 pr("\t%s\n", head_meanwhile(severity));
113 (void)head_printscoop(hist, victim, actor);
117 pr("\nRelative calm prevails.\n");
122 head_printscoop(struct histstr (*hist)[MAXNOC], natid ano, natid vno)
127 hp = &hist[ano][vno];
128 severity = abs(hp->h_past) > abs(hp->h_recent) ? 1 : 0;
129 severity += (hp->h_past >= 0) ? 2 : 0;
130 severity += (hp->h_recent >= 0) ? 4 : 0;
131 head_describe(hp, severity, cname(ano), cname(vno));
139 head_meanwhile(int val)
145 return "On the other hand";
147 return "At the same time";
156 head_describe(struct histstr *hp, int what, char *aname, char *vname)
160 if (hp->h_recent > hp->h_past / 2)
161 pr("Bad relations between %s and %s worsen!", aname, vname);
163 pr("Carnage wrought by %s on %s continues unabated!",
167 if (hp->h_recent < -16)
168 pr("%s agression against %s has lessened slightly",
171 pr("Peace talks may occur between %s & %s", aname, vname);
174 if (hp->h_recent < -16) {
176 pr(" ! WAR ! Reversal of prior %s -- %s relations",
178 else if (hp->h_recent >= -25)
179 pr("VIOLENCE ERUPTS! -- %s wages war on %s", aname, vname);
181 pr("%s wreaks havoc on %s!", aname, vname);
183 pr("Breakdown in communication between %s & %s", aname, vname);
186 pr("FLASH! %s turns on former ally, %s!", aname, vname);
189 pr("%s \"makes friends\" with %s", aname, vname);
192 if (hp->h_past >= -25)
193 pr("%s seems to have forgotten earlier disagreement with %s",
196 pr("Tensions ease as %s attacks on %s seem at an end",
200 pr("%s good deeds further growing alliance with %s", aname, vname);
203 if (hp->h_recent - hp->h_past < 12)
204 pr("Honeymoon appears to be over between %s & %s",
207 pr("Friendly relations between %s & %s have cooled",
214 * returns 9 if no scoops were found
218 head_findscoop(struct histstr (*hist)[MAXNOC], natid maxcnum,
219 natid *ano, natid *vno)
228 for (i = 1; i < maxcnum; i++) {
229 for (j = 1; j < maxcnum; j++) {
231 k = abs(hp->h_recent / 2);
237 k = abs(hp->h_recent - hp->h_past);