+void Creature::DoWork(double amount) noexcept {
+ stats.Exhaustion().Add(amount / Stamina());
+ // burn resources proportional to composition
+ // factor = 1/total * 1/efficiency * amount * -1
+ double factor = -amount / (composition.TotalMass() * EnergyEfficiency());
+ // make a copy to total remains constant and
+ // no entries disappear during iteration
+ Composition comp(composition);
+ for (auto &cmp : comp) {
+ double value = cmp.value * factor * sim.Resources()[cmp.resource].inverse_energy;
+ AddMass(cmp.resource, value);
+ }
+}
+