2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * nreport.c: File a news report. Downgrade relations if things get hostile.
30 * Known contributors to this file:
42 #include "prototypes.h"
45 nreport(natid actor, int event, natid victim, int times)
51 filereport(actor, event, victim, times);
53 * this is probably pretty expensive, but hopefully we
54 * don't fire zillions of these things off every second.
56 if (victim == 0 || (nice = rpt[event].r_good_will) >= 0)
59 * Pretty schlocky to put it here, but
60 * I guess it can't go anywhere else.
64 if (!chance((double)-nice * times / 20.0))
66 if ((np = getnatp(victim)) == 0)
68 if ((rel = getrel(np, actor)) < HOSTILE)
78 setrel(victim, actor, rel);
86 struct free *freelist;
93 fp = (struct free *)malloc(sizeof(*fp));
100 * snoop through the news articles looking
101 * for articles which have timed out. Only
102 * called when no free items left.
107 register time_t oldnewstime;
112 (void)time(&newstime);
113 oldnewstime = newstime - NEWS_PERIOD;
114 for (n = 0; getnews(n, &news); n++) {
115 if (news.nws_when < oldnewstime)
119 if (!ef_extend(EF_NEWS, 100))
134 if ((fp = freelist) == 0)
151 ncache(time_t now, int actor, int event, int victim, int times)
153 static struct newscache cache[MAXNOC][SLOTS];
154 register struct newscache *np;
160 oldtime = 0x7fffffff;
161 for (i = 0; i < SLOTS; i++) {
162 np = &cache[actor][i];
163 if (np->news.nws_when < oldtime) {
165 oldtime = np->news.nws_when;
169 if ((now - np->news.nws_when) > minutes(5))
171 if (np->news.nws_vrb == event && np->news.nws_vno == victim &&
172 np->news.nws_ntm + times <= 127) {
173 np->news.nws_ntm += times;
178 logerror("internal error; ncache oldslot < 0");
179 return &cache[actor][0];
181 np = &cache[actor][oldslot];
182 np->news.nws_ano = actor;
183 np->news.nws_vno = victim;
184 np->news.nws_when = now;
185 np->news.nws_vrb = event;
186 np->news.nws_ntm = times;
192 filereport(int actor, int event, int victim, int times)
194 struct newscache *np;
198 np = ncache(now, actor, event, victim, times);
199 ef_write(EF_NEWS, np->id, (s_char *)&np->news);