3 # $Id: elite-path,v 1.4 2003/03/07 00:42:10 mdw Exp $
5 package require "elite" "1.0.1"
12 for {set i 0} {$i < [llength $argv]} {incr i} {
13 set a [lindex $argv $i]
17 set a [lindex $argv $i]
18 set g [parse-galaxy-spec $a]
19 if {[string equal $g ""]} {
20 puts stderr "$argv0: bad galaxy string `$a'"
27 set d [expr {int([lindex $argv $i] * 10)}]
31 set a [lindex $argv $i]
32 set weight "weight-$a"
33 if {[lsearch -exact [info commands "weight-*"] $weight] == -1} {
34 puts stderr "$argv0: unknown weight function `$a'"
35 puts stderr "$argv0: I know [info commands weight-*]"
41 set a [lindex $argv $i]
43 "none" - "distance" - "weight" { set acc $a }
45 puts stderr "$argv0: unknown accumulation `$a'"
46 puts stderr "$argv0: I know `none', `distance' and `weight'"
55 puts stderr "unknown switch `$a'"
65 set ww [elite-galaxylist $g]
69 foreach a [lrange $argv $i end] {
70 set s [parse-planet-spec $g $a]
71 if {[string equal $s ""]} {
72 puts stderr "$argv0: unknown planet `$a'"
75 if {![info exists px($s)]} {
76 puts stderr "$argv0: planet `$a' doesn't exist in galaxy $ng"
81 if {[llength $r] < 2} {
82 puts stderr "usage: $argv0 \[-g GAL\] \[-d DIST\] \[-w WEIGHT\] \[-a ACC\] PLANET PLANET ..."
85 elite-adjacency adj $ww $d
86 set home [lindex $r 0]
90 foreach w [lrange $r 1 end] {
91 destructure {p m} [shortest-path adj $home $w $weight]
93 puts stderr "$argv0: no route from [worldname $home] to [worldname $w]"
96 set tm [expr {$tm + $m}]
100 puts [format " 1 %s" [world-summary $start]]
103 elite-worldinfo p $start
104 destructure {x y} [list $p(x) $p(y)]
109 if {![string equal $s $last]} {
111 set d [expr {[elite-distance $x $y $p(x) $p(y)]/10.0}]
113 set td [expr {$td + $d}]
114 set summ [format "%3d %s" $h [world-summary $s]]
115 set w [eval $weight [list $last $s]]
116 set tw [expr {$tw + $w}]
120 append summ [format " (+ %.1f = %.1f LY)" $d $td]
123 append summ [format " (+ %s = %s)" $w $tw]
127 destructure {x y} [list $p(x) $p(y)]
131 if {$tw != $tm} { error "inconsistent metric ($tw != $tm)" }
134 if {![string equal $acc "distance"]} {
135 append summ [format "%stotal distance = %.1f LY" $sep $td]
138 if {![string equal $weight "weight-hops"] && \
139 ![string equal $weight "weight-fuel"] && \
140 ![string equal $acc "weight"]} {
141 append summ [format "%stotal metric = %s" $sep $tm]
144 if {![string equal $summ "# ()"]} { puts $summ }