Coding Class: Dagger

From LSWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 22:58, 8 May 2008 (edit)
Matts (Talk | contribs)

← Previous diff
Revision as of 23:00, 8 May 2008 (edit)
Matts (Talk | contribs)
(Code Discussion)
Next diff →
Line 1: Line 1:
- 1) #include <item.h>+1) #include <item.h>
2) inherit "/std/item"; 2) inherit "/std/item";
3) void configure() { 3) void configure() {
Line 41: Line 41:
# add_proportion() defines the materials that an item is crafted from. In our case we're making an iron dagger so we define it as above. I could extend this out further and add another proportion for Material_Wood and define it as a hilt. Add another proportion for leather and wrap the hilt in leather. Add another proportion for gold and give the dagger some nice inlaid writing. And on and on. You can see the materials that are defined in /def/material/*, and more about the element descriptor in 'man element' # add_proportion() defines the materials that an item is crafted from. In our case we're making an iron dagger so we define it as above. I could extend this out further and add another proportion for Material_Wood and define it as a hilt. Add another proportion for leather and wrap the hilt in leather. Add another proportion for gold and give the dagger some nice inlaid writing. And on and on. You can see the materials that are defined in /def/material/*, and more about the element descriptor in 'man element'
-==== Code Discussion ====+==== Notes ====
So the above code is the bare bones minimal effort it takes to create a code-current basic iron dagger. If you're an older coder you may notice several things missing that you are used to. Namely some type of set_id() or set_names(), set_weapon_class() and other such things. The reason we don't need them here is because we are using the power of [[definitions]] to our advantage. We tell the object that it's a dagger weapon made of iron and the game can figure out what to call it, how to color it, what weapon class, penetration, attack speed, weight and value it needs to have; among other things.<br><br> So the above code is the bare bones minimal effort it takes to create a code-current basic iron dagger. If you're an older coder you may notice several things missing that you are used to. Namely some type of set_id() or set_names(), set_weapon_class() and other such things. The reason we don't need them here is because we are using the power of [[definitions]] to our advantage. We tell the object that it's a dagger weapon made of iron and the game can figure out what to call it, how to color it, what weapon class, penetration, attack speed, weight and value it needs to have; among other things.<br><br>
You can get an idea of how this is possible by checking out the /def/* files listed above. Feel free to browse around while you're in there and get a feel of what's defined and what isn't. You can get an idea of how this is possible by checking out the /def/* files listed above. Feel free to browse around while you're in there and get a feel of what's defined and what isn't.
<nowiki><nowiki>Insert non-formatted text here</nowiki></nowiki> <nowiki><nowiki>Insert non-formatted text here</nowiki></nowiki>

Revision as of 23:00, 8 May 2008

1) #include <item.h>

2) inherit "/std/item";
3) void configure() {
    ::configure();
    4) weapon()->set_weapon_type(Weapon_Type_Dagger);
    5) set_craft(Craft_Good);
    6) add_description(Description_Type_Generic);
    7) add_proportion(([
        Element_Type       : Material_Iron,
        Element_Proportion : 1.0,
    ]));
}

Contents

Important Header Files

  • /lib/craft.h
    • Craft_Good
  • /lib/item.h
  • /lib/materials.h
    • Material_Iron
  • /lib/weapons.h
    • Weapon_Type_Dagger
  • /lib/descriptors/description.h
    • Description_Type_Generic
  • /lib/descriptors/element.h
    • Element_Type
    • Element_Proportion

Important Source Files

  • /def/material/i/iron.c
  • /def/weapon_type/d/dagger.c
  • /obj/extensions/weapon.c
  • /std/item.c

Code Comments

  1. Includes our generic item header file which is a collection of other useful header files.
  2. Inherits our generic item object which defines and makes available the basic functions we need to create an item of any type, including weapons and armour. /std/weapon and /std/armour still exist, but are deprecated.
  3. The configure() function is defined by /std/item and any base inheritble you will use to create an object. This function is used to define and initialize identities, crafts, descriptions, materials, and other basic configuration aspects of an item. Other functions to be aware of are create(), preinit(), and init(). Each are called at different times in an items' creation.
  4. This calls set_weapon_type() function defined in the weapon() function in /std/item, which ultimately just returns the weapon extension object attached to the item. See, set_weapon_type() isn't defined by /std/item itself, but by /obj/extensions/weapon. weapon() is a reference to that extension. set_weapon_type() defines what type of weapon we are creating here. The types available are defined in /lib/weapons.h
  5. set_craft() defines the craftsmanship of the item in question. The craft types available are in /lib/craft.h
  6. add_description() and its cousin add_known_description() let you define what an object looks like when a player examines it. The options and customization here can become rather complicated and in-depth, so Description_Type_Generic gives you a nice clean, but very basic, way to summarize this. In general you will get a description of what type of item it is, its material make-up, its craftsmanship, size and weight. You can see more types of description macros in /lib/descriptions/description.h
  7. add_proportion() defines the materials that an item is crafted from. In our case we're making an iron dagger so we define it as above. I could extend this out further and add another proportion for Material_Wood and define it as a hilt. Add another proportion for leather and wrap the hilt in leather. Add another proportion for gold and give the dagger some nice inlaid writing. And on and on. You can see the materials that are defined in /def/material/*, and more about the element descriptor in 'man element'

Notes

So the above code is the bare bones minimal effort it takes to create a code-current basic iron dagger. If you're an older coder you may notice several things missing that you are used to. Namely some type of set_id() or set_names(), set_weapon_class() and other such things. The reason we don't need them here is because we are using the power of definitions to our advantage. We tell the object that it's a dagger weapon made of iron and the game can figure out what to call it, how to color it, what weapon class, penetration, attack speed, weight and value it needs to have; among other things.

You can get an idea of how this is possible by checking out the /def/* files listed above. Feel free to browse around while you're in there and get a feel of what's defined and what isn't. <nowiki>Insert non-formatted text here</nowiki>

Personal tools