home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume15 / xstratgo / part01 < prev    next >
Encoding:
Internet Message Format  |  1993-01-26  |  53.8 KB

  1. Path: uunet!ogicse!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v15i011:  xstratego - X Windows stratego interface for two players, Part01/04
  5. Message-ID: <3816@master.CNA.TEK.COM>
  6. Date: 26 Oct 92 23:51:50 GMT
  7. Article-I.D.: master.3816
  8. Sender: news@master.CNA.TEK.COM
  9. Lines: 2029
  10. Approved: billr@saab.CNA.TEK.COM
  11. Xref: uunet comp.sources.games:1510
  12.  
  13. Submitted-by: Henk-Jan Visscher <hjvissc@cs.vu.nl>
  14. Posting-number: Volume 15, Issue 11
  15. Archive-name: xstratego/Part01
  16. Environment: X11, Xaw
  17.  
  18.  
  19. #! /bin/sh
  20. # This is a shell archive.  Remove anything before this line, then unpack
  21. # it by saving it into a file and typing "sh file".  To overwrite existing
  22. # files, type "sh file -c".  You can also feed this as standard input via
  23. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  24. # will see the following message at the end:
  25. #        "End of archive 1 (of 4)."
  26. # Contents:  README MANIFEST Makefile.std dialog.c icons main.c play.c
  27. #   setup.c xstratego.6
  28. # Wrapped by billr@saab on Mon Oct 26 15:47:07 1992
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'README' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'README'\"
  32. else
  33. echo shar: Extracting \"'README'\" \(276 characters\)
  34. sed "s/^X//" >'README' <<'END_OF_FILE'
  35. X
  36. XXstratego is a X windows based stratego interface for two players.
  37. XYou can either play against another player (on the same or different host)
  38. Xor create a board setup for later use.
  39. X
  40. XThe man page includes a summary of the Stratego rules, in case you haven't
  41. Xplayed in awhile.
  42. END_OF_FILE
  43. if test 276 -ne `wc -c <'README'`; then
  44.     echo shar: \"'README'\" unpacked with wrong size!
  45. fi
  46. # end of 'README'
  47. fi
  48. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  49.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  50. else
  51. echo shar: Extracting \"'MANIFEST'\" \(2255 characters\)
  52. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  53. X   File Name        Archive #    Description
  54. X-----------------------------------------------------------
  55. X Imakefile                  2    
  56. X MANIFEST                   1    This shipping list
  57. X Makefile                   4    
  58. X Makefile.std               1    
  59. X README                     1    
  60. X buzz.c                     2    
  61. X buzz.h                     4    
  62. X callback.c                 2    
  63. X dialog.c                   1    
  64. X icons                      1    
  65. X icons/account_cursor.h     4    
  66. X icons/account_cursor_mask.h  4    
  67. X icons/board_cursor.h       4    
  68. X icons/board_cursor_mask.h  4    
  69. X icons/boat_cursor.h        4    
  70. X icons/boat_cursor_mask.h   4    
  71. X icons/bomb.h               3    
  72. X icons/bomb_mask.h          3    
  73. X icons/bomb_s.h             3    
  74. X icons/c.c                  4    
  75. X icons/captain.h            3    
  76. X icons/captain_mask.h       2    
  77. X icons/captain_s.h          3    
  78. X icons/colonel.h            3    
  79. X icons/colonel_mask.h       2    
  80. X icons/colonel_s.h          3    
  81. X icons/enemy.h              3    
  82. X icons/enemy_mask.h         2    
  83. X icons/enemy_s.h            3    
  84. X icons/flag.h               3    
  85. X icons/flag_mask.h          3    
  86. X icons/flag_s.h             3    
  87. X icons/free.h               3    
  88. X icons/free_mask.h          3    
  89. X icons/free_s.h             3    
  90. X icons/general.h            3    
  91. X icons/general_mask.h       2    
  92. X icons/general_s.h          3    
  93. X icons/lieutenant.h         2    
  94. X icons/lieutenant_mask.h    2    
  95. X icons/lieutenant_s.h       3    
  96. X icons/major.h              3    
  97. X icons/major_mask.h         2    
  98. X icons/major_s.h            3    
  99. X icons/marshal.h            3    
  100. X icons/marshal_mask.h       2    
  101. X icons/marshal_s.h          3    
  102. X icons/miner.h              3    
  103. X icons/miner_mask.h         2    
  104. X icons/miner_s.h            3    
  105. X icons/scout.h              3    
  106. X icons/scout_mask.h         2    
  107. X icons/scout_s.h            3    
  108. X icons/sergeant.h           3    
  109. X icons/sergeant_mask.h      2    
  110. X icons/sergeant_s.h         3    
  111. X icons/spy.h                3    
  112. X icons/spy_mask.h           3    
  113. X icons/spy_s.h              4    
  114. X init.c                     2    
  115. X main.c                     1    
  116. X message.c                  2    
  117. X play.c                     1    
  118. X register.c                 2    
  119. X setup.c                    1    
  120. X socket.c                   2    
  121. X stratego.h                 2    
  122. X tiles.h                    3    
  123. X xstratego.6                1    
  124. END_OF_FILE
  125. if test 2255 -ne `wc -c <'MANIFEST'`; then
  126.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  127. fi
  128. # end of 'MANIFEST'
  129. fi
  130. if test -f 'Makefile.std' -a "${1}" != "-c" ; then 
  131.   echo shar: Will not clobber existing file \"'Makefile.std'\"
  132. else
  133. echo shar: Extracting \"'Makefile.std'\" \(10382 characters\)
  134. sed "s/^X//" >'Makefile.std' <<'END_OF_FILE'
  135. X# Makefile generated by imake - do not edit!
  136. X# $XConsortium: imake.c,v 1.65 91/07/25 17:50:17 rws Exp $
  137. X#
  138. X# The cpp used on this machine replaces all newlines and multiple tabs and
  139. X# spaces in a macro expansion with a single space.  Imake tries to compensate
  140. X# for this, but is not always successful.
  141. X#
  142. X
  143. X# -------------------------------------------------------------------------
  144. X# Makefile generated from "Imake.tmpl" and <Imakefile>
  145. X# $XConsortium: Imake.tmpl,v 1.139 91/09/16 08:52:48 rws Exp $
  146. X#
  147. X# Platform-specific parameters may be set in the appropriate <vendor>.cf
  148. X# configuration files.  Site-specific parameters should be set in the file
  149. X# site.def.  Full rebuilds are recommended if any parameters are changed.
  150. X#
  151. X# If your C preprocessor does not define any unique symbols, you will need
  152. X# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
  153. X# "make World" the first time).
  154. X#
  155. X
  156. X# -------------------------------------------------------------------------
  157. X# site-specific configuration parameters that need to come before
  158. X# the platform-specific parameters - edit site.def to change
  159. X
  160. X# site:  $XConsortium: site.def,v 1.2 91/07/30 20:26:44 rws Exp $
  161. X
  162. X# -------------------------------------------------------------------------
  163. X# platform-specific configuration parameters - edit sun.cf to change
  164. X
  165. X# platform:  $XConsortium: sun.cf,v 1.69 91/09/09 18:23:59 rws Exp $
  166. X
  167. X# operating system:  SunOS 4.1.1
  168. X
  169. X# $XConsortium: sunLib.rules,v 1.6 91/03/24 17:55:58 rws Exp $
  170. X
  171. X# -------------------------------------------------------------------------
  172. X# site-specific configuration parameters that go after
  173. X# the platform-specific parameters - edit site.def to change
  174. X
  175. X# site:  $XConsortium: site.def,v 1.2 91/07/30 20:26:44 rws Exp $
  176. X
  177. X            SHELL = /bin/sh
  178. X
  179. X              TOP = .
  180. X      CURRENT_DIR = .
  181. X
  182. X               AR = ar clq
  183. X  BOOTSTRAPCFLAGS =
  184. X               CC = cc
  185. X               AS = as
  186. X
  187. X         COMPRESS = compress
  188. X              CPP = /lib/cpp $(STD_CPP_DEFINES)
  189. X    PREPROCESSCMD = cc -E $(STD_CPP_DEFINES)
  190. X          INSTALL = install
  191. X               LD = ld
  192. X             LINT = lint
  193. X      LINTLIBFLAG = -C
  194. X         LINTOPTS = -axz
  195. X               LN = ln -s
  196. X             MAKE = make
  197. X               MV = mv
  198. X               CP = cp
  199. X
  200. X           RANLIB = ranlib
  201. X  RANLIBINSTFLAGS =
  202. X
  203. X               RM = rm -f
  204. X            TROFF = psroff
  205. X         MSMACROS = -ms
  206. X              TBL = tbl
  207. X              EQN = eqn
  208. X     STD_INCLUDES =
  209. X  STD_CPP_DEFINES =
  210. X      STD_DEFINES =
  211. X EXTRA_LOAD_FLAGS =
  212. X  EXTRA_LIBRARIES =
  213. X             TAGS = ctags
  214. X
  215. X    SHAREDCODEDEF = -DSHAREDCODE
  216. X         SHLIBDEF = -DSUNSHLIB
  217. X
  218. X    PROTO_DEFINES =
  219. X
  220. X     INSTPGMFLAGS =
  221. X
  222. X     INSTBINFLAGS = -m 0755
  223. X     INSTUIDFLAGS = -m 4755
  224. X     INSTLIBFLAGS = -m 0644
  225. X     INSTINCFLAGS = -m 0444
  226. X     INSTMANFLAGS = -m 0444
  227. X     INSTDATFLAGS = -m 0444
  228. X    INSTKMEMFLAGS = -m 4755
  229. X
  230. X      CDEBUGFLAGS = -O
  231. X        CCOPTIONS = -pipe
  232. X
  233. X      ALLINCLUDES = $(INCLUDES) $(EXTRA_INCLUDES) $(TOP_INCLUDES) $(STD_INCLUDES)
  234. X       ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(EXTRA_DEFINES) $(PROTO_DEFINES) $(DEFINES)
  235. X           CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
  236. X        LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
  237. X
  238. X           LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  239. X
  240. X        LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS) $(LOCAL_LDFLAGS)
  241. X
  242. X   LDCOMBINEFLAGS = -X -r
  243. X      DEPENDFLAGS =
  244. X
  245. X        MACROFILE = sun.cf
  246. X           RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
  247. X
  248. X    IMAKE_DEFINES =
  249. X
  250. X         IRULESRC = $(CONFIGDIR)
  251. X        IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES)
  252. X
  253. X     ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
  254. X            $(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
  255. X            $(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
  256. X
  257. X# -------------------------------------------------------------------------
  258. X# X Window System Build Parameters
  259. X# $XConsortium: Project.tmpl,v 1.137 91/07/30 22:57:01 rws Exp $
  260. X
  261. X# -------------------------------------------------------------------------
  262. X# X Window System make variables; this need to be coordinated with rules
  263. X
  264. X          PATHSEP = /
  265. X        USRLIBDIR = /usr/lib
  266. X           BINDIR = /usr/bin/X11
  267. X          INCROOT = /usr/include
  268. X     BUILDINCROOT = $(TOP)
  269. X      BUILDINCDIR = $(BUILDINCROOT)/X11
  270. X      BUILDINCTOP = ..
  271. X           INCDIR = $(INCROOT)/X11
  272. X           ADMDIR = /usr/adm
  273. X           LIBDIR = $(USRLIBDIR)/X11
  274. X        CONFIGDIR = $(LIBDIR)/config
  275. X       LINTLIBDIR = $(USRLIBDIR)/lint
  276. X
  277. X          FONTDIR = $(LIBDIR)/fonts
  278. X         XINITDIR = $(LIBDIR)/xinit
  279. X           XDMDIR = $(LIBDIR)/xdm
  280. X           TWMDIR = $(LIBDIR)/twm
  281. X            MANPATH = /usr/man:/usr/local/man
  282. X       MANSOURCEPATH = $(MANPATH)/man
  283. X           MANSUFFIX = 1
  284. X        LIBMANSUFFIX = 3
  285. X              MANDIR = $(MANSOURCEPATH)$(MANSUFFIX)
  286. X           LIBMANDIR = $(MANSOURCEPATH)$(LIBMANSUFFIX)
  287. X              NLSDIR = $(LIBDIR)/nls
  288. X           PEXAPIDIR = $(LIBDIR)/PEX
  289. X         XAPPLOADDIR = $(LIBDIR)/app-defaults
  290. X          FONTCFLAGS = -t
  291. X
  292. X     INSTAPPFLAGS = $(INSTDATFLAGS)
  293. X
  294. X            IMAKE = imake
  295. X           DEPEND = makedepend
  296. X              RGB = rgb
  297. X
  298. X            FONTC = bdftopcf
  299. X
  300. X        MKFONTDIR = mkfontdir
  301. X        MKDIRHIER = /bin/sh $(BINDIR)/mkdirhier
  302. X
  303. X        CONFIGSRC = $(TOP)/config
  304. X       DOCUTILSRC = $(TOP)/doc/util
  305. X        CLIENTSRC = $(TOP)/clients
  306. X          DEMOSRC = $(TOP)/demos
  307. X           LIBSRC = $(TOP)/lib
  308. X          FONTSRC = $(TOP)/fonts
  309. X       INCLUDESRC = $(TOP)/X11
  310. X        SERVERSRC = $(TOP)/server
  311. X          UTILSRC = $(TOP)/util
  312. X        SCRIPTSRC = $(UTILSRC)/scripts
  313. X       EXAMPLESRC = $(TOP)/examples
  314. X       CONTRIBSRC = $(TOP)/../contrib
  315. X           DOCSRC = $(TOP)/doc
  316. X           RGBSRC = $(TOP)/rgb
  317. X        DEPENDSRC = $(UTILSRC)/makedepend
  318. X         IMAKESRC = $(CONFIGSRC)
  319. X         XAUTHSRC = $(LIBSRC)/Xau
  320. X          XLIBSRC = $(LIBSRC)/X
  321. X           XMUSRC = $(LIBSRC)/Xmu
  322. X       TOOLKITSRC = $(LIBSRC)/Xt
  323. X       AWIDGETSRC = $(LIBSRC)/Xaw
  324. X       OLDXLIBSRC = $(LIBSRC)/oldX
  325. X      XDMCPLIBSRC = $(LIBSRC)/Xdmcp
  326. X      BDFTOSNFSRC = $(FONTSRC)/bdftosnf
  327. X      BDFTOSNFSRC = $(FONTSRC)/clients/bdftosnf
  328. X      BDFTOPCFSRC = $(FONTSRC)/clients/bdftopcf
  329. X     MKFONTDIRSRC = $(FONTSRC)/clients/mkfontdir
  330. X         FSLIBSRC = $(FONTSRC)/lib/fs
  331. X    FONTSERVERSRC = $(FONTSRC)/server
  332. X     EXTENSIONSRC = $(TOP)/extensions
  333. X         XILIBSRC = $(EXTENSIONSRC)/lib/xinput
  334. X      PHIGSLIBSRC = $(EXTENSIONSRC)/lib/PEX
  335. X
  336. X# $XConsortium: sunLib.tmpl,v 1.11 91/07/31 11:32:08 rws Exp $
  337. X
  338. XSHLIBLDFLAGS = -assert pure-text
  339. XPICFLAGS = -pic
  340. X
  341. X  DEPEXTENSIONLIB =
  342. X     EXTENSIONLIB = -lXext
  343. X
  344. X          DEPXLIB = $(DEPEXTENSIONLIB)
  345. X             XLIB = $(EXTENSIONLIB) -lX11
  346. X
  347. X        DEPXMULIB = $(USRLIBDIR)/libXmu.sa.$(SOXMUREV)
  348. X           XMULIB = -lXmu
  349. X
  350. X       DEPOLDXLIB =
  351. X          OLDXLIB = -loldX
  352. X
  353. X      DEPXTOOLLIB = $(USRLIBDIR)/libXt.sa.$(SOXTREV)
  354. X         XTOOLLIB = -lXt
  355. X
  356. X        DEPXAWLIB = $(USRLIBDIR)/libXaw.sa.$(SOXAWREV)
  357. X           XAWLIB = -lXaw
  358. X
  359. X        DEPXILIB =
  360. X           XILIB = -lXi
  361. X
  362. X        SOXLIBREV = 4.10
  363. X          SOXTREV = 4.10
  364. X         SOXAWREV = 5.0
  365. X        SOOLDXREV = 4.10
  366. X         SOXMUREV = 4.10
  367. X        SOXEXTREV = 4.10
  368. X      SOXINPUTREV = 4.10
  369. X
  370. X      DEPXAUTHLIB = $(USRLIBDIR)/libXau.a
  371. X         XAUTHLIB =  -lXau
  372. X      DEPXDMCPLIB = $(USRLIBDIR)/libXdmcp.a
  373. X         XDMCPLIB =  -lXdmcp
  374. X
  375. X        DEPPHIGSLIB = $(USRLIBDIR)/libphigs.a
  376. X           PHIGSLIB =  -lphigs
  377. X
  378. X LINTEXTENSIONLIB = $(LINTLIBDIR)/llib-lXext.ln
  379. X         LINTXLIB = $(LINTLIBDIR)/llib-lX11.ln
  380. X          LINTXMU = $(LINTLIBDIR)/llib-lXmu.ln
  381. X        LINTXTOOL = $(LINTLIBDIR)/llib-lXt.ln
  382. X          LINTXAW = $(LINTLIBDIR)/llib-lXaw.ln
  383. X           LINTXI = $(LINTLIBDIR)/llib-lXi.ln
  384. X        LINTPHIGS = $(LINTLIBDIR)/llib-lphigs.ln
  385. X
  386. X          DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
  387. X
  388. X         DEPLIBS1 = $(DEPLIBS)
  389. X         DEPLIBS2 = $(DEPLIBS)
  390. X         DEPLIBS3 = $(DEPLIBS)
  391. X
  392. X# -------------------------------------------------------------------------
  393. X# Imake rules for building libraries, programs, scripts, and data files
  394. X# rules:  $XConsortium: Imake.rules,v 1.123 91/09/16 20:12:16 rws Exp $
  395. X
  396. X# -------------------------------------------------------------------------
  397. X# start of Imakefile
  398. X
  399. XLOCAL_LIBRARIES = $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
  400. X    DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
  401. X
  402. XSRCS = buzz.c callback.c dialog.c init.c main.c message.c play.c register.c setup.c socket.c
  403. XOBJS = buzz.o callback.o dialog.o init.o main.o message.o play.o register.o setup.o socket.o
  404. X
  405. X PROGRAM = stratego
  406. X
  407. Xall:: stratego
  408. X
  409. Xstratego: $(OBJS) $(DEPLIBS)
  410. X    $(RM) $@
  411. X    $(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
  412. X
  413. Xsaber_stratego:: $(SRCS)
  414. X    # load $(ALLDEFINES) $(SRCS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  415. X
  416. Xosaber_stratego:: $(OBJS)
  417. X    # load $(ALLDEFINES) $(OBJS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
  418. X
  419. Xinstall:: stratego
  420. X    @if [ -d $(DESTDIR)$(BINDIR) ]; then set +x; \
  421. X    else (set -x; $(MKDIRHIER) $(DESTDIR)$(BINDIR)); fi
  422. X    $(INSTALL) -c $(INSTPGMFLAGS)  stratego $(DESTDIR)$(BINDIR)
  423. X
  424. Xinstall.man:: stratego.man
  425. X    @if [ -d $(DESTDIR)$(MANDIR) ]; then set +x; \
  426. X    else (set -x; $(MKDIRHIER) $(DESTDIR)$(MANDIR)); fi
  427. X    $(INSTALL) -c $(INSTMANFLAGS) stratego.man $(DESTDIR)$(MANDIR)/stratego.$(MANSUFFIX)
  428. X
  429. Xdepend::
  430. X    $(DEPEND) $(DEPENDFLAGS) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
  431. X
  432. Xlint:
  433. X    $(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS)
  434. Xlint1:
  435. X    $(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
  436. X
  437. Xclean::
  438. X    $(RM) $(PROGRAM)
  439. X
  440. X# -------------------------------------------------------------------------
  441. X# common rules for all Makefiles - do not edit
  442. X
  443. Xemptyrule::
  444. X
  445. Xclean::
  446. X    $(RM_CMD) "#"*
  447. X
  448. XMakefile::
  449. X    -@if [ -f Makefile ]; then set -x; \
  450. X    $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
  451. X    else exit 0; fi
  452. X    $(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
  453. X
  454. Xtags::
  455. X    $(TAGS) -w *.[ch]
  456. X    $(TAGS) -xw *.[ch] > TAGS
  457. X
  458. Xsaber:
  459. X    # load $(ALLDEFINES) $(SRCS)
  460. X
  461. Xosaber:
  462. X    # load $(ALLDEFINES) $(OBJS)
  463. X
  464. X# -------------------------------------------------------------------------
  465. X# empty rules for directories that do not have SUBDIRS - do not edit
  466. X
  467. Xinstall::
  468. X    @echo "install in $(CURRENT_DIR) done"
  469. X
  470. Xinstall.man::
  471. X    @echo "install.man in $(CURRENT_DIR) done"
  472. X
  473. XMakefiles::
  474. X
  475. Xincludes::
  476. X
  477. X# -------------------------------------------------------------------------
  478. X# dependencies generated by makedepend
  479. X
  480. END_OF_FILE
  481. if test 10382 -ne `wc -c <'Makefile.std'`; then
  482.     echo shar: \"'Makefile.std'\" unpacked with wrong size!
  483. fi
  484. # end of 'Makefile.std'
  485. fi
  486. if test -f 'dialog.c' -a "${1}" != "-c" ; then 
  487.   echo shar: Will not clobber existing file \"'dialog.c'\"
  488. else
  489. echo shar: Extracting \"'dialog.c'\" \(2998 characters\)
  490. sed "s/^X//" >'dialog.c' <<'END_OF_FILE'
  491. X/*
  492. X * Dialog.c
  493. X */
  494. X
  495. X#include "stratego.h"
  496. X
  497. X#define CHAR_WIDTH(f)    ((f)->max_bounds.rbearing - (f)->min_bounds.lbearing -2)
  498. X#define CHAR_HEIGHT(f)    ((f)->max_bounds.ascent + (f)->max_bounds.descent - 2)
  499. X
  500. X#define max(a, b)    ((a) > (b) ? (a) : (b))
  501. X
  502. X#define DIALOG_OK        0
  503. X#define DIALOG_CANCEL        1
  504. X#define DIALOG_UNDECIDED    2
  505. X
  506. Xstatic int dialog_status;
  507. X
  508. Xstatic XtCallbackProc DialogOk ()
  509. X{
  510. X    dialog_status = DIALOG_OK;
  511. X}
  512. X
  513. Xstatic XtCallbackProc DialogCancel ()
  514. X{
  515. X    dialog_status = DIALOG_CANCEL;
  516. X}
  517. X
  518. XBool DialogBoxResult (prompt, input_buffer, edit_length, cancel_fl)
  519. Xchar *prompt, *input_buffer;
  520. Xint edit_length, cancel_fl;
  521. X{
  522. X    Widget Popupshell, Dialog, Editfield;
  523. X    Dimension width, twidth, theight, dwidth;
  524. X    XFontStruct *font;
  525. X    XEvent event;
  526. X    Dimension right_margin, left_margin;
  527. X    Position x, y;
  528. X    Arg args[3];
  529. X    int argc;
  530. X
  531. X    Popupshell = XtCreatePopupShell ("PopupShell", overrideShellWidgetClass,
  532. X                     Toplevel, NULL, ZERO);
  533. X
  534. X    XtSetArg (args[0], XtNlabel, prompt);
  535. X    argc = 1;
  536. X
  537. X    if (input_buffer != NULL) {
  538. X        if (strlen (input_buffer) > edit_length)
  539. X            edit_length = strlen (input_buffer);
  540. X        XtSetArg (args[1], XtNvalue, input_buffer);
  541. X        argc = 2;
  542. X    }
  543. X    Dialog = XtCreateManagedWidget ("Popup", dialogWidgetClass,
  544. X                    Popupshell, args, argc);
  545. X
  546. X    XawDialogAddButton (Dialog, "   OK   ", DialogOk, NULL);
  547. X    if (cancel_fl == ADD_CANCEL)
  548. X        XawDialogAddButton (Dialog, " CANCEL ", DialogCancel, NULL);
  549. X
  550. X    font = NULL;
  551. X    XtSetArg (args[0], XtNfont, &font);
  552. X    XtGetValues (Dialog, args, 1);
  553. X    if (font != NULL)
  554. X        dwidth = CHAR_WIDTH (font) * strlen(prompt);
  555. X    else
  556. X        dwidth = 150;
  557. X
  558. X    if (edit_length > 0) {
  559. X        Editfield = XtNameToWidget (Dialog, "value");
  560. X        XtSetArg (args[0], XtNfont, &font);
  561. X        XtSetArg (args[1], XtNrightMargin, &right_margin);
  562. X        XtSetArg (args[2], XtNleftMargin, &left_margin);
  563. X        XtGetValues (Editfield, args, 3);
  564. X        width = right_margin + left_margin +
  565. X            CHAR_WIDTH (font) * edit_length;
  566. X
  567. X        XtSetArg (args[0], XtNwidth, width);
  568. X        XtSetValues (Editfield, args, 1);
  569. X
  570. X        dwidth = max (dwidth, width);
  571. X    }
  572. X
  573. X/* Position Dialog box in center of application */
  574. X    XtSetArg (args[0], XtNwidth, &twidth);
  575. X    XtSetArg (args[1], XtNheight, &theight);
  576. X    XtGetValues (Board, args, 2);
  577. X
  578. X    XtTranslateCoords (Board, (Position) (twidth - dwidth) / 2,
  579. X                     (Position) (theight - 58) / 2, &x, &y);
  580. X    
  581. X    XtMoveWidget (Popupshell, x, y);
  582. X    XtPopup (Popupshell, XtGrabExclusive);
  583. X
  584. X    dialog_status = DIALOG_UNDECIDED;
  585. X
  586. X    do {
  587. X        XtAppNextEvent (app_con, &event);
  588. X        XtDispatchEvent (&event);
  589. X    } while (dialog_status == DIALOG_UNDECIDED);
  590. X
  591. X    if (input_buffer != NULL)
  592. X        strcpy (input_buffer, XawDialogGetValueString(Dialog));
  593. X
  594. X    XtPopdown (Popupshell);
  595. X    XtDestroyWidget (Dialog);
  596. X    
  597. X    if (dialog_status == DIALOG_CANCEL) {
  598. X        message ("Operation cancelled.");
  599. X        return False;
  600. X    }
  601. X
  602. X    return True;
  603. X}
  604. X
  605. X
  606. X/*
  607. X * Dialog value box Return Key redefinition.
  608. X */
  609. Xstatic XtActionsRec actions[] = {
  610. X    { "DialogOk",     (void (*)()) DialogOk }
  611. X};
  612. X
  613. Xvoid init_dialog ()
  614. X{
  615. X    XtAppAddActions (XtWidgetToApplicationContext (Toplevel),
  616. X             actions, XtNumber (actions));
  617. X}
  618. END_OF_FILE
  619. if test 2998 -ne `wc -c <'dialog.c'`; then
  620.     echo shar: \"'dialog.c'\" unpacked with wrong size!
  621. fi
  622. # end of 'dialog.c'
  623. fi
  624. if test ! -d 'icons' ; then
  625.     echo shar: Creating directory \"'icons'\"
  626.     mkdir 'icons'
  627. fi
  628. if test -f 'main.c' -a "${1}" != "-c" ; then 
  629.   echo shar: Will not clobber existing file \"'main.c'\"
  630. else
  631. echo shar: Extracting \"'main.c'\" \(8622 characters\)
  632. sed "s/^X//" >'main.c' <<'END_OF_FILE'
  633. X/*
  634. X * Main.c
  635. X */
  636. X
  637. X#include "stratego.h"
  638. X
  639. XXtAppContext app_con;
  640. XXtInputId EnemyID;
  641. XWidget Toplevel, Stratego, Board, Tiles, Message;
  642. X
  643. Xstatic void init_actions ();
  644. Xvoid new_button_box ();
  645. X
  646. Xstatic String fallback_resources[] = { 
  647. X    "*PopupShell.allowShellResize:  True",
  648. X    "*PopupShell.borderWidth:       4",
  649. X    "*PopupShell.Dialog*shapeStyle: oval",
  650. X    "*PopupShell.Dialog.value.translations: #override \\n \
  651. X                        <Key>Return: DialogOk()",
  652. X    "*Board.borderWidth:             4",
  653. X    "*Board.defaultDistance:         1",
  654. X
  655. X    "*Water.highlightThickness:         0",
  656. X
  657. X    "*BoardPosition.highlightThickness: 0",
  658. X
  659. X    "*Tiles.borderWidth:             2",
  660. X    "*Tiles.defaultDistance:         2",
  661. X    "*TilePosition.orientation:        horizontal",
  662. X
  663. X    "*TileBitmap.borderWidth:        0",
  664. X    "*TileBitmap.highlightThickness:    1",
  665. X
  666. X    "*ButtonSet.borderWidth:        0",
  667. X    "*ButtonSet.defaultDistance:        10",
  668. X
  669. X    "*Button.shapeStyle:            oval",
  670. X
  671. X    "*Message.resizable:            True",
  672. X    "*Message.borderWidth:            0",
  673. X    "*translations:                #augment \\n \
  674. X                        <Btn2Down>: CaughtByHook() \\n \
  675. X                        <Btn3Down>: CaughtByHook()",
  676. X    NULL
  677. X};
  678. X
  679. Xstatic BUTTON setup_buttons[] = {
  680. X    " Cursor  ", WipeCursor, TRUE, NULL,
  681. X    "  Load   ", Load,     TRUE, NULL,
  682. X    "  Ready  ", Ready,     TRUE, NULL,
  683. X    " Message ", Mail,     TRUE, NULL,
  684. X    "  Clear  ", Clear,     TRUE, NULL,
  685. X    "  Store  ", Store,     TRUE, NULL,
  686. X    "   Quit  ", Quit,     TRUE, NULL,
  687. X#ifdef DEBUG
  688. X    "  Debug  ", Debug,     TRUE, NULL,
  689. X#endif
  690. X};
  691. X
  692. Xstatic void create_board (), create_tiles ();
  693. XBOARD_POS board[MAX_ROWS][MAX_COLS];
  694. XPLAYER players[2];
  695. X
  696. Xstatic void Usage()
  697. X{
  698. X    fprintf (stderr, "Usage: xstratego opponent@machine <Your name>.\n");
  699. X    fprintf (stderr, "       or xstratego -s to set up a board.\n");
  700. X    exit (1);
  701. X}
  702. X
  703. Xmain (argc, argv)
  704. Xint argc;
  705. Xchar *argv[];
  706. X{
  707. X    Arg args[2];
  708. X    char *at_sym;
  709. X    char name_buf[100];
  710. X    int i;
  711. X
  712. X    Toplevel = XtAppInitialize (&app_con, "Xstratego", NULL, ZERO,
  713. X                    &argc, argv, fallback_resources, NULL,ZERO);
  714. X
  715. X    if (argc == 2 && !strcmp (argv[1], "-s")) {
  716. X        strcpy (players[0].name, "Nobody");
  717. X        players[0].setup_only = TRUE;
  718. X
  719. X        for (i = 0; i < XtNumber(setup_buttons); i++) {
  720. X            if (setup_buttons[i].callback == Ready || 
  721. X                          setup_buttons[i].callback == Mail)
  722. X                setup_buttons[i].sensitive = FALSE;
  723. X        }
  724. X    }
  725. X    else if (argc == 3 && (at_sym = strchr (argv[1], '@')) != NULL) {
  726. X        *at_sym++ = '\0';
  727. X        setup_communication (argv[2], argv[1], at_sym);
  728. X    }
  729. X    else
  730. X        Usage ();
  731. X
  732. X    Stratego = XtCreateManagedWidget ("Stratego", formWidgetClass, Toplevel,
  733. X                      NULL, ZERO);
  734. X
  735. X    XtSetArg (args[0], XtNlabel, "  ");
  736. X    Message = XtCreateManagedWidget ("Message", labelWidgetClass, Stratego,
  737. X                     args, 1);
  738. X
  739. X    init_icons ();
  740. X    init_board ();
  741. X    init_dialog ();
  742. X    init_actions ();
  743. X
  744. X    create_board (Stratego);
  745. X    create_tiles (Stratego);
  746. X
  747. X    new_button_box (setup_buttons, XtNumber(setup_buttons));
  748. X    
  749. X    XtSetArg (args[0], XtNfromHoriz, NULL);
  750. X    XtSetArg (args[1], XtNfromVert, NULL);
  751. X    XtSetValues (Board, args, 2);
  752. X
  753. X    XtSetArg (args[0], XtNfromHoriz, Board);
  754. X    XtSetArg (args[1], XtNfromVert, NULL);
  755. X    XtSetValues (Tiles, args, 2);
  756. X
  757. X    XtSetArg (args[0], XtNfromHoriz, NULL);
  758. X    XtSetArg (args[1], XtNfromVert, Board);
  759. X    XtSetValues (Message, args, 2);
  760. X
  761. X    if (players[0].setup_only == FALSE) {
  762. X        sprintf (name_buf, "Stratego (%s) [%s@%s.%s]", players[0].name,
  763. X             players[0].login, players[0].machine,
  764. X             players[0].domain);
  765. X        EnemyID = XtAppAddInput (app_con, players[1].fd,
  766. X                     XtInputReadMask,
  767. X                     EnemyInterrupt, NULL);
  768. X    }
  769. X    else
  770. X        strcpy (name_buf, "Stratego (Setup Board)");
  771. X
  772. X    XtSetArg (args[0], XtNtitle, name_buf);
  773. X    XtSetValues (Toplevel, args, 1);
  774. X
  775. X    XtRealizeWidget (Toplevel);
  776. X    XtAppMainLoop (app_con);
  777. X}
  778. X
  779. Xstatic void CaughtByHook()
  780. X{
  781. X    /* Action already done by action hook proecedure "ButtonPressHook" */
  782. X}
  783. X
  784. Xstatic XtActionsRec default_actions[] = {
  785. X    "CaughtByHook",    CaughtByHook
  786. X};
  787. X
  788. Xstatic void init_actions ()
  789. X{
  790. X    XtAppAddActions (app_con, default_actions, XtNumber (default_actions));
  791. X    XtAppAddActionHook (app_con, ButtonPressHook, NULL);
  792. X}
  793. X
  794. Xstatic Widget Underneath (y, x)
  795. Xint y, x;
  796. X{
  797. X    if (y == 0)
  798. X        return NULL;
  799. X    
  800. X    if (y == 6 && (x == 2 || x == 3 || x == 6 || x == 7))
  801. X        return board[4][x & ~0x01].widget;
  802. X    
  803. X    return board[y - 1][x].widget;
  804. X}
  805. X
  806. Xstatic Widget Nextto (y, x)
  807. Xint y, x;
  808. X{
  809. X    if (x == 0)
  810. X        return NULL;
  811. X    
  812. X    if ((y == 4 || y == 5) && (x == 4 || x == 8))
  813. X        return board[4][x - 2].widget;
  814. X    
  815. X    return board[y][x - 1].widget;
  816. X}
  817. X
  818. Xstatic void create_water (parent, y, x)
  819. XWidget parent;
  820. Xint y, x;
  821. X{
  822. X    Dimension wg_width, wg_height, wg_borderwidth;
  823. X    int df_distance, height, width;
  824. X    Arg args[5];
  825. X
  826. X    XtSetArg (args[0], XtNdefaultDistance, &df_distance);
  827. X    XtGetValues (parent, args, 1);
  828. X
  829. X    XtSetArg (args[0], XtNwidth, &wg_width);
  830. X    XtSetArg (args[1], XtNheight, &wg_height);
  831. X    XtSetArg (args[2], XtNborderWidth, &wg_borderwidth);
  832. X    XtGetValues (board[0][0].widget, args, 3);
  833. X
  834. X    width  = df_distance + 2 * (wg_width  + wg_borderwidth);
  835. X    height = df_distance + 2 * (wg_height + wg_borderwidth);
  836. X
  837. X    XtSetArg (args[0], XtNwidth, width);
  838. X    XtSetArg (args[1], XtNheight, height);
  839. X    XtSetArg (args[2], XtNcursor, tiles[BOAT_CURSOR].cursor);
  840. X    XtSetArg (args[3], XtNfromVert, board[y - 1][x].widget);
  841. X    XtSetArg (args[4], XtNfromHoriz, board[y][x - 1].widget);
  842. X
  843. X    board[y][x].widget = XtCreateManagedWidget ("Water", commandWidgetClass,
  844. X                            parent, args, 5);
  845. X
  846. X    XtAddCallback (board[y][x].widget, XtNcallback,
  847. X               ActivateBoardPosition, &board[y][x]);
  848. X}
  849. X
  850. Xstatic void create_board (parent)
  851. XWidget parent;
  852. X{
  853. X    Arg args[4];
  854. X    int x, y;
  855. X
  856. X    Board = XtCreateManagedWidget ("Board", formWidgetClass, parent,
  857. X                       NULL, ZERO);
  858. X
  859. X    XtSetArg (args[0], XtNbitmap, tiles[FREE].pixmap);
  860. X    XtSetArg (args[1], XtNcursor, tiles[BOARD_CURSOR].cursor);
  861. X    for (y = 0; y < MAX_ROWS; y++) {
  862. X        for (x = 0; x < MAX_COLS; x++) {
  863. X            if (board[y][x].value == WATER) {
  864. X                if (y == 4 && (x == 2 || x == 6))
  865. X                    create_water (Board, y, x);
  866. X                continue;
  867. X            }
  868. X
  869. X            XtSetArg (args[2], XtNfromVert, Underneath (y, x));
  870. X            XtSetArg (args[3], XtNfromHoriz, Nextto (y, x));
  871. X            board[y][x].widget = XtCreateManagedWidget (
  872. X                        "BoardPosition",
  873. X                         commandWidgetClass,
  874. X                         Board, args, 4);
  875. X
  876. X            XtAddCallback (board[y][x].widget, XtNcallback,
  877. X                       ActivateBoardPosition, &board[y][x]);
  878. X
  879. X            board[y][x].y = y;
  880. X            board[y][x].x = x;
  881. X        }
  882. X    }
  883. X}
  884. X
  885. Xstatic void create_tiles (parent)
  886. XWidget parent;
  887. X{
  888. X    Arg box_args[3], command_args[2], label_args[1];
  889. X    int i;
  890. X
  891. X    Tiles = XtCreateManagedWidget ("Tiles", formWidgetClass, parent,
  892. X                       NULL, ZERO);
  893. X
  894. X    XtSetArg (box_args[0],    XtNcursor, tiles[ACCOUNT_CURSOR].cursor);
  895. X    XtSetArg (command_args[0], XtNcursor, tiles[ACCOUNT_CURSOR].cursor);
  896. X
  897. X    for (i = FLAG; i <= BOMB; i++) {
  898. X        XtSetArg (box_args[1], XtNfromVert,
  899. X              (i == FLAG || i == LIEUTENANT) ? NULL : 
  900. X                        tiles[i - 1].box_widget);
  901. X        XtSetArg (box_args[2], XtNfromHoriz,
  902. X              (i < LIEUTENANT) ? NULL :
  903. X                tiles[i - (LIEUTENANT - FLAG)].box_widget);
  904. X        tiles[i].box_widget = XtCreateManagedWidget ("TilePosition",
  905. X                                 boxWidgetClass,
  906. X                                 Tiles, box_args,3);
  907. X
  908. X        XtSetArg (command_args[1], XtNbitmap, tiles[i].pixmap);
  909. X        tiles[i].bitmap_widget = XtCreateManagedWidget ("TileBitmap",
  910. X                        commandWidgetClass,
  911. X                        tiles[i].box_widget,
  912. X                        command_args, 2);
  913. X        XtAddCallback (tiles[i].bitmap_widget, XtNcallback, 
  914. X                   SelectSetupBoardCursor, &tiles[i]);
  915. X
  916. X        XtSetArg (label_args[0], XtNlabel, "   ");
  917. X        tiles[i].count_widget = XtCreateManagedWidget ("TileCount",
  918. X                          labelWidgetClass, 
  919. X                          tiles[i].box_widget,
  920. X                          label_args, 1);
  921. X        UpdateTileCount (&tiles[i], 0);
  922. X    }
  923. X}
  924. X
  925. Xvoid new_button_box (list, nr_buttons)
  926. XBUTTON *list;
  927. Xint nr_buttons;
  928. X{
  929. X    static BUTTON *prev_set;
  930. X    static int prev_nr_buttons;
  931. X    static Widget ButtonSet;
  932. X    Arg args[3];
  933. X    int i, split;
  934. X
  935. X    if (prev_set != (BUTTON *) 0) {
  936. X        for (i = 0; i < prev_nr_buttons; i++) {
  937. X            XtUnmanageChild (prev_set[i].widget);
  938. X            XtDestroyWidget (prev_set[i].widget);
  939. X        }
  940. X    }
  941. X    else {
  942. X        XtSetArg (args[0], XtNfromHoriz, Board);
  943. X        XtSetArg (args[1], XtNfromVert,  Tiles);
  944. X        ButtonSet = XtCreateManagedWidget ("ButtonSet", formWidgetClass,
  945. X                           Stratego, args, 2);
  946. X    }
  947. X
  948. X    prev_set = list;
  949. X    prev_nr_buttons = nr_buttons;
  950. X
  951. X    split = (nr_buttons + 1) / 2;
  952. X    for (i = 0; i < nr_buttons; i++) {
  953. X        XtSetArg (args[0], XtNlabel, list[i].label);
  954. X        XtSetArg (args[1], XtNfromHoriz,
  955. X                   (i < split) ? NULL : list[i - split].widget);
  956. X        XtSetArg (args[2], XtNfromVert,
  957. X                   (i % split) ? list[i - 1].widget : NULL);
  958. X        list[i].widget = XtCreateManagedWidget ("Button",
  959. X                            commandWidgetClass,
  960. X                            ButtonSet, args, 3);
  961. X        if (list[i].callback)
  962. X            XtAddCallback (list[i].widget, XtNcallback, 
  963. X                       list[i].callback, NULL);
  964. X        if (list[i].sensitive == FALSE)
  965. X            XtSetSensitive(list[i].widget, FALSE);
  966. X    }
  967. X}
  968. END_OF_FILE
  969. if test 8622 -ne `wc -c <'main.c'`; then
  970.     echo shar: \"'main.c'\" unpacked with wrong size!
  971. fi
  972. # end of 'main.c'
  973. fi
  974. if test -f 'play.c' -a "${1}" != "-c" ; then 
  975.   echo shar: Will not clobber existing file \"'play.c'\"
  976. else
  977. echo shar: Extracting \"'play.c'\" \(8802 characters\)
  978. sed "s/^X//" >'play.c' <<'END_OF_FILE'
  979. X/*
  980. X * Play.c
  981. X */
  982. X
  983. X#include "stratego.h"
  984. X
  985. Xstatic void announce_loser ();
  986. Xvoid check_can_play ();
  987. X
  988. X/*
  989. X * Remise Button Callback Routine.
  990. X */
  991. Xstatic Widget remise_button_widget = NULL;
  992. X
  993. Xvoid EnableRemiseButton()
  994. X{
  995. X    if (remise_button_widget != NULL) {
  996. X        XtSetSensitive(remise_button_widget, True);
  997. X        remise_button_widget = NULL;
  998. X    }
  999. X}
  1000. X
  1001. Xstatic XtCallbackProc Remise (widget)
  1002. XWidget widget;
  1003. X{
  1004. X    remise_button_widget = widget;
  1005. X
  1006. X    XtSetSensitive (widget, FALSE);
  1007. X
  1008. X    send_remise_offer ();
  1009. X
  1010. X    message ("On its way...");
  1011. X}
  1012. X
  1013. X/*
  1014. X * Incoming remise offer.
  1015. X */
  1016. Xvoid RemiseOffered ()
  1017. X{
  1018. X    char msg_buf[100];
  1019. X
  1020. X    sprintf (msg_buf, "%s offers a Remise. Do you accept %s?",
  1021. X         players[1].name, players[0].name);
  1022. X
  1023. X    if (DialogBoxResult (msg_buf, NULL, 0, ADD_CANCEL) == True) {
  1024. X        send_remise_answer (REMISE_ACCEPTED);
  1025. X        end_game ();
  1026. X    }
  1027. X    else
  1028. X        send_remise_answer (REMISE_DECLINED);
  1029. X}
  1030. X
  1031. X/*
  1032. X * GiveUp button
  1033. X */
  1034. Xstatic XtCallbackProc GiveUp (widget)
  1035. XWidget widget;
  1036. X{
  1037. X    if (DialogBoxResult ("Loser!", NULL, 0, ADD_CANCEL) == True) {
  1038. X        send_quit ();
  1039. X        message ("You surrender unconditionally to %s...",
  1040. X             players[1].name);
  1041. X        end_game ();
  1042. X    }
  1043. X}
  1044. X
  1045. X
  1046. X/*
  1047. X * Play module.
  1048. X */
  1049. Xstatic BUTTON play_buttons[] = {
  1050. X    " Remise  ", Remise,    TRUE, NULL,
  1051. X    " Message ", Mail,      TRUE, NULL,
  1052. X    " Give Up ", GiveUp,    TRUE, NULL,
  1053. X};
  1054. X
  1055. Xvoid start_play ()
  1056. X{
  1057. X    int i;
  1058. X
  1059. X    players[players[0].has_first_move ? 0 : 1].status = PL_PLAYING;
  1060. X
  1061. X    new_button_box (play_buttons, XtNumber(play_buttons));
  1062. X
  1063. X    if (players[0].has_first_move) {
  1064. X        players[0].status = PL_PLAYING;
  1065. X        message ("It is your move %s!", players[0].name);
  1066. X        check_can_play (O_PLAYER);
  1067. X    }
  1068. X    else {
  1069. X        message ("It is %s'%s move %s!", players[1].name, 
  1070. X            (players[1].name[strlen (players[1].name) - 1] == 's') ? "" : "s", players[0].name);
  1071. X        check_can_play (O_ENEMY);
  1072. X    }
  1073. X    
  1074. X    for (i = FLAG; i <= BOMB; i++)
  1075. X        UpdateTileCount (&tiles[i], tiles[i].available);
  1076. X}
  1077. X
  1078. Xstatic Boolean legal_movement (from_pos, to_pos)
  1079. XBOARD_POS *from_pos, *to_pos;
  1080. X{
  1081. X    int y, x, dx, dy, dist_x, dist_y;
  1082. X    int from_x, from_y;
  1083. X    int legal;
  1084. X
  1085. X    from_x = from_pos->x;
  1086. X    from_y = from_pos->y;
  1087. X    y = to_pos->y;
  1088. X    x = to_pos->x;
  1089. X
  1090. X    dx = ((dist_x = from_x - x) < 0) ? 1 : -1;
  1091. X    dy = ((dist_y = from_y - y) < 0) ? 1 : -1;
  1092. X
  1093. X    if ((dist_x && dist_y) || (dist_x == 0 && dist_y == 0))
  1094. X        return False;
  1095. X
  1096. X    legal = 1;
  1097. X
  1098. X    if (abs (dist_x) > 1 || abs (dist_y) > 1) {
  1099. X        if (from_pos->value != SCOUT)
  1100. X            return False;
  1101. X
  1102. X        if (dist_x != 0) {    /* Horizontal movement */
  1103. X            do {
  1104. X                from_x += dx;
  1105. X                legal = (board[from_y][from_x].value == FREE);
  1106. X            } while (from_x != x && legal);
  1107. X        }
  1108. X        else if (dist_y != 0) {    /* Vertical movement */
  1109. X            do {
  1110. X                from_y += dy;
  1111. X                legal = (board[from_y][from_x].value == FREE);
  1112. X            } while (from_y != y && legal);
  1113. X        }
  1114. X    }
  1115. X
  1116. X    return legal ? True : False;
  1117. X}
  1118. X
  1119. Xvoid play_tile (board_pos)
  1120. XBOARD_POS *board_pos;
  1121. X{
  1122. X    BOARD_POS *from_pos = players[0].from_pos;
  1123. X
  1124. X    if (players[0].status == PL_PLAYING) {
  1125. X        if (board_pos->value == FREE)
  1126. X            display_error (move_empty);
  1127. X        else if (board_pos->value == WATER)
  1128. X            display_error (illegal);
  1129. X        else if (board_pos->owner == O_ENEMY)
  1130. X            display_error (move_opponent);
  1131. X        else if (board_pos->value == FLAG)
  1132. X            display_error (move_flag);
  1133. X        else if (board_pos->value == BOMB)
  1134. X            display_error (move_bomb);
  1135. X        else {
  1136. X            players[0].status   = PL_PICKED_UP;
  1137. X            players[0].from_pos = board_pos;
  1138. X            MarkBoardPosition (board_pos, True);
  1139. X        }
  1140. X    }
  1141. X    else if (players[0].status == PL_PICKED_UP) {
  1142. X        if (board_pos->value == WATER)
  1143. X            display_error (in_water);
  1144. X        else if (board_pos == from_pos)
  1145. X            ;
  1146. X        else if (board_pos->owner == O_PLAYER)
  1147. X            display_error (kill_own);
  1148. X        else if (board_pos->value == FREE || board_pos->owner==O_ENEMY){
  1149. X            if (legal_movement (from_pos, board_pos)) {
  1150. X                switch (execute_move (from_pos, board_pos)) {
  1151. X                case DO_MOVE:
  1152. X                    send_move (from_pos, board_pos);
  1153. X                    players[0].status = PL_READY;
  1154. X                    check_can_play (O_ENEMY);
  1155. X                    break;
  1156. X                case REMISE_MOVE:
  1157. X                case WIN_MOVE:
  1158. X                    send_move (from_pos, board_pos);
  1159. X                    end_game ();
  1160. X                case UNDO_MOVE:
  1161. X                    players[0].status = PL_PLAYING;
  1162. X                    break;
  1163. X                }
  1164. X                return;
  1165. X            }
  1166. X
  1167. X            display_error (illegal);
  1168. X        }
  1169. X
  1170. X    /* Cancel move */
  1171. X        if (players[0].status == PL_PICKED_UP)
  1172. X            MarkBoardPosition (from_pos, False);
  1173. X
  1174. X        players[0].status = PL_PLAYING;
  1175. X
  1176. X    }
  1177. X}
  1178. X
  1179. Xvoid ConfirmMove ()
  1180. X{
  1181. X    AssignBoardPosition (players[0].from_pos, &tiles[FREE], O_NOBODY);
  1182. X    AssignBoardPosition (players[0].to_pos, players[0].to_tile,
  1183. X                 players[0].to_owner);
  1184. X
  1185. X    players[0].confirm = False;
  1186. X}
  1187. X
  1188. Xint execute_move (from_pos, to_pos)
  1189. XBOARD_POS *from_pos, *to_pos;
  1190. X{
  1191. X    TILE *from_tile, *to_tile;
  1192. X    int winner, move_type;
  1193. X
  1194. X    if (players[0].confirm)
  1195. X        ConfirmMove ();
  1196. X
  1197. X    players[0].from_pos = from_pos;
  1198. X    players[0].to_pos   = to_pos;
  1199. X
  1200. X    from_tile = &tiles[from_pos->value];
  1201. X    to_tile   = &tiles[to_pos->value];
  1202. X
  1203. X    if (to_pos->owner == O_NOBODY) {
  1204. X    /* Player move */
  1205. X        if (from_pos->owner == O_PLAYER) {
  1206. X            AssignBoardPosition (from_pos, &tiles[FREE], O_NOBODY);
  1207. X            AssignBoardPosition (to_pos, from_tile, O_PLAYER);
  1208. X
  1209. X            move_type = register_board (O_PLAYER);
  1210. X            if (move_type == UNDO_MOVE) {
  1211. X                AssignBoardPosition (from_pos, from_tile,
  1212. X                             O_PLAYER);
  1213. X                AssignBoardPosition (to_pos, &tiles[FREE],
  1214. X                             O_NOBODY);
  1215. X            }
  1216. X
  1217. X            return move_type;
  1218. X        }
  1219. X
  1220. X    /* Enemy move */
  1221. X        players[0].to_owner = from_pos->owner;
  1222. X        players[0].to_tile  = from_tile;
  1223. X        players[0].confirm  = True;
  1224. X
  1225. X    /* Show move on board */
  1226. X        AssignBoardPosition (from_pos, &tiles[ENEMY], from_pos->owner);
  1227. X        AssignBoardPosition (to_pos,   &tiles[ENEMY], from_pos->owner);
  1228. X        MarkBoardPosition (from_pos, True);
  1229. X        MarkBoardPosition (to_pos,   True);
  1230. X
  1231. X    /* Fill in right board values to register board setup */
  1232. X        from_pos->owner = O_NOBODY;
  1233. X        from_pos->value = tiles[FREE].value;
  1234. X        to_pos->owner   = O_ENEMY;
  1235. X        to_pos->value   = from_tile->value;
  1236. X
  1237. X        return register_board (O_ENEMY);
  1238. X    }
  1239. X
  1240. X/* Battle stations */
  1241. X    MarkBoardPosition (from_pos, True);
  1242. X    MarkBoardPosition (to_pos,   True);
  1243. X
  1244. X    if (to_tile->value == FLAG) {
  1245. X        UpdateTileCount (&tiles[FLAG], -1);
  1246. X        announce_loser (to_pos->owner);
  1247. X        return WIN_MOVE;
  1248. X    }
  1249. X
  1250. X    players[0].confirm = True;
  1251. X
  1252. X    if ((from_tile->value == SPY   && to_tile->value == MARSHAL) ||
  1253. X        (from_tile->value == MINER && to_tile->value == BOMB) ||
  1254. X        (from_tile->value < to_tile->value && to_tile->value != BOMB)) {
  1255. X        players[0].to_owner = from_pos->owner;
  1256. X        players[0].to_tile  = from_tile;
  1257. X        if ((winner = from_pos->owner) == O_PLAYER)
  1258. X            UpdateTileCount (to_tile, -1);
  1259. X    }
  1260. X    else if (to_tile->value == from_tile->value) {
  1261. X        players[0].to_owner = O_NOBODY;
  1262. X        players[0].to_tile  = &tiles[FREE];
  1263. X        winner = (time (NULL) & 0x01) ? O_PLAYER : O_ENEMY;
  1264. X        UpdateTileCount (to_tile, -1);
  1265. X    }
  1266. X    else {
  1267. X        players[0].to_owner = to_pos->owner;
  1268. X        players[0].to_tile  = to_tile;
  1269. X        winner = to_pos->owner;
  1270. X        if ((winner = to_pos->owner) == O_PLAYER)
  1271. X            UpdateTileCount (from_tile, -1);
  1272. X    }
  1273. X
  1274. X    display_error ((winner == O_PLAYER) ? win_capture : lose_capture);
  1275. X
  1276. X    register_hit ();
  1277. X
  1278. X    return DO_MOVE;
  1279. X}
  1280. X
  1281. Xstatic void announce_loser (loser)
  1282. Xint loser;
  1283. X{
  1284. X    if (loser == O_PLAYER)
  1285. X        message ("I'm afraid you bought it, old boy.");
  1286. X    else
  1287. X        message ("Nice one %s!", players[0].name);
  1288. X}
  1289. X
  1290. Xvoid check_can_play (owner)
  1291. Xint owner;
  1292. X{
  1293. X    BOARD_POS *board_pos;
  1294. X    int y, x, enemy;
  1295. X
  1296. X    enemy = (owner == O_PLAYER) ? O_ENEMY : O_PLAYER;
  1297. X
  1298. X    for (y = 0; y < MAX_ROWS; y++) {
  1299. X        for (x = 0; x < MAX_COLS; x++) {
  1300. X        board_pos = &board[y][x];
  1301. X        if (board_pos->owner != owner || board_pos->value <= FLAG  ||
  1302. X                             board_pos->value >= BOMB)
  1303. X            continue;
  1304. X
  1305. X        if (y - 1 >= 0 && (board[y - 1][x].value == FREE ||
  1306. X                       board[y - 1][x].owner == enemy))
  1307. X            return;
  1308. X
  1309. X        if (y + 1 < MAX_ROWS && (board[y + 1][x].value == FREE ||
  1310. X                     board[y + 1][x].owner == enemy))
  1311. X            return;
  1312. X
  1313. X        if (x - 1 >= 0 && (board[y][x - 1].value == FREE ||
  1314. X                       board[y][x - 1].owner == enemy))
  1315. X            return;
  1316. X
  1317. X        if (x + 1 < MAX_COLS && (board[y][x + 1].value == FREE ||
  1318. X                     board[y][x + 1].owner == enemy))
  1319. X            return;
  1320. X
  1321. X        }
  1322. X    }
  1323. X
  1324. X    announce_loser (owner);
  1325. X    end_game ();
  1326. X}
  1327. X
  1328. X/*
  1329. X * End game routines.
  1330. X */
  1331. X
  1332. X
  1333. XXtCallbackProc FastQuit (widget)
  1334. XWidget widget;
  1335. X{
  1336. X    XtDestroyApplicationContext (app_con);
  1337. X    exit (0);
  1338. X}
  1339. X
  1340. Xstatic BUTTON endgame_buttons[] = {
  1341. X    " Quit ",  FastQuit,  TRUE, NULL,
  1342. X    " Store ", Store,     TRUE, NULL
  1343. X};
  1344. X
  1345. X
  1346. Xvoid end_game ()
  1347. X{
  1348. X    BOARD_POS *board_pos;
  1349. X    int nr_buttons = XtNumber (endgame_buttons) - 1;
  1350. X    int y, x;
  1351. X
  1352. X    end_communications ();
  1353. X
  1354. X    if (players[0].confirm)
  1355. X        ConfirmMove ();
  1356. X
  1357. X    if (players[0].status <= PL_SETUP_READY)
  1358. X        nr_buttons++;        /* Allow saving current position */
  1359. X    else {                /* Show board              */
  1360. X        for (y = 0; y < MAX_ROWS; y++) { 
  1361. X            for (x = 0; x < MAX_COLS; x++) { 
  1362. X                if (board[y][x].owner == O_ENEMY) {
  1363. X                       board_pos = &board[y][x];
  1364. X                       board_pos->value = abs(board_pos->value);
  1365. X                       MarkBoardPosition (board_pos, True);
  1366. X                }
  1367. X            }
  1368. X        }
  1369. X    }
  1370. X
  1371. X    new_button_box (endgame_buttons, nr_buttons);
  1372. X
  1373. X    players[0].status = PL_ENDGAME;
  1374. X}
  1375. END_OF_FILE
  1376. if test 8802 -ne `wc -c <'play.c'`; then
  1377.     echo shar: \"'play.c'\" unpacked with wrong size!
  1378. fi
  1379. # end of 'play.c'
  1380. fi
  1381. if test -f 'setup.c' -a "${1}" != "-c" ; then 
  1382.   echo shar: Will not clobber existing file \"'setup.c'\"
  1383. else
  1384. echo shar: Extracting \"'setup.c'\" \(7918 characters\)
  1385. sed "s/^X//" >'setup.c' <<'END_OF_FILE'
  1386. X/*
  1387. X * Setup.c
  1388. X */
  1389. X
  1390. X#include "stratego.h"
  1391. X
  1392. X#include <sys/types.h>
  1393. X#include <sys/stat.h>
  1394. X
  1395. X/*    HJV:    Normally found in stdlib.h, but some systems do not
  1396. X        have this include file, or have it at another location.
  1397. X        Hoping they will not change the value of F_OK, I hereby
  1398. X        declare it as zero, as it should be.
  1399. X*/
  1400. X
  1401. X#ifndef F_OK
  1402. X#define F_OK 0
  1403. X#endif
  1404. X
  1405. Xstatic void SelectBoardCursor ();
  1406. X
  1407. X/*
  1408. X * Setup buttonbox Callback routines.
  1409. X */
  1410. X
  1411. X/*
  1412. X * WipeCursor Button Callback Routine.
  1413. X */
  1414. XXtCallbackProc WipeCursor (widget)
  1415. XWidget widget;
  1416. X{
  1417. X    SelectBoardCursor (&tiles[FREE]);
  1418. X}
  1419. X
  1420. X
  1421. X/*
  1422. X * Clear Button Callback Routine.
  1423. X */
  1424. XXtCallbackProc Clear (widget)
  1425. XWidget widget;
  1426. X{
  1427. X    int y, x;
  1428. X
  1429. X    for (y = MAX_ROWS - 4; y < MAX_ROWS; y++) {
  1430. X        for (x = 0; x < MAX_COLS; x++) { 
  1431. X            if (board[y][x].value != FREE) {
  1432. X                UpdateTileCount (&tiles[board[y][x].value],
  1433. X                         1);
  1434. X                AssignBoardPosition (&board[y][x], &tiles[FREE],
  1435. X                             O_NOBODY);
  1436. X            }
  1437. X        }
  1438. X    }
  1439. X    send_clear_board ();
  1440. X
  1441. X    SelectBoardCursor (&tiles[FREE]);
  1442. X}
  1443. X
  1444. X
  1445. X/*
  1446. X * Message Button Callback Routine.
  1447. X */
  1448. X
  1449. XXtCallbackProc Mail (widget)
  1450. XWidget widget;
  1451. X{
  1452. X    char msg_buf[100];
  1453. X
  1454. X    msg_buf[0] = '\0';
  1455. X    if (DialogBoxResult ("Enter Message", msg_buf, 80, ADD_CANCEL) == True)
  1456. X        send_mail (msg_buf);
  1457. X}
  1458. X
  1459. X
  1460. X/*
  1461. X * Ready Button Callback Routine.
  1462. X */
  1463. Xstatic BUTTON ready_buttons[] = {
  1464. X    " Message ", Mail, TRUE, NULL,
  1465. X    "  Quit   ", Quit, TRUE, NULL,
  1466. X};
  1467. X
  1468. XXtCallbackProc Ready (widget)
  1469. XWidget widget;
  1470. X{
  1471. X    char msg_buf[100];
  1472. X    int i;
  1473. X
  1474. X    for (i = FLAG; i <= BOMB; i++) {
  1475. X        if (tiles[i].count) {
  1476. X            display_error (finished_premature);
  1477. X            return;
  1478. X        }
  1479. X    }
  1480. X
  1481. X    sprintf (msg_buf, "You will no longer be able to change your setup.");
  1482. X    if (DialogBoxResult (msg_buf, NULL, 0, ADD_CANCEL) == True) {
  1483. X        players[0].status = PL_SETUP_READY;
  1484. X        send_ready ();
  1485. X
  1486. X        if (players[1].status != PL_SETUP_READY) {
  1487. X            message ("Waiting for %s to finish his setup...",
  1488. X                 players[1].name);
  1489. X            new_button_box (ready_buttons, XtNumber(ready_buttons));
  1490. X        }
  1491. X        else
  1492. X            start_play ();
  1493. X    }
  1494. X}
  1495. X
  1496. X
  1497. X/*
  1498. X * Quit Button Callback Routine.
  1499. X */
  1500. XXtCallbackProc Quit (widget)
  1501. XWidget widget;
  1502. X{
  1503. X    if (DialogBoxResult ("Please Confirm Quit", NULL, 0,
  1504. X                            ADD_CANCEL) == True) {
  1505. X        send_quit ();
  1506. X        XtDestroyApplicationContext (app_con);
  1507. X        exit (0);
  1508. X    }
  1509. X}
  1510. X
  1511. X
  1512. X/*
  1513. X * Store Button Callback Routine.
  1514. X */
  1515. Xstatic char filename[NAME_LENGTH] = "board.dat";
  1516. X
  1517. XXtCallbackProc Store (widget)
  1518. XWidget widget;
  1519. X{
  1520. X    char file_buf[80];
  1521. X    char msg_buf[100];
  1522. X    FILE *fp;
  1523. X    int x, y;
  1524. X
  1525. X    strcpy (file_buf, filename);
  1526. X
  1527. X    if (DialogBoxResult ("Enter Filename to Store", file_buf, 50,
  1528. X                            ADD_CANCEL) == False)
  1529. X        return;
  1530. X    
  1531. X    if (access (file_buf, F_OK) == 0) {
  1532. X        sprintf (msg_buf, "\"%s\" already exists. Overwrite?",file_buf);
  1533. X        if (DialogBoxResult (msg_buf, NULL, 0, ADD_CANCEL) == False)
  1534. X            return;
  1535. X    }
  1536. X
  1537. X    if ((fp = fopen (file_buf, "w")) == NULL) {
  1538. X        message ("Cannot open datafile \"%s\".", file_buf);
  1539. X        return;
  1540. X    }
  1541. X
  1542. X    strcpy (filename, file_buf);
  1543. X
  1544. X    for (y = 6; y < MAX_ROWS; y++)
  1545. X        for (x = 0; x < MAX_COLS; x++)
  1546. X            fprintf (fp, "%d ", board[y][x].value);
  1547. X    fclose (fp);
  1548. X
  1549. X    chmod (filename, 0600);
  1550. X    
  1551. X    message ("Board setup saved in \"%s\".", filename);
  1552. X}
  1553. X
  1554. X
  1555. X/*
  1556. X * Load Button Callback Routine.
  1557. X */
  1558. XXtCallbackProc Load (widget)
  1559. XWidget widget;
  1560. X{
  1561. X    char file_buf[80];
  1562. X    FILE *fp;
  1563. X    int y, x, tile_value;
  1564. X    TILE *tile;
  1565. X    BOARD_POS *board_pos;
  1566. X    Boolean failed = FALSE;
  1567. X
  1568. X    strcpy (file_buf, filename);
  1569. X
  1570. X    if (DialogBoxResult ("Enter Filename to Load", file_buf, 50,
  1571. X                               ADD_CANCEL) == False)
  1572. X        return;
  1573. X
  1574. X    strcpy (filename, file_buf);
  1575. X
  1576. X    if ((fp = fopen (filename, "r")) == NULL) {
  1577. X        extern int errno, sys_nerr;
  1578. X        extern char *sys_errlist[];
  1579. X
  1580. X        message ("Cannot open datafile \"%s\": %s", filename,
  1581. X             (errno < 0 || errno >= sys_nerr) ? "Unknown error" :
  1582. X                                sys_errlist[errno]);
  1583. X        return;
  1584. X    }
  1585. X
  1586. X    Clear (widget, (XtPointer) NULL, (XtPointer) NULL);
  1587. X
  1588. X    for (y = 6; y < MAX_ROWS && failed == False; y++) {
  1589. X        for (x = 0; x < MAX_COLS && failed == False; x++) {
  1590. X            if (fscanf (fp, "%d ", &tile_value) != 1) {
  1591. X                message ("Datafile damaged!");
  1592. X                failed = True;
  1593. X            }
  1594. X            else if (tile_value >= FLAG && tile_value <= BOMB) {
  1595. X                board_pos = &board[y][x];
  1596. X                tile = &tiles[tile_value];
  1597. X                if (tile->count == 0) {
  1598. X                    message ("Hmmm, seems like a cheat file to me %s!", players[0].name);
  1599. X                    failed = True;
  1600. X                }
  1601. X                AssignBoardPosition (board_pos, tile, O_PLAYER);
  1602. X                UpdateTileCount (tile, -1);
  1603. X                send_tile_placed (board_pos);
  1604. X            }
  1605. X            else if (tile_value != 0) {
  1606. X                message ("Datafile damaged!");
  1607. X                failed = True;
  1608. X            }
  1609. X        }
  1610. X    }
  1611. X
  1612. X    fclose (fp);
  1613. X
  1614. X    if (failed == True)
  1615. X        Clear (widget, (XtPointer) NULL, (XtPointer) NULL);
  1616. X    else
  1617. X        message ("Board setup loaded from \"%s\".", filename);
  1618. X}
  1619. X
  1620. X
  1621. X/*
  1622. X * TileBitmap widget class callback routines.
  1623. X */
  1624. Xstatic void SelectBoardCursor (tile)
  1625. XTILE *tile;
  1626. X{
  1627. X    int y, x, limit;
  1628. X    Arg args[1];
  1629. X
  1630. X    if (players[0].status == PL_ENDGAME) {    /* Opponent quitted the game */
  1631. X        message ("The game has ended!");
  1632. X        return;
  1633. X    }
  1634. X
  1635. X    limit = (players[0].status == PL_SETUP) ? MAX_ROWS - 4 : 0;
  1636. X
  1637. X    XtSetArg (args[0], XtNcursor, tile->cursor);
  1638. X    for (y = MAX_ROWS - 1; y >= limit; y--)
  1639. X        for (x = MAX_COLS - 1; x >= 0; x--)
  1640. X            XtSetValues (board[y][x].widget, args, 1);
  1641. X    
  1642. X    players[0].tile_select = tile->value;
  1643. X}
  1644. X
  1645. XXtCallbackProc SelectSetupBoardCursor (widget, tile)
  1646. XWidget widget;
  1647. XTILE *tile;
  1648. X{
  1649. X    if (players[0].status != PL_SETUP)
  1650. X        return;
  1651. X
  1652. X    if (tile->count == 0) {
  1653. X        message ("You have no more %ss left!", tile->name);
  1654. X        return;
  1655. X    }
  1656. X
  1657. X    SelectBoardCursor (tile);
  1658. X}
  1659. X
  1660. X
  1661. X/*
  1662. X * Called from callback routine of BoardPosition widget class.
  1663. X */
  1664. Xvoid setup_tile (board_pos)
  1665. XBOARD_POS *board_pos;
  1666. X{
  1667. X    TILE *tile;
  1668. X
  1669. X    if (board_pos->value == WATER) {
  1670. X        message ("Splash blup blup.");
  1671. X        return;
  1672. X    }
  1673. X
  1674. X    if (board_pos->y < MAX_ROWS - 4) {
  1675. X        message ("You cannot put a tile on enemy territory.");
  1676. X        return;
  1677. X    }
  1678. X
  1679. X    if (board_pos->value != FREE) {
  1680. X        UpdateTileCount (&tiles[board_pos->value], 1);
  1681. X        AssignBoardPosition (board_pos, &tiles[FREE], O_NOBODY);
  1682. X        send_tile_placed (board_pos);
  1683. X        if (players[0].tile_select == FREE)
  1684. X            return; /* Erasing */
  1685. X    }
  1686. X
  1687. X    tile = &tiles[players[0].tile_select];
  1688. X    if (tile->value < FLAG || tile->value > BOMB) {
  1689. X        /* No tile selected */
  1690. X        message ("You must select a tile first.");
  1691. X        return;
  1692. X    }
  1693. X
  1694. X    AssignBoardPosition (board_pos, tile, O_PLAYER);
  1695. X    UpdateTileCount (tile, -1);
  1696. X    send_tile_placed (board_pos);
  1697. X
  1698. X    if (tile->count == 0)
  1699. X        SelectBoardCursor (&tiles[FREE]);
  1700. X}
  1701. X
  1702. X#ifdef DEBUG
  1703. XXtCallbackProc Debug ()
  1704. X{
  1705. X    char file_buf[80];
  1706. X    FILE *fp;
  1707. X    int y, x, tile_value;
  1708. X    TILE *tile;
  1709. X    BOARD_POS *board_pos;
  1710. X    Boolean failed = FALSE;
  1711. X    char msg_buf[100];
  1712. X    int i;
  1713. X    char filename[100];
  1714. X
  1715. X    strcpy (filename, "board.dat");
  1716. X    if (DialogBoxResult ("Enter file", filename, sizeof(filename), ADD_CANCEL) == False)
  1717. X        return;
  1718. X
  1719. X    if ((fp = fopen (filename, "r")) == NULL) {
  1720. X        extern int errno, sys_nerr;
  1721. X        extern char *sys_errlist[];
  1722. X
  1723. X        message ("Cannot open datafile \"%s\": %s", filename,
  1724. X             (errno < 0 || errno >= sys_nerr) ? "Unknown error" :
  1725. X                                sys_errlist[errno]);
  1726. X        return;
  1727. X    }
  1728. X
  1729. X    Clear ();
  1730. X
  1731. X    for (y = 6; y < MAX_ROWS && failed == False; y++) {
  1732. X        for (x = 0; x < MAX_COLS && failed == False; x++) {
  1733. X            if (fscanf (fp, "%d ", &tile_value) != 1) {
  1734. X                message ("Datafile damaged!");
  1735. X                failed = True;
  1736. X            }
  1737. X            else if (tile_value >= FLAG && tile_value <= BOMB) {
  1738. X                board_pos = &board[y][x];
  1739. X                tile = &tiles[tile_value];
  1740. X                if (tile->count == 0) {
  1741. X                    message ("Hmmm, seems like a cheat file to me %s!", players[0].name);
  1742. X                    failed = True;
  1743. X                }
  1744. X                AssignBoardPosition (board_pos, tile, O_PLAYER);
  1745. X                UpdateTileCount (tile, -1);
  1746. X                send_tile_placed (board_pos);
  1747. X            }
  1748. X            else if (tile_value != 0) {
  1749. X                message ("Datafile damaged!");
  1750. X                failed = True;
  1751. X            }
  1752. X        }
  1753. X    }
  1754. X
  1755. X    fclose (fp);
  1756. X
  1757. X    if (failed == True)
  1758. X        Clear ();
  1759. X    else
  1760. X        message ("Board setup loaded from \"%s\".", filename);
  1761. X
  1762. X        players[0].status = PL_SETUP_READY;
  1763. X        send_ready ();
  1764. X
  1765. X    if (players[1].status != PL_SETUP_READY) {
  1766. X        message ("Waiting for %s to finish his setup...",
  1767. X             players[1].name);
  1768. X    }
  1769. X    else
  1770. X        start_play ();
  1771. X}
  1772. X#endif
  1773. END_OF_FILE
  1774. if test 7918 -ne `wc -c <'setup.c'`; then
  1775.     echo shar: \"'setup.c'\" unpacked with wrong size!
  1776. fi
  1777. # end of 'setup.c'
  1778. fi
  1779. if test -f 'xstratego.6' -a "${1}" != "-c" ; then 
  1780.   echo shar: Will not clobber existing file \"'xstratego.6'\"
  1781. else
  1782. echo shar: Extracting \"'xstratego.6'\" \(7526 characters\)
  1783. sed "s/^X//" >'xstratego.6' <<'END_OF_FILE'
  1784. X.TH XSTRATEGO 6 "17 March 1991"
  1785. X.SH NAME
  1786. Xxstratego \- X windows based
  1787. X.I stratego
  1788. Xinterface for two players.
  1789. X.SH SYNOPSIS
  1790. X.B xstratego
  1791. X.IB login @ hostname
  1792. X.B playername
  1793. X.br
  1794. X.B xstratego
  1795. X.B \-s
  1796. X.SH DESCRIPTION
  1797. X.LP
  1798. XThe first command line version lets you play against another player, where
  1799. X.TP 15
  1800. X.I login
  1801. Xis your opponents login name.
  1802. X.TP 15
  1803. X.I hostname
  1804. Xis the name of the host he (or she) is currently logged on.
  1805. X.TP 15
  1806. X.B playername
  1807. Xis the name under which you want to play.
  1808. X.LP
  1809. XThe second version gives you the opportunity to create a board setup and save
  1810. Xit for later use.
  1811. X.SH GAME BASICS
  1812. X.B
  1813. XStratego
  1814. Xis a famous board game that has been around for many years. Here is an
  1815. Xoverview of the rules for those who are not familiar with them.
  1816. X.br
  1817. XThe game is played on a board consisting of ten by ten squares. Each
  1818. Xplayer has forty tiles which are placed upon the lower half of the
  1819. Xboard. Each of these tiles has a certain value and move capability. The
  1820. Xvalue of a tile is symbolized by an army rank. In the table below is an
  1821. Xoverview of the tiles and their capabilities. The
  1822. X.I Amount
  1823. Xcolumn shows the number of tiles you have of each type.
  1824. X.sp
  1825. X.TS
  1826. Xlw(.25i) lw(.25i) lw(.25i) lw(.25i) lw(.25i) lw(.25i).
  1827. X_
  1828. X.sp 3p
  1829. X.TB
  1830. XRank    Name    Amount    Can Take    Can be taken by    Movement
  1831. X.sp 3p
  1832. X_
  1833. X.sp 3p
  1834. X 1    Marshal          1    All    Spy    Normal (one square)
  1835. X 2    General          1    Lower rank    Higher rank    Normal
  1836. X 3    Colonel          2    Lower rank    Higher rank    Normal
  1837. X 4    Major          3    Lower rank    Higher rank    Normal
  1838. X 5    Captain          4    Lower rank    Higher rank    Normal
  1839. X 6    Lieutenant          4    Lower rank    Higher rank    Normal
  1840. X 7    Sergeant          4    Lower rank    Higher rank    Normal
  1841. X 8    Miner          5    Lower rank and Bombs    Higher rank    Normal
  1842. X 9    Scout          8    Lower rank    Higher rank    Several squares
  1843. X10    Spy          1    Flag and Marshall    Higher rank    Normal
  1844. X11    Bomb          6    All except Miners    Miner    None
  1845. X12    Flag          1    None    All    None
  1846. X.sp 3p
  1847. X_
  1848. X.TE
  1849. X.sp
  1850. XEight board positions are designated as water. Nobody can swim. The
  1851. Xobject of the game is to take your opponents flag. The values of your
  1852. Xopponents tiles are (of course) not visible to you.
  1853. X.br
  1854. XThe players now take turns. There are two type of moves, moving or
  1855. Xattacking a tile. A move consists of moving a tile horizontal or
  1856. Xvertical. Diagonal moves are not permitted. When you attack an enemy
  1857. Xtile, both the attacking and attacked tile will reveil their value.
  1858. XNormally the highest rank will win (see table) and the other tile will
  1859. Xbe taken off the board. If you attack the enemy and win, your tile will
  1860. Xtake the enemies tile position on the board.
  1861. X.br
  1862. XThe game has ended if one of the following cases occur:
  1863. X.IP \(bu
  1864. XThe flag of one of the players is taken. The winner is the one who's
  1865. Xflag is still standing.
  1866. X.IP \(bu
  1867. XOne of the players can no longer make a valid move. This player will
  1868. Xhave lost the game.
  1869. X.IP \(bu
  1870. XIf the same board setup occurs three times, without a tile being taken
  1871. Xon either side the game is said to have ended in remise. Xstratego will
  1872. Xwarn you whenever a board setup occurs for the second time. It will ask
  1873. Xfor confirmation for the move that will end the game in remise.
  1874. X.SH XSTRATEGO DESCRIPTION
  1875. X.B xstratego
  1876. Xwill start up in
  1877. X.I setup mode.
  1878. XThe tiles are represented by bitmaps and displayed to the right in the
  1879. X.I
  1880. Xtile window
  1881. Xof the application. They are positioned in two columns and in ranking
  1882. Xorder, starting at the flag and moving from the marshal beneath it via
  1883. Xthe general, colonel, major, captain, lieutenant, sergeant, miner,
  1884. Xscout and spy to the bomb. To the right of each tile is a counter
  1885. Xdisplaying the number of tiles of that type you still have to place on
  1886. Xthe board.
  1887. X.br
  1888. XYou can place a tile on the board by clicking on its bitmap in the
  1889. X.I
  1890. Xtile window
  1891. Xwith the left mouse button. Your cursor will change into the selected
  1892. Xtile. Place the cursor on the board position you want to put the tile
  1893. Xand click the left mouse button again. You can remove tiles from the
  1894. Xboard by clicking the left mouse button on the corresponding board
  1895. Xposition with a neutral cursor (see
  1896. X.I Cursor
  1897. Xbelow)
  1898. XClick
  1899. X.I Ready
  1900. Xif you have completed your setup. When your opponent has finished as
  1901. Xwell, both players will automatically enter
  1902. X.I
  1903. Xplay mode.
  1904. X.br
  1905. XThe buttons on the right hand side of your screen have the following
  1906. Xmeaning:
  1907. X.TP 15
  1908. X.B Cursor
  1909. XThis will reset your cursor to the
  1910. X.I neutral
  1911. Xcursor.
  1912. X.TP 15
  1913. X.B Clear
  1914. XClears your setup.
  1915. X.TP 15
  1916. X.B Load
  1917. XYou will be prompted for a filename which should contain a board setup.
  1918. XYour current setup will be replaced by the new one.
  1919. X.TP 15
  1920. X.B Store
  1921. XYou will be prompted for a filename in which you can save your
  1922. X(possibly incomplete) board setup.
  1923. X.TP 15
  1924. X.B Ready
  1925. XIf you have placed all your tiles on the board and want to start play
  1926. Xwith this setup then click
  1927. X.I Ready.
  1928. XAll you have to do now is wait for your opponent to do the same.
  1929. X.TP 15
  1930. X.B Quit
  1931. XIf you decide to chicken out.
  1932. X.TP 15
  1933. X.B Message
  1934. XWill give you an opportunity to send a message to your opponent.
  1935. X.sp
  1936. X.LP
  1937. XIf both players have completed their setup, the computer will decide
  1938. Xwho will go first. The
  1939. X.I
  1940. Xtile window
  1941. Xnow indicates how many tiles of each type your opponent has left. You
  1942. Xcan move a tile by clicking on it with the left mouse button. This tile
  1943. Xwill be redrawn in grey. Click again on the board position you want to
  1944. Xmove the tile to. The tile will be placed on the new position if the
  1945. Xmove was legal.
  1946. X.br
  1947. XYou can attack an enemy tile by clicking the tile you want to attack
  1948. Xwith first and then the enemy tile you want to attack. If the movement
  1949. Xis legal, you will be shown the value of the enemy tile and the losing
  1950. Xtile(s) will be taken off the board.
  1951. X.br
  1952. XWhen your opponent has made a move, you will be shown the results. The
  1953. Xtile that moved will be shown in grey at two places: at the position
  1954. Xwhere it came from and at the position where it moved to. Pressing any
  1955. Xmouse button at an arbitrary place in the application will complete the
  1956. Xmove.
  1957. X.br
  1958. XThe new buttons on the right hand side have the following meaning:
  1959. X.TP 15
  1960. X.B Remise
  1961. XThis will send a remise offer to your opponent. It can either be
  1962. Xaccepted or declined. You will be informed of the results.
  1963. X.TP 15
  1964. X.B
  1965. XGive Up
  1966. XFor losers only!
  1967. X.TP 15
  1968. X.B Message
  1969. XFor the diplomatic communication.
  1970. X.SH XSTRATEGO RESOURCES
  1971. XXstratego is build from the following components:
  1972. X.TP 15
  1973. X.B *Stratego
  1974. XToplevel form widget. Contains all other widgets.
  1975. X.TP 15
  1976. X.B *Stratego.Board
  1977. XForm widget with defaultDistance resource set to 1.
  1978. X.TP 15
  1979. X.B *Stratego.Board.BoardPosition
  1980. XIndividual command widgets that make up the board.
  1981. X.TP 15
  1982. X.B *Stratego.Board.Water
  1983. XCommand widgets that contain the water areas inside the board
  1984. X.TP 15
  1985. X.B *Stratego.Tiles
  1986. XThe
  1987. X.I
  1988. Xtile window
  1989. Xform widget that contains the tile positions.
  1990. X.TP 15
  1991. X.B *Stratego.Tiles.TilePosition
  1992. XBox widget container for tile bitmap and counter.
  1993. X.TP 15
  1994. X.B *Stratego.Tiles.TilePosition.TileBitmap
  1995. XCommand widget that contains the tile bitmap
  1996. X.TP 15
  1997. X.B *Stratego.Tiles.TilePosition.TileCount
  1998. XLabel widget displaying the counter associated with the tile.
  1999. X.TP 15
  2000. X.B *Stratego.Message
  2001. XLabel widget at the bottom of the board. Functions as message display
  2002. Xarea.
  2003. X.TP 15
  2004. X.B *Stratego.ButtonSet
  2005. XForm widget functioning as container for right hand side buttons.
  2006. X.TP 15
  2007. X.B *Stratego.ButtonSet.Button
  2008. XCommand widgets inside ButtonSet.
  2009. X.TP 15
  2010. X.B *PopupShell.Dialog
  2011. XDialogbox widget inside popup shell.
  2012. X.SH BUGS
  2013. XThere should be an option to save and restore a game.
  2014. X.SH AUTHOR
  2015. XMichiel Huisjes (huisjes@cs.vu.nl)
  2016. X.br
  2017. XI would like to thank Peter Valkenburg (valke@psy.vu.nl) without whom
  2018. Xthe random messages would be a lot less funny.
  2019. END_OF_FILE
  2020. if test 7526 -ne `wc -c <'xstratego.6'`; then
  2021.     echo shar: \"'xstratego.6'\" unpacked with wrong size!
  2022. fi
  2023. # end of 'xstratego.6'
  2024. fi
  2025. echo shar: End of archive 1 \(of 4\).
  2026. cp /dev/null ark1isdone
  2027. MISSING=""
  2028. for I in 1 2 3 4 ; do
  2029.     if test ! -f ark${I}isdone ; then
  2030.     MISSING="${MISSING} ${I}"
  2031.     fi
  2032. done
  2033. if test "${MISSING}" = "" ; then
  2034.     echo You have unpacked all 4 archives.
  2035.     rm -f ark[1-9]isdone
  2036. else
  2037.     echo You still need to unpack the following archives:
  2038.     echo "        " ${MISSING}
  2039. fi
  2040. ##  End of shell archive.
  2041. exit 0
  2042.