Coding Class: Dagger II

From LSWiki

Jump to: navigation, search
 #include <item.h>
 inherit "/std/item";
 void configure() {
         Element_Type       : Material_Steel,
         Element_Proportion : 1.0,
         Element_Type       : Material_Oak,
         Element_Proportion : 0.4,
         Element_Part       : Part_Base,
         Element_Flags      : Element_Flag_Secondary,
         Element_Type       : Material_Leather,
         Element_Proportion : 0.4,
         Element_Part       : Part_Wrap,
         Element_Form       : Form_Strips,
         Element_Color      : "black",
         Element_Flags      : Element_Flag_Secondary,
         Element_Type       : Material_Silver,
         Element_Proportion : 0.1,
         Element_Part       : Part_Inlay,
         Element_Form       : Form_Writing,

Important Header Files

  • /lib/descriptors/element.h
    • Element_*
  • /lib/materials.h
    • Material_*
    • Part_*, Form_*

Important Source Files

  • /def/part/*
  • /def/form/*
  • /obj/extensions/weapon.c
  • /std/item.c

Code Comments

So in this step we're going to take our dagger a little further and flesh out its physical form. We do this by utilizing the various defined parts and forms for elements. These are defined as macros in /lib/materials.h and their supporting code is contained in /def/form and /def/part respectively.

Looking at each proportion we notice first that I've changed iron to steel as the 'bulk' proportion. While I could explicitly set that proportion to be Part_Bulk, it is default behavior to assume that it is unless otherwise specified. So the bulk of our dagger is going to be made of steel, which is great. Element_Proportion tells us how much, proportionally, of our dagger is made of steel. In this case it's 1.0, meaning 1 whole part is steel. Looking at the others you may wonder, "Well how can you have it 1.0 then have other materials that are 0.4, 0.4 and 0.1! That's like 1.9!" It's because the proportions are relative to each other. If the steel is 1.0, then there is a little under half as much leather, half as much oak, and a tenth as much silver. It's all relative.

The Element_Form and Element_Part settings are particularly important because they let you set those elements apart from each other in your object, so that you can target and use them specifically in descriptions or what have you. As an example we could alter our description to include:

    Description_Type    : Description_Type_Element_Name,
    Description_Index   : ([ Element_Part : Part_Inlay ]),

What that will do for us is find the element in our dagger that is Part_Inlay (the silver writing) and give us its element name. This type of configuration is very important for how we handle items now, since materials changing is quite doable now. That silver could at any time and for any reason change to say, mithril, and by setting our dagger up this way the system will be able to recognize and deal with it. silver-inlaid-writing will seamlessly become mithril-inlaid-writing, etc.

That's the other thing that these Form_ and Part_ macros do for us. They can define by default a way to describe your object. If you look at the flags I set for the elements I made sure that _Oak and _Leather are set as Element_Flag_Secondary. That flag tells the object to not use those materials when describing the object. Otherwise the dagger would show up as 'a black leather-strips-wrapped steel dagger', which I don't particularly want for this incarnation of it. What I do want, is for 'a silver-writing-inlaid steel dagger' to show up, so using Part_Inlay and Form_Writing and allowing the element to show accomplishes this. I encourage you to spend time playing with the various macros and definitions and seeing how they affect the generated look of your item. You will find many of them useful.

Personal tools