home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume17 / gbp / part15 < prev    next >
Encoding:
Internet Message Format  |  1993-03-20  |  54.5 KB

  1. Path: uunet!news.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v17i027:  gbp - Galactic Bloodshed+, an empire-like war game, Part15/21
  5. Message-ID: <4555@master.CNA.TEK.COM>
  6. Date: 12 Feb 93 17:32:25 GMT
  7. Sender: news@master.CNA.TEK.COM
  8. Lines: 1703
  9. Approved: billr@saab.CNA.TEK.COM
  10. Xref: uunet comp.sources.games:1706
  11.  
  12. Submitted-by: deragon@harpo.cs.nyu.edu (Seeker)
  13. Posting-number: Volume 17, Issue 27
  14. Archive-name: gbp/Part15
  15. Supersedes: gb3: Volume 10, Issue 1-14
  16. Environment: sockets, curses
  17.  
  18.  
  19.  
  20. #! /bin/sh
  21. # This is a shell archive.  Remove anything before this line, then unpack
  22. # it by saving it into a file and typing "sh file".  To overwrite existing
  23. # files, type "sh file -c".  You can also feed this as standard input via
  24. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  25. # will see the following message at the end:
  26. #        "End of archive 15 (of 21)."
  27. # Contents:  user/Makefile.SH user/build.c1 user/scrap.c
  28. #   utils/makestar.c utils/makeuniv.c
  29. # Wrapped by billr@saab on Fri Feb 12 09:14:28 1993
  30. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  31. if test -f 'user/Makefile.SH' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'user/Makefile.SH'\"
  33. else
  34. echo shar: Extracting \"'user/Makefile.SH'\" \(10992 characters\)
  35. sed "s/^X//" >'user/Makefile.SH' <<'END_OF_FILE'
  36. Xcase $CONFIG in
  37. X'')
  38. X    if test ! -f config.sh; then
  39. X    ln ../config.sh . || \
  40. X    ln ../../config.sh . || \
  41. X    ln ../../../config.sh . || \
  42. X    (echo "Can't find config.sh."; exit 1)
  43. X    fi
  44. X    . ./config.sh
  45. X    ;;
  46. Xesac
  47. Xcase "$0" in
  48. X*/*) cd `expr X$0 : 'X\(.*\)/'` ;;
  49. Xesac
  50. X
  51. Xecho "Extracting user/Makefile (with variable substitutions)"
  52. Xcat >Makefile <<!GROK!THIS!
  53. X#
  54. X#  user level Makefile for the GB+ program
  55. X#  This makefile will make the commands library routines
  56. X#
  57. X# Bug reports, patches, comments, suggestions should be sent to:
  58. X#
  59. X#    John Deragon deragon@jethro.cs.nyu.edu
  60. X#
  61. X# Revision 1.1  93/01/28 jpd
  62. X# 
  63. X#
  64. X# Variables
  65. X#    Variables established by Configure
  66. XCC        =    $cc
  67. XCCFLAGS        =    $ccflags $xencf
  68. XCHGRP        =    $chgrp
  69. XCHMOD        =    $chmod
  70. XCP        =    $cp
  71. XDEST        =    $bin
  72. XECHO        =    $echo
  73. XLFLAGS        =    $ldflags 
  74. XLIB        =    $lib
  75. XLIB2        =     $libs
  76. XLIBS        =    $termlib 
  77. XLINT        =    $lint
  78. XMV        =    $mv
  79. XOPTIMIZE    =    $optimize
  80. XRM        =     $rm -f
  81. XAR        =     $ar
  82. XRANLIB  =   $ranlib
  83. XTOUCH        =    $touch
  84. XPORT        =   $port
  85. XHOST        =   $host
  86. X
  87. X!GROK!THIS!
  88. X
  89. Xcat >>Makefile <<'!NO!SUBS!'
  90. X
  91. X#    Variables you may want to manually edit
  92. X#        If you want debug logging then you'll
  93. X#        want to uncomment the following.
  94. X#DEBUG        =    -DDEBUG
  95. X
  96. X#        If you're on an ACSnet system (Australia) then
  97. X#        you'll want to uncomment the following.
  98. X# DACSNET    =    -DACSNET
  99. X
  100. X#    Other general variables
  101. XBIN        =    ../bin
  102. XCFLAGS        =    $(CCFLAGS) $(OPTIMIZE) -I$(INCLDIR) $(DEBUG) $(DACSNET) 
  103. XINCLDIR        =    ../hdrs
  104. XLINTFLAGS    =    -I$(INCLDIR)
  105. XSHELL        =    /bin/sh
  106. XARFLAGS     =   cq
  107. XLIBTARGET   =   libuser.a
  108. X
  109. X#     Lists
  110. XUSER_SRC        =    analysis.c \
  111. X                    autoreport.c \
  112. X                    autoshoot.c \
  113. X                    build.c \
  114. X                    capital.c \
  115. X                    capture.c \
  116. X                    cs.c \
  117. X                    declare.c \
  118. X                    dissolve.c \
  119. X                    dock.c \
  120. X                    enslave.c \
  121. X                    examine.c \
  122. X                    explore.c \
  123. X                    fire.c \
  124. X                    fuel.c \
  125. X                    guardian.c \
  126. X                    land.c \
  127. X                    launch.c \
  128. X                    load.c \
  129. X                    map.c \
  130. X                    mobiliz.c \
  131. X                    move.c \
  132. X                    name.c \
  133. X                    orbit.c \
  134. X                    order.c \
  135. X                    power.c \
  136. X                    prof.c \
  137. X                    relation.c \
  138. X                    rst.c \
  139. X                    scrap.c \
  140. X                    shootblast.c \
  141. X                    survey.c \
  142. X                    tech.c \
  143. X                    tele.c \
  144. X                    togg.c \
  145. X                    toxi.c \
  146. X                    vict.c  \
  147. X                    sche.c \
  148. X                    help.c \
  149. X                    chan.c \
  150. X                    zoom.c
  151. X
  152. XUSER_OBJ        =    analysis.o \
  153. X                    autoreport.o \
  154. X                    autoshoot.o \
  155. X                    build.o \
  156. X                    capital.o \
  157. X                    capture.o \
  158. X                    cs.o \
  159. X                    declare.o \
  160. X                    dissolve.o \
  161. X                    dock.o \
  162. X                    enslave.o \
  163. X                    examine.o \
  164. X                    explore.o \
  165. X                    fire.o \
  166. X                    fuel.o \
  167. X                    guardian.o \
  168. X                    land.o \
  169. X                    launch.o \
  170. X                    load.o \
  171. X                    map.o \
  172. X                    mobiliz.o \
  173. X                    move.o \
  174. X                    name.o \
  175. X                    orbit.o \
  176. X                    order.o \
  177. X                    power.o \
  178. X                    prof.o \
  179. X                    relation.o \
  180. X                    rst.o \
  181. X                    scrap.o \
  182. X                    shootblast.o \
  183. X                    survey.o \
  184. X                    tech.o \
  185. X                    tele.o \
  186. X                    togg.o \
  187. X                    toxi.o \
  188. X                    vict.o  \
  189. X                    sche.o \
  190. X                    help.o \
  191. X                    chan.o \
  192. X                    zoom.o
  193. X
  194. X
  195. X# Standard targets
  196. Xall:        libuser.a
  197. X
  198. X#    Dependencies and rules for compiling C programs
  199. Xlibuser.a:    $& $(USER_OBJ)
  200. X        $(AR) $(ARFLAGS) $(LIBTARGET) $(USER_OBJ)
  201. X        $(RANLIB) $(LIBTARGET)
  202. X
  203. Xobjects:    $& $(USER_OBJ)
  204. X
  205. Xclean:    
  206. X        $(RM) $(USER_OBJ)
  207. X# DO NOT DELETE THIS LINE -- make depend depends on it.
  208. Xanalysis.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  209. Xanalysis.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  210. Xanalysis.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h
  211. Xanalysis.o: ../hdrs/proto.h
  212. Xautoreport.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  213. Xautoreport.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/proto.h
  214. Xautoreport.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h
  215. Xautoshoot.o: ../hdrs/vars.h ../hdrs/files.h ../hdrs/tweakables.h
  216. Xautoshoot.o: ../hdrs/config.h ../hdrs/ships.h
  217. Xautoshoot.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/doturn.h
  218. Xautoshoot.o: ../hdrs/buffers.h ../hdrs/proto.h
  219. Xbuild.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  220. Xbuild.o: ../hdrs/tweakables.h ../hdrs/config.h 
  221. Xbuild.o: ../hdrs/ships.h ../hdrs/races.h ../hdrs/shipdata.h
  222. Xbuild.o: ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  223. Xcapital.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  224. Xcapital.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  225. Xcapital.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  226. Xcapture.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  227. Xcapture.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  228. Xcapture.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  229. Xchan.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  230. Xchan.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/races.h
  231. Xchan.o: ../hdrs/buffers.h ../hdrs/power.h ../hdrs/proto.h
  232. Xcs.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  233. Xcs.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  234. Xcs.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  235. Xdeclare.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  236. Xdeclare.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  237. Xdeclare.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  238. Xdissolve.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  239. Xdissolve.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  240. Xdissolve.o: ../hdrs/races.h ../hdrs/doturn.h ../hdrs/power.h
  241. Xdissolve.o: ../hdrs/buffers.h ../hdrs/proto.h
  242. Xdock.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  243. Xdock.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  244. Xdock.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  245. Xenslave.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  246. Xenslave.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  247. Xenslave.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  248. Xexamine.o: ../hdrs/GB_copyright.h ../hdrs/vars.h
  249. Xexamine.o: ../hdrs/files.h ../hdrs/tweakables.h ../hdrs/config.h
  250. Xexamine.o: ../hdrs/ships.h ../hdrs/races.h
  251. Xexamine.o: ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  252. Xexplore.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  253. Xexplore.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  254. Xexplore.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  255. Xfire.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  256. Xfire.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  257. Xfire.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h
  258. Xfuel.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  259. Xfuel.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  260. Xfuel.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/proto.h
  261. Xhelp.o: ../hdrs/vars.h ../hdrs/files.h
  262. Xhelp.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/buffers.h
  263. Xland.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  264. Xland.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  265. Xland.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  266. Xlaunch.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  267. Xlaunch.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  268. Xlaunch.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  269. Xload.o: ../hdrs/GB_copyright.h ../hdrs/vars.h
  270. Xload.o: ../hdrs/files.h ../hdrs/tweakables.h ../hdrs/config.h
  271. Xload.o: ../hdrs/ships.h ../hdrs/races.h ../hdrs/power.h
  272. Xload.o: ../hdrs/buffers.h ../hdrs/proto.h
  273. Xmap.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  274. Xmap.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  275. Xmap.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  276. Xmobiliz.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  277. Xmobiliz.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  278. Xmobiliz.o: ../hdrs/buffers.h ../hdrs/races.h ../hdrs/power.h ../hdrs/proto.h
  279. Xmove.o: ../hdrs/GB_copyright.h ../hdrs/vars.h
  280. Xmove.o: ../hdrs/files.h ../hdrs/tweakables.h ../hdrs/config.h
  281. Xmove.o: ../hdrs/ships.h ../hdrs/races.h ../hdrs/power.h
  282. Xmove.o: ../hdrs/buffers.h ../hdrs/proto.h
  283. Xname.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  284. Xname.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/races.h
  285. Xname.o: ../hdrs/power.h ../hdrs/ships.h ../hdrs/buffers.h ../hdrs/proto.h
  286. Xorbit.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  287. Xorbit.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  288. Xorbit.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  289. Xorder.o: ../hdrs/GB_copyright.h ../hdrs/vars.h
  290. Xorder.o: ../hdrs/files.h ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  291. Xorder.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  292. Xpower.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  293. Xpower.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  294. Xpower.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  295. Xprof.o: ../hdrs/GB_copyright.h
  296. Xprof.o: ../hdrs/vars.h ../hdrs/files.h ../hdrs/tweakables.h ../hdrs/config.h
  297. Xprof.o: ../hdrs/races.h ../hdrs/ships.h ../hdrs/buffers.h ../hdrs/proto.h
  298. Xrelation.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  299. Xrelation.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/races.h
  300. Xrelation.o: ../hdrs/ships.h ../hdrs/buffers.h ../hdrs/proto.h
  301. Xrst.o: ../hdrs/GB_copyright.h ../hdrs/vars.h
  302. Xrst.o: ../hdrs/files.h ../hdrs/tweakables.h ../hdrs/config.h
  303. Xrst.o: ../hdrs/ships.h ../hdrs/races.h ../hdrs/power.h
  304. Xrst.o: ../hdrs/buffers.h ../hdrs/proto.h
  305. Xsche.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  306. Xsche.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/buffers.h
  307. Xscrap.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  308. Xscrap.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  309. Xscrap.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h
  310. Xshootblast.o: ../hdrs/GB_copyright.h ../hdrs/vars.h
  311. Xshootblast.o: ../hdrs/files.h ../hdrs/tweakables.h ../hdrs/config.h
  312. Xshootblast.o: ../hdrs/ships.h ../hdrs/races.h
  313. Xshootblast.o: ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  314. Xsurvey.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  315. Xsurvey.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  316. Xsurvey.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  317. Xtech.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  318. Xtech.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  319. Xtech.o: ../hdrs/power.h ../hdrs/races.h ../hdrs/buffers.h  ../hdrs/proto.h
  320. Xtele.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  321. Xtele.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/races.h
  322. Xtele.o: ../hdrs/buffers.h ../hdrs/power.h ../hdrs/ships.h ../hdrs/proto.h
  323. Xtogg.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  324. Xtogg.o: ../hdrs/tweakables.h ../hdrs/config.h  ../hdrs/ships.h
  325. Xtogg.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h ../hdrs/proto.h
  326. Xtoxi.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  327. Xtoxi.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  328. Xtoxi.o: ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h  ../hdrs/proto.h
  329. Xvict.o: ../hdrs/GB_copyright.h ../hdrs/vars.h
  330. Xvict.o: ../hdrs/files.h ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/proto.h
  331. Xvict.o: ../hdrs/ships.h ../hdrs/races.h ../hdrs/power.h ../hdrs/buffers.h 
  332. Xzoom.o: ../hdrs/GB_copyright.h ../hdrs/vars.h ../hdrs/files.h
  333. Xzoom.o: ../hdrs/tweakables.h ../hdrs/config.h ../hdrs/ships.h
  334. Xzoom.o: ../hdrs/races.h ../hdrs/buffers.h ../hdrs/proto.h
  335. X!NO!SUBS!
  336. END_OF_FILE
  337. if test 10992 -ne `wc -c <'user/Makefile.SH'`; then
  338.     echo shar: \"'user/Makefile.SH'\" unpacked with wrong size!
  339. fi
  340. # end of 'user/Makefile.SH'
  341. fi
  342. if test -f 'user/build.c1' -a "${1}" != "-c" ; then 
  343.   echo shar: Will not clobber existing file \"'user/build.c1'\"
  344. else
  345. echo shar: Extracting \"'user/build.c1'\" \(10636 characters\)
  346. sed "s/^X//" >'user/build.c1' <<'END_OF_FILE'
  347. X#ident  "@(#)build.c    1.7 2/1/93 "
  348. X/*
  349. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky,
  350. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. Restrictions in
  351. X * GB_copyright.h build -- build a ship Mon Apr 15 02:07:08 MDT 1991
  352. X * Reformatted the 'make' command when at Factory scope. Evan Koffler
  353. X */
  354. X
  355. X#include "GB_copyright.h"
  356. X
  357. X#include <math.h>
  358. X#include <curses.h>
  359. X#include <setjmp.h>
  360. X#include <signal.h>
  361. X#include <strings.h>
  362. X#define EXTERN extern
  363. X#include "vars.h"
  364. X#include "ships.h"
  365. X#include "races.h"
  366. X#include "power.h"
  367. X#include "buffers.h"
  368. X
  369. Xextern int      ShipVector[];
  370. X
  371. Xvoid            upgrade(int, int, int);
  372. Xvoid            make_mod(int, int, int, int);
  373. Xvoid            build(int, int, int);
  374. Xint             getcount(int, char *);
  375. Xint             can_build_at_planet(int, int, startype *, planettype *);
  376. Xint             get_build_type(char *);
  377. Xint             can_build_this(int, racetype *, char *);
  378. Xint             can_build_on_ship(int, racetype *, shiptype *, char *);
  379. Xint 
  380. Xcan_build_on_sector(int, racetype *, planettype *, sectortype *, int, int,
  381. X            char *);
  382. Xint             build_at_ship(int, int, racetype *, shiptype *, int *, int *);
  383. Xvoid 
  384. Xautoload_at_planet(int, shiptype *, planettype *, sectortype *, int *,
  385. X           double *);
  386. Xvoid            autoload_at_ship(int, shiptype *, shiptype *, int *, double *);
  387. Xvoid            initialize_new_ship(int, int, racetype *, shiptype *, double, int);
  388. Xvoid 
  389. Xcreate_ship_by_planet(int, int, racetype *, shiptype *, planettype *,
  390. X              int, int, int, int);
  391. Xvoid 
  392. Xcreate_ship_by_ship(int, int, racetype *, int, startype *, planettype *,
  393. X            shiptype *, shiptype *);
  394. Xdouble          getmass(shiptype *);
  395. Xint             ship_size(shiptype *);
  396. Xdouble          cost(shiptype *);
  397. Xvoid            system_cost(double *, double *, int, int);
  398. Xdouble          complexity(shiptype *);
  399. Xvoid            Getship(shiptype *, int, racetype *);
  400. Xvoid            Getfactship(shiptype *, shiptype *);
  401. Xint             Shipcost(int, racetype *);
  402. Xvoid            sell(int, int, int);
  403. Xvoid            bid(int, int, int);
  404. Xint             shipping_cost(int, int, double *, int);
  405. X#include "proto.h"
  406. X
  407. X/* upgrade ship characteristics */
  408. Xvoid 
  409. Xupgrade(int Playernum, int Governor, int APcount)
  410. X{
  411. X    int             value, oldcost, newcost, netcost;
  412. X    shiptype        ship, *dirship, *s2;
  413. X    double          complex;
  414. X    racetype       *Race;
  415. X
  416. X    if (Dir[Playernum - 1][Governor].level != LEVEL_SHIP) {
  417. X        notify(Playernum, Governor,
  418. X               "You have to change scope to the ship you wish to upgrade.\n");
  419. X        return;
  420. X    }
  421. X    if (!getship(&dirship, Dir[Playernum - 1][Governor].shipno)) {
  422. X        sprintf(buf, "Illegal dir value.\n");
  423. X        notify(Playernum, Governor, buf);
  424. X        return;
  425. X    }
  426. X    if (testship(Playernum, Governor, dirship)) {
  427. X        free(dirship);
  428. X        return;
  429. X    }
  430. X    if (dirship->damage) {
  431. X        notify(Playernum, Governor, "You cannot upgrade damaged ships.\n");
  432. X        free(dirship);
  433. X        return;
  434. X    }
  435. X    if (dirship->type == OTYPE_FACTORY) {
  436. X        notify(Playernum, Governor, "You can't upgrade factories.\n");
  437. X        free(dirship);
  438. X        return;
  439. X    }
  440. X    Race = races[Playernum - 1];
  441. X    bcopy(dirship, &ship, sizeof(shiptype));
  442. X
  443. X    if (argn == 3)
  444. X        sscanf(args[2], "%d", &value);
  445. X    else
  446. X        value = 0;
  447. X
  448. X    if (value < 0) {
  449. X        notify(Playernum, Governor, "That's a ridiculous setting.\n");
  450. X        free(dirship);
  451. X        return;
  452. X    }
  453. X    if (Shipdata[dirship->build_type][ABIL_MOD]) {
  454. X        if (match(args[1], "armor")) {
  455. X            ship.armor = MAX(dirship->armor, MIN(value, 100));
  456. X        } else if (match(args[1], "crew")
  457. X               && Shipdata[dirship->build_type][ABIL_MAXCREW]) {
  458. X            ship.max_crew = MAX(dirship->max_crew, MIN(value, 10000));
  459. X        } else if (match(args[1], "cargo")
  460. X               && Shipdata[dirship->build_type][ABIL_CARGO]) {
  461. X            ship.max_resource = MAX(dirship->max_resource, MIN(value, 10000));
  462. X        } else if (match(args[1], "hanger")
  463. X               && Shipdata[dirship->build_type][ABIL_HANGER]) {
  464. X            ship.max_hanger = MAX(dirship->max_hanger, MIN(value, 10000));
  465. X        } else if (match(args[1], "fuel")
  466. X               && Shipdata[dirship->build_type][ABIL_FUELCAP]) {
  467. X            ship.max_fuel = MAX(dirship->max_fuel, MIN(value, 10000));
  468. X        } else if (match(args[1], "mount")
  469. X               && Shipdata[dirship->build_type][ABIL_MOUNT]
  470. X               && !dirship->mount) {
  471. X            if (!Crystal(Race)) {
  472. X                notify(Playernum, Governor,
  473. X                       "Your race does not now how to utilize crystal power yet.\n");
  474. X                free(dirship);
  475. X                return;
  476. X            }
  477. X            ship.mount = !ship.mount;
  478. X        } else if (match(args[1], "destruct")
  479. X               && Shipdata[dirship->build_type][ABIL_DESTCAP]) {
  480. X            ship.max_destruct = MAX(dirship->max_destruct, MIN(value, 10000));
  481. X        } else if (match(args[1], "speed")
  482. X               && Shipdata[dirship->build_type][ABIL_SPEED]) {
  483. X            ship.max_speed = MAX(dirship->max_speed, MAX(1, MIN(value, 9)));
  484. X        } else if (match(args[1], "hyperdrive")
  485. X               && Shipdata[dirship->build_type][ABIL_JUMP]
  486. X               && !dirship->hyper_drive.has
  487. X               && Hyper_drive(Race)) {
  488. X            ship.hyper_drive.has = 1;
  489. X        } else if (match(args[1], "primary")
  490. X               && Shipdata[dirship->build_type][ABIL_PRIMARY]) {
  491. X            if (match(args[2], "strength")) {
  492. X                if (ship.primtype == NONE) {
  493. X                    notify(Playernum, Governor, "No caliber defined.\n");
  494. X                    free(dirship);
  495. X                    return;
  496. X                }
  497. X                ship.primary = atoi(args[3]);
  498. X                ship.primary = MAX(ship.primary, dirship->primary);
  499. X            } else if (match(args[2], "caliber")) {
  500. X                if (match(args[3], "light"))
  501. X                    ship.primtype = MAX(LIGHT, dirship->primtype);
  502. X                else if (match(args[3], "medium"))
  503. X                    ship.primtype = MAX(MEDIUM, dirship->primtype);
  504. X                else if (match(args[3], "heavy"))
  505. X                    ship.primtype = MAX(HEAVY, dirship->primtype);
  506. X                else {
  507. X                    notify(Playernum, Governor, "No such caliber.\n");
  508. X                    free(dirship);
  509. X                    return;
  510. X                }
  511. X                ship.primtype = MIN(Shipdata[dirship->build_type][ABIL_PRIMARY],
  512. X                            ship.primtype);
  513. X            } else {
  514. X                notify(Playernum, Governor, "No such gun characteristic.\n");
  515. X                free(dirship);
  516. X                return;
  517. X            }
  518. X        } else if (match(args[1], "secondary")
  519. X             && Shipdata[dirship->build_type][ABIL_SECONDARY]) {
  520. X            if (match(args[2], "strength")) {
  521. X                if (ship.sectype == NONE) {
  522. X                    notify(Playernum, Governor, "No caliber defined.\n");
  523. X                    free(dirship);
  524. X                    return;
  525. X                }
  526. X                ship.secondary = atoi(args[3]);
  527. X                ship.secondary = MAX(ship.secondary, dirship->secondary);
  528. X            } else if (match(args[2], "caliber")) {
  529. X                if (match(args[3], "light"))
  530. X                    ship.sectype = MAX(LIGHT, dirship->sectype);
  531. X                else if (match(args[3], "medium"))
  532. X                    ship.sectype = MAX(MEDIUM, dirship->sectype);
  533. X                else if (match(args[3], "heavy"))
  534. X                    ship.sectype = MAX(HEAVY, dirship->sectype);
  535. X                else {
  536. X                    notify(Playernum, Governor, "No such caliber.\n");
  537. X                    free(dirship);
  538. X                    return;
  539. X                }
  540. X                ship.sectype = MIN(Shipdata[dirship->build_type][ABIL_SECONDARY],
  541. X                           ship.sectype);
  542. X            } else {
  543. X                notify(Playernum, Governor, "No such gun characteristic.\n");
  544. X                free(dirship);
  545. X                return;
  546. X            }
  547. X        } else if (match(args[1], "cew")
  548. X               && Shipdata[dirship->build_type][ABIL_CEW]) {
  549. X            if (!Cew(Race)) {
  550. X                sprintf(buf, "Your race cannot build confined energy weapons.\n");
  551. X                notify(Playernum, Governor, buf);
  552. X                free(dirship);
  553. X                return;
  554. X            }
  555. X            if (!Shipdata[dirship->build_type][ABIL_CEW]) {
  556. X                notify(Playernum, Governor,
  557. X                       "This kind of ship cannot mount confined energy weapons.\n");
  558. X                free(dirship);
  559. X                return;
  560. X            }
  561. X            value = atoi(args[3]);
  562. X            if (match(args[2], "strength")) {
  563. X                ship.cew = value;
  564. X            } else if (match(args[2], "range")) {
  565. X                ship.cew_range = value;
  566. X            } else {
  567. X                notify(Playernum, Governor, "No such option for CEWs.\n");
  568. X                free(dirship);
  569. X                return;
  570. X            }
  571. X        } else if (match(args[1], "laser")
  572. X               && Shipdata[dirship->build_type][ABIL_LASER]) {
  573. X            if (!Laser(Race)) {
  574. X                sprintf(buf, "Your race cannot build lasers.\n");
  575. X                notify(Playernum, Governor, buf);
  576. X                free(dirship);
  577. X                return;
  578. X            }
  579. X            if (Shipdata[dirship->build_type][ABIL_LASER])
  580. X                ship.laser = 1;
  581. X            else {
  582. X                notify(Playernum, Governor,
  583. X                       "That ship cannot be fitted with combat lasers.\n");
  584. X                free(dirship);
  585. X                return;
  586. X            }
  587. X        } else {
  588. X            notify(Playernum, Governor,
  589. X                   "That characteristic either doesn't exist or can't be modified.\n");
  590. X            free(dirship);
  591. X            return;
  592. X        }
  593. X    } else {
  594. X        notify(Playernum, Governor, "This ship cannot be upgraded.\n");
  595. X        free(dirship);
  596. X        return;
  597. X    }
  598. X
  599. X    /*
  600. X     * check to see whether this ship can actually be built by this
  601. X     * player
  602. X     */
  603. X    if ((complex = complexity(&ship)) > Race->tech) {
  604. X        sprintf(buf, "This upgrade requires an engineering technology of %.1f.\n", complex);
  605. X        notify(Playernum, Governor, buf);
  606. X        free(dirship);
  607. X        return;
  608. X    }
  609. X    /*
  610. X     * check to see if the new ship will actually fit inside the hanger
  611. X     * if it is on another ship. Maarten
  612. X     */
  613. X    if (dirship->whatorbits == LEVEL_SHIP) {
  614. X        (void) getship(&s2, dirship->destshipno);
  615. X        if (s2->max_hanger - (s2->hanger - dirship->size) < ship_size(&ship)) {
  616. X            sprintf(buf, "Not enough free hanger space on %c%d.\n",
  617. X                Shipltrs[s2->type], dirship->destshipno);
  618. X            notify(Playernum, Governor, buf);
  619. X            sprintf(buf, "%d more needed.\n",
  620. X                ship_size(&ship) - (s2->max_hanger - (s2->hanger - dirship->size)));
  621. X            notify(Playernum, Governor, buf);
  622. X            free(s2);
  623. X            free(dirship);
  624. X            return;
  625. X        }
  626. X    }
  627. X    /* compute new ship costs and see if the player can afford it */
  628. X    newcost = Race->God ? 0 : (int) cost(&ship);
  629. X    oldcost = Race->God ? 0 : dirship->build_cost;
  630. X    netcost = Race->God ? 0 : 2 * (newcost - oldcost);    /* upgrade is expensive */
  631. X    if (newcost < oldcost) {
  632. X        notify(Playernum, Governor, "You cannot downgrade ships!\n");
  633. X        free(dirship);
  634. X        return;
  635. X    }
  636. X    if (!Race->God)
  637. X        netcost += !netcost;
  638. X
  639. X    if (netcost > dirship->resource) {
  640. X        sprintf(buf, "Old value %dr   New value %dr\n", oldcost, newcost);
  641. X        notify(Playernum, Governor, buf);
  642. X        sprintf(buf, "You need %d resources on board to make this modification.\n", netcost);
  643. X        notify(Playernum, Governor, buf);
  644. X    } else if (netcost || Race->God) {
  645. X        sprintf(buf, "Old value %dr   New value %dr\n", oldcost, newcost);
  646. X        notify(Playernum, Governor, buf);
  647. X        sprintf(buf, "Characteristic modified at a cost of %d resources.\n", netcost);
  648. X        notify(Playernum, Governor, buf);
  649. X        bcopy(&ship, dirship, sizeof(shiptype));
  650. X        dirship->resource -= netcost;
  651. X        if (dirship->whatorbits == LEVEL_SHIP) {
  652. X            s2->hanger -= dirship->size;
  653. X            dirship->size = ship_size(dirship);
  654. X            s2->hanger += dirship->size;
  655. X            putship(s2);
  656. X        }
  657. X        dirship->size = ship_size(dirship);
  658. X        dirship->base_mass = getmass(dirship);
  659. X        dirship->build_cost = Race->God ? 0 : cost(dirship);
  660. X        dirship->complexity = complexity(dirship);
  661. X
  662. X        putship(dirship);
  663. X    } else
  664. X        notify(Playernum, Governor, "You can not make this modification.\n");
  665. X    free(dirship);
  666. X}
  667. X
  668. END_OF_FILE
  669. if test 10636 -ne `wc -c <'user/build.c1'`; then
  670.     echo shar: \"'user/build.c1'\" unpacked with wrong size!
  671. fi
  672. # end of 'user/build.c1'
  673. fi
  674. if test -f 'user/scrap.c' -a "${1}" != "-c" ; then 
  675.   echo shar: Will not clobber existing file \"'user/scrap.c'\"
  676. else
  677. echo shar: Extracting \"'user/scrap.c'\" \(8063 characters\)
  678. sed "s/^X//" >'user/scrap.c' <<'END_OF_FILE'
  679. X/*
  680. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky,
  681. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h. Restrictions in
  682. X * GB_copyright.h.
  683. X * 
  684. X * scrap.c -- turn a ship to junk
  685. X */
  686. X
  687. X#include "GB_copyright.h"
  688. X#define EXTERN extern
  689. X#include "vars.h"
  690. X#include "ships.h"
  691. X#include "races.h"
  692. X#include "power.h"
  693. X#include "buffers.h"
  694. X#include <signal.h>
  695. X
  696. Xvoid            scrap(int, int, int);
  697. X#include "proto.h"
  698. X
  699. Xvoid 
  700. Xscrap(int Playernum, int Governor, int APcount)
  701. X{
  702. X    planettype     *planet;
  703. X    sectortype     *sect;
  704. X    shiptype       *s, *s2;
  705. X    int             shipno, nextshipno;
  706. X    int             scrapval = 0, destval = 0, crewval = 0, xtalval = 0,
  707. X                    troopval = 0;
  708. X    double          fuelval = 0.0;
  709. X    racetype       *Race;
  710. X
  711. X    if (argn < 2) {
  712. X        notify(Playernum, Governor, "Scrap what?\n");
  713. X        return;
  714. X    }
  715. X    nextshipno = start_shiplist(Playernum, Governor, args[1]);
  716. X
  717. X    while (shipno = do_shiplist(&s, &nextshipno))
  718. X        if (in_list(Playernum, args[1], s, &nextshipno) &&
  719. X            authorized(Governor, s)) {
  720. X            if (s->max_crew && !s->popn) {
  721. X                notify(Playernum, Governor, "Can't scrap that ship - no crew.\n");
  722. X                free(s);
  723. X                continue;
  724. X            }
  725. X            if (s->whatorbits == LEVEL_UNIV) {
  726. X                continue;
  727. X            } else if (!enufAP(Playernum, Governor, Stars[s->storbits]->AP[Playernum - 1], APcount)) {
  728. X                free(s);
  729. X                continue;
  730. X            }
  731. X            if (s->whatorbits == LEVEL_PLAN && s->type == OTYPE_TOXWC) {
  732. X                sprintf(buf, "WARNING: This will release %d toxin points back into the atmosphere!!\n", s->special.waste.toxic);
  733. X                notify(Playernum, Governor, buf);
  734. X            }
  735. X            if (!s->docked) {
  736. X                sprintf(buf, "%s is not landed or docked.\nNo resources can be reclaimed.\n", Ship(s));
  737. X                notify(Playernum, Governor, buf);
  738. X            }
  739. X            if (s->whatorbits == LEVEL_PLAN) {
  740. X                /* wc's release poison */
  741. X                getplanet(&planet, (int) s->storbits, (int) s->pnumorbits);
  742. X                if (landed(s))
  743. X                    getsector(§, planet, (int) s->land_x, (int) s->land_y);
  744. X            }
  745. X            if (docked(s)) {
  746. X                if (!getship(&s2, (int) (s->destshipno))) {
  747. X                    free(s);
  748. X                    continue;
  749. X                }
  750. X                if (!(s2->docked && s2->destshipno == s->number) &&
  751. X                    !s->whatorbits == LEVEL_SHIP) {
  752. X                    sprintf(buf, "Warning, other ship not docked..\n");
  753. X                    notify(Playernum, Governor, buf);
  754. X                    free(s);
  755. X                    free(s2);
  756. X                    continue;
  757. X                }
  758. X            }
  759. X            scrapval = Cost(s) / 2 + s->resource;
  760. X
  761. X            if (s->docked) {
  762. X                sprintf(buf, "%s: original cost: %d\n", Ship(s), Cost(s));
  763. X                notify(Playernum, Governor, buf);
  764. X                sprintf(buf, "         scrap value%s: %d rp's.\n",
  765. X                    s->resource ? "(with stockpile) " : "", scrapval);
  766. X                notify(Playernum, Governor, buf);
  767. X
  768. X                if (s->whatdest == LEVEL_SHIP &&
  769. X                s2->resource + scrapval > Max_resource(s2) &&
  770. X                    s2->type != STYPE_SHUTTLE) {
  771. X                    scrapval = Max_resource(s2) - s2->resource;
  772. X                    sprintf(buf, "(There is only room for %d resources.)\n", scrapval);
  773. X                    notify(Playernum, Governor, buf);
  774. X                }
  775. X                if (s->fuel) {
  776. X                    sprintf(buf, "Fuel recovery: %.0f.\n", s->fuel);
  777. X                    notify(Playernum, Governor, buf);
  778. X                    fuelval = s->fuel;
  779. X                    if (s->whatdest == LEVEL_SHIP && s2->fuel + fuelval > Max_fuel(s2)) {
  780. X                        fuelval = Max_fuel(s2) - s2->fuel;
  781. X                        sprintf(buf, "(There is only room for %.2f fuel.)\n", fuelval);
  782. X                        notify(Playernum, Governor, buf);
  783. X                    }
  784. X                } else
  785. X                    fuelval = 0.0;
  786. X
  787. X                if (s->destruct) {
  788. X                    sprintf(buf, "Weapons recovery: %d.\n", s->destruct);
  789. X                    notify(Playernum, Governor, buf);
  790. X                    destval = s->destruct;
  791. X                    if (s->whatdest == LEVEL_SHIP && s2->destruct + destval > Max_destruct(s2)) {
  792. X                        destval = Max_destruct(s2) - s2->destruct;
  793. X                        sprintf(buf, "(There is only room for %d destruct.)\n", destval);
  794. X                        notify(Playernum, Governor, buf);
  795. X                    }
  796. X                } else
  797. X                    destval = 0;
  798. X
  799. X                if (s->popn + s->troops) {
  800. X                    if (s->whatdest == LEVEL_PLAN && sect->owner > 0 && sect->owner != Playernum) {
  801. X                        sprintf(buf, "You don't own this sector; no crew can be recovered.\n");
  802. X                        notify(Playernum, Governor, buf);
  803. X                    } else {
  804. X                        sprintf(buf, "Population/Troops recovery: %d/%d.\n",
  805. X                            s->popn, s->troops);
  806. X                        notify(Playernum, Governor, buf);
  807. X                        troopval = s->troops;
  808. X                        if (s->whatdest == LEVEL_SHIP && s2->troops + troopval > Max_mil(s2)) {
  809. X                            troopval = Max_mil(s2) - s2->troops;
  810. X                            sprintf(buf, "(There is only room for %d troops.)\n", troopval);
  811. X                            notify(Playernum, Governor, buf);
  812. X                        }
  813. X                        crewval = s->popn;
  814. X                        if (s->whatdest == LEVEL_SHIP && s2->popn + crewval > Max_crew(s2)) {
  815. X                            crewval = Max_crew(s2) - s2->popn;
  816. X                            sprintf(buf, "(There is only room for %d crew.)\n", crewval);
  817. X                            notify(Playernum, Governor, buf);
  818. X                        }
  819. X                    }
  820. X                } else {
  821. X                    crewval = 0;
  822. X                    troopval = 0;
  823. X                }
  824. X
  825. X                if (s->crystals + s->mounted) {
  826. X                    if (s->whatdest == LEVEL_PLAN && sect->owner > 0 && sect->owner != Playernum) {
  827. X                        sprintf(buf, "You don't own this sector; no crystals can be recovered.\n");
  828. X                        notify(Playernum, Governor, buf);
  829. X                    } else {
  830. X                        xtalval = s->crystals + s->mounted;
  831. X                        if (s->whatdest == LEVEL_SHIP && s2->crystals + xtalval > Max_crystals(s2)) {
  832. X                            xtalval = Max_crystals(s2) - s2->crystals;
  833. X                            sprintf(buf, "(There is only room for %d crystals.)\n", xtalval);
  834. X                            notify(Playernum, Governor, buf);
  835. X                        }
  836. X                        sprintf(buf, "Crystal recovery: %d.\n", xtalval);
  837. X                        notify(Playernum, Governor, buf);
  838. X                    }
  839. X                } else
  840. X                    xtalval = 0;
  841. X            }
  842. X            /* more adjustments needed here for hanger. Maarten */
  843. X            if (s->whatorbits == LEVEL_SHIP)
  844. X                s2->hanger -= s->size;
  845. X
  846. X            if (s->whatorbits == LEVEL_UNIV)
  847. X                deductAPs(Playernum, Governor, APcount, 0, 1);
  848. X            else
  849. X                deductAPs(Playernum, Governor, APcount, (int) s->storbits, 0);
  850. X
  851. X            Race = races[Playernum - 1];
  852. X            kill_ship(Playernum, s);
  853. X            putship(s);
  854. X            if (docked(s)) {
  855. X#ifdef NEVER
  856. X                fuelval = MIN(fuelval, 1. * Max_fuel(s2) - s2->fuel);
  857. X                destval = MIN(destval, Max_destruct(s2) - s2->destruct);
  858. X                if (s2->type != STYPE_SHUTTLE)    /* Leave scrapval alone
  859. X                                 * for shuttles */
  860. X                    scrapval = MIN(scrapval, Max_resource(s2) - s2->resource);
  861. X                troopval = MIN(troopval, Max_crew(s2) - s2->troops);
  862. X                crewval = MIN(crewval, Max_crew(s2) - s2->popn);
  863. X                xtalval = MIN(xtalval, Max_crystals(s2) - s2->crystals);
  864. X#endif
  865. X                s2->crystals += xtalval;
  866. X                rcv_fuel(s2, (double) fuelval);
  867. X                rcv_destruct(s2, destval);
  868. X                rcv_resource(s2, scrapval);
  869. X                rcv_troops(s2, troopval, Race->mass);
  870. X                rcv_popn(s2, crewval, Race->mass);
  871. X                /*
  872. X                 * check for docking status in case scrapped
  873. X                 * ship is landed. Maarten
  874. X                 */
  875. X                if (!(s->whatorbits == LEVEL_SHIP)) {
  876. X                    s2->docked = 0;    /* undock the surviving
  877. X                             * ship */
  878. X                    s2->whatdest = LEVEL_UNIV;
  879. X                    s2->destshipno = 0;
  880. X                }
  881. X                putship(s2);
  882. X                free(s2);
  883. X            }
  884. X            if (s->whatorbits == LEVEL_PLAN) {
  885. X                free(planet);    /* This has already been
  886. X                         * allocated */
  887. X                getplanet(&planet, (int) s->storbits, (int) s->pnumorbits);
  888. X                if (landed(s)) {
  889. X                    if (sect->owner == Playernum) {
  890. X                        sect->popn += troopval;
  891. X                        sect->popn += crewval;
  892. X                    } else if (sect->owner == 0) {
  893. X                        sect->owner = Playernum;
  894. X                        sect->popn += crewval;
  895. X                        sect->troops += troopval;
  896. X                        planet->info[Playernum - 1].numsectsowned++;
  897. X                        planet->info[Playernum - 1].popn += crewval;
  898. X                        planet->info[Playernum - 1].popn += troopval;
  899. X                        sprintf(buf, "Sector %d,%d Colonized.\n", s->land_x, s->land_y);
  900. X                        notify(Playernum, Governor, buf);
  901. X                    }
  902. X                    planet->info[Playernum - 1].resource += scrapval;
  903. X                    planet->popn += crewval;
  904. X                    planet->info[Playernum - 1].destruct += destval;
  905. X                    planet->info[Playernum - 1].fuel += (int) fuelval;
  906. X                    planet->info[Playernum - 1].crystals += (int) xtalval;
  907. X                    putsector(sect, planet, (int) s->land_x, (int) s->land_y);
  908. X                    free(sect);
  909. X                }
  910. X                putplanet(planet, (int) s->storbits, (int) s->pnumorbits);
  911. X                free(planet);
  912. X            }
  913. X            if (landed(s)) {
  914. X                sprintf(buf, "\nScrapped.\n");
  915. X                notify(Playernum, Governor, buf);
  916. X            } else {
  917. X                sprintf(buf, "\nDestroyed.\n");
  918. X                notify(Playernum, Governor, buf);
  919. X            }
  920. X            free(s);
  921. X        } else
  922. X            free(s);
  923. X}
  924. END_OF_FILE
  925. if test 8063 -ne `wc -c <'user/scrap.c'`; then
  926.     echo shar: \"'user/scrap.c'\" unpacked with wrong size!
  927. fi
  928. # end of 'user/scrap.c'
  929. fi
  930. if test -f 'utils/makestar.c' -a "${1}" != "-c" ; then 
  931.   echo shar: Will not clobber existing file \"'utils/makestar.c'\"
  932. else
  933. echo shar: Extracting \"'utils/makestar.c'\" \(10604 characters\)
  934. sed "s/^X//" >'utils/makestar.c' <<'END_OF_FILE'
  935. X
  936. X/* makestar.c -- create, name, position, and make planetd for a star.
  937. X *
  938. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, 
  939. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h.
  940. X * Restrictions in GB_copyright.h.
  941. X */
  942. X#if 0
  943. XG.O.D. [1] > methane melts at -182C
  944. XG.O.D. [1] > it boils at -164
  945. XG.O.D. [1] > ammonia melts at -78C
  946. XG.O.D. [1] > boils at -33
  947. X#endif
  948. X
  949. X#include <math.h>
  950. X#include "GB_copyright.h"
  951. X#define EXTERN
  952. X#include "vars.h"
  953. X#include "ships.h"
  954. X#include "races.h"
  955. X#include "power.h"      /* (for power) */
  956. X
  957. X#define PLANET_DIST_MAX 1900.0
  958. X#define PLANET_DIST_MIN 100.0
  959. X
  960. X#define ALLOCATE(type) ((type *) malloc(sizeof(type)))
  961. X#undef malloc
  962. X#undef realloc
  963. X#undef free 
  964. X/* Just in case */
  965. X
  966. Xextern void place_star(startype *star);
  967. Xextern planettype Makeplanet(double, short, int);
  968. X
  969. Xvoid Makestar_init(void) ;
  970. Xchar *NextStarName(void) ;
  971. Xstartype *Makestar(FILE *, FILE *) ;
  972. Xvoid Makeplanet_init(void) ;
  973. Xchar *NextPlanetName(int);
  974. Xvoid rand_list(int, int *);
  975. X
  976. Xextern double double_rand(void);
  977. Xextern int int_rand(int, int);
  978. Xextern int round_rand(double);
  979. Xextern int rposneg(void);
  980. X
  981. X
  982. Xint Numtypes[TYPE_DESERT+2] = {0, };
  983. Xint Resource[TYPE_DESERT+2] = {0, } ;
  984. Xint Numsects[TYPE_DESERT+2][PLATED+1] = {0, } ;
  985. Xint Fertsects[TYPE_DESERT+2][PLATED+1] = {0, } ;
  986. Xchar *Nametypes[] = {"Earth", "Asteroid", "Airless", "Iceball", "Gaseous",
  987. X                       "Water", "Forest", "Desert", " >>"};
  988. Xchar *Namesects[] = {"sea", "land", "mountain", "gaseous", "ice",
  989. X                       "desert", "forest", "plated"};
  990. X
  991. X
  992. X/*
  993. X * Variables found in makeuniv.c:  */
  994. Xextern int autoname_plan ;
  995. Xextern int autoname_star ;
  996. Xextern int minplanets ;
  997. Xextern int maxplanets ;
  998. Xextern int nstars ;
  999. Xextern int planetlesschance ;
  1000. Xextern int printplaninfo ;
  1001. Xextern int printstarinfo ;
  1002. X
  1003. X
  1004. X
  1005. Xint Temperature(double dist, int stemp)
  1006. X{
  1007. X  return -269 + stemp * 1315 * 40 / (40 + dist) ;
  1008. X} 
  1009. X
  1010. X
  1011. Xvoid PrintStatistics(void)
  1012. X{
  1013. X  int i, j, y ;
  1014. X
  1015. X  printf("\nPlanet/Sector distribution -\n") ;
  1016. X  printf("Type NP     .    *    ^    ~    #    (    -    NS   Avg     Res    Avg  A/Sec\n") ;
  1017. X  for (i=0; i<=TYPE_DESERT+1; i++)
  1018. X    {
  1019. X    printf("%3.3s%4d ", Nametypes[i], Numtypes[i]);
  1020. X    if (i < TYPE_DESERT+1)
  1021. X      Numtypes[TYPE_DESERT+1] += Numtypes[i] ;
  1022. X    for (j=0; j<PLATED; j++)
  1023. X      {
  1024. X      printf("%5d", Numsects[i][j]) ;
  1025. X      Numsects[i][PLATED] += Numsects[i][j] ;
  1026. X      if (i <= TYPE_DESERT)
  1027. X        Numsects[TYPE_DESERT+1][j] += Numsects[i][j] ;
  1028. X      }
  1029. X    printf("%6d %5.1f", Numsects[i][PLATED],
  1030. X           (1.0 * Numsects[i][PLATED]) / Numtypes[i]) ;
  1031. X    printf("%8d %7.1f %5.1f\n", Resource[i], 
  1032. X           ((double)Resource[i]) / Numtypes[i], 
  1033. X           ((double)Resource[i]) / Numsects[i][PLATED]) ;
  1034. X    Resource[TYPE_DESERT+1] += Resource[i] ;
  1035. X    }
  1036. X  printf("Average Sector Fertility -\n") ;
  1037. X  printf("Type NP     .    *    ^    ~    #    (    -    Fert  /Plan  /Sect\n") ;
  1038. X  for (i=0; i<=TYPE_DESERT+1; i++)
  1039. X    {
  1040. X    printf("%3.3s%4d ", Nametypes[i], Numtypes[i]);
  1041. X    y = 0 ;
  1042. X    for (j=0; j<PLATED; j++)
  1043. X      {
  1044. X      if (Numsects[i][j])
  1045. X        printf("%5.1f", ((double)Fertsects[i][j]) / Numsects[i][j]) ;
  1046. X      else
  1047. X        printf("    -") ;
  1048. X      y += Fertsects[i][j] ;
  1049. X      Fertsects[TYPE_DESERT+1][j] += Fertsects[i][j] ;
  1050. X      }
  1051. X    printf("%8d %7.1f %5.1f\n", y,
  1052. X           (1.0 * y) / Numtypes[i], 
  1053. X           (1.0 * y) / Numsects[i][PLATED]) ;
  1054. X    }
  1055. X  }
  1056. X
  1057. X
  1058. Xint ReadNameList(char ss[1000][20], int n, int m, char *filename)
  1059. X{
  1060. X  register int i, j ;
  1061. X  FILE *f = fopen(filename, "r") ;
  1062. X
  1063. X  if (f == NULL) {
  1064. X    printf("Unable to open \"%s\".\n", filename) ;
  1065. X    return -1 ;
  1066. X    }
  1067. X  for (i = 0; i < n; i++) {
  1068. X    for (j = 0; j < m; j++)
  1069. X      if ('\n' == (ss[i][j] = getc(f))) {
  1070. X        ss[i][j] = '\0' ;
  1071. X        goto next ;
  1072. X        }
  1073. X      else if (EOF == ss[i][j])
  1074. X        goto out ;
  1075. X    ss[i][j-1] = '\0' ;
  1076. X    while ('\n' !=  (j = getc(f)))
  1077. X      if (EOF == j)
  1078. X        goto out ;
  1079. X  next: ;
  1080. X    }
  1081. X out:
  1082. X  fclose(f) ;
  1083. X  printf("%d names listed in %s\n", i, filename) ;
  1084. X  return i ;
  1085. X  }
  1086. X
  1087. X
  1088. Xvoid rand_list(int n, int *list) /* mix up the numbers 0 thru n */
  1089. X{
  1090. X  short nums[1000], i, j, k ;
  1091. X  short kk, ii ;
  1092. X
  1093. X  for (i=0; i<=n; i++)
  1094. X    nums[i] = 0 ;
  1095. X  for (j=0; j<=n; j++)
  1096. X    {
  1097. X    i = k = int_rand(0, n) ;
  1098. X    while (nums[k] != 0)
  1099. X      k += nums[k] ;
  1100. X    list[j] = k ;
  1101. X    if (k == n)
  1102. X      nums[k] = -n, kk = 0 ;
  1103. X    else
  1104. X      nums[k] = 1, kk = k + 1 ;
  1105. X    /* K is now the next position in the list after the most recent number. */
  1106. X    /* Go through the list, making each pointer point to k.  */
  1107. X    while (i != k)
  1108. X      {
  1109. X      ii = i + nums[i] ;
  1110. X      nums[i] = kk - i ;
  1111. X      i = ii ;
  1112. X      }
  1113. X    }
  1114. X  }
  1115. X
  1116. X
  1117. X
  1118. Xint numplist, namepcount ;
  1119. Xchar PNames[1000][20] ;
  1120. Xint planet_list[1000] ;
  1121. X
  1122. Xvoid Makeplanet_init(void)
  1123. X{
  1124. X  numplist = ReadNameList(PNames, 1000, 20, PLANETLIST) ;
  1125. X  rand_list(numplist, planet_list) ;
  1126. X  if (numplist < 0)
  1127. X    exit(0) ;
  1128. X  namepcount = 0 ;
  1129. X}
  1130. X
  1131. Xchar *NextPlanetName(int i)
  1132. X{
  1133. X  static char *Numbers[] = {"1","2","3","4","5","6","7","8","9","10","11",
  1134. X                              "12","13","14","15" } ;
  1135. X  if (autoname_plan && (namepcount < numplist))
  1136. X    return PNames[planet_list[namepcount++]] ;
  1137. X  else
  1138. X    return Numbers[i] ;
  1139. X  }
  1140. X
  1141. X
  1142. Xint numslist, namestcount ;
  1143. Xchar SNames[1000][20] ;
  1144. Xint star_list[1000] ;
  1145. X
  1146. Xvoid Makestar_init(void)
  1147. X{
  1148. X  numslist = ReadNameList(SNames, 1000, 20, STARLIST) ;
  1149. X  rand_list(numslist, star_list) ;
  1150. X  if (numslist < 0)
  1151. X    exit(0) ;
  1152. X  namestcount = 0;
  1153. X  }
  1154. X
  1155. Xchar *NextStarName(void)
  1156. X{
  1157. X  static char buf[20] ;
  1158. X  int i ;
  1159. X
  1160. X  if (autoname_star && (namestcount <= numslist))
  1161. X    return SNames[star_list[namestcount++]] ;
  1162. X  else {
  1163. X    printf("Next star name:") ;
  1164. X    for (i=0; i<NAMESIZE-4; i++)
  1165. X      putchr('.') ;
  1166. X    for (i=0; i<NAMESIZE-4; i++)
  1167. X      putchr('\010') ;          /* ^H */
  1168. X    scanf("%14[^\n]", buf) ;
  1169. X    getchr() ;
  1170. X    }
  1171. X  return buf ;
  1172. X  }
  1173. X
  1174. Xstartype *Makestar(FILE *planetdata, FILE *sectordata)
  1175. X{
  1176. X  planettype planet ; 
  1177. X  int type, roll, temperature, empty_slots ;
  1178. X  int i, y, x ;
  1179. X  double dist, distmin, distmax, distsep;
  1180. X  double angle, xpos, ypos ;
  1181. X  startype *Star ;
  1182. X
  1183. X  /* get names, positions of stars first */
  1184. X  Star = ALLOCATE(startype) ;
  1185. X  bzero(Star, sizeof(startype)) ;
  1186. X  Star->gravity = int_rand(0, int_rand(0,300)) + 
  1187. X    int_rand(0, 300) + int_rand(100,400) + int_rand(0, 9) / 10.0 ;
  1188. X  Star->temperature = round_rand(Star->gravity/100.0) ;
  1189. X/* + int_rand(0,2) - 1 ; */
  1190. X  strcpy(Star->name, NextStarName()) ;
  1191. X  place_star(Star);
  1192. X  if (printstarinfo)
  1193. X    printf("Star %s: gravity %1.1f, temp %d\n", 
  1194. X           Star->name, Star->gravity, (int)Star->temperature) ;
  1195. X  /* 
  1196. X   * Generate planets for this star: */
  1197. X  Star->numplanets = int_rand(minplanets, maxplanets) ;
  1198. X
  1199. X  distmin = PLANET_DIST_MIN;
  1200. X  for (i=0; i<Star->numplanets; i++)  {
  1201. X      distsep = (PLANET_DIST_MAX - distmin)/(double)(Star->numplanets-i);
  1202. X      distmax = distmin + distsep;
  1203. X      dist = distmin + double_rand()*(distmax - distmin);
  1204. X      distmin = dist;
  1205. X
  1206. X      temperature = Temperature(dist, Star->temperature);
  1207. X    angle = 2.0*M_PI*double_rand() ;
  1208. X    xpos = dist * sin(angle) ;
  1209. X    ypos = dist * cos(angle) ;
  1210. X    
  1211. X    strcpy(Star->pnames[i], NextPlanetName(i)) ;
  1212. X    
  1213. X    roll = int_rand(1,100) ;
  1214. X    if ((int_rand(1,100) <= 10) || (temperature > 400))
  1215. X      {
  1216. X      type = TYPE_ASTEROID;
  1217. X      } 
  1218. X    else if ((temperature > 100) && (temperature <= 400))
  1219. X      {
  1220. X      if (roll <= 60)
  1221. X        type = TYPE_MARS;
  1222. X      else
  1223. X        type = TYPE_DESERT;
  1224. X      } 
  1225. X    else if ((temperature > 30) && (temperature <= 100)) 
  1226. X      {
  1227. X      if (roll <= 25)
  1228. X        type = TYPE_EARTH;
  1229. X      else if (roll <= 50)
  1230. X        type = TYPE_WATER;
  1231. X      else if (roll <= 80)
  1232. X        type = TYPE_FOREST;
  1233. X      else if (roll <= 90)
  1234. X        type = TYPE_DESERT;
  1235. X      else 
  1236. X        type = TYPE_MARS;
  1237. X      } 
  1238. X    else if ((temperature > -10) && (temperature <= 30))
  1239. X      {
  1240. X      if (roll <= 45)
  1241. X        type = TYPE_EARTH;
  1242. X      else if (roll <= 70)
  1243. X        type = TYPE_WATER;
  1244. X      else if (roll <= 95)
  1245. X        type = TYPE_FOREST;
  1246. X      else
  1247. X        type = TYPE_DESERT;
  1248. X      } 
  1249. X    else if ((temperature > -50) && (temperature <= -10))
  1250. X      {
  1251. X      if (roll <= 30)
  1252. X        type = TYPE_DESERT;
  1253. X      else if (roll <= 60)
  1254. X        type = TYPE_ICEBALL;
  1255. X      else if (roll <= 90)
  1256. X        type = TYPE_FOREST;
  1257. X      else
  1258. X        type = TYPE_MARS;
  1259. X      } 
  1260. X    else if ((temperature > -100) && (temperature <= -50))
  1261. X      {
  1262. X      if (roll <= 50)
  1263. X        type = TYPE_GASGIANT;
  1264. X      else if (roll <= 80)
  1265. X        type = TYPE_ICEBALL;
  1266. X      else
  1267. X        type = TYPE_MARS;
  1268. X      } 
  1269. X    else if (temperature <= -100) 
  1270. X      {
  1271. X      if (roll <= 80)
  1272. X        type = TYPE_ICEBALL;
  1273. X      else
  1274. X        type = TYPE_GASGIANT;
  1275. X      } 
  1276. X    planet = Makeplanet(dist, Star->temperature, type);
  1277. X    planet.xpos = xpos;
  1278. X    planet.ypos = ypos;
  1279. X    planet.total_resources = 0; 
  1280. X    Numtypes[type]++;
  1281. X    if (printplaninfo) {
  1282. X      printf("Planet %s: temp %d, type %s (%u)\n", Star->pnames[i],
  1283. X             planet.conditions[RTEMP], Nametypes[planet.type], planet.type);
  1284. X      printf("Position is (%1.0f,%1.0f) relative to %s; distance %1.0f.\n",
  1285. X             planet.xpos, planet.ypos, Star->name, dist);
  1286. X      printf("sect map(%dx%d):\n",planet.Maxx,planet.Maxy);
  1287. X      for (y=0; y<planet.Maxy; y++) {
  1288. X        for (x=0; x<planet.Maxx; x++) {
  1289. X          switch (Sector(planet,x,y).condition) {
  1290. X          case LAND:   putchr(CHAR_LAND);   break;
  1291. X          case SEA:    putchr(CHAR_SEA);    break;
  1292. X          case MOUNT:  putchr(CHAR_MOUNT);  break;
  1293. X          case ICE:    putchr(CHAR_ICE);    break;
  1294. X          case GAS:    putchr(CHAR_GAS);    break;
  1295. X          case DESERT: putchr(CHAR_DESERT); break;
  1296. X          case FOREST: putchr(CHAR_FOREST); break;
  1297. X          default: putchr('?'); break;
  1298. X            }
  1299. X          }
  1300. X        putchr('\n') ;
  1301. X        }
  1302. X      putchr('\n') ;
  1303. X      }
  1304. X    /* 
  1305. X     * Tabulate statistics for this star's planets. */
  1306. X    for (y=0; y<planet.Maxy; y++)
  1307. X      for (x=0; x<planet.Maxx; x++) {
  1308. X        char d = Sector(planet,x,y).condition ;
  1309. X        planet.total_resources += Sector(planet,x,y).resource ;
  1310. X        Resource[type] += Sector(planet,x,y).resource ;
  1311. X        Numsects[type][d]++ ;
  1312. X        Fertsects[type][d] += Sector(planet,x,y).fert ;
  1313. X        }
  1314. X    Star->planetpos[i] = (int)ftell(planetdata); 
  1315. X    /* posn of file-last write*/
  1316. X    planet.sectormappos = (int)ftell(sectordata); /* sector map pos */
  1317. X    fwrite(&planet,sizeof(planettype),1,planetdata); /* write planet */
  1318. X    /* write each sector row */
  1319. X    for (y=0; y < planet.Maxy; y++)
  1320. X      fwrite( &Sector(planet,0,y), 
  1321. X             sizeof(sectortype), planet.Maxx, sectordata) ;
  1322. X    }
  1323. X  return Star ;
  1324. X  }
  1325. END_OF_FILE
  1326. if test 10604 -ne `wc -c <'utils/makestar.c'`; then
  1327.     echo shar: \"'utils/makestar.c'\" unpacked with wrong size!
  1328. fi
  1329. # end of 'utils/makestar.c'
  1330. fi
  1331. if test -f 'utils/makeuniv.c' -a "${1}" != "-c" ; then 
  1332.   echo shar: Will not clobber existing file \"'utils/makeuniv.c'\"
  1333. else
  1334. echo shar: Extracting \"'utils/makeuniv.c'\" \(10236 characters\)
  1335. sed "s/^X//" >'utils/makeuniv.c' <<'END_OF_FILE'
  1336. X/* makeuniv.c -- universe creation program.
  1337. X *   Makes various required data files; calls makestar for each star desired.
  1338. X * 
  1339. X * Galactic Bloodshed, copyright (c) 1989 by Robert P. Chansky, 
  1340. X * smq@ucscb.ucsc.edu, mods by people in GB_copyright.h.
  1341. X * Restrictions in GB_copyright.h.
  1342. X */
  1343. X
  1344. X#include "GB_copyright.h"
  1345. X#define EXTERN
  1346. X#include "vars.h"
  1347. X#include "ships.h"
  1348. X#include "races.h"
  1349. X#include "power.h"    /* (for power) */
  1350. X#include <math.h>
  1351. X
  1352. X#undef malloc
  1353. X#undef realloc
  1354. X#undef free 
  1355. X/* Just in case */
  1356. X
  1357. Xextern int Temperature(double, int);
  1358. Xextern void PrintStatistics(void);
  1359. Xextern void Makeplanet_init(void);
  1360. Xextern void Makestar_init(void);
  1361. Xextern startype *Makestar(FILE *, FILE *);
  1362. Xvoid InitFile(char *, void *, int) ;
  1363. Xvoid EmptyFile(char *);
  1364. Xvoid place_star(startype *);
  1365. Xvoid produce_postscript(char *);
  1366. X
  1367. X#define DEFAULT_POSTSCRIPT_MAP_FILENAME "universe.ps"
  1368. X#define NRINGS 3
  1369. X#define RING_SPACING (10000 * (UNIVSIZE / 10000) / NRINGS)
  1370. X
  1371. Xint autoname_star = -1 ;
  1372. Xint autoname_plan = -1 ;
  1373. Xint minplanets = -1 ;
  1374. Xint maxplanets = -1 ;
  1375. Xint nstars = -1 ;
  1376. Xint planetlesschance = 0 ;
  1377. Xint printpostscript = 0 ;
  1378. Xint printplaninfo = 0 ;
  1379. Xint printstarinfo = 0 ;
  1380. X
  1381. X
  1382. Xstatic int occupied[100][100];
  1383. X
  1384. Xvoid main(int argc, char *argv[])
  1385. X{
  1386. X  FILE *stardata, *planetdata, *sectordata ;
  1387. X  char str[200] ;
  1388. X  int c, i, star, x ;
  1389. X  double att, xspeed[NUMSTARS], yspeed[NUMSTARS] ;
  1390. X  
  1391. X  /* 
  1392. X   * Initialize: */
  1393. X  srandom(getpid());
  1394. X  Bzero(Sdata);
  1395. X  
  1396. X  /*
  1397. X   * Read the arguments for values: */
  1398. X  for (i=1; i<argc; i++)
  1399. X    if (argv[i][0] != '-')
  1400. X      goto usage ;
  1401. X    else 
  1402. X      switch (argv[i][1]) {
  1403. X      case 'a': autoname_star = 1 ;  break ;
  1404. X      case 'b': autoname_plan = 1 ;  break ;
  1405. X      case 'e': planetlesschance = atoi(argv[++i]) ;  break ;
  1406. X      case 'l': minplanets = atoi(argv[++i]) ;  break ;
  1407. X      case 'm': maxplanets = atoi(argv[++i]) ;  break ;
  1408. X      case 'p': printpostscript = 1 ;  break ;
  1409. X      case 's': nstars = atoi(argv[++i]) ;  break ;
  1410. X      case 'v': printplaninfo = 1 ;  break ;
  1411. X      case 'w': printstarinfo = 1 ;  break ;
  1412. X      default:
  1413. X    printf("\n") ;
  1414. X    printf("Unknown option \"%s\".\n", argv[i]) ;
  1415. X      usage:
  1416. X    printf("\n") ;
  1417. X    printf("Usage: makeuniv [-a] [-b] [-e E] [-l MIN] [-m MAX] [-s N] [-v] [-w]\n") ;
  1418. X    printf("  -a      Autoload star names.\n") ;
  1419. X    printf("  -b      Autoload planet names.\n") ;
  1420. X    printf("  -e E    Make E%% of stars have no planets.\n") ;
  1421. X    printf("  -l MIN  Other systems will have at least MIN planets.\n") ;
  1422. X    printf("  -m MAX  Other systems will have at most  MAX planets.\n") ;
  1423. X    printf("  -p      Create postscript map file of the universe.\n") ;
  1424. X    printf("  -s S    The universe will have S stars.\n") ;
  1425. X    printf("  -v      Print info and map of planets generated.\n") ;
  1426. X    printf("  -w      Print info on stars generated.\n") ;
  1427. X    printf("\n") ;
  1428. X    exit(0) ;
  1429. X    }
  1430. X
  1431. X  /*
  1432. X   * Get values for all the switches that still don't have good values. */
  1433. X  if (autoname_star == -1) {
  1434. X    printf("\nDo you wish to use the file \"%s\" for star names? [y/n]> ",
  1435. X       STARLIST);
  1436. X    c = getchr();
  1437. X    if (c != '\n')
  1438. X      getchr();
  1439. X    autoname_star = (c=='y');
  1440. X    }
  1441. X  if (autoname_plan == -1) {
  1442. X    printf("\nDo you wish to use the file \"%s\" for planet names? [y/n]> ",
  1443. X       PLANETLIST) ;
  1444. X    c = getchr();
  1445. X    if (c != '\n')
  1446. X      getchr();
  1447. X    autoname_plan = (c=='y');
  1448. X    }
  1449. X  while ((nstars < 1) || (nstars >= NUMSTARS)) {
  1450. X    printf("Number of stars [1-%d]:", NUMSTARS-1) ;
  1451. X    scanf("%d", &nstars) ;
  1452. X    }
  1453. X  while ((minplanets <= 0) || (minplanets > MAXPLANETS)) {
  1454. X    printf("Minimum number of planets per system [1-%d]: ", MAXPLANETS) ;
  1455. X    scanf("%d", &minplanets) ;
  1456. X    }
  1457. X  while ((maxplanets < minplanets) || (maxplanets > MAXPLANETS)) {
  1458. X    printf("Maximum number of planets per system [%d-%d]: ", 
  1459. X       minplanets, MAXPLANETS) ;
  1460. X    scanf("%d", &maxplanets) ;
  1461. X    }
  1462. X
  1463. X  Makeplanet_init() ;
  1464. X  Makestar_init() ;
  1465. X  Sdata.numstars = nstars ;
  1466. X  sprintf(str, "/bin/mkdir %s", DATADIR) ;
  1467. X  system(str) ;
  1468. X  
  1469. X  if (NULL == (planetdata = fopen(PLANETDATAFL,"w+"))) {
  1470. X    printf("Unable to open planet data file \"%s\"\n", PLANETDATAFL) ;
  1471. X    exit(-1) ;
  1472. X    }
  1473. X  if (NULL == (sectordata = fopen(SECTORDATAFL,"w+"))) {
  1474. X    printf("Unable to open sector data file \"%s\"\n", SECTORDATAFL) ;
  1475. X    exit(-1) ;
  1476. X    }
  1477. X  
  1478. X  for (star=0; star<nstars; star++) 
  1479. X    {
  1480. X    Stars[star] = Makestar(planetdata, sectordata) ;
  1481. X    xspeed[star] = 0;
  1482. X    yspeed[star] = 0; 
  1483. X    }
  1484. X  fchmod(planetdata,00660);    /* change data files to group readwrite */
  1485. X  fclose(planetdata);
  1486. X  fchmod(sectordata,00660);
  1487. X  fclose(sectordata);
  1488. X  
  1489. X  /* 
  1490. X   * Try to more evenly space stars.  Essentially this is an inverse-gravity
  1491. X   * calculation: the nearer two stars are to each other, the more they
  1492. X   * repulse each other.  Several iterations of this will suffice to move all
  1493. X   * of the stars nicely apart. */
  1494. X
  1495. X
  1496. X
  1497. X
  1498. X
  1499. X
  1500. X  for (i=0; i<CREAT_UNIV_ITERAT; i++)
  1501. X    for (star=0; star<Sdata.numstars; star++) {
  1502. X      for (x=0; x<Sdata.numstars; x++)    /* star2 */
  1503. X    if (x!=star) {
  1504. X      /* find inverse of distance squared */
  1505. X      att = 10*UNIVSIZE / Distsq(Stars[star]->xpos, Stars[star]->ypos, Stars[x]->xpos, Stars[x]->ypos);
  1506. X      xspeed[star] += att * (Stars[star]->xpos - Stars[x]->xpos);
  1507. X      if (Stars[star]->xpos>UNIVSIZE || Stars[star]->xpos< -UNIVSIZE)
  1508. X        xspeed[star] *= -1;
  1509. X      yspeed[star] += att * (Stars[star]->ypos - Stars[x]->ypos);
  1510. X      if (Stars[star]->ypos>UNIVSIZE || Stars[star]->ypos< -UNIVSIZE)
  1511. X        yspeed[star] *= -1;
  1512. X      }
  1513. X      Stars[star]->xpos += xspeed[star];
  1514. X      Stars[star]->ypos += yspeed[star];
  1515. X      }
  1516. X  
  1517. X
  1518. X
  1519. X
  1520. X
  1521. X  if ((stardata = fopen(STARDATAFL,"w+"))==NULL) {
  1522. X    printf("Unable to open star data file \"%s\"\n", STARDATAFL) ;
  1523. X    exit(-1) ;
  1524. X    }
  1525. X  fwrite(&(Sdata),sizeof(Sdata),1,stardata);
  1526. X  for (star=0; star<Sdata.numstars; star++)
  1527. X    fwrite(Stars[star],sizeof(startype),1,stardata);
  1528. X  fchmod(stardata,00660);
  1529. X  fclose(stardata);
  1530. X  
  1531. X  EmptyFile(SHIPDATAFL) ;
  1532. X  EmptyFile(SHIPFREEDATAFL) ;
  1533. X  EmptyFile(COMMODDATAFL) ;
  1534. X  EmptyFile(COMMODFREEDATAFL) ;
  1535. X  EmptyFile(PLAYERDATAFL) ;
  1536. X  EmptyFile(RACEDATAFL) ;
  1537. X
  1538. X  { 
  1539. X  struct power p[MAXPLAYERS];
  1540. X  bzero((char *)p, sizeof(p));
  1541. X  InitFile(POWFL, p, sizeof(p)) ;
  1542. X  }
  1543. X  
  1544. X  { 
  1545. X  struct block p[MAXPLAYERS];
  1546. X  bzero((char *)p, sizeof(p));
  1547. X  InitFile(BLOCKDATAFL, p, sizeof(p)) ;
  1548. X  }
  1549. X  
  1550. X  /*
  1551. X   * Telegram files: directory and a file for each player. */
  1552. X  sprintf(str, "/bin/mkdir %s", TELEGRAMDIR );
  1553. X  system(str);
  1554. X  chmod(TELEGRAMDIR, 00770);
  1555. X#if 0  
  1556. X  /* Why is this not needed any more? */
  1557. X  for (i=1; i<MAXPLAYERS; i++) {
  1558. X    sprintf(str, "%s.%d", TELEGRAMFL, i );
  1559. X    EmptyFile(str) ;
  1560. X    }
  1561. X#endif
  1562. X
  1563. X  /*
  1564. X   * News files: directory and the 4 types of news. */
  1565. X  sprintf(str, "/bin/mkdir %s", NEWSDIR );
  1566. X  system(str);
  1567. X  chmod(NEWSDIR, 00770);
  1568. X  EmptyFile(DECLARATIONFL) ;
  1569. X  EmptyFile(TRANSFERFL) ;
  1570. X  EmptyFile(COMBATFL) ;
  1571. X  EmptyFile(ANNOUNCEFL) ;
  1572. X  
  1573. X  PrintStatistics() ;
  1574. X
  1575. X  if (printpostscript)
  1576. X    produce_postscript(DEFAULT_POSTSCRIPT_MAP_FILENAME) ;
  1577. X  }
  1578. X
  1579. Xvoid InitFile(char *filename, void *ptr, int len)
  1580. X{
  1581. X  FILE *f = fopen(filename, "w+") ;
  1582. X
  1583. X  if (f == NULL) {
  1584. X    printf("Unable to open \"%s\".\n", filename) ;
  1585. X    exit(-1) ;
  1586. X    }
  1587. X  fwrite(ptr, len, 1, f) ;
  1588. X  fchmod(f, 00660) ;
  1589. X  fclose(f) ;
  1590. X}
  1591. X
  1592. Xvoid EmptyFile(char *filename)
  1593. X{
  1594. X  InitFile(filename, NULL, 0) ;
  1595. X }
  1596. X
  1597. X/*
  1598. X * The procedure below was adapted from a program which is
  1599. X * Copyright: Andreas Girgensohn (andreasg@cs.colorado.edu)
  1600. X * produces a Postscript map of the universe. */
  1601. Xvoid produce_postscript(char *filename)
  1602. X{
  1603. X  int min_x, max_x, min_y, max_y, i ;
  1604. X  double scale, nscale ;
  1605. X  FILE *f = fopen(filename, "w+") ;
  1606. X
  1607. X  if (f == NULL) {
  1608. X    printf("Unable to open postscript file \"%s\".\n", filename) ;
  1609. X    return ;
  1610. X    }
  1611. X  printf("Creating postscript file..") ;
  1612. X  fflush(stdout) ;
  1613. X  min_x = max_x = Stars[0]->xpos;
  1614. X  min_y = max_y = Stars[0]->ypos;
  1615. X  for (i = 1; i < nstars; i++) {
  1616. X    if (Stars[i]->xpos < min_x)
  1617. X      min_x = Stars[i]->xpos;
  1618. X    if (Stars[i]->xpos > max_x)
  1619. X      max_x = Stars[i]->xpos;
  1620. X    if (Stars[i]->ypos < min_y)
  1621. X      min_y = Stars[i]->ypos;
  1622. X    if (Stars[i]->ypos > max_y)
  1623. X      max_y = Stars[i]->ypos;
  1624. X    }
  1625. X  /* max map size: 8.5in x 11in sheet, 0.5in borders, */
  1626. X  /* 0.5in on the right for star names */
  1627. X  /* 72 points = 1in */
  1628. X  scale = 7.0 * 72 / (max_x - min_x);
  1629. X  nscale = 10.0 * 72 / (max_y - min_y);
  1630. X  if (nscale < scale)
  1631. X    scale = nscale;
  1632. X  fprintf(f, "%%!PS-Adobe-2.0\n\n");
  1633. X  /* 0,0 is in the topleft corner */
  1634. X  fprintf(f, "0.5 72 mul 10.5 72 mul translate\n");
  1635. X  fprintf(f, "/drawcircle\n");
  1636. X  fprintf(f, "{\n");
  1637. X  fprintf(f, "  newpath 0 360 arc stroke\n");
  1638. X  fprintf(f, "}\n");
  1639. X  fprintf(f, "def\n\n");
  1640. X  fprintf(f, "/drawstar\n");
  1641. X  fprintf(f, "{\n");
  1642. X  fprintf(f, "  /starname exch def\n");
  1643. X  fprintf(f, "  /ypos exch def\n");
  1644. X  fprintf(f, "  /xpos exch def\n");
  1645. X  fprintf(f, "  xpos ypos 2 drawcircle\n");
  1646. X  fprintf(f, "  4 xpos add ypos moveto\n");
  1647. X  fprintf(f, "  starname show\n");
  1648. X  fprintf(f, "}\n");
  1649. X  fprintf(f, "def\n\n");
  1650. X  fprintf(f, "0 setlinewidth\n");
  1651. X  fprintf(f, "newpath -10 10 moveto 7.5 72 mul 10 add 10 lineto\n");
  1652. X  fprintf(f, "7.5 72 mul 10 add %d lineto -10 %d lineto closepath clip\n",
  1653. X      (int) ((min_y - max_y) * scale) - 10,
  1654. X      (int) ((min_y - max_y) * scale) - 10);
  1655. X#if 0
  1656. X  /*
  1657. X   * Print scale rings from center of universe (0,0): */
  1658. X  fprintf ("\n/Times-Bold findfont 9 scalefont setfont\n\n");
  1659. X  for (i = 1; i <= NRINGS; i++)
  1660. X    fprintf(f, "%d %d %d drawcircle\n",
  1661. X        (int) ( - min_x * scale), (int) (min_y * scale),
  1662. X        (int) (i * RING_SPACING * scale)) ;
  1663. X#endif
  1664. X  /*
  1665. X   * Print each star. */
  1666. X  fprintf(f, "\n/Times-Roman findfont 8 scalefont setfont\n\n");
  1667. X  for (i = 0; i < nstars; i++)
  1668. X    fprintf(f, "%d %d (%s) drawstar\n", 
  1669. X        (int) ((Stars[i]->xpos - min_x) * scale),
  1670. X        (int) ((min_y - Stars[i]->ypos) * scale), Stars[i]->name) ;
  1671. X  fprintf(f, "\nshowpage\n");
  1672. X  fclose(f) ;
  1673. X  printf("done\n") ;
  1674. X}
  1675. X
  1676. Xvoid place_star(startype *star)
  1677. X{
  1678. X    int found = 0, i, j;
  1679. X    while(!found) {
  1680. X    star->xpos = (double)int_rand(-UNIVSIZE, UNIVSIZE);
  1681. X    star->ypos = (double)int_rand(-UNIVSIZE, UNIVSIZE);
  1682. X        /* check to see if another star is nearby */
  1683. X    i = 100*((int)star->xpos + UNIVSIZE)/(2*UNIVSIZE);
  1684. X    j = 100*((int)star->xpos + UNIVSIZE)/(2*UNIVSIZE);
  1685. X    if(!occupied[i][j])
  1686. X        occupied[i][j] = found = 1;
  1687. X    }
  1688. X    return;
  1689. X}
  1690. END_OF_FILE
  1691. if test 10236 -ne `wc -c <'utils/makeuniv.c'`; then
  1692.     echo shar: \"'utils/makeuniv.c'\" unpacked with wrong size!
  1693. fi
  1694. # end of 'utils/makeuniv.c'
  1695. fi
  1696. echo shar: End of archive 15 \(of 21\).
  1697. cp /dev/null ark15isdone
  1698. MISSING=""
  1699. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ; do
  1700.     if test ! -f ark${I}isdone ; then
  1701.     MISSING="${MISSING} ${I}"
  1702.     fi
  1703. done
  1704. if test "${MISSING}" = "" ; then
  1705.     echo You have unpacked all 21 archives.
  1706.     echo "Now type './buildfiles.sh'"
  1707.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1708. else
  1709.     echo You still need to unpack the following archives:
  1710.     echo "        " ${MISSING}
  1711. fi
  1712. ##  End of shell archive.
  1713. exit 0
  1714.