What is an entity ?
An entity is anything that has a specific position on the world map. An entity has properties and conditional features. There are some basic features which divide entities into several subclasses :
- 'static' feature : a static entity cannot move on the map. It cannot be taken or pushed. For example : doors and traps or big containers like barrels and crates that the player is not supposed to take in his inventory.
- 'soul' feature : this is an animated entity which moves or acts by its own will. These are mainly creatures and npc. Most entities with soul have other features which describe how they move or act.
- entities which have neither static, nor soul features are items, which can be taken, used or combined by the player.
Why using generic entities ?
What would be the benefit of having a generic class or struct for all game entities ? Why not coding separately objects (doors, traps), items (weapons, armors, ...) and creatures ?
I see some evident avantages :
- a single file format for most of the game parameters
- only features are harcoded, which mean less code and hopefully less bugs
Creatures are items
Some of our items are containers. The 'container' feature adds a list of items to the container item. Why not using this same list for the creature inventory ? By simply adding the 'container' feature to all 'soul' entities, we have the backbone of the inventory system without a single line of code.
Since creatures are items, the player could put living creatures in its inventory and even equip it. What about an acid spitting worm instead of a standard sword ?
Items are creatures
Some creature have the 'slot' feature. This feature adds slots on which we can equip items. For a humanoid creature, we have head, neck, torso, arms, wrists, hands, legs, feet slots. We can equip armors and weapons on these slots. Now if we use the same feature on an item, we have we got ? A sword with a pommel slot and two rain guard slot. We can equip other items (enchanted gems) on this sword to change its characteristics. From the engine point of view, there is few differences between equiping a sword with a +2 DMG gem and equiping the player with a +2 DMG dagger.
Since items are creatures, we can give will or even dialogs to some objects.