24 Jan, 2011, quixadhal wrote in the 21st comment:
Votes: 0
Ah, I see. So you could use a multimap to do something like:

weapon[0] = blaster, weapon[1] = railgun, weapon[blasters] = { 0, 2, 3 }, weapon[aft] = { 3, 4, 5 };

But with correct syntax, of course. :)
24 Jan, 2011, David Haley wrote in the 22nd comment:
Votes: 0
Well, a multimap needs to have keys of the same type and values of the same type. So you couldn't map, say, slot numbers to weapons, and then weapon types to slot numbers, unless you used numeric identifiers for everything.
24 Jan, 2011, sankoachaea wrote in the 23rd comment:
Votes: 0
what do you mean David? what is wrong with:

multimap<string, int> m;

// and using something like this
m.insert(pair<string, int>("laser", 1));
m.insert(pair<string, int>("torpedo", 2));
m.insert(pair<string, int>("laser", 3));
24 Jan, 2011, David Haley wrote in the 24th comment:
Votes: 0
Nothing is wrong with that; the keys are all of the same type and the values are also all of the same type. Quix's example mixed types, unless I'm misunderstanding his pseudo-code.
24 Jan, 2011, sankoachaea wrote in the 25th comment:
Votes: 0
ahhh, gotcha! I'm just dropping 'weapon' from the equation. If we did:
multimap<string, int> weapon;

weapon.insert(pair<string, int>("laser", 1));
etc..


har.. just for mapping weapontype (as a string though) to slot location (the int)… I'm still not sure multimaps would be the perfect tool for this, but the nice thing about this is string comparison is built into the STL.. so it would be pretty easy to list all slots related to each weapon type, if you're on a ship with a lot of slots and such.
25 Jan, 2011, sankoachaea wrote in the 26th comment:
Votes: 0
hrm, quix example looks like a non-multimap style associative array…

like a lua table lol
25 Jan, 2011, Runter wrote in the 27th comment:
Votes: 0
Associative array is a map. So I'm not sure the distinction you're drawing there other than it's not a multikey associative array, perhaps.
25 Jan, 2011, sankoachaea wrote in the 28th comment:
Votes: 0
*Associative array is an abstract data type. In C++, it's represented as a map. In other languages, it might be called a dictionary, hash, table, or hashtable. In Javascript, all objects behave as associative arrays. In PHP, any array can be associative, but their keys are limited to integers or strings.

The distinction I'm making is that I don't think multimaps are the best route for what he wants to do. (Weapon upgrades on ships later? How are you planning that? The player selects the weapon slot on his ship, the weapon type, and then upgrades? Or does he just select the weapon slot he wants to upgrade, and the code seeing it as a blaster automatically changes it to the next best available blaster? Or does he select the weapon time he wants to upgrade, then it lists the slots on his ship containing those weapons? Is there an 'upgrade all available' option? These kinds of things will likely require iteration through this container. What if you have a VERY LARGE ship, weapons on top, bottom, front, back, center, both sides? With say 20-40 slots on each 'area'. How are you going to list weapons/weapon-locations in that case? Do you know the multimap::iterator is not a mutable iterator?)

Also, @David: I think he still still used only two types, he just tried to reference by value instead of key.
25 Jan, 2011, David Haley wrote in the 29th comment:
Votes: 0
Well, there's not much point speculating really on what he might or might not have meant with pseudo-code. :smile:

Note that a hash table is an implementation of map, and not just a name for it. A map is an abstract data type as well. C++'s implementation of maps is with binary trees over the key set. Perl uses a hash table (as its name implies). So do Python and Lua.

Regarding multi-maps and the problem at hand… multi-maps are appropriate if you need one key to map to several things. So, if you have a map from slot type to weapon in slots of that type, you might have a multi-map. But if you have a map from actual slot to the weapon in that particular slot, a multi-map (probably) doesn't make sense.

To be honest I think we're getting too much into implementation here without having a particular clear idea of what we're trying to implement…
26 Jan, 2011, sankoachaea wrote in the 30th comment:
Votes: 0
Hrm, you're probably right about that (speculation on pseudo-code.) I also agree with you regarding the multi-map issue. Doing it by slot-type to weapon in slots of that type seems fairly inflexible though, and even more so from actual slot to the weapon in that particular slot.

When I listed hashtable, I was specificaly referring to Lisp. Similarly with Perl and Ruby for hashes. Python(?) as well as Smalltalk and Objective C call them dictionaries, yea? In fact, besides C++, I think Java is the only other language that uses the term map.

Anyway, maybe he can shed some light on this. I personally like to get an idea of how the OP envisions using the code.. (as you probably gathered from my last post.)

Cheers. (and thanks for the response, David.)
26 Jan, 2011, David Haley wrote in the 31st comment:
Votes: 0
Python calls it a dictionary, which again is an abstract container term, but implements it with a hash table. For what it's worth, the term 'map' is quite common in mathematics. As you can see in Java, the term 'map' is abstract, and implemented with TreeMap, HashMap, etc.

I completely agree that we need to have use cases before we can choose implementations. If there are going to be very many kinds of operations, it might even make sense to have everything in a list and scan it linearly each time. It's hard to know without the big picture.
26 Jan, 2011, sankoachaea wrote in the 32nd comment:
Votes: 0
Agreed.

You could use lists within multi-maps yea?
26 Jan, 2011, David Haley wrote in the 33rd comment:
Votes: 0
If you wanted to, sure, you could have multimaps that map from keys to lists; you'd then have a map from keys to at least one list of elements. This is probably getting a little unusual, though.
14 Feb, 2011, Kayle wrote in the 34th comment:
Votes: 0
So after re-reading this, what I picked up is that there are several ways to do what I'm attempting to do and that without more specifics, a proper recommendation can't be made. So here goes. Specifics.

In the system in question, players will be able to swap out any number of core components of their ships with better ones that the salvage, create, or buy. Now for everything but weapons this is easy, because you can only have one of each of them. You can only have one reactor, one hyperdrive, etc. But with weapons, it depends on the ship frame that you're using. Returning to prior examples:

The X-Wing would have 4 weapon slots, while an A-Wing would only have 2 weapon slots. (These slots are only laser weaponry, Launchers and Counter Measures have their own component types and slots.)

So, Player A owns an X-Wing with 2 Ariake Technology RX-347T Laser Cannons, and 2 CEC TR-213 Ion Cannons. Now, he salvages another Laser Cannon from a recent space engagement and decides to replace one of his existing ones. So he lands his ship at a Shipyard, and set about his work of removing one of the Ariake Technology RX-347T Laser Cannons with the new Raybark T-16X Modulating Laser Cannon. Now, logically, if he removed one of the prior weapons, the new one would be installed in it's place. They wouldn't magically re-arrange themselves because one of them came off. So if the Ariake guns were in Weapon Slots 1 and 2, and he removed the one in weapon slot 1, the new gun should go right back into Slot 1. So the slots should look like this:

Before:
Slot 1 - Ariake Technology RX-347T Laser Cannons
Slot 2 - Ariake Technology RX-347T Laser Cannons
Slot 3 - CEC TR-213 Ion Cannons
Slot 4 - CEC TR-213 Ion Cannons

After Swap:
Slot 1 - Raybark T-16X Modulating Laser Cannon
Slot 2 - Ariake Technology RX-347T Laser Cannons
Slot 3 - CEC TR-213 Ion Cannons
Slot 4 - CEC TR-213 Ion Cannons


Hopefully, that clears up that part of things. The second thing I need to be able to do is to track pairings of weapons for linked fire situations. Continuing with Player A's ship as the example. He sets the Laser weapons up as Weapon Group 1 (WG1), and the Ion weapons as Weapon Group 2 (WG2). Now in combat, if he's looking to disable his opponent instead of kill them, he can set fire mode to WG2, and just fire the Ions. Or if he needs to destroy them, set fire mode to WG1 and destroy them. Or if he just doesn't care set fire mode to full, and fire all four weapons. The groupings don't necessarily need to be handled in the same field as the actual weapon slots, they can be a second field, even say a map to hold the slots the weapons are in, and then a multimap to hold the groupings, or something. I don't really know. Hence my starting this thread.

Hopefully this helps to get a clear recommendation on how to get these set up.
14 Feb, 2011, kiasyn wrote in the 35th comment:
Votes: 0
so basically you're making EQ for ships ;) have a look at how eq works for players?
14 Feb, 2011, Kayle wrote in the 36th comment:
Votes: 0
kiasyn said:
so basically you're making EQ for ships ;) have a look at how eq works for players?


No, it doesn't work like equipment does. If it did, I wouldn't have needed to ask how to do it.
15 Feb, 2011, Kayle wrote in the 37th comment:
Votes: 0
Can you go be a bothersome twit somewhere else, so that people who are actually willing to answer my questions can? Thanks.
15 Feb, 2011, sankoachaea wrote in the 38th comment:
Votes: 0
He suggested a logical place to look for inspiration in regards to possible solutions for this problem. Just because you chose to dismiss it completely doesn't mean the answer wasn't there or that he's being a twit.
Kayle said:
Now, logically, if he removed one of the prior weapons, the new one would be installed in it's place. They wouldn't magically re-arrange themselves because one of them came off. So if the Ariake guns were in Weapon Slots 1 and 2, and he removed the one in weapon slot 1, the new gun should go right back into Slot 1.


I can't tell if you're asking what is the appropriate structure to hold this data or if there is a structure that will handle manipulating the data it contains for you. If he only has 4 slots on his ship (fixed size) and he removes a weapon in one of those slots then that would be the only available space for the new weapon to go..

function weapon_replace (old_weapon, new_weapon, <optional weapongroup>)
{
..check if old weapon is really on the ship..
..check if new weapon is available to player (inventory?)
..do stuff to whatever structure you decide to use..

..was an optional weapongroup given? if so, lets set that up now..
..return something..
}
15 Feb, 2011, Runter wrote in the 39th comment:
Votes: 0
My only suggestion is use a fire-control module that contains the weapon groupings. And that it correlates with an actual fire-control chip on the ship. From a gameplay perspective it can be yet another part that can be customized to your needs.
15 Feb, 2011, Kayle wrote in the 40th comment:
Votes: 0
sankoachaea said:
He suggested a logical place to look for inspiration in regards to possible solutions for this problem. Just because you chose to dismiss it completely doesn't mean the answer wasn't there or that he's being a twit.


I dismissed it, because the two are completely separate concepts. The equipment is attached to a Player. These components aren't attached TO a Ship, they ARE a ship. I had already looked at equipment handling and it didn't apply.


sankoachaea said:
I can't tell if you're asking what is the appropriate structure to hold this data or if there is a structure that will handle manipulating the data it contains for you. If he only has 4 slots on his ship (fixed size) and he removes a weapon in one of those slots then that would be the only available space for the new weapon to go..

function weapon_replace (old_weapon, new_weapon, <optional weapongroup>)
{
..check if old weapon is really on the ship..
..check if new weapon is available to player (inventory?)
..do stuff to whatever structure you decide to use..

..was an optional weapongroup given? if so, lets set that up now..
..return something..
}


I'm looking for a an appropriate structure that won't re-arrange the items inside it because one of them is removed. A vector, as was originally suggested, will move all elements forward to fill in the gaps of the removed element. This won't work in my situation, because removing a weapon from Slot 1, does not make Slot 2 slide to fill in Slot 1.

Runter said:
My only suggestion is use a fire-control module that contains the weapon groupings. And that it correlates with an actual fire-control chip on the ship. From a gameplay perspective it can be yet another part that can be customized to your needs.


That's something I hadn't considered, and might actually be worth digging around some Rulebooks, Wikis to se how various spaec flight games/universes handled that kind of things.
20.0/57