clan.c

Cedit/clan.c · 15.5 KB

From the archive Cedit.zip

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.                                                  *
 ***************************************************************************/

/***************************************************************************
*	ROM 2.4 is copyright 1993-1996 Russ Taylor		           *
*	ROM has been brought to you by the ROM consortium		   *
*	    Russ Taylor (rtaylor@efn.org)				   *
*	    Gabrielle Taylor						   *
*	    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			   *
***************************************************************************/

/***************************************************************************
*       This file is for clan related commands.  Included here is:         *
*                 The JOIN command.                                        *
*                 The immortal CLEADER command.                            *
*                 The clan leader ACCEPT command.                          *
*                 The clan leader LONER command.                           *
*       Clans can be found in the clan table in tables.c                   *
*                             -Blizzard (blizzard_imp@hotmail.com)         *
***************************************************************************/

/***************************************************************************
*    Highly Modified clan system modded by Bojack of Dragonball Arena.	   *
*	Added to this file is:					   	   *
*		top_clan						   *
*		bit names						   *
*		loading clans						   *
*		is_clan							   *
*		is_same_clan						   *
*		clan_lookup						   *
*		player_rank						   *
*		player_clan						   *
*	Nothing else was modified, I purposely made it around the	   *
*	clan system written by Blizzard.				   *
***************************************************************************/

#if defined(macintosh)
#include <types.h>
#include <time.h>
#else
#include <sys/types.h>
#include <sys/time.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "merc.h"

#include "db.h" // For top_clan and added into do_memory 

int top_clan;

char *clan_bit_name( int clan_flags )
{
    static char buf[512];
  
    buf[0] = '\0';
    if ( clan_flags & CLAN_INDEPENDENT	) strcat( buf, " independent");
    if ( clan_flags & CLAN_CHANGED	) strcat( buf, " changed");
    if ( clan_flags & CLAN_DELETED	) strcat( buf, " deleted");
    if ( clan_flags & CLAN_IMMORTAL	) strcat( buf, " immortal");
  
    return ( buf[0] != '\0' ) ? buf+1 : "none";
}

void load_clans(void)
{
    FILE *fp;
    char *string;
    int count = 0;
    int i;
    bool fMatch = FALSE;

    for (i = 0; i < (1 + top_clan); i++) //MAX_CLAN; i++)
    {
	clan_table[i].name = "";
      	clan_table[i].who_name = "";
      	clan_table[i].leader = "";
      	clan_table[i].c_rank[0].rankname = "";
	clan_table[i].flags = 0;
    }

    if (!(fp = fopen(DATA_FILE, "r")) )
    {
	log_string("Error: guild.dat file not found!");
	exit(1);
    }
    
    for (;;)
    {
	string = feof(fp) ? "End" : fread_word(fp);

	if (!str_cmp(string, "End"))
	    break;

	switch (UPPER(string[0]))
  	{
          case 'C':
	      top_clan++;
              count++;
              clan_table[count].name = fread_string(fp);
              fMatch = TRUE;
              break;

          case 'F':
              clan_table[count].flags  = fread_flag( fp );
              fMatch = TRUE;
              break;

          case 'L':
	      clan_table[count].leader = fread_string(fp);
	      fMatch = TRUE;
	      break;
	          
	  case 'R':
	      if (!str_cmp(string, "CRank") || !str_cmp(string, "Rank"))
	      {
		  i = fread_number(fp);
		  clan_table[count].c_rank[i].rankname = fread_string(fp);
		  fMatch = TRUE;
	      }
	      break;

	  case 'W':
	      clan_table[count].who_name = fread_string(fp);
	      fMatch = TRUE;
	      break;
	  }			/* end of switch */
    }				/* end of while (!feof) */

    if (!fMatch)
    {
	logstr(LOG_BUG, "Fread_clans: no match.", 0);
	fread_to_eol(fp);
    }
    fclose(fp);
    return;
}

bool is_clan(CHAR_DATA * ch)
{
    return ch->clan;
} 

bool is_same_clan(CHAR_DATA * ch, CHAR_DATA * victim)
{
    if (IS_SET(clan_table[ch->clan].flags, CLAN_INDEPENDENT))
	return FALSE;
    else
	return (ch->clan == victim->clan);
}

int clan_lookup(const char *name)
{
    int clan;

    for (clan = 0; clan < (1 + top_clan); clan++)
    {
	if (!str_prefix(name, clan_table[clan].name))
	    return clan;
    }

    return 0;
}

char *player_rank(CHAR_DATA * ch)
{
    if (ch->clan == 0)
	return '\0';
    return clan_table[ch->clan].c_rank[ch->c_rank].rankname;
}

char *player_clan(CHAR_DATA * ch)
{
    if (ch->clan == 0)
	return '\0';
    return clan_table[ch->clan].name;
}


/* Commands */
void do_cleader (CHAR_DATA *ch, char *argument) {
    char arg[MAX_INPUT_LENGTH];
    CHAR_DATA *victim;
    int i;

    one_argument( argument, arg );

    if (arg[0] == '\0') {
        sendch( "Syntax: CLEADER <name>\n\r", ch );
        return;
    }

    if ((victim = get_char_world(ch, arg)) == NULL ) {
        sendch( "They aren't here.\n\r", ch );
        return;
    }

    if (victim->level > ch->level) {
        sendch( "You failed.\n\r", ch );
        return;
    }

    if (IS_SET(victim->act, PLR_LEADER)) {
        REMOVE_BIT(victim->act, PLR_LEADER);
        sendch( "The gods have revoked your leadership priviliges.\n\r", victim );
        sendch( "Leadership removed.\n\r", ch );
        victim->c_rank = 1;
        //sprintf(buf,"$N takes leadership away from %s",victim->name);
    }
    else {
        if (!is_clan(victim)) {
            sendch ("That person must be clanned first.\n\r", ch);
            return;
        }

        for (i = 0; i < (1 + top_clan); i++)
	{
            if (clan_table[i].name == clan_table[victim->clan].name)
                break;
        }

        free_string(clan_table[victim->clan].leader);
        SET_BIT(victim->act, PLR_LEADER);
        clan_table[victim->clan].leader = str_dup(victim->name);
        sendch( "The gods have made you a clan leader.\n\r", victim );
        sendch( "Leadership set.\n\r", ch );
        victim->c_rank = 7;
        //sprintf(buf,"$N make %s a clan leader.",victim->name);
	save_clans(ch, argument);	
    }
    return;
}

void do_promote(CHAR_DATA *ch, char *argument) {
    char arg[MAX_INPUT_LENGTH];
    char arg1[MAX_INPUT_LENGTH];
    CHAR_DATA *victim;
    int value;

    one_argument( argument, arg );

    if(ch->clan == 0) {
        sendch( "Huh?\n\r", ch);   
        return;
    }

    if(!IS_SET(ch->act, PLR_LEADER)){
	sendch("You cannot promote anyone!\n\r", ch);
	return;
    }

    if (arg[0] == '\0' || !is_number(arg1)) {
	sendch( "Who do you want to promote?\n\r", ch);
	sendch( "Type promote <name> <rank #>\n\r", ch);
	return;
    }

    if ((victim = get_char_world(ch, arg)) == NULL ) {
	sendch( "They aren't here!\n\r", ch);
	return;
    }

    if (victim == ch) {
	sendch( "You cannot promote yourself!\n\r", ch);
	return;
    }
    if (victim->clan != ch->clan) {
	sendch( "You cannot promote them.\n\r", ch);
	return;
    }

    if (victim->c_rank > 6) {
	sendch( "You cannot promote them any higher!\n\r", ch);
	return;
    }

    value = atoi(arg1);
    if (value < 1 || value > MAX_RANK) {
	sendch( "Value must be 1 - 6.\n\r", ch);
	return;
    }

    if (value && IS_IMMORTAL(victim) ) {
	sendch ("Heh... I don't think so.\n\r", ch);
	return;
    }

    if (value < victim->c_rank) {
	sendch ("Use 'demote <who> <rank #>' to demote someone.\n\r", ch);
	return;
    }
    else
	victim->c_rank = value;
        sendch( "You have promoted them!\n\r", ch);
        sendch( "You have been promoted!\n\r", victim);
    return;
}

void do_demote(CHAR_DATA *ch, char *argument) {
    char arg[MAX_INPUT_LENGTH];
    char arg1[MAX_INPUT_LENGTH];
    CHAR_DATA *victim;
    int value;

    one_argument( argument, arg );

    if(ch->clan == 0) {
        sendch( "Huh?\n\r", ch);
        return;
    }

    if(!IS_SET(ch->act, PLR_LEADER)){
        sendch( "You cannot demote anyone!\n\r", ch);
        return;
    }

    if (arg[0] == '\0' || !is_number(arg1)) {
        sendch( "Who do you want to demote?\n\r", ch);
        sendch( "Type demote <name> <rank #>\n\r", ch);
        return;
    }

    if ((victim = get_char_world(ch, arg)) == NULL ) {
        sendch( "They aren't here!\n\r", ch);
        return;
    }

    if (IS_SET(victim->act, PLR_LEADER)){
        sendch("You cannot demote a leader!\n\r", ch);
        return;
    }

    if (victim == ch) {
        sendch( "You cannot demote yourself!\n\r", ch);
        return;
    }
    if (victim->clan != ch->clan) {
        sendch( "You cannot demote them.\n\r", ch);
        return;
    }

    if (victim->c_rank < 1) {
        sendch( "You cannot demote them any lower!\n\r", ch);
        return;
    }

    value = atoi(arg1);
    if (value < 1 || value > MAX_RANK) {
        sendch( "Value must be 1 - 6.\n\r", ch);
        return;
    }

    if (value && IS_IMMORTAL(victim) ) {
        sendch ("Heh... I don't think so.\n\r", ch);
        return;
    }

    if (value > victim->c_rank) {
        sendch ("Use 'promote <who> <rank #>' to promote someone.\n\r", ch);
        return;
    }
    else
        victim->c_rank = value;
        sendch( "You have demoted them!\n\r", ch);
        sendch( "You have been demoted!\n\r", victim);
    return;
}

void do_join (CHAR_DATA *ch, char *argument) {
//    DESCRIPTOR_DATA *d;
    char arg[MAX_INPUT_LENGTH];
//    char buf[MAX_STRING_LENGTH];

//    int clan;

    if (IS_SET(ch->act, PLR_LEADER)) {
        sendch("You can't join another clan while you are currently a leader!\n\r"
               "Step down from leadership first.\n\r", ch);
        return;
    }

    one_argument( argument, arg );

    if (arg[0] == '\0') {
	if(ch->petition == 0)
	{
	    sendch( "You will now allow yourself to be clanned.\n\r", ch );
	    ch->petition = 1;
	}
	else
	{
	    sendch( "You will not allow yourself to be clanned.\n\r", ch );
	    ch->petition = 0;
	}
        return;
    }

    if ((clan_lookup(arg)) == 0) {
        sendch("There is no clan by that name.\n\r", ch);
        return;
    }

    if (!str_cmp(arg, "loner")) {
        sendch("You are now a loner.\n\r", ch);
        ch->petition = 0;
	ch->clan = 1;
	ch->c_rank = 1;
        return;
    }

    if (ch->clan > 0) {
        sendch ("You are already in a clan!\n\r", ch);
        return;
    }
/* 
    else {
	sprintf (buf, "{Y[CLAN] Ok. You have applied to %s{x.\n\r", clan_table[clan].name);
    	sendch(buf, ch);
    	ch->petition = clan;

    	for (d = descriptor_list; d != NULL; d = d->next)
            if (IS_SET(d->character->act, PLR_LEADER) && clan == d->character->clan)
	    {
		sprintf (buf, "{Y[CLAN] %s has petitioned to join your clan.{x\n\r", ch->name);
		sendch (buf, d->character);
	    }
*/
    return;
// }
}

void do_accept (CHAR_DATA *ch, char *argument) {
    char arg[MAX_INPUT_LENGTH];
    char buf[MAX_INPUT_LENGTH];
    CHAR_DATA *victim;

    if (!IS_SET(ch->act, PLR_LEADER))
    {
        sendch("You are not a clan leader.\n\r", ch);
        return;
    }

    one_argument( argument, arg );

    if (arg[0] == '\0') {
/*        DESCRIPTOR_DATA *d;
        char buf[MAX_STRING_LENGTH];
        bool found = FALSE;

        sendch ("Pending applications:\n\r", ch);
        for (d = descriptor_list; d != NULL; d = d->next) {
            if (d->character->petition == ch->clan) {
                sprintf (buf, "  %s\n\r", d->character->name);
                sendch (buf, ch);
                found = TRUE;
            }
        }
        if (!found)
            sendch ("None.\n\r", ch);
*/
	sendch("Syntax: accept <player>.\n\r", ch);
        return;
    }

    if ((victim = get_char_world(ch, arg)) == NULL)
    {
        sendch("They are not playing.\n\r", ch);
        return;
    }

    if (victim->petition == 0) {
        sendch("They do not wish to join a clan.\n\r", ch);
        return;
    }

    victim->clan = ch->clan;
    victim->petition = 0;
    victim->c_rank = 1;
    sendch("You have accepted them into your clan.\n\r", ch);
    sprintf(buf,"You have joined %s.\n\r", clan_table[victim->clan].name);
    sendch(buf, victim);
    return;
 }

void do_clanremove (CHAR_DATA *ch, char *argument) {
    char arg[MAX_INPUT_LENGTH];
    CHAR_DATA *victim;

    if (!IS_SET(ch->act, PLR_LEADER)) {
        sendch("You are not a clan leader.\n\r", ch);
        return;
    }

    one_argument( argument, arg );

    if (arg[0] == '\0') {
        sendch( "Remove who?\n\r", ch );
        return;
    }

    if ((victim = get_char_world(ch, arg)) == NULL) {
        sendch("They are not playing.\n\r", ch);
        return;
    }

    if (victim->clan == 0)
    {
        sendch("They're not in a clan in the first place.\n\r", ch);
        return;
    }

    if (victim->clan != ch->clan)
    {
        sendch("They're not in your clan.\n\r", ch);
        return;
    }

    victim->clan = 0;
    victim->petition = 0;
    victim->c_rank = 0;
    sendch("You have removed them from your clan.\n\r", ch);
    sendch("You have been removed from your clan.\n\r", victim);
    return;
}

void do_loner( CHAR_DATA *ch, char *argument )
 {
    char arg[MAX_INPUT_LENGTH];
    CHAR_DATA *victim;

    if (!IS_SET(ch->act, PLR_LEADER)) {
        sendch("You are not a clan leader.\n\r", ch);
        return;
    }

    one_argument( argument, arg );

    if (arg[0] == '\0') {
        sendch( "Loner who?\n\r", ch );
        return;
    }

    if ((victim = get_char_world(ch, arg)) == NULL)
    {
        sendch("They are not playing.\n\r", ch);
        return;
    }

    if (victim->clan == 0)
    {
        sendch("They're not in a clan in the first place.\n\r", ch);
        return;
    }

    if (victim->clan != ch->clan)
    {
        sendch("They're not in your clan.\n\r", ch);
        return;
    }

    victim->clan = 1;
    victim->petition = 0;
    victim->c_rank = 1;
    sendch ("You have made them a loner.\n\r", ch);
    sendch ("You have been made a loner.\n\r", victim);
    return;
 }

Site Stats

Snippets: 1791
Codebases: 571