/**************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvements 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 *
* benefiting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************
* ROM 2.4 is copyright 1993-1998 Russ Taylor *
* ROM has been brought to you by the ROM consortium *
* Russ Taylor (rtaylor@hypercube.org) *
* Gabrielle Taylor (gtaylor@hypercube.org) *
* Brian Moore (zump@rom.org) *
* By using this code, you have agreed to follow the terms of the *
* ROM license, in the file Rom24/doc/rom.license *
***************************************************************************
* 1stMUD ROM Derivative (c) 2001-2002 by Ryan Jennings *
* http://1stmud.dlmud.com/ <r-jenn@shaw.ca> *
***************************************************************************/
#include <sys/types.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "merc.h"
#include "tables.h"
#include "olc.h"
#include "lookup.h"
#include "interp.h"
const struct flag_type *flag_lookup(const char *name, const struct flag_type *f)
{
if (IS_NULLSTR(name))
return NULL;
while (f->name != NULL)
{
if (str_prefix(name, f->name) == 0)
return f;
f++;
}
return NULL;
}
CLAN_DATA *clan_lookup(const char *name)
{
CLAN_DATA *clan;
for (clan = clan_first; clan; clan = clan->next)
{
if (LOWER(name[0]) == LOWER(clan->name[0]) &&
!str_prefix(name, clan->name))
return clan;
}
return NULL;
}
int position_lookup(const char *name)
{
int pos;
for (pos = 0; position_table[pos].name != NULL; pos++)
{
if (LOWER(name[0]) == LOWER(position_table[pos].name[0]) &&
!str_prefix(name, position_table[pos].name))
return pos;
}
return -1;
}
int sex_lookup(const char *name)
{
int sex;
for (sex = 0; sex_table[sex].name != NULL; sex++)
{
if (LOWER(name[0]) == LOWER(sex_table[sex].name[0]) &&
!str_prefix(name, sex_table[sex].name))
return sex;
}
return -1;
}
int size_lookup(const char *name)
{
int size;
for (size = 0; size_table[size].name != NULL; size++)
{
if (LOWER(name[0]) == LOWER(size_table[size].name[0]) &&
!str_prefix(name, size_table[size].name))
return size;
}
return -1;
}
/* returns race number */
RACE_DATA *race_lookup(const char *name)
{
RACE_DATA *race;
for (race = race_first; race != NULL; race = race->next)
{
if (LOWER(name[0]) == LOWER(race->name[0]) &&
!str_prefix(name, race->name))
return race;
}
return NULL;
}
int item_lookup(const char *name)
{
int type;
for (type = 0; item_table[type].name != NULL; type++)
{
if (LOWER(name[0]) == LOWER(item_table[type].name[0]) &&
!str_prefix(name, item_table[type].name))
return item_table[type].type;
}
return -1;
}
int liq_lookup(const char *name)
{
int liq;
for (liq = 0; liq_table[liq].liq_name != NULL; liq++)
{
if (LOWER(name[0]) == LOWER(liq_table[liq].liq_name[0]) &&
!str_prefix(name, liq_table[liq].liq_name))
return liq;
}
return -1;
}
HELP_DATA *help_lookup(const char *keyword)
{
HELP_DATA *pHelp;
char temp[MIL], argall[MIL];
argall[0] = '\0';
while (keyword[0] != '\0')
{
keyword = one_argument(keyword, temp);
if (argall[0] != '\0')
strcat(argall, " ");
strcat(argall, temp);
}
for (pHelp = help_first; pHelp != NULL; pHelp = pHelp->next)
if (is_name(argall, pHelp->keyword))
return pHelp;
return NULL;
}
CMD_DATA *command_lookup(const char *name)
{
int hash;
CMD_DATA *pCmd;
if (IS_NULLSTR(name))
return NULL;
hash = LOWER(name[0]) % 126;
for (pCmd = command_hash[hash]; pCmd; pCmd = pCmd->next_hash)
if (!str_prefix(name, pCmd->name))
return pCmd;
return NULL;
}
DEITY_DATA *deity_lookup(const char *arg)
{
DEITY_DATA *i;
for (i = deity_first; i; i = i->next)
if (!str_prefix(arg, i->name))
return i;
return NULL;
}
int tzone_lookup(const char *arg)
{
int i;
for (i = 0; i < MAX_TZONE; i++)
{
if (!str_cmp(arg, tzone_table[i].name))
return i;
}
for (i = 0; i < MAX_TZONE; i++)
{
if (is_name(arg, tzone_table[i].zone))
return i;
}
return -1;
}