/
lib/banish/
lib/d/coronos/
lib/d/coronos/w/alena/
lib/d/coronos/w/angel/
lib/d/coronos/w/angel/caves/
lib/d/coronos/w/angel/caves/monst/
lib/d/coronos/w/angel/city/chambers/
lib/d/coronos/w/angel/city/monst/
lib/d/coronos/w/angel/city/obj/
lib/d/coronos/w/angel/city/streets/
lib/d/coronos/w/angel/farms/plains/
lib/d/coronos/w/angel/monst/
lib/d/tempus/
lib/d/tempus/w/angel/
lib/d/tempus/w/kingbill/
lib/d/tempus/w/mirak/
lib/d/tempus/w/mirak/monst/
lib/d/tempus/w/mirak/obj/
lib/d/tempus/w/relgar/planes/baat/
lib/d/tempus/w/sarak/
lib/d/tempus/w/serepion/mon/
lib/d/tempus/w/valrejn/
lib/doc/
lib/doc/domains/
lib/doc/efun/
lib/include/fn_specs/
lib/info/
lib/inherit/base/
lib/log/
lib/log/mailbox/
lib/log/main/
lib/news/
lib/obj/party/
lib/objects/componen/
lib/open/
lib/open/party/
lib/open/paste/
lib/open/spells/
lib/open/valrejn/
lib/players/
lib/players/alena/
lib/players/alena/obj/
lib/players/alena/open/
lib/players/alena/private/
lib/players/angel/
lib/players/angel/obj/
lib/players/ash/
lib/players/biggs/
lib/players/biggs/food/
lib/players/biggs/gobkeep/
lib/players/biggs/mnstr/
lib/players/biggs/town/caves/
lib/players/biggs/town/tower/
lib/players/biggs/wpns/
lib/players/calris/
lib/players/deathurg/
lib/players/deathurg/open/
lib/players/deathurg/private/thief/
lib/players/dogberry/
lib/players/dogberry/library/
lib/players/dogberry/open/
lib/players/epsilon/
lib/players/epsilon/private/
lib/players/farewell/
lib/players/hippo/
lib/players/hippo/open/
lib/players/hippo/tools/
lib/players/jimpa/
lib/players/josh/
lib/players/josh/room/
lib/players/josh/room/mage/dungeon/
lib/players/josh/room/mage/dungeon/obj/
lib/players/josh/wep/
lib/players/kingbill/
lib/players/metatron/
lib/players/miette/
lib/players/mirak/
lib/players/mirak/open/
lib/players/parsilan/
lib/players/relgar/
lib/players/relgar/private/
lib/players/sarak/
lib/players/sarak/bugs/
lib/players/sarak/feelings/
lib/players/sarak/magical/
lib/players/sarak/minotaur/island/
lib/players/sarak/open/
lib/players/sarak/private/
lib/players/serepion/
lib/players/serepion/open/
lib/players/serepion/private/
lib/players/spike/
lib/players/spike/open/
lib/players/spike/private/
lib/players/spike/seaworld/
lib/players/valrejn/
lib/players/valrejn/open/
lib/players/valrejn/private/
lib/players/virus/
lib/players/wrath/
lib/players/wrath/arm/
lib/players/wrath/mon/
lib/players/wrath/room/
lib/players/wrath/room/entry/
lib/players/wrath/room/zolgath/
lib/players/wrath/weap/
lib/players/zil/
lib/room/
lib/room/city/arena/
lib/room/city/creator/
lib/room/city/garden/monst/
lib/room/city/library/
lib/room/city/library/open/books/
lib/room/city/shop/
lib/room/death/
lib/room/death/open/
lib/room/island/
lib/room/keeps/
lib/room/registry/
lib/room/ships/crew/
lib/room/ships/open/
lib/room/ships/open/types/bounty/
lib/room/ships/open/types/nebula/
lib/room/ships/open/types/phoenix/
lib/secure/udp_cmd_/
lib/skills/
lib/skills/fighter/
lib/skills/psionici/
lib/skills/thief/
lib/usr/
lib/usr/creators/
lib/usr/no_banis/
lib/usr/players/
/* PARTY DAEMON v1.0 (c)Angel, March 1993.
 * This is the master file for the party system, which keeps
 * track of all the parties on the mud, their cumulative exp,
 * age, members, as well as the parties name and leader, the
 * latter of which is usually the first member of the members
 * array. This file, each time the exp array is re-written, a
 * new file of Highest and Best parties, dependant upon exp
 * gained per unit of time, is written. This way a little
 * competition is encouranged between players 8)
 *
 * v2.0 (c) Angel, Aug 96
 */

#include <mudlib.h>
#include <ansi.h>


#define PARTY_OB	"/obj/party/party_ob"
#define PARTY_FILE 	"/obj/party/party_d"
#define PARTY_SAVE 	"open/party/party_save"
#define PARTY_BEST 	"/open/party/party_best"

#define SAVE        /* saves parties when quit */

mapping party_data;



string *query_all_members(string str);

void reset(status arg) {
  if(arg) return;

#ifdef SAVE
  restore_object(PARTY_SAVE);
#endif /* SAVE */

  if(!party_data || !m_sizeof(party_data)) {
    party_data = ([
      /* Order is as follows...                                        
       * party name : ([  party members : ({ memebers, }),
       *		  total  exp    : amount
       *		  total  exp    : amount
       *		  born: 
       *		  rate: 
       *		  founder : name,
       */
    ]);
  }
}

/**********************************************************
 * FN SPECS 
 */
void write_best_party();

/**********************************************************
 * FUNCTIONS 
 */
status query_party(string str) {
  if(!str) return 0;
  if(party_data[str]) return 1;
  return 0;
}


status add_party(mapping mapp, string str) {
  int i;
  mixed *arr;

  if(!m_sizeof(mapp)) return 0;
  if(!str) return 0;

  arr = m_indices(mapp);

  if(!query_party(str)) {
    party_data += mapp;
  }
#ifdef SAVE
  save_object(PARTY_SAVE);
#endif /* SAVE */
  return 1;
}



status remove_party(string str) {
  if(!query_party(str)) return 0;
  party_data = m_delete(party_data, str);
#ifdef SAVE
  save_object(PARTY_SAVE);
#endif /* SAVE */
  return 1;
}


mapping query_party_data() { return party_data; }

string *query_members(string str) {
  return query_all_members(str);
}


string *query_all_members(string party) {
  string *tmp;
  mapping mapp;

  if(mapp = party_data[party]) {
    tmp = mapp["members"];    
    return tmp;
  }
}


string query_leader(string party) {
  string tmp;
  mapping mapp;

  if(mapp = party_data[party]) {
    if(!tmp = mapp["leader"]) {
      tell_object(this_player(), "Your party has no leader!\n");
      remove_party(party);
    }
    else {
      return tmp;
    }
  }
}      
      


string query_founder(string party) {
  string tmp;
  mapping mapp;

  if(mapp = party_data[party]) {
    if(tmp = mapp["founder"]) {
      return tmp;
    }
    else {
      tell_object(this_player(), "Your party has no founder!\n");
      remove_party(party);
    }
  }
}


int query_age(string party) {
  int tmp;
  mapping mapp;
  if(mapp = party_data[party]) {
    if(tmp = mapp["age"]) 
      return tmp;
  }
}


int query_rate(string party) {
  int tmp;
  mapping mapp;
  if(mapp = party_data[party]) {
    if(tmp = mapp["rate"])
      return tmp;
  }
}


int query_total_exp(string party) {
  int tmp;
  mapping mapp;

  if(mapp = party_data[party]) {
    if(tmp = mapp["total exp"]) 
      return tmp;
  }
}


mixed *best_party() {
  mixed *party;
  mixed *party_names, party_info;
  string *temp;
  string tmp;
  mapping mapp;
  int i, rate;

  party = ({});

  party_names = m_indices(party_data);
  party_info  = m_values(party_data);


  for(i=0; i<sizeof(party_names); i++) {
    mapp = party_info[i];
    rate = mapp["rate"];
    party += ({
      ({ party_names[i], query_rate(party_names[i]), }),
    });
  }

  party = sort_array(party, "by_rate", this_object());

#ifdef SAVE
  save_object(PARTY_SAVE);
#endif /* SAVE */
  return party;
}

status by_rate(mixed *a, mixed *b) {
  return (a[1] < b[1]) ? 1 : 0;
}


void write_best_party() {
  mixed *party;
  string txt, tmp;
  string *temp_party;
  int i;

  party = best_party();

   txt = RED_B+BOLD+YELLOW_F+
        "_______________________________________________________________\n"+
        ">                 Best Parties on "+BLINK+MUD_NAME+OFF+
        RED_B+BOLD+YELLOW_F+"                     <\n"+
        "---------------------------------------------------------------\n"+
        OFF+BOLD+RED_B+YELLOW_F+
    " | Party Name              Members                    Rating | \n";

  for(i=0; i<sizeof(party); i++) {
    if(party[i][1] && sizeof(query_all_members(party[i][0]))) {
      tmp = " | "+party[i][0]+"                            ";
      tmp = extract(tmp,0,20);
      temp_party = query_all_members(party[i][0]);
      if(sizeof(temp_party))
        tmp = tmp +" "+capitalize(implode(temp_party, " "));
      tmp += "                                             ";
      tmp = extract(tmp,0,55);
      tmp += party[i][1]+"                                 ";
      tmp = extract(tmp,0,60);
      txt = txt + tmp +"|\n";
    }
  }


  txt += BOLD+YELLOW_F;
  txt += "_______________________________________________________________\n"+
         ">                                                             <\n"+
         "---------------------------------------------------------------\n";
  txt += OFF;

  if(this_player()->valid_write(PARTY_BEST)) {
    rm(PARTY_BEST);
    write_file(PARTY_BEST, txt);
  }
}



status get_party_object(string party, object player) {
  int i;
  object party_ob;

  if(!player) player = this_player();

  if(!party) return 0;

  if(member_array((string)player->query_name(1),
                  query_all_members(party)) == -1) return 0;

  if(present("party_object", player)) {
    party_ob = present("party_object", player);
    destruct(party_ob);
  }

  party_ob = clone_object(PARTY_OB);
  party_ob -> set_age(query_age(party));
  party_ob -> set_total_exp(query_total_exp(party));
  party_ob -> set_party(party);
  party_ob -> set_members(query_all_members(party));
  party_ob -> set_leader(query_leader(party));
  party_ob -> set_rate(query_rate(party));
  party_ob -> add_members((string)this_player()->query_name(1));
  move_object(party_ob, player);

  tell_object(player, "\nRestoring '"+party+"' party object...\n\n");
  return 1;
}