]> git.scottworley.com Git - planeteer/blob - planeteer.go
fd697beab4216deaf35127a5c161f875b57f2f36
[planeteer] / planeteer.go
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
18 package main
19
20 import "flag"
21 import "json"
22 import "os"
23 import "fmt"
24
25 var datafile = flag.String("planet_data_file", "planet-data",
26 "The file to read planet data from")
27
28 type planet_data struct {
29 Commodities []struct {
30 Name string
31 BasePrice int
32 CanSell bool
33 Limit int
34 }
35 Planets []struct {
36 Name string
37 BeaconOn bool
38 /* Use relative prices rather than absolute prices because you
39 can get relative prices without traveling to each planet. */
40 RelativePrices []struct {
41 Name string
42 Value int
43 }
44 }
45 }
46
47 func ReadData() (data planet_data) {
48 f, err := os.Open(*datafile)
49 if err != nil {
50 panic(err)
51 }
52 defer f.Close()
53 err = json.NewDecoder(f).Decode(&data)
54 if err != nil {
55 panic(err)
56 }
57 return
58 }
59
60 func main() {
61 flag.Parse()
62 data := ReadData()
63 fmt.Printf("%v", data)
64 }