The canBuildInt() returns an int that represents the reason why you can't build. This so the help text lets you know what you need to do in order to build the Improvement. The Improvement will be shaded out in your Units commands. This also lets you know what builds you have on your Units so new Players can see them, even if they don't have the right requirement yet, like a Number of Sheep in the City. I am sure you can find a better way to do this.
I would rename canBuild to canBuildWithReason (or something) and that one returns an int, which is an enum value. I will then make a new function for all the calls to canBuild.
Code:
bool CvUnit::canBuild(arg)
{
return canBuildWithReason(arg) == BUILDREPLY_OK;
}
That will make a single function for determining reply and reason while we do not have to touch any of the current calls to canBuild().
Adding a reason is a good idea btw. It just need to be done in a more readable way, not to mention using only one approach to determine the output. Right now they can get out of sync.
Speaking of how easy it is to make a new jit array, I think I need one for "Yields that Player can Trade, but can not make himself." Like for PlateArmor, the player can buy it from a Trade Screen but at times he cant not make it himself. So, when he gets home with the PlateArmor and unloads it, he can not see it in the City. So, perhaps the Jit arrray can set to True as soon as the Player loads or recieves into his City such a Yield. This will action rebuild the Resource Table and allow you to see the Yield, but still not allow you to Produce the Yield Yourself. I have a rudimentary version of this working but not with a Jit array.
We could do some lengthy setup where we loop professions and make a list of yields we can produce with currently available professions. That would require a bunch of custom code though.
Instead we can add another yield array to XML, which tells which yields you can produce.
This would allow us to make the cache as easily as I just did with improvements. However if we add allowed_yields as an extra argument to updateInventionEffectCacheSingleArray(), it will skip looking at yields not allowed by that array. As a result, the resulting array will only be true if produce and allow are both enabled by XML.
This will follow the standard rules meaning if a yield production has no civic, which enables production, production will be enabled once the yield itself is enabled. In other words, enabling producing a yield is always on and can be ignored unless it is explicitly specified otherwise in XML.
However I don't want to mess too much with the player cache right now. I modified it in the prospecting_setting branch because it contain the start of the code to disable prospectors. If I mess too much with this function, I risk conflicts. I would rather merge that branch back into AI_traders before making any more player caches.
I think I skipped mentioning this, but when looping professions to find prospectors, it disables all professions dealing with yields, which have yet to be invented. In the producing loop, if it checks against produceable yields rather than allowed yields, it will disable professions producing the yields you can't produce yet. We would still need to modify "background production", such as buildings and centre plot, but just disabling the professions and we are more than half way there to have production eliminated.
Btw the produceable yield idea has a decent sideeffect. It opens up for col2071 where you for instance have to get uranium from the natives to research it before you can produce it (in last release). That can't be done right now, but if the uranium tech enables production instead of general allowing uranium, it can be done.