3
maxMult = 5, -- max price multiplier if source & dest are at opposite ends of universe
5
{name = 'Bobble-Headed Dolls', base = 20, chance = 0.5},
6
{name = 'Alliance Foodstuffs', base = 50, chance = 0.8},
7
{name = 'Medical Supplies', base = 150, chance = 0.4},
8
{name = 'Building Materials', base = 100, chance = 0.4},
9
{name = 'Scrap', base = 25, chance = 0.4}
13
function Good:stockPlanets()
14
for _, planet in ipairs(the.planets.sprites) do
15
while #planet.goods == 0 do
16
for _, good in ipairs(self.potentialGoods) do
17
if math.random() < good.chance then
18
if self.goods[good.name] then
19
-- calculate price from distance to source
20
local source = self.goods[good.name].source
21
local base = self.goods[good.name].base
22
local gvec = vector.new(planet.x - source.x,
25
-- multiplier should be betw 1-maxMult and increase
26
-- exponentially with distance from source
27
local mult = gvec:len2() / the.bg.width^2 * (self.maxMult - 1) + 1
29
table.insert(planet.goods, {good.name, math.floor(base * mult)})
31
-- set this planet as the source
32
self.goods[good.name] = {
39
end -- for good in potentialGoods
40
end -- while #planet.goods == 0
41
end -- for planet in the.planets