RPG Questions [Archive] - C Board

PDA

View Full Version : RPG Questions


KneeGrow
10-22-2003, 07:44 PM
Lets say i wanted to make a simple rpg...

Would i use Structs for items/monsters/magic? Is that the best choice?

As for items, would there be a seperate struct for items and weapons since they use completely different variables (as weapons has to do damage etc)

Please gimme some advice

Thanks in advance

revelation437
10-22-2003, 08:04 PM
if my brain wasnt stuck in bio mode, i'd help



need any help with phylums?

revelation437
10-22-2003, 08:09 PM
posted in another thread

typedef enum ITEM_TYPE { IT_WEAPON, IT_POTION, IT_ARMOR, IT_WHATEVER };

struct ITEM {
int minDmg; // damage minimum
int maxDmg;// damage maximum
int costbase;// cost to purchase and sell to be used in formula
int craftxp; // xp you gain from crafting object
char [25] name; // readable name of the object
int id; // numerical value of item for quick comparisons
ITEM_TYPE type; // enumerated type of item
}


ITEM gameItems[230];
// might be a good idea to have a function that can parse a file - with a specific format for item information to fill this array. That way you can modify all your game items in a text file with out recompiling.


if ur using c++
think of a class as a struct where u can check for stuff and what not. less checking code in ur actual code, its all abstractly hidden in the class

KneeGrow
10-22-2003, 08:57 PM
But with that previous post, what woudl the struct look like for a potion for example? What would you do about the maxdamage and mindamage then?

jverkoey
10-22-2003, 09:00 PM
you could turn that in to min health max health and that would be the bounds that it would randomly generate the new health with.......you don't *always* have to follow the naming convention :), well, most of the time you should, but in this case you can make an exception

Jeremy G
10-23-2003, 11:24 PM
Originally posted by KneeGrow
But with that previous post, what woudl the struct look like for a potion for example? What would you do about the maxdamage and mindamage then?

The original code posted was by me, and at the time I was basing the struct off of a weapon crafting rpg test. IN the middle of making the example struct to offer as help I added a feature to maek it more robust(I added the ITEMTYPE to the struct) but I forgot change the variable names to be move vague. THis would be a better example:


typedef enum ITEM_TYPE { IT_WEAPON, IT_POTION, IT_ARMOR, IT_WHATEVER };

struct ITEM {
int min; // minimum value - use is determined by item type. Weapons would equate this to damge
// potions would equate this to healing power
// armor might equate these to armorclass, weight or damge deflecting values
int max;// maximum value - same as above
int costbase;// cost to purchase and sell to be used in formula
int craftxp; // xp you gain from crafting object - potions would call this alchemey
char [25] name; // readable name of the object
int id; // numerical value of item for quick comparisons
ITEM_TYPE type; // enumerated type of item
}


ITEM gameItems[230];
// gameItems would be the games list of all the items in the game.

// else where in your player/character object

ITEM inventory[230][100];
// this is an array of an array. This limits the player to having 100 of every item.


Of course this is a pretty simple item object. A real games item struct would probably be much bigger with a ton more variables that would or wouldnt be used in special item cases. Its up to you to come up with a suitable item object.


Good luck.

KneeGrow
10-24-2003, 06:38 PM
Originally posted by dbgt goten
The original code posted was by me, and at the time I was basing the struct off of a weapon crafting rpg test. IN the middle of making the example struct to offer as help I added a feature to maek it more robust(I added the ITEMTYPE to the struct) but I forgot change the variable names to be move vague. THis would be a better example:


typedef enum ITEM_TYPE { IT_WEAPON, IT_POTION, IT_ARMOR, IT_WHATEVER };

struct ITEM {
int min; // minimum value - use is determined by item type. Weapons would equate this to damge
// potions would equate this to healing power
// armor might equate these to armorclass, weight or damge deflecting values
int max;// maximum value - same as above
int costbase;// cost to purchase and sell to be used in formula
int craftxp; // xp you gain from crafting object - potions would call this alchemey
char [25] name; // readable name of the object
int id; // numerical value of item for quick comparisons
ITEM_TYPE type; // enumerated type of item
}


ITEM gameItems[230];
// gameItems would be the games list of all the items in the game.

// else where in your player/character object

ITEM inventory[230][100];
// this is an array of an array. This limits the player to having 100 of every item.


Of course this is a pretty simple item object. A real games item struct would probably be much bigger with a ton more variables that would or wouldnt be used in special item cases. Its up to you to come up with a suitable item object.


Good luck.

as for the struct that you posted, lets say i have an item that does no damage and is only used for one particular thing. For example this item is a Gem that can upgrade your weapons or a fishing rod to fish some fish. Would u just set item.min and item.max = to 0 since you arent gonna use those?

jverkoey
10-25-2003, 12:30 AM
well, theoretically, if you aren't going to use those values, you shouldn't even have to bother with them at all :)

Jeremy G
10-25-2003, 01:50 AM
Exactly. For example the quake 3 source code has a fairly huge entity struct that has variables for name, health, carried items, speed etc. etc. There are many cases where these variables arnt used. A map entity that spawns say quad or haste doesn't use the health variable, nor does it carry an items. In these special cases the variables simply arnt used. The functions that handle the struct list's loop through the item array checks what type it is, and sends it off to its appropriate handler. The appropriate handler ignores all variables that arn't needed.