Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - programmerlike

Pages: [1]
1
Programming / Re: OO roguelike design
« 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!

2
Programming / Re: C# Automatic XML Deserialization
« on: March 31, 2011, 12:54:26 PM »
Yeah that's very similar to serialization mechanism already included in .NET!
It's just simpler to use and needs less attributes configuration to make it work. Obviously it just supports XML (.NET can serialize to binary files to) but it's pretty straightforward to use... also, i have a simple way to tell the serializer which fields must be included and which can be omitted (the Optional property of the AutoSerializerAttribute).
Of course .NET is better, faster and probably my lib still have some bugs... it's just simpler to use and more dedicated to XML. By the way it's indeed nothing amazing but just a tool to make things work as soon as possible for me without messing around with a lot of .NET attributes.
Anyway you did good making non .NET experts notice that this feature already existed natively in the language and that my library is just a home-made way to do a small portion of what .NET does in a simpler to understand way.
I'm still debugging it and also i have to add more detailed documentation.

If someone is still interested i will make it available as open source project as soon as it's good enough to show it.

3
Programming / Re: C# Automatic XML Deserialization
« on: March 31, 2011, 12:26:32 AM »
Ok... I just want to point it out... I made a general purpose xml library that can read any class from a file and not just item or monster. You create class "C" then call the loader and it understands how to load it without you coding the parser or providing the load method any additional parameter. It is achieved using type reflection.

4
Programming / Re: C# Automatic XML Deserialization
« on: March 30, 2011, 09:59:17 PM »
Maybe you misunderstood me...
My post was about a class i made that at runtime looks up into public fields of your class and finds xml tags with the same name, then fill those fields with data. Also arrays and nested complex objects are supported. Whatever class you want to load from xml you don't have to code anything!
Since you agree with me that easy data importing is a must have feature i hope you find my effort uefull. Anyway it's c# so you cant' use it in c++ code.

Hope this time was more clear!

5
Programming / C# Automatic XML Deserialization
« on: March 30, 2011, 09:09:48 PM »
Hello,

i did just finished to code a parser that can automatically fill class data from an Xml using reflection (it's c# but it could be easily translated to java).
Look at the following data (real example from the roguelike i'm working on):

Code: [Select]
    class Roll
    {
        [AutoSerializer(Optional = true)]
        public int Base
        { get; set; }

        public int Dice
        { get; set; }
       
        public int Faces
        { get; set; }

        public override string ToString()
        {
            return string.Format("{0}+{1}d{2}", Base, Dice, Faces);
        }
    }

    enum PotionKind
    {
        Healing = 0,

        Mana = 1       
    }

    class ItemTemplate
    {
        public string Name
        { get; private set; }

        public double Weight
        { get; private set; }       

        [AutoSerializer(Optional = true)]
        public bool IsStackable
        { get; private set; }

        [AutoSerializer(Optional = true)]
        public Roll Damage
        { get; private set; }

        [AutoSerializer(Optional = true)]
        public int Protection
        { get; private set; }

        [AutoSerializer(Optional = true)]
        public PotionKind PotionKind
        { get; private set; }

        [AutoSerializer(Optional = true)]
        public bool IsWeldable
        { get; private set; }

        [AutoSerializer(Optional = true)]
        public bool IsWearable
        { get; private set; }

        [AutoSerializer(Optional = true)]
        public bool IsQuaffable
        { get; private set; }

        [AutoSerializer(Optional = true)]
        public bool IsProjectile
        { get; private set; }

        ItemTemplate()
        {
        }
    }

The Optional property of the AutoSerializerAttribute tells the serializer that that property can be omitted in the xml file.
OK... now this is a test XML file:

Code: [Select]
<?xml version="1.0" encoding="utf-8" ?>
<GameData> 
  <ArrayItem>   
    <Name>Leather Armor</Name>
    <Weight>4.5</Weight>   
    <Protection>3</Protection>   
    <IsWearable>true</IsWearable>
  </ArrayItem>
  <ArrayItem>
    <Name>Long Sword</Name>
    <Weight>1</Weight>   
    <Damage>
      <!-- 2+2d6 -->
      <Base>2</Base>
      <Dice>2</Dice>
      <Faces>6</Faces>
    </Damage>   
    <IsWeldable>true</IsWeldable>
  </ArrayItem>
  <ArrayItem>
    <Name>Potion of Healing</Name>
    <Weight>0.1</Weight>
    <PotionKind>Healing</PotionKind>
    <IsQuaffable>true</IsQuaffable>
  </ArrayItem>
</GameData>

Now you just need to run the following method:

Code: [Select]
ItemTemplate[] items = AutoSerializer.Load<ItemTemplate>(xmlFile);

And the "items" array will be filled with the data from the XML file.
The system also supports nested arrays:

Code: [Select]
    class SomeObject
    {
        public int[] SomeValues
        { get; private set; }
    }

Code: [Select]
<?xml version="1.0" encoding="utf-8" ?>
<GameData> 
  <ArrayItem>
    <SomeValues>
      <ArrayItem>1</ArrayItem>
      <ArrayItem>2</ArrayItem>
      <ArrayItem>3</ArrayItem>
    </SomeValues>
  </ArrayItem>
  <ArrayItem>
    <SomeValues>
      <ArrayItem>4</ArrayItem>
      <ArrayItem>5</ArrayItem>
      <ArrayItem>6</ArrayItem>
    </SomeValues>
  </ArrayItem>
</GameData>

WELL... maybe no one is interested in it... just wanted to know your opinion...

6
Programming / Re: OO roguelike design
« on: March 30, 2011, 01:38:13 PM »
I love when i have to admit i was wrong because it means i learned/understand something new...
I switched to the single ItemEntity class design.
The "big swith statement" is currently only in the UI code (as Ancient already correctly pointed out)...
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"...
So my UI code could look like this:
Code: [Select]
ActionList GetItemActions(Item item)
{
  ActionList actions;

  if (item.IsWearable())
    actions.Add(new WearItem(item));
  if (item.IsQuaffable())
    actions.Add(new QuaffItem(item));
  // etc...

  return actions;
}

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())));

Each Decorator implementation overrides only relevant methods of the ItemDecorator class.
For example:
Code: [Select]
  //
  // VERY C# LIKE CODE
  //
  class Quaffable subclass of ItemDecorator
  {
    int potionType; // set in the constructor

    public Quaffable(int potionType, IItem baseItem)   
    {
       baseClassConstructor(baseItem);
       this.potionType = potionType;
    }

    public int overrides GetPotionType()
    {
       return potionType;
    }

    public bool overrides IsQuaffable()
    {
       return true;
    }
  }

A datafile for that item could look like the following:
Code: [Select]
ITEM
  NAME=Potion of Healing
  UsabilityFlags=QUAFFABLE | THROWABLE | WELDABLE
  // Reading those flags the parser is smart enough to ignore useless values (for instance ArmorClass)
  Effect=EFFECT_HEALING
  Range=RANGE_POTION
  Damage=DAMAGE_POTION
END ITEM

OK... another huge post... hope someone reads it!
Regards!

7
Programming / Re: OO roguelike design
« on: March 28, 2011, 09:25:26 PM »
Your approach seems good to me... but, if you read my class hierarchy, you'll notice that ItemEntity objects tell you the actions an actor can do with them. For example the Weapon class will return the following actions:
  -WieldWeapon (if not weld already)
  -DropItem (if not weld)
  -PutAwayWeapon (if weld)
With your approach i'd need a big switch statement on the "ItemType" field of ItemEntity and i don't like it.
For my simple first roguelike project i'm sticking with my pattern but i clearly understand your point and probably doing things your way leads to more flexibility... tnx anyway.

8
Programming / Re: OO roguelike design
« on: March 28, 2011, 12:34:22 PM »
OK... i received a lot of feedback and i'm happy with your suggestions/comments.
I'm actually coding a test-bed for this "framework".
When i get it working i'll be posting a download link here to show you what i have achieved.

Bye

9
Programming / Re: OO roguelike design
« on: March 27, 2011, 10:14:03 PM »
For your project would it be easier to assign 1 color variable to the entity? This way the background can be printed by your rendering engine by whatever color tile the entity is sitting upon. Blue water, brown ground or green grass, with a white @ sitting on it?

It's possible, of course, but it's something i can change later since now i'm more concerned with the basic processing framework (and not with rendering).

10
Programming / Re: OO roguelike design
« on: March 27, 2011, 09:45:46 PM »
Tnx for all of your replies!

i'm already storing "appearence" of entities in a static table... that was only to make it simpler to understand in my previous post.
It's like this:

class Icon
{
   glyph and colors
}

class IconSets
{
  // if visible is false i use grayed-out colors (for fog of war)
  static Icon[] GetDungeonCellsSet(bool visible) { ... }

  // hero, monsters, weapon, armour, potion etc
  static Icon[] GetEntitiesSet() { ... }
}

class Entity
{
   Icon Icon;
   and the rest...
}

I'm thinking about the following interface:
Numpad to move
Spacebar to pop up a menu (text lines with a frame around it)
Entries of this menu are:
  Rest
  Ranged Attack (only if you have a ranged weapon equipped)
  Inventory
  Spells

Inventory and Spells will display submenus.
ItemEntity class has a method that returns a list of actions that you can do with it.
Example:

class Weapon subclass of ItemEntity
{
   ActionList WhenSelected(Actor actor)
   {
      ActionList A;
 
      if (!actor.Equips(this))
        A.Add( WieldAction(this) );
      A.Add( DropItemAction(this) );

      return A;
   }
}

So if you select Inventory and then a weapon, you'll see two possible actions, wield and drop.
For spells, instead, after you choose one you will be prompted to select target square.

Please let me know what you think... i'm starting to code the framework right now to see if it works...

11
Programming / OO roguelike design
« on: March 27, 2011, 05:03:42 PM »
Hello there,

i discovered this community when i decided to start my first roguelike project and immediately registered in order to share my ideas with you experienced roguelike programmers...
I'm NOT new to game programming, this is just my first roguelike game.
I intend to use c# with no additional library (i know most people use some version of the curses lib). I know that a large part of you think that many aspects of roguelikes are not to be designed in advance but i think it would be wise to design the major framework at least...

I want to share with you the data structures i had in mind (pseudo-code, of course):
 
  // entities represents anything in the dungeon
  //
  class Entity
  {
    Char glyph;
    Color Background;
    Color Foreground;
    int X, Y;
  }

  // hero and monsters are actors
  //
  class Actor subclass of Entity
  {
    abstract Action Think();
  }
 
  // an object that tells you the next actor that has to make
  // a move
  //
  class ActorScheduler
  {
    Actor Current;
    void GoNext() { ... }
  }
 
  // an action is anything that an actor can do
  // examples are:
  //   MoveAction
  //   UseItemAction
  //   AttackAction
  //   etc
  //
  class Action
  {
    abstract void Execute();
  }

  class Dungeon
  {
    grid of tiles (empty, wall, corridor, room, door etc)
    list of entities
  }

The main loop should look like this:

  Action action = actorScheduler.Current.Think();
  action.Execute();
  actorScheduler.GoNext();
  // maybe update fov, stats display etc...
  repeat untill gameover

That's all about the framework. Another thing i had in mind was the following:

  class Entity
  {
    everything like before

    // This method has the following meaning:
    // if the hero touches this entity, what happens?
    // for example an ItemEntity should return the PickUpItemAction
    // I'd really appreciate suggestion for the name of this method...
    // I know that ProvidedInteraction is not very clear...
    //
    Action ProvidedInteraction(Actor actor);
  }

WELL... i know it's a long post but i hope someone reads it all and shares his opinion with me...

Bye

Pages: [1]