home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume13 / dominion / part25 < prev    next >
Encoding:
Internet Message Format  |  1992-02-10  |  60.8 KB

  1. Path: uunet!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v13i061:  dominion - a multi-player world simulation game, Part25/28
  5. Message-ID: <2464@masterCNA.TEK.COM>
  6. Date: 11 Feb 92 18:27:42 GMT
  7. Sender: news@masterCNA.TEK.COM
  8. Lines: 2060
  9. Approved: billr@saab.CNA.TEK.COM
  10.  
  11. Submitted-by: rosalia@dirac.physics.sunysb.edu (Mark Galassi)
  12. Posting-number: Volume 13, Issue 61
  13. Archive-name: dominion/Part25
  14. Environment: Unix, curses
  15.  
  16.  
  17.  
  18. #! /bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of archive 25 (of 28)."
  25. # Contents:  COPYING cinfo.c diplolib.c maglib.c root.c
  26. # Wrapped by billr@saab on Tue Feb 11 10:14:58 1992
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'COPYING' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'COPYING'\"
  30. else
  31. echo shar: Extracting \"'COPYING'\" \(12488 characters\)
  32. sed "s/^X//" >'COPYING' <<'END_OF_FILE'
  33. X
  34. X            GNU GENERAL PUBLIC LICENSE
  35. X             Version 1, February 1989
  36. X
  37. X Copyright (C) 1989 Free Software Foundation, Inc.
  38. X                    675 Mass Ave, Cambridge, MA 02139, USA
  39. X Everyone is permitted to copy and distribute verbatim copies
  40. X of this license document, but changing it is not allowed.
  41. X
  42. X                Preamble
  43. X
  44. X  The license agreements of most software companies try to keep users
  45. Xat the mercy of those companies.  By contrast, our General Public
  46. XLicense is intended to guarantee your freedom to share and change free
  47. Xsoftware--to make sure the software is free for all its users.  The
  48. XGeneral Public License applies to the Free Software Foundation's
  49. Xsoftware and to any other program whose authors commit to using it.
  50. XYou can use it for your programs, too.
  51. X
  52. X  When we speak of free software, we are referring to freedom, not
  53. Xprice.  Specifically, the General Public License is designed to make
  54. Xsure that you have the freedom to give away or sell copies of free
  55. Xsoftware, that you receive source code or can get it if you want it,
  56. Xthat you can change the software or use pieces of it in new free
  57. Xprograms; and that you know you can do these things.
  58. X
  59. X  To protect your rights, we need to make restrictions that forbid
  60. Xanyone to deny you these rights or to ask you to surrender the rights.
  61. XThese restrictions translate to certain responsibilities for you if you
  62. Xdistribute copies of the software, or if you modify it.
  63. X
  64. X  For example, if you distribute copies of a such a program, whether
  65. Xgratis or for a fee, you must give the recipients all the rights that
  66. Xyou have.  You must make sure that they, too, receive or can get the
  67. Xsource code.  And you must tell them their rights.
  68. X
  69. X  We protect your rights with two steps: (1) copyright the software, and
  70. X(2) offer you this license which gives you legal permission to copy,
  71. Xdistribute and/or modify the software.
  72. X
  73. X  Also, for each author's protection and ours, we want to make certain
  74. Xthat everyone understands that there is no warranty for this free
  75. Xsoftware.  If the software is modified by someone else and passed on, we
  76. Xwant its recipients to know that what they have is not the original, so
  77. Xthat any problems introduced by others will not reflect on the original
  78. Xauthors' reputations.
  79. X
  80. X  The precise terms and conditions for copying, distribution and
  81. Xmodification follow.
  82. X
  83. X            GNU GENERAL PUBLIC LICENSE
  84. X   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  85. X
  86. X  0. This License Agreement applies to any program or other work which
  87. Xcontains a notice placed by the copyright holder saying it may be
  88. Xdistributed under the terms of this General Public License.  The
  89. X"Program", below, refers to any such program or work, and a "work based
  90. Xon the Program" means either the Program or any work containing the
  91. XProgram or a portion of it, either verbatim or with modifications.  Each
  92. Xlicensee is addressed as "you".
  93. X
  94. X  1. You may copy and distribute verbatim copies of the Program's source
  95. Xcode as you receive it, in any medium, provided that you conspicuously and
  96. Xappropriately publish on each copy an appropriate copyright notice and
  97. Xdisclaimer of warranty; keep intact all the notices that refer to this
  98. XGeneral Public License and to the absence of any warranty; and give any
  99. Xother recipients of the Program a copy of this General Public License
  100. Xalong with the Program.  You may charge a fee for the physical act of
  101. Xtransferring a copy.
  102. X
  103. X  2. You may modify your copy or copies of the Program or any portion of
  104. Xit, and copy and distribute such modifications under the terms of Paragraph
  105. X1 above, provided that you also do the following:
  106. X
  107. X    a) cause the modified files to carry prominent notices stating that
  108. X    you changed the files and the date of any change; and
  109. X
  110. X    b) cause the whole of any work that you distribute or publish, that
  111. X    in whole or in part contains the Program or any part thereof, either
  112. X    with or without modifications, to be licensed at no charge to all
  113. X    third parties under the terms of this General Public License (except
  114. X    that you may choose to grant warranty protection to some or all
  115. X    third parties, at your option).
  116. X
  117. X    c) If the modified program normally reads commands interactively when
  118. X    run, you must cause it, when started running for such interactive use
  119. X    in the simplest and most usual way, to print or display an
  120. X    announcement including an appropriate copyright notice and a notice
  121. X    that there is no warranty (or else, saying that you provide a
  122. X    warranty) and that users may redistribute the program under these
  123. X    conditions, and telling the user how to view a copy of this General
  124. X    Public License.
  125. X
  126. X    d) You may charge a fee for the physical act of transferring a
  127. X    copy, and you may at your option offer warranty protection in
  128. X    exchange for a fee.
  129. X
  130. XMere aggregation of another independent work with the Program (or its
  131. Xderivative) on a volume of a storage or distribution medium does not bring
  132. Xthe other work under the scope of these terms.
  133. X
  134. X  3. You may copy and distribute the Program (or a portion or derivative of
  135. Xit, under Paragraph 2) in object code or executable form under the terms of
  136. XParagraphs 1 and 2 above provided that you also do one of the following:
  137. X
  138. X    a) accompany it with the complete corresponding machine-readable
  139. X    source code, which must be distributed under the terms of
  140. X    Paragraphs 1 and 2 above; or,
  141. X
  142. X    b) accompany it with a written offer, valid for at least three
  143. X    years, to give any third party free (except for a nominal charge
  144. X    for the cost of distribution) a complete machine-readable copy of the
  145. X    corresponding source code, to be distributed under the terms of
  146. X    Paragraphs 1 and 2 above; or,
  147. X
  148. X    c) accompany it with the information you received as to where the
  149. X    corresponding source code may be obtained.  (This alternative is
  150. X    allowed only for noncommercial distribution and only if you
  151. X    received the program in object code or executable form alone.)
  152. X
  153. XSource code for a work means the preferred form of the work for making
  154. Xmodifications to it.  For an executable file, complete source code means
  155. Xall the source code for all modules it contains; but, as a special
  156. Xexception, it need not include source code for modules which are standard
  157. Xlibraries that accompany the operating system on which the executable
  158. Xfile runs, or for standard header files or definitions files that
  159. Xaccompany that operating system.
  160. X
  161. X  4. You may not copy, modify, sublicense, distribute or transfer the
  162. XProgram except as expressly provided under this General Public License.
  163. XAny attempt otherwise to copy, modify, sublicense, distribute or transfer
  164. Xthe Program is void, and will automatically terminate your rights to use
  165. Xthe Program under this License.  However, parties who have received
  166. Xcopies, or rights to use copies, from you under this General Public
  167. XLicense will not have their licenses terminated so long as such parties
  168. Xremain in full compliance.
  169. X
  170. X  5. By copying, distributing or modifying the Program (or any work based
  171. Xon the Program) you indicate your acceptance of this license to do so,
  172. Xand all its terms and conditions.
  173. X
  174. X  6. Each time you redistribute the Program (or any work based on the
  175. XProgram), the recipient automatically receives a license from the original
  176. Xlicensor to copy, distribute or modify the Program subject to these
  177. Xterms and conditions.  You may not impose any further restrictions on the
  178. Xrecipients' exercise of the rights granted herein.
  179. X
  180. X  7. The Free Software Foundation may publish revised and/or new versions
  181. Xof the General Public License from time to time.  Such new versions will
  182. Xbe similar in spirit to the present version, but may differ in detail to
  183. Xaddress new problems or concerns.
  184. X
  185. XEach version is given a distinguishing version number.  If the Program
  186. Xspecifies a version number of the license which applies to it and "any
  187. Xlater version", you have the option of following the terms and conditions
  188. Xeither of that version or of any later version published by the Free
  189. XSoftware Foundation.  If the Program does not specify a version number of
  190. Xthe license, you may choose any version ever published by the Free Software
  191. XFoundation.
  192. X
  193. X  8. If you wish to incorporate parts of the Program into other free
  194. Xprograms whose distribution conditions are different, write to the author
  195. Xto ask for permission.  For software which is copyrighted by the Free
  196. XSoftware Foundation, write to the Free Software Foundation; we sometimes
  197. Xmake exceptions for this.  Our decision will be guided by the two goals
  198. Xof preserving the free status of all derivatives of our free software and
  199. Xof promoting the sharing and reuse of software generally.
  200. X
  201. X                NO WARRANTY
  202. X
  203. X  9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  204. XFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
  205. XOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
  206. XPROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
  207. XOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  208. XMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
  209. XTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
  210. XPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
  211. XREPAIR OR CORRECTION.
  212. X
  213. X  10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  214. XWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  215. XREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  216. XINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
  217. XOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
  218. XTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  219. XYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  220. XPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  221. XPOSSIBILITY OF SUCH DAMAGES.
  222. X
  223. X             END OF TERMS AND CONDITIONS
  224. X
  225. X    Appendix: How to Apply These Terms to Your New Programs
  226. X
  227. X  If you develop a new program, and you want it to be of the greatest
  228. Xpossible use to humanity, the best way to achieve this is to make it
  229. Xfree software which everyone can redistribute and change under these
  230. Xterms.
  231. X
  232. X  To do so, attach the following notices to the program.  It is safest to
  233. Xattach them to the start of each source file to most effectively convey
  234. Xthe exclusion of warranty; and each file should have at least the
  235. X"copyright" line and a pointer to where the full notice is found.
  236. X
  237. X    <one line to give the program's name and a brief idea of what it does.>
  238. X    Copyright (C) 19yy  <name of author>
  239. X
  240. X    This program is free software; you can redistribute it and/or modify
  241. X    it under the terms of the GNU General Public License as published by
  242. X    the Free Software Foundation; either version 1, or (at your option)
  243. X    any later version.
  244. X
  245. X    This program is distributed in the hope that it will be useful,
  246. X    but WITHOUT ANY WARRANTY; without even the implied warranty of
  247. X    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  248. X    GNU General Public License for more details.
  249. X
  250. X    You should have received a copy of the GNU General Public License
  251. X    along with this program; if not, write to the Free Software
  252. X    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  253. X
  254. XAlso add information on how to contact you by electronic and paper mail.
  255. X
  256. XIf the program is interactive, make it output a short notice like this
  257. Xwhen it starts in an interactive mode:
  258. X
  259. X    Gnomovision version 69, Copyright (C) 19xx name of author
  260. X    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
  261. X    This is free software, and you are welcome to redistribute it
  262. X    under certain conditions; type `show c' for details.
  263. X
  264. XThe hypothetical commands `show w' and `show c' should show the
  265. Xappropriate parts of the General Public License.  Of course, the
  266. Xcommands you use may be called something other than `show w' and `show
  267. Xc'; they could even be mouse-clicks or menu items--whatever suits your
  268. Xprogram.
  269. X
  270. XYou should also get your employer (if you work as a programmer) or your
  271. Xschool, if any, to sign a "copyright disclaimer" for the program, if
  272. Xnecessary.  Here a sample; alter the names:
  273. X
  274. X  Yoyodyne, Inc., hereby disclaims all copyright interest in the
  275. X  program `Gnomovision' (a program to direct compilers to make passes
  276. X  at assemblers) written by James Hacker.
  277. X
  278. X  <signature of Ty Coon>, 1 April 1989
  279. X  Ty Coon, President of Vice
  280. X
  281. XThat's all there is to it!
  282. END_OF_FILE
  283. if test 12488 -ne `wc -c <'COPYING'`; then
  284.     echo shar: \"'COPYING'\" unpacked with wrong size!
  285. fi
  286. # end of 'COPYING'
  287. fi
  288. if test -f 'cinfo.c' -a "${1}" != "-c" ; then 
  289.   echo shar: Will not clobber existing file \"'cinfo.c'\"
  290. else
  291. echo shar: Extracting \"'cinfo.c'\" \(12038 characters\)
  292. sed "s/^X//" >'cinfo.c' <<'END_OF_FILE'
  293. X  /* cinfo.c  --  curses-based info browsing utility/library */
  294. X
  295. X/*
  296. X * Copyright (C) 1990 Free Software Foundation, Inc.
  297. X * Written by Mark Galassi.
  298. X *
  299. X * This file is part of cinfo.
  300. X *
  301. X * cinfo is free software; you can redistribute it and/or
  302. X * modify it under the terms of the GNU General Public License as published
  303. X * by the Free Software Foundation; either version 1, or (at your option)
  304. X * any later version.
  305. X *
  306. X * This software is distributed in the hope that it will be useful,
  307. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  308. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  309. X * GNU General Public License for more details.
  310. X *
  311. X * You should have received a copy of the GNU General Public License
  312. X * along with this software; see the file COPYING.  If not, write to
  313. X * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  314. X */
  315. X
  316. X#include <stdio.h>
  317. X#include <curses.h>
  318. X#ifdef SYSV
  319. X# include <string.h>
  320. X#else
  321. X# include <strings.h>
  322. X#endif /* SYSV */
  323. X
  324. X/* some systems already have strstr() */
  325. X/* #define HAVE_STRSTR */
  326. X
  327. X#define LINE_LEN 80        /* longer than this is truncated */
  328. X  /* this is defined in the Makefile */
  329. X/* #define STANDALONE        /* if we run standalone... */
  330. X#define INFO_PATH "/usr/local/lib/emacs/info"
  331. X#ifndef INFO_INTRO
  332. X# define INFO_INTRO "/usr/local/lib/info_intro"
  333. X#endif /* INFO_INTRO */
  334. X#define INFO_CHAR 0x1F        /* ^_, used to specify an info line */
  335. X#define DEL 0x7F        /* DELETE character */
  336. X
  337. X  /* global variables */
  338. X
  339. X  /* current node fields */
  340. Xchar node[LINE_LEN], node_prev[LINE_LEN],
  341. X  node_next[LINE_LEN], node_up[LINE_LEN];
  342. X
  343. X  /* seek pointer in info file where the tag table is */
  344. Xlong tag_table_pos = 0;
  345. X
  346. X  /* this tells us that we must show a new page */
  347. Xint update_info_page = 1;
  348. X
  349. X  /* main routine if this program is run standalone.  Otherwise,
  350. X     the cinfo() routine can be called from anywhere.
  351. X   */
  352. X#ifdef STANDALONE
  353. Xmain(argc, argv)
  354. X     int argc;
  355. X     char *argv[];
  356. X{
  357. X  switch (argc) {
  358. X  case 2:
  359. X    cinfo(argv[1], "Top");
  360. X    break;
  361. X  case 3:
  362. X    cinfo(argv[1], argv[2]);
  363. X    break;
  364. X  default:
  365. X    printf("Useage: %s filename [tag]\n", argv[0]);
  366. X    clean_exit();
  367. X    exit(1);
  368. X  }
  369. X  clean_exit();
  370. X  exit(0);
  371. X}
  372. Xclean_exit(){};
  373. X
  374. X#endif /* STANDALONE */
  375. X
  376. Xstatic WINDOW *infow;        /* screen-size window in which it happens */
  377. X
  378. X  /* run curses-based info browsing.
  379. X     fname: name of info file
  380. X     tag:   topic we should try to search for
  381. X   */
  382. Xcinfo(fname, tag)
  383. X     char fname[], tag[];
  384. X{
  385. X  char item[LINE_LEN];
  386. X  int done = 0;            /* for the input loop */
  387. X  long old_pos;
  388. X  char c;
  389. X  FILE *fp, *intro_fp, *find_info_file();
  390. X
  391. X    /* open up the info file */
  392. X  fp = find_info_file(fname);
  393. X  find_tag_table(fp);
  394. X  if ((intro_fp = fopen(INFO_INTRO, "r")) == NULL) {
  395. X    printf("Cannot open info file %s, exiting.\n", INFO_INTRO);
  396. X    clean_exit();
  397. X    exit(1);
  398. X  }
  399. X  cinfo_init_screen();
  400. X    /* if they start at top level, give them the help screen */
  401. X  if (strcmp(tag, "Top") == 0) {
  402. X    cinfo_intro_screen(intro_fp, infow);
  403. X  }
  404. X
  405. X  find_menu_item(fp, tag);
  406. X  parse_info_line(fp);        /* make sure we have the current line parsed */
  407. X/*  wclear(infow); */
  408. X
  409. X  while (!done) {
  410. X    old_pos = ftell(fp);    /* before this page is shown */
  411. X    if (show_page(fp, infow) == -1) {
  412. X      /* means that we ran into a new info line */
  413. X      parse_info_line(fp);
  414. X    }
  415. X    cinfo_statline("(SPACE, DEL/BS, m, n, p, u, q, ?)");
  416. X    switch (wgetch(infow)) {
  417. X    case ' ':
  418. X      update_info_page = 1;
  419. X      break;
  420. X    case DEL:            /* should go back a screen */
  421. X    case '\b':
  422. X      break;
  423. X    case 'm':            /* let user choose a tag */
  424. X      if (prompt(item) != -1) {    /* did they type something? */
  425. X    fseek(fp, old_pos, 0);    /* in case find_menu_item does not work */
  426. X    find_menu_item(fp, item);
  427. X    parse_info_line(fp);    /* make sure we have the current line parsed */
  428. X    update_info_page = 1;
  429. X      }
  430. X      break;
  431. X    case 'n':
  432. X      if (strlen(node_next) > 0) {
  433. X    find_menu_item(fp, node_next);
  434. X    parse_info_line(fp);
  435. X      }
  436. X      update_info_page = 1;
  437. X      break;
  438. X    case 'p':
  439. X      if (strlen(node_prev) > 0) {
  440. X    find_menu_item(fp, node_prev);
  441. X    parse_info_line(fp);
  442. X      }
  443. X      update_info_page = 1;
  444. X      break;
  445. X    case 'u':
  446. X      if (strlen(node_up) > 0) {
  447. X    find_menu_item(fp, node_up);
  448. X    parse_info_line(fp);
  449. X      }
  450. X      break;
  451. X    case 'q':
  452. X      done = 1;
  453. X      break;
  454. X    case '?':
  455. X      cinfo_intro_screen(intro_fp, infow);
  456. X      wclear(infow);
  457. X      update_info_page = 1;
  458. X      break;
  459. X    default:
  460. X      fseek(fp, old_pos, 0);
  461. X      break;
  462. X    }
  463. X  }
  464. X  fclose(fp);
  465. X  fclose(intro_fp);
  466. X  cinfo_cleanup();
  467. X}
  468. X
  469. X  /* prepare the screen */
  470. Xcinfo_init_screen()
  471. X{
  472. X#ifdef STANDALONE
  473. X  printf("initializing screen...\r\n");
  474. X  initscr();
  475. X  savetty();
  476. X  nonl();
  477. X  cbreak();
  478. X  noecho();
  479. X#endif /* STANDALONE */
  480. X    /* prepare a full-size window to work in */
  481. X  infow = newwin(LINES, COLS, 0, 0);
  482. X  wclear(infow);
  483. X  wmove(infow, 0, 0);
  484. X  wrefresh(infow);
  485. X}
  486. X
  487. X  /* clean up curses, if necessary, and free memory */
  488. Xcinfo_cleanup()
  489. X{
  490. X  wclear(infow);
  491. X  wrefresh(infow);
  492. X  delwin(infow);
  493. X#ifdef STANDALONE
  494. X  resetty();
  495. X  endwin();
  496. X#endif /* STANDALONE */
  497. X}
  498. X
  499. X  /* shows the introductory page and waits for a key hit */
  500. Xcinfo_intro_screen(intro_fp, infow)
  501. X     FILE *intro_fp;
  502. X     WINDOW *infow;
  503. X{
  504. X  char line[2*LINE_LEN];
  505. X  int n = 0;
  506. X
  507. X  wclear(infow);
  508. X  rewind(intro_fp);
  509. X  while (fgets(line, 2*LINE_LEN, intro_fp) != NULL) {
  510. X    line[LINE_LEN-1] = '\0';    /* truncate it */
  511. X    mvwaddstr(infow, n, 0, line);
  512. X    wclrtoeol(infow);
  513. X    wrefresh(infow);
  514. X    ++n;
  515. X  }
  516. X  wgetch(infow);
  517. X}
  518. X
  519. X  /* shows the given string at the bottom of the page */
  520. Xcinfo_statline(s)
  521. X     char s[];
  522. X{
  523. X  wmove(infow, LINES-1, 0);
  524. X  waddstr(infow, s);
  525. X  wclrtoeol(infow);
  526. X  wrefresh(infow);
  527. X}
  528. X
  529. Xcinfo_statline2()
  530. X{
  531. X  wmove(infow, LINES-2, 0);
  532. X  wstandout(infow);
  533. X  wprintw(infow ,"%s", node);
  534. X  wstandend(infow);
  535. X  wprintw(infow, ", p: %s, u: %s, n: %s", node_prev, node_up, node_next);
  536. X  wclrtoeol(infow);
  537. X  wrefresh(infow);
  538. X}
  539. X
  540. X  /* this is kind of the guts of it:
  541. X     setting the file pointer to a menu item.
  542. X     this function also returns the seek pointer
  543. X   */
  544. Xfind_menu_item(fp, tag)
  545. X     FILE *fp;
  546. X     char tag[];
  547. X{
  548. X  long old_pos = ftell(fp), pos;
  549. X  char line[2*LINE_LEN], s[LINE_LEN], item[LINE_LEN];
  550. X#ifndef HAVE_STRSTR
  551. X#ifdef __STDC__
  552. X  extern char *strstr(char *, char *);
  553. X#else /* STDC */
  554. X  extern char *strstr();
  555. X#endif /* STDC */
  556. X#endif /* HAVE_STRSTR */
  557. X
  558. X  fseek(fp, tag_table_pos, 0);
  559. X    /* prepare a scanning format string */
  560. X  sprintf(s, "Node: %%[-A-Z a-z0-9_`\']");
  561. X  while (1) {
  562. X    if ((fgets(line, 2*LINE_LEN, fp) == NULL) || (sscanf(line, s, item) < 0)) {
  563. X      fseek(fp, old_pos, 0);
  564. X      return old_pos;
  565. X    }
  566. X      /* now convert all to lower case */
  567. X    str_lower(item);
  568. X    str_lower(tag);
  569. X    if (strncmp(item, tag, strlen(tag)) == 0) {
  570. X        /* ugly kludge, but scanf seems to not do what I want */
  571. X      sscanf(line+strlen("Node: ")+strlen(item)+1, "%ld", &pos);
  572. X      fseek(fp, pos-1, 0);
  573. X      return pos;
  574. X    }
  575. X  }
  576. X}
  577. X
  578. X  /* this function is essential:
  579. X     it sets the node[], node_prev[], node_next[] and node_up[] strings
  580. X   */
  581. Xparse_info_line(fp)
  582. X     FILE *fp;
  583. X{
  584. X  char line[2*LINE_LEN];
  585. X  long old_pos = ftell(fp);
  586. X  char *ptr;
  587. X  int n;
  588. X
  589. X  fgets(line, 2*LINE_LEN, fp);
  590. X    /* we can only parse it if it is really a node line */
  591. X  if (strncmp(line, "File:", strlen("File:")) != 0) {
  592. X    fseek(fp, old_pos, 0);
  593. X    return -1;
  594. X  }
  595. X#define BAD_HACK
  596. X#ifdef BAD_HACK
  597. X    /* now I play funny pointer games to parse
  598. X       this line.  I assume that strstr() returns NULL
  599. X       if the second string is not a substring of the
  600. X       first.
  601. X     */
  602. X  if (ptr = strstr(line, "Node: ")) {
  603. X    n = (int) ((long) strchr(ptr, ',') - (long) ptr - strlen("Node: "));
  604. X    strncpy(node, ptr+strlen("Node: "), n);
  605. X    node[n] = '\0';
  606. X  } else {            /* field is not there */
  607. X    strcpy(node, "");
  608. X  }
  609. X
  610. X  if (ptr = strstr(line, "Prev: ")) {
  611. X    n = (int) ((long) strchr(ptr, ',') - (long) ptr - strlen("Prev: "));
  612. X    strncpy(node_prev, ptr+strlen("Prev: "), n);
  613. X    node_prev[n] = '\0';
  614. X  } else {            /* field is not there */
  615. X    strcpy(node_prev, "");
  616. X  }
  617. X
  618. X  if (ptr = strstr(line, "Up: ")) {
  619. X    n = (int) ((long) strchr(ptr, ',') - (long) ptr - strlen("Up: "));
  620. X    strncpy(node_up, ptr+strlen("Up: "), n);
  621. X    node_up[n] = '\0';
  622. X  } else {            /* field is not there */
  623. X    strcpy(node_up, "");
  624. X  }
  625. X
  626. X    /* this last one is easier, because it is
  627. X       the last field in an info line.  but
  628. X       remember to remove the newline.
  629. X     */
  630. X  if (ptr = strstr(line, "Next: ")) {
  631. X    strcpy(node_next, ptr+strlen("Next: "));
  632. X    node_next[strlen(node_next)-1] = '\0';
  633. X  } else {            /* field is not there */
  634. X    strcpy(node_next, "");
  635. X  }
  636. X
  637. X#endif /* BAD HACK */
  638. X  fseek(fp, old_pos, 0);    /* go back to where we were */
  639. X  return 1;
  640. X}
  641. X
  642. X  /* this is also an essential function:
  643. X     it shows the current information page
  644. X   */
  645. Xshow_page(fp, infow)
  646. X     FILE *fp;
  647. X     WINDOW *infow;
  648. X{
  649. X  int n = 0;            /* line counter */
  650. X  char line[2*LINE_LEN];
  651. X
  652. X  if (!update_info_page) {    /* do we need to redraw? */
  653. X    return 0;
  654. X  }
  655. X  update_info_page = 0;
  656. X  wclear(infow);
  657. X  for (n = 0; n < LINES-2; ++n) {
  658. X    fgets(line, 2*LINE_LEN, fp);
  659. X    line[LINE_LEN-1] = '\0';    /* truncate it */
  660. X      /* stop if you get to a new info format entry */
  661. X    if (line[0] == INFO_CHAR) {
  662. X      cinfo_statline2();
  663. X      return -1;
  664. X    } else {
  665. X      mvwaddstr(infow, n, 0, line);
  666. X      wclrtoeol(infow);
  667. X      wrefresh(infow);
  668. X    }
  669. X  }
  670. X  cinfo_statline2();
  671. X  return 1;
  672. X}
  673. X
  674. X  /* prompt the user for a tag; return -1 if there is no input */
  675. Xprompt(item)
  676. X     char item[];
  677. X{
  678. X  int ret;
  679. X
  680. X  echo();
  681. X  nocbreak();
  682. X  cinfo_statline("Enter your menu choice: ");
  683. X  ret = wscanw(infow, "%[^\n]", item);
  684. X  cbreak();
  685. X  noecho();
  686. X  if (ret <= 0) {
  687. X    return -1;
  688. X  }
  689. X  return 1;
  690. X}
  691. X
  692. X  /* called at the start, this finds the location of the tag table */
  693. Xfind_tag_table(fp)
  694. X     FILE *fp;
  695. X{
  696. X  char line[2*LINE_LEN];
  697. X  long pos;
  698. X
  699. X  while (1) {
  700. X    pos = ftell(fp);
  701. X    if (fgets(line, 2*LINE_LEN, fp) == NULL) {
  702. X      break;
  703. X    }
  704. X    if (line[0] == INFO_CHAR) {
  705. X      fgets(line, 2*LINE_LEN, fp);
  706. X      if (strncmp(line, "Tag table:", strlen("Tag table:")) == 0) {
  707. X    tag_table_pos = ftell(fp); /* got it!!! */
  708. X    break;
  709. X      }
  710. X    }
  711. X  }
  712. X}
  713. X
  714. X  /* converts a string to lower case */
  715. Xstr_lower(s)
  716. X     char s[];
  717. X{
  718. X  while (*s) {
  719. X    if (*s >= 'A' && *s <= 'Z') { /* is it upper case? */
  720. X      *s = *s - ('A' - 'a');    /* if so, convert */
  721. X    }
  722. X    ++s;
  723. X  }
  724. X}
  725. X
  726. X  /* tries to find and fopen() the .info file in a variety
  727. X     of paths.  returns the file pointer or exits.
  728. X   */
  729. XFILE *find_info_file(fname)
  730. X     char fname[];
  731. X{
  732. X  char full_fname[LINE_LEN];
  733. X  FILE *fp, *fopen();
  734. X
  735. X    /* try several file names, see if one of them works */
  736. X  if ((fp = fopen(fname, "r")) == NULL) {
  737. X    strcpy(full_fname, fname);
  738. X    strcat(full_fname, ".info");    /* try it with a ".info" */
  739. X    if ((fp = fopen(full_fname, "r")) == NULL) {
  740. X      strcpy(full_fname, INFO_PATH);
  741. X      strcat(full_fname, "/");
  742. X      strcat(full_fname, fname);
  743. X      if ((fp = fopen(full_fname, "r")) == NULL) {
  744. X    strcat(full_fname, ".info");
  745. X    if ((fp = fopen(full_fname, "r")) == NULL) {
  746. X      printf("Cannot open file %s or %s, exiting.\n", fname, full_fname);
  747. X          clean_exit();
  748. X      exit(1);
  749. X    }
  750. X      }
  751. X    }
  752. X  }
  753. X  return fp;
  754. X}
  755. X
  756. X
  757. X#ifndef HAVE_STRSTR
  758. X
  759. X  /* System V has strstr(), which is useful, but bsd
  760. X     does not.  This is a replacement for strstr that
  761. X     should make up for that.  The algorithm is a
  762. X     total hack, and probably not too fast.
  763. X   */
  764. X  /* strstr() returns a pointer to the first occurrence of
  765. X     s2 inside s1.  A generalization of index() or strchr().
  766. X     strstr() returns NULL if s2 is not a substring of s1.
  767. X   */
  768. Xchar *
  769. Xstrstr(s1, s2)
  770. X     char *s1, *s2;
  771. X{
  772. X  char *p = NULL;        /* what we are looking for */
  773. X  char *s;
  774. X  int n = strlen(s2);
  775. X
  776. X    /* run through s1, and see if at any point s2 appears */
  777. X  for (s = s1; *s != '\0'; ++s) {
  778. X    if (strncmp(s, s2, n) == 0) {
  779. X      p = s;            /* we found it!!! */
  780. X      break;
  781. X    }
  782. X  }
  783. X  return p;
  784. X}
  785. X
  786. X#endif /* HAVE_STRSTR */
  787. END_OF_FILE
  788. if test 12038 -ne `wc -c <'cinfo.c'`; then
  789.     echo shar: \"'cinfo.c'\" unpacked with wrong size!
  790. fi
  791. # end of 'cinfo.c'
  792. fi
  793. if test -f 'diplolib.c' -a "${1}" != "-c" ; then 
  794.   echo shar: Will not clobber existing file \"'diplolib.c'\"
  795. else
  796. echo shar: Extracting \"'diplolib.c'\" \(11937 characters\)
  797. sed "s/^X//" >'diplolib.c' <<'END_OF_FILE'
  798. X/* diplolib.c -- basic, non-visual diplomacy routines */
  799. X
  800. X/*
  801. X * Copyright (C) 1990 Free Software Foundation, Inc.
  802. X * Written by the dominion project.
  803. X *
  804. X * This file is part of dominion.
  805. X *
  806. X * dominion is free software; you can redistribute it and/or
  807. X * modify it under the terms of the GNU General Public License as published
  808. X * by the Free Software Foundation; either version 1, or (at your option)
  809. X * any later version.
  810. X *
  811. X * This software is distributed in the hope that it will be useful,
  812. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  813. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  814. X * GNU General Public License for more details.
  815. X *
  816. X * You should have received a copy of the GNU General Public License
  817. X * along with this software; see the file COPYING.  If not, write to
  818. X * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  819. X */
  820. X
  821. X/* what follows here is a list of ALL routines in this file and
  822. X   a one-line blurb stating what it does......
  823. X*/
  824. X
  825. X/* allocate_diplo(n): allocates space for a new diplomacy matrix */
  826. X/* init_diplo(n): initializes diplo matrix of size n */
  827. X/* increase_diplo(dm_old, dm_new, n, np): used when new nations are added */
  828. X/* read_in_diplo(dm, n): reads in current diplo matrix from file */
  829. X/* read_initial_diplo(dm, n): reads beginning-of-turn diplomacy in */
  830. X/* dump_diplo(np, dm, n): dumps new diplo information to a file */
  831. X/* update_diplo(): called by dominionupdate to update newly met nations */
  832. X/* have_met(dm, nation1, nation2): returns true if nation 1 and 2 have met */
  833. X/* get_indices(dm, nation1, nation2, n1, n2): takes ids, gives indices in dm */
  834. X/* handle_meet(dm, nation1, nation2): actually changes from UNMET to NEUTRAL */
  835. X/* get_diplo_status(dm, nation1, nation2): will return the status of n1 to n2*/
  836. X/* set_diplo_status(dm, nation1, nation2, New_Status): changes status */
  837. X/* are_allied(nation1, nation2): returns 1 if they are allied */
  838. X/* lock_diplo(np): lock the diplomacy file */
  839. X/* unlock_diplo(): unlock the diplomacy file */
  840. X/* diplo_is_locked(): see if the diplo file is locked */
  841. X
  842. X#include "dominion.h"
  843. X#include "misc.h"
  844. X#include <stdio.h>
  845. X
  846. Xextern Sworld world;
  847. Xextern int (*wrapx)(), (*wrapy)();
  848. X
  849. X/* */
  850. X/* allocate_diplo(): allocates space for a new diplomacy matrix */
  851. X/* */
  852. X
  853. XSdiplo **allocate_diplo(n)
  854. X     int n;            /* number of nations */
  855. X{
  856. X  int i;
  857. X  Sdiplo **dm;
  858. X
  859. X  dm = (Sdiplo **) malloc(n*sizeof(Sdiplo *));
  860. X  for (i = 0; i < n; ++i) {
  861. X    dm[i] = (Sdiplo *) malloc(n*sizeof(Sdiplo));
  862. X  }
  863. X  return dm;
  864. X}
  865. X
  866. X/* */
  867. X/* initializes a diplomacy data structure at the beginning
  868. X   of the game, when there is no file, and all nations are unmet! */
  869. X/* */
  870. X
  871. Xinit_diplo(n)
  872. X     int n;            /* number of nations */
  873. X{
  874. X  Sdiplo **dm;
  875. X  int i, j;
  876. X  FILE *fp, *fopen();
  877. X
  878. X  dm = allocate_diplo(n);
  879. X
  880. X  for (i = 0; i < n; ++i) {
  881. X    for (j = 0; j < n; ++j) {
  882. X      dm[i][j].status = UNMET;
  883. X      dm[i][j].self_id = world.nations[i].id;
  884. X      dm[i][j].neighbor_id = world.nations[j].id;
  885. X    }
  886. X    dm[i][i].status = SELF;
  887. X  }
  888. X
  889. X  if ((fp = fopen(DIPLO_FILE, "w")) == NULL) {
  890. X    printf("sorry, cannot open file %s for writing\n", DIPLO_FILE);
  891. X    return -1;
  892. X  }
  893. X  critical();
  894. X  for (i = 0; i < n; ++i) {
  895. X    fwrite(dm[i], n*sizeof(Sdiplo), 1, fp);
  896. X  }
  897. X  fclose(fp);
  898. X  noncritical();
  899. X}
  900. X
  901. X/* increase_diplo(): Called when a nation has been added to world.
  902. X     take a diplo matrix, and add a new blank entry to it.
  903. X     assume that dm_old and dm_new both have storage */
  904. X
  905. Xincrease_diplo(dm_old, dm_new, n, np)
  906. X     Sdiplo **dm_old, **dm_new;
  907. X     int n;            /* number of nations *before* increase */
  908. X     Snation *np;
  909. X{
  910. X  int i, j;
  911. X
  912. X    /* first copy the old stuff */
  913. X  for (i = 0; i < n; ++i) {
  914. X    for (j = 0; j < n; ++j) {
  915. X      dm_new[i][j] = dm_old[i][j];
  916. X    }
  917. X  }
  918. X    /* then put defaults for the new stuff */
  919. X  for (i = 0; i <= n; ++i) {
  920. X    dm_new[n][i].status = UNMET;
  921. X    dm_new[n][i].self_id = np->id;  /* was world.nations[i].id */
  922. X    dm_new[n][i].neighbor_id = world.nations[i].id;
  923. X      /* now do the transpose */
  924. X    dm_new[i][n].status = UNMET;
  925. X    dm_new[i][n].self_id = world.nations[i].id;
  926. X    dm_new[i][n].neighbor_id = np->id; /* was world.nations[n].id */
  927. X  }
  928. X  dm_new[n][n].status = SELF;
  929. X}
  930. X
  931. X
  932. X  /* reads information into the diplomacy file */
  933. Xread_in_diplo(dm, n)
  934. X     Sdiplo **dm;
  935. X     int n;            /* number of nations */
  936. X{
  937. X  int i;
  938. X  FILE *dfp, *fopen();
  939. X
  940. X  if ((dfp = fopen(DIPLO_FILE, "r")) == NULL) {
  941. X    return -1;
  942. X  }
  943. X
  944. X  for (i = 0; i < n; ++i) {
  945. X    fread(dm[i], n*sizeof(Sdiplo), 1, dfp);
  946. X  }
  947. X  fclose(dfp);
  948. X  return 1;
  949. X}
  950. X
  951. X/* This reads in the diplomacy matrix as it was at the beginning of
  952. X   the turn.  It is important to do this, because the software must
  953. X   know if the user is changing diplomacy by more than 2 levels.
  954. X */
  955. Xread_initial_diplo(dm, n)
  956. X     Sdiplo **dm;
  957. X     int n;            /* number of nations */
  958. X{
  959. X  int i;
  960. X  FILE *dfp, *fopen();
  961. X
  962. X  if ((dfp = fopen(INIT_DIPLO_FILE, "r")) == NULL) {
  963. X    return -1;
  964. X  }
  965. X
  966. X  for (i = 0; i < n; ++i) {
  967. X    fread(dm[i], n*sizeof(Sdiplo), 1, dfp);
  968. X  }
  969. X  fclose(dfp);
  970. X}
  971. X
  972. X  /* dumps the data structure to the diplomacy file. */
  973. Xdump_diplo(np, dm, n)
  974. X     Snation *np;        /* the nation that is writing (if any) */
  975. X     Sdiplo **dm;
  976. X     int n;
  977. X{
  978. X  FILE *dfp, *fopen();
  979. X  int i;
  980. X
  981. X  if ((dfp = fopen(DIPLO_FILE, "w")) == NULL) {
  982. X    return -1;
  983. X  }
  984. X  critical();
  985. X  lock_diplo(np);
  986. X  for (i = 0; i < n; ++i) {
  987. X    fwrite(dm[i], n*sizeof(Sdiplo), 1, dfp);
  988. X  }
  989. X  fclose(dfp);
  990. X  noncritical();
  991. X  unlock_diplo();
  992. X}
  993. X
  994. X
  995. X/* update_diplo(): called by the update routine so that when two
  996. X     nations have met, they will have their status changed from UNMET
  997. X     to NEUTRAL.  */
  998. X
  999. Xupdate_diplo()
  1000. X{
  1001. X  Sdiplo **dm;
  1002. X  struct pt_list *plist;
  1003. X  Sarmy *army_ptr;
  1004. X  struct armyid *sect_alist;
  1005. X  Ssector *sect_ptr;
  1006. X  Snation *cn;
  1007. X  int x,y, i,j, k, cn_id;
  1008. X  FILE *fp, *fopen();
  1009. X  char cmd_str[PATHLEN];
  1010. X
  1011. X/*   printf("updating diplomacy\n"); */
  1012. X  dm = allocate_diplo(world.n_nations);
  1013. X  read_in_diplo(dm, world.n_nations);
  1014. X
  1015. X  for (k = 1; k < world.n_nations; ++k) {   /* to run through all nations */
  1016. X    cn = &world.nations[k];        /* current nation */
  1017. X    cn_id = world.nations[k].id;  /* current nation id */
  1018. X
  1019. X    for (plist = cn->ptlist; plist != NULL; plist = plist->next){
  1020. X      x = plist->pt.x;
  1021. X      y = plist->pt.y;
  1022. X      for(i= x-LAND_SIGHT; i <= x+LAND_SIGHT; ++i) {
  1023. X    for(j= y-LAND_SIGHT; j <= y+LAND_SIGHT; ++j) {
  1024. X        /* unowned */
  1025. X      if ((world.map[(*wrapx)(i,j)][(*wrapy)(i,j)].owner != 0) &&
  1026. X              (world.map[(*wrapx)(i,j)][(*wrapy)(i,j)].owner != cn_id)) {
  1027. X        handle_meet(dm, cn_id,
  1028. X            world.map[(*wrapx)(i,j)][(*wrapy)(i,j)].owner);
  1029. X      }
  1030. X    }
  1031. X      }
  1032. X    }
  1033. X    for (army_ptr = cn->armies; army_ptr != NULL; army_ptr = army_ptr->next){
  1034. X      x = army_ptr->pos.x;
  1035. X      y = army_ptr->pos.y;
  1036. X      for(i= x-ARMY_SIGHT; i <= x+ARMY_SIGHT; ++i) {
  1037. X    for(j= y-ARMY_SIGHT; j <= y+ARMY_SIGHT; ++j) {
  1038. X      sect_ptr = &world.map[(*wrapx)(i,j)][(*wrapy)(i,j)];
  1039. X        /* unowned */
  1040. X      if ((world.map[(*wrapx)(i,j)][(*wrapy)(i,j)].owner != 0) &&
  1041. X          (world.map[(*wrapx)(i,j)][(*wrapy)(i,j)].owner != cn_id)) {
  1042. X        handle_meet(dm, cn_id,
  1043. X            world.map[(*wrapx)(i,j)][(*wrapy)(i,j)].owner);
  1044. X      }
  1045. X      for (sect_alist = sect_ptr->alist; sect_alist != NULL;
  1046. X           sect_alist = sect_alist->next) {
  1047. X        if ((sect_alist->owner != 0) && (sect_alist->owner != cn_id)) {
  1048. X          handle_meet(dm, cn_id, sect_alist->owner);
  1049. X        }
  1050. X      }
  1051. X    }
  1052. X      }
  1053. X    }
  1054. X  }
  1055. X  dump_diplo(NULL, dm, world.n_nations);
  1056. X  free_diplo(dm, world.n_nations);
  1057. X  sprintf(cmd_str, "cp %s %s\n", DIPLO_FILE, INIT_DIPLO_FILE);
  1058. X  system(cmd_str);
  1059. X/*    printf("done with diplomacy... too slow??\n"); */
  1060. X}
  1061. X
  1062. Xhave_met(dm, nation1, nation2)
  1063. X     Sdiplo **dm;
  1064. X     int nation1, nation2;
  1065. X{
  1066. X  int ind1, ind2;
  1067. X
  1068. X  ind1=0; ind2=0;
  1069. X  if ((nation1 >= world.n_nations) || (nation2 >= world.n_nations)) {
  1070. X    return(0);    /* bad nation id.... return false */
  1071. X  }
  1072. X  get_indices(dm, nation1, nation2, &ind1, &ind2);
  1073. X
  1074. X  if ((dm[ind1][ind2].status==UNMET)||(dm[ind1][ind2].status == SELF)) { 
  1075. X                /* if unmet, or self    */
  1076. X    return(0);            /* false */
  1077. X  } else {
  1078. X    return(1);            /* true */
  1079. X  }
  1080. X
  1081. X}
  1082. X
  1083. Xget_indices(dm, nation1, nation2, n1, n2)
  1084. X     Sdiplo **dm;
  1085. X     int nation1, nation2, *n1, *n2;
  1086. X{
  1087. X
  1088. X/*  while(nation1 != dm[(*n1)++][0].self_id)      /* find nation 1 */
  1089. X/*    ;
  1090. X  (*n1)--;
  1091. X  while(nation2 != dm[*n1][(*n2)++].neighbor_id)  /* find nation 2 */
  1092. X/*    ;
  1093. X  (*n2)--;
  1094. X*/
  1095. X    *n1 = nation1;
  1096. X    *n2 = nation2;
  1097. X}
  1098. X
  1099. X
  1100. Xhandle_meet(dm, nation1, nation2)
  1101. X     Sdiplo **dm;
  1102. X     int nation1, nation2;
  1103. X{
  1104. X
  1105. X  int n1, n2; 
  1106. X
  1107. X  n1=0; n2=0;
  1108. X  if (!have_met(dm,nation1,nation2)) {
  1109. X    get_indices(dm, nation1, nation2, &n1, &n2);
  1110. X    dm[n1][n2].status = NEUTRAL;      /* set their status to neutral */
  1111. X    n1=0; n2=0;                /* now do transpose */
  1112. X    get_indices(dm, nation2, nation1, &n2, &n1);
  1113. X    dm[n2][n1].status = NEUTRAL;  
  1114. X
  1115. X  }
  1116. X}
  1117. X
  1118. X
  1119. Xget_diplo_status(dm, nation1, nation2)
  1120. X     Sdiplo **dm;
  1121. X     int nation1, nation2;
  1122. X{
  1123. X  int n1, n2;
  1124. X
  1125. X  n1=0; n2=0;
  1126. X  if ((nation1 >= world.n_nations) || (nation2 >= world.n_nations)) {
  1127. X    return(0);    /* bad nation id.... return false */
  1128. X  };
  1129. X  get_indices(dm, nation1, nation2, &n1, &n2);
  1130. X  return(dm[n1][n2].status);
  1131. X}
  1132. X
  1133. Xset_diplo_status(dm, nation1, nation2, New_Status)
  1134. X     Sdiplo **dm;
  1135. X     int nation1, nation2, New_Status;
  1136. X{
  1137. X  int n1,n2;
  1138. X
  1139. X  n1 = 0; n2 = 0;
  1140. X  if ((nation1 >= world.n_nations) || (nation2 >= world.n_nations)) {
  1141. X    printf("Bad Nation ID in set_diplo_status.\n");    /* bad nation id... */
  1142. X  };
  1143. X  get_indices(dm, nation1, nation2, &n1, &n2);
  1144. X  dm[n1][n2].status = New_Status;
  1145. X}
  1146. X
  1147. X/* */
  1148. X/* free_diplo(): frees space for of diplomacy matrix */
  1149. X/* */
  1150. X
  1151. Xfree_diplo(dm, n)
  1152. X     Sdiplo **dm;
  1153. X     int n;            /* number of nations */
  1154. X{
  1155. X  int i;
  1156. X
  1157. X  for (i = 0; i < n; ++i) {
  1158. X    free(dm[i]);
  1159. X  }
  1160. X  free(dm);
  1161. X
  1162. X}
  1163. X
  1164. X#ifdef OLD_NPC_DIPLO
  1165. Xupdate_npc_diplo()
  1166. X{
  1167. X  Sdiplo **dm, **allocate_diplo();
  1168. X  Snation *np;
  1169. X  int Loop;
  1170. X  dm = allocate_diplo(world.n_nations);
  1171. X  read_in_diplo(dm, world.n_nations);
  1172. X  for (Loop = 1; Loop < world.n_nations; Loop++) {
  1173. X    np = &world.nations[Loop];
  1174. X    if (np->npc_flag !=0) {
  1175. X      do_npc_diplo(dm, np);
  1176. X    }
  1177. X  }
  1178. X  dump_diplo(NULL, dm, world.n_nations);
  1179. X  free_diplo(dm, world.n_nations);
  1180. X}
  1181. X
  1182. Xdo_npc_diplo(dm,np)
  1183. X     Sdiplo **dm;
  1184. X     Snation *np;
  1185. X{
  1186. X  int Loop;
  1187. X  
  1188. X  /* Take care of NPC diplomacy here */
  1189. X  
  1190. X  for (Loop = 1; Loop < world.n_nations; Loop++) {
  1191. X    set_diplo_status(dm,np->id,Loop,get_diplo_status(dm,Loop,np->id));
  1192. X  }
  1193. X}
  1194. X#endif /* OLD_NPC_DIPLO */
  1195. X
  1196. X  /* this returns 1 if these two nationes are allied to each other.
  1197. X     It uses the user.diplo_matrix, instead of reading it in, for speed.
  1198. X   */
  1199. Xare_allied(id1, id2)
  1200. X     int id1, id2;
  1201. X{
  1202. X/*  Sdiplo **dm, **allocate_diplo(); */
  1203. X  extern Suser user;
  1204. X  Sdiplo **dm = user.diplo_matrix;
  1205. X
  1206. X/*  dm = allocate_diplo(world.n_nations);
  1207. X  read_in_diplo(dm, world.n_nations);
  1208. X*/
  1209. X
  1210. X  if (dm[id1][id2].status >= ALLIED && dm[id2][id1].status >= ALLIED) {
  1211. X    return 1;
  1212. X  }
  1213. X  /* free_diplo(dm, world.n_nations); */
  1214. X  return 0;
  1215. X}
  1216. X
  1217. X  /* creates a diplomacy lock file, and puts some information into it */
  1218. Xlock_diplo(np)
  1219. X     Snation *np;
  1220. X{
  1221. X  FILE *lockfp, *fopen();
  1222. X  long now_secs;
  1223. X
  1224. X  if ((lockfp = fopen("diplo.lock", "w")) == NULL) {
  1225. X    return -1;
  1226. X  }
  1227. X  now_secs = time(0L);
  1228. X  fprintf(lockfp, "%ld; Nation: %s; time: %s", now_secs,
  1229. X      np ? np->name : "none", ctime(&now_secs));
  1230. X  fclose(lockfp);
  1231. X  return 1;
  1232. X}
  1233. X
  1234. Xunlock_diplo()
  1235. X{
  1236. X  unlink("diplo.lock");
  1237. X}
  1238. X
  1239. X  /* returns 1 if the diplo file is locked */
  1240. Xdiplo_is_locked()
  1241. X{
  1242. X  FILE *lock_fp, *fopen();
  1243. X  char line[EXECLEN];
  1244. X  long now_secs, lock_secs;
  1245. X
  1246. X  if ((lock_fp = fopen("diplo.lock", "r")) == NULL) {
  1247. X    return 0;            /* there is no lock file */
  1248. X  }
  1249. X    /* now see if the lock file is outdated.  if so, remove it */
  1250. X  fscanf(lock_fp, "%s", line);
  1251. X  sscanf(line, "%d", &lock_secs);
  1252. X  now_secs = time(0L);
  1253. X  if (abs(now_secs - lock_secs) > 2*30) { /* older than 2 minutes? */
  1254. X    unlink("diplo.lock");
  1255. X    return 0;
  1256. X  }
  1257. X  return 1;            /* if not, it is locked!! */
  1258. X}
  1259. END_OF_FILE
  1260. if test 11937 -ne `wc -c <'diplolib.c'`; then
  1261.     echo shar: \"'diplolib.c'\" unpacked with wrong size!
  1262. fi
  1263. # end of 'diplolib.c'
  1264. fi
  1265. if test -f 'maglib.c' -a "${1}" != "-c" ; then 
  1266.   echo shar: Will not clobber existing file \"'maglib.c'\"
  1267. else
  1268. echo shar: Extracting \"'maglib.c'\" \(9209 characters\)
  1269. sed "s/^X//" >'maglib.c' <<'END_OF_FILE'
  1270. X/* maglib.c -- routines having to do with magic powers */
  1271. X
  1272. X/*
  1273. X * Copyright (C) 1990 Free Software Foundation, Inc.
  1274. X * Written by the dominion project.
  1275. X *
  1276. X * This file is part of dominion.
  1277. X *
  1278. X * dominion is free software; you can redistribute it and/or
  1279. X * modify it under the terms of the GNU General Public License as published
  1280. X * by the Free Software Foundation; either version 1, or (at your option)
  1281. X * any later version.
  1282. X *
  1283. X * This software is distributed in the hope that it will be useful,
  1284. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1285. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1286. X * GNU General Public License for more details.
  1287. X *
  1288. X * You should have received a copy of the GNU General Public License
  1289. X * along with this software; see the file COPYING.  If not, write to
  1290. X * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  1291. X */
  1292. X
  1293. X#include "dominion.h"
  1294. X#include "misc.h"
  1295. X#include <stdio.h>
  1296. X#include <math.h>
  1297. X
  1298. X  /* dynamic array, to be read from file */
  1299. Xextern struct spirit_type *spirit_types;
  1300. Xextern Suser user;
  1301. X
  1302. Xextern int debug;
  1303. Xextern FILE *mailfile;
  1304. X
  1305. X  /* this is the routine actually called by the update program */
  1306. Xdomagic(np, mailfile)
  1307. X     Snation *np;
  1308. X     FILE *mailfile;
  1309. X{
  1310. X  int old_skill, new_skill, old_pts, new_pts;
  1311. X
  1312. X  old_skill = np->mag_skill;
  1313. X  old_pts = np->spell_pts;
  1314. X  new_skill = new_mag_skill(np);
  1315. X    /* must subtract the spell points used by spirits and such */
  1316. X  new_pts = new_spell_pts(np) - military_maint_spell_pts(np);
  1317. X  if (debug) {
  1318. X    printf("nation %s has old_mag_skill = %d, new_skill = %d\n",
  1319. X       np->name, old_skill, new_skill);
  1320. X    printf("nation %s has old_pts = %d, new_pts = %d\n",
  1321. X       np->name, old_pts, new_pts);
  1322. X  }
  1323. X  if (mailfile) {
  1324. X    fprintf(mailfile,
  1325. X        "Your skill in magic has increased from %d to %d\n",
  1326. X        old_skill, new_skill);
  1327. X    fprintf(mailfile,
  1328. X        "You have gained %d spell points, for a new total of %d\n",
  1329. X        new_pts-old_pts, new_pts);
  1330. X  }
  1331. X/*  get_new_spell(&user, old_skill, new_skill); should be in load_nation() or init_user() */
  1332. X  np->mag_skill = new_skill;
  1333. X  np->spell_pts = new_pts;
  1334. X}
  1335. X
  1336. X#define JEWEL_MAG_POWER (3.0/4.0)
  1337. X
  1338. X  /* this routine calculates the new mag_skill for a nation */
  1339. Xnew_mag_skill(np)
  1340. X     Snation *np;
  1341. X{
  1342. X  int increase;
  1343. X
  1344. X  increase = (int) 
  1345. X    ((np->race.mag_apt + priestliness(np)) / 100.0 *
  1346. X     (sqrt(1.0 * (calc_revenue (np) * np->mag_r_d/100.0
  1347. X       + np->cur_mag_r_d * np->money/100.0)) * MAG_MONEY_FACTOR
  1348. X      + pow((double)(calc_jewels (np) * np->mag_r_d_jewels / 100.0 +
  1349. X     np->jewels * np->cur_mag_r_d_jewels / 100.0),JEWEL_MAG_POWER)
  1350. X         * (MAG_JEWEL_FACTOR * 10))); /* 10 * the number of spell pts */
  1351. X  return np->mag_skill + increase;
  1352. X}
  1353. X
  1354. X  /* this calculates how many new spell points a nation gets this turn.
  1355. X     note that spell points accumulate but little.
  1356. X   */
  1357. Xnew_spell_pts(np)
  1358. X     Snation *np;
  1359. X{
  1360. X  int new_pts;
  1361. X
  1362. X  new_pts = (int)( pow((calc_jewels (np) * (np->mag_r_d_jewels / 100.0) +
  1363. X             np->jewels * np->cur_mag_r_d_jewels / 100.0),JEWEL_MAG_POWER)
  1364. X            * MAG_JEWEL_FACTOR *
  1365. X          ((np->race.mag_apt + priestliness (np)) / 100.0));
  1366. X  if (np->spell_pts < 0) {
  1367. X    return new_pts + np->spell_pts;
  1368. X  } else {
  1369. X    return (3*new_pts + np->spell_pts)/3; /* a mild accumulation */
  1370. X  }
  1371. X}
  1372. X
  1373. X  /* these spells are loaded in init_user() */
  1374. Xget_spells(up, skill)
  1375. X     Suser *up;
  1376. X     int skill;
  1377. X{
  1378. X  FILE *fp, *fopen();
  1379. X  Sspell spell, *tmp_spell;
  1380. X  char fname[2*NAMELEN], line[EXECLEN];
  1381. X  int done = 0, level; /* cost */
  1382. X
  1383. X  if (debug)
  1384. X    printf("nation %s, skill=%d\n", up->np->name, skill);
  1385. X  strcpy(fname, MAG_PREFIX);
  1386. X  strcat(fname, up->np->mag_order);
  1387. X
  1388. X  if ((fp = fopen(fname, "r")) == NULL) {
  1389. X    printf("could not open file for magic order %s.  returning.\n",
  1390. X       up->np->mag_order);
  1391. X    return -1;
  1392. X  }
  1393. X  while (!done) {
  1394. X    if (fgets(line, EXECLEN, fp) == NULL) {
  1395. X      done = 1;
  1396. X      fclose(fp);
  1397. X      return;
  1398. X    }
  1399. X    if (line[0] != '#') {    /* lines with '#' are comments */
  1400. X        /* make sure this is a spell and NOT a
  1401. X       summoned spirit or an exec line
  1402. X     */
  1403. X      if (strncmp(line, "summon_", strlen("summon_")) != 0
  1404. X      && strncmp(line, "EXEC:", strlen("EXEC:")) != 0) {
  1405. X    sscanf(line, "%s%d%d%d", spell.name, &level, &spell.cost,
  1406. X           &spell.duration);
  1407. X          /* add it to the user's spell list (if they deserve) */
  1408. X    if (level <= skill) {
  1409. X      if (debug) {
  1410. X        printf("found %s, level=%d, cost=%d, duration=%d\n", spell.name,
  1411. X           level, spell.cost, spell.duration);
  1412. X        printf("nation %s gets new spell <%s>\n",
  1413. X           up->np->name, spell.name);
  1414. X      }
  1415. X      if (up->spell_list == NULL) {
  1416. X        up->spell_list = (Sspell *) malloc(sizeof(Sspell));
  1417. X        *(up->spell_list) = spell;
  1418. X        up->spell_list->next = NULL;
  1419. X      } else {
  1420. X        tmp_spell = up->spell_list;
  1421. X        while (tmp_spell != NULL) { /* find end of list */
  1422. X          if (tmp_spell->next == NULL) {
  1423. X        tmp_spell->next = (Sspell *) malloc(sizeof(Sspell));
  1424. X        spell.next = NULL; /* making sure */
  1425. X        *(tmp_spell->next) = spell;
  1426. X        break;
  1427. X          }
  1428. X          tmp_spell = tmp_spell->next;
  1429. X        }
  1430. X      }
  1431. X    }
  1432. X      }
  1433. X    }
  1434. X  }
  1435. X  fclose(fp);
  1436. X}
  1437. X
  1438. X  /* these spirits are loaded in init_user() */
  1439. Xget_spirits(up, skill)
  1440. X     Suser *up;
  1441. X     int skill;
  1442. X{
  1443. X  FILE *fp, *fopen();
  1444. X  Sspirit spirit, *tmp_spirit;
  1445. X  char fname[2*NAMELEN], line[EXECLEN];
  1446. X  int done = 0, level;        /* , cost */
  1447. X
  1448. X  if (debug)
  1449. X    printf("nation %s, new_skill=%d\n",
  1450. X       up->np->name, skill);
  1451. X  strcpy(fname, MAG_PREFIX);
  1452. X  strcat(fname, up->np->mag_order);
  1453. X
  1454. X  if ((fp = fopen(fname, "r")) == NULL) {
  1455. X    printf("could not open file for magic order %s.  returning.\n",
  1456. X       up->np->mag_order);
  1457. X    return -1;
  1458. X  }
  1459. X  while (!done) {
  1460. X    if (fgets(line, EXECLEN, fp) == NULL) {
  1461. X      done = 1;
  1462. X      fclose(fp);
  1463. X      return;
  1464. X    }
  1465. X    if (line[0] != '#') {    /* lines with '#' are comments */
  1466. X      sscanf(line, "summon_%s%d%d", spirit.type, &level, &spirit.cost);
  1467. X        /* now we either get the spirit, or skip until the "end" of it */
  1468. X        /* now see if the line starts with a "summon_" */
  1469. X      if (strncmp(line, "summon_", strlen("summon_")) == 0) {
  1470. X      /* add it to the user's spirit list (if they deserve) */
  1471. X    if (level <= skill) {
  1472. X      if (up->spirit_list == NULL) {
  1473. X        up->spirit_list = (Sspirit *) malloc(sizeof(Sspirit));
  1474. X        *(up->spirit_list) = spirit;
  1475. X        up->spirit_list->next = NULL;
  1476. X      } else {
  1477. X        tmp_spirit = up->spirit_list;
  1478. X        while (tmp_spirit != NULL) { /* find end of list */
  1479. X          if (tmp_spirit->next == NULL) {
  1480. X        tmp_spirit->next = (Sspirit *) malloc(sizeof(Sspirit));
  1481. X        spirit.next = NULL; /* making sure */
  1482. X        *(tmp_spirit->next) = spirit;
  1483. X        break;
  1484. X          }
  1485. X          tmp_spirit = tmp_spirit->next;
  1486. X        }
  1487. X      }
  1488. X    }
  1489. X      }
  1490. X    }
  1491. X  }
  1492. X  fclose(fp);
  1493. X}
  1494. X
  1495. X
  1496. X  /* show a user's collection of spells and spirits */
  1497. Xlist_user_spells(up)
  1498. X     Suser *up;
  1499. X{
  1500. X  Sspell *tmp_spell;
  1501. X  Sspirit *tmp_spirit;
  1502. X
  1503. X  printf("Spells for Nation %s, of magic order %s:\n",
  1504. X     up->np->name, up->np->mag_order);
  1505. X  for (tmp_spell = up->spell_list; tmp_spell != NULL;
  1506. X       tmp_spell = tmp_spell->next) {
  1507. X    show_spell(tmp_spell);
  1508. X  }
  1509. X  printf("Spirits available to %s, of magic order %s:\n",
  1510. X     up->np->name, up->np->mag_order);
  1511. X  for (tmp_spirit = up->spirit_list; tmp_spirit != NULL;
  1512. X       tmp_spirit = tmp_spirit->next) {
  1513. X    show_spirit(tmp_spirit);
  1514. X  }
  1515. X}
  1516. X
  1517. Xshow_spell(spellp)
  1518. X     Sspell *spellp;
  1519. X{
  1520. X  int i;
  1521. X
  1522. X  printf("Spell <%s>, cost %d\n",
  1523. X     spellp->name, spellp->cost);
  1524. X}
  1525. Xshow_spirit(spiritp)
  1526. X     Sspirit *spiritp;
  1527. X{
  1528. X  int i;
  1529. X
  1530. X/*  printf("Spirit <%s>, level %d, cost %d\n",
  1531. X     spiritp->type, spiritp->level, spiritp->cost);
  1532. X  for (i = 0; i < spiritp->n_lines; ++i) {
  1533. X    printf("%s", spiritp->lines[i]);
  1534. X  }
  1535. X*/
  1536. X  printf("removed, since spirit/spell system has changed");
  1537. X}
  1538. X
  1539. X  /* at startup, this reads the spirit_types[] from a file */
  1540. Xload_spirit_types()
  1541. X{
  1542. X  FILE *fp, *fopen();
  1543. X  char line[210];
  1544. X  int i;
  1545. X
  1546. X  if ((fp = fopen(SPIRIT_TYPES_FILE, "r")) == NULL) {
  1547. X    printf("cannot open spirit types file.  quitting.\n");
  1548. X    perror("load_spirit_types");
  1549. X    clean_exit();
  1550. X    exit(1);
  1551. X  }
  1552. X
  1553. X  do {
  1554. X    fgets(line, 200, fp);
  1555. X  } while (line[0] == '#');
  1556. X    /* we should have the line with the number of spirit types in file */
  1557. X  sscanf(line, "%d", &user.n_spirit_types);
  1558. X
  1559. X  spirit_types =
  1560. X (struct spirit_type *) malloc(user.n_spirit_types*sizeof(struct spirit_type));
  1561. X
  1562. X  for (i = 0; i < user.n_spirit_types; ) {
  1563. X    fgets(line, 100, fp);
  1564. X    line[strlen(line)-1] = '\0';
  1565. X    if (line[0] != '#') {        /* ignore comments */
  1566. X      sscanf(line,"%s : %1s : %d : %f : %d : %d : %d : %d : %d",
  1567. X         spirit_types[i].type, &spirit_types[i].type_char,
  1568. X         &spirit_types[i].size, &spirit_types[i].move_factor,
  1569. X         &spirit_types[i].bonus,
  1570. X         &spirit_types[i].spell_pts_draft, &spirit_types[i].jewel_draft,
  1571. X         &spirit_types[i].jewel_maint, &spirit_types[i].flags);
  1572. X      ++i;
  1573. X    }
  1574. X  }
  1575. X
  1576. X  fclose(fp);
  1577. X}
  1578. X
  1579. X  /* returns true if this nation can draft that type of spirit */
  1580. Xis_valid_spirit_type(np, type)
  1581. X     Snation *np;
  1582. X     char type[];
  1583. X{
  1584. X  int i;
  1585. X
  1586. X    /* for now, the all spirit types are fair game */
  1587. X  for (i = 0; i < user.n_spirit_types; ++i) {
  1588. X    if (strncmp(spirit_types[i].type, type, NAMELEN) == 0) {
  1589. X      return 1;            /* got it!!! */
  1590. X    }
  1591. X  }
  1592. X  return 0;            /* we did not find that spirit type */
  1593. X}
  1594. END_OF_FILE
  1595. if test 9209 -ne `wc -c <'maglib.c'`; then
  1596.     echo shar: \"'maglib.c'\" unpacked with wrong size!
  1597. fi
  1598. # end of 'maglib.c'
  1599. fi
  1600. if test -f 'root.c' -a "${1}" != "-c" ; then 
  1601.   echo shar: Will not clobber existing file \"'root.c'\"
  1602. else
  1603. echo shar: Extracting \"'root.c'\" \(11313 characters\)
  1604. sed "s/^X//" >'root.c' <<'END_OF_FILE'
  1605. X  /* root.c -- special super-user commands */
  1606. X
  1607. X/*
  1608. X * Copyright (C) 1990 Free Software Foundation, Inc.
  1609. X * Written by the dominion project.
  1610. X *
  1611. X * This file is part of dominion.
  1612. X *
  1613. X * dominion is free software; you can redistribute it and/or
  1614. X * modify it under the terms of the GNU General Public License as published
  1615. X * by the Free Software Foundation; either version 1, or (at your option)
  1616. X * any later version.
  1617. X *
  1618. X * This software is distributed in the hope that it will be useful,
  1619. X * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1620. X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1621. X * GNU General Public License for more details.
  1622. X *
  1623. X * You should have received a copy of the GNU General Public License
  1624. X * along with this software; see the file COPYING.  If not, write to
  1625. X * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  1626. X */
  1627. X
  1628. X#include "dominion.h"
  1629. X
  1630. X#include <stdio.h>
  1631. X
  1632. Xextern Sworld world;
  1633. Xextern Suser user;
  1634. X
  1635. Xroot_edit()
  1636. X{
  1637. X  WINDOW *rew;
  1638. X  char s[EXECLEN];
  1639. X  int done = 0;
  1640. X
  1641. X  rew = newwin(6, COLS-20, LINES/4, 10);
  1642. X  touchwin(rew);
  1643. X  while (!done) {
  1644. X    werase(rew);
  1645. X    sprintf(s, "Root Editing");
  1646. X    wmove(rew, 1, (COLS/2-20-strlen(s))/2);
  1647. X    wstandout(rew);
  1648. X    waddstr(rew, s);
  1649. X    wstandend(rew);
  1650. X    mvwaddstr(rew, 3, 3, "Edit [s]ector or [n]ation? ");
  1651. X    wrefresh(rew);
  1652. X    switch (getch()) {
  1653. X    case 's':
  1654. X      root_edit_sector();
  1655. X      break;
  1656. X    case 'n':
  1657. X      root_edit_nation();
  1658. X      break;
  1659. X    case ' ':
  1660. X      done = 1;
  1661. X      break;
  1662. X    default:
  1663. X      break;
  1664. X    }
  1665. X  }
  1666. X  delwin(rew);
  1667. X  touch_all_wins(stdscr);
  1668. X}
  1669. X
  1670. Xroot_edit_sector()
  1671. X{
  1672. X  WINDOW *resw;
  1673. X  int pop_change, done = 0, new_owner, change;
  1674. X
  1675. X  Ssector *sp = &world.map[user.cursor.x][user.cursor.y];
  1676. X
  1677. X  resw = newwin(8, COLS-2, LINES-10, 1);
  1678. X  touchwin(resw);
  1679. X
  1680. X  while (!done) {
  1681. X    werase(resw);
  1682. X    mvwaddstr(resw, 5, 2, "Change: [p]opulation, [o]wner ");
  1683. X    mvwaddstr(resw, 6, 2, "        [s]oil, [m]etal, [j]ewels, [a]ltitude");
  1684. X/*    box(resw, 'R', 'R'); */
  1685. X    wrefresh(resw);
  1686. X    switch (getch()) {
  1687. X    case 'p':
  1688. X      mvwprintw(resw, 1, 1, "Sector (%d,%d), pop=%d, what population change? ",
  1689. X        sp->loc.x, sp->loc.y, sp->n_people);
  1690. X      wrefresh(resw);
  1691. X      if (wget_number(resw, &pop_change) > 0) {
  1692. X    sp->n_people += pop_change;
  1693. X    cpeople_sector(sp, pop_change);
  1694. X      }
  1695. X      break;
  1696. X    case 'o':
  1697. X      mvwprintw(resw, 1, 1, "Sector (%d,%d), owner=%d, which new owner id? ",
  1698. X        sp->loc.x, sp->loc.y, sp->owner);
  1699. X      wrefresh(resw);
  1700. X      if (wget_number(resw, &new_owner) > 0 && new_owner <= world.n_nations) {
  1701. X      /* 1. remove from old owner's list
  1702. X         2. add to new owner's list
  1703. X       */
  1704. X    if (sp->owner != 0) {
  1705. X      subtsector(&world.nations[sp->owner], sp->loc.x, sp->loc.y);
  1706. X    }
  1707. X    sp->owner = new_owner;
  1708. X    cowner_sector(sp, new_owner);
  1709. X    if (new_owner != 0) {    /* nation 0 has no sector list */
  1710. X      addsector(&world.nations[new_owner], sp->loc.x, sp->loc.y);
  1711. X    }
  1712. X      }
  1713. X      break;
  1714. X    case 's':
  1715. X      mvwprintw(resw, 1, 1, "Sector (%d,%d), soil=%d, what soil change? ",
  1716. X        sp->loc.x, sp->loc.y, sp->soil);
  1717. X      wrefresh(resw);
  1718. X      if (wget_number(resw, &change) > 0) {
  1719. X    sp->soil += change;
  1720. X    csoil_sector(sp, change);
  1721. X      }
  1722. X      break;
  1723. X    case 'm':
  1724. X      mvwprintw(resw, 1, 1, "Sector (%d,%d), metal=%d, what metal change? ",
  1725. X        sp->loc.x, sp->loc.y, sp->metal);
  1726. X      wrefresh(resw);
  1727. X      if (wget_number(resw, &change) > 0) {
  1728. X    sp->metal += change;
  1729. X    cmetal_sector(sp, change);
  1730. X      }
  1731. X      break;
  1732. X    case 'j':
  1733. X      mvwprintw(resw, 1, 1, "Sector (%d,%d), jewels=%d, what jewels change? ",
  1734. X        sp->loc.x, sp->loc.y, sp->jewels);
  1735. X      wrefresh(resw);
  1736. X      if (wget_number(resw, &change) > 0) {
  1737. X    sp->jewels += change;
  1738. X    cjewels_sector(sp, change);
  1739. X      }
  1740. X      break;
  1741. X    case 'a':
  1742. X      mvwprintw(resw,1,1,"Sector (%d,%d), altitude=%d, what altitude change? ",
  1743. X        sp->loc.x, sp->loc.y, sp->altitude);
  1744. X      wrefresh(resw);
  1745. X      if (wget_number(resw, &change) > 0) {
  1746. X    sp->altitude += change;
  1747. X    caltitude_sector(sp, change);
  1748. X      }
  1749. X      break;
  1750. X    case ' ':
  1751. X      done = 1;
  1752. X      break;
  1753. X    default:
  1754. X      break;
  1755. X    }
  1756. X  }
  1757. X  delwin(resw);
  1758. X  touch_all_wins(stdscr);
  1759. X  refresh();
  1760. X}
  1761. X
  1762. X  /* allows the game master to tinker with a nation */
  1763. Xroot_edit_nation()
  1764. X{
  1765. X  WINDOW *renw;
  1766. X  int done = 0, change, id;
  1767. X  Snation *np;
  1768. X  char name[NAMELEN], s[EXECLEN];
  1769. X  char c;
  1770. X
  1771. X  Ssector *sp = &world.map[user.cursor.x][user.cursor.y];
  1772. X
  1773. X  renw = newwin(9, COLS-2, LINES-12, 1);
  1774. X  touchwin(renw);
  1775. X  mvwaddstr(renw, 1, 3, "Which nation (id) do you want to change? ");
  1776. X  wrefresh(renw);
  1777. X  if (wget_number(renw, &id) < 0) {
  1778. X    return;
  1779. X  }
  1780. X  np = &world.nations[id];
  1781. X  while (!done) {
  1782. X    werase(renw);
  1783. X    mvwprintw(renw, 1, 6, "Editing nation %s [%c]", np->name, np->mark);
  1784. X    switch (np->npc_flag) {
  1785. X    case NPC_NOMAIL:
  1786. X      wprintw(renw, " [npc]     ");
  1787. X      break;
  1788. X    case NPC_MAIL:
  1789. X      wprintw(renw, " [npc+mail]");
  1790. X      break;
  1791. X    case NOT_NPC:
  1792. X    default:
  1793. X      wprintw(renw, "           ");
  1794. X      break;
  1795. X    }
  1796. X/*          np->npc_flag ? "npc" : "not npc"); */
  1797. X    mvwaddstr(renw, 4, 2,
  1798. X          "Change: [N]ame, [p]assword, [D]estroy, [t]oggle npc");
  1799. X    mvwaddstr(renw, 5, 2, "        [s]heckles, [m]etal, [j]ewels, [f]ood");
  1800. X    mvwaddstr(renw, 6, 2, "        [T]ech skill, [M]ag skill, [S]pell pts");
  1801. X    mvwaddstr(renw, 7, 2, "        [d]iplomacy, mag. [o]rder, nation mar[k]");
  1802. X    if (np->npc_flag) {
  1803. X      mvwaddstr(renw, 8, 2, "        [a]ggressiveness");
  1804. X/*      mvwaddstr(renw, 8, 2,
  1805. X        "[a]ggressiveness, [e]xpansionism, [i]solationism");
  1806. X */
  1807. X    }
  1808. X/*    box(renw, 'R', 'R'); */
  1809. X    wrefresh(renw);
  1810. X    switch (getch()) {
  1811. X    case 'N':
  1812. X      mvwprintw(renw, 1, 1, "Give new name for nation: ");
  1813. X      wrefresh(renw);
  1814. X      if (wget_name(renw, name) > 0) {
  1815. X    strcpy(np->name, name);
  1816. X    sprintf(s, "NATION_NAME:%d:%s\n", np->id, name);
  1817. X    gen_exec(s);
  1818. X      }
  1819. X      break;
  1820. X    case 'p':
  1821. X      change_passwd(np, renw);
  1822. X      break;
  1823. X    case 'D':
  1824. X      root_destroy_nation(np, renw);
  1825. X      break;
  1826. X    case 't':            /* rotate values for the npc flag */
  1827. X      np->npc_flag = (np->npc_flag + 1) % 3;
  1828. X/*      np->npc_flag = !np->npc_flag; */
  1829. X      if (np->npc_flag) {
  1830. X    sprintf(s, "SET_NPC:%d\n", np->id);
  1831. X      } else {
  1832. X    sprintf(s, "CLEAR_NPC:%d\n", np->id);
  1833. X      }
  1834. X      gen_exec(s);
  1835. X      break;
  1836. X    case 's':
  1837. X      mvwprintw(renw, 1, 1, "Nation's money=%d;  what change? ", np->money);
  1838. X      wrefresh(renw);
  1839. X      if (wget_number(renw, &change) > 0) {
  1840. X    np->money += change;
  1841. X    cmoney(np, change);
  1842. X      }
  1843. X      break;
  1844. X    case 'm':
  1845. X      mvwprintw(renw, 1, 1, "Nation's metal=%d;  what change? ", np->metal);
  1846. X      wrefresh(renw);
  1847. X      if (wget_number(renw, &change) > 0) {
  1848. X    np->metal += change;
  1849. X    cmetal(np, change);
  1850. X      }
  1851. X      break;
  1852. X    case 'j':
  1853. X      mvwprintw(renw, 1, 1, "Nation's jewels=%d;  what change? ", np->jewels);
  1854. X      wrefresh(renw);
  1855. X      if (wget_number(renw, &change) > 0) {
  1856. X    np->jewels += change;
  1857. X    cjewels(np, change);
  1858. X      }
  1859. X      break;
  1860. X    case 'f':
  1861. X      mvwprintw(renw, 1, 1, "Nation's food=%d;  what change? ", np->food);
  1862. X      wrefresh(renw);
  1863. X      if (wget_number(renw, &change) > 0) {
  1864. X    np->food += change;
  1865. X    cfood(np, change);
  1866. X      }
  1867. X      break;
  1868. X    case 'T':
  1869. X      mvwprintw(renw, 1, 1, "Nation's tech skill=%d;  what change? ",
  1870. X        np->tech_skill);
  1871. X      wrefresh(renw);
  1872. X      if (wget_number(renw, &change) > 0) {
  1873. X    np->tech_skill += change;
  1874. X    ctech_skill(np, change);
  1875. X      }
  1876. X      break;
  1877. X    case 'M':
  1878. X      mvwprintw(renw, 1, 1, "Nation's mag skill=%d;  what change? ",
  1879. X        np->mag_skill);
  1880. X      wrefresh(renw);
  1881. X      if (wget_number(renw, &change) > 0) {
  1882. X    np->mag_skill += change;
  1883. X    cmag_skill(np, change);
  1884. X      }
  1885. X      break;
  1886. X    case 'S':
  1887. X      mvwprintw(renw, 1, 1, "Nation's spell pts=%d;  what change? ",
  1888. X        np->spell_pts);
  1889. X      wrefresh(renw);
  1890. X      if (wget_number(renw, &change) > 0) {
  1891. X    np->spell_pts += change;
  1892. X    cspell_pts(np, change);
  1893. X      }
  1894. X      break;
  1895. X    case 'o':            /* change magic order */
  1896. X      do {
  1897. X    mvwprintw(renw, 1, 1, "Give new magic order (currently %s) ",
  1898. X          np->mag_order);
  1899. X    wclrtoeol(renw);
  1900. X    wrefresh(renw);
  1901. X    wget_name(renw, name);
  1902. X      } while (!is_good_order(name));
  1903. X      strcpy(np->mag_order, name);
  1904. X      sprintf(s, "NATION_ORDER:%d:%s\n", np->id, name);
  1905. X      gen_exec(s);
  1906. X      break;
  1907. X    case 'k':            /* change nation mark */
  1908. X      mvwprintw(renw, 1, 1, "Give new nation mark ");
  1909. X      wclrtoeol(renw);
  1910. X      wrefresh(renw);
  1911. X      fflush(stdin);
  1912. X      do {
  1913. X    c = getchar();
  1914. X    putchar(c);
  1915. X      } while (!free_nation_mark(&world, c));
  1916. X      np->mark = c;
  1917. X      sprintf(s, "NATION_MARK:%d:%c\n", np->id, c);
  1918. X      gen_exec(s);
  1919. X      break;
  1920. X    case 'd':
  1921. X      diplo_report(np);
  1922. X      break;
  1923. X    case 'a':
  1924. X      if (np->npc_flag) {
  1925. X    set_aggressiveness(np, renw);
  1926. X      }
  1927. X      break;
  1928. X    case ' ':
  1929. X      done = 1;
  1930. X      break;
  1931. X    default:
  1932. X      break;
  1933. X    }
  1934. X  }
  1935. X  delwin(renw);
  1936. X  touch_all_wins();
  1937. X  refresh();
  1938. X}
  1939. X
  1940. X  /* here are some exec lines available only to the Gamemaster */
  1941. Xcowner_sector(sp, owner)
  1942. X     Ssector *sp;
  1943. X     int owner;
  1944. X{
  1945. X  char s[EXECLEN];
  1946. X
  1947. X  sprintf(s, "COWNER_SECTOR:%d:%d:%d\n", sp->loc.x, sp->loc.y, owner);
  1948. X  gen_exec(s);
  1949. X}
  1950. X
  1951. Xcsoil_sector(sp, change)
  1952. X     Ssector *sp;
  1953. X     int change;
  1954. X{
  1955. X  char s[EXECLEN];
  1956. X
  1957. X  sprintf(s, "CSOIL_SECTOR:%d:%d:%d\n", sp->loc.x, sp->loc.y, change);
  1958. X  gen_exec(s);
  1959. X}
  1960. X
  1961. Xcmetal_sector(sp, change)
  1962. X     Ssector *sp;
  1963. X     int change;
  1964. X{
  1965. X  char s[EXECLEN];
  1966. X
  1967. X  sprintf(s, "CMETAL_SECTOR:%d:%d:%d\n", sp->loc.x, sp->loc.y, change);
  1968. X  gen_exec(s);
  1969. X}
  1970. X
  1971. Xcjewels_sector(sp, change)
  1972. X     Ssector *sp;
  1973. X     int change;
  1974. X{
  1975. X  char s[EXECLEN];
  1976. X
  1977. X  sprintf(s, "CJEWELS_SECTOR:%d:%d:%d\n", sp->loc.x, sp->loc.y, change);
  1978. X  gen_exec(s);
  1979. X}
  1980. X
  1981. Xcaltitude_sector(sp, change)
  1982. X     Ssector *sp;
  1983. X     int change;
  1984. X{
  1985. X  char s[EXECLEN];
  1986. X
  1987. X  sprintf(s, "CALTITUDE_SECTOR:%d:%d:%d\n", sp->loc.x, sp->loc.y, change);
  1988. X  gen_exec(s);
  1989. X}
  1990. X
  1991. X  /* this is serious:  destroy a nation, interactively, as super user */
  1992. Xroot_destroy_nation(np, renw)
  1993. X     Snation *np;
  1994. X     WINDOW *renw;
  1995. X{
  1996. X  char c;
  1997. X  char s[EXECLEN];
  1998. X
  1999. X  mvwaddstr(renw, 3, 4, "Are you quite sure?  This is serious!!! ");
  2000. X  wrefresh(renw);
  2001. X  if ((c = wgetch(renw)) == 'y' || c == 'Y') {
  2002. X    mvwaddstr(renw, 4, 6, "Confirm again, dude: ");
  2003. X    wrefresh(renw);
  2004. X    if ((c = wgetch(renw)) == 'y' || c == 'Y') {
  2005. X      destroy_nation(np->id);
  2006. X      sprintf(s, "DESTROY:%d\n", np->id);
  2007. X      gen_exec(s);
  2008. X    }
  2009. X  }
  2010. X}
  2011. X
  2012. X  /* allow the nation's aggressiveness to be modified.  we
  2013. X     will make a new window so that this can be called from
  2014. X     various different places (such as the root editing and
  2015. X     the info report).
  2016. X   */
  2017. Xset_aggressiveness(np, current_win)
  2018. X     Snation *np;
  2019. X     WINDOW *current_win;    /* for redrawing purposes */
  2020. X{
  2021. X  WINDOW *aggw;
  2022. X  int aggr;
  2023. X  char s[EXECLEN];
  2024. X
  2025. X  aggw = newwin(8, 30, LINES-14, 10);
  2026. X  touchwin(aggw);
  2027. X  mvwprintw(aggw, 3, 3, "Current aggressiveness %d", np->npc_agg);
  2028. X  mvwprintw(aggw, 4, 3, "Give new value: ");
  2029. X  box(aggw, '|', '-');
  2030. X  wrefresh(aggw);
  2031. X  if (wget_number(aggw, &aggr) < 0) { /* if user types nothing or bad value */
  2032. X    delwin(aggw);
  2033. X    touchwin(current_win);
  2034. X    return;
  2035. X  }
  2036. X    /* set the new value and make sure we don't overflow */
  2037. X  np->npc_agg = aggr;
  2038. X  np->npc_agg = min(np->npc_agg, 100);
  2039. X  np->npc_agg = max(np->npc_agg, 0);
  2040. X  sprintf(s, "NPC_PARAM:%d:%d:%d:%d\n", np->id, np->npc_agg,
  2041. X      np->npc_exp, np->npc_iso);
  2042. X  gen_exec(s);
  2043. X  delwin(aggw);
  2044. X  touchwin(current_win);
  2045. X  return;
  2046. X}
  2047. END_OF_FILE
  2048. if test 11313 -ne `wc -c <'root.c'`; then
  2049.     echo shar: \"'root.c'\" unpacked with wrong size!
  2050. fi
  2051. # end of 'root.c'
  2052. fi
  2053. echo shar: End of archive 25 \(of 28\).
  2054. cp /dev/null ark25isdone
  2055. MISSING=""
  2056. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ; do
  2057.     if test ! -f ark${I}isdone ; then
  2058.     MISSING="${MISSING} ${I}"
  2059.     fi
  2060. done
  2061. if test "${MISSING}" = "" ; then
  2062.     echo You have unpacked all 28 archives.
  2063.     echo "Now execute ./do_cat.sh to build doc files"
  2064.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2065. else
  2066.     echo You still need to unpack the following archives:
  2067.     echo "        " ${MISSING}
  2068. fi
  2069. ##  End of shell archive.
  2070. exit 0
  2071.