Geoff the Medio wrote:
Bigjoe5 wrote:
ResetTargetMaxUnpairedMeters
Are there any paired (or target or max) empire meters?
Well no, but should there be paired meters added (or target or max), which isn't totally unthinkable, the types of meters that would be reset by this function would be target, max and unpaired, and it would be annoying to have to go back and change the name of the function when that happens.
Geoff the Medio wrote:
As long as that's the case, you could / should also just iterate over all empire meters and reset them all, rather than hard coding individual meter names.
I hadn't realized that was possible, but at a second look, there does seem to be an m_meters I could iterate over. This does also defeat the purpose of leaving the name of the function as-is, so I might as well just change it, I suppose.
Geoff the Medio wrote:
If some empire meters need to be handled differently, then something fancier to specify how each meter should be handled seems necessary...
I feel the same way about regular meters too, but as it stands there seems to typically be just a lot of repeated calls to the same function on different, hard-coded meters.
A relatively easy way to handle it might be to have an enumerated type (MeterRole, or some such) representing whether the meter is target, max, unpaired or current, and then have m_meters map from a string (or for planet meters, the enum MeterType) to a pair<Meter, MeterRole>, instead of just a meter. That way it would be easy to iterate over the whole set of meters and just act on meters of a particular role or roles.
Or we could define some new classes derived from Meter, but that just sounds painful and way too complicated.
edit: How's this?
Code:
void Empire::ResetMeters() {
for (std::map<std::string, Meter>::iterator it = m_meters.begin(); it != m_meters.end(); ++it) {
it->second.ResetCurrent();
}
}