3 # $Id: elite-prices,v 1.3 2003/02/26 00:03:08 mdw Exp $
5 package require "elite" "1.0.0"
7 foreach-world $galaxy1 p {
8 set econame $eco($p(economy))
9 if {[info exists rep($econame)]} { continue }
10 set rep($econame) $p(seed)
14 set from $rep(poor-agri)
25 if {$x < $lo} { set lo $x }
26 if {$x > $hi} { set hi $x }
28 return [list $lo [expr {$tot/double($n)}] $hi]
33 if {[info exists rep($p)]} { return $rep($p) }
34 set s [parse-planet-spec $g $p]
35 if {[string equal $s ""]} {
36 puts stderr "$argv0: bad planet spec `$p'"
42 proc check-profits {from to} {
44 set np [expr {[llength $products]/2}]
45 puts -nonewline stderr "Thinking: \[[string repeat { } 32]\] "
46 puts -nonewline stderr "\[[string repeat { } $np]\] "
47 puts -nonewline stderr "\rThinking: \["
49 foreach {a s} [list l $from e $to] {
50 for {set f 0} {$f < 256} {incr f} {
52 foreach {t p} $products { destructure [list ${a}($f:$t) .] $m($t) }
53 if {($f & 15) == 15} { puts -nonewline stderr "."; flush stderr }
56 puts -nonewline stderr "\] \["
59 foreach {t p} $products {
62 for {set f 0} {$f < 256} {incr f} {
66 destructure {llo lavg lhi} [loavghi $ll]
67 destructure {elo eavg ehi} [loavghi $ee]
69 [expr {$elo - $lhi}] \
70 [expr {int($eavg - $lavg)}] \
72 puts -nonewline stderr "."; flush stderr
80 set usage "usage: $argv0 \[-g GALAXY\] \[-s SORT\] \[FROM TO\]"
81 for {set i 0} {$i < [llength $argv]} {incr i} {
82 switch -glob -- [lindex $argv $i] {
85 set a [lindex $argv $i]
86 set g [parse-galaxy-spec $a]
87 if {[string equal $g ""]} {
88 puts stderr "$argv0: bad galaxy string `$a'"
95 set a [lindex $argv $i]
97 "min" - "minimum" { set sortcol 1 }
98 "avg" - "average" { set sortcol 2 }
99 "max" - "maximum" { set sortcol 3 }
101 puts stderr "$argv0: unknown sort type: `$a' (must be `min', `max' or `avg'"
120 set argv [lrange $argv $i end]
121 switch -exact -- [llength $argv] {
124 destructure {fp tp} $argv
125 set from [get-world $fp]
126 set to [get-world $tp]
127 foreach {p s} [list $fp $from $tp $to] {
128 if {[string equal $s ""]} {
129 puts stderr "$argv0: bad planet spec `$p'"
140 set pp [check-profits $from $to]
142 set pp [lsort -index $sortcol -real -decreasing $pp]
145 destructure {t min avg max} $i
146 puts [format "%-15s %6.1f %5.1f %5.1f" $t \
147 [expr {$min/10.0}] [expr {$avg/10.0}] [expr {$max/10.0}]]