First commit. master
authorKarynax <karynax23@yahoo.com>
Mon, 25 Mar 2013 14:41:58 +0000 (00:11 +0930)
committerKarynax <karynax23@yahoo.com>
Mon, 25 Mar 2013 14:41:58 +0000 (00:11 +0930)
389 files changed:
BUILD [new file with mode: 0644]
COPYING [new file with mode: 0644]
Makefile [new file with mode: 0644]
code/cargtool.pas [new file with mode: 0644]
code/combat.pas [new file with mode: 0644]
code/comm.pas [new file with mode: 0644]
code/comm2.pas [new file with mode: 0644]
code/crew2.pas [new file with mode: 0644]
code/crewgen.pas [new file with mode: 0644]
code/crewinfo.pas [new file with mode: 0644]
code/crewtick.pas [new file with mode: 0644]
code/data.pas [new file with mode: 0644]
code/detsound.pas [new file with mode: 0644]
code/display.pas [new file with mode: 0644]
code/emstool.pas [new file with mode: 0644]
code/ending.pas [new file with mode: 0644]
code/explore.pas [new file with mode: 0644]
code/fixnames.py [new file with mode: 0644]
code/gmouse.pas [new file with mode: 0644]
code/graphics.asm [new file with mode: 0644]
code/heapchk.pas [new file with mode: 0644]
code/info.pas [new file with mode: 0644]
code/init.pas [new file with mode: 0644]
code/install.pas [new file with mode: 0644]
code/intro.pas [new file with mode: 0644]
code/is.pas [new file with mode: 0644]
code/journey.pas [new file with mode: 0644]
code/main.pas [new file with mode: 0644]
code/modplay.pas [new file with mode: 0644]
code/mouse.asm [new file with mode: 0644]
code/mover.asm [new file with mode: 0644]
code/mover2.asm [new file with mode: 0644]
code/saveload.pas [new file with mode: 0644]
code/scroller.asm [new file with mode: 0644]
code/shipmake.pas [new file with mode: 0644]
code/sndcfg.pas [new file with mode: 0644]
code/starter.pas [new file with mode: 0644]
code/usecode.pas [new file with mode: 0644]
code/utils.pas [new file with mode: 0644]
code/utils2.pas [new file with mode: 0644]
code/version.pas [new file with mode: 0644]
code/weird.pas [new file with mode: 0644]
data/alien.cpr [new file with mode: 0644]
data/alien1.cpr [new file with mode: 0644]
data/alien10.cpr [new file with mode: 0644]
data/alien2.cpr [new file with mode: 0644]
data/alien3.cpr [new file with mode: 0644]
data/alien4.cpr [new file with mode: 0644]
data/alien5.cpr [new file with mode: 0644]
data/alien6.cpr [new file with mode: 0644]
data/alien7.cpr [new file with mode: 0644]
data/alien8.cpr [new file with mode: 0644]
data/alien9.cpr [new file with mode: 0644]
data/back1.cpr [new file with mode: 0644]
data/back10.cpr [new file with mode: 0644]
data/back11.cpr [new file with mode: 0644]
data/back2.cpr [new file with mode: 0644]
data/back3.cpr [new file with mode: 0644]
data/back4.cpr [new file with mode: 0644]
data/back5.cpr [new file with mode: 0644]
data/back6.cpr [new file with mode: 0644]
data/back7.cpr [new file with mode: 0644]
data/back8.cpr [new file with mode: 0644]
data/back9.cpr [new file with mode: 0644]
data/battle1.cpr [new file with mode: 0644]
data/cargo.cpr [new file with mode: 0644]
data/channel7.cpr [new file with mode: 0644]
data/char.cpr [new file with mode: 0644]
data/char2.cpr [new file with mode: 0644]
data/charani.cpr [new file with mode: 0644]
data/charani.dta [new file with mode: 0644]
data/charcom.cpr [new file with mode: 0644]
data/cloud.cpr [new file with mode: 0644]
data/com.cpr [new file with mode: 0644]
data/conv0001.dta [new file with mode: 0644]
data/conv0001.ind [new file with mode: 0644]
data/conv0002.dta [new file with mode: 0644]
data/conv0002.ind [new file with mode: 0644]
data/conv0003.dta [new file with mode: 0644]
data/conv0003.ind [new file with mode: 0644]
data/conv0004.dta [new file with mode: 0644]
data/conv0004.ind [new file with mode: 0644]
data/conv0005.dta [new file with mode: 0644]
data/conv0005.ind [new file with mode: 0644]
data/conv0006.dta [new file with mode: 0644]
data/conv0006.ind [new file with mode: 0644]
data/conv1000.dta [new file with mode: 0644]
data/conv1000.ind [new file with mode: 0644]
data/conv1001.dta [new file with mode: 0644]
data/conv1001.ind [new file with mode: 0644]
data/conv1002.dta [new file with mode: 0644]
data/conv1002.ind [new file with mode: 0644]
data/conv1003.dta [new file with mode: 0644]
data/conv1003.ind [new file with mode: 0644]
data/conv1004.dta [new file with mode: 0644]
data/conv1004.ind [new file with mode: 0644]
data/conv1005.dta [new file with mode: 0644]
data/conv1005.ind [new file with mode: 0644]
data/conv1006.dta [new file with mode: 0644]
data/conv1006.ind [new file with mode: 0644]
data/conv1007.dta [new file with mode: 0644]
data/conv1007.ind [new file with mode: 0644]
data/conv1008.dta [new file with mode: 0644]
data/conv1008.ind [new file with mode: 0644]
data/conv1009.dta [new file with mode: 0644]
data/conv1009.ind [new file with mode: 0644]
data/conv1010.dta [new file with mode: 0644]
data/conv1010.ind [new file with mode: 0644]
data/conv1011.dta [new file with mode: 0644]
data/conv1011.ind [new file with mode: 0644]
data/conv1100.dta [new file with mode: 0644]
data/conv1100.ind [new file with mode: 0644]
data/conv1101.dta [new file with mode: 0644]
data/conv1101.ind [new file with mode: 0644]
data/conv1102.dta [new file with mode: 0644]
data/conv1102.ind [new file with mode: 0644]
data/conv1103.dta [new file with mode: 0644]
data/conv1103.ind [new file with mode: 0644]
data/demoscr2.cpr [new file with mode: 0644]
data/demoscr3.cpr [new file with mode: 0644]
data/demoscr4.cpr [new file with mode: 0644]
data/demoscrn.cpr [new file with mode: 0644]
data/end1.cpr [new file with mode: 0644]
data/end2.cpr [new file with mode: 0644]
data/end3.cpr [new file with mode: 0644]
data/end4.cpr [new file with mode: 0644]
data/end5.cpr [new file with mode: 0644]
data/end6.cpr [new file with mode: 0644]
data/fight.cpr [new file with mode: 0644]
data/icons.vga [new file with mode: 0644]
data/image01.cpr [new file with mode: 0644]
data/image02.cpr [new file with mode: 0644]
data/image03.cpr [new file with mode: 0644]
data/image04.cpr [new file with mode: 0644]
data/image05.cpr [new file with mode: 0644]
data/image06.cpr [new file with mode: 0644]
data/image07.cpr [new file with mode: 0644]
data/image08.cpr [new file with mode: 0644]
data/image09.cpr [new file with mode: 0644]
data/image10.cpr [new file with mode: 0644]
data/image11.cpr [new file with mode: 0644]
data/image12.cpr [new file with mode: 0644]
data/image13.cpr [new file with mode: 0644]
data/image14.cpr [new file with mode: 0644]
data/image15.cpr [new file with mode: 0644]
data/image16.cpr [new file with mode: 0644]
data/image17.cpr [new file with mode: 0644]
data/image18.cpr [new file with mode: 0644]
data/image19.cpr [new file with mode: 0644]
data/image20.cpr [new file with mode: 0644]
data/image21.cpr [new file with mode: 0644]
data/image22.cpr [new file with mode: 0644]
data/image23.cpr [new file with mode: 0644]
data/image24.cpr [new file with mode: 0644]
data/image25.cpr [new file with mode: 0644]
data/image26.cpr [new file with mode: 0644]
data/image27.cpr [new file with mode: 0644]
data/image28.cpr [new file with mode: 0644]
data/image29.cpr [new file with mode: 0644]
data/image30.cpr [new file with mode: 0644]
data/image31.cpr [new file with mode: 0644]
data/image32.cpr [new file with mode: 0644]
data/intro2.cpr [new file with mode: 0644]
data/intro5.cpr [new file with mode: 0644]
data/intro6.cpr [new file with mode: 0644]
data/landform.cpr [new file with mode: 0644]
data/log.cpr [new file with mode: 0644]
data/log.dta [new file with mode: 0644]
data/main.cpr [new file with mode: 0644]
data/main.pal [new file with mode: 0644]
data/main3.cpr [new file with mode: 0644]
data/plan1.dta [new file with mode: 0644]
data/planicon.dta [new file with mode: 0644]
data/psyche.cpr [new file with mode: 0644]
data/savegame.dir [new file with mode: 0644]
data/saver.cpr [new file with mode: 0644]
data/sector.cpr [new file with mode: 0644]
data/ship1.cpr [new file with mode: 0644]
data/shippix.dta [new file with mode: 0644]
data/ships.dta [new file with mode: 0644]
data/sysname.dta [new file with mode: 0644]
data/sysset.dta [new file with mode: 0644]
data/tech1.cpr [new file with mode: 0644]
data/titles.dta [new file with mode: 0644]
data/trade.cpr [new file with mode: 0644]
data/waricon.cpr [new file with mode: 0644]
data/waricon.pal [new file with mode: 0644]
data/weapicon.dta [new file with mode: 0644]
data/weapon.dta [new file with mode: 0644]
data/world.cpr [new file with mode: 0644]
dmp/det_aria.pas [new file with mode: 0644]
dmp/det_pas.pas [new file with mode: 0644]
dmp/det_sb.pas [new file with mode: 0644]
dmp/detgus.pas [new file with mode: 0644]
dmp/dsmistub.pas [new file with mode: 0644]
dmp/emhm.pas [new file with mode: 0644]
dmp/getcpu.pas [new file with mode: 0644]
dmp/loaders.pas [new file with mode: 0644]
dmp/mcp.pas [new file with mode: 0644]
dmp/modload.pas [new file with mode: 0644]
dosbox.conf [new file with mode: 0644]
makedata/aardcon1.txt [new file with mode: 0644]
makedata/aliemake.pas [new file with mode: 0644]
makedata/alienshp.txt [new file with mode: 0644]
makedata/anom.txt [new file with mode: 0644]
makedata/artimake.pas [new file with mode: 0644]
makedata/cargmake.pas [new file with mode: 0644]
makedata/cargo.txt [new file with mode: 0644]
makedata/contact.txt [new file with mode: 0644]
makedata/conv0000.txt [new file with mode: 0644]
makedata/convmake.d [new file with mode: 0644]
makedata/creamake.pas [new file with mode: 0644]
makedata/creation.txt [new file with mode: 0644]
makedata/crew.txt [new file with mode: 0644]
makedata/crewcon1.txt [new file with mode: 0644]
makedata/crewcon2.txt [new file with mode: 0644]
makedata/crewcon3.txt [new file with mode: 0644]
makedata/crewcon4.txt [new file with mode: 0644]
makedata/crewcon5.txt [new file with mode: 0644]
makedata/crewcon6.txt [new file with mode: 0644]
makedata/crewmake.pas [new file with mode: 0644]
makedata/data.d [new file with mode: 0644]
makedata/dpahcon1.txt [new file with mode: 0644]
makedata/element.txt [new file with mode: 0644]
makedata/elemmake.pas [new file with mode: 0644]
makedata/ermicon1.txt [new file with mode: 0644]
makedata/event.txt [new file with mode: 0644]
makedata/eventmak.pas [new file with mode: 0644]
makedata/font0.cpr [new file with mode: 0644]
makedata/font0.pal [new file with mode: 0644]
makedata/getfont.pas [new file with mode: 0644]
makedata/guilcon1.txt [new file with mode: 0644]
makedata/iconcon1.txt [new file with mode: 0644]
makedata/iconmake.pas [new file with mode: 0644]
makedata/itemdata.txt [new file with mode: 0644]
makedata/iteminfo.txt [new file with mode: 0644]
makedata/itemmake.pas [new file with mode: 0644]
makedata/logmake.d [new file with mode: 0644]
makedata/logs.txt [new file with mode: 0644]
makedata/makename.pas [new file with mode: 0644]
makedata/mochcon1.txt [new file with mode: 0644]
makedata/names.txt [new file with mode: 0644]
makedata/quacon1.txt [new file with mode: 0644]
makedata/scandata.txt [new file with mode: 0644]
makedata/scanmake.pas [new file with mode: 0644]
makedata/scavcon1.txt [new file with mode: 0644]
makedata/sengcon1.txt [new file with mode: 0644]
makedata/shipmake.pas [new file with mode: 0644]
makedata/sysmake.pas [new file with mode: 0644]
makedata/tek2con1.txt [new file with mode: 0644]
makedata/tek3con1.txt [new file with mode: 0644]
makedata/tek4con1.txt [new file with mode: 0644]
makedata/tek5con1.txt [new file with mode: 0644]
makedata/template.txt [new file with mode: 0644]
makedata/titecon1.txt [new file with mode: 0644]
makedata/voidcon1.txt [new file with mode: 0644]
makedata/weapmake.pas [new file with mode: 0644]
makedata/weapon.txt [new file with mode: 0644]
makedata/weapons.txt [new file with mode: 0644]
other/evolve.txt [new file with mode: 0644]
other/itemdata.txt [new file with mode: 0644]
other/items.txt [new file with mode: 0644]
other/stuff.txt [new file with mode: 0644]
other/sysdata.txt [new file with mode: 0644]
other/xp.txt [new file with mode: 0644]
png/alien.png [new file with mode: 0644]
png/alien1.png [new file with mode: 0644]
png/alien10.png [new file with mode: 0644]
png/alien2.png [new file with mode: 0644]
png/alien3.png [new file with mode: 0644]
png/alien4.png [new file with mode: 0644]
png/alien5.png [new file with mode: 0644]
png/alien6.png [new file with mode: 0644]
png/alien7.png [new file with mode: 0644]
png/alien8.png [new file with mode: 0644]
png/alien9.png [new file with mode: 0644]
png/back01.png [new file with mode: 0644]
png/back02.png [new file with mode: 0644]
png/back03.png [new file with mode: 0644]
png/back04.png [new file with mode: 0644]
png/back05.png [new file with mode: 0644]
png/back06.png [new file with mode: 0644]
png/back07.png [new file with mode: 0644]
png/back08.png [new file with mode: 0644]
png/back09.png [new file with mode: 0644]
png/back10.png [new file with mode: 0644]
png/back11.png [new file with mode: 0644]
png/back12.png [new file with mode: 0644]
png/back13.png [new file with mode: 0644]
png/back14.png [new file with mode: 0644]
png/back15.png [new file with mode: 0644]
png/back16.png [new file with mode: 0644]
png/back17.png [new file with mode: 0644]
png/back18.png [new file with mode: 0644]
png/back19.png [new file with mode: 0644]
png/back20.png [new file with mode: 0644]
png/back21.png [new file with mode: 0644]
png/back22.png [new file with mode: 0644]
png/battle1.png [new file with mode: 0644]
png/cargo.png [new file with mode: 0644]
png/channel7.png [new file with mode: 0644]
png/char.png [new file with mode: 0644]
png/char2.png [new file with mode: 0644]
png/charani.png [new file with mode: 0644]
png/charcom.png [new file with mode: 0644]
png/cloud.png [new file with mode: 0644]
png/com.png [new file with mode: 0644]
png/end1.png [new file with mode: 0644]
png/end2.png [new file with mode: 0644]
png/end3.png [new file with mode: 0644]
png/end4.png [new file with mode: 0644]
png/end5.png [new file with mode: 0644]
png/end6.png [new file with mode: 0644]
png/fight.png [new file with mode: 0644]
png/font.png [new file with mode: 0644]
png/font0.png [new file with mode: 0644]
png/icons.png [new file with mode: 0644]
png/image01.png [new file with mode: 0644]
png/image02.png [new file with mode: 0644]
png/image03.png [new file with mode: 0644]
png/image04.png [new file with mode: 0644]
png/image05.png [new file with mode: 0644]
png/image06.png [new file with mode: 0644]
png/image07.png [new file with mode: 0644]
png/image08.png [new file with mode: 0644]
png/image09.png [new file with mode: 0644]
png/image10.png [new file with mode: 0644]
png/image11.png [new file with mode: 0644]
png/image12.png [new file with mode: 0644]
png/image13.png [new file with mode: 0644]
png/image14.png [new file with mode: 0644]
png/image15.png [new file with mode: 0644]
png/image16.png [new file with mode: 0644]
png/image17.png [new file with mode: 0644]
png/image18.png [new file with mode: 0644]
png/image19.png [new file with mode: 0644]
png/image20.png [new file with mode: 0644]
png/image21.png [new file with mode: 0644]
png/image22.png [new file with mode: 0644]
png/image23.png [new file with mode: 0644]
png/image24.png [new file with mode: 0644]
png/image25.png [new file with mode: 0644]
png/image26.png [new file with mode: 0644]
png/image27.png [new file with mode: 0644]
png/image28.png [new file with mode: 0644]
png/image29.png [new file with mode: 0644]
png/image30.png [new file with mode: 0644]
png/image31.png [new file with mode: 0644]
png/image32.png [new file with mode: 0644]
png/intro2.png [new file with mode: 0644]
png/intro5.png [new file with mode: 0644]
png/landform.png [new file with mode: 0644]
png/log.png [new file with mode: 0644]
png/main-cube.png [new file with mode: 0644]
png/main-status-bulb.png [new file with mode: 0644]
png/main.pal [new file with mode: 0644]
png/main.png [new file with mode: 0644]
png/main3.png [new file with mode: 0644]
png/mouse--char.png [new file with mode: 0644]
png/mouse--com.png [new file with mode: 0644]
png/mouse-1.png [new file with mode: 0644]
png/mouse-2.png [new file with mode: 0644]
png/mouse-3.png [new file with mode: 0644]
png/planet-icons.png [new file with mode: 0644]
png/planicon.png [new file with mode: 0644]
png/psyche.png [new file with mode: 0644]
png/saver.png [new file with mode: 0644]
png/sector.png [new file with mode: 0644]
png/shield-icons.png [new file with mode: 0644]
png/ship1.png [new file with mode: 0644]
png/shippart.png [new file with mode: 0644]
png/tech1.png [new file with mode: 0644]
png/trade.png [new file with mode: 0644]
png/waricon.png [new file with mode: 0644]
png/weapon-icons.png [new file with mode: 0644]
png/world.png [new file with mode: 0644]
sound/EXPLODE1.SAM [new file with mode: 0644]
sound/EXPLODE2.SAM [new file with mode: 0644]
sound/GUN1.SAM [new file with mode: 0644]
sound/GUN4.SAM [new file with mode: 0644]
sound/LASER1.SAM [new file with mode: 0644]
sound/LASER2.SAM [new file with mode: 0644]
sound/LASER3.SAM [new file with mode: 0644]
sound/LASER4.SAM [new file with mode: 0644]
sound/LASER5.SAM [new file with mode: 0644]
sound/LASER6.SAM [new file with mode: 0644]
sound/LASER7.SAM [new file with mode: 0644]
todo.txt [new file with mode: 0644]
version.txt [new file with mode: 0644]

diff --git a/BUILD b/BUILD
new file mode 100644 (file)
index 0000000..2afebb4
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,29 @@
+Software required to build:
+
+       Borland Pascal 7 is requird to build the game and some tools used to create data files.
+
+       The Digital Mars D compiler is required to the conversation and log conversion tools.
+               http://digitalmars.com/d/1.0/index.html
+
+       Borland's BGI Toolkit is required for VGA256.BGI
+
+       Python is required for the fixnames.py script. This converts all files in a directory in lowercase.
+
+Wine/DOSBox setup:
+       The Makefile assumes that Borland Pascal has been installed to F:\BP and Ironseed is placed in S:\IRONSEED
+
+       The command "sudo echo 0 > /proc/sys/vm/mmap_min_addr" may be required to run DOS executables under Wine. Newer versions of Wine may invoke DOSBox execute the command.
+
+
+Borland Pascal 7 setup:
+       The directories use in Borland Pascal need to be configured.
+       Run BP and in the menu "Options -> Directories" configure the directories like below.
+               EXE & TPU directory:  s:\ironseed\code
+               Include directories:  s:\ironseed\code;s:\ironseed\dmp
+               Unit directories:     s:\ironseed\code;s:\ironseed\dmp;f:\bp\units;f:\bp\winunits
+               Object directories:   s:\ironseed\code;s:\ironseed\dmp
+               Resource directories: f:\bp\units;
+
+BGI Toolkit:
+       VGA256.BGI should be extracted from the toolkit. It should be then converted to a .OBJ file with BINOBJ.EXE included with Borland Pascal.
+       VGA256.OBJ should be place in ironseed/code
\ No newline at end of file
diff --git a/COPYING b/COPYING
new file mode 100644 (file)
index 0000000..94a9ed0
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,674 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    <program>  Copyright (C) <year>  <name of author>
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..3f61619
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,195 @@
+
+export WINEPREFIX=/home/xen/.wine-ironseed/
+WINE=wine
+
+FIXNAMES=python code/fixnames.py
+
+DMPSRC=$(shell find dmp -name "*.pas")
+MAINSRC=$(shell find code -name "*.pas") $(DMPSRC)
+CREWGENSRC=code/crewgen.pas code/data.pas code/gmouse.pas code/saveload.pas code/display.pas code/utils.pas code/modplay.pas $(DMPSRC)
+INTROSRC=code/intro.pas code/version.pas code/gmouse.pas code/modplay.pas $(DMPSRC)
+ISSRC=code/is.pas
+
+TPC=$(WINE) f:/bp/bin/tpc.exe /Tf:\\bp\\bin
+TPCFLAGS=/B /Q /M /DUSE_EMS /L /GD /\$$N+ /\$$G+ /\$$S- /\$$I-
+TPCTOOLFLAGS=/B /Q /M /DUSE_EMS /L /GD /\$$N+ /\$$G+ /\$$S- /\$$I+
+# /Ecode /Ocode /Udmp /Idmp
+
+TASM=$(WINE) f:/bp/bin/tasm.exe 
+
+CREWCONVS=data/conv0001.dta data/conv0002.dta data/conv0003.dta data/conv0004.dta data/conv0005.dta data/conv0006.dta
+RACECONVS=data/conv1001.dta data/conv1002.dta data/conv1003.dta data/conv1004.dta data/conv1005.dta data/conv1006.dta data/conv1007.dta data/conv1008.dta data/conv1009.dta data/conv1010.dta data/conv1011.dta
+SPECCONVS=data/conv1100.dta data/conv1101.dta data/conv1102.dta data/conv1103.dta
+all: convmake logmake main.exe crewgen.exe intro.exe detsound.exe is.exe $(RACECONVS) $(SPECCONVS) $(CREWCONVS) data/log.dta datafiles # sndcfg.exe
+
+convmake: makedata/convmake.d makedata/data.d
+       dmd makedata/convmake.d makedata/data.d
+
+logmake: makedata/logmake.d makedata/data.d
+       dmd makedata/logmake.d makedata/data.d
+
+data/conv0001.dta: makedata/crewcon1.txt convmake
+       ./convmake makedata/crewcon1.txt data/conv0001
+data/conv0002.dta: makedata/crewcon2.txt convmake
+       ./convmake makedata/crewcon2.txt data/conv0002
+data/conv0003.dta: makedata/crewcon3.txt convmake
+       ./convmake makedata/crewcon3.txt data/conv0003
+data/conv0004.dta: makedata/crewcon4.txt convmake
+       ./convmake makedata/crewcon4.txt data/conv0004
+data/conv0005.dta: makedata/crewcon5.txt convmake
+       ./convmake makedata/crewcon5.txt data/conv0005
+data/conv0006.dta: makedata/crewcon6.txt convmake
+       ./convmake makedata/crewcon6.txt data/conv0006
+
+data/conv1001.dta: makedata/sengcon1.txt convmake
+       ./convmake makedata/sengcon1.txt data/conv1001
+data/conv1002.dta: makedata/dpahcon1.txt convmake
+       ./convmake makedata/dpahcon1.txt data/conv1002
+data/conv1003.dta: makedata/aardcon1.txt convmake
+       ./convmake makedata/aardcon1.txt data/conv1003
+data/conv1004.dta: makedata/ermicon1.txt convmake
+       ./convmake makedata/ermicon1.txt data/conv1004
+data/conv1005.dta: makedata/titecon1.txt convmake
+       ./convmake makedata/titecon1.txt data/conv1005
+data/conv1006.dta: makedata/quacon1.txt convmake
+       ./convmake makedata/quacon1.txt  data/conv1006
+data/conv1007.dta: makedata/scavcon1.txt convmake
+       ./convmake makedata/scavcon1.txt data/conv1007
+data/conv1008.dta: makedata/iconcon1.txt convmake
+       ./convmake makedata/iconcon1.txt data/conv1008
+data/conv1009.dta: makedata/guilcon1.txt convmake
+       ./convmake makedata/guilcon1.txt data/conv1009
+data/conv1010.dta: makedata/mochcon1.txt convmake
+       ./convmake makedata/mochcon1.txt data/conv1010
+data/conv1011.dta: makedata/voidcon1.txt convmake
+       ./convmake makedata/voidcon1.txt data/conv1011
+data/conv1100.dta: makedata/tek2con1.txt convmake
+       ./convmake makedata/tek2con1.txt data/conv1100
+data/conv1101.dta: makedata/tek3con1.txt convmake
+       ./convmake makedata/tek3con1.txt data/conv1101
+data/conv1102.dta: makedata/tek4con1.txt convmake
+       ./convmake makedata/tek4con1.txt data/conv1102
+data/conv1103.dta: makedata/tek5con1.txt convmake
+       ./convmake makedata/tek5con1.txt data/conv1103
+
+data/log.dta: makedata/logs.txt logmake
+       ./logmake makedata/logs.txt data/titles.dta data/log.dta 
+
+# /CD /$$N+ /$$G+ /$$S- /$$I- 
+main.exe: $(MAINSRC) code/mover.obj code/vga256.obj
+       $(TPC) $(TPCFLAGS) code\\main.pas #| linefix
+       $(FIXNAMES) code
+       cat code/main.exe code/main.ovr > main.exe
+       touch main.exe --reference=code/main.exe
+
+crewgen.exe: $(CREWGENSRC) code/mover.obj code/vga256.obj
+       $(TPC) $(TPCFLAGS) code\\crewgen.pas #| linefix
+       $(FIXNAMES) code
+       cp code/crewgen.exe ./crewgen.exe
+
+intro.exe: $(INTROSRC) code/scroller.obj code/vga256.obj
+       $(TPC) $(TPCFLAGS) code\\intro.pas #| linefix
+       $(FIXNAMES) code
+       cp code/intro.exe ./intro.exe
+
+is.exe: $(ISSRC)
+       $(TPC) $(TPCFLAGS) code\\is.pas #| linefix
+       $(FIXNAMES) code
+       cp code/is.exe ./is.exe
+
+sndcfg.exe: code/sndcfg.pas #makedata/win.pas
+       $(TPC) $(TPCFLAGS) code\\sndcfg.pas #| linefix
+       $(FIXNAMES) code
+       cp code/sndcfg.exe ./sndcfg.exe
+
+detsound.exe: code/detsound.pas
+       $(TPC) $(TPCFLAGS) code\\detsound.pas #| linefix
+       $(FIXNAMES) code
+       cp code/detsound.exe ./detsound.exe
+
+code/graphics.obj: code/graphics.asm
+       $(TASM) code\\graphics.asm code\\
+       $(FIXNAMES) code
+code/mouse.obj: code/mouse.asm
+       $(TASM) code\\mouse.asm code\\
+       $(FIXNAMES) code
+code/mover.obj: code/mover.asm
+       $(TASM) code\\mover.asm code\\
+       $(FIXNAMES) code
+code/mover2.obj: code/mover2.asm
+       $(TASM) code\\mover2.asm code\\
+       $(FIXNAMES) code
+code/scroller.obj: code/scroller.asm
+       $(TASM) code\\scroller.asm code\\
+       $(FIXNAMES) code
+
+clean:
+       rm -f code/*.tpu code/*.exe code/*.ovr code/*.map
+       rm -f code/graphics.obj code/mourse.obj code/mover.obj code/mover2.obj code/scroller.obj
+       rm -f main.exe crewgen.exe intro.exe
+       rm -f convmake logmake
+       rm -f data/iteminfo.dta data/creation.dta data/cargo.dta data/scan.dta data/sysnames.dta data/contact0.dta data/crew.dta data/artifact.dta data/elements.dta data/event.dta
+
+code/itemmake.exe: makedata/itemmake.pas
+       $(TPC) $(TPCTOOLFLAGS) makedata\\itemmake.pas #| linefix
+       $(FIXNAMES) code
+code/creamake.exe: makedata/creamake.pas
+       $(TPC) $(TPCTOOLFLAGS) makedata\\creamake.pas #| linefix
+       $(FIXNAMES) code
+code/cargmake.exe: makedata/cargmake.pas
+       $(TPC) $(TPCTOOLFLAGS) makedata\\cargmake.pas #| linefix
+       $(FIXNAMES) code
+code/scanmake.exe: makedata/scanmake.pas
+       $(TPC) $(TPCTOOLFLAGS) makedata\\scanmake.pas #| linefix
+       $(FIXNAMES) code
+code/sysmake.exe: makedata/sysmake.pas
+       $(TPC) $(TPCTOOLFLAGS) makedata\\sysmake.pas #| linefix
+       $(FIXNAMES) code
+code/aliemake.exe: makedata/aliemake.pas
+       $(TPC) $(TPCTOOLFLAGS) makedata\\aliemake.pas #| linefix
+       $(FIXNAMES) code
+code/crewmake.exe: makedata/crewmake.pas
+       $(TPC) $(TPCTOOLFLAGS) makedata\\crewmake.pas #| linefix
+       $(FIXNAMES) code
+code/artimake.exe: makedata/artimake.pas
+       $(TPC) $(TPCTOOLFLAGS) makedata\\artimake.pas #| linefix
+       $(FIXNAMES) code
+code/elemmake.exe: makedata/elemmake.pas
+       $(TPC) $(TPCTOOLFLAGS) makedata\\elemmake.pas #| linefix
+       $(FIXNAMES) code
+code/eventmak.exe: makedata/eventmak.pas
+       $(TPC) $(TPCTOOLFLAGS) makedata\\eventmak.pas #| linefix
+       $(FIXNAMES) code
+
+data/iteminfo.dta: code/itemmake.exe makedata/iteminfo.txt
+       $(WINE) code/itemmake.exe
+       $(FIXNAMES) code data
+data/creation.dta: code/creamake.exe makedata/creation.txt
+       $(WINE) code/creamake.exe
+       $(FIXNAMES) code data other
+data/cargo.dta: code/cargmake.exe makedata/cargo.txt
+       $(WINE) code/cargmake.exe
+       $(FIXNAMES) code data
+data/scan.dta: code/scanmake.exe makedata/scandata.txt
+       $(WINE) code/scanmake.exe
+       $(FIXNAMES) code data
+data/sysname.dta: code/sysmake.exe makedata/names.txt
+       $(WINE) code/sysmake.exe
+       $(FIXNAMES) code data
+data/contact0.dta: code/aliemake.exe makedata/contact.txt
+       $(WINE) code/aliemake.exe
+       $(FIXNAMES) code data
+data/crew.dta: code/crewmake.exe makedata/crew.txt
+       $(WINE) code/crewmake.exe
+       $(FIXNAMES) code data
+data/artifact.dta: code/artimake.exe makedata/anom.txt
+       $(WINE) code/artimake.exe
+       $(FIXNAMES) code data
+data/elements.dta: code/elemmake.exe makedata/element.txt
+       $(WINE) code/elemmake.exe
+       $(FIXNAMES) code data
+data/event.dta: code/eventmak.exe makedata/event.txt
+       $(WINE) code/eventmak.exe
+       $(FIXNAMES) code data
+
+datafiles: data/iteminfo.dta data/creation.dta data/cargo.dta data/scan.dta data/sysname.dta data/contact0.dta data/crew.dta data/artifact.dta data/elements.dta data/event.dta
diff --git a/code/cargtool.pas b/code/cargtool.pas
new file mode 100644 (file)
index 0000000..62f3fdf
--- /dev/null
@@ -0,0 +1,2128 @@
+unit cargtool;\r
+(********************************************************************\r
+    This file is part of Ironseed.\r
+\r
+    Ironseed is free software: you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation, either version 3 of the License, or\r
+    (at your option) any later version.\r
+\r
+    Ironseed is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with Ironseed.  If not, see <http://www.gnu.org/licenses/>.\r
+********************************************************************)\r
+\r
+{***************************\r
+   Cargo/Creation unit for IronSeed\r
+\r
+   Channel 7\r
+   Destiny: Virtual\r
+\r
+\r
+   Copyright 1994\r
+\r
+***************************}\r
+\r
+{$O+}\r
+\r
+interface\r
+\r
+procedure inventory;\r
+procedure creation;\r
+function StartBuild(background : Boolean; root, item, team : Integer) :Integer;\r
+\r
+implementation\r
+\r
+uses crt, data, gmouse, utils, weird, utils2, saveload, modplay, journey,\r
+ display, usecode,heapchk;\r
+\r
+type\r
+ cargobuttontype= array[110..126,92..228] of byte;\r
+ iteminfotype=\r
+  record\r
+   index: integer;\r
+   info: array[0..3] of string[28];\r
+  end;\r
+var\r
+ drawit,qmode,colorcode                                            : boolean;\r
+ i,j,a,b,cargoindex,cargomode,viewteam,maxcreation,lastinfo : integer;\r
+   teamjob                                                 : integer;\r
+ cargobuttons                                              : ^cargobuttontype;\r
+ filters                                                   : array[1..3] of byte;\r
+ filters2                                                  : array[1..4] of byte;\r
+ createinfo                                                : ^createarray;\r
+ iteminfo                                                  : ^iteminfotype;\r
+   res2cargo                                               : array[1..250] of Integer;\r
+   history                                                 : array[1..32] of Integer;\r
+   historyindex                                                    : Integer;\r
+                                                            \r
+function GetBuildTime(item : Integer):Integer;\r
+var\r
+   i : Integer;\r
+begin\r
+   for i:= 1 to maxcargo do\r
+      if cargo[i].index = item then\r
+      begin\r
+        GetBuildTime := bldcargo[i] * 100;\r
+        exit;\r
+      end;\r
+end;\r
+\r
+function StartBuild(background : Boolean; root, item, team : Integer) :Integer;\r
+var\r
+   i, j, k : Integer;\r
+begin\r
+   i := 1;\r
+   while (i <= maxcargo) and (cargo[i].index <> item) do inc(i);\r
+   if i > maxcargo then {doesn't exist!}\r
+   begin\r
+      StartBuild := -2;\r
+      exit;\r
+   end;\r
+   if prtcargo[i,1] = 0 then {can't be assembled}\r
+   begin\r
+      StartBuild := 0;\r
+      exit;\r
+   end;\r
+   if (item = 3021) and (not chevent(18)) then {thermoplast can only be made after it's discovery}\r
+   begin\r
+      StartBuild := -3;\r
+      exit;\r
+   end;\r
+   for j := 1 to 6 do {high enough level?}\r
+      if lvlcargo[i,j] > ship.crew[j].level then\r
+      begin\r
+        StartBuild := -1;\r
+        exit;\r
+      end;\r
+   k := 1; {how many of the first part are needed?}\r
+   for j := 2 to 3 do\r
+      if prtcargo[i,1] = prtcargo[i,j] then\r
+        inc(k);\r
+   if InCargo(prtcargo[i,1]) < k then {check first part}\r
+   begin\r
+      if prtcargo[i,1] = item then\r
+        StartBuild := 0 {stop infinite recursion}\r
+      else\r
+        StartBuild := StartBuild(background, root, prtcargo[i,1], team);\r
+      exit;\r
+   end;\r
+   for j := 2 to 3 do\r
+      if InCargo(prtcargo[i,j]) < 1 then\r
+      begin\r
+        if prtcargo[i,j] = item then\r
+           StartBuild := 0 {stop infinite recursion}\r
+        else\r
+           StartBuild := StartBuild(background, root, prtcargo[i,j], team);\r
+        exit;\r
+      end;\r
+   ship.engrteam[team].job := item;\r
+   ship.engrteam[team].extra := root;\r
+   ship.engrteam[team].jobtype := 3;\r
+   ship.engrteam[team].timeleft := GetBuildTime(item);\r
+   for j := 1 to 3 do\r
+      RemoveCargo(prtcargo[i,j]);\r
+   RebuildCargoReserve;\r
+   StartBuild := 1;\r
+   for j := 1 to 6 do\r
+      addxp(j, lvlcargo[i,j], ord(not background));\r
+   teamjob := 0;\r
+end;\r
+\r
+function CheckBuildSubStock(item : Integer) :Integer;\r
+var\r
+   i, j, k, l : Integer;\r
+begin\r
+   i := InCargoIndex(item);\r
+   if (i <> 0) and (ship.numcargo[i] - rescargo[i] - res2cargo[i] > 0) then\r
+   begin {in stock}\r
+      inc(res2cargo[i]);\r
+      CheckBuildSubStock := 1;\r
+      exit;\r
+   end;\r
+   i := 1;\r
+   while (i <= maxcargo) and (cargo[i].index <> item) do inc(i);\r
+   if i > maxcargo then {doesn't exist!}\r
+   begin\r
+      CheckBuildSubStock := -2;\r
+      exit;\r
+   end;\r
+   for j := 1 to 6 do {high enough level?}\r
+      if lvlcargo[i,j] > ship.crew[j].level then\r
+      begin\r
+        CheckBuildSubStock := -1;\r
+        exit;\r
+      end;\r
+   if prtcargo[i,j] = 0 then\r
+   begin\r
+      CheckBuildSubStock := 0;\r
+      exit;\r
+   end;\r
+   l := 2;\r
+   for j := 1 to 3 do\r
+   begin\r
+      if prtcargo[i,j] = item then\r
+        k := 0 {stop infinite recursion}\r
+      else\r
+        k := CheckBuildSubStock(prtcargo[i,j]);\r
+      case k of\r
+       -2 : l := -2;\r
+       -1 : if l > -1 then l := -1;\r
+       0  : if l > 0 then l := 0;\r
+       {1..2: donothing;}\r
+      end;\r
+   end;\r
+   CheckBuildSubStock := l;\r
+end;\r
+\r
+function CheckBuildStock(item : Integer):Integer;\r
+var\r
+   i, j, k, l : Integer;\r
+begin\r
+   for i := 1 to 250 do\r
+      res2cargo[i] := 0;\r
+   i := 1;\r
+   while (i <= maxcargo) and (cargo[i].index <> item) do inc(i);\r
+   if i > maxcargo then {doesn't exist!}\r
+   begin\r
+      CheckBuildStock := -2;\r
+      exit;\r
+   end;\r
+   if prtcargo[i, 1] = 0 then {not a buildable item}\r
+      CheckBuildStock := -2;\r
+   for j := 1 to 6 do {high enough level?}\r
+      if lvlcargo[i,j] > ship.crew[j].level then\r
+      begin\r
+        CheckBuildStock := -1;\r
+        exit;\r
+      end;\r
+   l := 0;\r
+   for j := 1 to 3 do\r
+   begin\r
+      k := CheckBuildSubStock(prtcargo[i,j]);\r
+      case k of\r
+       -2    : l := -2;\r
+       -1..0: l := l or 0;\r
+       1     : l := l or (1 shl (j + j - 2));\r
+       2     : l := l or (2 shl (j + j - 2));\r
+       {1..2: donothing;}\r
+      end;\r
+   end;\r
+   CheckBuildStock := l;\r
+end;\r
+\r
+procedure HistoryClear;\r
+var\r
+   i : Integer;\r
+begin\r
+   for i := 1 to 32 do\r
+      History[i] := 0;\r
+   HistoryIndex := 0;\r
+end; { HistoryClear }\r
+\r
+procedure HistoryPush(index : Integer);\r
+var\r
+   i : Integer;\r
+begin\r
+   if HistoryIndex >= 32 then\r
+   begin\r
+      for i := 1 to 31 do\r
+        History[i] := History[i + 1];\r
+      History[32] := index;\r
+   end else begin\r
+      inc(HistoryIndex);\r
+      History[HistoryIndex] := index;\r
+   end;\r
+end; { HistoryAdd }\r
+\r
+function HistoryPop: Integer;\r
+begin\r
+   if HistoryIndex <= 0 then\r
+   begin\r
+      HistoryPop := 0;\r
+      exit;\r
+   end;\r
+   HistoryPop := History[HistoryIndex];\r
+   dec(HistoryIndex);\r
+end; { HistoryPop }\r
+\r
+procedure opendoors;\r
+begin\r
+   if ship.options[6]=0 then\r
+   begin\r
+      fadestep(1);\r
+      for i:=20 to 130 do\r
+        fillchar(screen[i,90],144,0);\r
+      for i:=110 to 126 do\r
+        mymove(cargobuttons^[i,92],screen[i,92],34);\r
+   end\r
+   else\r
+      for a:=0 to 109 do\r
+      begin\r
+        fadestep(1);\r
+        for i:=20 to 130-a do\r
+           mymove(screen[i+1,90],screen[i,90],36);\r
+        if ((131-a)<127) and ((131-a)>109) then\r
+           mymove(cargobuttons^[131-a,92],screen[131-a,92],34);\r
+      end;\r
+   plainfadearea(38,78,40,82,-12);\r
+   plainfadearea(44,78,46,82,12);\r
+end;\r
+\r
+procedure closedoors;\r
+var temp: pscreentype;\r
+begin\r
+ if ship.options[6]=0 then exit;\r
+ mousehide;\r
+ new(temp);\r
+ loadscreen('data\cargo',temp);\r
+ for i:=110 to 126 do\r
+  fillchar(temp^[i,94],133,0);\r
+ for a:=1 to 110 do\r
+  for i:=20 to 20+a do\r
+   mymove(temp^[110-a+i,90],screen[i,90],36);\r
+ dispose(temp);\r
+ mouseshow;\r
+ plainfadearea(38,78,40,82,12);\r
+ plainfadearea(44,78,46,82,-12);\r
+end;\r
+\r
+procedure newcursor(start: integer);\r
+var finished: boolean;\r
+begin\r
+ cargoindex:=start;\r
+ finished:=false;\r
+ repeat\r
+  inc(cargoindex);\r
+  case ship.cargo[cargoindex] of\r
+   1000..1499: if filters2[1]=1 then finished:=true;\r
+   1500..1999: if filters2[2]=1 then finished:=true;\r
+   2000..3999: if filters2[4]=1 then finished:=true;\r
+   4000..5999: if filters2[3]=1 then finished:=true;\r
+   6000..6999: if filters2[4]=1 then finished:=true;\r
+  end;\r
+ until (finished) or (cargoindex=251);\r
+end;\r
+\r
+procedure revnewcursor(start: integer);\r
+var finished: boolean;\r
+begin\r
+ cargoindex:=start;\r
+ finished:=false;\r
+ repeat\r
+  dec(cargoindex);\r
+  case ship.cargo[cargoindex] of\r
+   1000..1499: if filters2[1]=1 then finished:=true else dec(cargoindex);\r
+   1500..1999: if filters2[2]=1 then finished:=true else dec(cargoindex);\r
+   2000..3999,6000..6999: if filters2[4]=1 then finished:=true else dec(cargoindex);\r
+   4000..5999: if filters2[3]=1 then finished:=true else dec(cargoindex);\r
+  end;\r
+ until (finished) or (cargoindex<1);\r
+end;\r
+\r
+procedure drawfilters;\r
+var a,b: integer;\r
+begin\r
+ for a:=1 to 2 do\r
+  for b:=0 to 1 do\r
+   for i:=72+a*5 to 74+a*5 do\r
+    for j:=269+b*9 to 276+b*9 do\r
+     screen[i,j]:=48+filters2[a+b*2]*8;\r
+end;\r
+\r
+procedure readydata;\r
+begin\r
+   mousehide;\r
+   {compressfile(tempdir+'\current',@screen);}\r
+   quicksavescreen(tempdir+'\current',@screen, true);\r
+   {fading;}\r
+   fadefull(-8, 20);\r
+   playmod(true,'sound\cargo.mod');\r
+   loadscreen('data\cargo',@screen);\r
+   new(cargobuttons);\r
+   for i:=110 to 126 do\r
+   begin\r
+      mymove(screen[i,92],cargobuttons^[i,92],34);\r
+      fillchar(screen[i,94],133,0);\r
+   end;\r
+   plainfadearea(38,78,40,82,12);\r
+   drawfilters;\r
+   {fadein;}\r
+   opendoors;\r
+   dispose(cargobuttons);\r
+   mouseshow;\r
+   done:=false;\r
+   newcursor(0);\r
+   cargomode:=0;\r
+   lightindex:=232;\r
+   bkcolor:=0;\r
+   oldt1:=t1;\r
+end;\r
+\r
+procedure checklist(down: boolean);\r
+var str1: string[3];\r
+var str2: string[3];\r
+begin\r
+   str(rescargo[x]:3,str2);\r
+ case ship.cargo[x] of\r
+            0: ;\r
+   1000..1499: if filters2[1]=1 then\r
+                begin\r
+                 if down then dec(y) else inc(y);\r
+                 str(ship.numcargo[x]:3,str1);\r
+                 j:=1;\r
+                 while cargo[j].index<>ship.cargo[x] do inc(j);\r
+                 printxy(96-10,16+y*6,str1+'('+str2+')'+cargo[j].name);\r
+                end;\r
+   1500..1999: if filters2[2]=1 then\r
+                begin\r
+                 if down then dec(y) else inc(y);\r
+                 str(ship.numcargo[x]:3,str1);\r
+                 j:=1;\r
+                 while cargo[j].index<>ship.cargo[x] do inc(j);\r
+                 printxy(96-10,16+y*6,str1+'('+str2+')'+cargo[j].name);\r
+                end;\r
+   2000..3999: if filters2[4]=1 then\r
+                begin\r
+                 if down then dec(y) else inc(y);\r
+                 str(ship.numcargo[x]:3,str1);\r
+                 j:=1;\r
+                 while cargo[j].index<>ship.cargo[x] do inc(j);\r
+                 printxy(96-10,16+y*6,str1+'('+str2+')'+cargo[j].name);\r
+                end;\r
+   4000..5999: if filters2[3]=1 then\r
+                begin\r
+                 if down then dec(y) else inc(y);\r
+                 str(ship.numcargo[x]:3,str1);\r
+                 j:=1;\r
+                 while cargo[j].index<>ship.cargo[x] do inc(j);\r
+                 printxy(96-10,16+y*6,str1+'('+str2+')'+cargo[j].name);\r
+                end;\r
+   6000..6999: if filters2[4]=1 then\r
+                begin\r
+                 if down then dec(y) else inc(y);\r
+                 getartifactname(ship.cargo[x]);\r
+                 str(ship.numcargo[x]:3,str1);\r
+                 printxy(96-10,16+y*6,str1+'     '+cargo[maxcargo].name);\r
+                end;\r
+  end;\r
+end;\r
+\r
+procedure displaylist;\r
+begin\r
+ if ship.cargo[cargoindex]=0 then\r
+  begin\r
+   newcursor(cargoindex);\r
+   if cargoindex=251 then revnewcursor(cargoindex);\r
+  end;\r
+ tcolor:=28;\r
+ bkcolor:=0;\r
+ x:=cargoindex-1;\r
+ mousehide;\r
+ y:=7;\r
+ repeat\r
+  checklist(true);\r
+  dec(x);\r
+ until (y=1) or (x<1);\r
+ if y>1 then\r
+  for i:=23 to 16+y*6 do\r
+   fillchar(screen[i,92],133,0);\r
+ bkcolor:=6;\r
+ x:=cargoindex;\r
+ y:=6;\r
+ repeat\r
+  checklist(false);\r
+  bkcolor:=0;\r
+  inc(x);\r
+ until (y=14) or (x>251);\r
+ if y<14 then\r
+  for i:=23+y*6 to 106 do\r
+   fillchar(screen[i,92],133,0);\r
+ mouseshow;\r
+end;\r
+\r
+procedure displayinfo;\r
+var s: string[9];\r
+    draw: boolean;\r
+begin\r
+ if ship.cargo[cargoindex]=0 then\r
+  begin\r
+   newcursor(cargoindex);\r
+   if cargoindex=251 then newcursor(0);\r
+  end;\r
+ if cargoindex=0 then exit;\r
+ x:=cargoindex;\r
+ tcolor:=28;\r
+ bkcolor:=6;\r
+ y:=0;\r
+ mousehide;\r
+ repeat\r
+  while (x<251) and (ship.cargo[x]=0) do inc(x);\r
+  draw:=false;\r
+  case ship.cargo[x] of\r
+   1000..1499: if filters2[1]=1 then draw:=true;\r
+   1500..1999: if filters2[2]=1 then draw:=true;\r
+   2000..3999,6000..6999: if filters2[4]=1 then draw:=true;\r
+   4000..5999: if filters2[3]=1 then draw:=true;\r
+  end;\r
+  if (x<251) and (draw) then\r
+   begin\r
+    if ship.cargo[x]>6000 then\r
+     begin\r
+      j:=maxcargo;\r
+      getartifactname(ship.cargo[x]);\r
+     end\r
+    else\r
+     begin\r
+      j:=1;\r
+      while ship.cargo[x]<>cargo[j].index do inc(j);\r
+     end;\r
+    inc(y);\r
+    printxy(92,2+y*20,cargo[j].name);\r
+    if y>0 then bkcolor:=0;\r
+    case ship.cargo[x] of\r
+     1000..1499: s:='Weapon   ';\r
+     1500..1999: s:='Shield   ';\r
+     2000..2999: s:='Device   ';\r
+     3000..3999: s:='Component';\r
+     4000..5999: s:='Material ';\r
+     6000..6999: s:='Artifact ';\r
+     else s:='         ';\r
+    end;\r
+    printxy(100,8+y*20,'Type: '+s);\r
+    x1:=cargo[j].size/10;\r
+    str(x1:7:1,s);\r
+    printxy(100,14+y*20,'Size:'+s);\r
+    str(ship.numcargo[x]:3,s);\r
+    printxy(175,14+y*20,'Num:'+s);\r
+   end;\r
+  inc(x);\r
+ until (y=4) or (x>250);\r
+ if y<4 then\r
+  for i:=22+y*20 to 106 do\r
+   fillchar(screen[i,92],133,0);\r
+ mouseshow;\r
+end;\r
+\r
+function request(s: string; alt,text: integer): integer;\r
+type\r
+ scrtype=array[40..140,74..245] of byte;\r
+var\r
+ cursor,lastx,lasty,result: integer;\r
+ tempscr: ^scrtype;\r
+ done: boolean;\r
+\r
+ procedure undocursor2;\r
+ begin\r
+  case cursor of\r
+   0: exit;\r
+   1: plainfadearea(78,78,128,92,-3);\r
+   2: plainfadearea(135,78,185,92,-3);\r
+   3: plainfadearea(192,78,242,92,-3);\r
+  end;\r
+ end;\r
+\r
+ procedure drawcursor2;\r
+ begin\r
+  case cursor of\r
+   0: exit;\r
+   1: plainfadearea(78,78,128,92,3);\r
+   2: plainfadearea(135,78,185,92,3);\r
+   3: plainfadearea(192,78,242,92,3);\r
+  end;\r
+ end;\r
+\r
+ procedure processkey2;\r
+ var ans: char;\r
+ begin\r
+  undocursor2;\r
+  ans:=readkey;\r
+  case upcase(ans) of\r
+    #0:begin\r
+        ans:=readkey;\r
+        case ans of\r
+         #75,#77:if cursor=1 then cursor:=2 else cursor:=1;\r
+        end;\r
+       end;\r
+   #13:if cursor<>0 then done:=true;\r
+   #27: begin\r
+         cursor:=4;\r
+         done:=true;\r
+        end;\r
+   'A': begin\r
+         cursor:=1;\r
+         done:=true;\r
+        end;\r
+   'H': begin\r
+         cursor:=2;\r
+         done:=true;\r
+        end;\r
+   'O','1': begin\r
+             cursor:=3;\r
+             done:=true;\r
+            end;\r
+  #10: printbigbox(GetHeapStats1,GetHeapStats2);\r
+  end;\r
+  drawcursor2;\r
+  lastx:=mouse.x;\r
+  lasty:=mouse.y;\r
+ end;\r
+\r
+ procedure findmouse2;\r
+ var button: boolean;\r
+     newcursor: integer;\r
+ begin\r
+  if mouse.getstatus then button:=true else button:=false;\r
+  if (not button) and (mouse.x=lastx) or (mouse.y=lasty) then exit;\r
+  case mouse.y of\r
+   78..92: case mouse.x of\r
+             78..128: newcursor:=1;\r
+            135..185: newcursor:=2;\r
+            192..242: newcursor:=3;\r
+            else newcursor:=0;\r
+           end;\r
+   else newcursor:=0;\r
+  end;\r
+  if newcursor<>cursor then\r
+   begin\r
+    undocursor2;\r
+    cursor:=newcursor;\r
+    drawcursor2;\r
+   end;\r
+  if (cursor<>0) and (button) then done:=true;\r
+ end;\r
+\r
+ function mainloop2: integer;\r
+ begin\r
+  done:=false;\r
+  lastx:=0;\r
+  lasty:=0;\r
+  cursor:=0;\r
+  mouseshow;\r
+  repeat\r
+   findmouse2;\r
+   if fastkeypressed then processkey2;\r
+  until done;\r
+  mainloop2:=cursor;\r
+ end;\r
+\r
+begin\r
+ new(tempscr);\r
+ mousehide;\r
+ tcolor:=text;\r
+ for i:=60 to 102 do\r
+  mymove(screen[i,74],tempscr^[i,74],43);\r
+ tcolor:=text-5;\r
+ bkcolor:=35+alt;\r
+ button(75,60,245,102,alt);\r
+ button(78,78,128,92,2+alt);\r
+ button(135,78,185,92,2+alt);\r
+ button(192,78,242,92,2+alt);\r
+ printxy(156-round(length(s)*2.5),65,s);\r
+ bkcolor:=37+alt;\r
+ printxy(92,82,'All');\r
+ printxy(146,82,'Half');\r
+ printxy(206,82,'One');\r
+ result:=mainloop2;\r
+ mousehide;\r
+ for i:=60 to 102 do\r
+  mymove(tempscr^[i,74],screen[i,74],43);\r
+ dispose(tempscr);\r
+ request:=result;\r
+ bkcolor:=3;\r
+ mouseshow;\r
+ mouse.x:=0;\r
+ mouse.y:=0;\r
+end;\r
+\r
+procedure dropit;\r
+var s: string[20];\r
+begin\r
+   if (cargoindex=0) or (cargoindex=251) then exit;\r
+   if (ship.cargo[cargoindex]=1056) or (ship.cargo[cargoindex]>6899) then\r
+   begin\r
+      a:=ship.options[5];\r
+      ship.options[5]:=2;\r
+      printbigbox('That item is too vital','to jettison!');\r
+      ship.options[5]:=a;\r
+      exit;\r
+   end;\r
+   if rescargo[cargoindex] >= ship.numcargo[cargoindex] then\r
+   begin\r
+      a:=ship.options[5];\r
+      ship.options[5]:=2;\r
+      printbigbox('Can''t jettison that!','It''s needed for building.');\r
+      ship.options[5]:=a;\r
+      exit;\r
+   end;\r
+   j:=1;\r
+   while cargo[j].index<>ship.cargo[cargoindex] do inc(j);\r
+   s:=cargo[j].name;\r
+   i:=20;\r
+   while (cargo[j].name[i]=' ') do dec(i);\r
+   s[0]:=chr(i);\r
+   j:=request('Jettison '+s+'?',0,31);\r
+   case j of\r
+     1 : begin\r
+           ship.numcargo[cargoindex]:=0;\r
+           ship.cargo[cargoindex]:=0;\r
+           revnewcursor(cargoindex);\r
+           if cargoindex<1 then newcursor(1);\r
+        end;\r
+     2 : begin\r
+           dec(ship.numcargo[cargoindex],ship.numcargo[cargoindex] div 2);\r
+           if ship.numcargo[cargoindex]=0 then\r
+           begin\r
+              ship.cargo[cargoindex]:=0;\r
+              revnewcursor(cargoindex);\r
+              if cargoindex<1 then newcursor(1);\r
+           end;\r
+        end;\r
+     3 : begin\r
+           if ship.numcargo[cargoindex]=1 then\r
+           begin\r
+              ship.numcargo[cargoindex]:=0;\r
+              ship.cargo[cargoindex]:=0;\r
+              revnewcursor(cargoindex);\r
+              if cargoindex<1 then newcursor(1);\r
+           end\r
+           else dec(ship.numcargo[cargoindex]);\r
+        end;\r
+   end;\r
+   bkcolor:=0;\r
+end;\r
+\r
+procedure findcargcursor;\r
+begin\r
+ if cargomode=0 then y:=((mouse.y-22) div 6)-6\r
+  else y:=(mouse.y-22) div 20;\r
+ if y=0 then exit;\r
+ while (y>0) and (cargoindex<251) do\r
+  begin\r
+   newcursor(cargoindex);\r
+   dec(y);\r
+  end;\r
+ while (y<0) and (cargoindex>0) do\r
+  begin\r
+   revnewcursor(cargoindex);\r
+   inc(y);\r
+  end;\r
+ if cargoindex>250 then revnewcursor(251);\r
+ if cargoindex<=0 then newcursor(0);\r
+end;\r
+\r
+procedure findmouse;\r
+var button: boolean;\r
+begin\r
+ if not mouse.getstatus then exit;\r
+ case mouse.x of\r
+  94..102: case mouse.y of\r
+              22..106: findcargcursor;\r
+             110..126: done:=true;\r
+            end;\r
+  104..113: case mouse.y of\r
+              22..106: findcargcursor;\r
+             110..126: dropit;\r
+            end;\r
+  115..159: case mouse.y of\r
+              22..106: findcargcursor;\r
+             110..117: begin\r
+                        if filters2[1]=0 then filters2[1]:=1 else filters2[1]:=0;\r
+                        newcursor(0);\r
+                        drawfilters;\r
+                       end;\r
+             119..126: begin\r
+                        if filters2[2]=0 then filters2[2]:=1 else filters2[2]:=0;\r
+                        newcursor(0);\r
+                        drawfilters;\r
+                       end;\r
+            end;\r
+  161..204: case mouse.y of\r
+              22..106: findcargcursor;\r
+             110..117: begin\r
+                        if filters2[3]=0 then filters2[3]:=1 else filters2[3]:=0;\r
+                        newcursor(0);\r
+                        drawfilters;\r
+                       end;\r
+             119..126: begin\r
+                        if filters2[4]=0 then filters2[4]:=1 else filters2[4]:=0;\r
+                        newcursor(0);\r
+                        drawfilters;\r
+                       end;\r
+            end;\r
+  206..215: case mouse.y of\r
+              22..106: findcargcursor;\r
+             110..126: begin\r
+                        if cargomode=1 then cargomode:=0 else cargomode:=1;\r
+                        for i:=22 to 106 do\r
+                         fillchar(screen[i,90],140,0);\r
+                        newcursor(0);\r
+                       end;\r
+            end;\r
+  217..226: case mouse.y of\r
+              22..106: findcargcursor;\r
+             110..117: begin\r
+                        if cargoindex>1 then revnewcursor(cargoindex)\r
+                         else revnewcursor(251);\r
+                        if cargoindex=0 then newcursor(0);\r
+                       end;\r
+             119..126: begin\r
+                        newcursor(cargoindex);\r
+                        if cargoindex=251 then revnewcursor(251);\r
+                       end;\r
+            end;\r
+  236..250: if (mouse.y>71) and (mouse.y<91) and yesnorequest('PRINT CARGO?',0,31) then printcargo;\r
+ end;\r
+ if cargoindex>250 then\r
+  begin\r
+   cargoindex:=0;\r
+   mousehide;\r
+   for i:=22 to 106 do\r
+    fillchar(screen[i,90],140,0);\r
+   mouseshow;\r
+  end;\r
+ if cargomode=0 then displaylist else displayinfo;\r
+ idletime:=0;\r
+end;\r
+\r
+procedure processkey;\r
+var ans: char;\r
+begin\r
+ ans:=readkey;\r
+ case upcase(ans) of\r
+  #27,'Q': done:=true;\r
+  #0: begin\r
+       ans:=readkey;\r
+       case ans of\r
+        #72:begin\r
+             if cargoindex>1 then revnewcursor(cargoindex)\r
+              else revnewcursor(251);\r
+             if cargoindex=0 then newcursor(0);\r
+            end;\r
+        #80: begin\r
+              newcursor(cargoindex);\r
+              if cargoindex=251 then revnewcursor(251);\r
+             end;\r
+        #81: begin\r
+              mouse.y:=101;\r
+              findcargcursor;\r
+             end;\r
+        #73: begin\r
+              mouse.y:=22;\r
+              findcargcursor;\r
+             end;\r
+       end;\r
+      end;\r
+  '1': begin\r
+        if filters2[1]=0 then filters2[1]:=1 else filters2[1]:=0;\r
+        newcursor(1);\r
+        drawfilters;\r
+       end;\r
+  '2': begin\r
+        if filters2[2]=0 then filters2[2]:=1 else filters2[2]:=0;\r
+        newcursor(1);\r
+        drawfilters;\r
+       end;\r
+  '3': begin\r
+        if filters2[3]=0 then filters2[3]:=1 else filters2[3]:=0;\r
+        newcursor(1);\r
+        drawfilters;\r
+       end;\r
+  '4': begin\r
+        if filters2[4]=0 then filters2[4]:=1 else filters2[4]:=0;\r
+        newcursor(1);\r
+        drawfilters;\r
+       end;\r
+  'D': dropit;\r
+  '`': bossmode;\r
+  '/','?': begin\r
+            if cargomode=1 then cargomode:=0 else cargomode:=1;\r
+            for i:=22 to 106 do\r
+             fillchar(screen[i,90],140,0);\r
+            newcursor(0);\r
+           end;\r
+  #10: printbigbox(GetHeapStats1,GetHeapStats2);\r
+ end;\r
+ if cargoindex>250 then\r
+  begin\r
+   cargoindex:=0;\r
+   mousehide;\r
+   for i:=22 to 106 do\r
+    fillchar(screen[i,90],140,0);\r
+   mouseshow;\r
+  end;\r
+ if cargomode=0 then displaylist else displayinfo;\r
+ idletime:=0;\r
+end;\r
+\r
+procedure animation;\r
+begin\r
+ setrgb256(lightindex,0,0,0);\r
+ inc(lightindex);\r
+ if lightindex=240 then lightindex:=232;\r
+ setrgb256(lightindex,0,0,48);\r
+ mousehide;\r
+ for i:=77 to 78 do\r
+  for j:=240 to 246 do\r
+   if random(2)=0 then screen[i,j]:=63 else screen[i,j]:=0;\r
+ mouseshow;\r
+end;\r
+\r
+procedure mainloop;\r
+begin\r
+ repeat\r
+  fadestep(8);\r
+  findmouse;\r
+  if fastkeypressed then processkey;\r
+  inc(idletime);\r
+  if idletime=maxidle then screensaver;\r
+  animation;\r
+  if batindex<8 then inc(batindex) else\r
+   begin\r
+    batindex:=0;\r
+    addtime2;\r
+    if cargomode=0 then displaylist else displayinfo;\r
+   end;\r
+  delay(tslice*4);\r
+ until done;\r
+end;\r
+\r
+procedure removedata;\r
+begin\r
+   mousehide;\r
+   {fading;}\r
+   {fadefull(-8, 20);}\r
+   fadestopmod(-8, 20);\r
+   mouse.setmousecursor(random(3));\r
+   {loadscreen(tempdir+'\current',@screen);}\r
+   quickloadscreen(tempdir+'\current',@screen, true);\r
+   showresearchlights;\r
+   bkcolor:=3;\r
+   displaytextbox(false);\r
+   textindex:=25;\r
+   if (viewmode=11) and (viewlevel=2) then displaybotinfo(6);\r
+   {fadein;}\r
+   mouseshow;\r
+   anychange:=true;\r
+   t1:=oldt1;\r
+end;\r
+\r
+procedure inventory;\r
+begin\r
+ readydata;\r
+ displaylist;\r
+ mainloop;\r
+ closedoors;\r
+ {stopmod;}\r
+ removedata;\r
+end;\r
+\r
+{***************************************************************************}\r
+\r
+procedure inccursor;\r
+begin\r
+ drawit:=false;\r
+ if cargomode=0 then\r
+ repeat\r
+  inc(cargoindex);\r
+  i:=0;\r
+  for j:=1 to 6 do if ship.crew[j].level>=createinfo^[cargoindex].levels[j] then inc(i);\r
+  case createinfo^[cargoindex].index of\r
+      0..2999: if filters[3]=1 then drawit:=true;\r
+   3000..3999: if filters[2]=1 then drawit:=true;\r
+   4000..4999: if filters[1]=1 then drawit:=true;\r
+  end;\r
+ until ((i=6) and (drawit)) or (cargoindex>maxcreation)\r
+ else\r
+  repeat\r
+   inc(cargoindex);\r
+   while (cargoindex<251) and (ship.numcargo[cargoindex]=0) do inc(cargoindex);\r
+   case ship.cargo[cargoindex] of\r
+      0..2999,6000..6999: if filters[3]=1 then drawit:=true;\r
+   3000..3999: if filters[2]=1 then drawit:=true;\r
+   4000..4999: if filters[1]=1 then drawit:=true;\r
+  end;\r
+  until (drawit) or (cargoindex>250);\r
+ if (qmode) and (viewteam>0) then\r
+  begin\r
+   viewteam:=0;\r
+   for i:=77 to 80 do\r
+    fillchar(screen[i,222],77,0);\r
+  end;\r
+ anychange:=true;\r
+end;\r
+\r
+procedure deccursor;\r
+begin\r
+ drawit:=false;\r
+ if cargomode=0 then\r
+ repeat\r
+  dec(cargoindex);\r
+  i:=0;\r
+  for j:=1 to 6 do if ship.crew[j].level>=createinfo^[cargoindex].levels[j] then inc(i);\r
+  case createinfo^[cargoindex].index of\r
+      0..2999: if filters[3]=1 then drawit:=true;\r
+   3000..3999: if filters[2]=1 then drawit:=true;\r
+   4000..4999: if filters[1]=1 then drawit:=true;\r
+  end;\r
+ until ((i=6) and (drawit)) or (cargoindex<1)\r
+ else\r
+  repeat\r
+   dec(cargoindex);\r
+   while (cargoindex>0) and (ship.numcargo[cargoindex]=0) do dec(cargoindex);\r
+   case ship.cargo[cargoindex] of\r
+      0..2999,6000..6999: if filters[3]=1 then drawit:=true;\r
+   3000..3999: if filters[2]=1 then drawit:=true;\r
+   4000..4999: if filters[1]=1 then drawit:=true;\r
+  end;\r
+  until (drawit) or (cargoindex<1);\r
+ if (qmode) and (viewteam>0) then\r
+  begin\r
+   viewteam:=0;\r
+   for i:=77 to 80 do\r
+    fillchar(screen[i,222],77,0);\r
+  end;\r
+ anychange:=true;\r
+end;\r
+\r
+procedure adjustteams;\r
+var a: integer;\r
+begin\r
+ mousehide;\r
+ for a:=1 to 3 do\r
+  begin\r
+   if (ship.engrteam[a].job=0) and (screen[114+a*10,204]=95) then anychange:=true;\r
+   if ship.engrteam[a].job=0 then i:=60 else i:=95;\r
+    for j:=204 to 207 do\r
+     screen[114+a*10,j]:=i;\r
+  end;\r
+{ if ship.research and 4>0 then\r
+  begin\r
+   i:=0;\r
+   for j:=1 to 3 do if ship.engrteam[j].job>0 then inc(i);\r
+   if i>1 then\r
+    begin\r
+     dec(ship.research,4);\r
+     mouseshow;\r
+     showchar(2,'Cancelling research.  Teams too busy.');\r
+     mousehide;\r
+    end;\r
+  end;}\r
+ mouseshow;\r
+end;\r
+\r
+procedure drawfilters2;\r
+var b: integer;\r
+begin\r
+ mousehide;\r
+ for b:=1 to 3 do\r
+  begin\r
+   if filters[b]=1 then i:=60 else i:=95;\r
+   for j:=51 to 54 do\r
+    screen[114+b*11,j]:=i;\r
+  end;\r
+ mouseshow;\r
+end;\r
+\r
+procedure opendoors2;\r
+var a,b: integer;\r
+    temppal: paltype;\r
+begin\r
+ fillchar(temppal,768,0);\r
+ for j:=112 to 159 do\r
+  temppal[j]:=colors[j];\r
+ set256colors(temppal);\r
+ delay(tslice*18);\r
+ b:=tslice div 3;\r
+ for a:=1 to 31 do\r
+  begin\r
+   for i:=1 to 3 do\r
+    begin\r
+     for j:=0 to 111 do\r
+      temppal[j,i]:=round(a*colors[j,i]/31);\r
+     for j:=160 to 255 do\r
+      temppal[j,i]:=round(a*colors[j,i]/31);\r
+    end;\r
+   set256colors(temppal);\r
+   delay(b);\r
+  end;\r
+end;\r
+\r
+procedure readycreationdata;\r
+var crfile: file of createarray;\r
+begin\r
+   if not chevent(18) then maxcreation:=totalcreation-1 else maxcreation:=totalcreation;\r
+   mousehide;\r
+   {compressfile(tempdir+'\current',@screen);}\r
+   quicksavescreen(tempdir+'\current',@screen, true);\r
+   {fading;}\r
+   {fadefull(-8, 20);}\r
+   fadestopmod(-8, 20);\r
+   playmod(true,'sound\compont.mod');\r
+   loadscreen('data\tech1',@screen);\r
+   drawfilters2;\r
+   new(iteminfo);\r
+   done:=false;\r
+   bkcolor:=0;\r
+   lastinfo:=0;\r
+   cargomode:=0;\r
+   cargoindex:=0;\r
+   oldt1:=t1;\r
+   tcolor:=31;\r
+   new(createinfo);\r
+   assign(crfile,'data\creation.dta');\r
+   reset(crfile);\r
+   if ioresult<>0 then errorhandler('creation.dta',1);\r
+   read(crfile,createinfo^);\r
+   if ioresult<>0 then errorhandler('creation.dta',5);\r
+   close(crfile);\r
+   for j:=95 to 98 do\r
+   begin\r
+      screen[6,j]:=63;\r
+      screen[14,j]:=95;\r
+   end;\r
+   if qmode then\r
+      for i:=6 to 14 do\r
+      begin\r
+        screen[i,34]:=63;\r
+        screen[i,33]:=63;\r
+      end\r
+      else\r
+        for i:=6 to 14 do\r
+        begin\r
+           screen[i,34]:=95;\r
+           screen[i,33]:=95;\r
+        end;\r
+   if colorcode then fillchar(screen[125,69],4,63);\r
+   viewteam:=0;\r
+   {if ship.options[6]=1 then opendoors2 else fadein;}\r
+   inccursor;\r
+   mouseshow;\r
+end;\r
+\r
+procedure displaybreakdown(item: integer);\r
+var s1,s2: string[15];\r
+    s: string[19];\r
+    k: integer;\r
+begin\r
+   if item=0 then exit;\r
+   lastinfo:=item;\r
+   mousehide;\r
+   tcolor:=28;\r
+   if item>6000 then\r
+   begin\r
+      getartifactname(item);\r
+      s:=cargo[maxcargo].name;\r
+   end\r
+   else\r
+   begin\r
+      a:=1;\r
+      while (createinfo^[a].index<>item) and (a<totalcreation{maxcreation}) do inc(a);\r
+      str(item,s1);\r
+      if (a=totalcreation{maxcreation}) and (createinfo^[a].index<>item) then\r
+        errorhandler('creation array overflow: '+s1,6);\r
+      s:=createinfo^[a].name;\r
+   end;\r
+   i:=1;\r
+   while (i<19) and (s[i]<>' ') do inc(i);\r
+   s1:=copy(s,0,i-1);\r
+   s2:=copy(s,i+1,19-i);\r
+   i:=length(s2);\r
+   while (i>1) and (s2[i]=' ') do dec(i);\r
+   s2[0]:=chr(i);\r
+   printxy(217+round((78-length(s1)*5)/2),59,s1);\r
+   printxy(217+round((78-length(s2)*5)/2),65,s2);\r
+   if item<6000 then\r
+   begin\r
+      if (cargomode=0) and (viewteam=0) then\r
+        k := CheckBuildStock(item);\r
+      for j:=1 to 3 do\r
+      begin\r
+        i:=createinfo^[a].parts[j];\r
+        if (cargomode=0) and (viewteam=0) then\r
+        begin\r
+           if k >= 0 then\r
+           begin\r
+              case ((k shr (j + j - 2)) and 3) of\r
+                0 : tcolor := 95;\r
+                1 : tcolor := 63;\r
+                2 : tcolor := 127;\r
+              end;\r
+           end else\r
+              tcolor:=95;\r
+           {\r
+           k:=1;\r
+           if createinfo^[a].parts[2]=createinfo^[a].parts[1] then inc(k);\r
+           if createinfo^[a].parts[3]=createinfo^[a].parts[1] then inc(k);\r
+           if (j<=k) and (incargo(createinfo^[a].parts[1])>=j) then tcolor:=63\r
+              else if (j>k) and (incargo(createinfo^[a].parts[j])>0) then tcolor:=63\r
+              else tcolor:=95;\r
+           }\r
+        end else tcolor:=26;\r
+        b:=1;\r
+        while (cargo[b].index<>i) do inc(b);\r
+        s:=cargo[b].name;\r
+        i:=1;\r
+        while (i<19) and (s[i]<>' ') do inc(i);\r
+        s1:=copy(s,0,i-1);\r
+        s2:=copy(s,i+1,19-i);\r
+        i:=length(s2);\r
+        while (i>1) and (s2[i]=' ') do dec(i);\r
+        s2[0]:=chr(i);\r
+        printxy(127+round((78-length(s1)*5)/2),j*21+19,s1);\r
+        printxy(127+round((78-length(s2)*5)/2),j*21+25,s2);\r
+      end;\r
+   end\r
+   else\r
+   begin\r
+      printxy(146,61,'Research');\r
+      printxy(146,67,'Artifact');\r
+   end;\r
+   mouseshow;\r
+end;\r
+\r
+procedure weaponinfo(n: integer);\r
+var str1: string[5];\r
+begin\r
+ tcolor:=31;\r
+ bkcolor:=1;\r
+ printxy(127,2,cargo[n].name);\r
+ tcolor:=95;\r
+ str((weapons[n].range div 1000):3,str1);\r
+ printxy(127,11,' Range: '+str1+' KKM');\r
+ str(weapons[n].energy:4,str1);\r
+ printxy(127,17,'Energy:'+str1+' GW');\r
+ str(weapons[n].damage:4,str1);\r
+ printxy(127,23,'Damage:'+str1+' GJ');\r
+ printxy(230,5, 'PSION');\r
+ printxy(230,11,'PRTCL');\r
+ printxy(230,17,'INTRL');\r
+ printxy(230,23,'ENRGY');\r
+ for j:=1 to 4 do\r
+  begin\r
+   x:=round(weapons[n].dmgtypes[j]/2);\r
+   for i:=-1 to 4 do\r
+    begin\r
+     if i>0 then y:=100-i\r
+      else y:=100+i;\r
+     fillchar(screen[1+i+j*6,260],x,y);\r
+     if x<50 then\r
+      fillchar(screen[1+i+j*6,260+x],50-x,0);\r
+    end;\r
+  end;\r
+ if n<59 then readweaicon(n-1) else readweaicon(n-2);\r
+ for i:=0 to 19 do\r
+  mymove(tempicon^[i],screen[9+i,210],5);\r
+ bkcolor:=0;\r
+end;\r
+\r
+procedure getinfo;\r
+var f   : file of iteminfotype;\r
+   index : integer;\r
+{   s   : String;}\r
+begin\r
+ if cargoindex=0 then exit;\r
+ assign(f,'data\iteminfo.dta');\r
+ reset(f);\r
+ if ioresult<>0 then errorhandler('iteminfo.dta',1);\r
+ if cargomode=0 then index:=createinfo^[cargoindex].index\r
+  else\r
+   begin\r
+    index:=ship.cargo[cargoindex];\r
+    if index>6000 then getartifactname(ship.cargo[cargoindex]);\r
+    if (index=3000) or (index=4000) then\r
+     begin\r
+      ship.cargo[cargoindex]:=0;\r
+      i:=ship.numcargo[cargoindex];\r
+      ship.numcargo[cargoindex]:=0;\r
+      for j:=1 to i do addcargo(index+random(20)+1, true);\r
+      index:=ship.cargo[cargoindex];\r
+      anychange:=true;\r
+      dec(cargoindex);\r
+      inccursor;\r
+      if ((cargomode=0) and (cargoindex>maxcreation)) or\r
+       ((cargomode=1) and (cargoindex>250)) then\r
+        begin\r
+         cargoindex:=0;\r
+         inccursor;\r
+         if ((cargomode=0) and (cargoindex>maxcreation)) or\r
+          ((cargomode=1) and (cargoindex>250)) then cargoindex:=0;\r
+        end;\r
+     end;\r
+   end;\r
+ i:=0;\r
+ if index>0 then\r
+  repeat\r
+   inc(i);\r
+   read(f,iteminfo^);\r
+   if ioresult<>0 then errorhandler('iteminfo.dta',5);\r
+  until (iteminfo^.index=index) or (i=totalcreation);\r
+ close(f);\r
+ tcolor:=24;\r
+ bkcolor:=165;\r
+ mousehide;\r
+ if cargomode=0 then printxy(1,160,createinfo^[cargoindex].name)\r
+  else\r
+   begin\r
+    if ship.cargo[cargoindex]>6000 then j:=maxcargo\r
+    else\r
+     begin\r
+      j:=1;\r
+      while (cargo[j].index<>ship.cargo[cargoindex]) do inc(j);\r
+     end;\r
+    printxy(1,160,cargo[j].name);\r
+   end;\r
+ tcolor:=18;\r
+ bkcolor:=2;\r
+ if (i=totalcreation) and (iteminfo^.index<>index) then\r
+  begin\r
+   for i:=175 to 195 do\r
+    fillchar(screen[i,6],140,2);\r
+   if index<6000 then printxy(1,169,'Fabricated Material        ')\r
+    else printxy(1,169,'Unknown Alien Artifact     ');\r
+  end\r
+ else\r
+  for j:=0 to 3 do\r
+   printxy(1,169+j*6,iteminfo^.info[j]);\r
+ bkcolor:=0;\r
+ if viewteam=0 then\r
+  begin\r
+   for j:=0 to 2 do\r
+    for i:=0 to 13 do\r
+     fillchar(screen[j*21+40+i,131],79,0);\r
+   for i:=59 to 72 do\r
+    fillchar(screen[i,221],79,0);\r
+   displaybreakdown(index);\r
+     {str(GetBuildTime(index),s);\r
+     printxy(5,5,s);}\r
+  end;\r
+ if (index>999) and (index<1500) then weaponinfo(index-999)\r
+  else if (index>1499) and (index<2000) then weaponinfo(index-1442)\r
+  else for i:=3 to 29 do\r
+        fillchar(screen[i,132],180,1);\r
+ mouseshow;\r
+end;\r
+\r
+procedure displaydevices;\r
+var k: integer;\r
+begin\r
+ anychange:=false;\r
+ if (qmode) and (cargoindex>0) then getinfo;\r
+ x:=cargoindex;\r
+ y:=9;\r
+ mousehide;\r
+ if x>0 then\r
+  repeat\r
+   drawit:=false;\r
+   i:=0;\r
+   for j:=1 to 6 do if ship.crew[j].level>=createinfo^[x].levels[j] then inc(i);\r
+   case createinfo^[x].index of\r
+       0..2999: begin\r
+                 if filters[3]=1 then drawit:=true;\r
+                 tcolor:=47;\r
+                end;\r
+    3000..3999: begin\r
+                 if filters[2]=1 then drawit:=true;\r
+                 tcolor:=79;\r
+                end;\r
+    4000..4999: begin\r
+                 if filters[1]=1 then drawit:=true;\r
+                 tcolor:=143;\r
+                end;\r
+   end;\r
+   if (i=6) and (drawit) then\r
+    begin\r
+     dec(y);\r
+     if y=8 then bkcolor:=6 else bkcolor:=0;\r
+     k:=0;\r
+     for j:=1 to 3 do if createinfo^[x].parts[j]=createinfo^[x].parts[1] then inc(k);\r
+     if (incargo(createinfo^[x].parts[1])<k) or\r
+        (incargo(createinfo^[x].parts[2])=0) or\r
+        (incargo(createinfo^[x].parts[3])=0)\r
+       then begin if not colorcode then tcolor:=16; end else tcolor:=31;\r
+     printxy(6,16+y*6,createinfo^[x].name);\r
+    end;\r
+   dec(x);\r
+  until (y=1) or (x<1);\r
+ if y>1 then\r
+  for i:=22 to y*6+16 do\r
+   fillchar(screen[i,11],100,0);\r
+ x:=cargoindex+1;\r
+ y:=8;\r
+ bkcolor:=0;\r
+ repeat\r
+  drawit:=false;\r
+  i:=0;\r
+  for j:=1 to 6 do if ship.crew[j].level>=createinfo^[x].levels[j] then inc(i);\r
+  case createinfo^[x].index of\r
+       0..2999: begin\r
+                 if filters[3]=1 then drawit:=true;\r
+                 tcolor:=47;\r
+                end;\r
+    3000..3999: begin\r
+                 if filters[2]=1 then drawit:=true;\r
+                 tcolor:=79;\r
+                end;\r
+    4000..4999: begin\r
+                 if filters[1]=1 then drawit:=true;\r
+                 tcolor:=143;\r
+                end;\r
+  end;\r
+  if (i=6) and (drawit) and (x<=maxcreation) then\r
+   begin\r
+    inc(y);\r
+    k:=0;\r
+    for j:=1 to 3 do if createinfo^[x].parts[j]=createinfo^[x].parts[1] then inc(k);\r
+    if (incargo(createinfo^[x].parts[1])<k) or\r
+       (incargo(createinfo^[x].parts[2])=0) or\r
+       (incargo(createinfo^[x].parts[3])=0)\r
+      then begin if not colorcode then tcolor:=16; end else tcolor:=31;\r
+    printxy(6,16+y*6,createinfo^[x].name);\r
+   end;\r
+  inc(x);\r
+ until (y=16) or (x>maxcreation);\r
+ if y<16 then\r
+  for i:=y*6+23 to 118 do\r
+   fillchar(screen[i,11],100,0);\r
+ mouseshow;\r
+end;\r
+\r
+procedure displaycargo;\r
+begin\r
+ anychange:=false;\r
+ if ship.cargo[cargoindex]=0 then inccursor;\r
+ if (qmode) and (cargoindex>0) then getinfo;\r
+ if cargoindex=0 then\r
+  begin\r
+   for i:=22 to 118 do\r
+    fillchar(screen[i,11],100,0);\r
+   exit;\r
+  end;\r
+ y:=9;\r
+ x:=cargoindex;\r
+ tcolor:=31;\r
+ mousehide;\r
+ repeat\r
+  drawit:=false;\r
+  while (x>0) and (ship.numcargo[x]=0) do dec(x);\r
+  if x>0 then\r
+   case ship.cargo[x] of\r
+       0..2999,6000..6999:\r
+                begin\r
+                 if filters[3]=1 then drawit:=true;\r
+                 tcolor:=47;\r
+                end;\r
+    3000..3999: begin\r
+                 if filters[2]=1 then drawit:=true;\r
+                 tcolor:=79;\r
+                end;\r
+    4000..4999: begin\r
+                 if filters[1]=1 then drawit:=true;\r
+                 tcolor:=143;\r
+                end;\r
+   end;\r
+  if not colorcode then tcolor:=31;\r
+  if drawit then\r
+   begin\r
+    if ship.cargo[x]>6000 then\r
+     begin\r
+      getartifactname(ship.cargo[x]);\r
+      i:=maxcargo;\r
+     end\r
+    else\r
+     begin\r
+      i:=1;\r
+      while (cargo[i].index<>ship.cargo[x]) do inc(i);\r
+     end;\r
+    dec(y);\r
+    if y=8 then bkcolor:=6 else bkcolor:=0;\r
+    printxy(6,16+y*6,cargo[i].name);\r
+   end;\r
+  dec(x);\r
+ until (y=1) or (x<1);\r
+ if y>1 then\r
+  for i:=22 to 16+y*6 do\r
+   fillchar(screen[i,11],100,0);\r
+ x:=cargoindex+1;\r
+ y:=8;\r
+ bkcolor:=0;\r
+ repeat\r
+  drawit:=false;\r
+  while (x<251) and (ship.numcargo[x]=0) do inc(x);\r
+  case ship.cargo[x] of\r
+       0..2999,6000..6999:\r
+                begin\r
+                 if filters[3]=1 then drawit:=true;\r
+                 tcolor:=47;\r
+                end;\r
+    3000..3999: begin\r
+                 if filters[2]=1 then drawit:=true;\r
+                 tcolor:=79;\r
+                end;\r
+    4000..4999: begin\r
+                 if filters[1]=1 then drawit:=true;\r
+                 tcolor:=143;\r
+                end;\r
+  end;\r
+  if not colorcode then tcolor:=31;\r
+  if (drawit) and (x<251) then\r
+   begin\r
+    if ship.cargo[x]>6000 then\r
+     begin\r
+      getartifactname(ship.cargo[x]);\r
+      i:=maxcargo;\r
+     end\r
+    else\r
+     begin\r
+      i:=1;\r
+      while (cargo[i].index<>ship.cargo[x]) do inc(i);\r
+     end;\r
+    inc(y);\r
+    printxy(6,16+y*6,cargo[i].name);\r
+   end;\r
+  inc(x);\r
+ until (y=16) or (x>250);\r
+ if y<16 then\r
+  for i:=y*6+23 to 118 do\r
+   fillchar(screen[i,11],100,0);\r
+ mouseshow;\r
+end;\r
+\r
+procedure displayteaminfo(team: integer);\r
+var b : integer;\r
+begin\r
+   tcolor:=31;\r
+   adjustteams;\r
+   if ship.engrteam[team].job=0 then\r
+   begin\r
+      mousehide;\r
+      for j:=0 to 2 do\r
+        for i:=0 to 13 do\r
+           fillchar(screen[j*21+40+i,131],79,0);\r
+      for i:=59 to 72 do\r
+        fillchar(screen[i,221],79,0);\r
+      for i:=77 to 80 do\r
+        fillchar(screen[i,222],77,0);\r
+      viewteam:=0;\r
+      mouseshow;\r
+      exit;\r
+   end;\r
+   mousehide;\r
+   if teamjob <> ship.engrteam[team].job then\r
+   begin\r
+      for j:=0 to 2 do\r
+        for i:=0 to 13 do\r
+           fillchar(screen[j*21+40+i,131],79,0);\r
+      for i:=59 to 72 do\r
+        fillchar(screen[i,221],79,0);\r
+      for i:=77 to 80 do\r
+        fillchar(screen[i,222],77,0);\r
+      teamjob := ship.engrteam[team].job;\r
+   end;\r
+   case ship.engrteam[team].jobtype of\r
+     0 : printxy(233,62,'Repairing');\r
+     1: printxy(231,62,'Installing');\r
+     2: printxy(236,62,'Removing');\r
+  5: printxy(236,62,'  Research');\r
+   end;\r
+   if ship.engrteam[team].jobtype<3 then\r
+   begin\r
+      for i:=77 to 80 do\r
+        fillchar(screen[i,222],77,0);\r
+      mouseshow;\r
+      exit;\r
+   end;\r
+   if ship.engrteam[team].jobtype<5 then displaybreakdown(ship.engrteam[team].job);\r
+   b:=76-round(ship.engrteam[team].timeleft/GetBuildTime(ship.engrteam[team].job)*76);\r
+   {b:=round((ship.engrteam[team].extra shr 8) * 76/\r
+   (ship.engrteam[team].extra and 255));}\r
+   if b=0 then b:=1;\r
+   for j:=0 to b do\r
+   begin\r
+      a:=round(15/b*j+48);\r
+      for i:=77 to 80 do\r
+        screen[i,j+222]:=a;\r
+   end;\r
+   if b<76 then\r
+      for i:=77 to 80 do\r
+        fillchar(screen[i,b+223],75-b,0);\r
+   mouseshow;\r
+   anychange:=true;\r
+end;\r
+\r
+procedure go2(team: integer);\r
+begin\r
+ if (ship.cargo[cargoindex]=3000) or (ship.cargo[cargoindex]=4000) then\r
+  begin\r
+   getinfo;\r
+   displaycargo;\r
+   exit;\r
+  end;\r
+ if ship.cargo[cargoindex]<6000 then\r
+  displaybreakdown(ship.cargo[cargoindex]);\r
+ with ship.engrteam[team] do\r
+  begin\r
+   job:=ship.cargo[cargoindex];\r
+   if job<6000 then jobtype:=4 else jobtype:=5;\r
+   timeleft:=0;\r
+   if job<6000 then\r
+    begin\r
+     i:=1;\r
+     while createinfo^[i].index<>job do inc(i);\r
+     for j:=1 to 6 do timeleft:=timeleft+100*createinfo^[i].levels[j];\r
+    end else timeleft:=6000+random(5)*100;\r
+   dec(ship.numcargo[cargoindex]);\r
+   if ship.numcargo[cargoindex]=0 then\r
+    begin\r
+     ship.cargo[cargoindex]:=0;\r
+     deccursor;\r
+     if cargoindex<1 then inccursor;\r
+     if cargoindex>250 then cargoindex:=0;\r
+    end;\r
+   {extra:=timeleft div 100;}\r
+  end;\r
+ teamjob := 0;\r
+ viewteam:=team;\r
+ adjustteams;\r
+end;\r
+\r
+procedure go(team: integer);\r
+begin\r
+ if cargoindex=0 then exit;\r
+ mousehide;\r
+ tcolor:=31;\r
+ for j:=0 to 2 do\r
+  for i:=0 to 13 do\r
+   fillchar(screen[j*21+40+i,131],79,0);\r
+ for i:=59 to 72 do\r
+  fillchar(screen[i,221],79,0);\r
+ mouseshow;\r
+ if ship.engrteam[team].job>0 then\r
+  begin\r
+   viewteam:=team;\r
+   exit;\r
+  end;\r
+ viewteam:=0;\r
+ if cargomode=1 then\r
+  begin\r
+   go2(team);\r
+   exit;\r
+  end;\r
+   \r
+   case createinfo^[cargoindex].index of\r
+     2004,2015..2017,1019,3000..5999 : ;\r
+   else\r
+      if not checkweight(true) then exit;\r
+   end;\r
+ displaybreakdown(createinfo^[cargoindex].index);\r
+   i := CheckBuildStock(createinfo^[cargoindex].index);\r
+   if (i and $03 = 0) or (i and $0c = 0) or (i and $30 = 0) then\r
+      i := 0\r
+   else if i >=0 then\r
+      i := StartBuild(True, createinfo^[cargoindex].index, createinfo^[cargoindex].index, team);\r
+      \r
+   case i of\r
+     0 : begin\r
+            tcolor:=92;\r
+            for i:=59 to 72 do\r
+               fillchar(screen[i,221],79,0);\r
+            for i:=77 to 80 do\r
+               fillchar(screen[i,222],77,0);\r
+            printxy(226,59,'Insufficient');\r
+            printxy(244,65,'Parts');\r
+            exit;\r
+         end;\r
+     -1        : begin\r
+       tcolor:=92;\r
+       for i:=59 to 72 do\r
+          fillchar(screen[i,221],79,0);\r
+       for i:=77 to 80 do\r
+          fillchar(screen[i,222],77,0);\r
+       printxy(226,59,'Insufficient');\r
+       printxy(244,65,'Level');\r
+       exit;\r
+     end;\r
+     -2        : begin\r
+       tcolor:=92;\r
+       for i:=59 to 72 do\r
+          fillchar(screen[i,221],79,0);\r
+       for i:=77 to 80 do\r
+          fillchar(screen[i,222],77,0);\r
+       printxy(226,59,'  Internal  ');\r
+       printxy(244,65,'Error');\r
+       exit;\r
+     end;\r
+     -3        : begin\r
+       tcolor:=92;\r
+       for i:=59 to 72 do\r
+          fillchar(screen[i,221],79,0);\r
+       for i:=77 to 80 do\r
+          fillchar(screen[i,222],77,0);\r
+       printxy(226,59,'Insufficient');\r
+       printxy(228,65,' Knowledge ');\r
+       exit;\r
+     end;\r
+   end;\r
+     { \r
+ i:=0;\r
+ for j:=1 to 3 do if createinfo^[cargoindex].parts[j]=createinfo^[cargoindex].parts[1] then inc(i);\r
+ if (incargo(createinfo^[cargoindex].parts[1])<i) or\r
+  (incargo(createinfo^[cargoindex].parts[2])=0) or\r
+  (incargo(createinfo^[cargoindex].parts[3])=0) then\r
+  begin\r
+   tcolor:=92;\r
+   for i:=59 to 72 do\r
+    fillchar(screen[i,221],79,0);\r
+   for i:=77 to 80 do\r
+    fillchar(screen[i,222],77,0);\r
+   printxy(226,59,'Insufficient');\r
+   printxy(244,65,'Parts');\r
+   exit;\r
+  end;\r
+ for j:=1 to 6 do if createinfo^[cargoindex].levels[j]>ship.crew[j].level then\r
+  begin\r
+   tcolor:=92;\r
+   for i:=59 to 72 do\r
+    fillchar(screen[i,221],79,0);\r
+   for i:=77 to 80 do\r
+    fillchar(screen[i,222],77,0);\r
+   printxy(226,59,'Insufficient');\r
+   printxy(244,65,'Level');\r
+   exit;\r
+  end;}\r
+ viewteam:=team;\r
+ {with ship.engrteam[team] do\r
+  begin\r
+   job:=createinfo^[cargoindex].index;\r
+   jobtype:=3;\r
+   timeleft:=0;\r
+   for j:=1 to 6 do timeleft:=timeleft+100*createinfo^[cargoindex].levels[j];\r
+   for j:=1 to 6 do addxp(j,25*createinfo^[cargoindex].levels[j],0);\r
+   (*extra:=timeleft div 100;*)\r
+   for j:=1 to 3 do removecargo(createinfo^[cargoindex].parts[j]);\r
+  end;}\r
+ adjustteams;\r
+ anychange:=true;\r
+end;\r
+\r
+procedure findcursor;\r
+begin\r
+ y:=(mouse.y-16) div 6;\r
+ if y=8 then exit;\r
+ HistoryClear;\r
+ y:=y-8;\r
+ repeat\r
+  if y<0 then\r
+   begin\r
+    deccursor;\r
+    if cargoindex<1 then inccursor;\r
+    inc(y);\r
+   end\r
+  else\r
+   begin\r
+    inccursor;\r
+    dec(y);\r
+   end;\r
+  if ((cargomode=0) and (cargoindex>maxcreation)) or\r
+   ((cargomode=1) and (cargoindex>250)) then\r
+    begin\r
+     deccursor;\r
+     y:=0;\r
+    end;\r
+ until (y=0) or (cargoindex<1);\r
+end;\r
+\r
+procedure setfilter(n: integer);\r
+begin\r
+ if filters[n]=0 then filters[n]:=1 else filters[n]:=0;\r
+ if cargoindex>0 then dec(cargoindex);\r
+ inccursor;\r
+ if ((cargomode=0) and (cargoindex>maxcreation)) or\r
+  ((cargomode=1) and (cargoindex>250)) then\r
+  begin\r
+   cargoindex:=0;\r
+   inccursor;\r
+   if ((cargomode=0) and (cargoindex>maxcreation)) or\r
+    ((cargomode=1) and (cargoindex>250)) then cargoindex:=0;\r
+  end;\r
+ drawfilters2;\r
+ anychange:=true;\r
+end;\r
+\r
+procedure setdevicemode;\r
+var a: integer;\r
+begin\r
+ if cargomode<>0 then\r
+  begin\r
+   mousehide;\r
+   for j:=95 to 98 do\r
+    begin\r
+     screen[6,j]:=63;\r
+     screen[14,j]:=95;\r
+    end;\r
+   mouseshow;\r
+   cargomode:=0;\r
+   cargoindex:=0;\r
+   inccursor;\r
+   if cargoindex>maxcreation then deccursor;\r
+  end\r
+ else if cargoindex<>0 then\r
+  begin\r
+   a:=0;\r
+   repeat\r
+    inc(a);\r
+   until (ship.engrteam[a].job=0) or (a=4);\r
+   if a<4 then go(a);\r
+  end;\r
+end;\r
+\r
+procedure setcargomode;\r
+begin\r
+ if cargomode<>1 then\r
+  begin\r
+   mousehide;\r
+   for j:=95 to 98 do\r
+    begin\r
+     screen[6,j]:=95;\r
+     screen[14,j]:=63;\r
+    end;\r
+   mouseshow;\r
+   cargomode:=1;\r
+   cargoindex:=0;\r
+   inccursor;\r
+   if cargoindex>250 then deccursor;\r
+  end\r
+ else if cargoindex<>0 then\r
+  begin\r
+   a:=0;\r
+   repeat\r
+    inc(a);\r
+   until (ship.engrteam[a].job=0) or (a=4);\r
+   if a<4 then go(a);\r
+  end;\r
+end;\r
+\r
+procedure setcolorcode;\r
+begin\r
+ mousehide;\r
+ if colorcode then\r
+  begin\r
+   fillchar(screen[125,69],4,95);\r
+   colorcode:=false;\r
+  end\r
+ else\r
+  begin\r
+   fillchar(screen[125,69],4,63);\r
+   colorcode:=true;\r
+  end;\r
+ mouseshow;\r
+ anychange:=true;\r
+end;\r
+\r
+procedure clearkbbuffer; assembler;\r
+asm\r
+ push es\r
+ cli\r
+ mov ax, 40h\r
+ mov es, ax\r
+ mov ax, [es:1Ah]\r
+ mov [es:1Ch], ax\r
+ sti\r
+ pop es\r
+end;\r
+\r
+procedure setpartcursor(index : integer);\r
+var\r
+   j : Integer;\r
+begin\r
+   if index = 0 then\r
+      exit;\r
+   j := 1;\r
+   while (j<=maxcreation) and (createinfo^[j].index<>index) do inc(j);\r
+   if j > maxcreation then\r
+      exit;\r
+   cargoindex:=j;\r
+   anychange:=true;\r
+end; { setpart }\r
+\r
+procedure setinfocursor(part: integer);\r
+var\r
+   i : Integer;\r
+begin\r
+   if (cargomode=1) or (cargoindex=0) or (lastinfo=0) then exit;\r
+   i:=1;\r
+   while (i<maxcreation) and (createinfo^[i].index<>lastinfo) do inc(i);\r
+   if createinfo^[i].parts[part]>4999 then exit;\r
+   HistoryPush(lastinfo);\r
+   setpartcursor(createinfo^[i].parts[part])\r
+ {j:=1;\r
+ while (j<maxcreation) and (createinfo^[j].index<>createinfo^[i].parts[part]) do inc(j);\r
+ cargoindex:=j;\r
+ anychange:=true;}\r
+end; { setinfocursor }\r
+\r
+procedure findcreationmouse;\r
+begin\r
+ if not mouse.getstatus then exit;\r
+ case mouse.x of\r
+    10..19: case mouse.y of\r
+              3..10: begin\r
+                      deccursor;\r
+                      if cargoindex<1 then inccursor;\r
+                     end;\r
+             11..18: if cargomode=0 then\r
+                      begin\r
+                       inccursor;\r
+                       if cargoindex>maxcreation then deccursor;\r
+                      end\r
+                     else\r
+                      begin\r
+                       inccursor;\r
+                       if cargoindex>250 then deccursor;\r
+                      end;\r
+              22..118: findcursor;\r
+             122..129: setfilter(1);\r
+             133..140: setfilter(2);\r
+             144..151: setfilter(3);\r
+            end;\r
+    20..31: case mouse.y of\r
+                3..18: if qmode then\r
+                        begin\r
+                         qmode:=false;\r
+                         mousehide;\r
+                         for i:=6 to 14 do\r
+                          begin\r
+                           screen[i,34]:=95;\r
+                           screen[i,33]:=95;\r
+                          end;\r
+                         mouseshow;\r
+                        end\r
+                       else\r
+                        begin\r
+                         qmode:=true;\r
+                         mousehide;\r
+                         for i:=6 to 14 do\r
+                          begin\r
+                           screen[i,34]:=63;\r
+                           screen[i,33]:=63;\r
+                          end;\r
+                         mouseshow;\r
+                         anychange:=true;\r
+                        end;\r
+              22..118: findcursor;\r
+             123..129: setfilter(1);\r
+             133..140: setfilter(2);\r
+             144..151: setfilter(3);\r
+            end;\r
+    32..37: case mouse.y of\r
+              22..118: findcursor;\r
+             122..129: setfilter(1);\r
+             133..140: setfilter(2);\r
+             144..151: setfilter(3);\r
+            end;\r
+    38..48: case mouse.y of\r
+              3..10: setdevicemode;\r
+              11..18: setcargomode;\r
+              22..118: findcursor;\r
+             122..129: setfilter(1);\r
+             133..140: setfilter(2);\r
+             144..151: setfilter(3);\r
+            end;\r
+    49..92: case mouse.y of\r
+                3..10: setdevicemode;\r
+               11..18: setcargomode;\r
+              22..118: findcursor;\r
+             122..129: if (mouse.x>70) then setcolorcode;\r
+            end;\r
+    93..99: case mouse.y of\r
+              22..118: findcursor;\r
+             122..129: setcolorcode;\r
+            end;\r
+  100..110: case mouse.y of\r
+                3..18: done:=true;\r
+              22..118: findcursor;\r
+             122..129: setcolorcode;\r
+            end;\r
+  120..125: case mouse.y of\r
+             44..49: setinfocursor(1);\r
+             65..70: setinfocursor(2);\r
+             86..91: setinfocursor(3);\r
+            end;\r
+  130..151: case mouse.y of\r
+    40..53: setinfocursor(1);\r
+    61..74: setinfocursor(2);\r
+    82..95: setinfocursor(3);\r
+  end;    \r
+  152..212: case mouse.y of\r
+    40..53: setinfocursor(1);\r
+    61..74: setinfocursor(2);\r
+    82..95: setinfocursor(3);\r
+             120..128: go(1);\r
+             130..138: go(2);\r
+             140..148: go(3);\r
+            end;\r
+  221..299: case mouse.y of\r
+    59..72: setpartcursor(HistoryPop);\r
+  end;\r
+ end;\r
+ idletime:=0;\r
+end;\r
+\r
+procedure processcreationkey;\r
+var ans: char;\r
+begin\r
+ ans:=readkey;\r
+ case upcase(ans) of\r
+  #0: begin\r
+       ans:=readkey;\r
+       case ans of\r
+        #80: if cargomode=0 then\r
+              begin\r
+               inccursor;\r
+               if cargoindex>maxcreation then deccursor;\r
+              end\r
+             else\r
+              begin\r
+               inccursor;\r
+               if cargoindex>250 then deccursor;\r
+              end;\r
+        #72: begin\r
+              deccursor;\r
+              if cargoindex<1 then inccursor;\r
+             end;\r
+        #81: begin {pgdn}\r
+              mouse.y:=113;\r
+              findcursor;\r
+             end;\r
+        #73: begin {pgup}\r
+              mouse.y:=22;\r
+              findcursor;\r
+             end;\r
+       end;\r
+      end;\r
+ #59: setdevicemode;\r
+ #60: setcargomode;\r
+  '1': begin\r
+        if filters[1]=0 then filters[1]:=1 else filters[1]:=0;\r
+        dec(cargoindex);\r
+        inccursor;\r
+       end;\r
+  '2': begin\r
+        if filters[2]=0 then filters[2]:=1 else filters[1]:=0;\r
+        dec(cargoindex);\r
+        inccursor;\r
+       end;\r
+  '3': begin\r
+        if filters[3]=0 then filters[3]:=1 else filters[1]:=0;\r
+        dec(cargoindex);\r
+        inccursor;\r
+       end;\r
+  '?','/': if qmode then\r
+        begin\r
+         qmode:=false;\r
+         mousehide;\r
+         for i:=6 to 14 do\r
+          begin\r
+           screen[i,34]:=95;\r
+           screen[i,33]:=95;\r
+          end;\r
+         mouseshow;\r
+        end\r
+       else\r
+        begin\r
+         qmode:=true;\r
+         mousehide;\r
+         for i:=6 to 14 do\r
+          begin\r
+           screen[i,34]:=63;\r
+           screen[i,33]:=63;\r
+          end;\r
+         mouseshow;\r
+         anychange:=true;\r
+        end;\r
+  #27: done:=true;\r
+  'Q': go(1);\r
+  'W': go(2);\r
+  'E': go(3);\r
+  '`': bossmode;\r
+  'C': setcolorcode;\r
+  #13: if cargomode=0 then setdevicemode else setcargomode;\r
+  #10: printbigbox(GetHeapStats1,GetHeapStats2);\r
+ end;\r
+ clearkbbuffer;\r
+ idletime:=0;\r
+end;\r
+\r
+procedure adjuststatlights;\r
+begin\r
+ t1:=t1+0.45;\r
+ if t1=6.28 then t1:=0;\r
+ mousehide;\r
+ for a:=0 to 4 do\r
+  begin\r
+   j:=abs(round(5*sin(t1+a/2)));\r
+   x:=31-a;\r
+   for i:=0 to j do\r
+    begin\r
+     dec(x,2);\r
+     screen[134-i,a*3+219]:=x;\r
+     screen[134-i,a*3+220]:=x;\r
+    end;\r
+   if j<5 then for\r
+    i:=j to 5 do\r
+     begin\r
+      screen[134-i,a*3+219]:=0;\r
+      screen[134-i,a*3+220]:=0;\r
+     end;\r
+  end;\r
+ mouseshow;\r
+end;\r
+\r
+procedure maincreationloop;\r
+begin\r
+   repeat\r
+      fadestep(8);\r
+      findcreationmouse;\r
+      if fastkeypressed then processcreationkey;\r
+      inc(idletime);\r
+      if idletime=maxidle then screensaver;\r
+      if batindex<8 then inc(batindex) else\r
+      begin\r
+        batindex:=0;\r
+        addtime2;\r
+      end;\r
+      adjuststatlights;\r
+      if viewteam>0 then displayteaminfo(viewteam) else adjustteams;\r
+      if anychange then\r
+      begin\r
+        if cargomode=0 then displaydevices else displaycargo;\r
+      end;\r
+      delay(tslice*2);\r
+   until done=true;\r
+end;\r
+\r
+procedure creation;\r
+begin\r
+   if (filters[1] = 0) and (filters[2] = 0) and (filters[3] = 0) then\r
+   begin\r
+      for j:=1 to 3 do filters[j]:=1;\r
+   end;\r
+   readycreationdata;\r
+   displaydevices;\r
+   maincreationloop;\r
+   dispose(createinfo);\r
+   dispose(iteminfo);\r
+   {stopmod;}\r
+   removedata;\r
+end;\r
+\r
+begin\r
+ for j:=1 to 4 do filters2[j]:=1;\r
+ qmode:=true;\r
+ for j:=1 to 3 do filters[j]:=1;\r
+ colorcode:=true;\r
+end.\r
diff --git a/code/combat.pas b/code/combat.pas
new file mode 100644 (file)
index 0000000..c724a23
--- /dev/null
@@ -0,0 +1,1504 @@
+unit combat;\r
+(********************************************************************\r
+    This file is part of Ironseed.\r
+\r
+    Ironseed is free software: you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation, either version 3 of the License, or\r
+    (at your option) any later version.\r
+\r
+    Ironseed is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with Ironseed.  If not, see <http://www.gnu.org/licenses/>.\r
+********************************************************************)\r
+\r
+{***************************\r
+   Battle/Combat unit for IronSeed\r
+\r
+   Channel 7\r
+   Destiny: Virtual\r
+\r
+\r
+   Copyright 1994\r
+\r
+***************************}\r
+\r
+{$O+}\r
+\r
+interface\r
+\r
+procedure initiatecombat;\r
+\r
+implementation\r
+\r
+uses crt, graph, data, gmouse, utils, utils2, modplay, weird, saveload, usecode, crewtick;\r
+\r
+const\r
+ maxships = 25;\r
+ maxformations = 3;\r
+ shipclass : array[0..14] of string[14] =\r
+  ('Shuttle       ','Scout         ','Fighter       ','Assault Scout ',\r
+   'Patrol Craft  ','Corvette      ','Frigate       ','Lt. Destroyer ',\r
+   'Hv. Destroyer ','Lt. Cruiser   ','Hv. Cruiser   ','Battle Cruiser',\r
+   'Flagship      ','Battleship    ','Dreadnaught   ');\r
+ formation : array[0..maxformations-1,0..4,1..3] of integer =\r
+  (\r
+   ((0,0,0),(-3000,0,0),(3000,0,0),(0,-3000,0),(0,3000,0)),               { planar plus }\r
+   ((0,0,0),(-3000,-3000,0),(3000,3000,0),(-3000,3000,0),(3000,-3000,0)), { planar cross}\r
+   ((0,0,0),(1000,0,1000),(2000,0,2000),(3000,0,3000),(4000,0,4000))      { 3d slash }\r
+   );\r
+type\r
+ alienshiparray= array[1..maxships] of alienshiptype;\r
+ statpictype= array[0..1,0..11] of byte;\r
+ alienshipdisplay= array[125..189,6..98] of byte;\r
+ barpictype= array[0..3,0..3] of byte;\r
+ shieldpictype= array[0..6,0..3] of byte;\r
+ msgtype= array[0..9,0..9] of byte;\r
+ msgarray= array[0..3] of msgtype;\r
+var\r
+ oldshddmg,i,a,b,nships,targetindex,fireweapon,moveindex,picx,picy: integer;\r
+ range: longint;\r
+ scanning,autofire,engaging,alienpicmode,dead: boolean;\r
+ poweredup: array[1..10] of integer;\r
+ userpowerup: array[1..10] of boolean;\r
+ ships: ^alienshiparray;\r
+ statpic,blank: ^statpictype;\r
+ stats: array[1..3] of byte;\r
+ part,r: real;\r
+ asdisplay: ^alienshipdisplay;\r
+ str1: string[10];\r
+ shieldpic,shieldpic2: ^shieldpictype;\r
+ alienname: string[12];\r
+ shipdir,shipdir2: integer;\r
+ msgs: ^msgarray;\r
+ learnchance:Integer;\r
+\r
+{*******************************************************************************}\r
+\r
+procedure displaystats;\r
+var i: integer;\r
+begin\r
+ if done then exit;\r
+ mousehide;\r
+ part:=102/ship.hullmax*ship.hulldamage;\r
+ if round(part)<>stats[1] then\r
+  begin\r
+   for i:=0 to 1 do\r
+    move(blank^[i],screen[117-stats[1]+i,269],10);\r
+   stats[1]:=round(part);\r
+   y:=117-round(part);\r
+   for i:=0 to 1 do\r
+    move(statpic^[i],screen[y+i,269],10);\r
+   end;\r
+ part:=102/32000*ship.battery;\r
+ if round(part)<>stats[2] then\r
+  begin\r
+   for i:=0 to 1 do\r
+    move(blank^[i],screen[117-stats[2]+i,285],10);\r
+   stats[2]:=round(part);\r
+   y:=117-round(part);\r
+   for i:=0 to 1 do\r
+    move(statpic^[i],screen[y+i,285],10);\r
+  end;\r
+ part:=102/100*ship.shieldlevel;\r
+ if round(part)<>stats[3] then\r
+  begin\r
+   for i:=0 to 1 do\r
+    move(blank^[i],screen[117-stats[3]+i,301],10);\r
+   stats[3]:=round(part);\r
+   y:=117-round(part);\r
+   for i:=0 to 1 do\r
+    move(statpic^[i],screen[y+i,301],10);\r
+  end;\r
+ mouseshow;\r
+end;\r
+\r
+procedure displayshieldpic(n: integer);\r
+begin\r
+ mousehide;\r
+ part:=102/100*ship.shieldopt[3];\r
+ for i:=0 to 6 do\r
+  fillchar(screen[114-round(part)+i,312],4,0);\r
+ if n>100-ship.damages[2] then n:=100-ship.damages[2];\r
+ ship.shieldopt[3]:=n;\r
+ part:=102/100*ship.shieldopt[3];\r
+ for i:=0 to 6 do\r
+  mymove(shieldpic^[i],screen[114-round(part)+i,312],1);\r
+ mouseshow;\r
+end;\r
+\r
+procedure displaytargetinfo2;\r
+var str1 : string[8];\r
+   j    : Integer;\r
+begin\r
+ mousehide;\r
+ with ships^[targetindex] do\r
+  begin\r
+   printxy(4,125,alienname);\r
+   b:=ships^[targetindex].maxhull;\r
+   if b<1000 then b:=b div 100\r
+   else b:=((b-1000) div 1600) + 9;\r
+   printxy(4,131,shipclass[b]+' '+chr(64+targetindex));\r
+   str(r:8:1,str1);\r
+   printxy(4,137,'Range: '+str1+' KM');\r
+   printxy(4,143,'Tech Level: '+chr(hi(techlevel)+48)+'.'+chr(lo(techlevel)+48));\r
+   str(ships^[targetindex].accelmax,str1);\r
+   printxy(4,149,'Accel: '+str1);\r
+   if picx>139 then j:=10 else j:=5;\r
+   if picy>=179 then a:=19 else a:=20;\r
+   for i:=0 to a do\r
+    mymove(backgr^[i+picy,picx],screen[161+i,14],j);\r
+   if j=5 then\r
+    for i:=0 to 19 do\r
+     fillchar(screen[161+i,34],20,0);\r
+   for j:=0 to 1 do\r
+    begin\r
+     a:=random(2);\r
+     for i:=0 to 9 do\r
+      move(msgs^[a,i],screen[162+i+j*10,60],10);\r
+    end;\r
+   for j:=0 to 1 do\r
+    begin\r
+     a:=random(2);\r
+     for i:=0 to 9 do\r
+      move(msgs^[a,i],screen[162+i+j*10,70],10);\r
+    end;\r
+   for j:=0 to 1 do\r
+    begin\r
+     a:=random(2)+2;\r
+     for i:=0 to 9 do\r
+      move(msgs^[a,i],screen[162+i+j*10,80],10);\r
+    end;\r
+  end;\r
+ mouseshow;\r
+end;\r
+\r
+procedure givedamage(n,d: integer);\r
+var j: integer;\r
+begin\r
+ d:=round(d/100*(100-ship.damages[3]));\r
+ if d<1 then d:=1;\r
+ with ships^[targetindex] do\r
+  begin\r
+   case n of\r
+    1: inc(damages[5],d);\r
+    2: dec(hulldamage,d);\r
+    3: dec(hulldamage,d div 2);\r
+    4: case random(8) of\r
+        0: inc(damages[1],d);\r
+        1: inc(damages[2],d);\r
+        2: inc(damages[3],d);\r
+        3: inc(damages[4],d);\r
+        4: inc(damages[6],d);\r
+        5: inc(damages[7],d);\r
+        6,7: dec(hulldamage,d);\r
+       end;\r
+    5: inc(damages[2],d);\r
+   end;\r
+   if hulldamage<0 then hulldamage:=0;\r
+   for j:=1 to 7 do if damages[j]>100 then damages[j]:=100;\r
+   if shieldlevel<0 then shieldlevel:=0;\r
+   if shield=1501 then shieldlevel:=damages[2];\r
+   if damages[5]=100 then hulldamage:=0;\r
+  end;\r
+end;\r
+\r
+procedure displaymap; forward;\r
+\r
+procedure firingweapon(n: integer);\r
+var j,i,a,b,c,d: integer;\r
+begin\r
+ c:=ship.gunnodes[n];\r
+ case weapons[c].dmgtypes[4] of\r
+   0..23: if weapons[c].dmgtypes[2]>weapons[c].dmgtypes[3] then soundeffect('gun4.sam',7000)\r
+           else soundeffect('gun1.sam',7000);\r
+   24..34: soundeffect('laser1.sam',7000);\r
+   35..45: soundeffect('laser2.sam',7000);\r
+   46..56: soundeffect('laser3.sam',7000);\r
+   57..67: soundeffect('laser4.sam',7000);\r
+   68..78: soundeffect('laser5.sam',7000);\r
+   79..89: soundeffect('laser6.sam',7000);\r
+   90..100: soundeffect('laser7.sam',7000);\r
+ end;\r
+ delay(tslice);\r
+ {if (skillcheck(4)) or ((scanning) and (random(100)<20)) then}\r
+ if SkillTest(True, 4, ships^[targetindex].skill - (ord(scanning) * 20), learnchance) then\r
+  begin\r
+   b:=ships^[targetindex].shield-1442;\r
+   for j:=1 to 4 do if weapons[c].dmgtypes[j]>0 then\r
+    begin\r
+     i:=round(weapons[c].dmgtypes[j]/100*weapons[c].damage*5);\r
+     if ships^[targetindex].shieldlevel=0 then givedamage(j,i)\r
+     else\r
+      begin\r
+       a:=round(weapons[b].dmgtypes[j]/100*weapons[b].damage*ships^[targetindex].shieldlevel/100);\r
+       if a<i then\r
+        begin\r
+         givedamage(j,i-a);\r
+         ships^[targetindex].shieldlevel:=1;\r
+         if ships^[targetindex].shield=1501 then ships^[targetindex].damages[2]:=100;\r
+        end\r
+       else\r
+        begin\r
+         part:=i/ships^[targetindex].shieldlevel;\r
+         part:=part*(1/weapons[b].damage);\r
+         part:=part*100;\r
+         a:=round(part*100);\r
+         d:=ships^[targetindex].shieldlevel-a;\r
+         if d<0 then\r
+          begin\r
+           givedamage(5,random(4)+1);\r
+           if ships^[targetindex].shield=1501 then\r
+            ships^[targetindex].damages[2]:=100;\r
+           ships^[targetindex].shieldlevel:=1;\r
+          end\r
+         else\r
+          begin\r
+           ships^[targetindex].shieldlevel:=d;\r
+           if ships^[targetindex].shield=1501 then\r
+            ships^[targetindex].damages[2]:=100-d;\r
+          end;\r
+        end;\r
+      end;\r
+    end;\r
+  end;\r
+ if ships^[targetindex].hulldamage=0 then\r
+  begin\r
+   ships^[targetindex].hulldamage:=1;\r
+   displaymap;\r
+   ships^[targetindex].hulldamage:=0;\r
+   targetindex:=1;\r
+   while (targetindex<=nships) and (ships^[targetindex].hulldamage=0) do inc(targetindex);\r
+   if targetindex>nships then done:=true;\r
+   with ships^[targetindex] do\r
+    begin\r
+     r:=sqr(relx/10);\r
+     r:=r+sqr(rely/10);\r
+     r:=r+sqr(relz/10);\r
+     r:=sqrt(r)*100;\r
+    end;\r
+   displaymap;\r
+  end;\r
+ poweredup[n]:=0;\r
+ fireweapon:=0;\r
+end;\r
+\r
+procedure powerup;\r
+var i,j: integer;\r
+begin\r
+ for j:=1 to 10 do\r
+  if (poweredup[j]>-1) and (poweredup[j]<100) then\r
+   begin\r
+    if (userpowerup[j]) and (poweredup[j]=0) and (ship.battery>=weapons[ship.gunnodes[j]].energy) then\r
+     begin\r
+      dec(ship.battery,weapons[ship.gunnodes[j]].energy);\r
+      poweredup[j]:=1;\r
+     end\r
+    else if poweredup[j]>0 then inc(poweredup[j]);\r
+    i:=round(poweredup[j]*0.31);\r
+    if i<16 then setcolor(80+i) else setcolor(32+i);\r
+    x:=((j-1) mod 5)*23+105;\r
+    y:=((j-1) div 5)*31+131;\r
+    mousehide;\r
+    rectangle(x,y,x+20,y+20);\r
+    mouseshow;\r
+   end\r
+  else if poweredup[j]=100 then\r
+    begin\r
+     part:=weapons[ship.gunnodes[j]].range;\r
+     if part>=r then setcolor(47) else setcolor(63);\r
+     x:=((j-1) mod 5)*23+105;\r
+     y:=((j-1) div 5)*31+131;\r
+     mousehide;\r
+     rectangle(x,y,x+20,y+20);\r
+     mouseshow;\r
+     if (part>=r) and ((autofire) or (fireweapon=j)) then firingweapon(j);\r
+   end;\r
+ if (ship.battery>0) and (ship.shieldlevel<ship.shieldopt[3]) then inc(ship.shieldlevel)\r
+  else if (ship.battery=0) and (ship.shieldlevel>0) then dec(ship.shieldlevel)\r
+  else if (Ship.shieldlevel>ship.shieldopt[3]) then dec(ship.shieldlevel);\r
+ for j:=1 to nships do\r
+  with ships^[j] do\r
+   begin\r
+    if shield>1501 then\r
+     begin\r
+      r:=sqr(relx/10);\r
+      r:=r+sqr(rely/10);\r
+      r:=r+sqr(relz/10);\r
+      r:=sqrt(r)*100;\r
+      i:=round(weapons[shield-1442].energy*shieldlevel/100);\r
+      if (battery>0) and (abs(r)<390000) and (shieldlevel<(100-damages[2])) then inc(shieldlevel)\r
+       else if ((battery=0) or (abs(r)>400000)) and (shieldlevel>0) then dec(shieldlevel)\r
+       else if shieldlevel>(100-damages[2]) then dec(shieldlevel);\r
+      if (abs(r)>230000) and (abs(r)<400000) and (i>round(regen*(100-damages[1])/100))\r
+       and (shieldlevel>2) then dec(shieldlevel,3);\r
+     end;\r
+    for i:=1 to 20 do\r
+       if charges[i]<100 then\r
+       begin\r
+         if (charges[i]=0) and (battery>=weapons[maxweapons].energy) then\r
+         begin\r
+            dec(battery,weapons[maxweapons].energy);\r
+            charges[i]:=1;\r
+         end\r
+         else if charges[i]>0 then inc(charges[i]);\r
+       end;\r
+   end;\r
+end;\r
+\r
+procedure showweaponicon(x1,y1,weap,node: integer);\r
+var j,i: integer;\r
+begin\r
+ if weap=0 then\r
+  begin\r
+   for i:=0 to 19 do\r
+    fillchar(screen[y1+i,x1],20,3);\r
+   exit;\r
+  end;\r
+ readweaicon(weap-1);\r
+ node:=4;\r
+ case node of\r
+  1,2,3,8: for i:=0 to 19 do\r
+            for j:=0 to 19 do\r
+             screen[y1+j,x1+i]:=tempicon^[i,j];\r
+  4,6: for i:=0 to 19 do\r
+        mymove(tempicon^[i],screen[y1+i,x1],5);\r
+  5,7: for i:=0 to 19 do\r
+        mymove(tempicon^[19-i],screen[y1+i,x1],5);\r
+  9,10: for i:=0 to 19 do\r
+         for j:=0 to 19 do\r
+          screen[y1+j,x1+20-i]:=tempicon^[i,j];\r
+ end;\r
+end;\r
+\r
+procedure displayweapons;\r
+var\r
+   j : Integer;\r
+begin\r
+ mousehide;\r
+ for j:=1 to 10 do\r
+   begin\r
+    x:=((j-1) mod 5)*23+105;\r
+    y:=((j-1) div 5)*31+131;\r
+    showweaponicon(x,y,ship.gunnodes[j],j);\r
+    if ship.gunnodes[j]>0 then\r
+     begin\r
+      a:=round(poweredup[j]*0.31);\r
+      if a<16 then setcolor(80+a) else setcolor(32+a);\r
+      rectangle(x,y,x+20,y+20);\r
+     end;\r
+   end;\r
+ mouseshow;\r
+end;\r
+\r
+procedure displaydamage;\r
+var a,b,i,j: integer;\r
+begin\r
+ if (done) or (dead) then exit;\r
+ mousehide;\r
+ for a:=1 to 7 do\r
+  begin\r
+   b:=round((100-ship.damages[a])/100*49);\r
+   if b<=0 then b:=1;\r
+   part:=31/b;\r
+   for j:=0 to b do\r
+    begin\r
+     screen[a*9+127,267+j]:=round(j*part);\r
+     screen[a*9+128,267+j]:=round(j*part);\r
+    end;\r
+   if b<51 then\r
+    begin\r
+     fillchar(screen[a*9+127,268+b],49-b,0);\r
+     fillchar(screen[a*9+128,268+b],49-b,0);\r
+    end;\r
+  end;\r
+ if 100-ship.damages[2]<ship.shieldopt[3] then displayshieldpic(100-ship.damages[2]);\r
+ part:=114-(102/100*(100-ship.damages[2]));\r
+ if round(part)<>oldshddmg then\r
+  begin\r
+   for i:=0 to 6 do\r
+    fillchar(screen[oldshddmg+i,296],4,0);\r
+   for i:=0 to 6 do\r
+    mymove(shieldpic2^[i],screen[round(part)+i,296],1);\r
+   oldshddmg:=round(part);\r
+  end;\r
+ mouseshow;\r
+end;\r
+\r
+procedure suckpower;\r
+var\r
+   j : Integer;\r
+begin\r
+ if ship.shield>1501 then\r
+  ship.battery:=ship.battery-round(weapons[ship.shield-1442].energy/100*ship.shieldlevel);\r
+ i:=round((100-ship.damages[1])/4);\r
+ if i=0 then i:=1;\r
+ ship.battery:=ship.battery+i;\r
+ if ship.battery<0 then ship.battery:=0\r
+  else if ship.battery>32000 then ship.battery:=32000;\r
+ for j:=1 to nships do if ships^[j].hulldamage>0 then\r
+  with ships^[j] do\r
+   begin\r
+    if shield>1501 then dec(battery,round(weapons[shield-1442].energy/100*shieldlevel));\r
+    inc(battery,round(regen*(100-damages[1])/100));\r
+    if battery<0 then battery:=0\r
+     else if battery>32000 then battery:=32000;\r
+    if (battery=0) and (shield>1501) and (damages[2]<99) then inc(damages[2],2);\r
+   end;\r
+end;\r
+\r
+procedure displaytargetinfo;\r
+var b : integer;\r
+   j  : Integer;\r
+begin\r
+ if done then exit;\r
+ with ships^[targetindex] do\r
+  begin\r
+   r:=sqr(relx/10);\r
+   r:=r+sqr(rely/10);\r
+   r:=r+sqr(relz/10);\r
+   r:=sqrt(r)*100;\r
+  end;\r
+ if alienpicmode then\r
+  begin\r
+   displaytargetinfo2;\r
+   exit;\r
+  end;\r
+ mousehide;\r
+ with ships^[targetindex] do\r
+  begin\r
+   r:=sqr(relx/10);\r
+   r:=r+sqr(rely/10);\r
+   r:=r+sqr(relz/10);\r
+   r:=sqrt(r)*100;\r
+   b:=maxhull;\r
+   if b<1000 then b:=b div 100\r
+   else b:=((b-1000) div 1600) + 9;\r
+   printxy(4,126,shipclass[b]+' '+chr(64+targetindex));\r
+   b:=round(hulldamage/maxhull*49);\r
+   if b<=0 then b:=1;\r
+   part:=31/b;\r
+   for i:=0 to b do\r
+    fillchar(screen[i+138,8],8,round(i*part));\r
+   if b<49 then\r
+    for i:=b+1 to 49 do\r
+     fillchar(screen[i+138,8],8,0);\r
+   b:=round((100-damages[5])/100*49);\r
+   if b<=0 then b:=1;\r
+   part:=31/b;\r
+   for i:=0 to b do\r
+    fillchar(screen[i+138,23],8,round(i*part));\r
+   if b<49 then\r
+    for i:=b+1 to 49 do\r
+     fillchar(screen[i+138,23],8,0);\r
+   b:=round(battery/32000*49);\r
+   if b<=0 then b:=1;\r
+   part:=31/b;\r
+   for i:=0 to b do\r
+    fillchar(screen[i+138,38],9,round(i*part));\r
+   if b<49 then\r
+    for i:=b+1 to 49 do\r
+     fillchar(screen[i+138,38],9,0);\r
+   b:=round(shieldlevel/100*49);\r
+   if b<=0 then b:=1;\r
+   part:=31/b;\r
+   for i:=0 to b do\r
+    fillchar(screen[i+138,54],8,round(i*part));\r
+   if b<49 then\r
+    for i:=b+1 to 49 do\r
+     fillchar(screen[i+138,54],8,0);\r
+   for j:=1 to 7 do\r
+    begin\r
+     b:=round((100-damages[j])/100*49);\r
+     if b<=0 then b:=1;\r
+     part:=31/b;\r
+     for i:=0 to b do\r
+      screen[i+138,62+5*j]:=round(i*part);\r
+     if b<49 then\r
+      for i:=b+1 to 49 do\r
+       screen[i+138,62+5*j]:=0;\r
+    end;\r
+  end;\r
+ mouseshow;\r
+end;\r
+\r
+procedure displaymap;\r
+var\r
+   j : Integer;\r
+begin\r
+ if dead then exit;\r
+ mousehide;\r
+ for j:=1 to nships do\r
+  begin\r
+   y:=round(ships^[j].rely/range*26.66);\r
+   x:=round(ships^[j].relx/range*119);\r
+   z:=round(ships^[j].relz/range*26);\r
+   if (abs(x)<119) and (abs(y)<26) and (abs(z)<40) then\r
+    begin\r
+     if z<0 then\r
+      for i:=y+62 to y+62-z do\r
+       screen[i,x+132]:=screen[i,x+132] xor 6\r
+     else\r
+      for i:=y+62 downto y+62-z do\r
+       screen[i,x+132]:=screen[i,x+132] xor 6;\r
+     screen[y+62,x+132]:=screen[y+62,x+132] xor 85;\r
+     if ships^[j].hulldamage=0 then i:=12 else i:=31;\r
+     screen[y+62-z,x+132]:=screen[y+62-z,x+132] xor i;\r
+     if j=targetindex then\r
+      begin\r
+       screen[y+62-z-2,x+132-2]:=screen[y+62-z-2,x+132-2] xor 60;\r
+       screen[y+62-z-2,x+132-1]:=screen[y+62-z-2,x+132-1] xor 60;\r
+       screen[y+62-z-1,x+132-2]:=screen[y+62-z-1,x+132-2] xor 60;\r
+       screen[y+62-z+2,x+132+1]:=screen[y+62-z+2,x+132+1] xor 60;\r
+       screen[y+62-z+2,x+132+2]:=screen[y+62-z+2,x+132+2] xor 60;\r
+       screen[y+62-z+1,x+132+2]:=screen[y+62-z+1,x+132+2] xor 60;\r
+      end;\r
+    end;\r
+  end;\r
+ mouseshow;\r
+end;\r
+\r
+procedure drawdirection(c: integer);\r
+begin\r
+ x:=((shipdir-1) mod 3)*12+225;\r
+ y:=((shipdir-1) div 3)*10+88;\r
+ setcolor(c);\r
+ mousehide;\r
+ rectangle(x,y,x+12,y+10);\r
+ if shipdir2=1 then rectangle(249,68,261,78)\r
+  else if shipdir2=2 then rectangle(249,78,261,88);\r
+ mouseshow;\r
+end;\r
+\r
+procedure takedamage(n,d: integer);\r
+var j: integer;\r
+begin\r
+ if dead then exit;\r
+ soundeffect('explode'+chr(49+random(2))+'.sam',9000);\r
+ delay(tslice div 2);\r
+ if d<1 then d:=1;\r
+ case n of\r
+  1: inc(ship.damages[5],d);\r
+  2: dec(ship.hulldamage,d);\r
+  3: dec(ship.hulldamage,d div 2);\r
+  4: case random(8) of\r
+      0: inc(ship.damages[1],d);\r
+      1: begin\r
+          if ship.damages[2]+d>135 then ship.shield:=0;\r
+          inc(ship.damages[2],d);\r
+         end;\r
+      2: begin\r
+          inc(ship.damages[4],d);\r
+          if ship.damages[4]>89 then drawdirection(95);\r
+         end;\r
+      3: begin\r
+          if ship.damages[3]+d>120 then\r
+           begin\r
+            j:=random(10)+1;\r
+            if ship.gunnodes[j]>0 then\r
+             begin\r
+              ship.gunnodes[j]:=0;\r
+              poweredup[j]:=-1;\r
+              displayweapons;\r
+             end;\r
+           end;\r
+          inc(ship.damages[3],d);\r
+         end;\r
+      4: inc(ship.damages[6],d);\r
+      5: inc(ship.damages[7],d);\r
+      6,7: dec(ship.hulldamage,d);\r
+     end;\r
+  5: inc(ship.damages[2],d);\r
+ end;\r
+ for j:=1 to 7 do if ship.damages[j]>100 then ship.damages[j]:=100;\r
+ if ship.hulldamage<0 then ship.hulldamage:=0;\r
+ displaydamage;\r
+ if ship.hulldamage=0 then\r
+  begin\r
+    if ship.wandering.alienid = 1013 then\r
+    begin\r
+       stopmod;\r
+       blast(63,0,0);\r
+       fadestopmod(-8, 20);\r
+    end else begin\r
+       deathsequence(0);\r
+    end;\r
+   done:=true;\r
+   dead:=true;\r
+   {quit:=true;}\r
+  end\r
+ else if ship.damages[5]=100 then\r
+  begin\r
+    if ship.wandering.alienid = 1013 then\r
+    begin\r
+       stopmod;\r
+       blast(63,0,0);\r
+       fadestopmod(-8, 20);\r
+    end else begin\r
+       deathsequence(1);\r
+    end;\r
+   done:=true;\r
+   dead:=true;\r
+   {quit:=true;}\r
+  end;\r
+ if ship.shield=1501 then ship.shieldlevel:=ship.damages[2];\r
+end;\r
+\r
+procedure impact(s,n: integer);\r
+var a,b,c,j,i: integer;\r
+begin\r
+ b:=ship.shield-1442;\r
+ for j:=1 to 4 do if weapons[n].dmgtypes[j]>0 then\r
+  begin\r
+   i:=round(weapons[n].dmgtypes[j]/100*weapons[n].damage*5);\r
+   i:=round(i/100*(100-ships^[s].damages[3]));\r
+   if ship.shieldlevel=0 then takedamage(j,i)\r
+   else\r
+    begin\r
+     a:=round(weapons[b].dmgtypes[j]/100*weapons[b].damage*ship.shieldlevel/100);\r
+     if a<i then\r
+      begin\r
+       takedamage(j,i);{round((i-a)/100*(100-ships^[s].damages[3])));}\r
+       ship.shieldlevel:=0;\r
+       if ship.shield=1501 then ship.damages[2]:=100;\r
+      end\r
+     else\r
+      begin\r
+       a:=round((i/(ship.shieldlevel/100*weapons[b].damage)*100));\r
+       c:=ship.shieldlevel-a;\r
+       if c<0 then\r
+        begin\r
+         takedamage(5,random(3)+1);\r
+         if ship.shield=1501 then\r
+          begin\r
+           ship.damages[2]:=100;\r
+           displaydamage;\r
+          end;\r
+         ship.shieldlevel:=1;\r
+        end\r
+       else\r
+        begin\r
+         ship.shieldlevel:=c;\r
+         if ship.shield=1501 then\r
+          begin\r
+           ship.damages[2]:=100-c;\r
+           displaydamage;\r
+          end;\r
+        end;\r
+      end;\r
+    end;\r
+  end;\r
+ displaystats;\r
+end;\r
+\r
+procedure moveships;\r
+var r: real;\r
+    a,j,i: integer;\r
+begin\r
+ for j:=1 to nships do\r
+  with ships^[j] do\r
+  begin\r
+   if (moveindex=5) and (hulldamage>0) and (damages[4]<90) then\r
+    begin\r
+     if (relx<5000) and (relx>0) and (dx<-3000) then inc(dx,accelmax)\r
+      else if (relx>-5000) and (relx<0) and (dx>3000) then dec(dx,accelmax)\r
+      else if (relx>0) and (dx>-1000) then dec(dx,accelmax)\r
+      else if (relx<0) and (dx<1000) then inc(dx,accelmax);\r
+     if (rely<5000) and (rely>0) and (dy<-3000) then inc(dy,accelmax)\r
+      else if (rely>-5000) and (rely<0) and (dy>3000) then dec(dy,accelmax)\r
+      else if (rely>0) and (dy>-1000) then dec(dy,accelmax)\r
+      else if (rely<0) and (dy<1000) then inc(dy,accelmax);\r
+     if (relz<5000) and (relz>0) and (dz<-3000) then inc(dz,accelmax)\r
+      else if (relz>-5000) and (relz<0) and (dz>3000) then dec(dz,accelmax)\r
+      else if (relz>0) and (dz>-1000) then dec(dz,accelmax)\r
+      else if (relz<0) and (dz<1000) then inc(dz,accelmax);\r
+    end;\r
+   if (moveindex=5) and (hulldamage>0) and (damages[4]>90) then\r
+   begin\r
+      dx := round(dx * 0.9);\r
+      dy := round(dy * 0.9);\r
+      dz := round(dz * 0.9);\r
+   end;\r
+   relx:=relx+round(dx/5);\r
+   rely:=rely+round(dy/5);\r
+   relz:=relz+round(dz/5);\r
+   r:=sqr(relx/10);\r
+   r:=r+sqr(rely/10);\r
+   r:=r+sqr(relz/10);\r
+   r:=sqrt(r)*100;\r
+   a:=ship.accelmax;\r
+   if ship.damages[4]>89 then a:=a div 4;\r
+   if shipdir<4 then rely:=rely+a\r
+    else if shipdir>6 then rely:=rely-a;\r
+   if shipdir mod 3=1 then relx:=relx+a\r
+    else if shipdir mod 3=0 then relx:=relx-a;\r
+   if shipdir2=1 then relz:=relz-a\r
+    else if shipdir2=2 then relz:=relz+a;\r
+   part:=ships^[j].range;\r
+   if hulldamage>0 then\r
+    for a:=1 to 20 do\r
+     if (charges[a]=100) then\r
+      begin\r
+       if part>=r then\r
+        begin\r
+         i:=random(120)-15*ship.options[4];\r
+         {if (i<skill) or ((scanning) and (random(100)<20)) then}\r
+        if not SkillTest(True, 4, skill + (ord(scanning) * 20), learnchance) then\r
+        begin\r
+           displaymap;\r
+           impact(j,maxweapons);\r
+           displaymap;\r
+          end;\r
+         charges[a]:=0;\r
+        end;\r
+      end;\r
+   if (abs(r)>1200000) then hulldamage:=0;\r
+   if (hulldamage=0) and (targetindex=j) then\r
+    begin\r
+     targetindex:=1;\r
+     while (targetindex<=nships) and (ships^[targetindex].hulldamage=0) do inc(targetindex);\r
+     if targetindex>nships then done:=true;\r
+    end;\r
+  end;\r
+ if moveindex=5 then moveindex:=0 else inc(moveindex);\r
+end;\r
+\r
+procedure previoustarget;\r
+begin\r
+ displaymap;\r
+ dec(targetindex);\r
+ while (targetindex>0) and (ships^[targetindex].hulldamage=0) do dec(targetindex);\r
+ if (targetindex=0) then\r
+  begin\r
+   targetindex:=nships;\r
+   while (targetindex>0) and (ships^[targetindex].hulldamage=0) do dec(targetindex);\r
+  end;\r
+ displaymap;\r
+end;\r
+\r
+procedure nexttarget;\r
+begin\r
+ displaymap;\r
+ inc(targetindex);\r
+ while (targetindex<=nships) and (ships^[targetindex].hulldamage=0) do inc(targetindex);\r
+ if (targetindex>nships) or (ships^[targetindex].hulldamage=0) then\r
+  begin\r
+   targetindex:=1;\r
+   while (targetindex<nships) and (ships^[targetindex].hulldamage=0) do inc(targetindex);\r
+  end;\r
+ displaymap;\r
+end;\r
+\r
+procedure switchalienmode;\r
+begin\r
+ mousehide;\r
+ for i:=125 to 189 do\r
+  fillchar(screen[i,6],93,0);\r
+ if not alienpicmode then\r
+  begin\r
+   for i:=156 to 189 do\r
+    move(asdisplay^[i,6],screen[i,6],93);\r
+   alienpicmode:=true;\r
+  end\r
+ else\r
+  begin\r
+   for i:=125 to 155 do\r
+    move(asdisplay^[i,6],screen[i,6],93);\r
+   alienpicmode:=false;\r
+  end;\r
+ mouseshow;\r
+end;\r
+\r
+procedure setdir(d: integer);\r
+begin\r
+ if ship.damages[4]>89 then exit;\r
+ drawdirection(0);\r
+ shipdir:=d;\r
+ if d=5 then shipdir2:=0;\r
+ drawdirection(63);\r
+end;\r
+\r
+procedure setdir2(d: integer);\r
+begin\r
+ if ship.damages[4]>89 then exit;\r
+ drawdirection(0);\r
+ shipdir2:=d;\r
+ drawdirection(63);\r
+end;\r
+\r
+procedure findtarget;\r
+var j: integer;\r
+begin\r
+ if (mouse.x<6) or (mouse.x>259) or (mouse.y<6) or (mouse.y>117) then exit;\r
+ for j:=1 to nships do\r
+  begin\r
+   z:=round(ships^[j].relz/range*26);\r
+   y:=62+round(ships^[j].rely/range*26.66)-z;\r
+   x:=132+round(ships^[j].relx/range*119);\r
+   if (abs(mouse.x-x)<5) and (abs(mouse.y-y)<5) and (ships^[j].hulldamage>0) then\r
+    begin\r
+     displaymap;\r
+     targetindex:=j;\r
+     displaymap;\r
+     displaytargetinfo;\r
+     j:=nships;\r
+    end;\r
+  end;\r
+end;\r
+\r
+procedure displaytimedelay;\r
+var\r
+ s: string[3];\r
+begin\r
+ tcolor:=63;\r
+ str(ship.options[2]:3,s);\r
+ mousehide;\r
+ printxy(277,2,s);\r
+ mouseshow;\r
+ tcolor:=95;\r
+end;\r
+\r
+procedure findmouse;\r
+begin\r
+ if not mouse.getstatus then exit;\r
+ case mouse.x of\r
+  105..125: case mouse.y of\r
+             131..151: fireweapon:=1;\r
+             152..156: if (mouse.x>108) and (mouse.x<122) then\r
+                        begin\r
+                         if userpowerup[1] then\r
+                          begin\r
+                           plainfadearea(109,152,121,154,32);\r
+                           userpowerup[1]:=false;\r
+                          end\r
+                         else\r
+                          begin\r
+                           plainfadearea(109,152,121,154,-32);\r
+                           userpowerup[1]:=true;\r
+                          end;\r
+                        end\r
+                       else findtarget;\r
+             157..161: if (mouse.x>108) and (mouse.x<122) then\r
+                        begin\r
+                         if userpowerup[6] then\r
+                          begin\r
+                           plainfadearea(109,159,121,161,32);\r
+                           userpowerup[6]:=false;\r
+                          end\r
+                         else\r
+                          begin\r
+                           plainfadearea(109,159,121,161,-32);\r
+                           userpowerup[6]:=true;\r
+                          end;\r
+                        end\r
+                       else findtarget;\r
+             162..182: fireweapon:=6;\r
+             else findtarget;\r
+            end;\r
+  128..148: case mouse.y of\r
+             131..151: fireweapon:=2;\r
+             152..156: if (mouse.x>131) and (mouse.x<145) then\r
+                        begin\r
+                         if userpowerup[2] then\r
+                          begin\r
+                           plainfadearea(132,152,144,154,32);\r
+                           userpowerup[2]:=false;\r
+                          end\r
+                         else\r
+                          begin\r
+                           plainfadearea(132,152,144,154,-32);\r
+                           userpowerup[2]:=true;\r
+                          end;\r
+                        end\r
+                       else findtarget;\r
+             157..161: if (mouse.x>131) and (mouse.x<145) then\r
+                        begin\r
+                         if userpowerup[7] then\r
+                          begin\r
+                           plainfadearea(132,159,144,161,32);\r
+                           userpowerup[7]:=false;\r
+                          end\r
+                         else\r
+                          begin\r
+                           plainfadearea(132,159,144,161,-32);\r
+                           userpowerup[7]:=true;\r
+                          end;\r
+                        end\r
+                       else findtarget;\r
+             162..182: fireweapon:=7;\r
+             else findtarget;\r
+            end;\r
+  151..171: case mouse.y of\r
+             131..151: fireweapon:=3;\r
+             152..156: if (mouse.x>154) and (mouse.x<168) then\r
+                        begin\r
+                         if userpowerup[3] then\r
+                          begin\r
+                           plainfadearea(155,152,167,154,32);\r
+                           userpowerup[3]:=false;\r
+                          end\r
+                         else\r
+                          begin\r
+                           plainfadearea(155,152,167,154,-32);\r
+                           userpowerup[3]:=true;\r
+                          end;\r
+                        end\r
+                       else findtarget;\r
+             157..161: if (mouse.x>154) and (mouse.x<168) then\r
+                        begin\r
+                         if userpowerup[8] then\r
+                          begin\r
+                           plainfadearea(155,159,167,161,32);\r
+                           userpowerup[8]:=false;\r
+                          end\r
+                         else\r
+                          begin\r
+                           plainfadearea(155,159,167,161,-32);\r
+                           userpowerup[8]:=true;\r
+                          end;\r
+                        end\r
+                       else findtarget;\r
+             162..182: fireweapon:=8;\r
+             else findtarget;\r
+            end;\r
+  174..194: case mouse.y of\r
+             131..151: fireweapon:=4;\r
+             152..156: if (mouse.x>177) and (mouse.x<191) then\r
+                        begin\r
+                         if userpowerup[4] then\r
+                          begin\r
+                           plainfadearea(178,152,190,154,32);\r
+                           userpowerup[4]:=false;\r
+                          end\r
+                         else\r
+                          begin\r
+                           plainfadearea(178,152,190,154,-32);\r
+                           userpowerup[4]:=true;\r
+                          end;\r
+                        end\r
+                       else findtarget;\r
+             157..161: if (mouse.x>177) and (mouse.x<191) then\r
+                        begin\r
+                         if userpowerup[9] then\r
+                          begin\r
+                           plainfadearea(178,159,190,161,32);\r
+                           userpowerup[9]:=false;\r
+                          end\r
+                         else\r
+                          begin\r
+                           plainfadearea(178,159,190,161,-32);\r
+                           userpowerup[9]:=true;\r
+                          end;\r
+                        end\r
+                       else findtarget;\r
+             162..182: fireweapon:=9;\r
+             191..195: if (mouse.x>183) then switchalienmode else findtarget;\r
+             else findtarget;\r
+            end;\r
+  195..196: case mouse.y of\r
+             191..195: switchalienmode;\r
+             else findtarget;\r
+            end;\r
+  197..217: case mouse.y of\r
+             131..151: fireweapon:=5;\r
+             152..156: if (mouse.x>200) and (mouse.x<214) then\r
+                        begin\r
+                         if userpowerup[5] then\r
+                          begin\r
+                           plainfadearea(201,152,213,154,32);\r
+                           userpowerup[5]:=false;\r
+                          end\r
+                         else\r
+                          begin\r
+                           plainfadearea(201,152,213,154,-32);\r
+                           userpowerup[5]:=true;\r
+                          end;\r
+                        end\r
+                       else findtarget;\r
+             157..161: if (mouse.x>200) and (mouse.x<214) then\r
+                        begin\r
+                         if userpowerup[10] then\r
+                          begin\r
+                           plainfadearea(201,159,213,161,32);\r
+                           userpowerup[10]:=false;\r
+                          end\r
+                         else\r
+                          begin\r
+                           plainfadearea(201,159,213,161,-32);\r
+                           userpowerup[10]:=true;\r
+                          end;\r
+                        end\r
+                       else findtarget;\r
+             162..182: fireweapon:=10;\r
+             191..195: if (mouse.x<209) then switchalienmode else findtarget;\r
+             else findtarget;\r
+            end;\r
+  223..225: if (mouse.y>184) and (mouse.y<193) then previoustarget;\r
+  226..242: case mouse.y of\r
+             124..144: if range>5000 then\r
+                        begin\r
+                         displaymap;\r
+                         dec(range,5000);\r
+                         str(range*10:7,str1);\r
+                         printxy(33,110,str1);\r
+                         displaymap;\r
+                        end;\r
+             151..173: if not autofire then\r
+                        begin\r
+                         autofire:=true;\r
+                         mousehide;\r
+                         for i:=125 to 126 do\r
+                          fillchar(screen[i,163],52,63);\r
+                         mouseshow;\r
+                        end\r
+                       else\r
+                        begin\r
+                         autofire:=false;\r
+                         mousehide;\r
+                         for i:=125 to 126 do\r
+                          fillchar(screen[i,163],52,95);\r
+                         mouseshow;\r
+                        end;\r
+             185..192: if (mouse.x<241) then previoustarget;\r
+               89..97: if mouse.x<237 then setdir(1) else setdir(2);\r
+              99..107: if mouse.x<237 then setdir(4) else setdir(5);\r
+             109..117: if mouse.x<237 then setdir(7) else setdir(8);\r
+             else findtarget;\r
+            end;\r
+  244..260: case mouse.y of\r
+             124..144: if range<5000000 then\r
+                        begin\r
+                         displaymap;\r
+                         inc(range,5000);\r
+                         str(range*10:7,str1);\r
+                         printxy(33,110,str1);\r
+                         displaymap;\r
+                        end;\r
+             151..173: if not scanning then\r
+                        begin\r
+                         scanning:=true;\r
+                         mousehide;\r
+                         for i:=187 to 188 do\r
+                          fillchar(screen[i,163],52,63);\r
+                         mouseshow;\r
+                        end\r
+                       else\r
+                        begin\r
+                         scanning:=false;\r
+                         mousehide;\r
+                         for i:=187 to 188 do\r
+                          fillchar(screen[i,163],52,95);\r
+                         mouseshow;\r
+                        end;\r
+             185..192: if (mouse.x>245) then nexttarget;\r
+               69..77: if mouse.x>248 then setdir2(1);\r
+               79..87: if mouse.x>248 then setdir2(2);\r
+               89..97: if mouse.x<249 then setdir(2) else setdir(3);\r
+              99..107: if mouse.x<249 then setdir(5) else setdir(6);\r
+             109..117: if mouse.x<249 then setdir(8) else setdir(9);\r
+             else findtarget;\r
+            end;\r
+  261..263: if (mouse.y>184) and (mouse.y<193) then nexttarget else findtarget;\r
+  271..279: if (mouse.y<10) and (ship.options[2]>1) then\r
+             begin\r
+              dec(ship.options[2]);\r
+              tslice:=ship.options[2];\r
+              displaytimedelay;\r
+             end;\r
+  291..312: case mouse.y of\r
+             11..117: displayshieldpic(round((117-mouse.y)*100/102));\r
+             1..9: if (mouse.x>299) and (mouse.x<309) and (ship.options[2]<255) then\r
+                    begin\r
+                     inc(ship.options[2]);\r
+                     tslice:=ship.options[2];\r
+                     displaytimedelay;\r
+                    end;\r
+            end;\r
+  else findtarget;\r
+ end;\r
+end;\r
+\r
+procedure processkey;\r
+var ans: char;\r
+begin\r
+ ans:=readkey;\r
+ case upcase(ans) of\r
+   #0: begin\r
+        ans:=readkey;\r
+        case ans of\r
+         #71: setdir(1);\r
+         #72: setdir(2);\r
+         #73: setdir(3);\r
+         #75: setdir(4);\r
+         #77: setdir(6);\r
+         #79: setdir(7);\r
+         #80: setdir(8);\r
+         #81: setdir(9);\r
+         #16,#45: begin\r
+           if yesnorequest('Do you want to quit?',0,31) then\r
+           begin\r
+              quit:=true;\r
+              done:=true;\r
+              {dead:=true;}\r
+           end;\r
+           tcolor:=95;\r
+           bkcolor:=0;\r
+        end;\r
+       end; { case }\r
+   end;\r
+  '-': setdir2(1);\r
+  '+': setdir2(2);\r
+  ' ': switchalienmode;\r
+  '<',',': previoustarget;\r
+  '>','.': nexttarget;\r
+  '`': bossmode;\r
+  'Q': fireweapon:=1;\r
+  'W': fireweapon:=2;\r
+  'E': fireweapon:=3;\r
+  'R': fireweapon:=4;\r
+  'T': fireweapon:=5;\r
+  'A': fireweapon:=6;\r
+  'S': fireweapon:=7;\r
+  'D': fireweapon:=8;\r
+  'F': fireweapon:=9;\r
+  'G': fireweapon:=10;\r
+ end;\r
+end;\r
+\r
+procedure mainloop;\r
+var index,cindex: integer;\r
+begin\r
+ index:=0;\r
+ cindex:=0;\r
+ displaymap;\r
+ repeat\r
+  fadestep(8);\r
+  findmouse;\r
+  if fastkeypressed then processkey;\r
+  inc(index);\r
+  if index=8 then\r
+   begin\r
+    suckpower;\r
+    index:=0;\r
+    displaymap;\r
+    moveships;\r
+    displaymap;\r
+   end;\r
+  displaystats;\r
+  displaytargetinfo;\r
+  powerup;\r
+  if not done then\r
+  begin\r
+     if cindex<16 then i:=cindex+32 else i:=64-cindex;\r
+     setrgb256(i,0,0,colors[i,3]);\r
+     if cindex<31 then inc(cindex) else cindex:=0;\r
+     if cindex<16 then i:=cindex+32 else i:=64-cindex;\r
+     setrgb256(i,0,0,63);\r
+     delay(tslice*3);\r
+  end;\r
+ until done;\r
+   if not quit then\r
+   begin\r
+      wait(1);\r
+      set256colors(colors);\r
+   end;\r
+end;\r
+\r
+procedure getshipinfo(n,j: integer);\r
+var f: file of alienshiptype;\r
+    i: integer;\r
+begin\r
+ case ship.wandering.alienid of\r
+     1..1000: i:=0;\r
+  1000..1007: i:=ship.wandering.alienid-1000;\r
+        1009: i:=8;\r
+        1010: i:=9;\r
+        1013: i:=10;  { drones }\r
+  else errorhandler('Invalid alien ship ID.',6);\r
+ end;\r
+ if i=10 then picy:=0 else picy:=i*20;\r
+ assign(f,'data\ships.dta');\r
+ reset(f);\r
+ if ioresult<>0 then errorhandler('ships.dta',1);\r
+ seek(f,j+i*11);\r
+ if ioresult<>0 then errorhandler('ships.dta',5);\r
+ read(f,ships^[n]);\r
+ if ioresult<>0 then errorhandler('ships.dta',5);\r
+ close(f);\r
+ with ships^[n] do\r
+ case j of\r
+   0..6: picx:=j*20;\r
+   7: picx:=140;\r
+   8: picx:=180;\r
+   9: picx:=220;\r
+  10: picx:=260;\r
+ end;\r
+end;\r
+\r
+procedure readyships;\r
+var f: file of alientype;\r
+    t: alientype;\r
+    form,index,c: integer;\r
+    basex,basey,basez: longint;\r
+begin\r
+ nships:=0;\r
+   learnchance := 100;\r
+ if ship.wandering.alienid=1013 then\r
+ begin\r
+    learnchance := 5;\r
+   t.name:='Drone';\r
+   t.victory:=(ship.options[4]+1)*10;\r
+  end\r
+ else\r
+  begin\r
+   assign(f,tempdir+'\contacts.dta');\r
+   reset(f);\r
+   if ioresult<>0 then errorhandler(tempdir+'\contacts.dta',1);\r
+   repeat\r
+    read(f,t);\r
+    if ioresult<>0 then errorhandler(tempdir+'\contacts.dta',5);\r
+   until t.id=ship.wandering.alienid;\r
+   close(f);\r
+  end;\r
+ tcolor:=95;\r
+ alienname:=t.name;\r
+ printxy(3,10,alienname);\r
+ if (showplanet) and (tempplan^[curplan].system=182) then a:=300 else a:=t.victory;\r
+ if a=0 then a:=1;\r
+ index:=4;\r
+ form:=random(maxformations);\r
+ repeat\r
+  inc(nships);\r
+  with ships^[nships] do\r
+   begin\r
+    if a>75 then c:=10\r
+    else if a<11 then c:=random(a)\r
+     else c:=random(6)+5;\r
+    getshipinfo(nships,c);\r
+    dec(a,c+1);\r
+    if index<4 then inc(index) else\r
+     begin\r
+      basex:=10000*random(6000);\r
+      if random(2)=0 then basex:=-basex;\r
+      basey:=10000*random(6000);\r
+      if random(2)=0 then basey:=-basey;\r
+      basez:=10000*random(6000);\r
+      if random(2)=0 then basez:=-basez;\r
+      index:=0;\r
+     end;\r
+    relx:=basex+formation[form,index,1];\r
+    rely:=basey+formation[form,index,2];\r
+    relz:=basez+formation[form,index,3];\r
+    if (shield<1502) then shieldlevel:=100;\r
+   end;\r
+ until (nships=maxships) or (a=0);\r
+end;\r
+\r
+procedure readydata;\r
+var\r
+   j : Integer;\r
+begin\r
+   mousehide;\r
+   compressfile(tempdir+'\current',@screen);\r
+   {fading;}\r
+   fadestopmod(-8, 20);\r
+   playmod(true,'sound\combat.mod');\r
+   loadscreen('data\fight',@screen);\r
+   loadscreen('data\cloud',backgr);\r
+   done:=false;\r
+   new(ships);\r
+   new(statpic);\r
+   new(blank);\r
+   new(asdisplay);\r
+   new(shieldpic);\r
+   new(shieldpic2);\r
+   new(msgs);\r
+   for i:=10 to 11 do\r
+      move(screen[i,71],statpic^[i-10],10);\r
+   for i:=26 to 27 do\r
+      move(screen[i,269],blank^[i-26],10);\r
+   for i:=0 to 6 do\r
+      mymove(screen[i+10,91],shieldpic^[i],1);\r
+   for i:=0 to 6 do\r
+      mymove(screen[i+10,101],shieldpic2^[i],1);\r
+   for j:=0 to 3 do\r
+      for i:=0 to 9 do\r
+        move(screen[i+10,110+j*10],msgs^[j,i],10);\r
+   for i:=9 to 20 do\r
+      fillchar(screen[i,71],177,0);\r
+   displaytimedelay;\r
+   tcolor:=95;\r
+   bkcolor:=0;\r
+   oldt1:=t1;\r
+   targetindex:=1;\r
+   if ship.options[4]=0 then\r
+   begin\r
+      autofire:=true;\r
+      scanning:=true;\r
+      for i:=125 to 126 do\r
+        fillchar(screen[i,163],52,63);\r
+      for i:=187 to 188 do\r
+        fillchar(screen[i,163],52,63);\r
+   end\r
+   else\r
+   begin\r
+      autofire:=false;\r
+      scanning:=false;\r
+      for i:=125 to 126 do\r
+        fillchar(screen[i,163],52,95);\r
+      for i:=187 to 188 do\r
+        fillchar(screen[i,163],52,95);\r
+   end;\r
+   for i:=9 to 117 do\r
+      for j:=6 to 260 do\r
+        if screen[i,j]=0 then screen[i,j]:=backgr^[i,j];\r
+   loadscreen('data\waricon',backgr);\r
+   stats[1]:=0;\r
+   stats[2]:=0;\r
+   stats[3]:=0;\r
+   oldshddmg:=20;\r
+   shipdir:=5;\r
+   shipdir2:=0;\r
+   fireweapon:=0;\r
+   moveindex:=0;\r
+   engaging:=false;\r
+   alienpicmode:=false;\r
+   dead:=false;\r
+   range:=60000;\r
+   printxy(33,110,' 600000 KM.R.');\r
+   for j:=1 to 10 do\r
+   begin\r
+      poweredup[j]:=-1;\r
+      if ship.armed then poweredup[j]:=99 else poweredup[j]:=0;\r
+      if ship.gunnodes[j]=0 then poweredup[j]:=-1;\r
+   end;\r
+   for i:=125 to 189 do\r
+      move(screen[i,6],asdisplay^[i],93);\r
+   for i:=137 to 189 do\r
+      fillchar(screen[i,6],93,0);\r
+   for j:=1 to 3 do stats[j]:=0;\r
+   displayweapons;\r
+   displaystats;\r
+   displaydamage;\r
+   drawdirection(63);\r
+   displayshieldpic(ship.shieldopt[3]);\r
+   readyships;\r
+   displaytargetinfo;\r
+   mouseshow;\r
+   for j:=1 to 10 do\r
+      if not userpowerup[j] then\r
+      begin\r
+        x:=((j-1) mod 5)*23;\r
+        y:=((j-1) div 5)*7;\r
+        plainfadearea(109+x,152+y,121+x,154+y,32);\r
+      end;\r
+   {fadein;}\r
+end;\r
+\r
+procedure savevictories;\r
+var f : file of alientype;\r
+   t  : alientype;\r
+   j  : Integer;\r
+begin\r
+ assign(f,tempdir+'\contacts.dta');\r
+ reset(f);\r
+ if ioresult<>0 then errorhandler(tempdir+'\contacts.dta',1);\r
+ i:=-1;\r
+ repeat\r
+  inc(i);\r
+  read(f,t);\r
+  if ioresult<>0 then errorhandler(tempdir+'\contacts.dta',4);\r
+ until t.id=ship.wandering.alienid;\r
+ seek(f,i);\r
+ if ioresult<>0 then errorhandler(tempdir+'\contacts.dta',4);\r
+ i:=nships div 4;\r
+ if i=0 then i:=1;\r
+ inc(t.victory,i);\r
+ i:=0;\r
+ for j:=1 to 7 do i:=i+ship.damages[j];\r
+ if i=0 then inc(t.victory,nships);\r
+ if t.anger<200 then inc(t.anger)\r
+ else if t.congeniality>0 then dec(t.congeniality);\r
+ if t.victory>20000 then t.victory:=20000;\r
+ write(f,t);\r
+ if ioresult<>0 then errorhandler(tempdir+'\contacts.dta',4);\r
+ close(f);\r
+end;\r
+\r
+procedure aftereffects;\r
+var\r
+   cargoitems : array[0..13] of integer;\r
+   j         : Integer;\r
+begin\r
+ playmod(true,'sound\victory.mod');\r
+ mousehide;\r
+ for i:=9 to 117 do\r
+  fillchar(screen[i,6],254,0);\r
+ for i:=125 to 189 do\r
+  fillchar(screen[i,6],93,0);\r
+ tcolor:=95;\r
+ printxy(18,8,'VICTORY!');\r
+ mouseshow;\r
+ if yesnorequest('DEPLOY SCAVENGER BOTS?',0,31) then\r
+  begin\r
+   tcolor:=22;\r
+   bkcolor:=0;\r
+   mousehide;\r
+   printxy(18,18,'SCAVENGER BOTS DEPLOYED...');\r
+   mouseshow;\r
+   tcolor:=28;\r
+   fillchar(cargoitems,11,0);\r
+   i:=random(nships);\r
+   if i>13 then i:=13;\r
+   a:=1;\r
+   while cargo[a].index<>3000 do inc(a);\r
+   for j:=0 to i do\r
+    begin\r
+     cargoitems[j]:=random(21);\r
+     mousehide;\r
+     printxy(24,28+j*6,cargo[a+cargoitems[j]].name);\r
+     mouseshow;\r
+     addcargo2(cargoitems[j]+3000, true);\r
+    end;\r
+   while fastkeypressed do readkey;\r
+   repeat\r
+   until (fastkeypressed) or (mouse.getstatus);\r
+   while fastkeypressed do readkey;\r
+  end;\r
+ savevictories;\r
+end;\r
+\r
+procedure initiatecombat;\r
+begin\r
+ readydata;\r
+ mainloop;\r
+ loadscreen('data\cloud',backgr);\r
+ if ((tempplan^[curplan].state=6) and (tempplan^[curplan].mode=2)) then makeastoroidfield\r
+  else if (tempplan^[curplan].state=0) and (tempplan^[curplan].mode=1) then makecloud;\r
+ dispose(msgs);\r
+ dispose(statpic);\r
+ dispose(blank);\r
+ dispose(ships);\r
+ dispose(asdisplay);\r
+ dispose(shieldpic);\r
+ dispose(shieldpic2);\r
+ if (not engaging) and (not dead) and (ship.wandering.alienid<1013) then aftereffects;\r
+ stopmod;\r
+ removedata;\r
+ if (engaging) and (targetready) then\r
+  engage(systems[nearby[target].index].x,systems[nearby[target].index].y,systems[nearby[target].index].z)\r
+ else if engaging then\r
+  begin\r
+   targetready:=true;\r
+   engage(ship.posx-10+random(20),ship.posy-10+random(20),ship.posz-10+random(20));\r
+  end;\r
+end;\r
+var\r
+   j : Integer;\r
+begin\r
+ for j:=1 to 10 do userpowerup[j]:=true;\r
+end.\r
diff --git a/code/comm.pas b/code/comm.pas
new file mode 100644 (file)
index 0000000..b32e6a9
--- /dev/null
@@ -0,0 +1,1896 @@
+unit comm;\r
+(********************************************************************\r
+    This file is part of Ironseed.\r
+\r
+    Ironseed is free software: you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation, either version 3 of the License, or\r
+    (at your option) any later version.\r
+\r
+    Ironseed is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with Ironseed.  If not, see <http://www.gnu.org/licenses/>.\r
+********************************************************************)\r
+\r
+{***************************\r
+   Communication unit for IronSeed\r
+\r
+   Channel 7\r
+   Destiny: Virtual\r
+\r
+\r
+   Copyright 1994\r
+\r
+***************************}\r
+\r
+{$O+}\r
+interface\r
+\r
+uses data;\r
+\r
+procedure conversewithcrew;\r
+procedure continuecontact(hail: boolean);\r
+procedure getspecial(n,contactindex: integer);\r
+procedure addtofile;\r
+procedure createwandering(order: integer);\r
+procedure getinfo;\r
+procedure checkwandering;\r
+procedure animatealien;\r
+procedure gettechlevel(plan: integer);\r
+\r
+implementation\r
+\r
+uses crt, gmouse, utils, combat, utils2, weird, modplay, comm2, journey, saveload, heapchk;\r
+\r
+const\r
+ numback= 19;\r
+type\r
+ eventtype=\r
+  record\r
+   want,give: integer;\r
+   msg: string[255];\r
+  end;\r
+ eventarray= array[0..9] of eventtype;\r
+var\r
+ commlevel,i,j,techlvl,eattype,contactindex,cursorx,index,indexa,indexb,indexc,oldcontactindex: integer;\r
+ brighter,infomode,shipflag,eventflag: boolean;\r
+ str1, str2: ^string;\r
+ question: string[20];\r
+ c: ^conversearray;\r
+ r: ^responsearray;\r
+ tmpm: ^mouseicontype;\r
+ aliens: pscreentype;\r
+ p: ^paltype;\r
+\r
+procedure createwandering(order: integer);\r
+var x,y: integer;                     { order = 0 > attack  }\r
+begin                                 {       = 1 > retreat }\r
+ with ship.wandering do               {       = 2 > nothing }\r
+  begin\r
+   orders:=order;\r
+   x:=hi(alien.techmin);\r
+   y:=lo(alien.techmin);\r
+   techlevel:=alien.techmin;\r
+   i:=5+random(4);\r
+   repeat\r
+    inc(y);\r
+    if y>9 then\r
+     begin\r
+      inc(x);\r
+      y:=0;\r
+      if x>6 then\r
+       begin\r
+        x:=6;\r
+        y:=0;\r
+       end;\r
+     end;\r
+    dec(i);\r
+   until (i=0) or (techlevel=alien.techmax);\r
+   techlevel:=x*256+y;\r
+   congeniality:=abs(alien.congeniality+random(11)-5);\r
+   anger:=abs(alien.anger+random(11)-5);\r
+   alienid:=alien.id;\r
+   case orders of\r
+    0: begin\r
+        relx:=3000+random(10000);\r
+        if random(2)=1 then relx:=-relx;\r
+        rely:=3000+random(10000);\r
+        if random(2)=1 then rely:=-rely;\r
+        relz:=3000+random(10000);\r
+        if random(2)=1 then relz:=-relz;\r
+       end;\r
+    1: begin\r
+        relx:=5000+random(12000);\r
+        if random(2)=1 then relx:=-relx;\r
+        rely:=5000+random(12000);\r
+        if random(2)=1 then rely:=-rely;\r
+        relz:=5000+random(12000);\r
+        if random(2)=1 then relz:=-relz;\r
+       end;\r
+    2: begin\r
+        relx:=3000+random(2000);\r
+        if random(2)=1 then relx:=-relx;\r
+        rely:=3000+random(2000);\r
+        if random(2)=1 then rely:=-rely;\r
+        relz:=3000+random(2000);\r
+        if random(2)=1 then relz:=-relz;\r
+       end;\r
+   end;\r
+ end;\r
+end;\r
+\r
+procedure checkwandering;\r
+var confile: file of alientype;\r
+begin\r
+ if ship.wandering.alienid<16000 then exit;\r
+ assign(confile,tempdir+'\contacts.dta');\r
+ reset(confile);\r
+ if ioresult<>0 then errorhandler('contacts.dta',1);\r
+ repeat\r
+  read(confile,alien);\r
+ until (alien.id=curplan) or (ioresult<>0);\r
+ close(confile);\r
+ if (alien.id=curplan) and (alien.anger>0) and (alien.congeniality/alien.anger<0.7) then createwandering(0);\r
+end;\r
+\r
+procedure gettechlevel(plan: integer);\r
+var i: integer;\r
+begin\r
+ if tempplan^[plan].orbit=0 then\r
+  begin\r
+   techlvl:=0;\r
+   exit;\r
+  end;\r
+ techlvl:=-2;\r
+ case tempplan^[plan].system of\r
+  93,138,78,191,171,221:\r
+    begin\r
+     techlvl:=6*256;\r
+     exit;\r
+    end;\r
+  45: if chevent(27) then\r
+    begin\r
+     techlvl:=0;\r
+     exit;\r
+    end\r
+   else\r
+    begin\r
+     techlvl:=6*256;\r
+     exit;\r
+    end;\r
+ end;\r
+ case tempplan^[plan].state of\r
+  2: case tempplan^[plan].mode of\r
+      2: techlvl:=-1;\r
+      3: techlvl:=tempplan^[plan].age div 15000000;\r
+     end;\r
+  3: begin\r
+      techlvl:=(tempplan^[plan].mode-1)*256;\r
+      case tempplan^[plan].mode of\r
+       1: techlvl:=techlvl+(tempplan^[plan].age div 1500000);\r
+       2: techlvl:=techlvl+(tempplan^[plan].age div 1000);\r
+       3: techlvl:=techlvl+(tempplan^[plan].age div 800);\r
+      end;\r
+     end;\r
+  4: begin\r
+      techlvl:=(tempplan^[plan].mode+2)*256;\r
+      case tempplan^[plan].mode of\r
+       1: techlvl:=techlvl+(tempplan^[plan].age div 400);\r
+       2: techlvl:=techlvl+(tempplan^[plan].age div 200);\r
+      end;\r
+     end;\r
+  5: case tempplan^[plan].mode of\r
+      1: begin\r
+          i:=tempplan^[plan].age div 100000000;\r
+          if i>9 then i:=9;\r
+          techlvl:=techlvl+i;\r
+         end;\r
+      2: techlvl:=-1;\r
+     end;\r
+  6: if tempplan^[curplan].mode=2 then techlvl:=6*256;   {void dwellers}\r
+ end;\r
+ i:=random(9);                              { junk first random number }\r
+ eattype:=random(3);\r
+ randomize;\r
+end;\r
+\r
+procedure getname(n: integer);\r
+type nametype= string[15];\r
+var str1: nametype;\r
+    f: file of nametype;\r
+begin\r
+ n:=n-tempplan^[n].system;\r
+ assign(f,'data\planname.txt');\r
+ reset(f);\r
+ if ioresult<>0 then errorhandler('data\planname.txt',1);\r
+ seek(f,n);\r
+ if ioresult<>0 then errorhandler('data\planname.txt',6);\r
+ read(f,str1);\r
+ if ioresult<>0 then errorhandler('data\planname.txt',6);\r
+ alien.name:=str1;\r
+ close(f);\r
+end;\r
+\r
+procedure addtofile;\r
+var confile,target: file of alientype;\r
+    err,already: boolean;\r
+    temp: alientype;\r
+    index: integer;\r
+begin\r
+ assign(confile,tempdir+'\contacts.dta');\r
+ reset(confile);\r
+ if ioresult<>0 then errorhandler('contacts.dta (adding new alien)',1);\r
+ err:=false;\r
+ already:=false;\r
+ index:=-1;\r
+ repeat\r
+  inc(index);\r
+  read(confile,temp);\r
+  if ioresult<>0 then err:=true;\r
+  if temp.id=alien.id then already:=true;\r
+ until (err) or (already);\r
+ if err then                       { add to end }\r
+  begin\r
+   seek(confile,index);\r
+   if ioresult<>0 then errorhandler(tempdir+'\contacts.dta (appending alien)',5);\r
+   write(confile,alien);\r
+   if ioresult<>0 then errorhandler(tempdir+'\contacts.dta (appending alien)',5);\r
+  end;\r
+ close(confile);\r
+end;\r
+\r
+procedure getspecial(n,contactindex: integer);\r
+var f: file of alientype;\r
+begin\r
+ if n=13 then\r
+  begin\r
+   alien.id:=contactindex;\r
+   exit;\r
+  end;\r
+ assign(f,'data\contact0.dta');\r
+ reset(f);\r
+ if ioresult<>0 then errorhandler('data\contact0.dta',1);\r
+ seek(f,n-1);\r
+ if ioresult<>0 then errorhandler('data\contact0.dta',5);\r
+ read(f,alien);\r
+ if ioresult<>0 then errorhandler('data\contact0.dta',5);\r
+ alien.id:=contactindex;\r
+ close(f);\r
+end;\r
+\r
+procedure setalienstructure(starting: integer);\r
+begin\r
+ case tempplan^[contactindex].system of\r
+   93: getspecial(1,contactindex);\r
+  138: getspecial(2,contactindex);\r
+   45: if not chevent(27) then getspecial(4,contactindex);\r
+  221: getspecial(5,contactindex);\r
+   78: getspecial(6,contactindex);\r
+  171: getspecial(8,contactindex);\r
+  191: getspecial(9,contactindex);\r
+  else\r
+   if (tempplan^[contactindex].mode=2) and (tempplan^[contactindex].state=6)\r
+     then getspecial(11,contactindex)\r
+  else\r
+   begin\r
+    case hi(techlvl) of\r
+     3: x:=1;\r
+     4: x:=2;\r
+     5: x:=3;\r
+     else x:=0;\r
+    end;\r
+    alien.conindex:=30+x;\r
+    getname(contactindex);\r
+    x:=hi(techlvl);\r
+    y:=lo(techlvl);\r
+    with alien do\r
+     begin\r
+      y:=y-5;\r
+      if y<0 then\r
+       begin\r
+        dec(x);\r
+        y:=10+y;\r
+       end;\r
+      if x<0 then\r
+       begin\r
+        x:=0;\r
+        y:=0;\r
+       end;\r
+      techmin:=x*256+y;\r
+      y:=lo(techlvl);\r
+      y:=y+5;\r
+      if y>9 then\r
+       begin\r
+        inc(x);\r
+        y:=y-10;\r
+       end;\r
+      if x>5 then\r
+       begin\r
+        x:=5;\r
+        y:=0;\r
+       end;\r
+      techmax:=x*256+y;\r
+      id:=contactindex;\r
+      victory:=random(40);\r
+      war:=false;\r
+      case starting of\r
+       1: begin\r
+           if random(3)=0 then war:=true;\r
+           congeniality:=15;\r
+           anger:=30;\r
+           createwandering(0);\r
+          end;\r
+       2: begin\r
+           congeniality:=20;\r
+           anger:=10;\r
+          end;\r
+       3: begin\r
+           congeniality:=40;\r
+           anger:=0;\r
+          end;\r
+       4: begin\r
+           congeniality:=20;\r
+           anger:=15;\r
+          end;\r
+       5: begin\r
+           congeniality:=5;\r
+           anger:=0;\r
+           createwandering(1);\r
+          end;\r
+      end;\r
+     end;\r
+   end;\r
+ end;\r
+ addtofile;\r
+end;\r
+\r
+procedure clearconvflags;\r
+var\r
+   i : Integer;\r
+begin\r
+   for i := 500 to 599 do\r
+      clearevent(i);\r
+end; { clearconvflags }\r
+\r
+procedure contactsequence(plan,com: integer);\r
+var a,b,index,contactmade: integer;\r
+    t: ^char;\r
+begin\r
+ mousehide;\r
+ if plan=0 then techlvl:=alien.techmax\r
+  else if (plan>-1) and (plan<1000) then gettechlevel(plan)\r
+  else if plan>1000 then techlvl:=1280\r
+  else techlvl:=0;\r
+ if techlvl<1 then\r
+  begin\r
+   printxy(12,135,'Unintelligible Cypher');\r
+   printxy(12,145,'Contact Failure');\r
+   mouseshow;\r
+   exit;\r
+  end;\r
+ contactmade:=0;\r
+ if (hi(techlvl)<4) then\r
+  case eattype of\r
+   0: contactmade:=1;\r
+   1: case com of\r
+       0: contactmade:=5;\r
+       1: contactmade:=3;\r
+       2: contactmade:=2;\r
+      end;\r
+   2: contactmade:=random(5);\r
+   end\r
+  else\r
+   case eattype of\r
+    0: case com of\r
+        0: if random(2)=0 then contactmade:=1 else contactmade:=3;\r
+        1: contactmade:=2+random(2);\r
+        2: contactmade:=2;\r
+       end;\r
+    1: case com of\r
+        0: contactmade:=4;\r
+        1: contactmade:=2+random(2);\r
+       2: contactmade:=2;\r
+       end;\r
+    2: contactmade:=random(5);\r
+   end;\r
+ if (contactmade>0) and (contactindex=-1) then\r
+  begin\r
+   contactindex:=plan;\r
+   tempplan^[contactindex].notes:=tempplan^[contactindex].notes or 2;\r
+   setalienstructure(contactmade);\r
+  end;\r
+ printxy(12,135,'Cypher Acknowledged');\r
+ printxy(12,145,'Awaiting Response');\r
+ if contactmade>0 then printxy(12,155,'Contact Established')\r
+  else contactindex:=-1;\r
+ mouseshow;\r
+end;\r
+\r
+{***************************************************************************}\r
+\r
+procedure loadconversation;\r
+var fc: file of converseindex;\r
+    fr: file of responsetype;\r
+    s: string[2];\r
+    str1: string[4];\r
+begin\r
+   fillchar(r^,sizeof(responsearray),0);\r
+   fillchar(c^,sizeof(conversearray),0);\r
+   str((contactindex+1):4,str1);\r
+   if contactindex<1000 then str1[1]:='0';\r
+   if contactindex<100 then str1[2]:='0';\r
+   if contactindex<10 then str1[3]:='0';\r
+   assign(fc,'data\conv'+str1+'.ind');\r
+   reset(fc);\r
+   if ioresult<>0 then errorhandler('data\conv'+str1+'.ind',1);\r
+   i:=0;\r
+   repeat\r
+      inc(i);\r
+      read(fc,c^[i]);\r
+   until ioresult<>0;\r
+   close(fc);\r
+   assign(fr,'data\conv'+str1+'.dta');\r
+   reset(fr);\r
+   if ioresult<>0 then errorhandler('data\conv'+str1+'.dta',1);\r
+   i:=0;\r
+   repeat\r
+      inc(i);\r
+      read(fr,r^[i]);\r
+   until ioresult<>0;\r
+   close(fr);\r
+end;\r
+\r
+procedure showportrait(n: integer);\r
+var s: string[2];\r
+    portrait: ^portraittype;\r
+begin\r
+ new(portrait);\r
+ str(n:2,s);\r
+ if n<10 then s[1]:='0';\r
+ loadscreen('data\image'+s,portrait);\r
+ for i:=0 to 34 do\r
+  begin\r
+   move(portrait^[i*2],screen[i*2+41,126],70);\r
+   delay(tslice div 5);\r
+  end;\r
+ for i:=0 to 34 do\r
+  begin\r
+   move(portrait^[i*2+1],screen[i*2+42,126],70);\r
+   delay(tslice div 5);\r
+  end;\r
+ dispose(portrait);\r
+end;\r
+\r
+procedure drawcursor;\r
+begin\r
+ for i:=(contactindex mod 3)*30+37 to (contactindex mod 3)*30+42 do\r
+  for j:=(contactindex div 3)*138+89 to (contactindex div 3)*138+93 do\r
+   if screen[i,j] div 16=3 then screen[i,j]:=screen[i,j]+32;\r
+ showportrait(ship.crew[contactindex+1].index);\r
+end;\r
+\r
+procedure erasecursor;\r
+begin\r
+ for i:=(contactindex mod 3)*30+37 to (contactindex mod 3)*30+42 do\r
+  for j:=(contactindex div 3)*138+89 to (contactindex div 3)*138+93 do\r
+   if screen[i,j] div 16=5 then screen[i,j]:=screen[i,j]-32;\r
+end;\r
+\r
+procedure displaycrewnames;\r
+var a,b: integer;\r
+begin\r
+ t1:=22/36;\r
+ for a:=0 to 5 do\r
+  begin\r
+   if (ship.crew[a+1].index=18) or (ship.crew[a+1].index=25) or (ship.crew[a+1].index=26)\r
+    then i:=6 else i:=1;\r
+   b:=1;\r
+   repeat\r
+    printxy((a div 3)*230+12+b*5,(a mod 3)*30+37,ship.crew[a+1].name[i]);\r
+    inc(i);\r
+    inc(b);\r
+   until ship.crew[a+1].name[i]=' ';\r
+   j:=round((0.40*ship.crew[a+1].men+0.60*ship.crew[a+1].emo-0.20*ship.crew[a+1].phy)*0.36);\r
+   if j>36 then j:=36\r
+   else if j<1 then j:=0;\r
+   for b:=0 to j do\r
+    begin\r
+     screen[(a mod 3)*30+48,(a div 3)*258+b+13]:=round(t1*b)+73;\r
+     screen[(a mod 3)*30+49,(a div 3)*258+b+13]:=round(t1*b)+73;\r
+    end;\r
+   if j<34 then\r
+    for b:=j+1 to 36 do\r
+     begin\r
+     screen[(a mod 3)*30+48,(a div 3)*258+b+13]:=0;\r
+     screen[(a mod 3)*30+49,(a div 3)*258+b+13]:=0;\r
+    end;\r
+  end;\r
+end;\r
+\r
+procedure checkstring(p,q,s: integer); forward;\r
+\r
+procedure command2(n: integer);\r
+begin\r
+ mousehide;\r
+ for i:=135 to 189 do\r
+  fillchar(screen[i,15],278,0);\r
+ printxy(12,182,'Subject:');\r
+ if contactindex>-1 then erasecursor;\r
+ contactindex:=n;\r
+ drawcursor;\r
+ showportrait(ship.crew[contactindex+1].index);\r
+ mouseshow;\r
+ loadconversation;\r
+ question:='HI';\r
+   {checkstring(95,176,170);}\r
+   checkstring(95,42,170);\r
+end;\r
+\r
+procedure findmouse2;\r
+begin\r
+ if not mouse.getstatus then exit;\r
+ case mouse.y of\r
+    30..50: case mouse.x of\r
+                9..85: if contactindex<>0 then command2(0);\r
+             235..311: if contactindex<>3 then command2(3);\r
+            end;\r
+    60..80: case mouse.x of\r
+                9..85: if contactindex<>1 then command2(1);\r
+             235..311: if contactindex<>4 then command2(4);\r
+            end;\r
+   90..110: case mouse.x of\r
+                9..85: if contactindex<>2 then command2(2);\r
+             235..311: if contactindex<>5 then command2(5);\r
+            end;\r
+  154..170: if mouse.x>309 then done:=true;\r
+ end;\r
+ idletime:=0;\r
+end;\r
+\r
+procedure printxy2(x1,y1,m,n,o: integer; s: string);\r
+var letter,j2,a,x,y,t : integer;\r
+label skipit; \r
+begin\r
+   t:=tcolor;\r
+   brighter:=false;\r
+   j2:=0;\r
+   x1:=x1+4;\r
+   for j:=1 to length(s) do\r
+   begin\r
+      if s[j]=#200 then\r
+      begin\r
+        if brighter then brighter:=false else brighter:=true;\r
+        goto skipit;\r
+      end;\r
+      letter:=ord(s[j]);\r
+      if brighter then\r
+        tcolor := n\r
+      else\r
+      {if (brighter) then\r
+      case ship.options[4] of\r
+      0: tcolor:=m;\r
+      1: tcolor:=n;\r
+      2: tcolor:=o;\r
+    end\r
+    else} tcolor:=o;\r
+      bkcolor:=m;\r
+      inc(j2);\r
+      y:=y1;\r
+      for i:=0 to 5 do\r
+      begin\r
+        inc(y);\r
+        x:=x1;\r
+        for a:=7 downto 4 do\r
+        begin\r
+           inc(x);\r
+           if font[ship.options[7],letter,i div 2] and (1 shl a)>0 then screen[y,x]:=tcolor\r
+           else if bkcolor<255 then screen[y,x]:=bkcolor;\r
+        end;\r
+        dec(tcolor,1);\r
+        x:=x1;\r
+        inc(y);\r
+        inc(i);\r
+        for a:=3 downto 0 do\r
+        begin\r
+           inc(x);\r
+           if font[ship.options[7],letter,i div 2] and (1 shl a)>0 then screen[y,x]:=tcolor\r
+           else if bkcolor<255 then screen[y,x]:=bkcolor;\r
+        end;\r
+        dec(tcolor,2);\r
+      end;\r
+      for i:=1 to 6 do screen[y1+i,x1+5]:=bkcolor;\r
+      delay(tslice div 3);\r
+      bkcolor:=0;\r
+      if brighter then\r
+        tcolor := n\r
+      else\r
+      {   if (brighter) then\r
+      case ship.options[4] of\r
+      0: tcolor:=m;\r
+      1: tcolor:=n;\r
+      2: tcolor:=o;\r
+    end\r
+    else} tcolor:=o;\r
+      y:=y1;\r
+      for i:=0 to 5 do\r
+      begin\r
+        x:=x1;\r
+        inc(y);\r
+        for a:=7 downto 4 do\r
+        begin\r
+           inc(x);\r
+           if font[ship.options[7],letter,i div 2] and (1 shl a)>0 then screen[y,x]:=tcolor\r
+           else if bkcolor<255 then screen[y,x]:=bkcolor;\r
+        end;\r
+        dec(tcolor,1);\r
+        inc(i);\r
+        inc(y);\r
+        x:=x1;\r
+        for a:=3 downto 0 do\r
+        begin\r
+           inc(x);\r
+           if font[ship.options[7],letter,i div 2] and (1 shl a)>0 then screen[y,x]:=tcolor\r
+           else if bkcolor<255 then screen[y,x]:=bkcolor;\r
+        end;\r
+        dec(tcolor,2);\r
+      end;\r
+      for i:=1 to 6 do screen[y1+i,x1+5]:=bkcolor;\r
+      x1:=x1+5;\r
+skipit:\r
+   end;\r
+   tcolor:=t;\r
+end;\r
+\r
+function parsestatement(y,n,p,q,s: integer): integer;\r
+var done: boolean;\r
+    a,b,c,i2,letter: integer;\r
+begin\r
+   str1^:=r^[n].response;\r
+   i:=1;\r
+   j:=1;\r
+   {copy response string, inserting crew names if needed}\r
+   repeat\r
+      if str1^[i]=#201 then\r
+      begin\r
+        inc(i);\r
+        a:=ord(str1^[i])+35-48;\r
+        b:=20;\r
+        while ship.crew[a].name[b]=' ' do dec(b);\r
+        for c:=1 to b do\r
+        begin\r
+           letter:=ord(ship.crew[a].name[c]);\r
+           case chr(letter) of\r
+             ' ' ..'"': letter:=letter-31;\r
+             ''''..'?': letter:=letter-35;\r
+             'A' ..'Z': letter:=letter-36;\r
+             'a' ..'z': letter:=letter-40;\r
+           else letter:=1;\r
+           end;        \r
+           str2^[j]:=chr(letter);\r
+           inc(j);\r
+        end;\r
+        dec(j);\r
+      end\r
+      else str2^[j]:=str1^[i];\r
+      inc(j);\r
+      inc(i);\r
+   until i>ord(str1^[0]);\r
+   str2^[0]:=chr(j-1);\r
+   done:=false;\r
+   repeat\r
+      str1^:=str2^;\r
+      i:=56;\r
+      if ord(str1^[0])>56 then\r
+      begin\r
+        while str1^[i]<>#1 do dec(i);\r
+        str2^:=copy(str1^,i+1,ord(str1^[0])-i);\r
+        str1^[0]:=chr(i-1);\r
+      end else done:=true;\r
+      printxy2(12,135+y*6,p,q,s,str1^);\r
+      inc(y);\r
+      if y=8 then\r
+      begin\r
+        for j:=184 to 188 do\r
+           fillchar(screen[j,15],288,0);\r
+        tcolor:=47;\r
+        printxy(146,191,'MORE');\r
+        i2:=47;\r
+        mouseshow;\r
+        repeat\r
+           fadestep(8);\r
+           tcolor:=i2;\r
+           printxy(146,191,'MORE');\r
+           dec(i2);\r
+           if i2=41 then i2:=47;\r
+           animatealien;\r
+           delay(tslice*5);\r
+        until (fastkeypressed) or (mouse.getstatus);\r
+        while fastkeypressed do readkey;\r
+        mousehide;\r
+        for j:=141 to 188 do\r
+           fillchar(screen[j,15],288,0);\r
+        printxy(146,191,'    ');\r
+        tcolor:=s;\r
+        y:=1;\r
+      end;\r
+   until done;\r
+   parsestatement:=y;\r
+end;\r
+\r
+procedure run20000event(n: integer);\r
+begin\r
+ case n of\r
+  20000: begin {good bye}\r
+          for i:=182 to 188 do\r
+           fillchar(screen[i,12],200,0);\r
+          contactindex:=-1;\r
+         end;\r
+  20001: begin {trade}\r
+          if alien.war then\r
+           begin\r
+            for i:=141 to 181 do\r
+             fillchar(screen[i,12],288,0);\r
+            printxy(12,141,'WE ARE AT WAR!');\r
+           end\r
+          else trade;\r
+         end;\r
+  20002: begin {attack!}\r
+          for i:=182 to 188 do\r
+           fillchar(screen[i,12],200,0);\r
+          contactindex:=-1;\r
+          createwandering(0);\r
+          ship.wandering.relx:=500+random(100);\r
+          ship.wandering.rely:=500+random(100);\r
+          ship.wandering.relz:=500+random(100);\r
+         end;\r
+  20003: begin {increase anger by 1}\r
+          if alien.anger<100 then inc(alien.anger);\r
+          if infomode then\r
+           begin\r
+            getinfo;\r
+            getinfo;\r
+           end;\r
+         end;\r
+  20004: begin {increase anger by 5}\r
+          inc(alien.anger,5);\r
+          if alien.anger>100 then alien.anger:=100;\r
+           begin\r
+            getinfo;\r
+            getinfo;\r
+           end;\r
+         end;\r
+  20005: begin {increase congeniality by 1}\r
+          if alien.congeniality<100 then inc(alien.congeniality);\r
+          if infomode then\r
+           begin\r
+            getinfo;\r
+            getinfo;\r
+           end;\r
+         end;\r
+  20006: begin {increase congeniality by 5}\r
+          inc(alien.congeniality,5);\r
+          if alien.congeniality>100 then alien.congeniality:=100;\r
+           begin\r
+            getinfo;\r
+            getinfo;\r
+           end;\r
+         end;\r
+ end;\r
+end;\r
+\r
+function run21000event(n, p,q,s: integer) : Boolean;\r
+var result : boolean;\r
+begin\r
+   run21000event := false;\r
+   case n of\r
+     21001 : begin {Phaedor Moch: Coolant + Radioactive}\r
+               if (incargo(4007) >= 1) and (incargo(4014) >= 1) then\r
+               begin\r
+                  bkcolor := 0;\r
+                  tcolor := s;\r
+                  printxy(12,135+(1)*6,'Give the Phaedor Moch a radioactive and a coolant?');\r
+                  mouseshow; \r
+                  result := yesnorequest('Give supplies?',0,31);\r
+                  mousehide;\r
+                  if result then\r
+                  begin\r
+                     removecargo(4007);\r
+                     removecargo(4014);\r
+                     addcargo(6907, true);\r
+                     run21000event := true;\r
+                     addpending(1101, 0);\r
+                     event(500);\r
+                  end else begin\r
+                     printxy(12,135+(2)*6,'No.');\r
+                  end;\r
+               end else begin\r
+                  bkcolor := 0;\r
+                  tcolor := s;\r
+                  printxy(12,135+(1)*6,'(Eng: We have no radioactives and coolants to spare.)');\r
+               end;\r
+            end;\r
+     21002 : begin {Aard: Stratamount}\r
+               if (incargo(3019) >= 1) then\r
+               begin\r
+                  printxy(12,135+(1)*6,'Give the Aard a stratamount?');\r
+                  mouseshow; \r
+                  result := yesnorequest('Give supplies?',0,31);\r
+                  mousehide;\r
+                  if result then\r
+                  begin\r
+                     removecargo(3019);\r
+                     addcargo(1009, true);\r
+                     run21000event := true;\r
+                     addpending(1102, 0);\r
+                     event(500);\r
+                  end else begin\r
+                     printxy(12,135+(2)*6,'No.');\r
+                  end;\r
+               end else begin\r
+                  bkcolor := 0;\r
+                  tcolor := s;\r
+                  printxy(12,135+(1)*6,'(Eng: We have no stratamounts to spare.)');\r
+               end;\r
+            end;\r
+   end;\r
+end;\r
+\r
+procedure checkstring(p,q,s: integer);\r
+var index,index2,i,i2: integer;\r
+begin\r
+   mousehide;\r
+   for i:=135 to 181 do\r
+      fillchar(screen[i,15],288,0);\r
+   for i:=182 to 187 do\r
+      fillchar(screen[i,61],100,0);\r
+   tcolor:=s;\r
+   printxy(12,135,question);\r
+   i:=20;\r
+   while question[i]=' ' do dec(i);\r
+   if i=0 then\r
+   begin\r
+      mouseshow;\r
+      exit;\r
+   end;\r
+   question[0]:=chr(i);\r
+   for j:=1 to i do\r
+      case question[j] of\r
+       ' ' ..'"': question[j]:=chr(ord(question[j])-31);\r
+       ''''..'?': question[j]:=chr(ord(question[j])-35);\r
+       'A' ..'Z': question[j]:=chr(ord(question[j])-36);\r
+       'a' ..'z': question[j]:=chr(ord(question[j])-40);\r
+       '%'       : question[j]:=#55;\r
+      else question[j]:=#1;\r
+      end;       \r
+   index:=0;\r
+   {i:=1;}\r
+   repeat\r
+      inc(index);\r
+      j:=pos(#1+question+#1,c^[index].keyword);\r
+      {if j > 0 then\r
+      begin\r
+        str(index,str1^);\r
+        str(ord(chevent(c^[index].event)),str2^);\r
+        str1^ := str1^ + ',' + str2^;\r
+        str(c^[index].event,str2^);\r
+        printxy(1, i * 6, str1^ + ',' + str2^ + '  ');\r
+        inc(i);\r
+        printxy(1, i * 6, '  ');\r
+      end;}\r
+      if (c^[index].event <> -1) and not chevent(c^[index].event) then\r
+        j := 0;\r
+   until (j>0) or (c^[index].rcode=0);\r
+   fillchar(question,21,ord(' '));\r
+   question[0]:=#20;\r
+   cursorx:=1;\r
+   if j=0 then\r
+   begin\r
+      mouseshow;\r
+      exit;\r
+   end;\r
+   i:=1;\r
+   while (r^[i].index<>c^[index].index) and (i<=maxconverse) do inc(i);\r
+   if i>maxconverse then\r
+   begin\r
+      str(c^[index].index,str1^);\r
+      errorhandler('index:'+str1^+' keyword:'+question+' not found.',6);\r
+   end;\r
+   if (c^[index].runevent<21000) or run21000event(c^[index].runevent,p,q,s) then\r
+   begin\r
+      case c^[index].rcode of\r
+       1 : parsestatement(1,i,p,q,s);\r
+       2 : begin\r
+              j:=1;\r
+              while r^[i+j].index=c^[index].index do inc(j);\r
+              parsestatement(1,i+random(j),p,q,s);\r
+           end;\r
+       3 : begin\r
+              index2:=i;\r
+              i2:=1;\r
+              repeat\r
+                 i2:=parsestatement(i2,index2,p,q,s);\r
+                 inc(index2);\r
+              until r^[i].index<>r^[index2].index;\r
+              printxy(12,182,'Subject:');\r
+           end;\r
+      end; { case }\r
+   end;\r
+   if (c^[index].runevent>19999) and (c^[index].runevent<21000) then\r
+      run20000event(c^[index].runevent);\r
+   mouseshow;\r
+end;\r
+\r
+procedure processkey2;\r
+var ans: char;\r
+    old: integer;\r
+begin\r
+ ans:=upcase(readkey);\r
+ tcolor:=31;\r
+ case ans of\r
+  'A'..'Z',' ','0'..'9','''','-': if contactindex>-1 then\r
+        begin\r
+         if cursorx<20 then\r
+          begin\r
+           for j:=20 downto cursorx do question[j]:=question[j-1];\r
+           question[cursorx]:=ans;\r
+           inc(cursorx);\r
+          end else question[cursorx]:=ans;\r
+         mousehide;\r
+         printxy(57,182,question);\r
+         mouseshow;\r
+        end;\r
+   #8: if contactindex>-1 then\r
+        begin\r
+         if cursorx>1 then dec(cursorx);\r
+         for j:=cursorx to 19 do question[j]:=question[j+1];\r
+         question[20]:=' ';\r
+         mousehide;\r
+         printxy(57,182,question);\r
+         mouseshow;\r
+        end;\r
+   #0: if contactindex>-1 then\r
+        begin\r
+         ans:=readkey;\r
+         case ans of\r
+          #77: if cursorx<20 then inc(cursorx);\r
+          #75: if cursorx>1 then dec(cursorx);\r
+          #83: begin\r
+                for j:=cursorx to 19 do question[j]:=question[j+1];\r
+                mousehide;\r
+                printxy(57,182,question);\r
+                mouseshow;\r
+               end;\r
+          #59: command2(0);\r
+          #60: command2(1);\r
+          #61: command2(2);\r
+          #62: command2(3);\r
+          #63: command2(4);\r
+          #64: command2(5);\r
+         end;\r
+        end\r
+        else\r
+         begin\r
+          ans:=readkey;\r
+          if (ans>#58) and (ans<#65) then command2(ord(ans)-59);\r
+         end;\r
+  #13: if contactindex>-1 then\r
+        begin\r
+         old:=contactindex;\r
+         {checkstring(95,176,170);}\r
+          checkstring(95,42,170);\r
+         if contactindex=-1 then\r
+          begin\r
+           i:=old;\r
+           old:=contactindex;\r
+           contactindex:=i;\r
+           erasecursor;\r
+           contactindex:=old;\r
+          end;\r
+        end;\r
+  #27: done:=true;\r
+  '`': bossmode;\r
+ end;\r
+ idletime:=0;\r
+end;\r
+\r
+procedure mainloop2;\r
+begin\r
+   repeat\r
+      fadestep(8);\r
+  if fastkeypressed then processkey2;\r
+  findmouse2;\r
+  if batindex<8 then inc(batindex) else\r
+   begin\r
+    batindex:=0;\r
+    addtime2;\r
+   end;\r
+  inc(idletime);\r
+  if idletime=maxidle then screensaver;\r
+  if contactindex>-1 then\r
+   begin\r
+    bkcolor:=95;\r
+    printxy(cursorx*5+52,182,question[cursorx]);\r
+    delay(tslice*2);\r
+    bkcolor:=0;\r
+    printxy(cursorx*5+52,182,question[cursorx]);\r
+    delay(tslice*2);\r
+   end\r
+  else delay(tslice*4);\r
+ until done;\r
+end;\r
+\r
+procedure readycrewdata;\r
+begin\r
+ mousehide;\r
+ compressfile(tempdir+'\current',@screen);\r
+ {fading;}\r
+ fadestopmod(-8, 20);\r
+ playmod(true,'sound\crewcomm.mod');\r
+ loadscreen('data\charcom',@screen);\r
+ oldt1:=t1;\r
+ bkcolor:=0;\r
+ tcolor:=170;\r
+ printxy(12,182,'Converse with crew member:');\r
+ done:=false;\r
+ contactindex:=-1;\r
+ alien.conindex:=-1;\r
+ fillchar(question,21,ord(' '));\r
+ question[0]:=#20;\r
+ new(str1);\r
+ new(str2);\r
+ new(c);\r
+ new(r);\r
+ cursorx:=1;\r
+ displaycrewnames;\r
+ {fadein;}\r
+ mouseshow;\r
+end;\r
+\r
+procedure conversewithcrew;\r
+begin\r
+   clearconvflags;\r
+   readycrewdata;\r
+   mainloop2;\r
+   dispose(str2);\r
+   dispose(str1);\r
+   dispose(c);\r
+   dispose(r);\r
+   {stopmod;}\r
+   removedata; {this one calls removedata in utils2}\r
+   {haltmod;}\r
+end;\r
+\r
+{*****************************************************************************}\r
+\r
+procedure loadbackground(n: integer);\r
+var str1: string[2];\r
+begin\r
+ str(((n-1) div 2)+1,str1);\r
+ loadscreen('data\back'+str1,backgr);\r
+ {new(p);}\r
+ mymove(colors,p^,192);\r
+ y:=(n-1) mod 2;\r
+ if y=1 then mymove(backgr^[100],backgr^,8000);\r
+ mousehide;\r
+ for i:=11 to 110 do\r
+  for j:=0 to 319 do\r
+   if (screen[i,j]=255) then screen[i,j]:=backgr^[i-11,j];\r
+ mouseshow;\r
+end;\r
+\r
+procedure loadalienpic(n: integer);\r
+var str1: string[2];\r
+begin\r
+ new(aliens);\r
+ str(n,str1);\r
+ loadscreen('data\alien'+str1,aliens);\r
+ for j:=0 to 159 do colors[j]:=p^[j];\r
+ {dispose(p);}\r
+ if n=10 then exit;\r
+ mousehide;\r
+ for i:=11 to 110 do\r
+  for j:=0 to 159 do\r
+   if aliens^[i-11,j]>0 then screen[i,j+20]:=aliens^[i-11,j];\r
+ mouseshow;\r
+end;\r
+\r
+procedure getshipinfo;\r
+var confile: file of alientype;\r
+    done: boolean;\r
+    temp: alientype;\r
+    str1: string[11];\r
+    r: real;\r
+begin\r
+ assign(confile,tempdir+'\contacts.dta');\r
+ reset(confile);\r
+ if ioresult<>0 then errorhandler(tempdir+'\contacts.dta',1);\r
+ done:=false;\r
+ repeat\r
+  read(confile,temp);\r
+  if ioresult<>0 then done:=true;\r
+  if (not done) and (temp.id>0) and (temp.id=ship.wandering.alienid) then done:=true;\r
+ until done;\r
+ close(confile);\r
+ printxy(217,20,temp.name);\r
+ printxy(217,20,temp.name);\r
+ printxy(217,30,'Vidcom');\r
+ if temp.id>1000 then printxy(217,40,'Unknown')\r
+  else printxy(217,40,systems[tempplan^[temp.id].system].name);\r
+ str1:=chr(hi(temp.techmin)+48)+'.'+chr(lo(temp.techmin)+48);\r
+ printxy(217,50,'Min Tech: '+str1);\r
+ str1:=chr(hi(temp.techmax)+48)+'.'+chr(lo(temp.techmax)+48);\r
+ printxy(217,60,'Max Tech: '+str1);\r
+ printxy(217,70,'Status:');\r
+ if temp.war then printxy(252,70,'War')\r
+  else printxy(252,70,'Peace');\r
+ if temp.anger=0 then\r
+  begin\r
+   if temp.congeniality>20 then i:=3\r
+    else i:=1;\r
+  end\r
+ else\r
+  begin\r
+   r:=temp.congeniality/temp.anger;\r
+   if r<0.3 then i:=5\r
+   else if r<0.7 then i:=4\r
+   else if round(r)=1 then i:=2\r
+   else i:=3;\r
+  end;\r
+ case i of\r
+  1: str1:='Afraid';\r
+  2: str1:='Indifferent';\r
+  3: str1:='Friendly';\r
+  4: str1:='Angry';\r
+  5: str1:='Violent';\r
+ end;\r
+ printxy(217,80,str1);\r
+end;\r
+\r
+procedure getcontactindex;\r
+var i: integer;\r
+    s: string[14];\r
+begin\r
+ i:=0;\r
+ if alien.conindex>29 then\r
+  begin\r
+   i:=1069+alien.conindex;\r
+   randseed:=alien.conindex;\r
+   loadbackground(random(numback)+1);\r
+   playmod(true,'sound\probe.mod');\r
+  end\r
+ else\r
+  begin\r
+   i:=alien.conindex;\r
+   randseed:=alien.conindex*1131;\r
+   case i of\r
+     1: s:='sengzhac.mod';\r
+     2: s:='dpak.mod';\r
+     3: s:='aard.mod';\r
+     4: s:='ermigen.mod';\r
+     5: s:='titarian.mod';\r
+     6: s:='quai.mod';\r
+     7: s:='scaveng.mod';\r
+     8: s:='icon.mod';\r
+     9: s:='guild.mod';\r
+    10: s:='phador.mod';\r
+    11: s:='void.mod';\r
+   else s:='';\r
+   end;\r
+   {if ioresult<>0 then printxy(217,20,'sound\'+s);}\r
+   if s<>'' then playmod(true,'sound\'+s);\r
+   {if checkerror then printxy(217,20,'checkerror');\r
+   if not playing then printxy(217,20,'not playing');\r
+   if ModuleError = MERR_MEMORY then printxy(217,20,'MERR_MEMORY');\r
+   if ModuleError = MERR_FILE then printxy(217,20,'MERR_FILE');\r
+   if ModuleError = MERR_TYPE then printxy(217,20,'MERR_TYPE');\r
+   if ModuleError = MERR_CORRUPT then printxy(217,20,'MERR_CORRUPT');}\r
+   case i of\r
+     1: j:=7;\r
+     2: j:=18;\r
+     3: j:=9;\r
+     4: j:=15;\r
+     5: j:=22;\r
+     6: j:=17;\r
+     7: j:=4;\r
+     8: j:=14;\r
+     9: j:=2;\r
+    10: j:=21;\r
+    11: j:=19;\r
+   end;\r
+   loadbackground(j);\r
+   if i<11 then loadalienpic(i);\r
+   animatealien;\r
+   i:=i+999;\r
+  end;\r
+ randomize;\r
+ contactindex:=i;\r
+end;\r
+\r
+procedure getinfo;\r
+var str1: string[11];\r
+    r: real;\r
+begin\r
+ if infomode then\r
+  begin\r
+   infomode:=false;\r
+   mousehide;\r
+   for i:=20 to 101 do\r
+    mymove(backgr^[i-11,222],screen[i,222],19);\r
+   mouseshow;\r
+   exit;\r
+  end;\r
+ if contactindex=-1 then exit;\r
+ infomode:=true;\r
+ tcolor:=31;\r
+ bkcolor:=255;\r
+ if shipflag then getshipinfo\r
+ else begin\r
+  printxy(217,20,alien.name);\r
+  if curplan=alien.id then\r
+   begin\r
+    if hi(alien.techmax)>=3 then printxy(217,30,'Radio')\r
+     else printxy(217,30,'Visual');\r
+   end\r
+  else printxy(217,30,'Subspace');\r
+  printxy(217,40,systems[tempplan^[curplan].system].name);\r
+  str1:=chr(hi(alien.techmin)+48)+'.'+chr(lo(alien.techmin)+48);\r
+  printxy(217,50,'Min Tech: '+str1);\r
+  str1:=chr(hi(alien.techmax)+48)+'.'+chr(lo(alien.techmax)+48);\r
+  printxy(217,60,'Max Tech: '+str1);\r
+  printxy(217,70,'Status:');\r
+  if alien.war then printxy(252,70,'War')\r
+   else printxy(252,70,'Peace');\r
+  if alien.anger=0 then\r
+   begin\r
+    if alien.congeniality>20 then i:=3\r
+     else i:=1;\r
+   end\r
+  else\r
+   begin\r
+    r:=alien.congeniality/alien.anger;\r
+    if r<0.3 then i:=5\r
+    else if r<0.7 then i:=4\r
+    else if round(r)=1 then i:=2\r
+    else i:=3;\r
+   end;\r
+  case i of\r
+   1: str1:='Afraid';\r
+   2: str1:='Indifferent';\r
+   3: str1:='Friendly';\r
+   4: str1:='Angry';\r
+   5: str1:='Violent';\r
+  end;\r
+  printxy(217,80,str1);\r
+ end;\r
+end;\r
+\r
+procedure findmouse3;\r
+begin\r
+ if not mouse.getstatus then exit;\r
+ case mouse.x of\r
+  308..317: if (mouse.y>142) and (mouse.y<169) then done:=true;\r
+  247..267: if (mouse.y>104) and (mouse.y<111) then getinfo;\r
+ end;\r
+ idletime:=0;\r
+end;\r
+\r
+procedure processkey3;\r
+var ans: char;\r
+begin\r
+ ans:=upcase(readkey);\r
+ tcolor:=26;\r
+ case ans of\r
+  'A'..'Z',' ','0'..'9','''','-': if contactindex>-1 then\r
+        begin\r
+         if cursorx<20 then\r
+          begin\r
+           for j:=20 downto cursorx do question[j]:=question[j-1];\r
+           question[cursorx]:=ans;\r
+           inc(cursorx);\r
+          end else question[cursorx]:=ans;\r
+         mousehide;\r
+         printxy(57,182,question);\r
+         mouseshow;\r
+        end;\r
+   #8: if contactindex>-1 then\r
+        begin\r
+         if cursorx>1 then dec(cursorx);\r
+         for j:=cursorx to 19 do question[j]:=question[j+1];\r
+         question[20]:=' ';\r
+         mousehide;\r
+         printxy(57,182,question);\r
+         mouseshow;\r
+        end;\r
+   #0: if contactindex>-1 then\r
+        begin\r
+         ans:=readkey;\r
+         case ans of\r
+          #77: if cursorx<20 then inc(cursorx);\r
+          #75: if cursorx>1 then dec(cursorx);\r
+          #83: begin\r
+                for j:=cursorx to 19 do question[j]:=question[j+1];\r
+                mousehide;\r
+                printxy(57,182,question);\r
+                mouseshow;\r
+               end;\r
+         end;\r
+        end;\r
+  #13: if contactindex>-1 then checkstring(47,55,28);{checkstring(47,31,28);}\r
+  '?','/': getinfo;\r
+  #27: done:=true;\r
+  '`': bossmode;\r
+  #10: printbigbox(GetHeapStats1,GetHeapStats2);\r
+ end;\r
+ idletime:=0;\r
+end;\r
+\r
+procedure animatealien;\r
+begin\r
+ mousehide;\r
+ case alien.conindex of\r
+  1: begin\r
+      if indexa<>255 then\r
+       begin\r
+        if indexa<6 then inc(indexa) else indexa:=255;\r
+        if (indexa<>255) then\r
+         begin\r
+          for i:=0 to 9 do\r
+           for j:=0 to 32 do\r
+            if aliens^[i+indexa*11,j+220]>0 then screen[i+37,j+85]:=aliens^[i+indexa*11,j+220]\r
+             else screen[i+37,j+85]:=backgr^[i+26,j+85];\r
+         end;\r
+       end\r
+      else if random(20)=0 then indexa:=0;\r
+      if indexb<14 then inc(indexb) else indexb:=0;\r
+      if indexb=0 then\r
+       begin\r
+        for i:=0 to 18 do\r
+         for j:=0 to 22 do\r
+          if aliens^[i+77,j+9]>0 then screen[i+88,j+29]:=aliens^[i+77,j+9]\r
+           else screen[i+88,j+29]:=backgr^[i+77,j+29];\r
+       end\r
+      else\r
+       for i:=0 to 18 do\r
+        for j:=0 to 22 do\r
+         if aliens^[i+((indexb-1) mod 7)*20,((indexb-1) div 7)*24+j+160]>0\r
+          then screen[i+88,j+29]:=aliens^[i+((indexb-1) mod 7)*20,((indexb-1) div 7)*24+j+160]\r
+          else screen[i+88,j+29]:=backgr^[i+77,j+29];\r
+      if random(20)=0 then\r
+       begin\r
+        if indexc<7 then inc(indexc) else indexc:=0;\r
+        for i:=0 to 21 do\r
+         for j:=0 to 42 do\r
+          if aliens^[i+indexc*23,260+j]>0 then screen[i+89,j+139]:=aliens^[i+indexc*23,260+j]\r
+           else screen[i+89,j+139]:=backgr^[i+78,j+139];\r
+       end;\r
+     end;\r
+  2: if ((random(200)=0) and (indexa=0)) or ((indexa<>255) and (indexa<>0)) then\r
+      begin\r
+       if indexb>0 then dec(indexb) else\r
+        begin\r
+         indexb:=3;\r
+         if indexa<12 then inc(indexa) else\r
+          begin\r
+           indexa:=255;\r
+           mouseshow;\r
+           exit;\r
+          end;\r
+        end;\r
+       dec(indexa);\r
+       for i:=0 to 54 do\r
+        for j:=0 to 34 do\r
+         if aliens^[i+(indexa mod 3)*59+2,(indexa div 3)*38+j+164]>0\r
+          then screen[i+16,j+140]:=aliens^[i+(indexa mod 3)*59+2,(indexa div 3)*38+j+164]\r
+           else screen[i+16,j+140]:=backgr^[i+5,j+140];\r
+       inc(indexa);\r
+      end;\r
+  3: if indexa=0 then\r
+      begin\r
+       randomize;\r
+       indexa:=random(1000);\r
+       indexb:=random(5);\r
+       indexa:=1;\r
+       for i:=0 to 23 do\r
+        for j:=0 to 23 do\r
+         if aliens^[i+indexb*30,j+170]>0 then screen[i+20,j+90]:=aliens^[i+indexb*30,j+170]\r
+          else screen[i+20,j+90]:=backgr^[i+9,j+90];\r
+      end;\r
+  4: if indexa<>255 then\r
+      begin\r
+       for i:=0 to 11 do\r
+        for j:=0 to 56 do\r
+         if aliens^[i+indexa*13,170+j]>0 then screen[i+23,j+91]:=aliens^[i+indexa*13,170+j]\r
+          else screen[i+23,j+91]:=backgr^[i+12,j+91];\r
+       if indexa<9 then inc(indexa) else indexa:=255;\r
+      end\r
+     else if random(20)=0 then indexa:=0;\r
+  5: begin\r
+      if indexa<5 then inc(indexa) else indexa:=0;\r
+      for i:=0 to 10 do\r
+       move(aliens^[i+indexa*12,170],screen[29+i,94],49);\r
+      if random(20)=0 then\r
+       begin\r
+        if indexb<4 then inc(indexb) else indexb:=0;\r
+        for i:=0 to 27 do\r
+         for j:=0 to 25 do\r
+          if aliens^[i+indexb*28,220+j]>0 then screen[i+41,j+57]:=aliens^[i+indexb*28,220+j]\r
+           else screen[i+41,j+57]:=backgr^[i+30,j+57];\r
+       end;\r
+      if random(20)=0 then\r
+       begin\r
+        if indexc<4 then inc(indexc) else indexc:=0;\r
+        for i:=0 to 27 do\r
+         for j:=0 to 25 do\r
+          if aliens^[i+indexb*28,250+j]>0 then screen[i+41,j+155]:=aliens^[i+indexb*28,250+j]\r
+           else screen[i+41,j+155]:=backgr^[i+30,j+155];\r
+       end;\r
+     end;\r
+  6: begin\r
+      if indexa<8 then inc(indexa) else indexa:=0;\r
+      for i:=0 to 19 do\r
+       for j:=0 to 37 do\r
+        if aliens^[i+indexa*20,j+170]>0 then screen[i+40,j+81]:=aliens^[i+indexa*20,j+170]\r
+         else screen[i+40,j+81]:=backgr^[i+19,j+81];\r
+     end;\r
+  7: begin\r
+      if indexa<18 then inc(indexa) else indexa:=0;\r
+      for i:=0 to 2 do\r
+       move(aliens^[i+indexa*4,180],screen[i+27,88],21);\r
+      if indexb<6 then inc(indexb) else indexb:=0;\r
+      for i:=0 to 33 do\r
+       for j:=0 to 20 do\r
+        if aliens^[i+120,j+indexb*21]>0 then screen[i+77,j+88]:=aliens^[i+120,j+indexb*21]\r
+         else screen[i+77,j+88]:=backgr^[i+66,j+88];\r
+     end;\r
+  8: if indexa<>255 then\r
+      begin\r
+       if indexa<8 then inc(indexa) else indexa:=255;\r
+       if (indexa<>255) then\r
+        begin\r
+         for i:=0 to 19 do\r
+          for j:=0 to 52 do\r
+           if aliens^[i+indexa*20,j+250]>0 then screen[i+57,j+77]:=aliens^[i+indexa*20,j+250]\r
+            else screen[i+57,j+77]:=backgr^[i+46,j+77];\r
+         end;\r
+      end\r
+     else if random(30)=0 then indexa:=0;\r
+  9: begin\r
+      if random(15)=0 then\r
+       begin\r
+        if indexa<7 then inc(indexa) else indexa:=0;\r
+        if indexa=0 then\r
+         begin\r
+          for i:=0 to 21 do\r
+           for j:=0 to 32 do\r
+            if aliens^[i+74,j+33]>0 then screen[i+85,j+53]:=aliens^[i+74,j+33]\r
+             else screen[i+85,j+53]:=backgr^[i+74,j+53];\r
+         end\r
+        else\r
+         for i:=0 to 21 do\r
+          for j:=0 to 32 do\r
+           if aliens^[i+indexa*25-24,j+162]>0 then screen[i+85,j+53]:=aliens^[i+indexa*25-24,j+162]\r
+            else screen[i+85,j+53]:=backgr^[i+74,j+53];\r
+       end\r
+      else if random(15)=0 then\r
+       begin\r
+        if indexb<5 then inc(indexb) else indexb:=0;\r
+        if indexb=0 then\r
+         begin\r
+          for i:=0 to 22 do\r
+           for j:=0 to 12 do\r
+            if aliens^[i+51,j+136]>0 then screen[i+62,j+156]:=aliens^[i+51,j+136]\r
+             else screen[i+62,j+156]:=backgr^[i+51,j+156];\r
+         end\r
+        else\r
+         for i:=0 to 22 do\r
+          for j:=0 to 12 do\r
+           if aliens^[i+indexb*26-26,j+200]>0 then screen[i+62,j+156]:=aliens^[i+indexb*26-26,j+200]\r
+            else screen[i+62,j+156]:=backgr^[i+51,j+156];\r
+       end;\r
+     end;\r
+  10: begin\r
+        if random(30)=0 then indexa:=random(9);\r
+        if indexb>0 then dec(indexb) else\r
+         begin\r
+          indexb:=20;\r
+          if indexa<8 then inc(indexa) else indexa:=0;\r
+         end;\r
+        for i:=0 to 8 do\r
+         move(aliens^[i+indexa*10+101],screen[i+51,111],50);\r
+       end;\r
+ end;\r
+ mouseshow;\r
+end;\r
+\r
+procedure mainloop3;\r
+begin\r
+   repeat\r
+      fadestep(8);\r
+  findmouse3;\r
+  if fastkeypressed then processkey3;\r
+  if batindex<8 then inc(batindex) else\r
+   begin\r
+    batindex:=0;\r
+    addtime2;\r
+   end;\r
+  inc(idletime);\r
+  if idletime=maxidle then screensaver;\r
+  if contactindex>-1 then\r
+   begin\r
+    bkcolor:=47;\r
+    printxy(cursorx*5+52,182,question[cursorx]);\r
+    delay(tslice*2);\r
+    bkcolor:=0;\r
+    printxy(cursorx*5+52,182,question[cursorx]);\r
+    delay(tslice*2);\r
+   end\r
+  else delay(tslice*4);\r
+  animatealien;\r
+ until done;\r
+end;\r
+\r
+procedure getlocals;\r
+var confile: file of alientype;\r
+    done: boolean;\r
+begin\r
+ if not showplanet then\r
+  begin\r
+   contactindex:=-1;\r
+   exit;\r
+  end;\r
+ assign(confile,tempdir+'\contacts.dta');\r
+ reset(confile);\r
+ if ioresult<>0 then errorhandler(tempdir+'\contacts.dta',1);\r
+ done:=false;\r
+ repeat\r
+  read(confile,alien);\r
+  if ioresult<>0 then done:=true;\r
+ until (done) or ((alien.id>0) and (alien.id=curplan));\r
+ close(confile);\r
+ if done then contactindex:=-1 else contactindex:=curplan;\r
+ if (tempplan^[curplan].system=45) and (chevent(27)) then\r
+  begin\r
+   contactindex:=-1;\r
+   tempplan^[curplan].notes:=tempplan^[curplan].notes and not 2;\r
+  end;\r
+ contactsequence(curplan,random(3));\r
+end;\r
+\r
+procedure getship;\r
+var confile: file of alientype;\r
+    done: boolean;\r
+begin\r
+ if ship.wandering.alienid>19999 then\r
+  begin\r
+   contactindex:=-1;\r
+   contactsequence(-1,random(3));\r
+   exit;\r
+  end;\r
+ assign(confile,tempdir+'\contacts.dta');\r
+ reset(confile);\r
+ if ioresult<>0 then errorhandler(tempdir+'\contacts.dta',1);\r
+ done:=false;\r
+ repeat\r
+  read(confile,alien);\r
+  if ioresult<>0 then done:=true;\r
+ until (done) or ((alien.id>0) and (alien.id=ship.wandering.alienid));\r
+ close(confile);\r
+ if done then contactindex:=-1 else contactindex:=alien.id;\r
+ shipflag:=true;\r
+ contactsequence(alien.id,random(3));\r
+end;\r
+\r
+procedure checkotherevents2;\r
+var t   : ^eventarray;\r
+    f   : file of eventarray;\r
+    done : boolean;\r
+    n,i         : integer;\r
+\r
+   procedure printstatement;\r
+   var done : boolean;\r
+      j            : integer;\r
+   begin\r
+      mousehide;\r
+      for j:=127 to 179 do\r
+        fillchar(screen[j,5],300,0);\r
+      str2^:=t^[i].msg;\r
+      done:=false;\r
+      y:=0;\r
+      repeat\r
+        str1^:=str2^;\r
+        j:=56;\r
+        if ord(str1^[0])>56 then\r
+        begin\r
+           while str1^[j]<>' ' do dec(j);\r
+           str2^:=copy(str1^,j+1,ord(str1^[0])-j);\r
+           str1^[0]:=chr(j-1);\r
+        end else done:=true;\r
+        printxy(12,135+y*6,str1^);\r
+        inc(y);\r
+      until done;\r
+      if n<10 then i:=9 else i:=0;\r
+      mouseshow;\r
+      eventflag:=true;\r
+   end;\r
+\r
+begin\r
+   if contactindex=-1 then exit;\r
+   n:=alien.conindex-1;\r
+   if n>10 then exit;\r
+   new(t);\r
+   assign(f,'data\event.dta');\r
+   reset(f);\r
+   if ioresult<>0 then errorhandler('data\event.dta',1);\r
+   seek(f,n);\r
+   if ioresult<>0 then errorhandler('data\event.dta',5);\r
+   read(f,t^);\r
+   if ioresult<>0 then errorhandler('data\event.dta',5);\r
+   close(f);\r
+   if (n<10) then\r
+   begin\r
+      for i:=0 to 9 do if not chevent(n*10+50+i) then\r
+      begin\r
+        if t^[i].want>20000 then\r
+        begin\r
+           if chevent(t^[i].want-20000) then printstatement;\r
+        end\r
+        else if (t^[i].want>0) then\r
+        begin\r
+           if incargo(t^[i].want)>0 then printstatement;\r
+        end\r
+        else if (t^[i].want=0) and (t^[i].give>0) then printstatement;\r
+      end;\r
+   end\r
+   else\r
+   begin\r
+      for i:=9 downto 0 do if not chevent(n*10+50+i) then\r
+      begin\r
+        if t^[i].want>20000 then\r
+        begin\r
+           if chevent(t^[i].want-20000) then printstatement;\r
+        end\r
+     else if (t^[i].want>0) then\r
+     begin\r
+       if incargo(t^[i].want)>0 then printstatement;\r
+     end\r
+     else if (t^[i].want=0) and (t^[i].give>0) then printstatement;\r
+      end;\r
+   end;\r
+   dispose(t);\r
+end;\r
+\r
+procedure readydata3(hail: boolean);\r
+begin\r
+   mousehide;\r
+   compressfile(tempdir+'\current',@screen);\r
+   {fading;}\r
+   fadestopmod(-8, 20);\r
+   loadscreen('data\com',@screen);\r
+   {fadein;}\r
+   new(tmpm);\r
+   for i:=0 to 15 do\r
+   begin\r
+      mymove(screen[i+130,20],tmpm^[i],4);\r
+      fillchar(screen[i+130,20],16,0);\r
+   end;\r
+   mousesetcursor(tmpm^);\r
+   dispose(tmpm);\r
+   done:=false;\r
+   bkcolor:=0;\r
+   tcolor:=28;\r
+   infomode:=false;\r
+   fillchar(question,21,ord(' '));\r
+   question[0]:=#20;\r
+   oldt1:=t1;\r
+   cursorx:=1;\r
+   indexa:=0;\r
+   indexb:=0;\r
+   oldcontactindex:=-1;\r
+   shipflag:=false;\r
+   eventflag:=false;\r
+   aliens:=nil;\r
+   new(str1);\r
+   new(str2);\r
+   new(c);\r
+   new(r);\r
+   new(p);\r
+   {$IFDEF DEMO}\r
+   contactindex:=-1;\r
+   {$ELSE}\r
+   if hail then getship\r
+   else getlocals;\r
+   {$ENDIF}\r
+   mouseshow;\r
+   if contactindex=-1 then\r
+   begin\r
+      mousehide;\r
+      for i:=10 to 110 do\r
+        for j:=0 to 319 do\r
+           if (screen[i,j]=255) and (i mod 2=0) then screen[i,j]:=random(32)+64\r
+           else if (screen[i,j]=255) then screen[i,j]:=random(32)+96;\r
+      {fadein;}\r
+      tcolor:=28;\r
+      bkcolor:=0;\r
+{$IFDEF DEMO}\r
+      printxy(12,140,'Wouldn''t it be cool to talk to aliens?');\r
+      printxy(12,150,'Buy the game and you can...');\r
+      printxy(12,160,'11 Alien races... 11 awesome songs...');\r
+      printxy(12,170,'You gotta buy the game!');\r
+{$ELSE}\r
+      printxy(12,170,'No response...');\r
+{$ENDIF}\r
+      mouseshow;\r
+      repeat\r
+        findmouse3;\r
+        for i:=64 to 95 do\r
+           colors[i]:=colors[random(32)];\r
+        fillchar(colors[96],96,0);\r
+        palettedirty := true;\r
+        fadestep(8);\r
+        {set256colors(colors);}\r
+        delay(5);\r
+        for i:=96 to 128 do\r
+           colors[i]:=colors[random(32)];\r
+        fillchar(colors[64],96,0);\r
+        palettedirty := true;\r
+        fadestep(0);\r
+        {set256colors(colors);}\r
+      until (fastkeypressed) or (done);\r
+      while fastkeypressed do readkey;\r
+      fadestopmod(-8, 20);\r
+      done:=true;\r
+   end\r
+   else\r
+   begin\r
+      oldcontactindex:=contactindex;\r
+      mousehide;\r
+      printxy(12,182,'Subject:');\r
+      mouseshow;\r
+      getcontactindex;\r
+      loadconversation;\r
+      {fadein;}\r
+      checkotherevents2;\r
+      if not eventflag then\r
+      begin\r
+        question:='HI';\r
+        if contactindex>-1 then checkstring(47,55,28); {checkstring(47,31,28);}\r
+      end;\r
+   end;\r
+end;\r
+\r
+procedure checkotherevents(n: integer);\r
+var t: ^eventarray;\r
+    f: file of eventarray;\r
+begin\r
+   new(t);\r
+   assign(f,'data\event.dta');\r
+   reset(f);\r
+   if ioresult<>0 then errorhandler('data\event.dta',1);\r
+   seek(f,n);\r
+   if ioresult<>0 then errorhandler('data\event.dta',5);\r
+   read(f,t^);\r
+   if ioresult<>0 then errorhandler('data\event.dta',5);\r
+   close(f);\r
+   if (n<10) then\r
+   begin\r
+      for i:=0 to 9 do if not chevent(n*10+50+i) then\r
+      begin\r
+        if t^[i].want>20000 then\r
+        begin\r
+           if chevent(t^[i].want-20000) then\r
+           begin\r
+              if t^[i].give>20000 then event(t^[i].give-20000)\r
+              else if t^[i].give>0 then addcargo(t^[i].give, true);\r
+              event(n*10+50+i);\r
+              i:=9;\r
+           end;\r
+        end\r
+        else if (t^[i].want>0) then\r
+        begin\r
+           if incargo(t^[i].want)>0 then\r
+           begin\r
+              if (t^[i].give>20000) and (t^[i].give<30000) then event(t^[i].give-20000)\r
+              else if (t^[i].give>0) and (t^[i].give<30000) then addcargo(t^[i].give, true);\r
+              event(n*10+50+i);\r
+              removecargo(t^[i].want);\r
+              i:=9;\r
+           end;\r
+        end\r
+        else if (t^[i].want=0) and (t^[i].give>0) then\r
+        begin\r
+           if (t^[i].give>20000) and (t^[i].give<30000) then event(t^[i].give-20000)\r
+           else if (t^[i].give>0) and (t^[i].give<30000) then addcargo(t^[i].give, true);\r
+           event(n*10+50+i);\r
+           i:=9;\r
+        end;\r
+      end;\r
+   end\r
+   else\r
+   begin\r
+      for i:=9 downto 0 do if not chevent(n*10+50+i) then\r
+      begin\r
+        if t^[i].want>20000 then\r
+        begin\r
+           if chevent(t^[i].want-20000) then\r
+           begin\r
+              if t^[i].give>20000 then event(t^[i].give-20000)\r
+              else if t^[i].give>0 then addcargo(t^[i].give, true);\r
+              event(n*10+50+i);\r
+              i:=0;\r
+           end;\r
+        end\r
+        else if (t^[i].want>0) then\r
+        begin\r
+           if incargo(t^[i].want)>0 then\r
+           begin\r
+              if (t^[i].give>20000) and (t^[i].give<30000) then event(t^[i].give-20000)\r
+              else if (t^[i].give>0) and (t^[i].give<30000) then addcargo(t^[i].give, true);\r
+              event(n*10+50+i);\r
+              removecargo(t^[i].want);\r
+              i:=0;\r
+           end;\r
+        end\r
+        else if (t^[i].want=0) and (t^[i].give>0) then\r
+        begin\r
+           if (t^[i].give>20000) and (t^[i].give<30000) then event(t^[i].give-20000)\r
+           else if (t^[i].give>0) and (t^[i].give<30000) then addcargo(t^[i].give, true);\r
+           event(n*10+50+i);\r
+           i:=0;\r
+        end;\r
+      end;\r
+   end;\r
+   dispose(t);\r
+end;\r
+\r
+procedure removedata;\r
+var n: integer;\r
+begin\r
+ n:=alien.conindex-1;\r
+ if aliens<>nil then dispose(aliens);\r
+ dispose(str2);\r
+ dispose(str1);\r
+ dispose(c);\r
+ dispose(r);\r
+ dispose(p);\r
+ {stopmod;}\r
+ {fading;}\r
+ fadestopmod(-8, 20);\r
+\r
+ loadscreen('data\cloud',backgr);\r
+ if showplanet then\r
+  begin\r
+   if ((tempplan^[curplan].state=6) and (tempplan^[curplan].mode=2)) then makeastoroidfield\r
+    else if (tempplan^[curplan].state=0) and (tempplan^[curplan].mode=1) then makecloud;\r
+  end;\r
+ mousehide;\r
+ mouse.setmousecursor(random(3));\r
+ loadscreen(tempdir+'\current',@screen);\r
+ bkcolor:=3;\r
+ displaytextbox(false);\r
+ textindex:=25;\r
+ {fadein;}\r
+ mouseshow;\r
+ anychange:=true;\r
+ t1:=oldt1;\r
+ if (oldcontactindex<>-1) and (n>-1) and (n<11) then\r
+  begin\r
+   if n<9 then event(n);\r
+   if n=10 then event(9);\r
+   checkotherevents(n);\r
+  end;\r
+end;\r
+\r
+procedure continuecontact(hail: boolean);\r
+begin\r
+ clearconvflags;\r
+ readydata3(hail);\r
+ if contactindex<>-1 then mainloop3;\r
+ removedata;\r
+end;\r
+\r
+begin\r
+end.\r
diff --git a/code/comm2.pas b/code/comm2.pas
new file mode 100644 (file)
index 0000000..dd093cb
--- /dev/null
@@ -0,0 +1,1064 @@
+unit comm2;\r
+(********************************************************************\r
+    This file is part of Ironseed.\r
+\r
+    Ironseed is free software: you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation, either version 3 of the License, or\r
+    (at your option) any later version.\r
+\r
+    Ironseed is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with Ironseed.  If not, see <http://www.gnu.org/licenses/>.\r
+********************************************************************)\r
+\r
+{***************************\r
+   Communication unit #2 for IronSeed\r
+\r
+   Channel 7\r
+   Destiny: Virtual\r
+\r
+\r
+   Copyright 1994\r
+\r
+***************************}\r
+\r
+{$O+}\r
+\r
+interface\r
+\r
+uses data;\r
+\r
+procedure computerlogs(n: integer);\r
+procedure trade;\r
+\r
+implementation\r
+\r
+uses crt, gmouse, weird, journey, utils, modplay, comm, heapchk;\r
+\r
+const\r
+ maxlogentries= 256;\r
+type\r
+ mousearray     = array[0..6] of mouseicontype;\r
+   titlebody    = record\r
+                     id   : Integer;\r
+                     text : string[49];\r
+                  end;    \r
+ titletype      = array[0..maxlogentries-1] of titlebody;\r
+ computerlogtype = array[0..24] of string[49];\r
+ alienstuffarray = array[1..20] of integer;\r
+var\r
+ i,j,index,logindex: integer;\r
+ tmpm: ^mousearray;\r
+ l: ^computerlogtype;\r
+ titles: ^titletype;\r
+ qmode,done: boolean;\r
+ cr: ^createarray;\r
+ alienstuff,tradestuff: ^alienstuffarray;\r
+ trademode,cargoindex,tradeindex,stuffindex,alienworth,tradeworth: integer;\r
+ str1: string[3];\r
+\r
+procedure printxy2(x1,y1: integer; s: string);\r
+var i,j,a,x,y,t        : integer;\r
+   bright      : boolean;\r
+begin\r
+   t:=tcolor;\r
+   bright := false;\r
+   x1:=x1+4;\r
+   for j:=1 to length(s) do\r
+   begin\r
+      if bright then\r
+        tcolor:=31\r
+      else\r
+        tcolor:=t;\r
+      y:=y1;\r
+      if s[j] = #200 then\r
+      begin\r
+        bright := not bright;\r
+      end else begin\r
+        for i:=0 to 5 do\r
+        begin\r
+           x:=x1;  { this stupid offset is pissing me off!!!!}\r
+           inc(y);\r
+           for a:=7 downto 4 do\r
+           begin\r
+              inc(x);\r
+              if font[ship.options[7],ord(s[j]),i div 2] and (1 shl a)>0 then screen[y,x]:=tcolor\r
+              else if bkcolor<255 then screen[y,x]:=bkcolor;\r
+           end;\r
+           dec(tcolor,2);\r
+           x:=x1;\r
+           inc(y);\r
+           inc(i);\r
+           for a:=3 downto 0 do\r
+           begin\r
+              inc(x);\r
+              if font[ship.options[7],ord(s[j]),i div 2] and (1 shl a)>0 then screen[y,x]:=tcolor\r
+              else if bkcolor<255 then screen[y,x]:=bkcolor;\r
+           end;\r
+           dec(tcolor,2);\r
+        end;\r
+        x1:=x1+5;\r
+        if bkcolor<255 then for i:=1 to 6 do screen[y1+i,x1]:=bkcolor;\r
+      end;\r
+   end;\r
+   tcolor:=t;\r
+end;\r
+\r
+function getlogindex(log : Integer):Integer;\r
+var\r
+   i : Integer;\r
+   s : string[10];\r
+begin\r
+   for i := 0 to maxlogentries - 1 do\r
+   begin\r
+      if titles^[i].id = log then\r
+      begin\r
+        getlogindex := i;\r
+        exit;\r
+      end;\r
+   end;\r
+   str(log, s);\r
+   errorhandler('data\titles.dta : ' + s,5);\r
+   getlogindex := -1;\r
+end;\r
+\r
+procedure loadlog(n: integer);\r
+var\r
+   f : file of computerlogtype;\r
+   s : string[10];\r
+begin\r
+   str(n, s);\r
+   assign(f,'data\log.dta');\r
+   reset(f);\r
+   if ioresult<>0 then errorhandler('data\log.dta',1);\r
+   seek(f,n);\r
+   read(f,l^);\r
+   if ioresult<>0 then errorhandler('data\log.dta : ' + s,5);\r
+   close(f);\r
+end;\r
+\r
+procedure displaylist;\r
+var i: integer;\r
+begin\r
+   mousehide;\r
+   tcolor:=79;\r
+   bkcolor:=0;\r
+   y:=13;\r
+   i:=logindex-1;\r
+   if i>-1 then\r
+      repeat\r
+        dec(y);\r
+        printxy2(6,14+y*6,titles^[getlogindex(logs[i])].text);\r
+        dec(i);\r
+      until (i<0) or (y=0);\r
+   if y>0 then\r
+      for i:=14 to y*6+14 do\r
+        fillchar(screen[i,8],246,0);\r
+   y:=12;\r
+   i:=logindex;\r
+   repeat\r
+      inc(y);\r
+      if i=logindex then bkcolor:=9 else bkcolor:=0;\r
+      printxy2(6,14+y*6,titles^[getlogindex(logs[i])].text);\r
+      inc(i);\r
+   until (i=maxlogentries) or (y=25) or (logs[i]<0);\r
+   if y<25 then\r
+      for i:=y*6+21 to 170 do\r
+        fillchar(screen[i,8],246,0);\r
+   mouseshow;\r
+end;\r
+\r
+procedure getlog;\r
+begin\r
+   mousehide;\r
+   tcolor:=79;\r
+   bkcolor:=0;\r
+   loadlog(getlogindex(logs[logindex]));\r
+   printxy2(6,15,titles^[getlogindex(logs[logindex])].text);\r
+ for j:=0 to 24 do\r
+    printxy2(6,22+j*6,l^[j]);\r
+ mouseshow;\r
+end;\r
+\r
+procedure subcursor;\r
+begin\r
+ if logindex>0 then\r
+  begin\r
+   dec(logindex);\r
+   if not qmode then displaylist else getlog;\r
+  end;\r
+end;\r
+\r
+procedure addcursor;\r
+begin\r
+ if (logs[logindex+1]>0) and (logindex<maxlogentries-1) then\r
+  begin\r
+   inc(logindex);\r
+   if not qmode then displaylist else getlog;\r
+  end;\r
+end;\r
+\r
+procedure findmouse;\r
+begin\r
+ if not mouse.getstatus then exit;\r
+ case mouse.x of\r
+   11..211: if (not qmode) and (mouse.y>13) and (mouse.y<170) then\r
+             begin\r
+              i:=((mouse.y-14) div 6)-13;\r
+              while i>0 do\r
+               begin\r
+                if (logs[logindex+1]>-1) and (logindex < maxlogentries - 1) then inc(logindex);\r
+                dec(i);\r
+               end;\r
+              while i<0 do\r
+               begin\r
+                if (logindex>-1) and (logindex>0) then dec(logindex);\r
+                inc(i);\r
+               end;\r
+              mousehide;\r
+              for i:=42 to 50 do\r
+               begin\r
+                screen[i,311]:=63;\r
+                screen[i,312]:=63;\r
+               end;\r
+              if not qmode then\r
+               for i:=14 to 173 do\r
+                fillchar(screen[i,8],246,0);\r
+               mouseshow;\r
+              qmode:=true;\r
+              if not qmode then displaylist else getlog;\r
+             end;\r
+  309..316: if (mouse.y<33) and (mouse.y>13) then done:=true;\r
+  262..270: case mouse.y of\r
+             91..101: subcursor;\r
+             105..115: addcursor;\r
+            end;\r
+  306..308: case mouse.y of\r
+             14..32: done:=true;\r
+             39..54: begin\r
+                      if qmode then\r
+                       begin\r
+                        qmode:=false;\r
+                        mousehide;\r
+                        for i:=42 to 50 do\r
+                         begin\r
+                          screen[i,311]:=79;\r
+                          screen[i,312]:=79;\r
+                         end;\r
+                        for i:=14 to 173 do\r
+                         fillchar(screen[i,8],246,0);\r
+                        mouseshow;\r
+                        displaylist;\r
+                       end\r
+                      else\r
+                       begin\r
+                        qmode:=true;\r
+                        mousehide;\r
+                        for i:=42 to 50 do\r
+                         begin\r
+                          screen[i,311]:=63;\r
+                          screen[i,312]:=63;\r
+                         end;\r
+                        for i:=14 to 174 do\r
+                         fillchar(screen[i,8],246,0);\r
+                        mouseshow;\r
+                        getlog;\r
+                       end;\r
+                     end;\r
+           end;\r
+  299..305: if (mouse.y<55) and (mouse.y>38) then\r
+             begin\r
+              if qmode then\r
+               begin\r
+                qmode:=false;\r
+                mousehide;\r
+                for i:=42 to 50 do\r
+                 begin\r
+                  screen[i,311]:=79;\r
+                  screen[i,312]:=79;\r
+                 end;\r
+                for i:=14 to 173 do\r
+                 fillchar(screen[i,8],246,0);\r
+                mouseshow;\r
+                displaylist;\r
+               end\r
+              else\r
+               begin\r
+                qmode:=true;\r
+                mousehide;\r
+                for i:=42 to 50 do\r
+                 begin\r
+                  screen[i,311]:=63;\r
+                  screen[i,312]:=63;\r
+                 end;\r
+                for i:=14 to 173 do\r
+                 fillchar(screen[i,8],246,0);\r
+                mouseshow;\r
+                getlog;\r
+               end;\r
+             end;\r
+ end;\r
+ idletime:=0;\r
+end;\r
+\r
+procedure processkey;\r
+var ans: char;\r
+begin\r
+ ans:=readkey;\r
+ case ans of\r
+  #0: begin\r
+       ans:=readkey;\r
+       case ans of\r
+        #72: subcursor;\r
+        #80: addcursor;\r
+       end;\r
+      end;\r
+  '?','/': begin\r
+        if qmode then\r
+         begin\r
+          qmode:=false;\r
+          mousehide;\r
+          for i:=42 to 50 do\r
+           begin\r
+            screen[i,311]:=79;\r
+            screen[i,312]:=79;\r
+           end;\r
+          for i:=14 to 173 do\r
+           fillchar(screen[i,8],246,0);\r
+          mouseshow;\r
+          displaylist;\r
+         end\r
+        else\r
+         begin\r
+          qmode:=true;\r
+          mousehide;\r
+          for i:=42 to 50 do\r
+           begin\r
+            screen[i,311]:=63;\r
+            screen[i,312]:=63;\r
+           end;\r
+          for i:=14 to 173 do\r
+           fillchar(screen[i,8],246,0);\r
+          mouseshow;\r
+          getlog;\r
+         end;\r
+       end;\r
+  #27: done:=true;\r
+  '`': bossmode;\r
+  #10: printbigbox(GetHeapStats1,GetHeapStats2);\r
+ end;\r
+ idletime:=0;\r
+end;\r
+\r
+procedure mainloop;\r
+begin\r
+   repeat\r
+      fadestep(8);\r
+  findmouse;\r
+  if fastkeypressed then processkey;\r
+  inc(idletime);\r
+  if idletime=maxidle then screensaver;\r
+  inc(index);\r
+  if index=7 then index:=0;\r
+  mousehide;\r
+  mousesetcursor(tmpm^[index]);\r
+  mouseshow;\r
+  delay(tslice*6);\r
+ until done;\r
+end;\r
+\r
+procedure readydata(intialdraw: boolean);\r
+var\r
+   f  : file of paltype;\r
+   f2 : file of titlebody;\r
+   i  : Integer;\r
+begin\r
+ assign(f,tempdir+'\current2.pal');\r
+ rewrite(f);\r
+ if ioresult<>0 then errorhandler(tempdir+'\current2.pal',1);\r
+ write(f,colors);\r
+ if ioresult<>0 then errorhandler(tempdir+'\current2.pal',5);\r
+ close(f);\r
+ mousehide;\r
+ compressfile(tempdir+'\current2',@screen);\r
+ {fading;}\r
+ fadestopmod(-8, 20);\r
+ playmod(true,'sound\creweval.mod');\r
+ loadscreen('data\log',@screen);\r
+ index:=0;\r
+ qmode:=false;\r
+ new(tmpm);\r
+ new(l);\r
+ new(titles);\r
+ assign(f2,'data\titles.dta');\r
+ reset(f2);\r
+ if ioresult<>0 then errorhandler('data\titles.dta',1);\r
+   i := 0;\r
+   while (ioresult = 0) and (not eof(f2)) and (i < maxlogentries) do\r
+   begin\r
+      read(f2,titles^[i]);\r
+      inc(i);\r
+   end;\r
+ if (ioresult<>0) or (i=0) then errorhandler('data\titles.dta',5);\r
+ close(f2);\r
+ for j:=0 to 6 do\r
+  for i:=0 to 15 do\r
+   mymove(screen[i+120,j*17+9],tmpm^[j,i],4);\r
+ mousesetcursor(tmpm^[0]);\r
+ for i:=15 to 170 do\r
+  fillchar(screen[i,8],246,0);\r
+ displaylist;\r
+ mouseshow;\r
+ {fadein;}\r
+ if intialdraw then\r
+  begin\r
+   qmode:=true;\r
+   for i:=42 to 50 do\r
+    begin\r
+     screen[i,311]:=63;\r
+     screen[i,312]:=63;\r
+    end;\r
+   for i:=15 to 170 do\r
+    fillchar(screen[i,8],246,0);\r
+   getlog;\r
+  end;\r
+ done:=false;\r
+end;\r
+\r
+procedure removedata(n: integer);\r
+begin\r
+ dispose(tmpm);\r
+ dispose(l);\r
+ dispose(titles);\r
+ mousehide;\r
+ {fading;}\r
+ fadestopmod(-8, 20);\r
+ mouse.setmousecursor(random(3));\r
+ loadscreen(tempdir+'\current2',@screen);\r
+ bkcolor:=3;\r
+ if n=0 then\r
+  begin\r
+   displaytextbox(false);\r
+   textindex:=25;\r
+  end;\r
+ {fadein;}\r
+ mouseshow;\r
+ anychange:=true;\r
+end;\r
+\r
+procedure computerlogs(n: integer);\r
+var initialdraw: boolean;\r
+begin\r
+   initialdraw:=false;\r
+   if n>0 then\r
+   begin\r
+      i:=0;\r
+      while (logs[i]<>n) and (i < maxlogentries) do inc(i);\r
+      if i >= maxlogentries then\r
+      begin\r
+        logindex := 0;\r
+      end else begin\r
+        logindex:=i;\r
+        initialdraw:=true;\r
+      end;\r
+   end\r
+   else logindex:=0;\r
+   readydata(initialdraw);\r
+   mainloop;\r
+   {stopmod;}\r
+   removedata(n);\r
+end;\r
+\r
+{**************************************************************************}\r
+\r
+procedure displayleftlist;\r
+begin\r
+ mousehide;\r
+ if trademode=0 then\r
+  begin\r
+   if tradeindex=0 then\r
+    begin\r
+     for i:=141 to 183 do\r
+      fillchar(screen[i,4],121,0);\r
+     mouseshow;\r
+     exit;\r
+    end;\r
+   x:=tradeindex;\r
+   y:=2;\r
+   repeat\r
+    if alienstuff^[x]>0 then\r
+     begin\r
+      if x=tradeindex then bkcolor:=6 else bkcolor:=0;\r
+      inc(y);\r
+      i:=1;\r
+      while cargo[i].index<>alienstuff^[x] do inc(i);\r
+      printxy(0,140+y*6,'    '+cargo[i].name);\r
+     end;\r
+    inc(x);\r
+   until (y=6) or (x>20);\r
+   if y<6 then\r
+    for i:=147+y*6 to 183 do\r
+     fillchar(screen[i,4],121,0);\r
+   x:=tradeindex-1;\r
+   y:=3;\r
+   bkcolor:=0;\r
+   repeat\r
+    if (alienstuff^[x]>0) and (x>0) then\r
+     begin\r
+      dec(y);\r
+      i:=1;\r
+      while cargo[i].index<>alienstuff^[x] do inc(i);\r
+      printxy(0,140+y*6,'    '+cargo[i].name);\r
+     end;\r
+    dec(x);\r
+   until (y=0) or (x<0);\r
+   if y>0 then\r
+    for i:=141 to 140+y*6 do\r
+     fillchar(screen[i,4],121,0);\r
+  end\r
+ else\r
+  begin\r
+   if cargoindex=0 then\r
+    begin\r
+     for i:=141 to 183 do\r
+      fillchar(screen[i,4],121,0);\r
+     mouseshow;\r
+     exit;\r
+    end;\r
+   x:=cargoindex;\r
+   y:=2;\r
+   repeat\r
+    if (ship.cargo[x]>0) and (ship.cargo[x]<6000) then\r
+     begin\r
+      if x=cargoindex then bkcolor:=6 else bkcolor:=0;\r
+      inc(y);\r
+      i:=1;\r
+      while cargo[i].index<>ship.cargo[x] do inc(i);\r
+      str(ship.numcargo[x]:3,str1);\r
+      printxy(0,140+y*6,str1+' '+cargo[i].name);\r
+     end;\r
+    inc(x);\r
+   until (y=6) or (x>250);\r
+   if y<6 then\r
+    for i:=147+y*6 to 183 do\r
+     fillchar(screen[i,4],121,0);\r
+   x:=cargoindex-1;\r
+   y:=3;\r
+   bkcolor:=0;\r
+   repeat\r
+    if (ship.cargo[x]>0) and (ship.cargo[x]<6000) and (x>0) then\r
+     begin\r
+      dec(y);\r
+      if ship.cargo[x]>5999 then\r
+       begin\r
+        getartifactname(ship.cargo[x]);\r
+        i:=maxcargo;\r
+       end\r
+      else\r
+       begin\r
+        i:=1;\r
+        while cargo[i].index<>ship.cargo[x] do inc(i);\r
+       end;\r
+      str(ship.numcargo[x]:3,str1);\r
+      printxy(0,140+y*6,str1+' '+cargo[i].name);\r
+     end;\r
+    dec(x);\r
+   until (y=0) or (x<0);\r
+   if y>0 then\r
+    for i:=141 to 140+y*6 do\r
+     fillchar(screen[i,4],121,0);\r
+  end;\r
+ mouseshow;\r
+end;\r
+\r
+procedure displayrightlist;\r
+begin\r
+ mousehide;\r
+ if stuffindex=0 then\r
+  begin\r
+   for i:=141 to 183 do\r
+    fillchar(screen[i,194],101,0);\r
+   mouseshow;\r
+   exit;\r
+  end;\r
+ x:=stuffindex;\r
+ y:=2;\r
+ repeat\r
+  if tradestuff^[x]>0 then\r
+   begin\r
+    if x=stuffindex then bkcolor:=6 else bkcolor:=0;\r
+    inc(y);\r
+    i:=1;\r
+    while cargo[i].index<>tradestuff^[x] do inc(i);\r
+    printxy(190,140+y*6,cargo[i].name);\r
+   end;\r
+  inc(x);\r
+ until (y=6) or (x>20);\r
+ if y<6 then\r
+  for i:=147+y*6 to 183 do\r
+   fillchar(screen[i,194],101,0);\r
+ x:=stuffindex-1;\r
+ y:=3;\r
+ bkcolor:=0;\r
+ repeat\r
+  if (tradestuff^[x]>0) and (x>0) then\r
+   begin\r
+    dec(y);\r
+    i:=1;\r
+    while cargo[i].index<>tradestuff^[x] do inc(i);\r
+    printxy(190,140+y*6,cargo[i].name);\r
+   end;\r
+  dec(x);\r
+ until (y=0) or (x<0);\r
+ if y>0 then\r
+  for i:=141 to 140+y*6 do\r
+   fillchar(screen[i,194],101,0);\r
+ mouseshow;\r
+end;\r
+\r
+procedure subcursor2;\r
+begin\r
+ if trademode=0 then\r
+  begin\r
+   dec(tradeindex);\r
+   while (tradeindex>0) and (alienstuff^[tradeindex]=0) do dec(tradeindex);\r
+   if tradeindex<1 then\r
+    begin\r
+     tradeindex:=1;\r
+     while (tradeindex<21) and (alienstuff^[tradeindex]=0) do inc(tradeindex);\r
+     if tradeindex=21 then tradeindex:=0;\r
+    end;\r
+  end\r
+ else\r
+  begin\r
+   dec(cargoindex);\r
+   while (cargoindex>0) and ((ship.cargo[cargoindex]=0) or (ship.cargo[cargoindex]>5999)) do dec(cargoindex);\r
+   if cargoindex<1 then\r
+    begin\r
+     cargoindex:=1;\r
+     while (cargoindex<251) and ((ship.cargo[cargoindex]=0) or (ship.cargo[cargoindex]>5999)) do inc(cargoindex);\r
+     if cargoindex>250 then cargoindex:=0;\r
+    end;\r
+  end;\r
+ displayleftlist;\r
+end;\r
+\r
+procedure subcursor3;\r
+begin\r
+ if trademode=0 then exit;\r
+ dec(stuffindex);\r
+ while (stuffindex>0) and (tradestuff^[stuffindex]=0) do dec(stuffindex);\r
+ if stuffindex<1 then\r
+  begin\r
+   stuffindex:=1;\r
+   while (stuffindex<21) and (tradestuff^[stuffindex]=0) do inc(stuffindex);\r
+   if stuffindex=21 then stuffindex:=0;\r
+  end;\r
+ displayrightlist;\r
+end;\r
+\r
+procedure addcursor2;\r
+begin\r
+ if trademode=0 then\r
+  begin\r
+   inc(tradeindex);\r
+   while (tradeindex<21) and (alienstuff^[tradeindex]=0) do inc(tradeindex);\r
+   if tradeindex>20 then\r
+    begin\r
+     tradeindex:=20;\r
+     while (tradeindex>0) and (alienstuff^[tradeindex]=0) do dec(tradeindex);\r
+    end;\r
+  end\r
+ else\r
+  begin\r
+   inc(cargoindex);\r
+   while (cargoindex<251) and ((ship.cargo[cargoindex]=0) or (ship.cargo[cargoindex]>5999)) do inc(cargoindex);\r
+   if cargoindex>250 then\r
+    begin\r
+     cargoindex:=250;\r
+     while (cargoindex>0) and ((ship.cargo[cargoindex]=0) or (ship.cargo[cargoindex]>5999)) do dec(cargoindex);\r
+    end;\r
+  end;\r
+ displayleftlist;\r
+end;\r
+\r
+procedure addcursor3;\r
+begin\r
+ if trademode=0 then exit;\r
+ inc(stuffindex);\r
+ while (stuffindex<21) and (tradestuff^[stuffindex]=0) do inc(stuffindex);\r
+ if stuffindex>20 then\r
+  begin\r
+   stuffindex:=20;\r
+   while (stuffindex>0) and (tradestuff^[stuffindex]=0) do dec(stuffindex);\r
+  end;\r
+ displayrightlist;\r
+end;\r
+\r
+function getworth(item: integer): integer;\r
+var i,j,worth: integer;\r
+begin\r
+ i:=0;\r
+ worth:=0;\r
+ case item of\r
+        3000: worth:=27;\r
+        4000: worth:=9;\r
+        4020: worth:=1;\r
+  5000..5999: worth:=3;\r
+  1000..1499: begin i:=1; worth:=4; end;\r
+  1500..1599: begin i:=1; worth:=6; end;\r
+  2000..2999: begin i:=1; worth:=4; end;\r
+  3001..3999: begin i:=1; worth:=3; end;\r
+  4000..4999: begin i:=1; worth:=2; end;\r
+ end;\r
+ if i=1 then\r
+  begin\r
+   while cr^[i].index<>item do inc(i);\r
+   for j:=1 to 3 do\r
+    if cr^[i].parts[j]>4999 then inc(worth)\r
+    else worth:=worth+getworth(cr^[i].parts[j]);\r
+  end;\r
+ getworth:=worth;\r
+end;\r
+\r
+procedure barterfor;\r
+var r: real;\r
+begin\r
+ if (trademode=1) or (tradeindex=0) then exit;\r
+ trademode:=1;\r
+ if cargoindex=0 then addcursor2;\r
+ i:=1;\r
+ while cargo[i].index<>alienstuff^[tradeindex] do inc(i);\r
+ mousehide;\r
+ printxy(93,127,cargo[i].name);\r
+ displayleftlist;\r
+ mouseshow;\r
+ fillchar(tradestuff^,sizeof(alienstuffarray),0);\r
+ alienworth:=getworth(alienstuff^[tradeindex]);\r
+ if alien.anger=0 then\r
+  begin\r
+   if alien.congeniality>20 then i:=3\r
+    else i:=1;\r
+  end\r
+ else\r
+  begin\r
+   r:=alien.congeniality/alien.anger;\r
+   if r<0.3 then i:=5\r
+   else if r<0.7 then i:=4\r
+   else if round(r)=1 then i:=2\r
+   else i:=3;\r
+  end;\r
+ alienworth:=round(alienworth*0.33*i);\r
+ tradeworth:=0;\r
+end;\r
+\r
+procedure rejectoffer;\r
+var j: integer;\r
+begin\r
+ if trademode=0 then exit;\r
+ trademode:=0;\r
+ mousehide;\r
+ for i:=128 to 133 do\r
+  fillchar(screen[i,97],101,0);\r
+ for i:=141 to 183 do\r
+  fillchar(screen[i,194],101,0);\r
+ for j:=1 to 20 do\r
+  if tradestuff^[j]>0 then addcargo2(tradestuff^[j], true);\r
+ for i:=158 to 164 do\r
+  fillchar(screen[i,131],57,0);\r
+ displayleftlist;\r
+ mouseshow;\r
+end;\r
+\r
+procedure acceptoffer;\r
+begin\r
+ if (trademode=0) or (tradeworth<alienworth) or (tradeindex=0) then exit;\r
+ case alienstuff^[tradeindex] of\r
+  2015: begin\r
+         addcargo(3012, true);\r
+         addcargo(3007, true);\r
+         addcargo(3018, true);\r
+        end;\r
+  2016: begin\r
+         addcargo(1000, true);\r
+         addcargo(1000, true);\r
+         addcargo(3008, true);\r
+        end;\r
+  2017: begin\r
+         addcargo(3018, true);\r
+         addcargo(3019, true);\r
+         addcargo(3012, true);\r
+        end;\r
+  2018: begin\r
+         addcargo(1506, true);\r
+         addcargo(1506, true);\r
+         addcargo(1034, true);\r
+        end;\r
+  2019: begin\r
+         addcargo(3015, true);\r
+         addcargo(3003, true);\r
+         addcargo(3009, true);\r
+        end;\r
+  else addcargo(alienstuff^[tradeindex], true);\r
+ end;\r
+ alienstuff^[tradeindex]:=0;\r
+ trademode:=0;\r
+ subcursor2;\r
+ mousehide;\r
+ for i:=128 to 133 do\r
+  fillchar(screen[i,97],101,0);\r
+ for i:=141 to 183 do\r
+  fillchar(screen[i,194],101,0);\r
+ for i:=158 to 164 do\r
+  fillchar(screen[i,131],57,0);\r
+ displayleftlist;\r
+ mouseshow;\r
+end;\r
+\r
+procedure showworth;\r
+var c,num: integer;\r
+begin\r
+ num:=57;\r
+ if tradeworth<alienworth then\r
+  begin\r
+   c:=37;\r
+   num:=round(tradeworth/alienworth*57);\r
+  end\r
+ else if tradeworth>=2*alienworth then c:=47\r
+ else c:=33;\r
+ mousehide;\r
+ for i:=158 to 164 do\r
+  begin\r
+   fillchar(screen[i,131],num,c);\r
+   if num<57 then fillchar(screen[i,131+num],57-num,0);\r
+  end;\r
+ mouseshow;\r
+end;\r
+\r
+procedure addstuff;\r
+var i: integer;\r
+begin\r
+ if (trademode=0) or (cargoindex=0) then exit;\r
+ i:=1;\r
+ while (i<21) and (tradestuff^[i]>0) do inc(i);\r
+ if i=21 then exit;\r
+ tradestuff^[i]:=ship.cargo[cargoindex];\r
+ tradeworth:=tradeworth+getworth(ship.cargo[cargoindex]);\r
+ dec(ship.numcargo[cargoindex]);\r
+ if ship.numcargo[cargoindex]=0 then\r
+  begin\r
+   ship.cargo[cargoindex]:=0;\r
+   subcursor2;\r
+  end;\r
+ stuffindex:=i;\r
+ displayrightlist;\r
+ showworth;\r
+end;\r
+\r
+procedure removestuff;\r
+begin\r
+ if (trademode=0) or (stuffindex=0) then exit;\r
+ addcargo(tradestuff^[stuffindex], true);\r
+ tradeworth:=tradeworth-getworth(tradestuff^[stuffindex]);\r
+ tradestuff^[stuffindex]:=0;\r
+ subcursor3;\r
+ if cargoindex=0 then addcursor2;\r
+ displayleftlist;\r
+ showworth;\r
+end;\r
+\r
+procedure findleftmouse;\r
+var y,j: integer;\r
+begin\r
+ y:=-3+((mouse.y-141) div 6);\r
+ repeat\r
+  if y<0 then\r
+   begin\r
+    subcursor2;\r
+    inc(y);\r
+   end\r
+  else if y>0 then\r
+   begin\r
+    addcursor2;\r
+    dec(y);\r
+   end;\r
+ until y=0;\r
+end;\r
+\r
+procedure findrightmouse;\r
+var y,j: integer;\r
+begin\r
+ y:=-3+((mouse.y-141) div 6);\r
+ repeat\r
+  if y<0 then\r
+   begin\r
+    subcursor3;\r
+    inc(y);\r
+   end\r
+  else if y>0 then\r
+   begin\r
+    addcursor3;\r
+    dec(y);\r
+   end;\r
+ until y=0;\r
+end;\r
+\r
+procedure findmouse2;\r
+begin\r
+ if not mouse.getstatus then exit;\r
+ case mouse.x of\r
+    21..90: case mouse.y of\r
+             126..134: if trademode=0 then barterfor;\r
+             138..186: findleftmouse;\r
+            end;\r
+    4..124: if (mouse.y>137) and (mouse.y<187) then findleftmouse;\r
+  130..139: case mouse.y of\r
+             172..179: subcursor2;\r
+             180..186: addcursor2;\r
+            end;\r
+  149..171: case mouse.y of\r
+             149..155: addstuff;\r
+             167..173: removestuff;\r
+            end;\r
+  179..188: case mouse.y of\r
+             172..179: subcursor3;\r
+             180..186: addcursor3;\r
+            end;\r
+  229..246: case mouse.y of\r
+             126..134: acceptoffer;\r
+             138..186: findrightmouse;\r
+            end;\r
+  247..261: case mouse.y of\r
+             104..111: getinfo;\r
+             126..134: acceptoffer;\r
+             138..186: findrightmouse;\r
+            end;\r
+  262..265: case mouse.y of\r
+             105..110: getinfo;\r