1
0
forked from 0ad/0ad
0ad/binaries/data/mods/public/simulation/ai/jubot/resources.js
2011-04-23 18:34:03 +00:00

37 lines
553 B
JavaScript

var Resources = Class({
types: ["food", "wood", "stone", "metal"],
_init: function(amounts)
{
for each (var t in this.types)
this[t] = amounts[t] || 0;
},
canAfford: function(that)
{
for each (var t in this.types)
if (this[t] < that[t])
return false;
return true;
},
add: function(that)
{
for each (var t in this.types)
this[t] += that[t];
},
subtract: function(that)
{
for each (var t in this.types)
this[t] -= that[t];
},
multiply: function(n)
{
for each (var t in this.types)
this[t] *= n;
},
});