This repository has been archived on 2025-02-12. You can view files and clone it, but cannot push or open issues or pull requests.
NeoStats-gameserv/hilo.c

94 lines
2.8 KiB
C
Raw Permalink Normal View History

/* GamesServ - Small Games Service - NeoStats Addon Module
2006-01-26 15:33:00 +00:00
** Copyright (c) 2006 Justin Hammond, Mark Hetherington, DeadNotBuried
**
** This program 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
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** 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
**
** GamesServ CVS Identification
** $Id$
*/
#include "neostats.h" /* Required for bot support */
#include "gamesserv.h"
2005-10-18 22:13:38 +00:00
static void stophilo(char *nic, int hlg);
static int num_low;
static int num_high;
static int num;
2005-10-18 22:13:38 +00:00
/*
* HiLO Timer Finished
*/
int timerupstophilo(void *userptr) {
stophilo( "", 0);
return NS_SUCCESS;
}
/*
* Start HiLo Game
*/
2005-10-13 22:39:49 +00:00
int starthilo(const CmdParams *cmdparams) {
if (CheckGameStart(cmdparams->source, cmdparams->av[0], GS_GAME_CHANNEL_HILO, 120, NS_FALSE, NS_TRUE) != NS_SUCCESS) {
2005-03-31 02:33:10 +00:00
return NS_SUCCESS;
}
2005-03-31 02:33:10 +00:00
num_low = (rand() % 999000);
num = (num_low + (rand() % 999) + 1);
num_high = (num_low + 1000);
2005-05-26 02:29:33 +00:00
irc_chanprivmsg (gs_bot, gameroom[GS_GAME_CHANNEL_HILO], "\0037A game of HiLo has been started by %s. Can you guess the number between %d and %d.", cmdparams->source->name, num_low, num_high);
2005-08-09 12:17:31 +00:00
AddTimer (TIMER_TYPE_COUNTDOWN, timerupstophilo, "hilocountdown", countdowntime[GS_GAME_CHANNEL_HILO], NULL);
return NS_SUCCESS;
}
/*
* Guess Number
*/
2005-10-13 22:39:49 +00:00
int guesshilo(const CmdParams *cmdparams) {
int hlg;
2005-05-26 02:29:33 +00:00
if (gamestatus[GS_GAME_CHANNEL_HILO] == GS_GAME_CHANNEL_PLAYING) {
hlg = atoi(cmdparams->av[0]);
if (hlg == num) {
stophilo(cmdparams->source->name, hlg);
return NS_SUCCESS;
}
if (hlg > num_low && hlg < num_high) {
if (hlg < num) {
num_low = hlg;
} else {
num_high = hlg;
}
2005-05-26 02:29:33 +00:00
irc_chanprivmsg (gs_bot, gameroom[GS_GAME_CHANNEL_HILO], "\0037%s You are a bit closer with %d , number is between %d and %d.", cmdparams->source->name, hlg, num_low, num_high);
return NS_SUCCESS;
}
}
return NS_SUCCESS;
}
/*
* Stop HiLo Game
*/
2005-10-18 22:13:38 +00:00
static void stophilo(char *nic, int hlg) {
if (!hlg) {
2005-05-26 02:29:33 +00:00
irc_chanprivmsg (gs_bot, gameroom[GS_GAME_CHANNEL_HILO], "\0037Times Up, it looks like your all Losers :)");
} else {
2005-05-26 02:29:33 +00:00
irc_chanprivmsg (gs_bot, gameroom[GS_GAME_CHANNEL_HILO], "\0037%s is correct with %d and wins, the rest of you are just Losers :)", nic, hlg);
DelTimer ("hilocountdown");
}
2005-05-26 02:29:33 +00:00
CheckPartGameChannel(GS_GAME_CHANNEL_HILO);
}