Apologies for such a lengthy post. I wanted to be sure it was understood what I was asking. If a MOD feels there is a better section for this to be in ( Game Design Theory? Programming Talk?) please do move it there. Thank you.
Hi guys,
this question relates to my Text RPG I am slowly but surely working on. (I've got most of my scrolling text box implemented as well as a user input routine that echos key hits and appears to be non-blocking like I need, so..making progress!)
I'm trying to do some planning ahead and decide how I want to approach object management for things like holding the actual room data, then calling that data as the player navigates through the virtual game world, as well as trying to come up with an inventory system as well, since from my point of view the two are somewhat related and will use the same basic principles when it comes to implementing those systems.
I of course do plan on using UDT's to make some basic structures and other object definitions, but as far as storing those individual objects and recalling that data when necessary I'm not sure what the best approach would be.
For example, for my actual game map I thinking of the time honored tradition of using arrays.. It will probably be either a 2D (x,y) or 3D (x,y,z (z axis for up/down above/below ground movement). However I am concerned with easing the developmental process as far as building rooms (and objects as well) giving them individual unique ID's and how to reference them by those ID's (more so for objects than the rooms) if/when I need to..
For rooms in particular I've got to have a way to link them.. Well this particular room has 3 exits, and those 3 exits lead to Rooms A, B, and C.
I could just reference by array index, but that would create complications I am hoping to avoid, because even though I am going to create maps of all the areas I am building, I'm worried about how I would need to keep track of them when building individual rooms, and making sure I link them appropriate.
Even a 1D array would work for that purpose, but it would be very quirky and unordered of course and I'd need to know every single rooms exact position in the array when assigning valid exit addresses, etc.. A 2D array is much more organized and would be presentative of any 2D map I draw out on paper but then I also have to worry about loading that data into those arrays in a quick and efficient manner, (I am NOT hard coding anything as I want to try and come up with a re-usable engine of sorts..)
Obviously if room A is 0,0 and linked to Room B at 0,1 but maybe the next time the data is loaded they are all in different positions? etc... It would create a problem.
Even if that situation is unlikely... I am much more interested in devising a Unique ID system, where every room has a unique ID, every item has a unique ID, every monster/NPC/anything else has a unique ID, etc..
I have no idea how to write a system that can assign those ID's (or let me assign them) randomly, and keep track of them internally, as well as lookup and interact with a particular ID based on user-input on the fly..
For example.. When I was working in Python with SQLite my Room mapping system was (probably) pretty primitive and based on some manual labor to keep things straight. I had a 2D grid, based on Letter / Number coordinates, as well as a general area prefix.
A B C D E F G
1
2
3
4
5
basically like that.. so the town center on such a map might be located at 1xD3 (Area 1, x (spacer), Column D, Row 3) and I basically assigned my valid room exit variables for each room as I was building them, referencing the map. When the player moved, the game would perform an SQL lookup for the grid coordinate (stored as a column value in each row, along with other column values for Town, Street, Room Description, etc) and the room data for that grid coordinate would be pulled up, assigned to the current room class (an array object of sorts :CurRoom.Title, .Name, .Description, etc). The "valid" exit values from the SQL data would be parsed through and valid exits printed as well, etc.
And that's how I did movement.. However this time I want to load the game map into memory and leave it there since its probably better to do so, and I can manage other things on the same map as well.
So let's say I had a 4x4 2D array
0 1 2 3
0
1
2
3
(I think that's right?)
let's say I filled it complete with rooms, and one of the variable fields was a unique ID field.
Instead of searching/pointing to (0,1) or (2,3) etc.. How would I iterate through that array (fastly) and search for the unique ID?
Is that even efficient? I have heard of using Linked Lists and Binary Trees, etc.. But what I have read on the forums, I do not completely "grasp" at this time.
I think it would be best if anyone could explain Arrays, vs Linked Lists, vs Binary Trees using simple code examples - related to what I would like to do.. (so making a 2D game map and how to reference and manipulate the data by unique ID)
I also mentioned an inventory system.. I am very confused on the best way to do this.. whether it is managing monsters, or items, or anything in particular..
Let's say there is a table in a pawn shop, and it has Two items on it I am interested in. They are both unique items with their own unique ID - BUT they are the same object as far as the game world is concerned.. A simple healing potion. It has the exact same description, same weight, same everything, but just like in real life they are both unique individual objects..
It will be challenging enough getting my parser (when the time comes) to distinguish wish one the player is referring to (i.e get first potion, or get second potion, attack third Orc, etc)
But I have NO IDEA how to keep track of "clone" unique items, by using their unique ID only!
If anyone can take the time to write out a good explanation, and some easy to follow example code on how I could implement this kind of functionality - or at least post a really good link that a beginner could grasp, I would be really grateful.