Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: What's the Most Efficient Way to Program This?  (Read 4498 times)

0 Members and 1 Guest are viewing this topic.

Koh

What's the Most Efficient Way to Program This?
« on: August 09, 2013, 01:07:42 am »
  • Tamer Koh
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 980
So I've been thinking about a little something I want to program into the World of Chaos games, and that's randomized equipment drops.  Like for example, when a monster is about to drop a Knife, instead of just getting a Knife, you have a chance to get a Polished Knife (which would be better than the regular Knife), or a Damaged Knife (worse than the regular Knife), and other tiers of such.  I was mostly thinking about how the heck I should approach this efficiently.

My primary thought is to have an array that represents an inventory (naturally) of 32 or however many slots for each class of item I want:  Consumables, Weapons, Armor and Key Items.  Inside this array is stored an ID number to represent an item.  My main focus is the Weapons (since the same could be done for the armor) array.  The values stored here would be ID numbers that represent an item...for example, 0 could be a Knife, 1 could be a Machete, 2 could be a Bronze Sword, etc.  However, I'd need another array that's adjusted alongside this that stores the adjusted "class" of the item.  0 would mean it's a plain old Knife, for example, 1 would mean it's a Polished Knife, 2 would mean it's a Damaged Knife, etc.  And finally, I'd need to create two lookup arrays; quite possibly 2D-arrays.   One with all of the weapons having their base values for each stat stored.  For example, 0, 0 would represent Knife's base Power stat, 0, 1 would be the Knife's base Fort stat, and etc.  The second 2D-array would be for the special classes, and how  much they modify the other values by percentage.  So 0, 0 would represent how much Polished affects the Base Power, 0, 1 would represent how much Polished affects the Base Fort stat, and etc.  The only problem I'm seeing with this method (besides being a bit weird to keep track of once the tables get pretty big) is...what if I want weapons to get random bonus stat increasers as well.  For example, you may pick up a plain old knife again, but this one has a +2 Power bonus.  Do I need to make the array that stores the special classes of each specific weapon in the weapons array a 2D array to store bonus changes too, also creating a bonus lookup table as well? And is this the most efficient route, or way more work than necessary?

I hope I'm being clear enough...this is boggling my mind.
Logged
  • Megaclipse Games

Starforsaken101

Wake the Beast
Re: What's the Most Efficient Way to Program Thi...
« Reply #1 on: August 09, 2013, 11:43:44 am »
  • www.mouffers.com
  • *
  • Reputation: +69/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2577
Okay, well no offense but your solution boggled my own mind a little, which tends to mean you're just equally as boggled as well. Here are my two cents on this topic:

First off, do you have a designated class per weapon or some sort of label on the weapon that tells the program what kind of weapon it is? For instance, do you have a Bronze Sword class? If you do, I would store a LIST or a VECTOR (not an array, man) of quality types it has. Equally, for the user's sake and general cleanliness, I would make an Enum class that stores the quality types as so:

enum SHITTY_QUALITY = 0
enum KINDA_OKAY = 1 etc etc (please excuse the pseudo-code, I've been hopping back and forth between AS3 and C# for the past couple of weeks)

So in your list, you'd have a list of these enums that you could lookup. If you want to tie in the effects with it, you could have some sort of Effects class that holds all of the effects you want and store a Dictionary<Quality,Effects> or something in your weapon class instead.

I'm not entirely sure all of that !@#$% made sense but if you want to talk more about it, just message me up or something.
Logged
  • Starforsaken101's DeviantART
Re: What's the Most Efficient Way to Program Thi...
« Reply #2 on: August 09, 2013, 01:02:16 pm »
  • ...---^^^---...
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 616
What programming language are you using?  I will respond as though you are using Game Maker because that is what I use, but the concepts should be able to be applied to whatever you are using.  Also, I am not entirely sure I am understanding your situation...  But.

It might be a good idea to make your weapon inventory into a list of lists...  By this I mean.

Every time you pick up a new weapon instead of just storing the ID of the weapon to the list, store a list of its attributes to the list.  This could be done in a number of ways and I can't say that I know which would be the most efficient, but what I might try to do is something like this.

Instead of just reserving a spot in the list for the ID of the weapon, you can reserve say...  10 slots in the list for the weapons ID and then its special attributes.  So when you add the newly acquired weapon you will write the ID to the list and then all of its attributes in the same list.  Then when you need to read the information from the list you will have to remember how many slots of data are allotted per weapon and then just loop through and read all the data from the one list.

Alternatively you could store each weapon and its attributes to its own mini list, and then store all the ID's of the different weapon lists to a larger master list.  Then when you need to call the data you can call the correct weapon list from the master list and then read the weapon ID and attributes from that list.  An example of what you might store in you mini list would be...

[ 0] = Weapon ID;

[1] = Level of Polish;
[2] = Sharpness;
[3] = Age of Equipment;
[4] = Fire Attribute;
[5] = Water Attribute;
[6] = Lightening Attribute;

The default value for each of the attributes would be 0.  Then you can store a value anywhere from -1 to 1 indicating that the knife is either completely dull (-1) or as sharp as it could possibly be (1).  Then when you build your equations that determine how much the weapon hurts the enemy, you will need to make sure that each of the attributes are worked into the equation.

This methode is assuming that you have stored somewhere else the base damage or strength of the particular weapon...  However you could also store this information in the above list as well, kind of like this.

[ 0] = Weapon ID;
[1] = Power of Weapon;
[2] = Weapon/Armor Defense
...
...

[3] = Level of Polish;
[4] = Sharpness;
[5] = Age of Equipment;
[6] = Fire Attribute;
[7] = Water Attribute;
[8] = Lightening Attribute;
...
...
...

Not sure if this makes sense, but it would be one way of doing it if I am understanding your problem correctly.  Hope it helped.   ;)

« Last Edit: August 09, 2013, 01:08:34 pm by Aero88 »
Logged

Koh

Re: What's the Most Efficient Way to Program Thi...
« Reply #3 on: August 09, 2013, 02:10:49 pm »
  • Tamer Koh
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 980
@Starforsaken101
Oh, you totally reminded me of the existence of ENUM in C++.  I haven't used that since I took the first level programming class, despite how insanely useful it is.  I'm sorry, though, because I should have specified I was doing this in Game Maker.  I've never attempted to build a game in C++, though it IS something on my to do list, since I'm getting much more familiar with the language deep down as I climb the programming language classes (finished Object Oriented Programming two semesters ago, and totally understood it all, because of my experience with Game Maker).

@Aero88
The second half regarding a list of attributes and IDS is what I was leaning towards the most.  A 2D array, where the first value represents the inventory slot, and the second value represents each specific attribute as you listed.  The modification to this is I have the IDs set up first, at which the stat values will be read from a text file (instead of loading in a massive array of ALL the weapon stats into active memory) into the correct array locations.  Like this:

Code: [Select]
/*
2D array for storing items.  First value represents the inventory slot
number of an item, the second represents specifics:

Second Value Meanings
00 = Is there an item here or not (boolean).
01 = Item class (0 = knives, 1 = swords).
02 = Item ID of the item class.
03 = Special Quality ID (used for equipment).
04 = Name of Item
05 = Level Requirement
06 = Power Modifier
07 = Fort Modifier
08 = Mystic Modifier
09 = Stamina Modifier
10 = Energy Modifier
11 = Sprite for the item in the HUD.
*/
global.inventory[25,10]=0;
Logged
  • Megaclipse Games

Starforsaken101

Wake the Beast
Re: What's the Most Efficient Way to Program Thi...
« Reply #4 on: August 09, 2013, 02:22:48 pm »
  • www.mouffers.com
  • *
  • Reputation: +69/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2577
You can simulate enums in any language: just make constants or whatever. In AS3 they look sorta like this:

public static const BLABLA:String = "bLABLABLA" or whatever.

I think you need to steer quite clear of Arrays, though. You keep saying 2D arrays but I don't feel like they're good in your case. You want something dynamic that can expand and equally reduce in size. Arrays are quite static in their size and can become a real pain in the ass.
Logged
  • Starforsaken101's DeviantART

Koh

Re: What's the Most Efficient Way to Program Thi...
« Reply #5 on: August 09, 2013, 02:40:37 pm »
  • Tamer Koh
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 980
I understand, it's just this isn't an inventory that infinitely expands, but rather a simple 25 slot inventory that stores all the qualities of items.  The only thing I'd have to backtrack to update is the max value for the 2nd tier, since more attributes of an item could come in my head, such as resistance boosts, buff effects, etc.  Game Maker DOES have ds_lists, though, which I guess is similar to a C++ vector?  Maybe I could use that...
Logged
  • Megaclipse Games

Starforsaken101

Wake the Beast
Re: What's the Most Efficient Way to Program Thi...
« Reply #6 on: August 09, 2013, 03:11:24 pm »
  • www.mouffers.com
  • *
  • Reputation: +69/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2577
I don't know, you can do what you want :P. You're the main developer on this. Just from somebody who works in the industry, it's generally a good idea to use something that can expand and retract. Arrays are good if you absolutely want to limit something all the time...but in terms of an inventory, you can easily just make a list and put a constant that states the limit you want it to be (so that way you do insert too many). Search functions are generally built in to lists better and I don't know..I just find it better practice.

Most languages have lists, not just C++. Lists, vectors, whatever.
Logged
  • Starforsaken101's DeviantART
Re: What's the Most Efficient Way to Program Thi...
« Reply #7 on: August 09, 2013, 04:02:06 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
I think what you're actually looking for is not a 2D array, but a jagged array.  Stars got the right idea here though.  Otherwise I would say assign probabilities to each, but that's still going to cause the need for some kind of data structure, so you might as well take the math out of it.
Logged



i love big weenies and i cannot lie

Starforsaken101

Wake the Beast
Re: What's the Most Efficient Way to Program Thi...
« Reply #8 on: August 09, 2013, 06:47:39 pm »
  • www.mouffers.com
  • *
  • Reputation: +69/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2577
I don't see a point in assigning a probability in a 2D array. You can easily make a structure or a class that holds a probability variable inside to go against this.

-List<Weapon>
-Weapon has probability, quality, etc.
-Roll some sort of percentage
-Go through list and choose the one that fits.

Simple. Sort of efficient. Not messy. Not confusing.
Logged
  • Starforsaken101's DeviantART
Re: What's the Most Efficient Way to Program Thi...
« Reply #9 on: August 09, 2013, 07:27:25 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Yep, much cleaner
Logged



i love big weenies and i cannot lie

Koh

Re: What's the Most Efficient Way to Program Thi...
« Reply #10 on: August 09, 2013, 09:50:39 pm »
  • Tamer Koh
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 980
I don't see a point in assigning a probability in a 2D array. You can easily make a structure or a class that holds a probability variable inside to go against this.

-List<Weapon>
-Weapon has probability, quality, etc.
-Roll some sort of percentage
-Go through list and choose the one that fits.

Simple. Sort of efficient. Not messy. Not confusing.
Actually, now that I think about it, Game Maker's ds_list functions more like that kind of list.  If I were to make each weapon a ghost object to make use of inheritance, that would work nicely.  The problem is, all objects inherit from an invisible Object superclass, which houses all the default variables objects have in Game Maker.  It just seems less memory intensive to have a few lists/arrays/vectors/etc. that are cross referenced, rather than a bunch of bulky ghost objects floating around, who are just accessed in a ds_ist.
Logged
  • Megaclipse Games

Starforsaken101

Wake the Beast
Re: What's the Most Efficient Way to Program Thi...
« Reply #11 on: August 09, 2013, 09:52:43 pm »
  • www.mouffers.com
  • *
  • Reputation: +69/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2577
Yeah I'm not entirely familiar with how GM works but generally inheritance is a good idea. However, you have to think about cleanliness and understanding as well. There's always a tradeoff :P
Logged
  • Starforsaken101's DeviantART
Re: What's the Most Efficient Way to Program Thi...
« Reply #12 on: August 10, 2013, 02:06:48 pm »
  • ...---^^^---...
  • *
  • Reputation: +6/-0
  • Offline Offline
  • Gender: Male
  • Posts: 616
I don't see a point in assigning a probability in a 2D array. You can easily make a structure or a class that holds a probability variable inside to go against this.

-List<Weapon>
-Weapon has probability, quality, etc.
-Roll some sort of percentage
-Go through list and choose the one that fits.

Simple. Sort of efficient. Not messy. Not confusing.
Actually, now that I think about it, Game Maker's ds_list functions more like that kind of list.  If I were to make each weapon a ghost object to make use of inheritance, that would work nicely.  The problem is, all objects inherit from an invisible Object superclass, which houses all the default variables objects have in Game Maker.  It just seems less memory intensive to have a few lists/arrays/vectors/etc. that are cross referenced, rather than a bunch of bulky ghost objects floating around, who are just accessed in a ds_ist.

Perhaps you already thought of this, but if you do go with the ghost objects, be sure to deactivate them all and then only activate the one you need when you need it to read data from it.  That way it will reduce the impact of having so many ghost objects around.
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.188 seconds with 63 queries.

anything