3 # $Id: elite-map,v 1.2 2003/02/25 00:25:38 mdw Exp $
5 package require "elite" "1.0.0"
7 set syms "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
10 if {$i < [string length $syms]} {
11 return [string index $syms $i]
13 set hi [expr {$i / [string length $syms]}]
14 set lo [expr {$i % [string length $syms]}]
15 return [string index $syms $hi][string index $syms $lo]
18 proc show-map {asp wx wy ww {n ""}} {
25 if {$x < $minx} { set minx $x}
26 if {$y < $miny} { set miny $y}
27 if {$x > $maxx} { set maxx $x}
28 if {$y > $maxy} { set maxy $y}
30 set dx [expr {$maxx - $minx}]
31 set dy [expr {$maxy - $miny}]
32 if {$dx == 0} { set dx 1 }
33 if {$dy == 0} { set dy 1 }
35 set sc [expr {$wx/double($dx)}]
36 if {$dy * $sc/$asp > $wy} {
37 set sc [expr {$wy * $asp/double($dy)}]
41 set gx [expr {int(($x - $minx) * $sc + 0.5)}]
42 set gy [expr {int(($y - $miny) * $sc/$asp + 0.5)}]
43 lappend gw [list $s $gx $gy]
46 set pw [lsort -index 1 -integer -increasing $gw]
47 set pw [lsort -index 2 -integer -increasing $pw]
53 destructure {s px py} $w
55 puts -nonewline [string repeat "\n" [expr {$py - $y}]]
60 puts -nonewline [string repeat " " [expr {$px - $x}]]
63 if {[string equal $s $n]} {
70 incr x [string length $sy]
79 if {![string equal $n ""]} {
84 set out [format "%2s %s" $sy [world-summary $s]]
85 if {![string equal $n ""]} {
86 append out [format " (%.1f LY)" \
87 [expr {[world-distance $p(x) $p(y) $pp(x) $pp(y)]/10.0}]]
93 proc local-area {g d n} {
99 if {abs($p(x) - $x) > $d + 10 || abs($p(y) - $y) > $d + 10 ||
100 [world-distance $p(x) $p(y) $x $y] > $d} { continue }
112 set usage "usage: $argv0 \[-qv\] \[-g GAL\] \[-d DIST\] \[-w WD,HT\] \[-a ASP\] \[PLANET\]"
113 for {set i 0} {$i < [llength $argv]} {incr i} {
114 set a [lindex $argv $i]
118 set a [lindex $argv $i]
119 set g [parse-galaxy-spec $a]
120 if {[string equal $g ""]} {
121 puts stderr "$argv0: bad galaxy string `$a'"
128 set d [expr {[lindex $argv $i] * 10}]
132 if {![regexp {^(\d+),(\d+)$} [lindex $argv $i] . wx wy]} {
133 puts stderr "$argv0: bad window size string"
139 set asp [lindex $argv $i]
161 set p [lrange $argv $i end]
162 switch -exact [llength $p] {
169 set n [parse-planet-spec $g $a]
170 if {[string equal $n ""]} {
171 puts stderr "$argv0: unknown planet `$a'"
174 set w [local-area $g $d $n]
181 set l [show-map $asp $wx $wy $w $n]