Coding Class: Dagger
From LSWiki
Revision as of 21:37, 8 May 2008 (edit) Matts (Talk | contribs) (→Important Header Files) ← Previous diff |
Current revision (13:38, 28 May 2008) (edit) Aedhan (Talk | contribs) |
||
Line 1: | Line 1: | ||
- | // Include our base header file | + | 1) #include <item.h> |
- | #include <item.h> | + | 2) inherit "/std/item"; |
- | // Inherit our base object for what we're creating | + | 3) void configure() { |
- | inherit "/std/item"; | + | ::configure(); |
- | // configure() is where we define what the object -is-, and indirectly what it does. | + | 4) weapon()->set_weapon_type(Weapon_Type_Dagger); |
- | void configure() { | + | 5) set_craft(Craft_Good); |
- | // Call the configure() function from the file we inherited above. This really only calls one other function but it's necessary so that everything we're about to do works. | + | 6) add_description(Description_Type_Generic); |
- | ::configure(); | + | 7) add_proportion(([ |
- | // Call set_weapon_type() in the weapon extension and set it to Weapon_Type_Dagger (since we're making a dagger!) | + | Element_Type : Material_Iron, |
- | weapon()->set_weapon_type(Weapon_Type_Dagger); | + | Element_Proportion : 1.0, |
- | // Set the craft of the item. | + | ])); |
- | set_craft(Craft_Good); | + | } |
- | // Setup a general default description. | + | |
- | add_description(Description_Type_Generic); | + | |
- | // Setup the materials and forms and parts that we want our dagger to be made of. | + | |
- | add_proportion(([ | + | |
- | Element_Type : Material_Iron, | + | |
- | Element_Proportion : 1.0, | + | |
- | ])); | + | |
- | } | + | |
==== Important Header Files ==== | ==== Important Header Files ==== | ||
Line 35: | Line 27: | ||
==== Important Source Files ==== | ==== Important Source Files ==== | ||
+ | * /def/material/i/iron.c | ||
+ | * /def/weapon_type/d/dagger.c | ||
* /obj/extensions/weapon.c | * /obj/extensions/weapon.c | ||
* /std/item.c | * /std/item.c | ||
- | ==== Code Discussion ==== | + | ==== 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 | ||
+ | # set_craft() defines the craftsmanship of the item in question. The craft types available are in /lib/craft.h | ||
+ | # 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 | ||
+ | # 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.<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. | ||
+ | <br><br> | ||
+ | [[Category: Coding Class]] |
Current revision
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
- 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
- set_craft() defines the craftsmanship of the item in question. The craft types available are in /lib/craft.h
- 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
- 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.