Coding Class: Dagger

From LSWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 22:45, 8 May 2008 (edit)
Matts (Talk | contribs)
(Code Discussion)
← Previous diff
Revision as of 22:53, 8 May 2008 (edit)
Matts (Talk | contribs)

Next diff →
Line 1: Line 1:
-#include <item.h>+ 1) #include <item.h>
- inherit "/std/item";+ 2) inherit "/std/item";
- void configure() {+ 3) void configure() {
::configure(); ::configure();
- weapon()->set_weapon_type(Weapon_Type_Dagger);+ 4) weapon()->set_weapon_type(Weapon_Type_Dagger);
- set_craft(Craft_Good);+ 5) set_craft(Craft_Good);
- add_description(Description_Type_Generic);+ 6) add_description(Description_Type_Generic);
- add_proportion(([+ 7) add_proportion(([
Element_Type : Material_Iron, Element_Type : Material_Iron,
Element_Proportion : 1.0, Element_Proportion : 1.0,
Line 32: Line 32:
* /std/item.c * /std/item.c
 +==== Code Comments ====
 +# Includes our generic item header file which is a collection of other useful header files.
 +## 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.
 +### 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.
 +#### 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
 +#####
==== Code Discussion ==== ==== Code Discussion ====
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>

Revision as of 22:53, 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.
    1. 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.
      1. 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.
        1. 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

Code Discussion

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