Adjust global economy based on the overall average price difference instead of amount bought vs sold.

This commit is contained in:
Robbie Antenesse 2016-04-13 23:33:42 -06:00
parent ee3dac7063
commit e87f4433d1
2 changed files with 12 additions and 10 deletions

View File

@ -92,18 +92,18 @@ G.economy = { // Aww yea, supply and demand.
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0], 0, 0, 0, 0],
CheckEconomy: function () { CheckEconomy: function () {
for (var i = 0; i < this.cargoSold; i++) { for (var i = 0; i < G.economy.cargoItemWorth.length; i++) {
var soldBoughtDifference = this.cargoBought[i] - this.cargoSold[i]; var totalPriceDifference = 0;
for (var m = 0; m < G.map.length; m++) {
if (Math.abs(soldBoughtDifference) > (this.cargoItemWorth[i] * 0.75)) { // If the difference is greater than 75% of the worth, totalPriceDifference += G.map.island.priceDifferences[i];
this.cargoItemWorth[i] += Math.round(soldBoughtDifference * 0.5); // Adjust the worth by half of the difference.
if (this.cargoItemWorth[i] < 1) {
this.cargoItemWorth[i] = 1; // Make worth never drop below 1.
}
} }
G.economy.cargoItemWorth[i] += Math.round(totalPriceDifference / G.map.length); // Apply the average price difference for the item.
} }
} }
}; };
function loadGameManager () {} function loadGameManager () {
for (var i = 0; i < G.economy.cargoItemWorth.length; i++) {
G.economy.cargoItemWorth[i] += Math.round(Math.randomRange(-5, 5));
}
}

View File

@ -110,6 +110,7 @@ pr_island.SellTo = function (itemIndex, price) {
G.inventory.cargo[itemIndex]--; G.inventory.cargo[itemIndex]--;
G.inventory.money += price; G.inventory.money += price;
G.economy.cargoSold[itemIndex]++;
} }
pr_island.BuyFrom = function (itemIndex, price) { pr_island.BuyFrom = function (itemIndex, price) {
@ -119,4 +120,5 @@ pr_island.BuyFrom = function (itemIndex, price) {
G.inventory.cargo[itemIndex]++; G.inventory.cargo[itemIndex]++;
G.inventory.money -= price; G.inventory.money -= price;
G.economy.cargoBought[itemIndex]++;
} }