int City::get_net_resource_production(Resource res) { return get_gross_resource_production(res) - get_resource_consumption(res); }
void AI_city::init_demands() { // At the bottom of this function, we reduce each demand value by the amount we // produce. We'll do food & gold after this reduction! // Demand for gold is always infinite. We just love the stuff! resource_demand[RES_GOLD] = INFINITE_RESOURCE; // We always want to have a healthy production of wood and stone, to help us // build more stuff! resource_demand[RES_WOOD] = 25; resource_demand[RES_STONE] = 25; // Go through all buildings and find anything we need for recipes. for (std::map<Building_type,int>::iterator it = buildings_built.begin(); it != buildings_built.end(); it++) { Building_type type = it->first; Building_datum* build_dat = Building_data[type]; // Here, "amount" refers to the amount of workers at this building type. int workers = it->second * build_dat->jobs.amount; for (int i = 0; i < build_dat->recipes.size(); i++) { Recipe rec = build_dat->recipes[i]; for (int n = 0; n < rec.resource_ingredients.size(); n++) { Resource_amount res_amt = rec.resource_ingredients[n]; res_amt.amount *= workers; resource_demand[res_amt.type] += res_amt.amount; } for (int n = 0; n < rec.mineral_ingredients.size(); n++) { Mineral_amount min_amt = rec.mineral_ingredients[n]; min_amt.amount *= workers; mineral_demand[min_amt.type] += min_amt.amount; } } } // We might also demand luxuries! First, pick what we like. for (int i = CIT_PEASANT; i < CIT_BURGHER; i++) { population[i].pick_luxuries(this); } // Now, set up demand for all luxuries. for (int i = 0; i < RES_MAX; i++) { Resource res = Resource(i); Resource_datum* res_dat = Resource_data[i]; if (res_dat->morale > 0) { int total_demand = 0; for (int n = CIT_PEASANT; n < CIT_BURGHER; n++) { int demand = (res_dat->demand * population[n].count) / 100; Luxury_type lux_type = res_dat->luxury_type; if (lux_type != LUX_NULL && population[n].luxury_demands[lux_type] != res) { demand *= 0.5; } total_demand += demand; } resource_demand[res] += total_demand; } } // Now reduce all demands by the amount we produce. for (int i = 0; i < RES_MAX; i++) { Resource res = Resource(i); int produced = get_gross_resource_production(res); if (resource_demand.count(res) && resource_demand[res] > 0) { if (resource_demand[res] < produced) { resource_demand.erase(res); } else { resource_demand[res] -= produced; } } } for (int i = 0; i < MINERAL_MAX; i++) { Mineral min = Mineral(i); int produced = (mineral_production.count(min) ? mineral_production[min] :0); if (mineral_demand.count(min) && mineral_demand[min] > 0) { if (mineral_demand[min] < produced) { mineral_demand.erase(min); } else { mineral_demand[min] -= produced; } } } // We always want gold! We just love the stuff! resource_demand[RES_GOLD] = INFINITE_RESOURCE; // Food demand is equivalent to 110% of our food deficit. int net_food = get_net_food(); if (net_food < 0) { resource_demand[RES_FOOD] = 1.1 * (0 - net_food); } }