1stMUD/corefiles/
1stMUD/gods/
1stMUD/notes/
1stMUD/player/
1stMUD/win32/
1stMUD/win32/ROM/
/**************************************************************************
*  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 <string.h>
#include <stdlib.h>
#include "merc.h"
#include "olc.h"
#include "lookup.h"
#include "recycle.h"
#include "globals.h"
#include "tables.h"
#include "recycle.h"

#define DEDIT(fun)  bool fun(CHAR_DATA *ch, const char *argument)

void dedit(CHAR_DATA * ch, char *argument)
{
	if (get_trust(ch) < MAX_LEVEL - 5)
	{
		chprintln(ch, "Insuffecient security to modify deity data");
		edit_done(ch);
		return;
	}

	if (!str_cmp(argument, "done"))
	{
		edit_done(ch);
		return;
	}

	if (emptystring(argument))
	{
		dedit_show(ch, argument);
		return;
	}

	if (!process_olc_command(ch, argument, deity_olc_comm_table))
		interpret(ch, argument);
	return;
}

CH_CMD(do_dedit)
{
	DEITY_DATA *pDeity;
	char arg[MSL];

	if (IS_NPC(ch))
		return;

	pDeity = deity_first;

	argument = one_argument(argument, arg);

	if (IS_NULLSTR(arg))
	{
		chprintln(ch, "Syntax: dedit create\n\r        dedit <deity name>");
		return;
	}

	pDeity = deity_lookup(arg);

	if (!pDeity || IS_NULLSTR(pDeity->name))
	{
		chprintln(ch, "That deity does not exist.");
		return;
	}
	else if (!str_cmp(arg, "save"))
	{
		save_deities();
		chprintln(ch, "Deity database saved.");
		return;
	}
	else if (!str_cmp(arg, "create"))
	{
		if (ch->pcdata->security < 9)
		{
			chprintln(ch,
					  "dEdit : Insuffecient security to create new deities.");
			return;
		}

		dedit_create(ch, argument);

		return;
	}

	edit_start(ch, pDeity, ED_DEITY);
	return;
}

DEDIT(dedit_show)
{
	DEITY_DATA *pDeity;

	EDIT_DEITY(ch, pDeity);

	chprintln(ch, draw_line(NULL, 0));
	chprintlnf(ch, "Name     : %s", pDeity->name);
	chprintlnf(ch, "Desc     : %s", pDeity->desc);
	chprintlnf(ch, "Skill    : %s", IS_STRSET(pDeity->skillname));
	chprintln(ch, draw_line(NULL, 0));
	return TRUE;
}

DEDIT(dedit_list)
{
	DEITY_DATA *i;
	bool found = FALSE;

	for (i = deity_first; i; i = i->next)
	{
		found = TRUE;
		chprintlnf(ch, "\t%-12s : %s", i->name, IS_STRSET(i->desc));
	}
	if (!found)
		chprintln(ch, "No deities.");
	return TRUE;
}

DEDIT(dedit_create)
{
	DEITY_DATA *pDeity;
	char buf[MIL];

	if (!IS_NULLSTR(argument) && deity_lookup(argument) == NULL)
		sprintf(buf, argument);
	else
		sprintf(buf, "New Deity%d", maxDeity + 1);

	pDeity = new_deity();
	replace_string(pDeity->name, buf);
	LINK(pDeity, deity_first, deity_last, next, prev);
	edit_start(ch, pDeity, ED_DEITY);
	chprintln(ch, "Deity created.");
	return TRUE;
}

DEDIT(dedit_delete)
{
	DEITY_DATA *pDeity;

	EDIT_DEITY(ch, pDeity);

	if (str_cmp(argument, "confirm"))
	{
		chprintln
			(ch,
			 "Typing 'delete confirm' will permanetely remove this command!");
		return FALSE;
	}
	else
	{
		UNLINK(pDeity, deity_first, deity_last, next, prev);
		free_deity(pDeity);
		pDeity = deity_first;
		ch->desc->pEdit = (void *) pDeity;

		chprintln(ch, "Deity deleted.");
	}

	return TRUE;
}