chiark / gitweb /
1c0c77408e99e85f5e41eb67721709441a6fda6c
[rocl] / elite-describe
1 #! /usr/bin/tclsh
2
3 package require "elite" "1.0.0"
4
5 proc describe n {
6   global economy government
7   elite-worldinfo p $n
8   puts "Name: $p(name)"
9   puts "Position: $p(x), $p(y) LY"
10   puts "Economy: $economy($p(economy))"
11   puts "Government: $government($p(government))"
12   puts "Tech. level: $p(techlevel)"
13   puts [format "Population: %s billion (%s)" \
14       [expr {$p(population)/10.0}] $p(inhabitants)]
15   puts "Gross productivity: $p(productivity) M Cr"
16   puts "Radius: $p(radius) km"
17   puts ""
18   set ll {}
19   set l 0
20   foreach w $p(description) {
21     incr l
22     incr l [string length $w]
23     if {$l > 72} { puts $ll; set ll {}; set l 0 }
24     lappend ll $w
25   }
26   puts $ll
27 }
28
29 if {[llength $argv] < 1} {
30   puts stderr "usage: $argv0 \[-g GALAXY\] PLANET ..."
31   exit 1
32 }
33 set g $galaxy1
34 for {set i 0} {$i < [llength $argv]} {incr i} {
35   set a [lindex $argv $i]
36   switch -- $a {
37     "-g" {
38       incr i
39       set a [lindex $argv $i]
40       set g [parse-galaxy-spec $a]
41       if {[string equal $g ""]} {
42         puts stderr "$argv0: bad galaxy string `$a'"
43         exit 1
44       }
45       destructure {. g} $g
46     }
47     default {
48       set n [parse-planet-spec $g $a]
49       if {[string equal $n ""]} {
50         puts stderr "$argv0: unknown planet `$a'"
51         continue
52       }
53       describe $n
54       puts ""
55     }
56   }
57 }