Author Topic: OO roguelike design  (Read 21980 times)

Ancient

  • Rogueliker
  • ***
  • Posts: 453
  • Karma: +0/-0
    • View Profile
Re: OO roguelike design
« Reply #15 on: March 30, 2011, 11:35:42 PM »
ItemType could be removed?
You mean that removing it i could weld a shield, an armor, a scroll? Is that correct? Looks interesting infact...
This way i could also remove the big switch in the UI and always return the same set of actions for all items... well maybe i could add just some properties (as flags) such: wearable, quaffable etc... otherwise you will have strange things like "wear potion of healing" or "quaff leather armor"...
You grasped the concept fast. At the same time it turns out you have not played much ADOM or POWDER, both famous roguelikes. First allows you to wield potions and then smash them on monsters' heads to apply the effect. Holy water and undead don't mix, neither do harmful potions and unresistant monsters. POWDER has artifact items. Trick is even scrolls can become enchanted items that way. When you have a scroll "Weresmash" which emits light radius you can decide to wield it instead of a torch. Probably in your off-hand to avoid smacking fire elementals with it. Just make sure wielding plate mails does not cause you to get great AC.

Flags work well for most of those actions as you had noticed. Wear can be accomplished by having WearLocation property. None means no WearItem returned. This way you can wear short swords. Set WearLocation = SlotScabbard. :)

Other way is to go with function pointers. QuaffAction would be pointer to function taking two arguments: Quaffer and ItemQuaffed. Null pointer means this item is not quaffable. DefaultQuaff is for potions. It just discards the item and applies effect to Quaffer object. BloodBaneQuaff is for legendary artifact sword "The BloodBane". This weapon drinks blood on successful hits and may increase its own enchantment up to +10. It stores the blood inside its core. The player may opt to put his mouth against the sword's hilt to drink this blood in order to regain many lost hit points. There is a cost: this action resets BloodBane's enchantment to -1. Thus BloodBaneQuaff restores HP of Quaffer object, and reduces enchantment of ItemQuaffed object.

Decide how far you want to venture. Since you expressed wish to make simple roguelike my recommendation is to go mostly with flags.


Ah, and I did remove ItemType once. Then I ended up with crude code for UI like this:
Code: [Select]
if item has damage and item has range
  category = ranged weapon
if item has damage and has magic cost
  category = combat wand
As you see this is pretty evil. I learned and brought back ItemType just renamed it to ItemCategory.

What do you think about the Decorator pattern for items? You have one big interface IItem with all item properties. You have one big ConcreteItem class that implements the interface returning all default zeros/false values. You then have an ItemDecorator class that implements the IItem interface delegating all methods implementation to an object implementing the IItem interface given in the constructor. So to have a quaffable/throwable/weldable item you do the following:
Code: [Select]
  IItem coolItem = new Quaffable(EFFECT_HEALING, new Throwable(RANGE_POTION, new Weldable(DAMAGE_POTION, new ConcreteItem())));
Looks neat! I must admit my practical knowledge with OOP is a bit limited. Since I'd hate to mislead you here a link to a post very much on topic. This will probably help you much more than I would: Item Depiction questions.
Michał Bieliński, reviewer for Temple of the Roguelike

programmerlike

  • Newcomer
  • Posts: 11
  • Karma: +0/-0
    • View Profile
    • Email
Re: OO roguelike design
« Reply #16 on: March 31, 2011, 12:58:13 PM »
Quote
This will probably help you much more than I would: Item Depiction questions.

Read it. It's very interesting and matches what i came up after our discussions. The most interesting part was about the ability to make aniything zap in an easy way, just a pointer to a "zap effect" or similar. So "sword of lightining" it's just a long sword with the ZAP_LIGHTINING effect set into it.

Cool!

MrMorley

  • Newcomer
  • Posts: 24
  • Karma: +0/-0
    • View Profile
    • Jason's Development Blog
    • Email
Re: OO roguelike design
« Reply #17 on: April 02, 2011, 07:32:34 PM »
At which point you could easily start going into component systems.

OOP is still obviously very useful for a lot of core engine things, but trying to hard-code everything in a game more simple than space invaders is somewhat of an anti-pattern.

Dungeon Siege used such a system, and a presentation can be seen here: http://scottbilas.com/files/2002/gdc_san_jose/game_objects_slides.pdf
« Last Edit: April 02, 2011, 07:42:23 PM by MrMorley »
Jason's Development Blog
Nerds who program party hard