#! /usr/bin/tclsh # # $Id: elite-path,v 1.2 2003/02/25 00:25:38 mdw Exp $ package require "elite" "1.0.0" set g $galaxy1 set ng 1 set weight weight-hops for {set i 0} {$i < [llength $argv]} {incr i} { set a [lindex $argv $i] switch -glob -- $a { "-g" { incr i set a [lindex $argv $i] set g [parse-galaxy-spec $a] if {[string equal $g ""]} { puts stderr "$argv0: bad galaxy string `$a'" exit 1 } destructure {ng g} $g } "-w" { incr i set a [lindex $argv $i] set weight "weight-$a" if {[lsearch -exact [info commands "weight-*"] $weight] == -1} { puts stderr "$argv0: unknown weight function `$a'" puts stderr "$argv0: I know [info commands weight-*]" exit 1 } } "--" { incr i break } "-*" { puts stderr "unknown switch `$a'" exit 1 } default { break } } } set r {} set ww [worldinfo $g] foreach-world $g ii { set px($ii(seed)) 1 } foreach a [lrange $argv $i end] { set s [parse-planet-spec $g $a] if {[string equal $s ""]} { puts stderr "$argv0: unknown planet `$a'" exit 1 } if {![info exists px($s)]} { puts stderr "$argv0: planet `$a' doesn't exist in galaxy $ng" exit 1 } lappend r $s } if {[llength $r] < 2} { puts stderr "usage: $argv0 \[-g GALAXY\] \[-w WEIGHT\] PLANET PLANET ..." exit 1 } puts -nonewline stderr "\[computing adjacency table..." adjacency $ww adj puts stderr " done\]" set home [lindex $r 0] set rt {} foreach w [lrange $r 1 end] { destructure {p .} [shortest-path adj $home $w $weight] if {![llength $p]} { puts -stderr "$argv0: no route from [worldinfo $home] to [worldinfo $w]" exit 1 } eval lappend rt $p set home $w } set last x foreach s $rt { if {![string equal $s $last]} { puts [world-summary $s] set last $s } }