I want to sort units based on a score assigned to them by a function. When a unit is created/destroyed, it is checked for some criteria to see if it is of the right type and then i want it to be added/delete from a list of all units of that type. When a unit is created, it is assigned this score, which never changes as long as the unit is alive.
I want to hold those units in a list, sorted by score, and then get its ID, perform an action to it and remove it from the list while it is doing that action (onto another sorted list of "active" units) and then put it back in the unused list once it done its job.
Since units will be added/removed quite frequently, it would be good if the operation was fast, and since the scores never change its a matter of adding a unit to the right place, kinda like an ordered tree, but to remove units that would be slow.
I could just do this:
Code: Select all
struct unitscore{
float score;
int id;
}
vector<unitscore> myunits;
Any ideas? (if i sounded too confusing just ask for more detail)