#! /usr/bin/tclsh
#
-# $Id: elite.tcl,v 1.5 2003/03/04 10:26:47 mdw Exp $
+# $Id: elite.tcl,v 1.6 2003/03/07 00:44:57 mdw Exp $
-package require "elite-bits" "1.0.0"
+package require "elite-bits" "1.0.1"
set galaxy1 "4a5a480253b7" ;# Seed for standard galaxy 1
return $c
}
-# --- worldinfo GAL ---
-#
-# Return a list describing the worlds in galaxy GAL (a seed). The list
-# contains a group of three elements for each world: the seed, x and y
-# coordinates (in decilightyears).
-
-proc worldinfo {g} {
- foreach-world $g p {
- lappend i $p(seed) $p(x) $p(y)
- }
- return $i
-}
-
-# --- world-distance X Y XX YY ---
-#
-# Computes the correct game distance in decilightyears between two worlds,
-# one at X, Y and the other at XX, YY.
-
-proc world-distance {x y xx yy} {
- set dx [expr {abs($x - $xx)/4}]
- set dy [expr {abs($y - $yy)/4}]
- return [expr {4 * floor(sqrt($dx * $dx + $dy * $dy))}]
-}
-
# --- nearest-planet WW X Y ---
#
# Returns the seed of the `nearest' planet given in the worldinfo list WW to
return $p
}
-# --- adjacency WW ADJ [D] ---
-#
-# Fill in the array ADJ with the adjacency table for the worlds listed in the
-# worldinfo list WW. That is, for each world seed S, ADJ(S) is set to a
-# worldinfo list containing the worlds within D (default 70) decilightyears
-# of S.
-
-proc adjacency {p adj {d 70}} {
- upvar 1 $adj a
- array set a {}
- foreach {s x y} $p {
- set done($s) 1
- lappend a($s)
- foreach {ss xx yy} $p {
- if {[info exists done($ss)]} { continue }
- if {abs($x - $xx) > $d + 10 || abs($y - $yy) > $d + 10 ||
- [world-distance $x $y $xx $yy] > $d} { continue }
- lappend a($s) $ss $xx $yy
- lappend a($ss) $s $x $y
- }
- }
-}
-
# --- worldname W ---
#
# Returns the name of the world with seed W.
proc weight-fuel {from to} {
elite-worldinfo f $from
elite-worldinfo t $to
- return [expr {[world-distance $f(x) $f(y) $t(x) $t(y)]/10.0}]
+ return [elite-distance $f(x) $f(y) $t(x) $t(y)]
}
# --- weight-safety A B ---
}
if {[regexp {^(0x[0-9a-fA-F]+|[0-9]+),\s*(0x[0-9a-fA-F]+|[0-9]+)$} \
$p . x y]} {
- return [nearest-planet [worldinfo $g] $x $y]
+ return [nearest-planet [elite-galaxylist $g] $x $y]
+ }
+ if {[regexp {^([^/]*)(?:/([1-9]\d*))?$} $p . p i]} {
+ if {[string equal $i ""]} { set i 1 }
+ set l [find-world $g $p]
+ if {$i <= [llength $l]} { return [lindex $l [expr {$i - 1}]] }
}
- set l [find-world $g $p]
- if {[llength $l]} { return [lindex $l 0] }
return {}
}
#
# Return a one-line summary string for PLANET.
-proc world-summary {s} {
+proc world-summary {s {ind 0} {spc 0}} {
global eco gov
elite-worldinfo p $s
- return [format "%-8s %4d %4d %-11s %-10s %2d %s" \
- $p(name) $p(x) $p(y) \
+ set is [string repeat " " $ind]
+ set ss [string repeat " " $spc]
+ return [format "%s%-8s%s %4d %4d %-11s %-10s %2d %s" \
+ $is $p(name) $ss $p(x) $p(y) \
$eco($p(economy)) $gov($p(government)) $p(techlevel) $p(seed)]
}
#----- That's all, folks ----------------------------------------------------
-package provide "elite" "1.0.0"
+package provide "elite" "1.0.1"