X-Git-Url: https://git.distorted.org.uk/~mdw/rocl/blobdiff_plain/b130b8f56dda8528a9cc18e86f825f1f4283cfbc..4041fdd8af852bf6fb4db0aa6ddd2c8c2f640574:/elite-editor diff --git a/elite-editor b/elite-editor index 3040388..f367c1c 100755 --- a/elite-editor +++ b/elite-editor @@ -1,10 +1,10 @@ #! /usr/bin/wish # -# $Id: elite-editor,v 1.2 2003/02/25 00:25:38 mdw Exp $ +# $Id$ -package require "elite" "1.0.0" +package require "elite" "1.0.1" -# --- Utility procedures ---------------------------------------------------- +#----- Utility procedures --------------------------------------------------- proc moan {msg} { global argv0 @@ -23,41 +23,14 @@ proc debug-array {name} { set k [array nextelement a $s] label $tl.k-$n -text $k -justify right entry $tl.v-$n -textvariable ${name}($k) -state disabled - grid configure $tl.k-$n -row $r -column 0 -sticky e - grid configure $tl.v-$n -row $r -column 1 -sticky we + grid configure $tl.k-$n -row $r -column 0 -sticky e -padx 1 -pady 1 + grid configure $tl.v-$n -row $r -column 1 -sticky we -padx 1 -pady 1 incr r incr n } array donesearch a $s } -proc write-file {name contents {trans binary}} { - if {[file exists $name]} { - if {[set rc [catch { file copy -force $name "$name.old" } err]]} { - return -code $rc $err - } - } - if {[set rc [catch { - set f [open $name w] - fconfigure $f -translation $trans - puts -nonewline $f $contents - close $f - } err]]} { - catch { close $f } - catch { file rename -force "$name.old" $name } - return -code $rc $err - } - return "" -} - -proc read-file {name {trans binary}} { - set f [open $name] - fconfigure $f -translation $trans - set c [read $f] - close $f - return $c -} - proc get-line-done {tl cmd} { if {![uplevel \#0 [concat $cmd [$tl.entry get]]]} { destroy $tl @@ -71,7 +44,7 @@ proc get-line {tl title prompt def cmd} { } toplevel $tl wm title $tl $title - label $tl.label -text "$prompt: " + label $tl.label -text "$prompt:" entry $tl.entry; $tl.entry insert 0 $def button $tl.ok -text OK -default active \ -command [list get-line-done $tl $cmd] @@ -85,16 +58,66 @@ proc entry-on-change {widget what} { bind $widget $what } +if {$tk_version >= 8.4} { + set entry_readonly readonly +} else { + set entry_readonly disabled +} + +#----- About box ------------------------------------------------------------ + +proc about-box {} { + if {[winfo exists .about]} { + # raise .about + return + } + toplevel .about + wm title .about "About elite-editor" + label .about.rocl -font {helvetica 16 bold} -justify left \ + -text "Right On Command-Line" + label .about.ee -font {helvetica 10 italic} -justify left \ + -text "elite-editor" + label .about.gpl -font {helvetica 8 normal} -justify left -text { +Copyright (c) 2003 Mark Wooding +Partly based on code by Ian Bell and Christian Pinder + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software Foundation, +Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + } + button .about.dismiss -text "Dismiss" -command { destroy .about } + pack .about.rocl -padx 4 -side top -anchor w + pack .about.ee -padx 4 -side top -anchor e + pack .about.gpl -padx 24 -side top -anchor center -expand 1 + pack .about.dismiss -side top -padx 4 -pady 4 -anchor e +} + +proc help-menu {m} { + menu $m.help + $m.help add command -label "About..." -command about-box + $m add cascade -label "Help" -menu $m.help +} + #----- Map editing machinery ------------------------------------------------ -tab col red orange yellow green blue magenta violet white +_tab col red orange yellow green blue magenta violet white set seq 0 set nwin 0 array set default {scale 15 colourby off connect 0} proc set-scale {seq sc} { - if {![regexp {^[0-9]+$} $sc]} { + if {![regexp {^\d+$} $sc]} { moan "bad scale factor `$sc'" return 1 } @@ -113,6 +136,15 @@ proc new-view {gs} { return 0 } +proc set-hyperspace-range {seq f} { + if {![regexp {^\d+(\.\d+)?$} $f]} { + moan "bad hyperspace range `$f'" + return 1 + } + map-set-fuel $seq [expr {$f * 10}] + return 0 +} + # --- Colour-coding planets --- proc colour-by {seq} { @@ -120,7 +152,7 @@ proc colour-by {seq} { set tl .map-$seq global col switch -exact -- $map(colourby) { - off { + off { foreach-world $map(galaxy) p { $tl.map itemconfigure $p(seed) -fill white -outline white } @@ -157,14 +189,15 @@ proc set-colour-by {seq} { proc show-connectivity {seq} { upvar \#0 map-$seq map - upvar \#0 adj-$map(galaxy) adj + upvar \#0 adj-$map(galaxy)-$map(fuel) adj upvar \#0 ww-$map(galaxy) ww set tl .map-$seq $tl.map delete conn if {!$map(connect)} { + show-path $seq return } - if {![info exists adj]} { adjacency $ww adj } + if {![info exists adj]} { elite-adjacency adj $ww $map(fuel) } foreach {s x y} $ww { set done($s) 1 foreach {ss xx yy} $adj($s) { @@ -176,6 +209,7 @@ proc show-connectivity {seq} { } } $tl.map lower conn sep + show-path $seq } proc set-connectivity {seq} { @@ -256,9 +290,96 @@ proc show-path {seq} { $tl.map lower path sep } +proc hide-path {seq} { + upvar \#0 map-$seq map + set tl .map-$seq + $tl.map delete path + unset map(path) + foreach i {2 3 11} { + $tl.menu.path entryconfigure $i -state disabled + } +} + +proc path-to-text {seq} { + upvar \#0 map-$seq map + set t {} + foreach n $map(path) { + append t [world-summary $n] "\n" + } + return $t +} + +proc save-path {seq} { + set file [tk_getSaveFile -initialfile "path" -title "Save path"] + if {[string equal $file ""]} { return } + if {[catch { write-file $file [path-to-text $seq] auto } err]} { + moan $err + } +} + +proc list-path {seq} { + upvar \#0 map-$seq map + set tl .map-$seq.path + if {[winfo exists $tl]} { + # raise $tl + } else { + toplevel $tl + wm title $tl "Path listing" + scrollbar $tl.hscr -orient horizontal -command [list $tl.text xview] + scrollbar $tl.vscr -orient vertical -command [list $tl.text yview] + text $tl.text -wrap none -width 80 -height 20 \ + -xscrollcommand [list $tl.hscr set] \ + -yscrollcommand [list $tl.vscr set] + grid configure $tl.text -row 0 -column 0 -sticky nsew + grid configure $tl.hscr -row 1 -column 0 -sticky ew + grid configure $tl.vscr -row 0 -column 1 -sticky ns + grid rowconfigure $tl 0 -weight 1 + grid columnconfigure $tl 0 -weight 1 + } + $tl.text configure -state normal + $tl.text delete 1.0 end + $tl.text insert end [path-to-text $seq] + $tl.text configure -state disabled +} + +proc load-path {seq} { + upvar \#0 map-$seq map + set tl .map-$seq + set file [tk_getOpenFile -title "Load path"] + if {[string equal $file ""]} { return } + if {[catch { + set f [open $file] + set path {} + while {[gets $f line] >= 0} { + if {[regexp {^\s*(\#|$)} $line]} { continue } + if {[regexp {\m[0-9a-f]{12}\M} $line p]} { + } else { + set p [parse-planet-spec $map(galaxy) [lindex $line 0]] + if {[string equal $p ""]} { + error "unrecognized path line `$line'" + } + } + lappend path $p + } + if {![in-galaxy-p $map(galaxy) $path]} { + error "not all worlds in this galaxy" + } + close $f + } err]} { + catch { close $f } + moan $err + return + } + set map(path) $path + foreach i {2 3 11} { + $tl.menu.path entryconfigure $i -state normal + } + show-path $seq +} + proc show-shortest-path {seq weight} { upvar \#0 map-$seq map - upvar \#0 adj-$map(galaxy) adj + upvar \#0 adj-$map(galaxy)-$map(fuel) adj upvar \#0 ww-$map(galaxy) ww set tl .map-$seq $tl.map delete path @@ -267,7 +388,7 @@ proc show-shortest-path {seq weight} { moan "no source or destination set" return } - if {![info exists adj]} { adjacency $ww adj } + if {![info exists adj]} { elite-adjacency adj $ww $map(fuel) } destructure {path weight} \ [shortest-path adj $map(select) $map(dest) $weight] if {![llength $path]} { @@ -275,16 +396,19 @@ proc show-shortest-path {seq weight} { return } set map(path) $path + foreach i {2 3 11} { + $tl.menu.path entryconfigure $i -state normal + } show-path $seq } # --- Planet information box --- -proc do-getinfo {tag seq x y} { - global economy government +proc show-worldinfo {tag p} { + global economy government entry_readonly upvar \#0 info-$tag info set tl .world-info-$tag - elite-worldinfo info [find-click $seq $x $y] + elite-worldinfo info $p if {[winfo exists $tl]} { # raise $tl } else { @@ -301,10 +425,10 @@ proc do-getinfo {tag seq x y} { prod-str "Productivity" radius-km "Radius" } { - label $tl.l-$item -text "$label: " -justify right - entry $tl.$item -textvariable info-${tag}($item) -state disabled - grid configure $tl.l-$item -row $r -column 0 -sticky e - grid configure $tl.$item -row $r -column 1 -columnspan 2 -sticky we + label $tl.l-$item -text "$label:" -justify right + entry $tl.$item -textvariable info-${tag}($item) -state $entry_readonly + grid configure $tl.l-$item -row $r -column 0 -sticky e -padx 1 -pady 1 + grid configure $tl.$item -row $r -column 1 -columnspan 2 -sticky we -padx 1 -pady 1 incr r } scrollbar $tl.descscr -orient vertical -command [list $tl.desc yview] @@ -331,6 +455,10 @@ proc do-getinfo {tag seq x y} { $tl.desc configure -state disabled } +proc do-getinfo {tag seq x y} { + show-worldinfo $tag [find-click $seq $x $y] +} + # --- Messing with selections --- proc to-ly {seq x} { @@ -415,17 +543,31 @@ proc select-byname {seq name seed proc} { set p [parse-planet-spec $map(galaxy) $map($name)] if {![string equal $p ""] && [in-galaxy-p $map(galaxy) $p]} { $proc $seq $p + return 1 } elseif {[info exists map($seed)]} { bell set map($name) [worldname $map($seed)] + return 0 } else { bell set map($name) "" + return 0 + } +} + +proc info-byname {seq name seed proc} { + upvar \#0 map-$seq map + if {[select-byname $seq $name $seed $proc]} { + show-worldinfo $seed $map($seed) } } proc set-selection {seq p} { upvar \#0 map-$seq map + set tl .map-$seq + if {[info exists map(cmdr)]} { + set p [cmdr-set-world $map(cmdr) $p] + } set map(select) $p elite-worldinfo pp $p select-world $seq @@ -435,10 +577,10 @@ proc set-selection {seq p} { } else { set-destination $seq $map(dest) } - if {[info exists map(cmdr)]} { - cmdr-set-world $map(cmdr) $p + foreach i {5 6 7 8 9} { + $tl.menu.path entryconfigure $i -state normal } -} +} proc do-select {seq x y} { set-selection $seq [find-click $seq $x $y] @@ -456,7 +598,7 @@ proc set-destination {seq p} { set map(dest-name) $pd(name) set map(distance) \ [format "%.1f" \ - [expr {[world-distance $ps(x) $ps(y) $pd(x) $pd(y)] / 10.0}]] + [expr {[elite-distance $ps(x) $ps(y) $pd(x) $pd(y)] / 10.0}]] } } @@ -475,7 +617,7 @@ proc map-populate {seq} { set scale $map(scale) $tl.map delete all $tl.map create line -10000 -20000 -10000 -20000 -fill black -tags sep - if {![info exists ww]} { set ww [worldinfo $map(galaxy)] } + if {![info exists ww]} { set ww [elite-galaxylist $map(galaxy)] } foreach {seed x y} $ww { elite-worldinfo p $seed set x [expr {$x * 10 / $map(scale)}] @@ -490,7 +632,6 @@ proc map-populate {seq} { colour-by $seq show-connectivity $seq - show-path $seq show-names $seq select-world $seq destination-world $seq @@ -527,6 +668,7 @@ proc map-attach-cmdr {seq cmdr} { upvar \#0 map-$seq map set map(cmdr) $cmdr map-set-title $seq + .map-$seq.menu.view entryconfigure 3 -state disabled } proc map-set-title {seq} { @@ -540,7 +682,7 @@ proc map-set-title {seq} { } proc map-set-galaxy {seq ng g} { - upvar \#0 map-$seq map + upvar \#0 map-$seq map if {[string equal $g $map(galaxy)]} { return } set map(galaxy-num) $ng map-set-title $seq @@ -553,14 +695,15 @@ proc map-set-galaxy {seq ng g} { proc map-set-fuel {seq qty} { upvar \#0 map-$seq map - set map(fuel) $qty + set map(fuel) [expr {int($qty)}] select-world $seq + show-connectivity $seq } # --- Making a new map window --- proc map-new {ng g} { - global seq nwin default + global seq nwin default entry_readonly incr seq incr nwin upvar \#0 map-$seq map @@ -581,19 +724,19 @@ proc map-new {ng g} { -yscrollcommand [list $tl.vscr set] \ -width $vwd -height $vht frame $tl.info - label $tl.info.lhome -text "Home: " + label $tl.info.lhome -text "Home:" entry $tl.info.home -textvariable map-${seq}(sel-name) - label $tl.info.ldest -text "Destination: " + label $tl.info.ldest -text " Destination:" entry $tl.info.dest -textvariable map-${seq}(dest-name) - label $tl.info.ldist -text "Distance: " + label $tl.info.ldist -text " Distance:" entry $tl.info.dist -textvariable map-${seq}(distance) \ - -state disabled -width 6 + -state $entry_readonly -width 6 pack \ $tl.info.lhome $tl.info.home \ $tl.info.ldest $tl.info.dest \ $tl.info.ldist $tl.info.dist \ - -side left - + -side left -pady 2 + scrollbar $tl.hscr -orient horizontal \ -command [list $tl.map xview] scrollbar $tl.vscr -orient vertical \ @@ -609,10 +752,14 @@ proc map-new {ng g} { $tl.menu add cascade -label "File" -menu $tl.menu.file menu $tl.menu.view $tl.menu.view add command -label "New map..." \ - -command [list get-line .new-view "New view" "Galaxy" $ng new-view] + -command [list get-line .new-view "New map" "Galaxy" $ng new-view] $tl.menu.view add command -label "Set scale..." \ -command [concat get-line .set-scale-$seq {"Set scale"} "Scale" \ \[set map-${seq}(scale)\] [list [list set-scale $seq]]] + $tl.menu.view add command -label "Set hyperspace range..." \ + -command [concat get-line .set-fuel-$seq {"Set hyperspace range"} \ + {"Hyperspace range"} \[expr \[set map-${seq}(fuel)\]/10.0\] \ + [list [list set-hyperspace-range $seq]]] $tl.menu.view add separator $tl.menu.view add radiobutton -label "Off" \ -variable map-${seq}(colourby) -value off \ @@ -635,17 +782,28 @@ proc map-new {ng g} { -command [list set-names $seq] $tl.menu add cascade -label "View" -menu $tl.menu.view menu $tl.menu.path - $tl.menu.path add command -label "Minimize hops" \ + $tl.menu.path add command -label "Load path..." \ + -command [list load-path $seq] + $tl.menu.path add command -label "Save path..." -state disabled \ + -command [list save-path $seq] + $tl.menu.path add command -label "List path..." -state disabled \ + -command [list list-path $seq] + $tl.menu.path add separator + $tl.menu.path add command -label "Minimize hops" -state disabled \ -command [list show-shortest-path $seq weight-hops] - $tl.menu.path add command -label "Minimize fuel" \ + $tl.menu.path add command -label "Minimize fuel" -state disabled \ -command [list show-shortest-path $seq weight-fuel] - $tl.menu.path add command -label "Maximize safety" \ + $tl.menu.path add command -label "Maximize safety" -state disabled \ -command [list show-shortest-path $seq weight-safety] - $tl.menu.path add command -label "Minimize safety" \ + $tl.menu.path add command -label "Minimize safety" -state disabled \ -command [list show-shortest-path $seq weight-encounters] - $tl.menu.path add command -label "Maximize trading" \ + $tl.menu.path add command -label "Maximize trading" -state disabled \ -command [list show-shortest-path $seq weight-trading] - $tl.menu add cascade -label "Compute path" -menu $tl.menu.path + $tl.menu.path add separator + $tl.menu.path add command -label "Hide path" -state disabled \ + -command [list hide-path $seq] + $tl.menu add cascade -label "Path" -menu $tl.menu.path + help-menu $tl.menu $tl configure -menu $tl.menu wm protocol $tl WM_DELETE_WINDOW [list map-destroy $seq] @@ -660,13 +818,17 @@ proc map-new {ng g} { bind $tl.map <3> [list do-select $seq %x %y] bind $tl.map <1> [list do-destination $seq %x %y] bind $tl.map [list do-getinfo dest $seq %x %y] - bind $tl.map [list do-getinfo home $seq %x %y] + bind $tl.map [list do-getinfo select $seq %x %y] map-set-title $seq entry-on-change $tl.info.home \ [list select-byname $seq sel-name select set-selection] entry-on-change $tl.info.dest \ [list select-byname $seq dest-name dest set-destination] + bind $tl.info.home \ + [list info-byname $seq sel-name select set-selection] + bind $tl.info.dest \ + [list info-byname $seq dest-name dest set-destination] map-setscale $seq $sc return $seq } @@ -695,7 +857,7 @@ proc integerp {min max n} { proc galaxyp {s} { if {![regexp {^[0-9a-fA-F]{12}$} $s]} { return 0 } return 1 -} +} proc cmdr-do-validate {seq widget check value} { upvar \#0 cmdr-$seq cmdr @@ -732,6 +894,7 @@ proc cmdr-set-fluc {seq} { } proc cmdr-cargo {seq} { + global entry_readonly upvar \#0 cmdr-$seq cmdr set tl .cmdr-$seq.cargo-qty if {[winfo exists $tl]} { @@ -742,34 +905,34 @@ proc cmdr-cargo {seq} { wm title $tl "Cargo for commander $cmdr(name)" global products set r 0 - label $tl.l-fluc -text "Fluctuation: " -justify right + label $tl.l-fluc -text "Fluctuation:" -justify right entry $tl.fluc -textvariable cmdr-${seq}(market-fluc) -justify right cmdr-validate-widget $seq $tl.fluc [list integerp 0 255] entry-on-change $tl.fluc [list cmdr-set-fluc $seq] - grid configure $tl.l-fluc -row $r -column 0 -sticky e - grid configure $tl.fluc -row $r -column 1 -columnspan 3 -sticky we + grid configure $tl.l-fluc -row $r -column 0 -sticky e -padx 1 -pady 1 + grid configure $tl.fluc -row $r -column 1 -columnspan 3 -sticky we -padx 1 -pady 1 incr r label $tl.l-item -text "Item" -justify center label $tl.l-price -text "Price" -justify center label $tl.l-station -text "Station" -justify center label $tl.l-hold -text "Hold" -justify center - grid configure $tl.l-item -row $r -column 0 -sticky e - grid configure $tl.l-price -row $r -column 1 -sticky we - grid configure $tl.l-station -row $r -column 2 -sticky we - grid configure $tl.l-hold -row $r -column 3 -sticky we + grid configure $tl.l-item -row $r -column 0 -sticky e -padx 1 -pady 1 + grid configure $tl.l-price -row $r -column 1 -sticky we -padx 1 -pady 1 + grid configure $tl.l-station -row $r -column 2 -sticky we -padx 1 -pady 1 + grid configure $tl.l-hold -row $r -column 3 -sticky we -padx 1 -pady 1 incr r foreach {tag label} $products { - label $tl.l-$tag -text "$label: " -justify right + label $tl.l-$tag -text "$label:" -justify right entry $tl.price-$tag -textvariable cmdr-${seq}(price-${tag}) \ - -justify right -state disabled -width 4 + -justify right -state $entry_readonly -width 4 foreach {pre col} {station 2 hold 3} { entry $tl.${pre}-${tag} -textvariable cmdr-${seq}(${pre}-${tag}) \ -justify right -width 4 cmdr-validate-widget $seq $tl.${pre}-${tag} [list integerp 0 255] grid configure $tl.${pre}-${tag} -row $r -column $col -stick we } - grid configure $tl.l-$tag -row $r -column 0 -sticky e - grid configure $tl.price-$tag -row $r -column 1 -sticky we + grid configure $tl.l-$tag -row $r -column 0 -sticky e -padx 1 -pady 1 + grid configure $tl.price-$tag -row $r -column 1 -sticky we -padx 1 -pady 1 incr r } grid columnconfigure $tl 1 -weight 1 @@ -790,6 +953,17 @@ proc cmdr-destroy {seq} { if {!$nwin} { exit } } +proc cmdr-new-map {seq} { + upvar \#0 cmdr-$seq cmdr + set tl .cmdr-$seq + if {$cmdr(std-gal)} { + set g $cmdr(gal-number) + } else { + set g $cmdr(gal-seed) + } + get-line .new-view "New map..." "Galaxy" $g new-view +} + proc cmdrdb-set {seq tag value} { upvar \#0 cmdr-$seq cmdr set tl .cmdr-$seq @@ -804,18 +978,26 @@ proc cmdrdb-custom {seq tag} { proc cmdr-set-world {seq p} { upvar \#0 cmdr-$seq cmdr + upvar \#0 ww-$cmdr(gal-seed) ww elite-worldinfo i $p - set cmdr(world-seed) $p + set pp [nearest-planet $ww $i(x) $i(y)] + if {![string equal $p $pp]} { + set n $i(name) + elite-worldinfo i $pp + moan "world $n is coincident with $i(name); substituting" + } + set cmdr(world-seed) $i(seed) set cmdr(world-name) $i(name) set cmdr(world-x) [expr {$i(x)/4}] set cmdr(world-y) [expr {$i(y)/2}] cmdr-set-fluc $seq + return $i(seed) } proc cmdr-update-world {seq} { upvar \#0 cmdr-$seq cmdr upvar \#0 ww-$cmdr(gal-seed) ww - if {![info exists ww]} { set ww [worldinfo $cmdr(gal-seed)] } + if {![info exists ww]} { set ww [elite-galaxylist $cmdr(gal-seed)] } set tl .cmdr-$seq set w [nearest-planet $ww \ [expr {$cmdr(world-x) * 4}] [expr {$cmdr(world-y) * 2}]] @@ -910,7 +1092,7 @@ proc cmdr-check {seq} { proc cmdr-open {seq} { upvar \#0 cmdr-$seq cmdr - global cmdr-$seq + global cmdr-$seq entry_readonly set tl .cmdr-$seq global nwin toplevel $tl @@ -926,16 +1108,16 @@ proc cmdr-open {seq} { set cmdr(bogus) 0 foreach {tag label kind} [list \ mission "Mission" { entry 2 255 } \ - score "Rating" { dropbox 65535\ - "Harmless" 0 \ - "Mostly harmless" 8 \ - "Poor" 6 \ - "Average" 32 \ + score "Rating" { dropbox 65535 \ + "Harmless" 0 \ + "Mostly harmless" 8 \ + "Poor" 16 \ + "Average" 32 \ "Above average" 64 \ - "Competent" 128 \ - "Dangerous" 512 \ - "Deadly" 2560 \ - "Elite" 6400 } \ + "Competent" 128 \ + "Dangerous" 512 \ + "Deadly" 2560 \ + "Elite" 6400 } \ legal-status "Legal status" { dropbox 255 \ "Clean" 0 \ "Offender" 1 \ @@ -945,11 +1127,11 @@ proc cmdr-open {seq} { fuel "Fuel" { tenth 4 25.5 } \ missiles "Missiles" { entry 4 255 } \ energy-unit "Energy unit" { dropbox 255 \ - "None" 0 \ + "None" 0 \ "Standard" 1 \ "Naval" 2 } \ front-laser "Front laser" $laser \ - rear-laser "Front laser" $laser \ + rear-laser "Rear laser" $laser \ left-laser "Left laser" $laser \ right-laser "Right laser" $laser \ ecm "ECM" toggle \ @@ -964,30 +1146,30 @@ proc cmdr-open {seq} { switch -exact -- [lindex $kind 0] { entry { destructure {. wd max} $kind - label $tl.l-$tag -text "$label: " -justify right + label $tl.l-$tag -text "$label:" -justify right entry $tl.$tag -textvariable cmdr-${seq}($tag) \ -width $wd -justify right cmdr-validate-widget $seq $tl.$tag [list integerp 0 $max] - grid configure $tl.l-$tag -row $r -column 0 -sticky e - grid configure $tl.$tag -row $r -column 1 -columnspan 2 -sticky we + grid configure $tl.l-$tag -row $r -column 0 -sticky e -padx 1 -pady 1 + grid configure $tl.$tag -row $r -column 1 -columnspan 2 -sticky we -padx 1 -pady 1 } tenth { destructure {. wd max} $kind - label $tl.l-$tag -text "$label: " -justify right + label $tl.l-$tag -text "$label:" -justify right entry $tl.$tag -textvariable cmdr-${seq}(div-$tag) \ -width $wd -justify right set cmdr(div-$tag) [format "%.1f" [expr {$cmdr($tag) / 10.0}]] trace variable cmdr-${seq}(div-$tag) w [list fix-tenth $tag] cmdr-validate-widget $seq $tl.$tag [list numericp 0 $max] - grid configure $tl.l-$tag -row $r -column 0 -sticky e - grid configure $tl.$tag -row $r -column 1 -columnspan 2 -sticky we + grid configure $tl.l-$tag -row $r -column 0 -sticky e -padx 1 -pady 1 + grid configure $tl.$tag -row $r -column 1 -columnspan 2 -sticky we -padx 1 -pady 1 } toggle { checkbutton $tl.$tag -text $label -variable cmdr-${seq}($tag) - grid configure $tl.$tag -row $r -column 0 -columnspan 3 -sticky w + grid configure $tl.$tag -row $r -column 0 -columnspan 3 -sticky w -padx 1 -pady 1 } dropbox { - label $tl.l-$tag -text "$label: " -justify right + label $tl.l-$tag -text "$label:" -justify right set menu $tl.m-$tag.menu menubutton $tl.m-$tag -textvariable cmdr-${seq}(r-${tag}) \ -indicatoron 1 -relief raised -menu $menu -width 8 \ @@ -1010,34 +1192,34 @@ proc cmdr-open {seq} { $menu add radiobutton -label "Custom" \ -value "Custom" -variable cmdr-${seq}(r-$tag) \ -command [list cmdrdb-custom $seq $tag] - grid configure $tl.l-$tag -row $r -column 0 -sticky e - grid configure $tl.m-$tag -row $r -column 1 -sticky we - grid configure $tl.$tag -row $r -column 2 -sticky we + grid configure $tl.l-$tag -row $r -column 0 -sticky e -padx 1 -pady 1 + grid configure $tl.m-$tag -row $r -column 1 -sticky we -padx 1 -pady 1 + grid configure $tl.$tag -row $r -column 2 -sticky we -padx 1 -pady 1 } cargo { button $tl.$tag -text $label -command [list cmdr-cargo $seq] - grid configure $tl.$tag -row $r -column 0 -columnspan 3 -sticky we + grid configure $tl.$tag -row $r -column 0 -columnspan 3 -sticky we -padx 1 -pady 1 } where { - label $tl.l-gal-number -text "Galaxy number: " -justify right + label $tl.l-gal-number -text "Galaxy number:" -justify right entry $tl.gal-number -textvariable cmdr-${seq}(gal-number) \ -justify right -width 2 cmdr-validate-widget $seq $tl.gal-number [list integerp 1 8] checkbutton $tl.std-gal -text "Standard galaxy" \ -variable cmdr-${seq}(std-gal) -justify left \ - -command [list cmdr-std-gal $seq] + -command [list cmdr-std-gal $seq] entry-on-change $tl.gal-number [list cmdr-set-gal-num $seq] - grid configure $tl.l-gal-number -row $r -column 0 -sticky e - grid configure $tl.std-gal -row $r -column 1 -sticky w - grid configure $tl.gal-number -row $r -column 2 -sticky we + grid configure $tl.l-gal-number -row $r -column 0 -sticky e -padx 1 -pady 1 + grid configure $tl.std-gal -row $r -column 1 -sticky w -padx 1 -pady 1 + grid configure $tl.gal-number -row $r -column 2 -sticky we -padx 1 -pady 1 incr r - label $tl.l-gal-seed -text "Galaxy seed: " -justify right + label $tl.l-gal-seed -text "Galaxy seed:" -justify right entry $tl.gal-seed -textvariable cmdr-${seq}(gal-seed) -width 12 cmdr-validate-widget $seq $tl.gal-seed galaxyp entry-on-change $tl.gal-seed [list cmdr-update-world $seq] - grid configure $tl.l-gal-seed -row $r -column 0 -sticky e + grid configure $tl.l-gal-seed -row $r -column 0 -sticky e -padx 1 -pady 1 grid configure $tl.gal-seed -row $r \ - -column 1 -columnspan 2 -sticky we + -column 1 -columnspan 2 -sticky we -padx 1 -pady 1 incr r if {[string equal $cmdr(gal-seed) [galaxy $cmdr(gal-number)]]} { set cmdr(std-gal) 1 @@ -1045,20 +1227,20 @@ proc cmdr-open {seq} { } else { set cmdr(std-gal) 0 } - label $tl.l-world-name -text "Planet: " -justify right + label $tl.l-world-name -text "Planet:" -justify right entry $tl.world-name -textvariable cmdr-${seq}(world-name) \ - -state disabled -width 10 -justify left - grid configure $tl.l-world-name -row $r -column 0 -sticky e + -state $entry_readonly -width 10 -justify left + grid configure $tl.l-world-name -row $r -column 0 -sticky e -padx 1 -pady 1 grid configure $tl.world-name -row $r \ - -column 1 -columnspan 2 -sticky we + -column 1 -columnspan 2 -sticky we -padx 1 -pady 1 incr r button $tl.$tag -text "Show galaxy map" \ -command [list cmdr-show-map $seq] - grid configure $tl.$tag -row $r -column 0 -columnspan 3 -sticky we + grid configure $tl.$tag -row $r -column 0 -columnspan 3 -sticky we -padx 1 -pady 1 } default { label $tl.l-$tag -text "($label)" -justify left - grid configure $tl.l-$tag -row $r -column 0 -sticky w + grid configure $tl.l-$tag -row $r -column 0 -sticky w -padx 1 -pady 1 } } incr r @@ -1074,9 +1256,13 @@ proc cmdr-open {seq} { $tl.menu.file add command -label "Save as..." \ -command [list cmdr-saveas $seq] $tl.menu.file add separator + $tl.menu.file add command -label "New map..." \ + -command [list cmdr-new-map $seq] + $tl.menu.file add separator $tl.menu.file add command -label "Close" -command [list cmdr-destroy $seq] $tl.menu.file add command -label "Quit" -command { exit } $tl.menu add cascade -label "File" -menu $tl.menu.file + help-menu $tl.menu $tl configure -menu $tl.menu grid columnconfigure $tl 2 -weight 1 wm protocol $tl WM_DELETE_WINDOW [list cmdr-destroy $seq] @@ -1153,38 +1339,10 @@ proc cmdr-save {seq} { } proc cmdr-new {} { - global seq galaxy1 products + global seq incr seq upvar \#0 cmdr-$seq cmdr - array set cmdr { - mission 0 - credits 1000 - fuel 70 - gal-number 1 - front-laser 0x0f - rear-laser 0 - left-laser 0 - right-laser 0 - cargo 20 - missiles 3 - legal-status 0 - score 0 - market-fluc 0 - } - set cmdr(gal-seed) $galaxy1 - foreach i { - ecm fuel-scoop energy-bomb energy-unit docking-computer - gal-hyperdrive escape-pod - } { set cmdr($i) 0 } - elite-worldinfo lave [find-world $galaxy1 "Lave"] - set cmdr(world-x) [expr {$lave(x)/4}] - set cmdr(world-y) [expr {$lave(y)/2}] - elite-market mkt $lave(seed) 0 - foreach {t n} $products { - destructure [list . cmdr(station-$t)] $mkt($t) - set cmdr(hold-$t) 0 - } - set cmdr(station-alien-items) 0 + jameson cmdr cmdr-open $seq } @@ -1192,14 +1350,27 @@ proc cmdr-new {} { wm withdraw . +bind Entry { %W delete 0 end } + if {[llength $argv]} { foreach a $argv { - set g [parse-galaxy-spec $a] - if {[llength $g]} { - destructure {ng g} $g - map-new $ng $g - } else { - cmdr-load $a + switch -glob -- $a { + "-jameson" { + cmdr-new + } + "-*" { + puts stderr "$argv0: unknown option: $a" + exit 1 + } + default { + set g [parse-galaxy-spec $a] + if {[llength $g]} { + destructure {ng g} $g + map-new $ng $g + } else { + cmdr-load $a + } + } } } } else {