Weapons' names generator

I'd like to make a simple generator of names for weapons, in this format:
adjective type_of_weapon
for example:
hero's bow

Words would be stored in a text file. Name would be randomly generated from adjective and type of weapon from the file. I'd like a text file to have such format:

adjectives: // these adjectives can be combined with every type of weapon
hero's
deadly
type:
adjective_for_that_type // adjective only for this type
another_type:
...

This way you could decide which adjectives and types of weapons you would like to generate w/o changing the code. I don't know how to store words from the file after reading them. I only want a description of how to do it, not code.
Last edited on
I know this is not what you're asking, but I really think that you should use JSON. Take a look: http://json.org/
I don't know how to store words from the file after reading them
Just have a container of strings for each type + one for common adjectives.

Then when you need to generate name for a weapon select one from combined pool of common and type specific adjectives.
@iQChange: Should I use JSON instead of a txt file? If yes, is this format correct?
{
	"adjectives" : [
		"hero's",
		"deadly"
	],
	
	"bow" : [
		"accurate",
		"fast"
	]
	
	"katana" : [
		"sharp"
	]
	
}


@MiiNiPaa So I should store an array of arrays of strings, and reallocate it with one more field every time program finds new type of weapon?
@TheHardew Pretty much. But if you're using C++, you won't have to mind how it looks like. Grab a lib and it does all the ugly stuff for you.
You can have a map weapon typevector of strings.
That way you can even have multiple entries for weapon type and even support for loading from different files easily.
bow:
sniper's

universal:
deadly

bow:
Odysseus'
What @MiiNiPaa said could be written as std::map<T, std::vector<std::string> > where T is the type in which you store the weapon's type. (e.g.: string)
So now I've got to learn about std::map and find some good JSON library. Thanks guys for your help!
Topic archived. No new replies allowed.