Author Topic: Implementing materials for items  (Read 6443 times)

Xan

  • Rogueliker
  • ***
  • Posts: 78
  • Karma: +0/-0
    • View Profile
Implementing materials for items
« on: April 14, 2011, 02:12:18 PM »
This is the state of the question:  I want to make differing kinds of material apply to different kinds of items, e.g., iron, mithril, etc., apply both to weapons and armor that are generally made of metal, and leather, dragon-skin, etc., apply to "cloth" armors, and so forth.

I have in place a generic system for applying modifications to objects, but right now I'm trying to figure out what's a good way to mark item types as implementing various materials, and how to represent those materials in terms of code classes.

For example, mithril material can apply to both armor and weapons, but it has to have very different effects for each (should increase the protection value of the armor, but increase the damage potential of the weapon).  I could represent this by making two classes MithrilWeaponMaterial and MithrilArmorMaterial, but then marking item types as implementing "metal" materials would become more complicated.  Or I could make one class MithrilMaterial, which when called upon to modify protection or offensive values, checks the item to which it is applied to determine the proper effect.  This case makes the single class more complicated, and more computationally expensive, but it simplifies the relation between the item type and material classes.

Comments?  Questions?  Advice?

For those who have implemented some kind of item material system in your own roguelike(s), perhaps you'd like to share a few tips?

Xecutor

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 263
  • Karma: +0/-0
    • View Profile
Re: Implementing materials for items
« Reply #1 on: April 14, 2011, 02:19:44 PM »
I think you will want to study how materials are handled in IVAN.

languard

  • Newcomer
  • Posts: 41
  • Karma: +0/-0
    • View Profile
    • Email
Re: Implementing materials for items
« Reply #2 on: April 14, 2011, 05:07:15 PM »
Also Dwarf Fortress has a very good material system implemented as well, and while the internal code isn't visible all of the material files are.

I would advise against separate properties for armor and weapons.  Taking a page from DF, a material has several properties: How sharp can it get, how heavy is it, how flexible is it, and so on.  Different items are going to care about different properties.  A hammer wouldn't care how sharp it can get, just how heavy is it.  A sword would pull on sharpness and hardness for cutting through things, and weight for how fast it can be swung.  Armor would mainly be concerned with hardness and flexibility, with weight tossed in for movement penalties.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Implementing materials for items
« Reply #3 on: April 16, 2011, 05:46:45 PM »
For those who have implemented some kind of item material system in your own roguelike(s), perhaps you'd like to share a few tips?

I think it's good to keep things simple in a way that things like material knows only what is has to do. Then combine material data with stuff like size and shape of the item to determine the result.