]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/head.c
Update copyright notice
[empserver] / src / lib / commands / head.c
index 6446bd6582d45332911f51e3a0cb5afc720248a9..00ce25cce9f1a1ddc2258f0027cdb843e90b2617 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
  *  ---
  *
  *  head.c: Print headlines of the Empire News
- * 
+ *
  *  Known contributors to this file:
- *     
+ *     Markus Armbruster, 2006-2013
  */
 
 #include <config.h>
 
-#include "misc.h"
-#include "player.h"
-#include "news.h"
-#include "nat.h"
-#include "file.h"
-#include "xy.h"
-#include "nsc.h"
 #include "commands.h"
+#include "news.h"
 
 struct histstr {
     int h_past;
@@ -52,14 +45,13 @@ static void head_describe(struct histstr *, int, char *, char *);
 static int head_printscoop(struct histstr (*hist)[MAXNOC], natid ano,
                           natid vno);
 static int head_findscoop(struct histstr (*hist)[MAXNOC],
-                         register natid maxcnum, natid *ano, natid *vno);
+                         natid maxcnum, natid *ano, natid *vno);
 
 int
 head(void)
 {
-    register int i;
-    register struct histstr *hp;
-    register natid maxcnum;
+    struct histstr *hp;
+    natid maxcnum;
     time_t now;
     int severity;
     int scoop;
@@ -71,11 +63,11 @@ head(void)
     natid actor;
     natid victim;
     struct nstr_item nstr;
-    int n;
+    int i, n;
 
     (void)time(&now);
     natp = getnatp(player->cnum);
-    if (player->argp[1] != 0 && *player->argp[1] != 0) {
+    if (player->argp[1] && *player->argp[1]) {
        news_per = days(atoi(player->argp[1]));
        if (news_per > days(3))
            news_per = days(3);
@@ -91,6 +83,8 @@ head(void)
     snxtitem_all(&nstr, EF_NEWS);
     maxcnum = 0;
     while (nxtitem(&nstr, &news)) {
+       if (!news.nws_vrb || CANT_HAPPEN(news.nws_vrb > N_MAX_VERB))
+           continue;
        news_age = now - news.nws_when;
        if (news_age > news_per)
            continue;
@@ -110,7 +104,7 @@ head(void)
     for (n = 0; n < 5; n++) {
        if ((scoop = head_findscoop(hist, maxcnum, &actor, &victim)) < 10)
            break;
-       severity = head_printscoop(hist, actor, victim);
+       head_printscoop(hist, actor, victim);
        hp = &hist[actor][victim];
        severity = hp->h_recent - hp->h_past;
        if (severity <= -scoop / 2 || severity >= scoop / 2) {
@@ -126,7 +120,7 @@ head(void)
 static int
 head_printscoop(struct histstr (*hist)[MAXNOC], natid ano, natid vno)
 {
-    register struct histstr *hp;
+    struct histstr *hp;
     int severity;
 
     hp = &hist[ano][vno];
@@ -143,18 +137,10 @@ head_printscoop(struct histstr (*hist)[MAXNOC], natid ano, natid vno)
 static char *
 head_meanwhile(int val)
 {
-    switch (val & 03) {
-    case 0:
-       return "Meanwhile";
-    case 1:
-       return "On the other hand";
-    case 2:
-       return "At the same time";
-    case 3:
-       return "Although";
-    }
-    /*NOTREACHED*/
-    return "";
+    static char *meanwhile[4] = {
+       "Meanwhile", "On the other hand", "At the same time", "Although"
+    };
+    return meanwhile[val % 4];
 }
 
 static void
@@ -170,7 +156,7 @@ head_describe(struct histstr *hp, int what, char *aname, char *vname)
        break;
     case 1:
        if (hp->h_recent < -16)
-           pr("%s agression against %s has lessened slightly",
+           pr("%s aggression against %s has lessened slightly",
               aname, vname);
        else
            pr("Peace talks may occur between %s & %s", aname, vname);
@@ -220,16 +206,12 @@ head_describe(struct histstr *hp, int what, char *aname, char *vname)
  * Pretty strange.
  */
 static int
-head_findscoop(struct histstr (*hist)[MAXNOC], register natid maxcnum,
+head_findscoop(struct histstr (*hist)[MAXNOC], natid maxcnum,
               natid *ano, natid *vno)
 {
-    register struct histstr *hp;
-    register int i;
-    register int j;
-    register int k;
-    int scoop;
-    natid actor;
-    natid victim;
+    struct histstr *hp;
+    int i, j, k, scoop;
+    natid actor, victim;
 
     scoop = 9;
     actor = 0;