3 # $Id: elite-path,v 1.3 2003/03/04 10:26:18 mdw Exp $
5 package require "elite" "1.0.0"
11 for {set i 0} {$i < [llength $argv]} {incr i} {
12 set a [lindex $argv $i]
16 set a [lindex $argv $i]
17 set g [parse-galaxy-spec $a]
18 if {[string equal $g ""]} {
19 puts stderr "$argv0: bad galaxy string `$a'"
26 set a [lindex $argv $i]
27 set weight "weight-$a"
28 if {[lsearch -exact [info commands "weight-*"] $weight] == -1} {
29 puts stderr "$argv0: unknown weight function `$a'"
30 puts stderr "$argv0: I know [info commands weight-*]"
36 set a [lindex $argv $i]
38 "none" - "distance" - "weight" { set acc $a }
40 puts stderr "$argv0: unknown accumulation `$a'"
41 puts stderr "$argv0: I know `none', `distance' and `weight'"
50 puts stderr "unknown switch `$a'"
64 foreach a [lrange $argv $i end] {
65 set s [parse-planet-spec $g $a]
66 if {[string equal $s ""]} {
67 puts stderr "$argv0: unknown planet `$a'"
70 if {![info exists px($s)]} {
71 puts stderr "$argv0: planet `$a' doesn't exist in galaxy $ng"
76 if {[llength $r] < 2} {
77 puts stderr "usage: $argv0 \[-g GALAXY\] \[-w WEIGHT\] \[-a ACC\] PLANET PLANET ..."
80 puts -nonewline stderr "\[computing adjacency table..."
83 set home [lindex $r 0]
87 foreach w [lrange $r 1 end] {
88 destructure {p m} [shortest-path adj $home $w $weight]
90 puts -stderr "$argv0: no route from [worldinfo $home] to [worldinfo $w]"
93 set tm [expr {$tm + $m}]
97 puts [format " 1 %s" [world-summary $start]]
100 elite-worldinfo p $start
101 destructure {x y} [list $p(x) $p(y)]
106 if {![string equal $s $last]} {
108 set d [expr {[world-distance $x $y $p(x) $p(y)]/10.0}]
110 set td [expr {$td + $d}]
111 set summ [format "%3d %s" $h [world-summary $s]]
112 set w [eval $weight [list $last $s]]
113 set tw [expr {$tw + $w}]
117 append summ [format " (+ %.1f = %.1f LY)" $d $td]
120 append summ [format " (+ %s = %s)" $w $tw]
124 destructure {x y} [list $p(x) $p(y)]
128 if {$tw != $tm} { error "inconsistent metric ($tw != $tm)" }
131 if {![string equal $acc "distance"]} {
132 append summ [format "%stotal distance = %.1f LY" $sep $td]
135 if {![string equal $weight "weight-hops"] && \
136 ![string equal $weight "weight-fuel"] && \
137 ![string equal $acc "weight"]} {
138 append summ [format "%stotal metric = %s" $sep $tm]
141 if {![string equal $summ "()"]} { puts $summ }