head     1.1;
access   ;
symbols  KSUrelease-Aug93:1.1;
locks    ; strict;
comment  @ * @;


1.1
date     93.07.01.08.12.45;  author bill;  state Exp;
branches ;
next     ;


desc
@@


1.1
log
@Start
@
text
@#ifndef lint
static char *RCSid = "$Header: news.c,v 1.1 89/12/14 08:20:17 jay Exp $";
#endif /* not lint */

/*
 * news
 *
 * Show the current empire news
 *
 * from PSL Empire, 1985
 */

#include "misc.h"
#include "nat.h"
#include "news.h"
#include "file.h"
#include "xy.h"
#include "nsc.h"
#ifdef LOTTERY
#include "lotto.h"
#endif

static	preport();

news()
{
    extern	char *argp[];
    struct	natstr *natp;
    long	now;
    int	page,i,firstpage,lastpage;
    time_t	delta;
    long	then;
    struct	nwsstr nws;
    struct	nstr_item nstr;
    
    (void) head();
    (void) time(&now);
    natp = getnatp(cnum);
    
    firstpage = 1;
#ifdef LOTTERY
    lastpage = 4;
#else
    lastpage = 3;
#endif
    delta = natp->nat_newstim;
    for (i=1; argp[i] && *argp[i]; i++) {
	if (*argp[i]=='p' || *argp[i]=='P')
	    firstpage = lastpage = atoi(argp[i]+1);
	else {
	    then = days(atoi(argp[i]));
	    delta = now - then;
	}
    }
    
    NAT_SET(nat_newstim, cnum, now);
    if (delta < now - days(3))
	delta = now - days(3);
    snxtitem_all(&nstr, EF_NEWS);
    pr(fmt("\nThe details of Empire news since %s", ctime(&delta)));
    for (page = firstpage; page <= lastpage; page++) {
	pr(fmt("\n\t === page %d ===\n", page));
	switch (page) {
	case 1:
	case 2:
	case 3:
	    while (nxtitem(&nstr, (char *)&nws)) {
 		if (rpt[nws.nws_vrb].r_newspage != page) continue;
		if (nws.nws_when < delta) continue;
		if (nws.nws_ntm == 0) nws.nws_ntm = 1;
		preport(&nws);
	    }
	    snxtitem_rewind(&nstr);
	    break;
#ifdef LOTTERY
	case 4:
	    if (i=openlotto()) {
		closelotto();
		pr(fmt("PogoLotto jackpot now $%d\n",i));
	    }
	    break;
#endif	
	default:
	    break;
	}
    }
    return 0;
}

static
    preport(np)
register struct nwsstr *np;
{
    register char *cp;
    register int i;
    char	buf[255];
    char	*ptr;
    
    cp = buf;
    *cp = 0;
    cp = copy(fmt("%-16.16s  ", ctime(&np->nws_when)), cp);
    ptr = numstr(np->nws_ntm);
    /*
     * vary the order of the printing of "%d times "
     */
    if ((random() & 3) == 0 && np->nws_ntm > 1) {
	cp = copy(fmt("%s times ", ptr), cp);
	np->nws_ntm = 1;
    }
    cp = copy(cname(np->nws_ano), cp);
    *cp++ = ' ';
    if (np->nws_vrb < 1 || np->nws_vrb > N_MAX_VERB)
	np->nws_vrb = 0;
    cp = copy(fmt(rpt[np->nws_vrb].r_newstory[random() % NUM_RPTS],
		  cname(np->nws_vno)), cp);
    if (np->nws_ntm != 1)
	cp = copy(fmt(" %s times", ptr), cp);
    *cp = 0;
    if (*buf >= 'a' && *buf <= 'z')
	*buf += 'A' - 'a';
    if (cp - buf > 80) {
	for (i=80; --i > 60; )
	    if (buf[i] == ' ') break;
	buf[i] = '\0';
	pr(fmt("%s\n\t\t  %s\n", buf, &buf[i+1]));
    } else {
	pr(fmt("%s\n", buf));
    }
    np->nws_ntm = 0;
    return;
}
@
