void PopulationPool::Update() { m_population = 0.0f; float future_population = 0.0f; // sum population from all PopCenters in this pool for (std::vector<int>::const_iterator it = m_pop_center_ids.begin(); it != m_pop_center_ids.end(); ++it) { if (TemporaryPtr<const PopCenter> center = GetPopCenter(*it)) { m_population += center->CurrentMeterValue(METER_POPULATION); future_population += center->NextTurnCurrentMeterValue(METER_POPULATION); } } m_growth = future_population - m_population; ChangedSignal(); }
void PopulationPool::Update() { m_population = 0.0f; float future_population = 0.0f; // sum population from all PopCenters in this pool for (int pop_center_id : m_pop_center_ids) { if (std::shared_ptr<const PopCenter> center = GetPopCenter(pop_center_id)) { m_population += center->CurrentMeterValue(METER_POPULATION); future_population += center->NextTurnCurrentMeterValue(METER_POPULATION); } } m_growth = future_population - m_population; ChangedSignal(); }
void ResourcePool::Update() { //DebugLogger() << "ResourcePool::Update for type " << boost::lexical_cast<std::string>(m_type); // sum production from all ResourceCenters in each group, for resource point type appropriate for this pool MeterType meter_type = ResourceToMeter(m_type); MeterType target_meter_type = ResourceToTargetMeter(m_type); if (INVALID_METER_TYPE == meter_type || INVALID_METER_TYPE == target_meter_type) ErrorLogger() << "ResourcePool::Update() called when m_type can't be converted to a valid MeterType"; // zero to start... m_connected_object_groups_resource_output.clear(); m_connected_object_groups_resource_target_output.clear(); // temporary storage: indexed by group of systems, which objects // are located in that system group? std::map<std::set<int>, std::set<TemporaryPtr<const UniverseObject> > > system_groups_to_object_groups; // for every object, find if a connected system group contains the object's // system. If a group does, place the object into that system group's set // of objects. If no group contains the object, place the object in its own // single-object group. std::vector<TemporaryPtr<const UniverseObject> > objects = Objects().FindObjects<const UniverseObject>(m_object_ids); for (std::vector<TemporaryPtr<const UniverseObject> >::const_iterator it = objects.begin(); it != objects.end(); ++it) { TemporaryPtr<const UniverseObject> obj = *it; int object_id = obj->ID(); int object_system_id = obj->SystemID(); // can't generate resources when not in a system if (object_system_id == INVALID_OBJECT_ID) continue; // is object's system in a system group? std::set<int> object_system_group; for (std::set<std::set<int> >::const_iterator groups_it = m_connected_system_groups.begin(); groups_it != m_connected_system_groups.end(); ++groups_it) { const std::set<int> sys_group = *groups_it; if (sys_group.find(object_system_id) != sys_group.end()) { object_system_group = sys_group; break; } } // if object's system is not in a system group, add it as its // own entry in m_connected_object_groups_resource_output and m_connected_object_groups_resource_target_output // this will allow the object to use its own locally produced // resource when, for instance, distributing pp if (object_system_group.empty()) { object_system_group.insert(object_id); // just use this already-available set to store the object id, even though it is not likely actually a system float obj_output = obj->GetMeter(meter_type) ? obj->CurrentMeterValue(meter_type) : 0.0f; m_connected_object_groups_resource_output[object_system_group] = obj_output; float obj_target_output = obj->GetMeter(target_meter_type) ? obj->CurrentMeterValue(target_meter_type) : 0.0f; m_connected_object_groups_resource_target_output[object_system_group] = obj_target_output; continue; } // if resource center's system is in a system group, record which system // group that is for later system_groups_to_object_groups[object_system_group].insert(obj); } // sum the resource production for object groups, and store the total // group production, indexed by group of object ids for (std::map<std::set<int>, std::set<TemporaryPtr<const UniverseObject> > >::const_iterator object_group_it = system_groups_to_object_groups.begin(); object_group_it != system_groups_to_object_groups.end(); ++object_group_it) { const std::set<TemporaryPtr<const UniverseObject> >& object_group = object_group_it->second; std::set<int> object_group_ids; float total_group_output = 0.0f; float total_group_target_output = 0.0f; for (std::set<TemporaryPtr<const UniverseObject> >::const_iterator obj_it = object_group.begin(); obj_it != object_group.end(); ++obj_it) { TemporaryPtr<const UniverseObject> obj = *obj_it; if (obj->GetMeter(meter_type)) total_group_output += obj->CurrentMeterValue(meter_type); if (obj->GetMeter(target_meter_type)) total_group_target_output += obj->CurrentMeterValue(target_meter_type); object_group_ids.insert(obj->ID()); } m_connected_object_groups_resource_output[object_group_ids] = total_group_output; m_connected_object_groups_resource_target_output[object_group_ids] = total_group_target_output; } ChangedSignal(); }