Building and repairing does not maintain 100% efficiency as the number of villagers working increases. Instead, the effective labour grows linearly, but at less than the growth of the number of villagers working. In particular, every extra villager constructing a building works at 33% efficiency and every extra villager repairing works at 50% efficiency. Building times are independent of everything except for the Spanish civilisation bonus and treadmill crane. Repairing rates however are fixed, but repair cost rates are directly proportional to the building cost and inversely proportional to the building's hit points in all case except for the town centre, where the repair cost rate is independent of all other factors.
The time taken to construct a building as a function of the number of villagers working on it is
s(n)=t0/((2/3)+(n/3))=3t0/(2+n)
Where t0 is the time taken to build with one villager. This can be normalised by dividing by t0 and
t(n)=3/(2+n)
Is the fraction of the build time with one villager required when building with n villagers. This can be verified by plotting the reciprocal of the build times against the number of villagers building; the result is simply a straight line that increases by 1/3 for every extra villager. What this shows is that every villager after the first is the equivalent of building with 1/3 of an extra villager, so building with 4 villagers is similar to building with 2 effective villagers.
Building with extra villagers is less efficient than building with one villager, but how less efficient? We want to know the total amount of time a group of villagers spends constructing a building. This is simply the build time multiplied by the number of villagers.
v(n)=3n/(2+n)
If we build with n villagers, the amount of time earlier the building is constructed is given by
t'(n)=1-3/(2+n)
t'(n)=(n-1)/(n+2)
The amount of extra villager-seconds expended to construct the building earlier is
v'(n)=3n/(2+n)-1
v'(n)=2(n-1)/(n+2)
So to construct a building t' seconds earlier, we pay for it with v' villager seconds. Dividing v' by t', we get 2, which means that for every second we want to save in the build time, we must make our villagers collectively work for 2 seconds longer. This means the waste accrued from building with multiple villagers grows linearly, so the penalty for building with many villagers is in principle no worse than the penalty for building with few villagers. Building a castle with many villagers remains economical even if it's erected in panic to protect against an approaching army. Constructing a town centre with many villagers leads to earlier villager production in exchange for a one-off time investment. Every second earlier a town centre is built leads to 1/25 of an extra villager; since the price of getting a town centre up a second earlier is 2 villager-seconds, this investment pays off after 50 seconds. Taking into account the cost of the extra 1/25 of a villager (2 food), we end up with approximately 200 seconds. In most situations, building a town centre with many villagers is very economical.
We now look at repairing. Unlike building, repairing isn't normalised to a building's construction time. Instead, repairing restores a fixed number of hit points to a building per second. Once again, when multiple villagers are involved, the hit points per second per villager does not remain the same. The formula for hit points restored per second as a function of the number of villagers repairing is
h(n)=25(n+1)/4
Although the hit points restored per second bears no relation to the building's hit points, the resources consumed per second does. With the exception of town centres, every building consumes half the resources per hit point that it takes to build it. The corollary of this is that repairing a building is very cost efficient and effectively halves the cost of that building. Building a second castle under the inevitability that the first will go down is equivalent to repairing one castle until you have "built" three castles. On top of that, masonry, architecture and hoardings give a short term boost to a building's hit points proportional to the hit points remaining on the building at the time. However, its long term effect is to make repairing a building more cost-efficient. A Byzantine castle with hoardings is almost 70% more cost effective to repair than an Aztec castle, while a French castle is 95% more cost-efficient.
The case of town centre varies from the rest of buildings in a very particular way; its repair cost bears no relation to it construction cost. It does not cost stone to repair a town centre, but it does cost a lot more wood. This wood rate has been quoted as being double the construction wood rate, but my tests have found this to be slightly wrong. To repair a town centre from half health would notionally cost half the town centre's entire wood cost, which is 275 wood. However, it in fact costs 280 wood. Repairing a town centre from one hit point yields 561 wood. This is clearly an irregular piece of programming, and the stray 1 might also be a remainder of this. Also, the repair cost is not affected by the British town centre bonus (even when the repair is done in the castle age), setting it aside from other civilisation building discounts, where the cost of repairing is reduced by the same factor as the cost of construction. Whatever way this is viewed, repairing a town centre is generally very wasteful, and the best response to a douche is simply to let the town centre go down and rebuild it somewhere else.
The rate at which villagers repair remains constant however, even with treadmill crane and the Spanish bonus, so a castle under fire from trebuchets and bombard cannons still needs the same level of attention regardless of the technologies and bonuses affecting the castle. A trebuchet inflicts 431 damage every 10 seconds, which is 43.1 damage per second. This requires 6 villagers repairing, and 7 for every extra trebuchet. A bombard cannon deals 224 damage every 6.5 seconds, which is equivalent to 34.5 damage per second. This requires 5 villagers repairing to offset, with 6 more for every extra bombard cannon. Taking into account hill advantage and siege engineers increases or reduces these numbers, but in general, this is an applicable rule of thumb.
Repairing siege weapons is similar to repairing buildings. Once again, siege weapons are repaired at half their construction cost rate. However, their hit point restoration rate is r(n)=25(n+1)/16. This is one quarter of the building restoration rate, which is presumably to balance out the smaller number of hit points siege weapons have and to avoid making repairing too easy. Repairing ships is exactly the same as repairing siege weapons.
Finally, we look at limiting behaviour of our formulae. Setting n equal to 0 in our construction formula gives us a hypothetical build time of 50% more than with one villager. This is obviously unrealistic, as 0 villagers do 0 work, as can easily be verified by setting n=0 in the villager-second formula. Letting n tend towards infinity leads to a building time of 0 and a total villager-second expenditure of three times the build time with one villager. This puts a limit on the wastage of building with multiple villagers. As we found that you pay a constant rate to shave seconds off the build time, it makes sense that reducing a build time to its minimum (0) should have a finite cost. This is twice the building time with one villager (as we are reducing the build time by the one villager build time) plus the build time with one villager, which gives three times the build time with one villager.
Increasing the number of villagers building or repairing gives a linear trade-off for the increase in speed of building or hit points restored. This is especially worthwhile for castles and town centres. The building technologies are in general underused and when researched make defending with castles very cost effective indeed. Repairing of ships and siege weapons is no different except for the slower hit point restore rate to compensate for their lower hit points. All are ultimately cost effective options.
The time taken to construct a building as a function of the number of villagers working on it is
s(n)=t0/((2/3)+(n/3))=3t0/(2+n)
Where t0 is the time taken to build with one villager. This can be normalised by dividing by t0 and
t(n)=3/(2+n)
Is the fraction of the build time with one villager required when building with n villagers. This can be verified by plotting the reciprocal of the build times against the number of villagers building; the result is simply a straight line that increases by 1/3 for every extra villager. What this shows is that every villager after the first is the equivalent of building with 1/3 of an extra villager, so building with 4 villagers is similar to building with 2 effective villagers.
Building with extra villagers is less efficient than building with one villager, but how less efficient? We want to know the total amount of time a group of villagers spends constructing a building. This is simply the build time multiplied by the number of villagers.
v(n)=3n/(2+n)
If we build with n villagers, the amount of time earlier the building is constructed is given by
t'(n)=1-3/(2+n)
t'(n)=(n-1)/(n+2)
The amount of extra villager-seconds expended to construct the building earlier is
v'(n)=3n/(2+n)-1
v'(n)=2(n-1)/(n+2)
So to construct a building t' seconds earlier, we pay for it with v' villager seconds. Dividing v' by t', we get 2, which means that for every second we want to save in the build time, we must make our villagers collectively work for 2 seconds longer. This means the waste accrued from building with multiple villagers grows linearly, so the penalty for building with many villagers is in principle no worse than the penalty for building with few villagers. Building a castle with many villagers remains economical even if it's erected in panic to protect against an approaching army. Constructing a town centre with many villagers leads to earlier villager production in exchange for a one-off time investment. Every second earlier a town centre is built leads to 1/25 of an extra villager; since the price of getting a town centre up a second earlier is 2 villager-seconds, this investment pays off after 50 seconds. Taking into account the cost of the extra 1/25 of a villager (2 food), we end up with approximately 200 seconds. In most situations, building a town centre with many villagers is very economical.
We now look at repairing. Unlike building, repairing isn't normalised to a building's construction time. Instead, repairing restores a fixed number of hit points to a building per second. Once again, when multiple villagers are involved, the hit points per second per villager does not remain the same. The formula for hit points restored per second as a function of the number of villagers repairing is
h(n)=25(n+1)/4
Although the hit points restored per second bears no relation to the building's hit points, the resources consumed per second does. With the exception of town centres, every building consumes half the resources per hit point that it takes to build it. The corollary of this is that repairing a building is very cost efficient and effectively halves the cost of that building. Building a second castle under the inevitability that the first will go down is equivalent to repairing one castle until you have "built" three castles. On top of that, masonry, architecture and hoardings give a short term boost to a building's hit points proportional to the hit points remaining on the building at the time. However, its long term effect is to make repairing a building more cost-efficient. A Byzantine castle with hoardings is almost 70% more cost effective to repair than an Aztec castle, while a French castle is 95% more cost-efficient.
The case of town centre varies from the rest of buildings in a very particular way; its repair cost bears no relation to it construction cost. It does not cost stone to repair a town centre, but it does cost a lot more wood. This wood rate has been quoted as being double the construction wood rate, but my tests have found this to be slightly wrong. To repair a town centre from half health would notionally cost half the town centre's entire wood cost, which is 275 wood. However, it in fact costs 280 wood. Repairing a town centre from one hit point yields 561 wood. This is clearly an irregular piece of programming, and the stray 1 might also be a remainder of this. Also, the repair cost is not affected by the British town centre bonus (even when the repair is done in the castle age), setting it aside from other civilisation building discounts, where the cost of repairing is reduced by the same factor as the cost of construction. Whatever way this is viewed, repairing a town centre is generally very wasteful, and the best response to a douche is simply to let the town centre go down and rebuild it somewhere else.
The rate at which villagers repair remains constant however, even with treadmill crane and the Spanish bonus, so a castle under fire from trebuchets and bombard cannons still needs the same level of attention regardless of the technologies and bonuses affecting the castle. A trebuchet inflicts 431 damage every 10 seconds, which is 43.1 damage per second. This requires 6 villagers repairing, and 7 for every extra trebuchet. A bombard cannon deals 224 damage every 6.5 seconds, which is equivalent to 34.5 damage per second. This requires 5 villagers repairing to offset, with 6 more for every extra bombard cannon. Taking into account hill advantage and siege engineers increases or reduces these numbers, but in general, this is an applicable rule of thumb.
Repairing siege weapons is similar to repairing buildings. Once again, siege weapons are repaired at half their construction cost rate. However, their hit point restoration rate is r(n)=25(n+1)/16. This is one quarter of the building restoration rate, which is presumably to balance out the smaller number of hit points siege weapons have and to avoid making repairing too easy. Repairing ships is exactly the same as repairing siege weapons.
Finally, we look at limiting behaviour of our formulae. Setting n equal to 0 in our construction formula gives us a hypothetical build time of 50% more than with one villager. This is obviously unrealistic, as 0 villagers do 0 work, as can easily be verified by setting n=0 in the villager-second formula. Letting n tend towards infinity leads to a building time of 0 and a total villager-second expenditure of three times the build time with one villager. This puts a limit on the wastage of building with multiple villagers. As we found that you pay a constant rate to shave seconds off the build time, it makes sense that reducing a build time to its minimum (0) should have a finite cost. This is twice the building time with one villager (as we are reducing the build time by the one villager build time) plus the build time with one villager, which gives three times the build time with one villager.
Increasing the number of villagers building or repairing gives a linear trade-off for the increase in speed of building or hit points restored. This is especially worthwhile for castles and town centres. The building technologies are in general underused and when researched make defending with castles very cost effective indeed. Repairing of ships and siege weapons is no different except for the slower hit point restore rate to compensate for their lower hit points. All are ultimately cost effective options.