#! /usr/bin/tclsh
#
-# $Id: elite.tcl,v 1.3 2003/02/26 01:13:22 mdw Exp $
+# $Id: elite.tcl,v 1.4 2003/03/01 17:47:07 mdw Exp $
package require "elite-bits" "1.0.0"
}
}
+# --- write-file NAME CONTENTS [TRANS] ---
+#
+# Write file NAME, storing CONTENTS translated according to TRANS (default
+# `binary'. The write is safe against errors -- we don't destroy the old
+# data until the file is written.
+
+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 ""
+}
+
+# --- read-file NAME [TRANS] ---
+#
+# Read the contents of the file NAME, translating it according to TRANS
+# (default `binary').
+
+proc read-file {name {trans binary}} {
+ set f [open $name]
+ fconfigure $f -translation $trans
+ set c [read $f]
+ close $f
+ return $c
+}
+
# --- worldinfo GAL ---
#
# Return a list describing the worlds in galaxy GAL (a seed). The list
$eco($p(economy)) $gov($p(government)) $p(techlevel) $p(seed)]
}
+# --- jameson ARR ---
+#
+# Fill ARR with the information about commander JAMESON.
+
+proc jameson {arr} {
+ global galaxy1 products
+ upvar 1 $arr 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
+}
+
#----- That's all, folks ----------------------------------------------------
package provide "elite" "1.0.0"