| 1 | #! /usr/bin/tclsh |
| 2 | ### |
| 3 | ### Describe a particular world |
| 4 | ### |
| 5 | ### (c) 2003 Mark Wooding |
| 6 | ### |
| 7 | |
| 8 | ###----- Licensing notice --------------------------------------------------- |
| 9 | ### |
| 10 | ### This program is free software; you can redistribute it and/or modify |
| 11 | ### it under the terms of the GNU General Public License as published by |
| 12 | ### the Free Software Foundation; either version 2 of the License, or |
| 13 | ### (at your option) any later version. |
| 14 | ### |
| 15 | ### This program is distributed in the hope that it will be useful, |
| 16 | ### but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | ### GNU General Public License for more details. |
| 19 | ### |
| 20 | ### You should have received a copy of the GNU General Public License |
| 21 | ### along with this program; if not, write to the Free Software Foundation, |
| 22 | ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 | |
| 24 | package require "elite" "1.0.1" |
| 25 | |
| 26 | ###-------------------------------------------------------------------------- |
| 27 | ### Support functions. |
| 28 | |
| 29 | proc describe n { |
| 30 | ## Describe the world with seed N. |
| 31 | |
| 32 | global economy government |
| 33 | |
| 34 | ## Fetch the necessary information. |
| 35 | elite-worldinfo p $n |
| 36 | |
| 37 | ## Format most of the data. |
| 38 | puts "Name: $p(name)" |
| 39 | puts "Seed: $p(seed)" |
| 40 | puts "Position: $p(x), $p(y) LY" |
| 41 | puts "Economy: $economy($p(economy))" |
| 42 | puts "Government: $government($p(government))" |
| 43 | puts "Tech. level: $p(techlevel)" |
| 44 | puts [format "Population: %s billion (%s)" \ |
| 45 | [expr {$p(population)/10.0}] $p(inhabitants)] |
| 46 | puts "Gross productivity: $p(productivity) M Cr" |
| 47 | puts "Radius: $p(radius) km" |
| 48 | |
| 49 | ## Format the world description, word-wrapping as necessary. |
| 50 | puts "" |
| 51 | set ll {} |
| 52 | set l 0 |
| 53 | foreach w $p(description) { |
| 54 | incr l |
| 55 | incr l [string length $w] |
| 56 | if {$l > 72} { puts $ll; set ll {}; set l 0 } |
| 57 | lappend ll $w |
| 58 | } |
| 59 | puts $ll |
| 60 | } |
| 61 | |
| 62 | ###-------------------------------------------------------------------------- |
| 63 | ### Main program. |
| 64 | |
| 65 | ## Parse the command line and describe the planets indicated. |
| 66 | if {[llength $argv] < 1} { |
| 67 | puts stderr "usage: $argv0 \[-g GALAXY\] PLANET ..." |
| 68 | exit 1 |
| 69 | } |
| 70 | set g $galaxy1 |
| 71 | for {set i 0} {$i < [llength $argv]} {incr i} { |
| 72 | set a [lindex $argv $i] |
| 73 | switch -- $a { |
| 74 | "-g" { |
| 75 | incr i |
| 76 | set a [lindex $argv $i] |
| 77 | set g [parse-galaxy-spec $a] |
| 78 | if {[string equal $g ""]} { |
| 79 | puts stderr "$argv0: bad galaxy string `$a'" |
| 80 | exit 1 |
| 81 | } |
| 82 | destructure {. g} $g |
| 83 | } |
| 84 | default { |
| 85 | set n [parse-planet-spec $g $a] |
| 86 | if {[string equal $n ""]} { |
| 87 | puts stderr "$argv0: unknown planet `$a'" |
| 88 | continue |
| 89 | } |
| 90 | describe $n |
| 91 | puts "" |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | ###----- That's all, folks -------------------------------------------------- |