Beispiel #1
0
/*
*  int paytaxes(x)         Function to pay taxes if any are due
*
*  Enter with the amount (in gp) to pay on the taxes.
*  Returns amount actually paid.
*/
int
paytaxes (int x)
{
  int i;
  int amt;

  if (x < 0)
    return (0L);
  if (readboard () < 0)
    return (0L);
  for (i = 0; i < SCORESIZE; i++)
    if (strcmp (winr[i].who, logname) == 0)	/* look for players winning entry */
      if (winr[i].score > 0)	/* search for a winning entry for the player */
	{
	  amt = winr[i].taxes;
	  if (x < amt)
	    amt = x;		/* don't overpay taxes (Ughhhhh) */
	  winr[i].taxes -= amt;
	  outstanding_taxes -= amt;
	  if (writeboard () < 0)
	    return (0);
	  return (amt);
	}
  return (0L);			/* couldn't find user on winning scoreboard */
}
Beispiel #2
0
/*
 * long paytaxes(x)		 Function to pay taxes if any are due
 *
 * Enter with the amount (in gp) to pay on the taxes.
 * Returns amount actually paid.
 */
long
paytaxes(long x)
{
	int    i;
	long   amt;
	if (x < 0)
		return (0L);
	if (readboard() < 0)
		return (0L);
	for (i = 0; i < SCORESIZE; i++)
		if (winr[i].suid == userid)	/* look for players winning
						 * entry */
			if (winr[i].score > 0) {	/* search for a winning
							 * entry for the player */
				amt = winr[i].taxes;
				if (x < amt)
					amt = x;	/* don't overpay taxes
							 * (Ughhhhh) */
				winr[i].taxes -= amt;
				outstanding_taxes -= amt;
				set_score_output();
				if (writeboard() < 0)
					return (0);
				return (amt);
			}
	return (0L);		/* couldn't find user on winning scoreboard */
}
Beispiel #3
0
/*
 *	makeboard() 		Function to create a new scoreboard (wipe out old one)
 *
 *	returns -1 if unable to write the scoreboard, returns 0 if all is OK
 */
makeboard()
	{
	register int i;
	for (i=0; i<SCORESIZE; i++)
		{
		winr[i].taxes = winr[i].score = sco[i].score = 0;
		winr[i].order = sco[i].order = i;
		}
	if (writeboard()) return(-1);
	chmod(scorefile,0660);
	return(0);
	}
Beispiel #4
0
/*
*  makeboard()         Function to create a new scoreboard (wipe out old one)
*
*  returns -1 if unable to write the scoreboard, returns 0 if all is OK
*/
int
makeboard (void)
{
  int i;

  for (i = 0; i < SCORESIZE; i++)
    {
      winr[i].taxes = winr[i].score = sco[i].score = 0;
      winr[i].order = sco[i].order = i;
    }

  if (writeboard ())
    return (-1);
  _chmod (scorefile, 0666);
  return (0);
}
Beispiel #5
0
/*
 * makeboard() 		Function to create a new scoreboard (wipe out old one)
 *
 * returns -1 if unable to write the scoreboard, returns 0 if all is OK
 */
int
makeboard(void)
{
	int    i;
	set_score_output();
	for (i = 0; i < SCORESIZE; i++) {
		winr[i].taxes = winr[i].score = sco[i].score = 0;
		winr[i].order = sco[i].order = i;
	}
	if (writeboard())
		return (-1);
	if (gid != egid)
		setegid(egid);
	chmod(scorefile, 0660);
	if (gid != egid)
		setegid(gid);
	return (0);
}
Beispiel #6
0
void
checkmail (void)
{
  int i;
  int gold, taxes;

  if (readboard () < 0)
    return;			/* can't find scoreboard */
  for (i = 0; i < SCORESIZE; i++)	/* search through winners scoreboard */
    if (strcmp (winr[i].who, logname) == 0 && winr[i].score > 0
	&& winr[i].hasmail)
      {
	winr[i].hasmail = 0;
	gold = taxes = winr[i].taxes;
	writeboard ();

	/* Intuit the amount of gold -- should have changed
	 * the score file, but ...  TAXRATE is an fraction.
	 */
	while ((gold * TAXRATE) < taxes)
	  gold += taxes;
	readmail (gold);
      }
}
Beispiel #7
0
void
died(int x)
{
	int    f, win;
	char            ch;
	const char     *mod;
	time_t          zzz;
	if (c[LIFEPROT] > 0) {	/* if life protection */
		switch ((x > 0) ? x : -x) {
		case 256:
		case 257:
		case 262:
		case 263:
		case 265:
		case 266:
		case 267:
		case 268:
		case 269:
		case 271:
		case 282:
		case 284:
		case 285:
		case 300:
			goto invalid;	/* can't be saved */
		};
		--c[LIFEPROT];
		c[HP] = 1;
		--c[CONSTITUTION];
		cursors();
		lprcat("\nYou feel wiiieeeeerrrrrd all over! ");
		emit_beep();
		lflush();
		sleep(4);
		return;		/* only case where died() returns */
	}
invalid:
	clearvt100();
	lflush();
	f = 0;
	if (ckpflag)
		unlink(ckpfile);/* remove checkpoint file if used */
	if (x < 0) {
		f++;
		x = -x;
	}			/* if we are not to display the scores */
	if ((x == 300) || (x == 257))
		exit(0);		/* for quick exit or saved game */
	if (x == 263)
		win = 1;
	else
		win = 0;
	c[GOLD] += c[BANKACCOUNT];
	c[BANKACCOUNT] = 0;
	/* now enter the player at the end of the scoreboard */
	newscore(c[GOLD], logname, x, win);
	diedsub(x);		/* print out the score line */
	lflush();

	set_score_output();
	if ((wizard == 0) && (c[GOLD] > 0)) {	/* wizards can't score		 */
#ifndef NOLOG
		if (gid != egid)
			setegid(egid);
		if (lappend(logfile) < 0) {	/* append to file */
			if (lcreat(logfile) < 0) {	/* and can't create new
							 * log file */
				lcreat((char *) 0);
				lprcat("\nCan't open record file:  I can't post your score.\n");
				sncbr();
				resetscroll();
				lflush();
				exit(0);
			}
			if (gid != egid)
				setegid(egid);
			chmod(logfile, 0660);
			if (gid != egid)
				setegid(gid);
		}
		if (gid != egid)
			setegid(gid);
		strcpy(logg.who, loginname);
		logg.score = c[GOLD];
		logg.diff = c[HARDGAME];
		if (x < 256) {
			ch = *monster[x].name;
			if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
				mod = "an";
			else
				mod = "a";
			snprintf(logg.what, sizeof(logg.what),
			    "killed by %s %s", mod, monster[x].name);
		} else
			snprintf(logg.what, sizeof(logg.what),
			    "%s", whydead[x - 256]);
		logg.cavelev = level;
		time(&zzz);	/* get CPU time -- write out score info */
		logg.diedtime = zzz;
#ifdef EXTRA
		times(&cputime);/* get CPU time -- write out score info */
		logg.cputime = i = (cputime.tms_utime + cputime.tms_stime) / 60 + c[CPUTIME];
		logg.lev = c[LEVEL];
		logg.ac = c[AC];
		logg.hpmax = c[HPMAX];
		logg.hp = c[HP];
		logg.elapsedtime = (zzz - initialtime + 59) / 60;
		logg.usage = (10000 * i) / (zzz - initialtime);
		logg.bytin = c[BYTESIN];
		logg.bytout = c[BYTESOUT];
		logg.moves = c[MOVESMADE];
		logg.spused = c[SPELLSCAST];
		logg.killed = c[MONSTKILLED];
#endif
		lwrite((char *) &logg, sizeof(struct log_fmt));
		lwclose();
#endif	/* NOLOG */

		/*
		 * now for the scoreboard maintenance -- not for a suspended
		 * game
		 */
		if (x != 257) {
			if (sortboard()) {
				set_score_output();
				scorerror = writeboard();
			}
		}
	}
	if ((x == 256) || (x == 257) || (f != 0))
		exit(0);
	if (scorerror == 0)
		showscores();	/* if we updated the scoreboard */
	if (x == 263)
		mailbill();
	exit(0);
}
Beispiel #8
0
void
died (int x)
{
  int f, win;
  /*char ch, *mod;
     time_t zzz; */

  if (cdesc[LIFEPROT] > 0)	/* if life protection */
    {
      switch ((x > 0) ? x : -x)
	{
	case 256:
	case 257:
	case 262:
	case 263:
	case 265:
	case 266:
	case 267:
	case 268:
	case 269:
	case 271:
	case 282:
	case 284:
	case 285:
	case 300:
	  goto invalid;		/* can't be saved */
	};
      --cdesc[LIFEPROT];
      cdesc[HP] = 1;
      --cdesc[CONSTITUTION];
      cursors ();
      lprcat ("\nYou feel wiiieeeeerrrrrd all over! ");
      lflush ();
      nap (NAPTIME);
      return;			/* only case where died() returns */
    }

  cursors ();
  lprcat ("\nPress any key to continue. ");
  ttgetch ();

invalid:
  /*clearvt100(); */
  lflush ();
  f = 0;

  /* if we are not to display the scores */
  if (x < 0)
    {
      f++;
      x = -x;
    }

  /* for quick exit or saved game */
  if ((x == 300) || (x == 257))
    {
      clearvt100 ();
      exit (EXIT_SUCCESS);
    }

  if (x == 263)
    win = 1;
  else
    win = 0;

  cdesc[GOLD] += cdesc[BANKACCOUNT];
  cdesc[BANKACCOUNT] = 0;

  /*  now enter the player at the end of the scoreboard */
  newscore (cdesc[GOLD], logname, x, win);
  diedsub (x);			/* print out the score line */
  lflush ();

  set_score_output ();
  if ((wizard == 0) && (cdesc[GOLD] > 0))	/*  wizards can't score     */
    {
      /*if (lappend(logfile)<0)
         {
         if (lcreat(logfile)<0) {
         lcreat((char*)0);
         lprcat("\nCan't open record file:  I can't post your score.\n");
         sncbr();
         resetscroll();
         lflush();
         clearvt100();
         exit(EXIT_SUCCESS);
         }
         _chmod(logfile,0666);
         }
         strcpy(logg.who,logname);
         logg.score = cdesc[GOLD];  
         logg.diff = cdesc[HARDGAME];
         if (x < 256) {
         ch = *monster[x].name;
         if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')
         mod="an";
         else
         mod="a";
         sprintf(logg.what,"killed by %s %s",mod,monster[x].name);
         }
         else sprintf(logg.what,"%s",whydead[x - 256]);
         logg.cavelev=level;
         time(&zzz);
         logg.diedtime=zzz;
         #ifdef EXTRA
         logg.lev=cdesc[LEVEL];          logg.ac=cdesc[AC];
         logg.hpmax=cdesc[HPMAX];        logg.hp=cdesc[HP];
         logg.elapsedtime=(zzz-initialtime+59)/60;
         logg.usage=(10000*i)/(zzz-initialtime);
         logg.bytin=cdesc[BYTESIN];      logg.bytout=cdesc[BYTESOUT];
         logg.moves=cdesc[MOVESMADE];    logg.spused=cdesc[SPELLSCAST];
         logg.killed=cdesc[MONSTKILLED];
         #endif
         lwrite((char*)&logg,sizeof(struct log_fmt));
         lwclose(); */

      /*  now for the scoreboard maintenance -- not for a suspended game  */
      if (x != 257)
	{
	  if (sortboard ())
	    scorerror = writeboard ();
	}
    }
  if ((x == 256) || (x == 257) || (f != 0))
    {
      clearvt100 ();
      exit (EXIT_SUCCESS);
    }
  if (scorerror == 0)
    {
      lflush ();
      clear ();
      resetscroll ();
      showscores ();		/* if we updated the scoreboard */
      cursors ();
      lprcat ("\nPress any key to exit. ");
      scbr ();
      ttgetch ();
    }
  clearvt100 ();
  exit (EXIT_SUCCESS);
}