Good = { goods = {}, maxMult = 6, -- max price multiplier if source & dest are at opposite ends of universe potentialGoods = { {name = 'Bobble-Headed Dolls', base = 20, chance = 0.5}, {name = 'Food', base = 50, chance = 0.8}, {name = 'Medical Supplies', base = 150, chance = 0.4}, {name = 'Building Materials', base = 100, chance = 0.4}, {name = 'Scrap', base = 25, chance = 0.4} }, } function Good:stockPlanets() for _, planet in ipairs(the.planets.sprites) do while #planet.goods == 0 do for _, good in ipairs(self.potentialGoods) do if math.random() < good.chance then if self.goods[good.name] then -- calculate price from distance to source local source = self.goods[good.name].source local base = self.goods[good.name].base local gvec = vector.new(planet.x - source.x, planet.y - source.y) -- multiplier should be betw 1-maxMult and increase -- exponentially with distance from source local mult = gvec:len2() / the.bg.width^2 * (self.maxMult - 1) + 1 table.insert(planet.goods, {good.name, math.floor(base * mult)}) else -- set this planet as the source self.goods[good.name] = { source = planet, base = good.base } end end end -- for good in potentialGoods end -- while #planet.goods == 0 end -- for planet in the.planets end