Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * calculates how much a productionsite of type \arg bo is needed inside it's
- * economy. \arg prio is initial value for this calculation
- *
- * \returns the calculated priority
- */
- int32_t DefaultAI::calculate_need_for_ps(BuildingObserver & bo, int32_t prio)
- {
- // some randomness to avoid that defaultAI is building always
- // the same (always == another game but same map with
- // defaultAI on same coords)
- prio += time(nullptr) % 3 - 1;
- // check if current economy can supply enough material for
- // production.
- for (uint32_t k = 0; k < bo.inputs.size(); ++k) {
- prio += 2 * wares.at(bo.inputs.at(k)).producers;
- prio -= wares.at(bo.inputs.at(k)).consumers;
- }
- if (bo.inputs.empty())
- prio += 4;
- int32_t output_prio = 0;
- for (uint32_t k = 0; k < bo.outputs.size(); ++k) {
- WareObserver & wo = wares.at(bo.outputs.at(k));
- if (wo.consumers > 0) {
- output_prio += wo.preciousness;
- output_prio += wo.consumers * 2;
- output_prio -= wo.producers * 2;
- if (bo.total_count() == 0)
- output_prio += 10; // add a big bonus
- }
- }
- if (bo.outputs.size() > 1)
- output_prio = static_cast<int32_t>
- (ceil(output_prio / sqrt(static_cast<double>(bo.outputs.size()))));
- prio += 2 * output_prio;
- // If building consumes some wares, multiply with current statistics of all
- // other buildings of this type to avoid constructing buildings where already
- // some are running on low resources.
- // Else at least add a part of the stats t the calculation.
- if (!bo.inputs.empty()) {
- prio *= bo.current_stats;
- prio /= 100;
- } else
- prio = ((prio * bo.current_stats) / 100) + (prio / 2);
- return prio;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement