#! /usr/bin/wish
#
-# $Id: elite-editor,v 1.4 2003/02/26 00:02:15 mdw Exp $
+# $Id: elite-editor,v 1.7 2003/03/03 10:38:08 mdw Exp $
package require "elite" "1.0.0"
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
# --- Planet information box ---
-proc do-getinfo {tag seq x y} {
+proc show-worldinfo {tag p} {
global economy government
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 {
$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} {
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
+ if {[info exists map(cmdr)]} {
+ set p [cmdr-set-world $map(cmdr) $p]
+ }
set map(select) $p
elite-worldinfo pp $p
select-world $seq
} else {
set-destination $seq $map(dest)
}
- if {[info exists map(cmdr)]} {
- cmdr-set-world $map(cmdr) $p
- }
}
proc do-select {seq x y} {
bind $tl.map <3> [list do-select $seq %x %y]
bind $tl.map <1> [list do-destination $seq %x %y]
bind $tl.map <Double-1> [list do-getinfo dest $seq %x %y]
- bind $tl.map <Double-3> [list do-getinfo home $seq %x %y]
+ bind $tl.map <Double-3> [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 <Control-Return> \
+ [list info-byname $seq sel-name select set-selection]
+ bind $tl.info.dest <Control-Return> \
+ [list info-byname $seq dest-name dest set-destination]
map-setscale $seq $sc
return $seq
}
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} {
score "Rating" { dropbox 65535\
"Harmless" 0 \
"Mostly harmless" 8 \
- "Poor" 6 \
+ "Poor" 16 \
"Average" 32 \
"Above average" 64 \
"Competent" 128 \
}
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
}
wm withdraw .
+bind Entry <Control-u> { %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 {