Corporate Executive exploit in K-Mod

vedg

Chieftain
Joined
Jan 14, 2014
Messages
25
Location
Ukraine
In K-Mod v1.46 it is possible to get free gold while building executives, which amounts to the executive hammer cost. It looks like fail-gold even though the executive is actually built. This means getting gold without losing any hammers. I suppose the exploit isn't present in unmodded BTS because I couldn't find any mention of it. I have found only one other post that describes this exploit at https://forums.civfanatics.com/threads/missionary-fail-gold.479236/#post-14795616. This other poster has also noticed the exploit in K-Mod (v1.44b).

Reproducing the exploit with the attached save:

1. Note the amount of gold in treasury and the expected net change at the end of the current turn.
2. End the turn and observe that treasury contains the expected amount of gold.
3. Reload the original save, start building one more executive in a city that is currently building something else and end the turn. Observe that the treasury contains 300 more gold than in step 2.

2 executives are built at the same turn in the attached save, which produces 300 gold if the total number of existing and queued executives equals 5. When only one executive is built while the executive limit is reached, the treasury receives 150 gold, which is an executive's hammer cost at Epic game speed. This is clearly a bug because a player who builds executives at the greatest possible rate is richly rewarded for no apparent reason.

I haven't actually checked, but missionaries are likely exploitable as well. I don't know if there is a similar bug with limited-number buildings, such as cathedrals.
 

Attachments

  • Ramesses II AD-1788.CivBeyondSwordSave
    418.6 KB · Views: 184
It's not fail-gold, but this change in K-Mod v1.1
changelog said:
"Lost production" for units is now assigned to another unit of the same type (previously, it was converted into gold). With this change, it is possible to build more than one unit per turn. (Note: this does not affect normal production overflow. It only affects the production beyond the overflow limit.)
combined with the conversion of production overflow into gold from the unofficial patch.

This loop in CvCity:: popOrder is at fault:
Code:
// K-Mod. use excess production to build more of the same unit
int iToBuild = 1 + iLostProduction / iProductionNeeded;
int iBuilt = 0;
for (iBuilt = 0; iBuilt < iToBuild; iBuilt++)
{
   ... // (code to initialize the new unit; as in BtS)
   if (!canTrain(eTrainUnit))
       break; //  can't build any more.
}
iLostProduction -= iProductionNeeded * (iBuilt-1);
The canTrain check exits the loop before increasing the iBuilt counter, and then the line after the loop, which is supposed to reduce the overflow production when more than one unit is built, instead adds the unit cost (150 hammers) to the overflow.

A super quick fix would be to move the increment of the loop counter into the body of the for loop, though a while loop would be easier to read, say:
Code:
do {
   ... // initialize the new unit
   iBuilt++;
} while(iBuilt < iToBuild && canTrain(eTrainUnit));
 
Top Bottom