]> git.scottworley.com Git - planeteer/blame - planeteer.go
Convert local prices to a flat map
[planeteer] / planeteer.go
CommitLineData
d07f3caa
SW
1/* Planeteer: Give trade route advice for Planets: The Exploration of Space
2 * Copyright (C) 2011 Scott Worley <sworley@chkno.net>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18package main
19
20import "flag"
21import "json"
22import "os"
23import "fmt"
24
25var datafile = flag.String("planet_data_file", "planet-data",
26 "The file to read planet data from")
27
9b3b3d9a
SW
28type Commodity struct {
29 Name string
30 BasePrice int
31 CanSell bool
32 Limit int
33}
34
d07f3caa 35type planet_data struct {
9b3b3d9a 36 Commodities []Commodity
d07f3caa
SW
37 Planets []struct {
38 Name string
39 BeaconOn bool
40 /* Use relative prices rather than absolute prices because you
41 can get relative prices without traveling to each planet. */
9b3b3d9a 42 RelativePrices map [string] int
d07f3caa
SW
43 }
44}
45
46func ReadData() (data planet_data) {
47 f, err := os.Open(*datafile)
48 if err != nil {
49 panic(err)
50 }
51 defer f.Close()
52 err = json.NewDecoder(f).Decode(&data)
53 if err != nil {
54 panic(err)
55 }
56 return
57}
58
59func main() {
60 flag.Parse()
61 data := ReadData()
62 fmt.Printf("%v", data)
63}