Comment 38 for bug 1772845

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

Sorry for some reason the comment was posted while not finished so another try

else if (bo.is(BuildingAttribute::kHunter)) {

// kHunter is assigned by defining and checking the AI Hint "collects_ware_from_Map = meat" in the productionsitedescr. it is asserted that a building with that hint really produces the ware//

 if (bf->critters_nearby < 5) { // no sense to build a hunter where there arte no animals
       continue;
      }

     if (bo.new_building == BuildingNecessity::kForced) {
       prio += 20;
      }

     // Overdue priority here
      prio += bo.primary_priority;

     prio += bf->supporters_nearby.at(bo.outputs.at(0)) * 5; // bonus if gamekeepers are near

     prio +=
         (bf->critters_nearby * 3) - 8 - 5 * bf->producers_nearby.at(bo.outputs.at(0));

     //malus if other hunters are near//

the problem with this code is that it counts producers of the first ware in the outputs. This has been valifd for the hunters until now and still is for the Frisian one (meat is the first output in the table fur is the second one. But to have a stable code we need to be sure, to just catch the meat producer any other production of a hunter like fur doesn't matter cause this is just to ensure that there are enough ressources on the map for the building to collect if a new building is built. My suggestion was to change the lines in the following way

     prio += bf->supporters_nearby.at("meat") * 5; // bonus if gamekeepers are near

     prio +=
         (bf->critters_nearby * 3) - 8 - 5 * bf->producers_nearby.at("meat");

     //malus if other hunters are near//

So there is no need to count producers or supporters for all outputs of a Hunter just the meat is of any interest in this case.

The same approach applies to the other special buildings and their primary wares. By the way the empire quarry had 2 produced wares in the pas as well. However as in that code only other quarries of the same tribe are taken into account that never led to a problem.

As you already realized this has currently the flaw that empire piggeries are taken into account as well for the empire hunter. And the mines producing "granite" are taken into account by the quarries code. But so far this has not led to big problems in AI yet and could be targeted for b21 in my opinion.