Author Topic: Crafting System  (Read 8304 times)

Offline Tsarenzi

  • Acquaintance
  • *
  • Posts: 7
    • View Profile
Crafting System
« on: September 06, 2009, 05:33:34 AM »
I made up a fancy little crafting system to help relieve boredom, and I would like to share what I came up with and make it all available for free use.  Please feel free to use and adapt any of it that you would like, and I would love to hear if you do anything cool with it.

The idea behind the system is to be very flexible, easily extendable, and allow a lot of user personalization, but still to make it use defined descriptions rather than completely free tooling.

It has recipes, which define what object and how it is made and the sorts of ingredients which are used for it, including a base material type, such as cloth or metal.  There is then also materials, which can be of these base material types.  For example, silk and wool are both types of cloth, and these will provide different descriptions and properties based on which material the user chooses.

There are also embellishments.  The type of embellishments which can be used are defined by the material used, and these affect only the description choices available for the object.

Prototype objects are an intermediate step in the crafting during which the object's description can be changed through adjusting it to cycle through the different front descriptor (adjectives and article before the object name ie: "a large") or back descriptor choices (descriptive comments after the object name ie: ", adorned with bows") and to add embellishments.  They aren't usable until they are finished.  You can also still salvage some of your materials from a prototype until it is finished.

Recipes can be used as either physical paper recipes in hand, or they can be memorized.  This puts them into an invisible recipebook and can then be referenced as strings in the craft command.  I went with this technique instead of a crafting recipe book daemon to more easily facilitate adding new recipes for standard users.  The recipes command allows a look at memorized recipes for reference.

Skill is used in two ways.  First, recipes have minimum skill levels which are required and they specify the skill which is needed, possibly any skill new or old.  Materials also have skill levels which are added onto the recipe's minimum.  If the sum of the recipe and material skill level is more than the player's skill level, they are simply unable to make it.  Secondly, how far above the minimum skill level the player is determines the chance they have of making different quality items.  Quality shows up as a part of the description, but functions can also be defined to be called with different values based on whether the craftsmanship is good or shoddy.  For example, SetWear can be called to describe a tight fit or a good fit, depending on craftsmanship, or SetProtection can be called to have better protection with better craftsmanship.  However, perfect craftsmanship is equivalent to quality craftsmanship except in descriptions and value, so the hard to achieve perfect result does not affect usability at all.

Personalized segments of description can be added into an item by including %s into recipes or embellishments, and then specifying the personalized string as an argument when crafting or embellishing with these objects, which replaces the %s with the string argument.  If this seems too risky, simply don't include any %s.

To add a new craftable object, all you need to do is:
1) create a recipe which defines the details of making it
2) create the pattern object to clone from which inherits and uses craftable
3) make sure all the ingredients and supplies needed are available

To add a whole new craft:
1) create new recipes which use a different skill and/or material type
2) create the pattern objects for each of these recipes
3) create materials of the type the recipes use
4) create embellishments of the type allowed by the materials
5) make sure all the needed ingredients and supplies are available

The code for the system is available at:
http://www.gridaksma.com/tsarenzi/crafting.zip

Please let me know if you have any problems with it.

I also made up a couple of mini-crafts using the system as examples, for people to see the coder side of how it works.  The sewing and baking examples are available here:
http://www.gridaksma.com/tsarenzi/sewing.zip
http://www.gridaksma.com/tsarenzi/baking.zip

And here is an example from the crafter's perspective, trying out a few things.  It is edited to avoid too much redundancy:

Code: [Select]
craft dress from silk
You begin work on crafting a dress out of silk.
> You carefully cut out the pieces of cloth, setting them aside for when you are
ready for them.
You sew the pieces of the bodice together.
You begin on piecing the skirt together.
You carefully attach the skirt to the bodice of the dress and begin on the
sleeves.
You attach the sleeves to the rest of the garment, and look over your work.
You have created a quality silk dress that seems ready for embellishment,
though you have left a few elements which will need to be finished after that
before you are done.
embellish dress with red dye
You add a small bottle of red dye to a quality silk dress.
 > embellish dress with embroidery little flowers
You add a length of thick embroidery floss to a quality silk dress.
 > l silk dress
A dress made of silk, a quality example of the craft.  It has been dyed red.
It has been embroidered with little flowers.
It seems to be in the process of being crafted, and will need to be finished
before it is ready.  However, embellishments could still be added to it in the
meantime.
 > adjust dress front
You adjust the dress slightly, leaving you with an average silk dress.
 > adjust dress front
You adjust the dress slightly, leaving you with a crimson silk dress.
/domains/crafting/sewing >
adjust dress back
You adjust the dress slightly, leaving you with a crimson silk dress, cut from
flowing cloth.
 > adjust dress back
You adjust the dress slightly, leaving you with a crimson silk dress with a
full skirt.
 > adjust dress back
You adjust the dress slightly, leaving you with a crimson silk dress, decorated
with embroidery.
 > adjust dress back
You adjust the dress slightly, leaving you with a crimson silk dress,
embroidered with little flowers.
 > finish dress
You put the finishing touches on a crimson silk dress, embroidered with little
flowers.
 > wear silk dress
You slip into your dress, noting the excellent fit.
 > craft hat from wool
You begin work on crafting a hat out of wool.
 > You start in on the necessary preparation.
You carefully put the pieces together.
You look over the finished work.
You have created a shoddy wool hat that seems ready for embellishment, though
you have left a few elements which will need to be finished after that before
you are done.
 > l wool hat
A hat made of wool, a crude example of the craft.
It seems to be in the process of being crafted, and will need to be finished
before it is ready.  However, embellishments could still be added to it in the
meantime.
 > salvage wool hat
You work on picking apart a shoddy wool hat.
You manage to salvage usable pieces of a wide bolt of wool.
 > combine wools
You combine a wide bolt of wool with a wide bolt of wool, leaving you with 38
units of the stuff.

Enjoy!

Tsarenzi

Offline Nilrin

  • Friend
  • **
  • Posts: 85
    • View Profile
Re: Crafting System
« Reply #1 on: September 07, 2009, 07:25:57 AM »

I was dying to try this out, but I think I'm missing something fundamental. I'm getting an error that complains about the #include ROOMS_H bit in craft.c.

Missing leading " or < in #include

The file is unmodified from the one provided. I'm gathering that for some reason ROOMS_H isn't defined for some reason? This should be laughably easy for me to figure out, but for whatever reason (lack of sleep?) I can't seem to wrap my head around this. It doesn't seem to be syntax related though. For whatever reason, you can't have ROOMS_H in verbs? At least, it seems I can't.

Any clues?

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1020
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Crafting System
« Reply #2 on: September 07, 2009, 09:40:57 AM »
I was dying to try this out, but I think I'm missing something fundamental. I'm getting an error that complains about the #include ROOMS_H bit in craft.c.

Maybe you have an older version of DS that doesn't have ROOMS_H defined
in global.h. See if you have a line in global.h that reads like:

Code: [Select]
#define ROOMS_H "/secure/include/rooms.h"
If not, add it.

Tsarenzi, thank you for your contribution. What is the licensing for it?

-Crat

Offline Tsarenzi

  • Acquaintance
  • *
  • Posts: 7
    • View Profile
Re: Crafting System
« Reply #3 on: September 07, 2009, 03:10:45 PM »
I developed it on the Dead Souls mudlib, and have no problem with releasing it to the same license.  I suppose I should be more explicit about that!

As for the problem with ROOMS_H, if Crat's suggestion doesn't fix it, the only thing ROOMS_H is used for is to move items to the furnace to destruct them after they are used up, so you could use a different method to destruct them.  Though if it's only complaining in craft.c that's a bit odd.  The same line is in salvage.c and finish.c etc.

Tsarenzi

Offline Nilrin

  • Friend
  • **
  • Posts: 85
    • View Profile
Re: Crafting System
« Reply #4 on: September 07, 2009, 04:06:59 PM »
That's the part that stumps me. I'm using DS 2.10.

Here's the line in global.h in my library.

#define ROOMS_H "/secure/include/rooms.h"

If I simply change the line to not use the define

#include "/secure/include/rooms.h"

I receive an error *Unknown token 'OBJ
STR'


Offline Raudhrskal

  • BFF
  • ***
  • Posts: 214
  • The MUD community needs YOUR help!
    • View Profile
Re: Crafting System
« Reply #5 on: September 07, 2009, 04:20:42 PM »
Honestly, it sounds more like a unmatched quote or paren _in_ the rooms.h file. If you'd be willing to paste your copy of it somewhere in here, it'd be nice.

I checked craft.c in hex editor, there's no BOM or any other weird stuff in there. It's using CRLF line endings, but all other files in the package do too. One absurd possibility is that the driver takes ROOMS_H<cr><lf> as a token of ROOMS_H<cr>, instead of ROOMS_H, but it's rather improbable.
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...

Offline Nilrin

  • Friend
  • **
  • Posts: 85
    • View Profile
Re: Crafting System
« Reply #6 on: September 08, 2009, 03:41:42 AM »
Here's my rooms.h file. It's unmodified from DS 2.10 but here it is anyways.

Code: [Select]
#ifndef s_rooms_h
#define s_rooms_h

#include <dirs.h>

#define ROOM_ARCH        "/secure/room/arch"
#define ROOM_CATCH_TELL  DIR_STANDARD_DOMAIN "/room/catchtell"
#define ROOM_DEATH       DIR_STANDARD_DOMAIN "/room/death"
#define ROOM_FREEZER DIR_STANDARD_DOMAIN "/room/freezer"
#define ROOM_FURNACE DIR_STANDARD_DOMAIN "/room/furnace"
#define ROOM_NETWORK     "/secure/room/network"
#define ROOM_POD         DIR_STANDARD_DOMAIN "/room/pod"
#define ROOM_ROUTER      "/secure/room/router"
#define ROOM_START DIR_STANDARD_DOMAIN "/room/start"
#define ROOM_VIRT_VOID DIR_STANDARD_DOMAIN "/virtual/void"
#define ROOM_VOID DIR_STANDARD_DOMAIN "/room/void"
#define ROOM_WIZ DIR_STANDARD_DOMAIN "/room/wiz_hall"

#endif /* s_rooms_h */

I should point out, that it isn't just craft.c that's having the problem, but all verbs in the crafting package which include ROOMS_H.

Also, on the neigh chance that it has anything to do with it, I'm running on Ubuntu using the standard archive software that comes with it to unzip the package.

I use gedit to edit files, which has some syntax assistance built in.

Offline Nilrin

  • Friend
  • **
  • Posts: 85
    • View Profile
Re: Crafting System
« Reply #7 on: September 08, 2009, 05:13:36 AM »

Alright so, I know very little about text encoding, but to test the theory, I opened combine.c and a new file and literally re-typed the code into a new file, saved it and did an 'update' from within the MUD. No problems what so ever. So there's definitely either something in the text encoding that the driver doesn't like, or my zip compression utility messes with the encoding causing the problem before hand.

Also, if I used the editor within the MUD to view one of the packaged files, there's plenty of this "^M" character throughout the file which shouldn't be there.


Offline Raudhrskal

  • BFF
  • ***
  • Posts: 214
  • The MUD community needs YOUR help!
    • View Profile
Re: Crafting System
« Reply #8 on: September 08, 2009, 05:27:26 AM »
Puzzling. One Stupid Thing To Try: Add a space at the end of the "#include ROOMS_H" line. No, I'm serious.

The first error, 'Missing leading " or < in #include' meant that ROOMS_H was undefined and did not expand into a quoted path.
The second one means that the verb parser, packages/parser.c (NOT the LPC parser grammar.y) interprets "OBJ STR" as a single verb substitution token, as opposed to two separate. It's quite a bit absurd, tho it means that the #include worked this time.
At this point, I would believe even the theory that your computer is haunted. You might want to try testing it with a clean copy of DS straight from dead-souls.net on a different physical machine.

... Well, wait there's one more option. No idea what version of GCC is the standard one in your version of Ubuntu, but it might be 4.4.x or something. The newer GCC is, the more aggresive its algorithms are even with no optimizaton enabled. I was recently fighting an obscure bug in a completely different program - it compiled, and ran, but one small feature did not work correctly because GCC4 decided that it doesn't need to re-fetch a global variable to a CPU register where it was necessary. That program worked perfectly on GCC3 and earlier. FluffOS surely isn't THAT bad, I never had found such problem (yet!), but right now I'm using it with GCC4.3, not 4.4.
*sigh* Anyway, what I'm trying to say is: check your "gcc -v", post the version string, and check your package manager (synaptic?) for older version to try. You should have 4.2 and 4.3 available, at least. Install one of these, then enter fluffos-2.xx and do:
Code: [Select]
make distclean; ./configureNext, edit GNUmakefile in this directory. Change CC=gcc to CC=gcc-4.3 (or whatever major version you installed) then, as usual, make && make install.

Good luck.

EDIT: Ahhh... So it still IS barfing on the CR-LF encoding when running under Unix? Weird, thought it was fixed.
No, I'm not going to delete the essay above.

There are line-ending converters; the 'tofrodos' package provides one. Also, many editors offer the option to change the line endings between DOS/Win, Unix, and Old Mac encodings. It varies, might be in menu, the save as dialog, or as a symbol in the status bar. ("C-x RET c utf-8-unix RET C-x C-s" might also happen... but... you'll probably never stumble upon that one :P)
« Last Edit: September 08, 2009, 05:38:14 AM by Raudhrskal »
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...

Offline Nilrin

  • Friend
  • **
  • Posts: 85
    • View Profile
Re: Crafting System
« Reply #9 on: September 08, 2009, 05:59:30 AM »

The problem was fixed by using a dos2unix program on the files in question.

I did notice though, the crafting package seems to be missing the 'finish' verb.

Offline Tsarenzi

  • Acquaintance
  • *
  • Posts: 7
    • View Profile
Re: Crafting System
« Reply #10 on: September 08, 2009, 03:10:04 PM »
Whoops.  And of course I had to do something ditzy like leave a file out.  finish.c is now in the posted package.

Glad to hear you managed to get the encoding issues figured out!

Tsarenzi

Offline Nilrin

  • Friend
  • **
  • Posts: 85
    • View Profile
Re: Crafting System
« Reply #11 on: January 12, 2010, 02:24:32 AM »

Long after playing around with this nice package of a crafting system, I discovered an odd glitch.

Basically, if I design an item which requires a good deal of time to craft in game (maybe over a minute or two) there are times when it simply hangs and fails to complete. There were two things that made this rather difficult for me to track down, aside from the fact that I'm a newbie.

1. Firstly, the hang occurred in craft.c at this point:

Code: [Select]
//        if(!(prototype->eventMove(this_player()) ))
//        {
//                return "Error creating the prototype.";
//        }

However, I didn't realise this until it occurred to me that "return" wont return anything to the player, but what the function itself will return. So, changing this to "return write("Error creating the prototype.");" would be one way of fixing that.

2. Secondly, the root of the problem, why is it failing to move the prototype to the player in the first place, and perhaps even more importantly, why does it only fail some of the time.

Well it eventually occurred to me (I'd rather not say how long it took) that the prototype is being created without an environment, and because of this, the reaper daemon is actually destructing the object.

Because of this, might I suggest another method of manipulating the prototype object? A quick fix would be to simply move the prototype object to the player straight away, so that it doesn't get wiped, or perhaps put it in some holding room until it can be moved to the player.


Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1020
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Crafting System
« Reply #12 on: January 12, 2010, 08:03:41 PM »
2. Secondly, the root of the problem, why is it failing to move the prototype to the player in the first place, and perhaps even more importantly, why does it only fail some of the time.

Well it eventually occurred to me (I'd rather not say how long it took) that the prototype is being created without an environment, and because of this, the reaper daemon is actually destructing the object.

Because of this, might I suggest another method of manipulating the prototype object? A quick fix would be to simply move the prototype object to the player straight away, so that it doesn't get wiped, or perhaps put it in some holding room until it can be moved to the player.

I'd bet on the reaper, yes. It's easy enough to test by moving the object to some designated
place, either the player or a room like ROOM_POD where things can hang around with an
environment while preparing to enter the game.

-Crat

Offline agrippa

  • Acquaintance
  • *
  • Posts: 27
    • View Profile
Re: Crafting System
« Reply #13 on: October 22, 2010, 10:09:51 AM »
Hi chaps,

I have been trying to implement this and it works fine until I try to finish an object.  Whenever I do this I get the following:


*Bad argument 1 to call_other()
Expected: string or array or object Got: 0.
Object: /verbs/players/finish at line 32

'<fake>' at /secure/save/creators/a/agrippa (/<driver>) at line 0
'cmdAll' at /secure/save/creators/a/agrippa (/lib/command.c) at line 210
'do_finish_obj' at /verbs/players/finish at line 32
Trace written to /log/runtime

Line 32 is:

prod->eventMove(this_player());

Would someone be able to assist?

Thanks,

Iain

Offline chaos

  • BFF
  • ***
  • Posts: 291
  • Job, school, social life, sleep. Pick 2.5.
    • View Profile
    • Lost Souls
Re: Crafting System
« Reply #14 on: October 22, 2010, 12:07:34 PM »
Well, that means prod doesn't exist.  That is, the variable is empty (has a 0 in it).