0
\$\begingroup\$

To learn more about AI during combat, I made a demo in Unity where a player would fight a creature in an arena. I started here because I plan to implement the system I'm working on in another game. In that game, there are a lot of different creatures a player has to fight.

These creatures have a body part set, a move list, an attribute set and a drop table for that type of creature. Currently I'm managing this by a big static class with drop tables, move tables, monster tables and item tables and so on in them. When a creature gets instantiated it copies monster data from that static class and when it dies items in the referenced drop table are instantiated, copying some data from the item table. Whenever a monster performs a move, the necessary information is looked up in that static class.

I could solve monster data by copying the necessary data into the monsters and then dispose of the class, but that leaves no option for items, which are referenced by ID and need to be looked up frequently. Serializing and deserializing the data wouldn't make sense if I would have to load the entire item table or unit attributes every time every time I access them. Keeping the entire game data loaded all the time doesn't sound like the best way to go about managing my data.

My own system is becoming unmanageable. Because I'm targetting Android, I'm also, to a lesser degree, worried that having such a big static class loaded all the time will become a burden once more features are added to the game. I have read this post but didn't find it of much help.

Which ways are there to improve from the current situation? How could I handle a frequently used item table/database more efficiently. And on the other side, how could I handle a move table and monster table better? How did NetHack do it, for example?

\$\endgroup\$
4
  • \$\begingroup\$ "Over a thousand items" isn't actually that much, even for mobile devices. How much data does one entry in your item database contain after deserialization? A hundred byte? Maybe a thousand? Then you are still in the order of 1 MB for all of them. Even low-end Android smartphones have several hundred MB of RAM. \$\endgroup\$
    – Philipp
    Dec 8, 2016 at 14:41
  • \$\begingroup\$ @Zimano have a look at this pattern also you could do a search for data driven design. DDD At it's most basic is just having a single class but loads in all its stats from a .txt or other file to make up many different objects in the game. \$\endgroup\$
    – lozzajp
    Dec 9, 2016 at 8:29
  • \$\begingroup\$ Have you calculated how much memory your dictionary will actually use? What about the latency your lookups cause? Is this even a problem for your target devices? Sounds more like premature optimization. \$\endgroup\$ Dec 12, 2016 at 5:06
  • \$\begingroup\$ @NickSavage My worry about performance was secondary. My primary reason was that the current implemented system is becoming unmanageable for me. I can assure you this is not premature optimization. I will make that more clear in the original question. \$\endgroup\$
    – Zimano
    Dec 12, 2016 at 16:05

1 Answer 1

-1
\$\begingroup\$

You should remove the static class and start using polymorphism, you should have an abstract superclass (maybe monster). Each monster should inherit from that and it should hold all data for its moves, stats etc. Items should be loaded when the monster is loaded and the monsters should have references to all of the items in their possession.

\$\endgroup\$
4
  • \$\begingroup\$ The data has to come from somewhere. You are actually describing my current approach but without a static class where universal data is saved. I have downvoted you as I feel like I already adressed the subjects you are talking about in my original question. \$\endgroup\$
    – Zimano
    Dec 8, 2016 at 15:16
  • \$\begingroup\$ My question is about how the data should be stored, its persistence and how it is accessed in regards to the frequency of the use of the data. \$\endgroup\$
    – Zimano
    Dec 8, 2016 at 15:23
  • \$\begingroup\$ Your question was about how you could improve your structure, and removing the static class is one of the key ways to do that. If your question is about the appropriate technologies to store the data in a persistent database it should be re-written as this is not clear. \$\endgroup\$
    – benh
    Dec 8, 2016 at 16:29
  • \$\begingroup\$ Removing the static class would mean removing the entire game database. I have already addressed the need to remove or transform the static class, as it was the basis for the question. \$\endgroup\$
    – Zimano
    Dec 8, 2016 at 19:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .