trivia.c
demise/src/trivia.c · 8.6 KB
From the archive dodbackup-final.tar.gz
Download the archive « Back to the archive contents
/***************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* In order to use any part of this Merc Diku Mud, you must comply with *
* both the original Diku license in 'license.doc' as well the Merc *
* license in 'license.txt'. In particular, you may not remove either of *
* these copyright notices. *
* *
* Much time and thought has gone into this software and you are *
* benefitting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************/
/***************************************************************************
* God Wars Mud improvements copyright (C) 1994, 1995, 1996 by Richard *
* Woolcock. This mud is NOT to be copied in whole or in part, or to be *
* run without the permission of Richard Woolcock. Nobody else has *
* permission to authorise the use of this code. *
***************************************************************************/
#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"
void
do_trivia (CHAR_DATA * ch, char *argument)
{
char buf[MSL];
char arg[MIL];
char arg2[MIL];
char arg3[MIL];
char arg4[MIL];
extern bool trivia;
extern int tqps;
extern int ttimer;
extern char question[100];
extern char awnser[100];
int time, qps;
argument = one_argument (argument, arg);
argument = one_argument (argument, arg2);
argument = one_argument (argument, arg3);
argument = one_argument (argument, arg4);
if (IS_NPC (ch))
return;
if (trivia)
{
send_to_char ("There's already a trivia running...\n\r", ch);
return;
}
if (arg[0] == '\0' || arg2[0] == '\0')
{
send_to_char
("Syntax: trivia <question> <answer> <creditreward> <fifteen/ten/five/one>.\n\r",
ch);
return;
}
qps = atoi (arg3);
if (qps < 1000 || qps > 10000)
{
send_to_char ("Keep it something between 1000 and 10000 Credits...\n\r",
ch);
return;
}
if (!str_cmp (arg, "") && !str_cmp (arg2, ""))
{
send_to_char ("Both question AND answer have to be given...\n\r", ch);
return;
}
if (!str_cmp (arg4, ""))
{
send_to_char ("Time must be given!\n\r", ch);
return;
}
if (!str_cmp (arg4, "fifteen"))
time = 15;
else if (!str_cmp (arg4, "ten"))
time = 10;
else if (!str_cmp (arg4, "five"))
time = 5;
else if (!str_cmp (arg4, "three"))
time = 3;
else if (!str_cmp (arg4, "one"))
time = 1;
else
{
stc ("fifteen, ten, five or one, (in text not number).\n\r", ch);
return;
}
sprintf (buf, "%s", capitalize (arg));
if (strlen (buf) > 100)
{
stc ("Too long question. Do NOT go over 100 characters!\n\r", ch);
return;
}
strcpy (question, buf);
sprintf (buf, "%s", capitalize (arg2));
if (strlen (buf) > 100)
{
stc ("Too long answer. Do NOT go over 100 characters!\n\r", ch);
return;
}
strcpy (awnser, buf);
tqps = qps;
ttimer = time;
trivia = TRUE;
sprintf (buf, "#7For %d credits...", tqps);
triviainfo (buf);
sprintf (buf, "#7%s", question);
triviainfo (buf);
if (ttimer != 0)
{
sprintf (buf, "#7You have %d minutes to answer the question.\n\r",
time);
triviainfo (buf);
}
return;
}
void
update_triviatime ()
{
extern bool trivia;
extern int tqps;
extern int ttimer;
extern char question[100];
extern char awnser[100];
char buf[MSL];
if (!trivia)
return;
ttimer--;
switch (ttimer)
{
case 25:
triviainfo ("#725 minutes left to answer the question...\n\r");
triviainfo ("#7For more information, type 'trivia'.\n\r");
break;
case 20:
triviainfo ("#720 minutes left to answer the question...\n\r");
triviainfo ("#7For more information, type 'trivia'.\n\r");
break;
case 15:
triviainfo ("#715 minutes left to answer the question...\n\r");
triviainfo ("#7For more information, type 'trivia'.\n\r");
break;
case 10:
triviainfo ("#710 minutes left to answer the question...\n\r");
triviainfo ("#7For more information, type 'trivia'.\n\r");
break;
case 5:
triviainfo ("#75 minutes left to answer the question...\n\r");
triviainfo ("#7For more information, type 'trivia'.\n\r");
break;
case 1:
triviainfo ("#71 minute left to answer the question...\n\r");
triviainfo ("#7For more information, type 'trivia'.\n\r");
break;
case 0:
triviainfo ("#7Nobody gave the right answer. Triva ended.\n\r");
sprintf (buf, "#7The right answer was: '%s'.\n\r", awnser);
triviainfo (buf);
clear_trivia ();
break;
}
}
void
do_ptrivia (CHAR_DATA * ch, char *argument)
{
char buf[MSL];
extern bool trivia;
extern int tqps;
extern int ttimer;
extern char question[100];
extern char awnser[100];
if (IS_NPC (ch))
return;
if (argument[0] == '\0')
{
if (trivia)
{
sprintf (buf, "#7The question is: '%s'.\n\r", question);
send_to_char (buf, ch);
sprintf (buf, "#7The reward is: %d Credits.\n\r", tqps);
send_to_char (buf, ch);
if (ttimer != 0)
{
sprintf (buf, "#7Time left to answer: '%d' minute(s)\n\r",
ttimer);
send_to_char (buf, ch);
}
send_to_char ("To answer the question, use 'tanswer'.\n\r", ch);
return;
}
send_to_char ("There's no trivia going on!\n\r", ch);
return;
}
return;
}
void
do_tawnser (CHAR_DATA * ch, char *argument)
{
char buf[MSL];
extern bool trivia;
extern int tqps;
extern int ttimer;
extern char question[100];
extern char awnser[100];
if (IS_NPC (ch))
return;
if (ch->in_room->vnum == 28 && IS_XXX (ch, XXX_WRAITHQUEST))
{
if (argument[0] == '\0')
{
send_to_char ("What is your answer?\n\r", ch);
return;
}
if (!str_cmp (argument, "ring"))
{
stc
("The sphinx nods his head.\n\r#7The Sphinx says '#PThat is correct#7'.#n\n\r",
ch);
do_clearclass (ch, "self");
do_pset (ch, "self class wraith");
ch->level = 3;
ch->trust = 3;
return;
}
}
if (!trivia)
{
send_to_char ("There's is no trivia running...\n\r", ch);
return;
}
if (ch->triviatimer > 0)
{
sprintf (buf, "You can't answer for another %d seconds.\n\r",
ch->triviatimer);
stc (buf, ch);
return;
}
if (!has_credit (ch))
return;
if (argument[0] == '\0')
{
send_to_char ("What is your answer?\n\r", ch);
return;
}
if (str_cmp (argument, awnser))
{
send_to_char ("Im sorry, thats the wrong answer!\n\r", ch);
sprintf (buf, "#7%s gave the wrong answer %s.\n\r", ch->name, argument);
ch->triviatimer = 6;
triviainfo (buf);
return;
}
sprintf (buf,
"#7%s has won the trivia, and recieves a reward of %d credits.\n\r",
ch->name, tqps);
triviainfo (buf);
sprintf (buf, "#7The right answer was: '%s'.\n\r", awnser);
triviainfo (buf);
ch->pcdata->quest += tqps;
clear_trivia ();
return;
}
void
clear_trivia ()
{
extern bool trivia;
extern int tqps;
extern int ttimer;
extern char question[100];
extern char awnser[100];
tqps = 0;
ttimer = 0;
strcpy (awnser, "");
strcpy (question, "");
trivia = FALSE;
}
void
do_resettrivia (CHAR_DATA * ch, char *argument)
{
extern bool trivia;
char buf[MSL];
if (IS_NPC (ch))
return;
if (!trivia)
{
stc ("There is no trivia running.\n\r", ch);
return;
}
sprintf (buf, "%s has resets the trivia.\n\r", ch);
triviainfo (buf);
clear_trivia ();
return;
}
void
triviainfo (char *argument)
{
DESCRIPTOR_DATA *d;
if (argument[0] == '\0')
return;
for (d = descriptor_list; d != NULL; d = d->next)
{
if (d->connected == CON_PLAYING)
{
send_to_char ("#R[#sT#sr#si#sv#si#sa#R]->#n ", d->character);
send_to_char (argument, d->character);
send_to_char ("\n\r", d->character);
}
}
}