/***************************************************************************
* This file contains auction code developed by Brian Babey, and any *
* communication regarding it should be sent to [bbabey@iname.com] *
* Web Address: http://www.erols.com/bribe/ *
* *
* 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-1995 Russ Taylor *
* ROM has been brought to you by the ROM consortium *
* Russ Taylor (rtaylor@pacinfo.com) *
* Gabrielle Taylor (gtaylor@pacinfo.com) *
* Brian Moore (rom@rom.efn.org) *
* By using this code, you have agreed to follow the terms of the *
* ROM license, in the file Rom24/doc/rom.license *
***************************************************************************/
#if defined(WIN32)
#include <windows.h>
#else
#include <sys/types.h>
#endif
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include "merc.h"
DECLARE_DO_FUN( do_auction );
DECLARE_SPELL_FUN(spell_identify);
void show_obj_stats( int sn, int level, CHAR_DATA *ch, void *vo );
void auction_channel( char * msg );
void do_auction( CHAR_DATA *ch, char * argument )
{
long gold=0;
OBJ_DATA * obj;
char arg1[MAX_INPUT_LENGTH], buf[MAX_STRING_LENGTH];
argument = one_argument( argument, arg1 );
if ( ch == NULL || IS_NPC(ch) )
return;
if ( arg1[0] == '\0')
{
if ( IS_SET(ch->comm,COMM_NOAUCTION) )
{
REMOVE_BIT(ch->comm,COMM_NOAUCTION );
send_to_char("Auction channel is now ON.\n\r",ch);
return;
}
SET_BIT(ch->comm,COMM_NOAUCTION);
send_to_char("Auction channel is now OFF.\n\r",ch);
return;
}
if ( !str_cmp( arg1, "info" ) )
{
obj = auction_info.item;
if ( !obj )
{
send_to_char("There is nothing up for auction right now.\n\r",ch);
return;
}
if ( auction_info.owner == ch )
{
sprintf( buf, "\n\rYou are currently auctioning %s.\n\r",
obj->short_descr );
send_to_char( buf, ch );
return;
}
else
spell_identify(skill_lookup( "identify" ), ch->level, ch, obj );
return;
}
if ( !str_cmp( arg1, "bid" ) )
{
long bid;
obj = auction_info.item;
if ( !obj )
{
send_to_char("There is nothing up for auction right now.\n\r",ch);
return;
}
if ( argument[0] == '\0' )
{
send_to_char("You must enter an amount to bid.\n\r",ch);
return;
}
bid = atol( argument );
if ( bid <= auction_info.current_bid )
{
sprintf(buf, "You must bid above the current bid of %ld gold.\n\r",
auction_info.current_bid );
return;
}
if ( bid < MINIMUM_BID )
{
sprintf( buf, "The minimum bid is %d gold.\n\r",MINIMUM_BID);
send_to_char(buf,ch);
return;
}
if ( (ch->gold) < bid )
{
send_to_char("You can't cover that bid.\n\r",ch);
return;
}
sprintf(buf, "%ld gold has been offered for %s.\n\r",
bid, auction_info.item->short_descr);
auction_channel( buf );
if ( auction_info.high_bidder != NULL )
{
auction_info.high_bidder->gold += auction_info.gold_held;
}
gold = UMIN( ch->gold, bid );
ch->gold -= gold;
/* ch->silver -= silver;*/
auction_info.gold_held = gold;
/* auction_info.silver_held = silver;*/
auction_info.high_bidder = ch;
auction_info.current_bid = bid;
auction_info.status = 0;
return;
}
if ( auction_info.item != NULL )
{
send_to_char("There is already another item up for bid.\n\r",ch);
return;
}
if ( (obj = get_obj_carry( ch, arg1 )) == NULL )
{
send_to_char("You aren't carrying that item.\n\r",ch);
return;
}
if ( IS_OBJ_STAT( obj, ITEM_NODROP ) )
{
send_to_char("You can't let go of that item.\n\r",ch);
return;
}
auction_info.owner = ch;
auction_info.item = obj;
auction_info.current_bid = 0;
auction_info.status = 0;
sprintf(buf,"Now taking bids on %s.\n\r", obj->short_descr );
auction_channel( buf );
obj_from_char( obj );
return;
}
void auction_update( )
{
char buf[MAX_STRING_LENGTH];
if ( auction_info.item == NULL )
return;
auction_info.status++;
if ( auction_info.status == AUCTION_LENGTH )
{
sprintf(buf,"%s SOLD to %s for %ld gold.\n\r",
capitalize(auction_info.item->short_descr),
auction_info.high_bidder->name,
auction_info.current_bid );
auction_channel( buf );
auction_info.owner->gold += auction_info.gold_held;
obj_to_char( auction_info.item, auction_info.high_bidder );
sprintf(buf, "%s appears in your hands.\n\r",
capitalize(auction_info.item->short_descr) );
send_to_char( buf, auction_info.high_bidder );
auction_info.item = NULL;
auction_info.owner = NULL;
auction_info.high_bidder = NULL;
auction_info.current_bid = 0;
auction_info.status = 0;
auction_info.gold_held = 0;
/* auction_info.silver_held = 0;*/
return;
}
if ( auction_info.status == AUCTION_LENGTH - 1 )
{
sprintf(buf, "%s - going twice at %ld gold.\n\r",
capitalize(auction_info.item->short_descr),
auction_info.current_bid );
auction_channel( buf );
return;
}
if ( auction_info.status == AUCTION_LENGTH - 2 )
{
if ( auction_info.current_bid == 0 )
{
sprintf(buf, "No bids on %s - item removed.\n\r",
auction_info.item->short_descr);
auction_channel( buf );
obj_to_char( auction_info.item, auction_info.owner );
sprintf(buf, "%s is returned to you.\n\r",
capitalize(auction_info.item->short_descr) );
send_to_char( buf, auction_info.owner );
auction_info.item = NULL;
auction_info.owner = NULL;
auction_info.current_bid = 0;
auction_info.status = 0;
return;
}
sprintf(buf, "%s - going once at %ld gold.\n\r",
capitalize(auction_info.item->short_descr),
auction_info.current_bid );
auction_channel( buf );
return;
}
return;
}
void auction_channel( char * msg )
{
char buf[MAX_STRING_LENGTH];
DESCRIPTOR_DATA *d;
sprintf(buf, "\n\r[AUCTION] %s", msg ); /* Add color if you wish */
for ( d = descriptor_list; d != NULL; d = d->next )
{
CHAR_DATA *victim;
victim = d->original ? d->original : d->character;
if ( d->connected == CON_PLAYING &&
!IS_SET(victim->comm,COMM_NOAUCTION) &&
!IS_SET(victim->comm,COMM_QUIET) )
{
send_to_char( buf, victim );
}
}
return;
}
/*
* Show_obj_stats: code taken from stock identify spell (-Brian)
*/
void show_obj_stats( int sn, int level, CHAR_DATA *ch, void *vo )
{
char buf[MAX_STRING_LENGTH];
OBJ_DATA *obj = (OBJ_DATA *) vo;
AFFECT_DATA *paf;
sprintf( buf,
"Object '%s' is type %s, extra flags %s.\n\rWeight is %d, value is %d, level is %d.\n\r",
obj->name,
item_type_name( obj ),
extra_bit_name( obj->extra_flags ),
/* extra2_bit_name( obj->extra2_flags ),*/ /* To be added later.-Lancelight */
/* extra3_bit_name( obj->extra3_flags ),*/
obj->weight,
obj->cost,
obj->level
);
send_to_char( buf, ch );
switch ( obj->item_type )
{
case ITEM_SCROLL:
case ITEM_POTION:
case ITEM_PILL:
sprintf( buf, "Level %d spells of:", obj->value[0] );
send_to_char( buf, ch );
if ( obj->value[1] >= 0 && obj->value[1] < MAX_SKILL )
{
send_to_char( " '", ch );
send_to_char( skill_table[obj->value[1]].name, ch );
send_to_char( "'", ch );
}
if ( obj->value[2] >= 0 && obj->value[2] < MAX_SKILL )
{
send_to_char( " '", ch );
send_to_char( skill_table[obj->value[2]].name, ch );
send_to_char( "'", ch );
}
if ( obj->value[3] >= 0 && obj->value[3] < MAX_SKILL )
{
send_to_char( " '", ch );
send_to_char( skill_table[obj->value[3]].name, ch );
send_to_char( "'", ch );
}
send_to_char( ".\n\r", ch );
break;
case ITEM_WAND:
case ITEM_STAFF:
sprintf( buf, "Has %d(%d) charges of level %d",
obj->value[1], obj->value[2], obj->value[0] );
send_to_char( buf, ch );
if ( obj->value[3] >= 0 && obj->value[3] < MAX_SKILL )
{
send_to_char( " '", ch );
send_to_char( skill_table[obj->value[3]].name, ch );
send_to_char( "'", ch );
}
send_to_char( ".\n\r", ch );
break;
case ITEM_WEAPON:
send_to_char("Weapon type is ",ch);
switch (obj->value[0])
{
case(WEAPON_EXOTIC) : send_to_char("exotic.\n\r",ch); break;
case(WEAPON_SWORD) : send_to_char("sword.\n\r",ch); break;
case(WEAPON_DAGGER) : send_to_char("dagger.\n\r",ch); break;
case(WEAPON_SPEAR) : send_to_char("spear/staff.\n\r",ch); break;
case(WEAPON_MACE) : send_to_char("mace/club.\n\r",ch); break;
case(WEAPON_AXE) : send_to_char("axe.\n\r",ch); break;
case(WEAPON_FLAIL) : send_to_char("flail.\n\r",ch); break;
case(WEAPON_WHIP) : send_to_char("whip.\n\r",ch); break;
case(WEAPON_POLEARM): send_to_char("polearm.\n\r",ch); break;
default : send_to_char("unknown.\n\r",ch); break;
}
sprintf(buf,"Damage is %dd%d (average %d).\n\r",
obj->value[1],obj->value[2],
(1 + obj->value[2]) * obj->value[1] / 2);
send_to_char( buf, ch );
break;
case ITEM_ARMOR:
sprintf( buf,
"Armor class is %d pierce, %d bash, %d slash, and %d vs. magic.\n\r",
obj->value[0], obj->value[1], obj->value[2], obj->value[3] );
send_to_char( buf, ch );
break;
}
if (!obj->enchanted)
for ( paf = obj->pIndexData->affected; paf != NULL; paf = paf->next )
{
if ( paf->location != APPLY_NONE && paf->modifier != 0 )
{
sprintf( buf, "Affects %s by %d.\n\r",
affect_loc_name( paf->location ), paf->modifier );
send_to_char( buf, ch );
}
}
for ( paf = obj->affected; paf != NULL; paf = paf->next )
{
if ( paf->location != APPLY_NONE && paf->modifier != 0 )
{
sprintf( buf, "Affects %s by %d.\n\r",
affect_loc_name( paf->location ), paf->modifier );
send_to_char( buf, ch );
}
}
return;
}