Mining Code for Dawn of Time MUDs

I’ve been coding for my MUD game, Athens and wrote up the following hash of code that could be altered for fishing, hunting (as in game animals), panning for gold, ect. It’s basically a hack of a lot of things that I dug around in.

Code Snippet and Instructions
Make sure to add an object type for PICK and to add mine.o to your makefile.

create mine.cpp
/*
mine.cpp
Upon not being able to find a snippet being publicly shared to do this,
I decided to try to write something simple myself.
- Hera, of Athens - The Mud athens.boue.ca port 9000
hera_of_athens@yahoo.com
*/

#include “include.h”

void do_mine( char_data *ch, char * )
{
OBJ_DATA *obj;
int mineevent;
if(!IS_SET(ch->in_room->room2_flags, ROOM2_MINE))
{
ch->println(“You are not in a mine.”);
return;
}

if (!IS_NPC(ch))
{
for ( obj = ch->carrying; obj; obj = obj->next_content )
{
if ( obj->item_type == ITEM_PICK && obj->wear_loc == WEAR_HOLD )
break;
}

if ( !obj )
{
ch->println(“You are not holding a pick.”);
return;
}else{

for ( obj = ch->in_room->contents; obj; obj = obj->next_content )
{
if ( obj->item_type == ITEM_ORE )
extract_obj( obj );
break;
}

if ( obj == NULL )
{
ch->println( “This is not a suitable place to mine.” );
return;
}

mineevent = dice(1,2);
switch(mineevent)
{
case 1:
ch->println(“Your pick strikes a soft ore. It is gold!\n\r”);
ch->gold=ch->gold+3;
break;

case 2:
ch->println(“Your pick strikes a soft ore. It is silver!\n\r”);
ch->silver=ch->silver+3;
break;
}
}
}
else
ch->println( “Mobiles don’t need to mine.” );

}

You can add more cases to give different amounts of gold or silver, or perhaps objects such as gems. I just put up two as an example.

To make this work, you’d have a mine shaft or cave or some other area, and flag the rooms ROOM2_MINE. You’d also have to have objects of type ORE reset into the room. I suggest making them not takable.

When a player walks into the mine and sees some ore in the room, he’ll know he can mine (if he’s got a pick). When he types MINE, one of the ore type objects in the room is purged. This prevents someone from simply typing MINE 200 times and getting a lot of money. When the area resets, more ore will show up and another player who comes along can mine again.