/traderous

To get this branch, use:
bzr branch http://9ix.org/bzr/traderous
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Planet = Tile:extend {
   image = 'data/planet1.png',
   potentialGoods = {
      {name = 'Bobble-Headed Dolls',
       low = 50, med = 100, high = 150,
       chance = 0.5},
      {name = 'Alliance Foodstuffs',
       low = 100, med = 250, high = 400,
       chance = 0.8},
      {name = 'Antique Weapons',
       low = 5000, med = 6000, high = 8000,
       chance = 0.1}
   },
   goods = {},
   onNew = function (self)
              self.indicator = Tile:new{ image = 'data/planet1ind.png' }
              the.indicators:add(self.indicator)

              while #self.goods == 0 do
                 for _, good in ipairs(self.potentialGoods) do
                    if math.random() < good.chance then
                       local tier = math.random(4) -- betw 1 and 4
                       if tier == 1 then
                          table.insert(self.goods, {good.name, good.low})
                       elseif tier ==2 then
                          table.insert(self.goods, {good.name, good.high})
                       else
                          -- double chance for med (3 or 4)
                          table.insert(self.goods, {good.name, good.med})
                       end
                    end
                 end
              end
           end,
   onUpdate = function (self)
                 if the.keys:justPressed('l') then
                    local hw = self.width / 2
                    local pvec = vector.new(the.player.x - (self.x + hw),
                                            the.player.y - (self.y + hw))

                    if pvec:len2() < hw ^ 2 then
                       tradeView = TradeView:new{ planet = self }
                       tradeView:activate()
                    end
                 end
              end
}