Ask coding questions

← Back to all posts
Database
JustinWu (8)

I'm trying to develop a randomizer for chests and enemy drops, but I can't think of a way how to expand the size of the database without reducing its readability. Is there a more effective way how I can write a data structure which contains vectors of objects than making putting a couple long vectors in a namespace?

The issue I have is focused in the data/assets folder.
(If database is an incorrect way to describe the stuff in said folder, please notify me.)

Answered by Highwayman (1483) [earned 5 cycles]
View Answer
Comments
hotnewtop
Highwayman (1483)

ok now that I'm seeing what you are talking about.. it seems like when you where naming each thing you kind of forget that you're inside a namespace, cause moveSetList::playerMoveSet seems kinda redundant. Probably want to change that to moveSetList::player, instead. or even better, not separate the moves from the actual player, and have Player::MoveSetList or Goblin::MoveSetList type thing. Also, you should probably make some more classes, like a Slash class and a Potion class or something, cause I'm seeing repeats of that. If you make a function or class or something then it can go from a bunch of

{moveObject(0, "Slash", 30, 80, true), moveObject(0, "Lunge", 40, 90, true)}),
// wood set...
{moveObject(0, "Slash", 30, 80, true), moveObject(0, "Lunge", 40, 90, true)}),
// ...
{moveObject(0, "Slash", 30, 80, true), moveObject(0, "Lunge", 40, 90, true)}),

// dagger set...
{moveObject(0, "Slash", 30, 80, true), moveObject(0, "Lunge", 40, 90, true)}),
// ...
{moveObject(0, "Slash", 30, 80, true), moveObject(0, "Lunge", 40, 90, true)}),

to more like

// wood set...
{SlashMove(), LungeMove()}),
// ...
{SlashMove(), LungeMove()}),

// dagger set...
{SlashMove(), LungeMove()}),
// ...
{SlashMove(), LungeMove()}),

ya know what I mean?

JustinWu (8)

@Highwayman
Yeah. Is there another way how I can rewrite the storage of different complete objects other than namespaces and vectors, though? Like a map or something?

Highwayman (1483)

hm... a map sounds interesting.. what if you stored the initializing parameters and names in a text file and then initialize a map to that at run time?

WeaponDefs.txt

Dagger 3 10 5
Sword 10 5 5
Bow 5 5 100

Weapons.cpp

std::map<String, Weapon*> gWeapons;

void initWeapons()
{
  std::ifstream file("WeaponDefs.txt");

  std::string wep_name;
  int wep_dmg, wep_speed, wep_range;
  while(file >> wep_name >> wep_dmg >> wep_speed >> wep_range)
  {
    gWeapons[wep_name] = new Weapon(wep_name, wep_dmg, wep_speed, wep_range);
  }
}

main.cpp or something.

int main()
{
  initWeapons();

  // ...

  player.weapon = gWeapons["Sword"];
}

@JustinWu

JustinWu (8)

@Highwayman
I was actually considering that design, though instead it was for storing player data.

Highwayman (1483)

I can't see your code because of the strange replit loading thing rn, so this might be off topic, but I think you might want to use using statements maybe?

  using small_name = std::vector<std::realy_long_type_name_thats_also_got_more_types_embedded_in_it_and_is_annoying<std::even_more_letters>>;
Coder100 (18248)

try structures

struct MyData {
  std::vector<type> enemy;
  std::vector<>
};

another way would be classes.

Probably you want to use classes more, as you can use constructors.