3 # $Id: elite-prices,v 1.5 2003/03/09 23:45:02 mdw Exp $
5 package require "elite" "1.0.1"
9 foreach-world $galaxy1 p {
10 set e $eco($p(economy))
12 if {[info exists rep($e)]} { continue }
16 if {$i == 8} { break }
21 set from $rep(poor-agri)
32 if {$x < $lo} { set lo $x }
33 if {$x > $hi} { set hi $x }
35 return [list $lo [expr {$tot/double($n)}] $hi]
40 if {[info exists rep($p)]} { return $rep($p) }
41 set s [parse-planet-spec $g $p]
42 if {[string equal $s ""]} {
43 puts stderr "$argv0: bad planet spec `$p'"
49 proc get-prices {ss arr} {
50 global products allreps
52 foreach {t p} $products { set l($t) {} }
53 foreach s [if {[string equal $ss ""]} { set allreps } { set ss }] {
54 if {![string equal $s ""]} {
55 for {set i 0} {$i < 256} {incr i} {
57 foreach {t p} $products { lappend l($t) [lindex $m($t) 0] }
61 foreach {t p} $products {
62 set a($t) [loavghi $l($t)]
68 set usage "usage: $argv0 \[-g GALAXY\] \[-s SORT\] \[FROM TO\]"
69 for {set i 0} {$i < [llength $argv]} {incr i} {
70 switch -glob -- [lindex $argv $i] {
73 set a [lindex $argv $i]
74 set g [parse-galaxy-spec $a]
75 if {[string equal $g ""]} {
76 puts stderr "$argv0: bad galaxy string `$a'"
83 set a [lindex $argv $i]
85 "min" - "minimum" { set sortcol 1 }
86 "avg" - "average" { set sortcol 2 }
87 "max" - "maximum" { set sortcol 3 }
89 puts stderr "$argv0: unknown sort type: `$a' (must be `min', `max' or `avg'"
108 set argv [lrange $argv $i end]
109 switch -exact -- [llength $argv] {
112 set w [get-world [lindex $argv 0]]
114 foreach {t p} $products {
115 destructure {min avg max} $pp($t)
116 puts [format "%-12s %5.1f %5.1f %5.1f" $t \
117 [expr {$min/10.0}] [expr {$avg/10.0}] [expr {$max/10.0}]]
122 destructure {f t} $argv
123 set from [get-world $f]
124 set to [get-world $t]
125 foreach {p s} [list $f $from $t $to] {
126 if {[string equal $s ""]} {
127 puts stderr "$argv0: bad planet spec `$p'"
141 foreach {t p} $products {
142 destructure {flo favg fhi} $fp($t)
143 destructure {tlo tavg thi} $tp($t)
144 lappend pp [list $t \
145 [expr {$tlo - $fhi}] \
146 [expr {int($tavg - $favg)}] \
147 [expr {$thi - $flo}]]
151 set pp [lsort -index $sortcol -real -decreasing $pp]
154 destructure {t min avg max} $i
155 puts [format "%-12s %6.1f %5.1f %5.1f" $t \
156 [expr {$min/10.0}] [expr {$avg/10.0}] [expr {$max/10.0}]]