|
Economy Code (for MercMuds) [by Maniac] |
|
|
|
Posted Wednesday, August 12th @ 11:26:52 PM, by George Greer in the Utils dept.
Added Feb 6, 1997. Click the link below to read it or download it.
From: Maniac <v942346@si.hhs.nl>
Subject: Mud Economy System
The Mythran Mud Economy Snippet Version 2 (used to be banking.c)
**** IMPORTANT NOTE ****
This snippet is for MercMud related code, and not CircleMUD related
code. However, if you wish to convert it, feel free to send it to
the CircleMUD Mailing List (and mention it to the author too)
************************
Code version: 2.1
Snippet Version: 2.2
This code will enhance your mud economy. Well i hear you ask, 'What is
that Maniac talking about now', well... I'll tell Ya...
This code will install a banking system in your mud, but not just a normal
banking system, nooooo... a very nice, expandable and configurable banking
system. This banking system has the following options:
Deposit: This is just your basic bank system
Withdraw: Also found in all other bank systems
Balance: What's new ???
But here it comes...
Transfer: Transfer money from one account to another...
... I hear you say, 'nuff. special !'
Well.. you're right... here it comes:
Buy: Buy shares from the bank, turn your mud into wallstreet
Sell: The opposite of buy. DUHHHhhh
Check: Check the value of your shares, could be handy...
And (still) last but not least:
The Director skill: update Force an update of the share price...
Well... that's it... That's the extent of the Mythran Banking System ver. 2
Copyrights and rules for using the economy system:
The Mythran Mud Economy system was written by The Maniac, it was
loosly based on the rather simple 'Ack!'s banking system'
If you use this code you must follow these rules.
-Keep all the credits in the code.
-Use the supplied help entries for bank and update
-Mail Maniac (v942346@si.hhs.nl) to say you use the code
-Send a bug report, if you find 'it'
-Credit me somewhere in your mud.
Enuf bullshit... on with the code...
MYTHRAN MUD ECONOMY SYSTEM INSTALLATION GUIDE (big words for little shit)
1. Put the code at the end of this file in a file called economy.c
2. Add economy.c to your Makefile(s)
3. Add the bank command to your interp.c and declare it in merc.h
Add the bank command somewhere AFTER the BAN command, or it won't
work anymore
{ "bank", do_bank, .......etc
4. Add these fields to your pc_data struct:
int balance;
int shares;
5. Add this line to your merc.h (Under the heading Global variables)
extern int share_value;
6. Add the update command to interp.c (L_DIR), and declare it in merc.h
7. Define a BANK_FILE like this
#define BANK_FILE "BANK.TXT" /* For bank info */
8. In merc.h under the heading /* update.c */ include this line
void bank_update args( ( void ) );
9. In do_score in act_info.c, replace the part that prints your
experience (and exp to level) and gold by this part.
/*
* This section (exp, gold, balance and shares) was written by
* The Maniac from Mythran Mud
*/
if (IS_NPC(ch)) /* NPC's have no bank balance and shares */
{ /* and don't level !! -- Maniac -- */
sprintf( buf,
"You have scored %d exp, and have %d gold coins\n\r",
ch->exp, ch->gold );
strcat( buf1, buf );
}
if (!IS_NPC(ch)) /* PC's do level and can have bank accounts */
{ /* HERO's don't level anymore */
sprintf( buf,
"You have scored %d exp, and need %d exp to level.\n\r",
ch->exp,IS_HERO(ch) ? (1) : ((ch->level+1)*1000)-ch->exp);
strcat( buf1, buf );
sprintf( buf,
"You have %d gold in cash, %d gold on the bank\n\r",
ch->gold, ch->pcdata->balance);
strcat (buf1, buf );
if ( ch->pcdata->shares )
{
sprintf(buf,"You have %d gold invested in %d shares (%d each).\n\r",
(ch->pcdata->shares * share_value),
ch->pcdata->shares, share_value);
strcat( buf1, buf );
}
}
10. In db.c, under 'Local booting procedures', add this line
void load_bank args( ( void ) );
11. In db.c, after the call to load_ban(), add this
log_string ("Loading bank info");
load_bank( );
12. Add this section in db.c (under load_ban would be fine)
/*
* Load the bank information (economy info)
* By Maniac from Mythran Mud
*/
void load_bank( void )
{
FILE *fp;
int number = 0;
if ( !( fp = fopen( BANK_FILE, "r" ) ) )
return;
for ( ; ; )
{
char *word;
char letter;
do
{
letter = getc( fp );
if ( feof( fp ) )
{
fclose( fp );
return;
}
}
while ( isspace( letter ) );
ungetc( letter, fp );
word = fread_word( fp );
if ( !str_cmp( word, "SHARE_VALUE" ) )
{
number = fread_number( fp );
if ( number > 0 )
share_value = number;
}
}
}
13. In db.c, in free_char, add these lines in the 'if (ch->pcdata)' section
ch->pcdata->balance = 0; /* Maniac, for bank */
ch->pcdata->shares = 0; /* Maniac, for bank */
14. In save.c, in fwrite_char, add these lines, after Bmfout
fprintf( fp, "Balance %d\n", ch->pcdata->balance );
fprintf( fp, "Shares %d\n", ch->pcdata->shares );
15. In fread_char (save.c) add these lines under case 'B' and case 'S'
KEY( "Balance", ch->pcdata->balance, fread_number( fp ) );
KEY( "Shares", ch->pcdata->shares, fread_number( fp ) );
16. In update.c add this section after the weather_update
/*
* Update the bank system
* (C) 1996 The Maniac from Mythran Mud
*
* This updates the shares value (I hope)
*/
void bank_update(void)
{
int value = 0;
FILE *fp;
if ((time_info.hour 17))
return; /* Bank is closed, no market... */
value = number_range ( 0, 200);
value -= 100;
value /= 10;
share_value += value;
if ( !( fp = fopen ( BANK_FILE, "w" ) ) )
{
bug( "bank_update: fopen of BANK_FILE failed", 0 );
return;
}
fprintf (fp, "SHARE_VALUE %d\n\r", share_value);
fclose(fp);
}
17. In update.c update_handler, under the call to list_update, add this
bank_update ( );
18. In act_wiz.c add this command.
void do_update( CHAR_DATA *ch, char *argument ) /* by Maniac */
{
char arg[MAX_INPUT_LENGTH];
if ( !authorized( ch, "iscore" ) )
return;
if ( argument[0] == '\0' ) /* No options ??? */
{
send_to_char( "Update, call some game functions\n\r\n\r", ch );
send_to_char( "bank: Update the share_value.\n\r", ch );
return;
}
argument = one_argument(argument, arg);
if (!str_prefix(arg, "bank" ) )
{
bank_update ( );
send_to_char ("Ok...bank updated.\n\r", ch);
return;
}
return;
}
19. That's it... there are only a few more things to do...
Somewhere in some .h file define these things...
These defines can be used to configure the economy system
(I myself have them in a config.h, included in merc.h)
/*
* Bank system money transfer option
*
* Defining BANK_TRANSFER allows the players to transfer money from
* their bank account to someone else's account
* This can be handy if players have to pay admission for their clan etc
* The clanleader doesn't have to be near the player and he is informed of
* all the transfers, he can't lose the transfered money either.
*
*/
#define BANK_TRANSFER
/*
* Mud Economy System
* Bank Investments
*
* Defining BANK_INVEST allows players to invest their money in a
* mud fund, the value of the fund may change from time to time
* making it possible for players to speculate on a random generator
* (or if you want to call it this way: the economy)
*
* Define SHARE_VALUE to be the start/average/default value of a share (100)
*/
#define BANK_INVEST
#define SHARE_VALUE 100
20. Don't forget to delete all your .o files and then recompile.
(if you don't do a make clean, the mud will crash)
21. Add these entries to your help.are file
0 BANK SHARES ECONOMY~
Syntax:
bank deposit
bank withdraw
bank balance
bank transfer
bank buy
bank sell
bank check
The Mythran mud bank system enhances the economy of the MUD. In a bank
you can deposit money to your account, withdraw money from it, check your
current bank balance, and transfer money to other players.
This can be usefull if you have to pay your fee for the clan or divide
the cash from your quest among eachother.
Another feature of the bank is that you can buy and sell shares. By buying
shares you can invest your money in the mud economy. The shares constantly
change in value, so you can make a nice profit if you buy and sell your
shares at the right times.
The current share price and be seen by going to the bank, or by checking
your score.
~
53 UPDATE~
Syntax:
update bank
The update command updates (several) in-game mechanisms.
Update bank forces an update of the share price
~
-----------cut here... economy.c ------cut here... economy.c ------------------
/*
* The Mythran Mud Economy Snippet Version 2 (used to be banking.c)
*
* Copyrights and rules for using the economy system:
*
* The Mythran Mud Economy system was written by The Maniac, it was
* loosly based on the rather simple 'Ack!'s banking system'
*
* If you use this code you must follow these rules.
* -Keep all the credits in the code.
* -Mail Maniac (v942346@si.hhs.nl) to say you use the code
* -Send a bug report, if you find 'it'
* -Credit me somewhere in your mud.
* -Follow the envy/merc/diku license
* -If you want to: send me some of your code
*
* All my snippets can be found on http://www.hhs.nl/~v942346/snippets.html
* Check it often because it's growing rapidly -- Maniac --
*/
#if defined( macintosh )
#include
#else
#include
#endif
#include
#include
#include
#include
#include
#include "merc.h"
int share_value = SHARE_VALUE; /* External share_value by Maniac */
void do_bank( CHAR_DATA *ch, char *argument )
{
/* The Mythran mud economy system (bank and trading)
*
* based on:
* Simple banking system. by -- Stephen --
*
* The following changes and additions where
* made by the Maniac from Mythran Mud
* (v942346@si.hhs.nl)
*
* History:
* 18/05/96: Added the transfer option, enables chars to transfer
* money from their account to other players' accounts
* 18/05/96: Big bug detected, can deposit/withdraw/transfer
* negative amounts (nice way to steal is
* bank transfer -(lots of dogh)
* Fixed it (thought this was better... -= Maniac =-)
* 21/06/96: Fixed a bug in transfer (transfer to MOBS)
* Moved balance from ch->balance to ch->pcdata->balance
* 21/06/96: Started on the invest option, so players can invest
* money in shares, using buy, sell and check
* Finished version 1.0 releasing it monday 24/06/96
* 24/06/96: Mythran Mud Economy System V1.0 released by Maniac
*
*/
CHAR_DATA *mob;
char buf[MAX_STRING_LENGTH];
char arg1[MAX_INPUT_LENGTH];
char arg2[MAX_INPUT_LENGTH];
if ( IS_NPC( ch ) )
{
send_to_char( "Banking Services are only available to players!\
n\r", ch );
return;
}
/* Check for mob with act->banker */
for ( mob = ch->in_room->people; mob; mob = mob->next_in_room )
{
if ( IS_NPC(mob) && IS_SET(mob->act, ACT_BANKER ) )
break;
}
if ( mob == NULL )
{
send_to_char( "You can't do that here.\n\r", ch );
return;
}
if ((time_info.hour 17))
{
send_to_char( "The bank is closed, it is open from 9 to 5.\n\r"
, ch);
return;
}
if ( argument[0] == '\0' )
{
send_to_char( "Bank Options:\n\r\n\r", ch );
send_to_char( "Bank balance: Displays your balance.\n\r", ch );
send_to_char( "Bank deposit : Deposit gold into your account.\n
\r", ch );
send_to_char( "Bank withdraw : Withdraw gold from your account.
\n\r", ch );
#if defined BANK_TRANSFER
send_to_char( "Bank transfer : Transfer gold to account.\n\r
", ch);
send_to_char( "Bank buy #: Buy # shares (in developement)\n\r",
ch);
send_to_char( "Bank sell #: Sell # shares (in developement)\n\r
", ch);
send_to_char( "Bank check: Check the current rates of the share
s. (in developement)\n\r", ch);
#endif
return;
}
argument = one_argument( argument, arg1 );
argument = one_argument( argument, arg2 );
/* Now work out what to do... */
if ( !str_prefix( arg1, "balance" ) )
{
sprintf(buf,"Your current balance is: %d GP.\n\r",ch->pcdata->b
alance );
do_say(mob, buf);
return;
}
if ( !str_prefix( arg1, "deposit" ) )
{
int amount;
if ( is_number ( arg2 ) )
{
amount = atoi( arg2 );
if (amount > ch->gold )
{
sprintf( buf, "How can you deposit %d GP when y
ou only have %d?\n\r", amount, ch->gold );
do_say(mob, buf );
return;
}
if (amount gold -= amount;
ch->pcdata->balance += amount;
sprintf ( buf, "You deposit %d GP. Your new balance is
%d GP.\n\r",
amount, ch->pcdata->balance );
send_to_char( buf, ch );
do_save( ch, "" );
return;
}
}
/* We only allow transfers if this is true... so define it... */
#if defined BANK_TRANSFER
if ( !str_prefix( arg1, "transfer" ) )
{
int amount;
CHAR_DATA *victim;
if ( is_number ( arg2 ) )
{
amount = atoi( arg2 );
if ( amount > ch->pcdata->balance )
{
sprintf( buf, "How can you transfer %d GP when
your balance is %d?\n\r",
amount, ch->pcdata->balance );
do_say( mob, buf);
return;
}
if (amount pcdata->balance -= amount;
victim->pcdata->balance += amount;
sprintf( buf, "You transfer %d GP. Your new balance is
%d GP.\n\r",
amount, ch->pcdata->balance );
send_to_char( buf, ch );
sprintf (buf, "[BANK] %s has transferred %d gold's to y
our account.\n\r", ch->name, amount);
send_to_char( buf, victim );
do_save( ch, "" );
do_save( victim, "");
return;
}
}
#endif
if ( !str_prefix( arg1, "withdraw" ) )
{
int amount;
if ( is_number ( arg2 ) )
{
amount = atoi( arg2 );
if ( amount > ch->pcdata->balance )
{
sprintf( buf, "How can you withdraw %d GP when
your balance is %d?\n\r",
amount, ch->pcdata->balance );
do_say (mob, buf );
return;
}
if (amount pcdata->balance -= amount;
ch->gold += amount;
sprintf( buf, "You withdraw %d GP. Your new balance is
%d GP.\n\r", amount, ch->pcdata->balance );
send_to_char( buf, ch );
do_save( ch, "" );
return;
}
}
/* If you want to have an invest option... define BANK_INVEST */
#if defined BANK_INVEST
if ( !str_prefix( arg1, "buy" ) )
{
int amount;
if ( is_number ( arg2 ) )
{
amount = atoi( arg2 );
if ( (amount * share_value) > ch->pcdata->balance )
{
sprintf( buf, "%d shares will cost you %d, get
more money.\n\r", amount, (amount * share_value) );
do_say(mob, buf);
return;
}
if (amount pcdata->balance -= (amount * share_value);
ch->pcdata->shares += amount;
sprintf( buf, "You buy %d shares for %d GP, you now hav
e %d shares.\n\r", amount, (amount * share_value), ch->pcdata->shares );
do_say(mob, buf);
do_save( ch, "" );
return;
}
}
if ( !str_prefix( arg1, "sell" ) )
{
int amount;
if ( is_number ( arg2 ) )
{
amount = atoi( arg2 );
if ( amount > ch->pcdata->shares )
{
sprintf( buf, "You only have %d shares.\n\r", c
h->pcdata->shares );
do_say(mob, buf);
return;
}
if (amount pcdata->balance += (amount * share_value);
ch->pcdata->shares -= amount;
sprintf( buf, "You sell %d shares for %d GP, you now ha
ve %d shares.\n\r", amount, (amount * share_value), ch->pcdata->shares );
do_say (mob, buf);
do_save( ch, "" );
return;
}
}
if ( !str_prefix( arg1, "check" ) )
{
sprintf (buf, "The current shareprice is %d.\n\r",share_value);
do_say(mob, buf);
if (ch->pcdata->shares)
{
sprintf (buf, "You currently have %d shares, (%d a share) w
orth totally %d gold.\n\r",
ch->pcdata->shares, share_value, (ch->pcdata->shares *
share_value) );
do_say(mob, buf);
}
return;
}
#endif
do_say(mob, "I don't know what you mean");
do_bank( ch, "" ); /* Generate Instructions */
return;
}
---------- end of snippet economy.c ------------- end ---------- end -------
<< Eavesdrop Skill [by Siv] | Reply | View as text | Flattened | Energy Drain Spell [by Chris Rehbein] >> |
|
Related Links |
|
|
|
CircleMUD Snippets |
|
|
Note: Not all of these snippets will work perfectly with
your version of code, so be prepared to fix one
or two bugs that may arise, and please let me know
what you needed to do to fix it. Sending a corrected
version is always welcome.
|
Finally, if you wish to use any of the snippets from this
page, you are more than welcome, just mention the
authors in your credits. If you wish to release any
of these snippets to the public on another site,
contact me FIRST.
|
|
|
|
|
|
|