How to store monsters, items, etc.

Started by
7 comments, last by Srekel 20 years, 8 months ago
This is more of a programming question: Is it better/easier/somehow more benificial to store item and monster data (such as Attack skill, Life, etc.) in classes in the program, compared to storing them in .cfg-files and opening them every time you play/create a monster? Or is it the other way around?
------------------"Kaka e gott" - Me
Advertisement

If your talking about static data I would use included structures ("data.h") and load them by copy or by pointer when the class is created.
Yeh, why not just have all the preconfigured monster settings e.g. hp they have and damage they do in your cfg files and when the game initializes load in all the data from the cfg into the predefined classes. That way it may take a bit of extra loading time but the game will never need to stop and read in data from files during the game which should keep it running efficiently.
hmm, well I started in JAVA so I may be biased but I think classes are the way to go. Using inheritence and polomerization. Seems to me the best way to orginze all your data. You can have item class with a weapon subclass, and then a subclass of weapon for each weapon. Then whenever an item is need you create an instance of that class. You then do all your updates and modifications to that instance and release it when its nolonger needed.

This also allows you to include dynamic items instead of static, so if you want to allow the player to name his weapon, or custimze you can.

How the data gets into the game is upto you, it can all be programmed and complied or I can like your other idea about loading it in from files. If it did that at the start of a new game or when loading a game, it would allow you to make changes to the game without having to recomplie it.


-----------------------------------------------------
Writer, Programer, Cook, I''m a Jack of all Trades
Current Design project
Chaos Factor Design Document

quote:Using inheritence and polomerization. Seems to me the best way to orginze all your data.


I do believe you mean polymorphism. Polymerization is the combination of monomers to form a new compound.

-Auron
quote:Original post by TechnoGoth
hmm, well I started in JAVA so I may be biased but I think classes are the way to go. Using inheritence and polomerization. Seems to me the best way to orginze all your data. You can have item class with a weapon subclass, and then a subclass of weapon for each weapon. Then whenever an item is need you create an instance of that class. You then do all your updates and modifications to that instance and release it when its nolonger needed.

This also allows you to include dynamic items instead of static, so if you want to allow the player to name his weapon, or custimze you can.

How the data gets into the game is upto you, it can all be programmed and complied or I can like your other idea about loading it in from files. If it did that at the start of a new game or when loading a game, it would allow you to make changes to the game without having to recomplie it.




Excellent descriptions of my problem. I guess if it is a huge project, then files would be the way to go. On the other hand, you probably have to recompile every now and then anyways, which means that you could "throw in" the changed item-classes at the same time...
------------------"Kaka e gott" - Me
I recall a recent discussion in another forum, and the conclusion was that use different classes when only different behaviour is required. For different data is it better that you load it from a file. For example: In a rather simple game you might only require two derived weapon classes, from a common base class like this:

class CBaseItem{public:    virtual void Create(ITEM_DATA *data); //default data storage, might be overridden to store additional data};class CBaseWeapon : public CBaseItem{public:    int m_damage; //data    char m_name[32]; //data    int m_graphic; //data    virtual void Attack(void); //behaviour    void Create(ITEM_DATA *data); //is overridden here to load static data specific to all weapons};class CMeleeWeapon : public CBaseWeapon{public:    void Attack(void); //attack behaviour is defined here for melee weapon};class CRangedWeapon : public CBaseWeapon{public:    int m_range; //data specific to this class    void Attack(void); //once again attack behaviour is redefined by another class    void Create(ITEM_DATA *data); //override again to load the m_range member};struct ITEM_DATA{    //this structure contains a list to the raw loaded data attributes for an item, and is passed as a parameter for item creation};vector<ITEM_DATA> item_data; //store this somewhere


Then, in a separate data file you might do this:

item startname = "Short sword"class = "CMeleeWeapon"damage = 5graphic_id = 54item end


During loading time all data is loaded from the designated data files. Then the appropiate class can be created, and the appropiate data initialized into the class. This example might not be the most thought through one, but it illustrates my point.

[edited by - Unwise owl on July 27, 2003 2:23:24 PM]
Maybe I''m just crazy, but why on God''s Green Earth would you put the data in your code? I mean, if you are having game balance issues (too easy, too hard, impossible for one type of character, etc...) then wouldn''t it be easier to just edit the data in a config file and then test again as opposed to recompiling every single time that you need to test balance?

How would you make different difficulty levels and keep those balanced?

It''s all about testing and giving the player options. It''s easy to do with separate files, more difficult to implement and test it if it''s in the code.
Well, you really never put your data in the code, you load it in. Though after writing that i see how once you have the game balanced to your liking, hardcoding has its benefits in security. Its a bit harder for people to make character hacks etc if all the data isnt right in front of them in a file. Only a bit harder, not by much. They can still find out where in memory this variable is and change it. So one again on second thought load your data, dont hardcode much. If you have hardcoded data you dont have an engine, you have a hack.

something...

This topic is closed to new replies.

Advertisement