Author Topic: The road to a crafting system  (Read 7871 times)

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Re: The road to a crafting system
« Reply #15 on: May 24, 2012, 08:20:55 pm »
also to add
Code: [Select]
inherit LIB_ITEMTYPE; to /lib/std/item.c

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Re: The road to a crafting system
« Reply #16 on: May 24, 2012, 08:51:58 pm »
here's the troublesome 'put' verb.  coupla things with it:  it does have the oddity that, if you have 5 or more "apple" resources and want to "put 5 apples on table", you cannot do that unless there are already apples on the table.  you can, however "put 5 apple on table" and that will work.  no idea how to fix that.  also you cannot put more apples into an existing heap of identical apples, even though you ought to be able to do that.  also provided here is the 'set' verb, which is in addition an action to configure an object, is a synonym for 'put'.

/lib/put.c
Code: [Select]
/*  /lib/put.c
 *  from the Dead Souls Mud Library
 *  handles things which may be put into other objects
 *  created by Descartes of Borg 960114
 *  2012-Feb-26 T. Cook corrected inability to use 'put' with multiple objects if target container not in inventory
 */
#include <lib.h>

private mixed PreventPut;

// abstract methods
string GetShort();
mixed CanDrop( object who );
mixed eventMove( mixed dest );
// end abstract methods

mixed SetPreventPut( mixed val ){
return ( PreventPut = val );
}

mixed GetPreventPut(){
return PreventPut;
}

varargs mixed CanPut( object who, object what ){
mixed tmp;
object env;

if( what ){ env = environment( what ); }
write( DebugFun( "CanPut", 0, who, what ) );
if( !env ){
return sprintf( "The %s doesn't seem to be anywhere.  Please file a bugreport.", remove_article( GetShort() ) );
}
if( ( tmp = CanDrop( who ) ) != 1 ){ return tmp; }
if( !environment() ){ destruct( this_object() ); return 1; }
if( environment() != this_player() && environment() != environment( this_player() ) ){ return 0; }
if( !PreventPut ){ return 1; }
if( stringp( PreventPut ) && PreventPut == "PERMIT" ){ return 1; }
if( intp( PreventPut ) ){ return 0; }
if( stringp( PreventPut ) ){ return PreventPut; }
if( objectp( PreventPut ) ){
if( PreventPut == who ){
return "You cannot put " + GetShort() + " anywhere.";
}else{
return 1;
}
}else if( functionp( PreventPut ) ){
return evaluate( PreventPut, who );
}else{
return "It seems you're unable to do that right now.";
}
}

varargs mixed eventPut( object who, object storage, string prep ){
int depth;
write( DebugFun( "eventPut", 1, who, storage, prep  ) );
if( !prep || prep == "" ){ prep = " into "; }
if( prep == " onto " && !inherits( LIB_SURFACE, previous_object() ) ){
who->eventPrint( "That isn't a load-bearing surface." );
return 0;
}
if( prep == " into " && inherits( LIB_SURFACE, previous_object() ) ){
who->eventPrint( sprintf(
"That's a surface.  Try '%sput %s on %s%s'.",
"%^BLACK%^%^B_WHITE%^", this_object()->GetCanonicalId()[0], storage->GetCanonicalId()[0], "%^RESET%^"
) );
return 0;
}
if(
( inherits( LIB_SIT, storage ) && sizeof( storage->GetSitters() ) ) ||
( inherits( LIB_LIE, storage ) && sizeof( storage->GetLiers() ) )
){
write( "There appears to be someone blocking your access." );
return 0;
}
if( !eventMove( storage ) ){
who->eventPrint( "The " + remove_article( this_object()->GetShort() ) + " stays where it is." );
return 0;
}

who->eventPrint( "You put " + GetShort() + prep + storage->GetShort() + "." );
environment( who )->eventPrint( who->GetName() + " puts " + GetShort() + prep + storage->GetShort() + ".", who );

if( inherits( LIB_STORAGE, this_object() ) ){
depth = this_object()->GetRecurseDepth();
if( depth && inherits( LIB_STORAGE, storage ) ){ storage->AddRecurseDepth( depth ); }
}
return 1;
}

static void create(){
PreventPut = 0;
}

mixed direct_put_obj_word_obj(){
write( DebugFun( "direct_put_obj_word_obj", 0, 0 ) );
return CanPut( this_player(), this_object() );
}

mixed direct_put_wrd_wrd_word_obj(){
write( DebugFun( "direct_wrd_wrd_word_obj", 0, 0 ) );
return CanPut( this_player(), this_object() );
}

mixed direct_put_obj_obj(){
write( DebugFun( "direct_put_obj_obj", 0, 0 ) );
return direct_put_obj_word_obj();
}
/* EOF */

/verbs/items/put.c
Code: [Select]
/*  /verbs/items/put.c
 *  from the Dead Souls Mud Library
 *  put OBJ in OBJ
 *  put OBJ into OBJ
 *  created by Descartes of Borg 950114
 *  Version: @(#) put.c 1.2@(#)
 *  Last modified: 96/12/31
 *  2012-Jan-29 T. Cook added 'set' synonym
 *  2012-Feb-24 T. Cook added CheckContainer() and ProcessVirtItems() in process to fix bugs
 */
#include <lib.h>
#include <daemons.h>
#include "include/put.h"
int CheckContainer( string s_amt1, string s_what1, string s_prep, object o_storage, string s_storage );
mapping ProcessVirtItems( string s_what );

inherit LIB_VERB;
string *eligible;

static void create(){
verb::create();
SetVerb( "put" );
SetSynonyms( "place", "stick", "set" );
SetRules(
// these rules are to allow use of set (calibrate) verb as well
"OBJ", "OBJ to STR", "STR on OBJ to STR",
//----
"OBS in OBJ", "OBS into OBJ", "OBS on OBJ", "OBS onto OBJ", "OBS OBJ",
"WRD WRD in OBJ", "WRD WRD into OBJ", "WRD WRD on OBJ", "WRD WRD onto OBJ"
);
SetErrorMessage( "Put what where?" );
SetHelp( HelpInfo( ([
"syntax": ({ "put <ITEM> in <CONTAINER>", "put <ITEM> into <CONTAINER>",
"put <ITEM> on <SURFACE>", "put <ITEM> onto <SURFACE>" }),
"body": "This allows you to place objects into or onto other objects.",
"synonyms": ({ "place", "stick", "set" }),
"see also": ({ "get", "give", "drop" })
]) ) );
}

// these are to allow set (calibrate) to work
mixed can_put_obj( mixed foo, mixed bar ){
return 0;
}

mixed can_put_obj_to_str( mixed *args... ){
write( DebugFun( "can_put_obj_to_str", this_player()->CanManipulate(), args ) );
return this_player()->CanManipulate();
}

mixed can_put_str_on_obj_to_str( string what1, mixed foo, string value1, string what2, string where, string value2 ){
object o_where, o_what, o_env = environment( this_player() );
if( !o_env ){ return "There's a problem...you don't have an environment!  Notify an admin promptly!"; }
o_where = present( where, o_env );
if( query_verb() == "set" ){
if( !o_where ){
return "You aren't able to find the " + where + "...";
}else{
if( present( what1, o_where ) ){
return present( what1, o_where )->eventSet( value1 );
}else{
return "You can't find the " + what1 + " on the " + where + "...";
}
}
}
return this_player()->CanManipulate();
}
//-----
mixed can_put_obs_word_obj( object *oa_what, string s_prep, object o_storage ){
write( DebugFun( "can_put_obs_word_obj", 0, oa_what, s_prep, o_storage ) );
if( check_light() ){
return this_player()->CanManipulate();
}else{
return 0;
}
}

mixed can_put_obj_word_obj( mixed m_foo, string s_prep, mixed m_bar, object o_what, object o_storage ){
object *oa_what;
write( DebugFun( "can_put_obj_word_obj", 0, m_foo, s_prep, m_bar, o_what, o_storage ) );
if( o_what ){ oa_what = ({ o_what }); }
return can_put_obs_word_obj( oa_what, s_prep, o_storage );
}

mixed can_put_obj_obj( object o_what, string s_prep, object o_storage ){
write( DebugFun( "can_put_obj_obj", 0, o_what, s_prep, o_storage ) );
return can_put_obj_word_obj( 0, s_prep, 0, o_what, o_storage );
}

mixed can_put_wrd_wrd_word_obj(
string s_amt1, string s_what1, string s_prep, object o_storage, string s_amt2, string s_what2, string s_storage
){
int i_amt;
mapping M_virt = ProcessVirtItems( s_what1 );

write( DebugFun( "can_put_wrd_wrd_word_obj", 1, s_amt1, s_what1, s_prep, o_storage, s_amt2, s_what2, s_storage ) );

    if( !s_amt1 || !s_what1 ){ return 0; }
    if( ( i_amt = numeralize( s_amt1 ) ) < 1 ){ return "You cannot do that!"; }

switch( M_virt["type"] ){
case "currency":
if( this_player()->GetCurrency( M_virt["name"] ) < i_amt ){
return "You don't have that much money on hand.";
}
break;
case "resource":
if( this_player()->GetResource( M_virt["name"] ) < i_amt ){
return "You don't have that many " + M_virt["plural"] + ".";
}
break;
default:
if( sizeof( filter( all_inventory( this_player() ), (: $1->id( $(M_virt["singular"]) ) :) ) ) < i_amt ){
return "You don't have that many " + M_virt["plural"] + ".";
}
break;
}
if( newbiep( this_player() ) ){ return "Newbies can't drop money."; }

if( o_storage && CheckContainer( s_amt1, s_what1, s_prep, o_storage, s_storage ) == -1 ){ return 1; }

if( intp( check_light() ) ){
return this_player()->CanManipulate();
}else{
return check_light();
}
}
//=====
mixed do_put_obj_word_obj( object what, string wrd, object storage ){
write( DebugFun( "do_put_obj_word_obj", 1, what, wrd, storage ) );
if( storage && storage->GetClosed() ){
write( capitalize( storage->GetShort() ) + " is closed." );
return 1;
}
    if(wrd == "in" || wrd == "into"){
if( wrd == "in" && present( what, storage ) && !present( what ) ){
return storage->eventSet( this_player(), what );
}
return storage->eventPutInto(this_player(), what);
}
    if(wrd == "on" || wrd == "onto"){
if( wrd == "on" && present( what, storage ) && !present( what ) ){
return storage->eventSet( this_player(), what );
}
return storage->eventPutOnto(this_player(), what);
}
}

mixed do_put_obj_obj( object what, object storage ){
string prepo;
write( DebugFun( "do_put_obj_obj", 0, what, storage ) );
if( storage && inherits( LIB_SURFACE, storage ) ){
prepo = "onto";
}else{
prepo = "into";
}
return do_put_obj_word_obj( what, prepo, storage );
}

mixed do_put_obs_word_obj( mixed *res, string wrd, object storage ){
// this object spams each item being put onto obj separately, instead of concatenating, fix that
object *obs;
obs = filter( res, (: objectp :) );
write( DebugFun( "do_put_obs_word_obj", 0, res, wrd, storage ) );
if( !sizeof( obs ) ){
mixed *ua;

ua = unique_array( res, (: $1 :) );
foreach( string *lines in ua ){
if( storage && storage->GetClosed() ){
write( capitalize( storage->GetShort() ) + " is closed." );
}else{
write( "That doesn't seem possible at the moment." );
}
return 1;
}
if( storage && storage->GetClosed() ){
write( capitalize( storage->GetShort() ) + " is closed." );
}else{
write( "That doesn't seem possible at the moment." );
}
return 1;
}
if( !sizeof( filter( obs, (: environment( $1 ) == this_player() :) ) ) ){
write( "You don't seem to be in possession of that." );
eligible = ({});
return 1;
}
eligible = filter( obs, (: ( !( $1->GetWorn() ) && environment( $1 ) == this_player() ) :) );
if( !sizeof( eligible ) ){
write( "Remove or unwield items before trying to put them somewhere." );
eligible = ({});
return 1;
}
if( wrd == "in" || wrd == "into" ){
foreach( object ob in eligible ){
storage->eventPutInto( this_player(), ob );
}
}
if( wrd == "on" || wrd == "onto" ){
foreach( object ob in eligible ){
storage->eventPutOnto( this_player(), ob );
}
}
eligible = ({});
return 1;
}

mixed do_put_obs_obj( mixed *res, object storage ){
string prepo;
write( DebugFun( "do_put_obs_obj", 0, res, storage ) );
if( storage && inherits( LIB_SURFACE, storage ) ){
prepo = "onto";
}else{
prepo = "into";
}
return do_put_obs_word_obj( res, prepo, storage );
}

mixed do_put_wrd_wrd_word_obj(
string s_amt1, string s_what1, string s_prep, object o_storage, string s_amt2, string s_what2, string s_storage
){
object pile, env;
int i_amt;
mapping M_virt = ProcessVirtItems( s_what1 );
object *oa_obs;

write( DebugFun( "do_put_wrd_word_obj", 1, s_amt1, s_what1, s_prep, o_storage, s_amt2, s_what2, s_storage ) );

if( CheckContainer( s_amt1, s_what1, s_prep, o_storage, s_storage ) == -1 ){ return 1; }

if(
( inherits( LIB_SIT, o_storage ) && sizeof( o_storage->GetSitters() ) ) ||
( inherits( LIB_LIE, o_storage ) && sizeof( o_storage->GetLiers()   ) )
){
write( "There appears to be someone blocking your access." );
return 0;
}

i_amt = numeralize( s_amt1 );
env = environment( this_player() );

switch( M_virt["type"] ){
case "currency":
pile = new( LIB_PILE );
pile->SetPile( M_virt["name"], i_amt );
if( !( pile->eventMove( o_storage ) ) || this_player()->AddCurrency( M_virt["name"], -i_amt ) == -1 ){
this_player()->eventPrint( "Something prevents your action." );
pile->eventDestruct();
return 1;
}
this_player()->eventPrint( sprintf(
"You put %s %s %s %s.",
i_amt == 1 ? GetArticle( M_virt["name"] ) : cardinal( i_amt ), M_virt["name"], s_prep, o_storage->GetShort()
) );
environment( this_player() )->eventPrint(
sprintf( "%s puts some money %s %s.", this_player()->GetName(), s_prep, o_storage->GetShort() ),
this_player()
);
break;
case "resource":
pile = new( LIB_HEAP );
pile->SetHeap( M_virt["name"], i_amt );
if( !( pile->eventMove( o_storage ) ) || this_player()->AddResource( M_virt["name"], -i_amt ) == -1 ){
this_player()->eventPrint( "Something prevents your action." );
pile->eventDestruct();
return 1;
}
this_player()->eventPrint( sprintf(
"You put %s %s %s %s.",
i_amt == 1 ? GetArticle( M_virt["name"] ) : cardinal( i_amt ),
i_amt == 1 ? M_virt["singular"] : M_virt["plural"], s_prep, o_storage->GetShort()
) );
environment( this_player() )->eventPrint( sprintf(
"%s puts %s %s %s %s.",
this_player()->GetName(), i_amt == 1 ? GetArticle( M_virt["name"] ) : "some",
i_amt == 1 ? M_virt["singular"] : M_virt["plural"],
s_prep, o_storage->GetShort() ), this_player()
);
break;
default:
oa_obs = filter( all_inventory( this_player() ), (: $1->id( $(M_virt["singular"]) ) :) );
do_put_obs_word_obj( oa_obs[0..i_amt - 1], s_prep, o_storage );
break;
}
return 1;
}

mixed eventCheckLight( object who ){
return check_light( who );
}

mapping ProcessVirtItems( string s_what ){
string s_item, s_newwhat = "", s_singwhat = "", s_multwhat = "", s_type = "other";
foreach( s_item in ECONOMY_D->__QueryCurrencies() ){
if(
strip_punctuation( singularize( lower_case( s_what ) ) ) ==
strip_punctuation( singularize( lower_case( s_item ) ) )
){
s_singwhat = singularize( s_item );
s_multwhat = pluralize( singularize( s_item ) );
s_newwhat = s_item;
s_type = "currency";
}
}
foreach( s_item in RESOURCES_D->QueryResources() ){
if(
strip_punctuation( singularize( lower_case( s_what ) ) ) ==
strip_punctuation( singularize( lower_case( s_item ) ) )
){
s_singwhat = singularize( s_item );
s_multwhat = pluralize( singularize( s_item ) );
s_newwhat = s_item;
s_type = "resource";
}
}
if( s_type == "other" ){
s_singwhat = singularize( s_what );
s_multwhat = pluralize( singularize( s_what ) );
s_newwhat = s_what;
}
return ([
"name": s_newwhat,
"singular": s_singwhat,
"plural": s_multwhat,
"type": s_type
]);
}

int CheckContainer( string s_amt1, string s_what1, string s_prep, object o_storage, string s_storage ){
switch( s_prep ){
case "on": case "onto":
if( !inherits( LIB_SURFACE, o_storage ) ){
if( inherits( LIB_STORAGE, o_storage ) ){
if( !s_amt1 ){
write( sprintf(
"The %s doesn't have a surface that can be used for that, but it is a container.  Try " +
"'%sput %s %s in %s%s'.",
s_storage, "%^B_WHITE%^%^BLACK%^", s_amt1, s_what1, s_storage, "%^RESET%^"
) );
}else{
write( sprintf(
"The %s doesn't have a surface that can be used for that, but it is a container.  Try " +
"'%sput %s in %s%s'.",
s_storage, "%^B_WHITE%^%^BLACK%^", s_what1, s_storage, "%^RESET%^"
) );
}
}else{
if( inherits( LIB_FLASK, o_storage ) ){
write( "The %s can only be used to hold liquids.", s_storage );
}else{
write( sprintf( "The %s isn't a container.", s_storage ) );
}
}
return -1;
}
break;
case "in": case "into":
if( inherits( LIB_SURFACE, o_storage ) ){
if( !s_amt1 ){
write( sprintf(
"That's a surface.  Try '%sput %s on %s%s'.",
"%^B_WHITE%^%^BLACK%^", s_what1, s_storage, "%^RESET%^"
) );
}else{
write( sprintf(
"That's a surface.  Try '%sput %s %s on %s%s'.",
"%^B_WHITE%^%^BLACK%^", s_amt1, s_what1, s_storage, "%^RESET%^"
) );
}
return -1;
}else{
if( !inherits( LIB_STORAGE, o_storage ) ){
if( inherits( LIB_FLASK, o_storage ) ){
write( "The %s can only be used to hold liquids.", s_storage );
}else{
write( sprintf( "The %s isn't a container.", s_storage ) );
}
return -1;
}else{
if( o_storage->GetClosed() ){
write( sprintf(
"The %s is closed.  It must be opened before you can put the %s in it.",
s_storage, s_what1
) );
return -1;
}
}
}
break;
default:
break;
}
return 1;
}
/* EOF */

/verbs/items/set.c  (from all the mass of commenting-out in here, I suspect something went horribly wrong with something I was trying to do)
Code: [Select]
/* /verbs/items/set.c
 * 2012-Jan-29 T. Cook
 * 2012-Feb-13 T. Cook removed ...on/in obj
 */
#include <lib.h>
#include <daemons.h>

inherit LIB_VERB;

static void create(){
verb::create();
SetVerb( "set" );
SetRules(
"OBJ", "off OBJ", "OBJ to STR",  "STR on OBJ to STR"
//"OBJ on OBJ", "off OBJ on OBJ", "OBJ on OBJ to STR", "STR on OBJ on OBJ to STR",
//"OBJ in OBJ", "off OBJ in OBJ", "OBJ in OBJ to STR", "STR on OBJ in OBJ to STR"
// note: these rules don't get checked because they're pre-empted; do my own parsing in the do_ function!
);
SetSynonyms( ({ "adjust", "align", "calibrate" }) );
SetErrorMessage( "Set something, perhaps to a particular mode, or a part on something to a particular mode?" );
SetHelp( HelpInfo( ([
"syntax": ({
"set <THING>", "set off <THING>", "set <THING> to <WHAT>", "set <PART> on <THING> to <WHAT>"
//"set <THING> on <WHERE>", "set off <THING> on <WHERE>", "set <THING> on <WHERE> to <WHAT>",
//"set <PART> on <THING> on <WHERE> to <WHAT>",
//"set <THING> in <WHERE>", "set off <THING> in <WHERE>", "set <THING> in <WHERE> to <WHAT>",
//"set <PART> on <THING> in <WHERE> to <WHAT>"
}),
"body": "Sets an item to a particular mode, such as a clock to 4:35 or the volume on a speaker to 6.  " +
"Also works for deliberately setting off alarms, bombs, traps, and the like, or for initially setting " +
"traps, et cetera.  Can refer to objects that are in or on other objects, as well.\n\n" +
"Synonyms:  adjust, align, calibrate"
]) ) );
}
//=====
mixed can_set(){  // ok
return this_player()->CanManipulate();
}

mixed can_set_obj( mixed m_foo, string s_what ){  // ok
return this_player()->CanManipulate();
}

mixed can_set_off_obj( mixed m_foo, string s_what ){  // ok
if( query_verb() == "set" ){
return this_player()->CanManipulate();
}else{
return sprintf(
"You can't %O the %O off.  If you feel you should be able to do that, please file a bug report.",
query_verb(), s_what
);
}
}

mixed can_set_obj_to_str( mixed *args... ){
//write( DebugFun( "can_set_obj_on_obj", this_player()->CanManipulate(), args ) );
return this_player()->CanManipulate();
}

mixed can_set_str_on_obj_to_str( string prop1, mixed foo, string value1, string prop2, string what, string value2 ){  // ok
return this_player()->CanManipulate();
}
//-----
/*mixed can_set_obj_on_obj( mixed *args... ){
//write( DebugFun( "can_set_obj_on_obj", this_player()->CanManipulate(), args ) );
return this_player()->CanManipulate();
}

mixed can_set_off_obj_on_obj( mixed *args... ){
if( query_verb() == "set" ){
return this_player()->GanManipulate();
}else{
return "\"" + capitalize( query_verb() ) + " off\"...what?  I don't understand that.  Please try to " +
"rephrase what you want to do.";
}
}

mixed can_set_obj_on_obj_to_str( mixed foo, mixed bar, string value1, string prop, string what, string value2 ){  // ok
//write( DebugFun( "can_set_obj_on_obj_to_str", this_player()->CanManipulate(), foo, bar, value1, prop, what, value2 ) );
return this_player()->CanManipulate();
}

mixed can_set_str_on_obj_on_obj_to_str( mixed *args... ){
return this_player()->CanManipulate();
}
//-----
mixed can_set_obj_in_obj( mixed *args... ){
//write( DebugFun( "can_set_obj_in_obj", this_player()->CanManipulate(), args ) );
return this_player()->CanManipulate();
}

mixed can_set_off_obj_in_obj( mixed *args... ){
//write( DebugFun( "can_set_off_obj_in_obj", 1, args ) );
if( query_verb() == "set" ){
return this_player()->GanManipulate();
}else{
return "\"" + capitalize( query_verb() ) + " off\"...what?  I don't understand that.  Please try to " +
"rephrase what you want to do.";
}
}

mixed can_set_obj_in_obj_to_str( mixed *args... ){
//write( DebugFun( "can_set_obj_in_obj_to_str", this_player()->CanManipulate(), args ) );
return this_player()->CanManipulate();
}

mixed can_set_str_on_obj_in_obj_to_str( mixed *args... ){
//write( DebugFun( "can_set_str_on_obj_in_obj_to_str", this_player()->CanManipulate(), args ) );
return this_player()->CanManipulate();
}*/
//=====
mixed do_set(){
return "Set something, something to what, or a part on something to what?";
}

varargs mixed do_set_obj( mixed item ){
return item->eventSet();
}

varargs mixed do_set_off_obj( mixed item ){
return item->eventTurnOn();
}

varargs mixed do_set_obj_to_str( mixed item, mixed setting ){
return item->eventSet( setting );
}

varargs mixed do_set_str_on_obj_to_str( mixed part, mixed item, mixed setting ){
return item->eventSet( setting, part );
}
//-----
/*varargs mixed do_set_obj_on_obj( mixed item ){
return item->eventSet();
}

varargs mixed do_set_off_obj_on_obj( mixed item ){
return item->eventTurnOn();
}

varargs mixed do_set_obj_on_obj_to_str( mixed *args... ){//mixed item, mixed setting ){
//write( DebugFun( "do_set_obj_on_obj_to_str", 1, args ) );
//return item->eventSet( setting );
return args[0]->eventSet( args[1] );
}

varargs mixed do_set_str_on_obj_on_obj_to_str( mixed part, mixed item, mixed setting ){
return item->eventSet( setting, part );
}
//-----
varargs mixed do_set_obj_in_obj( mixed item ){
return item->eventSet();
}

varargs mixed do_set_off_obj_in_obj( mixed item ){
return item->eventTurnOn();
}

varargs mixed do_set_obj_in_obj_to_str( mixed item, mixed setting ){
return item->eventSet( setting );
}

varargs mixed do_set_str_on_obj_in_obj_to_str( mixed part, mixed item, mixed setting ){
return item->eventSet( setting, part );
}*/
/* EOF */

/lib/events/set.c  (ditto)
Code: [Select]
/* /lib/events/set.c
 * allows items to access the 'set' verb
 * 2012-Feb-11 T. Cook added forms of use
 */
 // need to do checking in here, too, derp derp
 // pull *args things off into actual vars
#include <lib.h>

inherit LIB_TURN;

varargs mixed CanSet( object who, object what ){
return 1;
}
//=====
int direct_set_obj( object target ){
return CanSet( this_player() );
}

int direct_set_off_obj( object target ){
return turn::CanTurnOn( this_player() );
}

int direct_set_obj_to_str( object target, string what ){
return CanSet( this_player(), target );
}

int direct_set_str_on_obj_to_str( string target, object where, string what ){
return CanSet( this_player(), where );
}
//-----
/*int direct_set_obj_on_obj( object target, object where ){
return CanSet( this_player() );
}

int direct_set_off_obj_on_obj( object target, object where ){
return turn::CanTurnOn( this_player() );
}

int direct_set_obj_on_obj_to_str( object what1, mixed foo, string value1, string what2, string where, string value2 ){
//write( DebugFun(
//"direct_set_obj_on_obj_to_str", CanSet( this_player(), what1 ),
//what1, foo, value1, what2, where, value2
//) );
//if( !present( what2, present( where, environment( this_player() ) ) ) ){
//write( sprintf(
//"There isn't %O %O on the %O to set.",
//GetArticle( remove_article( what2 ) ), remove_article( what2 ), remove_article( where )
//) );
//return 0;
//}
return CanSet( this_player(), what1 );
}

int direct_set_str_on_obj_on_obj_to_str( string target, object where, string what, object wherewhere ){
return CanSet( this_player(), where );
}*/
/* EOF */

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Re: The road to a crafting system
« Reply #17 on: May 24, 2012, 08:55:18 pm »
and HERE'S the newer version of the mats command  :P

Code: [Select]
/* /secure/cmds/creators/mats.c
 * 2011-Dec-23 T. Cook
 * 2012-Apr-30 T. Cook added burn rate & notes properties
 * To do:  add array for resource type
 */
#include <lib.h>
#include <daemons.h>

inherit LIB_DAEMON;

int cmd( string str ){
string type, key, enc;
int vol, rate, i_scrX = this_player()->GetScreen()[0];
float mass;
mixed var;
string resourcetype, shortdesc, longdesc, state;
string *sa_properties = ({
"type", "state", "melting point", "boiling point", "refractive index", "acidity", "tensile modulus",
"shear modulus", "bulk modulus", "Poisson ratio", "Brinell hardness", "electrical resistance",
"thermal conductivity", "thermal resistance", "color", "mass", "volume", "rate", "shortdesc", "longdesc",
"burn rate", "notes"
});
string *sa_tmp, s_tmp = "";
string *sa_res = ({});
string s_resource;

enc = this_player()->GetProperty( "Encoding" );
if( !str ){
sa_tmp = ({
"\nThis is a list of the resources currently available on the MUD.  The command " +
"'%^B_WHITE%^%^BLACK%^mats <RESOURCE>%^RESET%^' will display all details for that item, and " +
"'%^B_WHITE%^%^BLACK%^mats <PROPERTY>%^RESET%^' will display a listing of the resources with " +
"a column of the specified property.\n"
});
sa_tmp += ({ "Resource" });
sa_tmp += ({ repeat_string( box( 0011, enc ), 25 ) });
foreach( s_resource in RESOURCES_D->QueryResources() ){ sa_tmp += ({ s_resource }); }
this_player()->more( sa_tmp, "system" );
return 1;
}
if( !archp( previous_object() ) ){ write( "You don't have permission to change the resources." ); return 1; }
log_file( "resources", previous_object()->GetCapName() + ":  " + str + " (" + ctime( time() ) + ")\n" );

foreach( s_resource in RESOURCES_D->QueryResources() ){
sa_res += ({ singularize( strip_punctuation( lower_case( s_resource ) ) ) });
}

if( sscanf( str, "add %s", type ) == 1 ){
if( member_array( type, ECONOMY_D->__QueryCurrencies() ) > -1 ){
write( "A currency already exists that has the same name; try again with a different resource name." );
return 1;
}
if( member_array( type, sa_properties ) > -1 ){
write( "That is used as a resource property, and so is not a valid resource name." );
return 1;
}
if( member_array( singularize( strip_punctuation( lower_case( type ) ) ), sa_res ) > -1 ){
write( "There already exists a resource that has a name too similar to this." );
return 1;
}
RESOURCES_D->add_resource(
type,
"resource",
"solid",
1.0,
1,
1,
add_article( remove_article( type ) ),
"This is " + add_article( remove_article( type ) ) + "."
);
message( "info", "Resource " + type + " added!", this_player() );
}else if( sscanf( str, "remove %s", type ) == 1 ){
if( member_array( type, sa_properties ) > -1 ){
write( "That is not a valid resource name." );
return 1;
}
RESOURCES_D->remove_resource( type );
message( "info", "Resource " + type + " removed!", this_player() );
}else if(
sscanf( str, "change %s for %s to %f",     key, type, var ) == 3 ||
sscanf( str, "change %s of %s to %f",      key, type, var ) == 3 ||
sscanf( str, "change %s for %s to %d",     key, type, var ) == 3 ||
sscanf( str, "change %s of %s to %d",      key, type, var ) == 3 ||
sscanf( str, "change %s for %s to %s",     key, type, var ) == 3 ||
sscanf( str, "change %s of %s to %s",      key, type, var ) == 3
){
switch( key ){
case "short": key = "shortdesc"; break;
case "long": key = "longdesc"; break;
default: break;
}
if( member_array( type, sa_properties ) > -1 ){
write( "That is not a valid resource name." );
return 1;
}
RESOURCES_D->change_resource( type, key, var );
message( "info", "Changed " + key + " for " + type + " to " + sprintf( "%O", var ), this_player() );
}else if( str == "reset" ){
write( "Resetting resources..." );
RESOURCES_D->ResetResources();
}else if( str == "properties" ){
write( "Materials have the following properties:\n" + format_page( sa_properties, 2 ) );
}else if( member_array( str, RESOURCES_D->QueryResources() ) > -1 ){
write( sprintf(
"%22s  %O\n"
"%22s  %O\n"
"%22s  %O\n"
"%22s  %O Celsius\n"
"%22s  %O Celsius\n"
"%22s  %O\n"
"%22s  %O Ph\n"
"%22s  %O GPa\n"
"%22s  %O GPa\n"
"%22s  %O GPa\n"
"%22s  %O\n"
"%22s  %O MPa\n"
"%22s  %O ohms per meter\n"
"%22s  %O Watts per meter Kelvin\n"
"%22s  %O m^2 Kelvin per Watt\n"
"%22s  %O\n"
"%22s  %O grams per unit\n"
"%22s  %O cm^3 per unit\n"
"%22s  %O copper per unit\n"
"%22s  %O\n"
"%22s  %O\n"
"%22s  %O units per minute\n"
"%22s  %O\n",
"             Resource:", str,
"                 Type:", RESOURCES_D->Query( str, "type" ),
"                State:", RESOURCES_D->Query( str, "state" ),
"        Melting point:", RESOURCES_D->Query( str, "melting point" ),
"        Boiling point:", RESOURCES_D->Query( str, "boiling point" ),
"     Refractive index:", RESOURCES_D->Query( str, "refractive index" ),
"              Acidity:", RESOURCES_D->Query( str, "acidity" ),
"      Tensile modulus:", RESOURCES_D->Query( str, "tensile modulus" ),
"        Shear modulus:", RESOURCES_D->Query( str, "shear modulus" ),
"         Bulk modulus:", RESOURCES_D->Query( str, "bulk modulus" ),
"        Poisson ratio:", RESOURCES_D->Query( str, "Poisson ratio" ),
"     Brinell hardness:", RESOURCES_D->Query( str, "Brinell hardness" ),
"Electrical resistance:", RESOURCES_D->Query( str, "electrical resistance" ),
" Thermal conductivity:", RESOURCES_D->Query( str, "thermal conductivity" ),
"   Thermal resistance:", RESOURCES_D->Query( str, "thermal resistance" ),
"                Color:", RESOURCES_D->Query( str, "color" ),
"                 Mass:", RESOURCES_D->Query( str, "mass" ),
"               Volume:", RESOURCES_D->Query( str, "volume" ),
"                Value:", RESOURCES_D->Query( str, "value" ),
"            Shortdesc:", RESOURCES_D->Query( str, "shortdesc" ),
"             Longdesc:", RESOURCES_D->Query( str, "longdesc" ),
"            Burn rate:", RESOURCES_D->Query( str, "burn rate" ),
"                Notes:", RESOURCES_D->Query( str, "notes" )
) );
}else if( member_array( str, sa_properties ) > -1 ){
sa_tmp = ({
sprintf( "%:-24s %s %:-" + ( i_scrX - 27 ) + "s", "Resource", box( 1100, enc ), capitalize( str ) )
});
sa_tmp += ({
repeat_string( box( 0011, enc ), 25 ) + box( 1111, enc ) + repeat_string( box( 0011, enc ), i_scrX - 27 )
});
foreach( s_resource in RESOURCES_D->QueryResources() ){
sa_tmp += ({ sprintf(
"%:-24s %s %:-" + ( i_scrX - 27 ) + "O",
s_resource, box( 1100, enc ), RESOURCES_D->Query( s_resource, str )
) });
}
this_player()->more( sa_tmp, "system" );
}else{
write( "Nothing happens." );
return 1;
}
return 1;
}

string GetHelp(){
return HelpInfo( ([
"syntax": ({
"mats", "mats <RESOURCE>", "mats add <RESOURCE>", "mats change <PROPERTY> for <RESOURCE> to <VALUE>"
}),
"body": "This command allows approved modififaction of the resource settings for the MUD; the 'add' " +
"parameter will add a new resource to the game, 'change' will modify an existing resource.  When " +
"the name of an existing resource is used by itself as the argument, a full listing of that " +
"resource's properties will be displayed.  Without any arguments, this command returns a listing " +
"of existing resources.  Note:  the resource name must be in a form that is a countable noun.\n\n" +
"Examples:  mats add chunk of iron\n" +
"           mats chunk of iron\n" +
"           mats change type for chunk of iron to metal"
]) );
}
/* EOF */
« Last Edit: May 24, 2012, 09:09:17 pm by z993126 »

Offline Nulvect

  • BFF
  • ***
  • Posts: 127
    • View Profile
Re: The road to a crafting system
« Reply #18 on: May 25, 2012, 12:35:11 am »
Not to be a buzzkill, but with the huge amount of code posted and reposted here, you may want to collect your original files into a zip, put your changes into a diff file or two, and attach them to a new post. Anyone who actually wants to use it as is would have to be pretty dedicated.

Offline hells

  • Acquaintance
  • *
  • Posts: 11
    • View Profile
Re: The road to a crafting system
« Reply #19 on: May 25, 2012, 02:32:15 am »
As requested. I was working from a fairly clean build and did a diff to find any changes. The files that have been modified are at:

http://www.savsoul.com/crafting.zip

- Hells

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Re: The road to a crafting system
« Reply #20 on: May 27, 2012, 12:27:45 am »
Definitely thanks, Hells.  Was thinking of just taking and making a new thread, this one ended up a real mess.

Hopefully people will get some use out of it now.  ^_^;;;

Offline detah

  • BFF
  • ***
  • Posts: 190
  • Ruler of 2D
    • View Profile
Re: The road to a crafting system
« Reply #21 on: May 31, 2012, 03:10:43 pm »
You just broke my brain.
/verbs/item/craft.c is pretty obvious and well commented. But /lib/living.c has seemingly no new content, no comments about crafting and no header update to reflect that any changes occurred since 1995. I would do some more commenting and header editing before zipping.

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Re: The road to a crafting system
« Reply #22 on: May 31, 2012, 04:49:35 pm »
living.c only has one or two additions relating to resources in the checks that go with currency, too; the actions they go with haven't been modified to support resources yet.  (give and steal, I think?)

*ahem*

Offline quixadhal

  • BFF
  • ***
  • Posts: 642
    • View Profile
    • WileyMUD
Re: The road to a crafting system
« Reply #23 on: June 03, 2012, 11:48:35 am »
Alternatively, you could just use a revision control system that was easily accessible *cough*github*cough*, so one could do their own $@#! diffs to see what has changed from a stable release....

I guess MUD coders are allergic to such things though, as ya'll seem to like packing zip files over and over again. :)

Offline Raudhrskal

  • BFF
  • ***
  • Posts: 214
  • The MUD community needs YOUR help!
    • View Profile
Re: The road to a crafting system
« Reply #24 on: June 07, 2012, 02:36:16 pm »
... huh.
You know, this IS odd. I'm using mercurial on all my private projects, but not on mud code...
I think, therefore i may be wrong.
Please note that if you met a Raudhrskal in a place that's not related to muds, it wasn't me. *sigh*... back when I started there was zero hits on google for that name...