1
0
forked from 0ad/0ad

Infinite farms with diminishing returns (but no farmland). Refs #1318.

This was SVN commit r13616.
This commit is contained in:
alpha123 2013-07-30 06:04:53 +00:00
parent 857ae2dd3e
commit 344a149a66
54 changed files with 16373 additions and 15239 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -96,7 +96,8 @@ function displaySingle(entState, template)
// Resource stats
if (entState.resourceSupply)
{
var resources = Math.ceil(+entState.resourceSupply.amount) + " / " + entState.resourceSupply.max;
var resources = entState.resourceSupply.isInfinite ? "\u221E" : // Infinity symbol
Math.ceil(+entState.resourceSupply.amount) + " / " + entState.resourceSupply.max;
var resourceType = entState.resourceSupply.type["generic"];
if (resourceType == "treasure")
resourceType = entState.resourceSupply.type["specific"];
@ -104,7 +105,8 @@ function displaySingle(entState, template)
var unitResourceBar = getGUIObjectByName("resourceBar");
var resourceSize = unitResourceBar.size;
resourceSize.rright = 100 * Math.max(0, Math.min(1, +entState.resourceSupply.amount / +entState.resourceSupply.max));
resourceSize.rright = entState.resourceSupply.isInfinite ? 100 :
100 * Math.max(0, Math.min(1, +entState.resourceSupply.amount / +entState.resourceSupply.max));
unitResourceBar.size = resourceSize;
getGUIObjectByName("resourceLabel").caption = toTitleCase(resourceType) + ":";
getGUIObjectByName("resourceStats").caption = resources;

View File

@ -260,12 +260,13 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
}
var cmpResourceSupply = Engine.QueryInterface(ent, IID_ResourceSupply);
if (cmpResourceSupply)
{
ret.resourceSupply = {
"max": cmpResourceSupply.GetMaxAmount(),
"amount": cmpResourceSupply.GetCurrentAmount(),
"type": cmpResourceSupply.GetType(),
if (cmpResourceSupply)
{
ret.resourceSupply = {
"isInfinite": cmpResourceSupply.IsInfinite(),
"max": cmpResourceSupply.GetMaxAmount(),
"amount": cmpResourceSupply.GetCurrentAmount(),
"type": cmpResourceSupply.GetType(),
"killBeforeGather": cmpResourceSupply.GetKillBeforeGather(),
"maxGatherers": cmpResourceSupply.GetMaxGatherers(),
"gatherers": cmpResourceSupply.GetGatherers()

View File

@ -255,9 +255,14 @@ ResourceGatherer.prototype.GetTargetGatherRate = function(target)
else if (type.generic && rates[type.generic])
{
rate = rates[type.generic] / cmpPlayer.GetCheatTimeMultiplier();
}
return (rate || 0);
}
// Apply diminishing returns with more gatherers, e.g. for infinite farms. For most resources this has no effect. (GetDiminishingReturns will return null.)
var diminishingReturns = cmpResourceSupply.GetDiminishingReturns();
if (diminishingReturns)
rate = +(rate - Math.pow((cmpResourceSupply.GetGatherers().length || 1) - 1, 2) / diminishingReturns).toFixed(2);
return (rate || 0);
};
/**

View File

@ -7,13 +7,13 @@ ResourceSupply.prototype.Schema =
"<Type>food.meat</Type>" +
"</a:example>" +
"<element name='KillBeforeGather' a:help='Whether this entity must be killed (health reduced to 0) before its resources can be gathered'>" +
"<data type='boolean'/>" +
"</element>" +
"<element name='Amount' a:help='Amount of resources available from this entity'>" +
"<data type='nonNegativeInteger'/>" +
"</element>" +
"<element name='Type' a:help='Type of resources'>" +
"<choice>" +
"<data type='boolean'/>" +
"</element>" +
"<element name='Amount' a:help='Amount of resources available from this entity'>" +
"<choice><data type='nonNegativeInteger'/><value>Infinity</value></choice>" +
"</element>" +
"<element name='Type' a:help='Type of resources'>" +
"<choice>" +
"<value>wood.tree</value>" +
"<value>wood.ruins</value>" +
"<value>stone.rock</value>" +
@ -29,21 +29,32 @@ ResourceSupply.prototype.Schema =
"<value>treasure.metal</value>" +
"<value>treasure.food</value>" +
"</choice>" +
"</element>" +
"<element name='MaxGatherers' a:help='Amount of gatherers who can gather resources from this entity at the same time'>" +
"<data type='nonNegativeInteger'/>" +
"</element>";
ResourceSupply.prototype.Init = function()
{
// Current resource amount (non-negative)
this.amount = this.GetMaxAmount();
this.gatherers = []; // list of IDs
};
ResourceSupply.prototype.GetKillBeforeGather = function()
{
return (this.template.KillBeforeGather == "true");
"</element>" +
"<element name='MaxGatherers' a:help='Amount of gatherers who can gather resources from this entity at the same time'>" +
"<data type='nonNegativeInteger'/>" +
"</element>" +
"<optional>" +
"<element name='DiminishingReturns' a:help='The rate at which adding more gatherers decreases overall efficiency. Lower numbers = faster dropoff. Leave the element out for no diminishing returns.'>" +
"<ref name='positiveDecimal'/>" +
"</element>" +
"</optional>";
ResourceSupply.prototype.Init = function()
{
// Current resource amount (non-negative)
this.amount = this.GetMaxAmount();
this.gatherers = []; // list of IDs
this.infinite = !isFinite(+this.template.Amount);
};
ResourceSupply.prototype.IsInfinite = function()
{
return this.infinite;
};
ResourceSupply.prototype.GetKillBeforeGather = function()
{
return (this.template.KillBeforeGather == "true");
};
ResourceSupply.prototype.GetMaxAmount = function()
@ -63,14 +74,24 @@ ResourceSupply.prototype.GetMaxGatherers = function()
ResourceSupply.prototype.GetGatherers = function()
{
return this.gatherers;
};
ResourceSupply.prototype.TakeResources = function(rate)
{
// 'rate' should be a non-negative integer
var old = this.amount;
return this.gatherers;
};
ResourceSupply.prototype.GetDiminishingReturns = function()
{
if ("DiminishingReturns" in this.template)
return ApplyTechModificationsToEntity("ResourceSupply/DiminishingReturns", +this.template.DiminishingReturns, this.entity);
return null;
};
ResourceSupply.prototype.TakeResources = function(rate)
{
if (this.infinite)
return { "amount": rate, "exhausted": false };
// 'rate' should be a non-negative integer
var old = this.amount;
this.amount = Math.max(0, old - rate);
var change = old - this.amount;

View File

@ -116,7 +116,7 @@ StatusBars.prototype.RegenerateSprites = function()
var cmpResourceSupply = Engine.QueryInterface(this.entity, IID_ResourceSupply);
if (cmpResourceSupply)
{
AddBar("supply", cmpResourceSupply.GetCurrentAmount() / cmpResourceSupply.GetMaxAmount());
AddBar("supply", cmpResourceSupply.IsInfinite() ? 1 : cmpResourceSupply.GetCurrentAmount() / cmpResourceSupply.GetMaxAmount());
}
/*

View File

@ -45,9 +45,9 @@
<RallyPoint disable=""/>
<ResourceSupply>
<KillBeforeGather>false</KillBeforeGather>
<Amount>5000</Amount>
<Amount>Infinity</Amount>
<Type>food.grain</Type>
<MaxGatherers>5</MaxGatherers>
<MaxGatherers>5</MaxGatherers>
</ResourceSupply>
<Sound>
<SoundGroups>

File diff suppressed because it is too large Load Diff

View File

@ -17,6 +17,7 @@ for ( # (these are probably more than we really need)
'Spacing Modifier Letters',
'General Punctuation',
'Combining Diacritical Marks',
'Mathematical Operators',
) {
print "# $_\n";
for my $r (@{Unicode::UCD::charblock($_)}) {