home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume27 / sfs / part18 < prev    next >
Text File  |  1991-12-27  |  57KB  |  2,073 lines

  1. Newsgroups: comp.sources.misc
  2. From: tcamp@hercules.acpub.duke.edu (Ted Campbell)
  3. Subject:  v27i018:  sfs - Space Flight Simulator, Part18/21
  4. Message-ID: <1991Dec24.191925.21134@sparky.imd.sterling.com>
  5. X-Md4-Signature: c08ed3bc3c8e1479e10d43492aebb243
  6. Date: Tue, 24 Dec 1991 19:19:25 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: tcamp@hercules.acpub.duke.edu (Ted Campbell)
  10. Posting-number: Volume 27, Issue 18
  11. Archive-name: sfs/part18
  12. Environment: IBMPC && EGA/VGA, UNIX-PC && MGR, UNIX && X11,
  13.  
  14. #!/bin/sh
  15. # do not concatenate these parts, unpack them in order with /bin/sh
  16. # file sfs/sfs/sfs.h continued
  17. #
  18. if test ! -r _shar_seq_.tmp; then
  19.     echo 'Please unpack part 1 first!'
  20.     exit 1
  21. fi
  22. (read Scheck
  23.  if test "$Scheck" != 18; then
  24.     echo Please unpack part "$Scheck" next!
  25.     exit 1
  26.  else
  27.     exit 0
  28.  fi
  29. ) < _shar_seq_.tmp || exit 1
  30. if test ! -f _shar_wnt_.tmp; then
  31.     echo 'x - still skipping sfs/sfs/sfs.h'
  32. else
  33. echo 'x - continuing file sfs/sfs/sfs.h'
  34. sed 's/^X//' << 'SHAR_EOF' >> 'sfs/sfs/sfs.h' &&
  35. X
  36. X
  37. SHAR_EOF
  38. echo 'File sfs/sfs/sfs.h is complete' &&
  39. chmod 0644 sfs/sfs/sfs.h ||
  40. echo 'restore of sfs/sfs/sfs.h failed'
  41. Wc_c="`wc -c < 'sfs/sfs/sfs.h'`"
  42. test 12242 -eq "$Wc_c" ||
  43.     echo 'sfs/sfs/sfs.h: original size 12242, current size' "$Wc_c"
  44. rm -f _shar_wnt_.tmp
  45. fi
  46. # ============= sfs/sfs/sfs.mak ==============
  47. if test -f 'sfs/sfs/sfs.mak' -a X"$1" != X"-c"; then
  48.     echo 'x - skipping sfs/sfs/sfs.mak (File already exists)'
  49.     rm -f _shar_wnt_.tmp
  50. else
  51. > _shar_wnt_.tmp
  52. echo 'x - extracting sfs/sfs/sfs.mak (Text)'
  53. sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfs.mak' &&
  54. PROJ    =SFS
  55. DEBUG    =0
  56. CC    =qcl
  57. CFLAGS_G        = /AS /W1 /Ze /I..\..\include /DDEBUG /DSPAWN
  58. CFLAGS_D    = /Zd /Gi$(PROJ).mdt /Od 
  59. CFLAGS_R    = /Od /Gs /DNDEBUG 
  60. CFLAGS    =$(CFLAGS_G) $(CFLAGS_R)
  61. LFLAGS_G    = /CP:0xffff /NOI /SE:0x80 /ST:0x1000 
  62. LFLAGS_D    = /INCR 
  63. LFLAGS_R    = 
  64. LFLAGS    =$(LFLAGS_G) $(LFLAGS_R)
  65. RUNFLAGS    =
  66. OBJS_EXT =     
  67. LIBS_EXT =     
  68. X
  69. all:    $(PROJ).exe
  70. X
  71. sfs.obj:    sfs.c
  72. X
  73. $(PROJ).exe:    sfs.obj $(OBJS_EXT)
  74. X    echo >NUL @<<$(PROJ).crf
  75. sfs.obj +
  76. $(OBJS_EXT)
  77. $(PROJ).exe
  78. X
  79. $(LIBS_EXT);
  80. <<
  81. X    link $(LFLAGS) @$(PROJ).crf
  82. X
  83. run: $(PROJ).exe
  84. X    $(PROJ) $(RUNFLAGS)
  85. X
  86. SHAR_EOF
  87. chmod 0644 sfs/sfs/sfs.mak ||
  88. echo 'restore of sfs/sfs/sfs.mak failed'
  89. Wc_c="`wc -c < 'sfs/sfs/sfs.mak'`"
  90. test 546 -eq "$Wc_c" ||
  91.     echo 'sfs/sfs/sfs.mak: original size 546, current size' "$Wc_c"
  92. rm -f _shar_wnt_.tmp
  93. fi
  94. # ============= sfs/sfs/sfs_di.c ==============
  95. if test -f 'sfs/sfs/sfs_di.c' -a X"$1" != X"-c"; then
  96.     echo 'x - skipping sfs/sfs/sfs_di.c (File already exists)'
  97.     rm -f _shar_wnt_.tmp
  98. else
  99. > _shar_wnt_.tmp
  100. echo 'x - extracting sfs/sfs/sfs_di.c (Text)'
  101. sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfs_di.c' &&
  102. /***************************************************************
  103. X
  104. X    sfs_di.c        Multiple Display Routines for
  105. X            Space Flight Simulator
  106. X
  107. X            Copyright (c) 1991, Ted A. Campbell
  108. X
  109. X            Bywater Software
  110. X            P. O. Box 4023 
  111. X            Duke Station 
  112. X            Durham, NC  27706
  113. X
  114. X            email: tcamp@hercules.acpub.duke.edu
  115. X
  116. X    Copyright and Permissions Information:
  117. X
  118. X    All U.S. and international copyrights are claimed by the
  119. X    author. The author grants permission to use this code
  120. X    and software based on it under the following conditions:
  121. X    (a) in general, the code and software based upon it may be 
  122. X    used by individuals and by non-profit organizations; (b) it
  123. X    may also be utilized by governmental agencies in any country,
  124. X    with the exception of military agencies; (c) the code and/or
  125. X    software based upon it may not be sold for a profit without
  126. X    an explicit and specific permission from the author, except
  127. X    that a minimal fee may be charged for media on which it is
  128. X    copied, and for copying and handling; (d) the code must be 
  129. X    distributed in the form in which it has been released by the
  130. X    author; and (e) the code and software based upon it may not 
  131. X    be used for illegal activities. 
  132. X
  133. ***************************************************************/
  134. X
  135. #include "stdio.h"
  136. #include "ctype.h"
  137. #include "bw.h"
  138. #include "gr.h"
  139. #include "kb.h"
  140. #include "ui.h"
  141. #include "as.h"
  142. #include "sfs.h"
  143. X
  144. #ifdef  __STDC__
  145. #include "malloc.h"
  146. #else
  147. extern  char * malloc();
  148. #define size_t   int
  149. #define time_t   long
  150. #endif
  151. X
  152. /***************************************************************
  153. X
  154. X    di_init()
  155. X
  156. ***************************************************************/
  157. X
  158. di_init( sorbit_array, n_orbits, d_array, n_displays, t_array )
  159. X   struct sfs_orbit **sorbit_array;
  160. X   int n_orbits;
  161. X   struct sfs_display ***d_array;
  162. X   int *n_displays;
  163. X   char ***t_array;
  164. X   {
  165. X   register int c, d;
  166. X   int n;
  167. X   int x_foci, x_active, x_new;
  168. X
  169. X   /* first determine the number of active orbits */
  170. X
  171. X   x_active = 0;
  172. X   for ( c = 0; c < n_orbits; ++c )
  173. X      {
  174. X      if ( sorbit_array[ c ] != NULL )
  175. X         {
  176. X     ++x_active;
  177. X     }
  178. X      }
  179. X
  180. X   /* now determine number of foci */
  181. X
  182. X   x_foci = 0;
  183. X   for ( c = 0; c < n_orbits; ++c )
  184. X      {
  185. X      if ( sorbit_array[ c ] != NULL )
  186. X     {
  187. X     x_new = TRUE;
  188. X     for ( d = 0; d < c; ++d )
  189. X        {
  190. X        if ( sorbit_array[ d ] != NULL )
  191. X           {
  192. X           if ( sorbit_array[ d ]->aorbit->focus ==
  193. X          sorbit_array[ c ]->aorbit->focus )
  194. X          {
  195. X          x_new = FALSE;
  196. X          }
  197. X           }
  198. X        }
  199. X     if ( x_new == TRUE )
  200. X        {
  201. X        ++x_foci;
  202. X        }
  203. X     }
  204. X      }
  205. X
  206. X   /* now calculate total number of displays: one visual for each orbit,
  207. X      then a ground track and a distant perspective display for each focus */
  208. X
  209. X   *n_displays = x_active + ( 2 * x_foci );
  210. X
  211. #ifdef  OLD_DEBUG
  212. X   sprintf( bw_ebuf, "Displays: %d total from %d orbits with %d foci",
  213. X      *n_displays, x_active, x_foci );
  214. X   bw_debug( bw_ebuf );
  215. #endif
  216. X
  217. X   /* allocate memory for d_array */
  218. X
  219. X   if ( ( *d_array = (struct sfs_display **)
  220. X      malloc( sizeof( struct sfs_display *) * *n_displays ) ) == NULL )
  221. X      {
  222. X      bw_error( DI_MEMERR );
  223. X      sfs_exit();
  224. X      exit( 0 );
  225. X      }
  226. X
  227. X   /* allocate memory for each structure within d_array */
  228. X
  229. X   for ( c = 0; c < *n_displays; ++c )
  230. X      {
  231. X      if ( ( (*d_array)[ c ] = (struct sfs_display *)
  232. X     malloc( sizeof( struct sfs_display ) ) ) == NULL )
  233. X     {
  234. X     bw_error( DI_DSMEMERR );
  235. X     sfs_exit();
  236. X     exit( 0 );
  237. X     }
  238. X      }
  239. X
  240. X   /* from now on, use n as the counter for the display being constructed */
  241. X   /* fill in the visual simulation displays */
  242. X
  243. X   n = 0;
  244. X   for ( c = 0; c < n_orbits; ++c )
  245. X      {
  246. X      if ( sorbit_array[ c ] != NULL )
  247. X     {
  248. X     (*d_array)[ n ]->type = SFSD_VISUAL;
  249. X     (*d_array)[ n ]->elements
  250. X        = VI_ORBOUTLINE | VI_GRIDFRONT | VI_SURFRONT | VI_STITLE;
  251. X     (*d_array)[ n ]->orbit = c;
  252. X     ++n;
  253. X     }
  254. X      }
  255. X
  256. X   /* fill in the ground track displays */
  257. X
  258. X   for ( c = 0; c < n_orbits; ++c )
  259. X      {
  260. X      if ( sorbit_array[ c ] != NULL )
  261. X     {
  262. X     x_new = TRUE;
  263. X     for ( d = 0; d < c; ++d )
  264. X        {
  265. X        if ( sorbit_array[ d ] != NULL )
  266. X           {
  267. X           if ( sorbit_array[ d ]->aorbit->focus ==
  268. X          sorbit_array[ c ]->aorbit->focus )
  269. X          {
  270. X          x_new = FALSE;
  271. X          }
  272. X           }
  273. X        }
  274. X     if ( x_new == TRUE )
  275. X        {
  276. X        (*d_array)[ n ]->type = SFSD_GROUND;
  277. X        (*d_array)[ n ]->elements
  278. X           = VI_ORBOUTLINE | VI_GRIDFRONT | VI_SURFRONT;
  279. X        (*d_array)[ n ]->orbit = c;
  280. X        (*d_array)[ n ]->focus = sorbit_array[ c ]->aorbit->focus;
  281. X        ++n;
  282. X        }
  283. X     }
  284. X      }
  285. X
  286. X   /* fill in the perspective displays */
  287. X
  288. X   for ( c = 0; c < n_orbits; ++c )
  289. X      {
  290. X      if ( sorbit_array[ c ] != NULL )
  291. X     {
  292. X     x_new = TRUE;
  293. X     for ( d = 0; d < c; ++d )
  294. X        {
  295. X        if ( sorbit_array[ d ] != NULL )
  296. X           {
  297. X           if ( sorbit_array[ d ]->aorbit->focus ==
  298. X          sorbit_array[ c ]->aorbit->focus )
  299. X          {
  300. X          x_new = FALSE;
  301. X          }
  302. X           }
  303. X        }
  304. X     if ( x_new == TRUE )
  305. X        {
  306. X        (*d_array)[ n ]->type = SFSD_PERSP;
  307. X        (*d_array)[ n ]->elements
  308. X           = VI_ORBOUTLINE | VI_GRIDFRONT | VI_SURFRONT;
  309. X        (*d_array)[ n ]->orbit = c;
  310. X        (*d_array)[ n ]->focus = sorbit_array[ c ]->aorbit->focus;
  311. X        ++n;
  312. X        }
  313. X     }
  314. X      }
  315. X
  316. X   /* allocate memory for t_array */
  317. X
  318. X   if ( ( *t_array = (char **)
  319. X      malloc( sizeof(char *) * *n_displays ) ) == NULL )
  320. X      {
  321. X      bw_error( DI_DMEMERR );
  322. X      sfs_exit();
  323. X      exit( 0 );
  324. X      }
  325. X
  326. X   /* now allocate memory for and write each title */
  327. X
  328. X   for ( c = 0; c < *n_displays; ++c )
  329. X      {
  330. X      switch ( (*d_array)[ c ]->type )
  331. X     {
  332. X     case SFSD_VISUAL:
  333. X        sprintf( bw_ebuf, VIS_TITLE,
  334. X           sorbit_array[ (*d_array)[ c ]->orbit ]->aorbit->focus->name,
  335. X           sorbit_array[ (*d_array)[ c ]->orbit ]->name,
  336. X           (*d_array)[ c ]->orbit + 1 );
  337. X        break;
  338. X     case SFSD_PERSP:
  339. X        sprintf( bw_ebuf, PER_TITLE,
  340. X           sorbit_array[ (*d_array)[ c ]->orbit ]->aorbit->focus->adjective );
  341. X        break;
  342. X     case SFSD_GROUND:
  343. X        sprintf( bw_ebuf, GTR_TITLE,
  344. X           sorbit_array[ (*d_array)[ c ]->orbit ]->aorbit->focus->adjective );
  345. X        break;
  346. X     default:
  347. #ifdef  DEBUG
  348. X        sprintf( bw_ebuf, "di_init() received incorrect type %d",
  349. X           (*d_array)[ c ]->type );
  350. X        bw_error( bw_ebuf );
  351. #endif
  352. X        break;
  353. X     }
  354. X
  355. X      if ( ( (*t_array)[ c ] = (char *)
  356. X     malloc( strlen( bw_ebuf ) + 2 ) ) == NULL )
  357. X     {
  358. X     bw_error( DI_DMEMERR );
  359. X     sfs_exit();
  360. X     exit( 0 );
  361. X     }
  362. X      strcpy( (*t_array)[ c ], bw_ebuf );
  363. X      }
  364. X
  365. X   }
  366. X
  367. SHAR_EOF
  368. chmod 0644 sfs/sfs/sfs_di.c ||
  369. echo 'restore of sfs/sfs/sfs_di.c failed'
  370. Wc_c="`wc -c < 'sfs/sfs/sfs_di.c'`"
  371. test 6336 -eq "$Wc_c" ||
  372.     echo 'sfs/sfs/sfs_di.c: original size 6336, current size' "$Wc_c"
  373. rm -f _shar_wnt_.tmp
  374. fi
  375. # ============= sfs/sfs/sfs_ft.c ==============
  376. if test -f 'sfs/sfs/sfs_ft.c' -a X"$1" != X"-c"; then
  377.     echo 'x - skipping sfs/sfs/sfs_ft.c (File already exists)'
  378.     rm -f _shar_wnt_.tmp
  379. else
  380. > _shar_wnt_.tmp
  381. echo 'x - extracting sfs/sfs/sfs_ft.c (Text)'
  382. sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfs_ft.c' &&
  383. /***************************************************************
  384. X
  385. X    sfs_ft.c        Forward Track Routines for
  386. X            Space Flight Simulator
  387. X
  388. X            Copyright (c) 1991, Ted A. Campbell
  389. X
  390. X            Bywater Software
  391. X            P. O. Box 4023 
  392. X            Duke Station 
  393. X            Durham, NC  27706
  394. X
  395. X            email: tcamp@hercules.acpub.duke.edu
  396. X
  397. X    Copyright and Permissions Information:
  398. X
  399. X    All U.S. and international copyrights are claimed by the
  400. X    author. The author grants permission to use this code
  401. X    and software based on it under the following conditions:
  402. X    (a) in general, the code and software based upon it may be 
  403. X    used by individuals and by non-profit organizations; (b) it
  404. X    may also be utilized by governmental agencies in any country,
  405. X    with the exception of military agencies; (c) the code and/or
  406. X    software based upon it may not be sold for a profit without
  407. X    an explicit and specific permission from the author, except
  408. X    that a minimal fee may be charged for media on which it is
  409. X    copied, and for copying and handling; (d) the code must be 
  410. X    distributed in the form in which it has been released by the
  411. X    author; and (e) the code and software based upon it may not 
  412. X    be used for illegal activities. 
  413. X
  414. ***************************************************************/
  415. X
  416. #include "stdio.h"
  417. #include "ctype.h"
  418. #include "bw.h"
  419. #include "gr.h"
  420. #include "kb.h"
  421. #include "ui.h"
  422. #include "as.h"
  423. #include "sfs.h"
  424. X
  425. static double x_lat, x_lon;
  426. static long x_r, x_n;
  427. X
  428. ft_init( sorbit_array, orbit, poll )
  429. X   struct sfs_orbit **sorbit_array;
  430. X   int orbit;
  431. X   int (*poll)();
  432. X   {
  433. X   register int c;
  434. X
  435. X   sprintf( bw_ebuf, FT_NOTICE, orbit + 1 );
  436. #ifdef OLD_DEBUG
  437. X   bw_debug( bw_ebuf );
  438. #else
  439. X   bw_message( bw_ebuf );
  440. #endif
  441. X
  442. X   sorbit_array[ orbit ]->ft_inc = sorbit_array[ orbit ]->aorbit->period / (double) FT_POINTS;
  443. X
  444. X   sorbit_array[ orbit ]->ft_t = sfs_insertion;
  445. X   sorbit_array[ orbit ]->last_time = sorbit_array[ orbit ]->ft_t;
  446. X
  447. X   for ( c = 0; c < FT_POINTS;  ++c )
  448. X      {
  449. X
  450. X      or_ssp( sorbit_array[ orbit ]->aorbit, sorbit_array[ orbit ]->ft_t, &x_lat, &x_lon, &x_r, &x_n );
  451. X      sorbit_array[ orbit ]->ft_buffer[ c ].latitude  = x_lat;
  452. X      sorbit_array[ orbit ]->ft_buffer[ c ].longitude = x_lon;
  453. X      sorbit_array[ orbit ]->ft_buffer[ c ].altitude  = x_r;
  454. X      sorbit_array[ orbit ]->ft_t += sorbit_array[ orbit ]->ft_inc;
  455. X
  456. X      /* call poll function */
  457. X
  458. X      (*poll) ();
  459. X
  460. X      }
  461. X
  462. X   sorbit_array[ orbit ]->ft_bufstart = 0;
  463. X   sorbit_array[ orbit ]->ft_bufpos   = FT_POINTS - 1;
  464. X
  465. X   }
  466. X
  467. ft_calc( newtime, sorbit_array, orbit, poll )
  468. X   long newtime;
  469. X   struct sfs_orbit **sorbit_array;
  470. X   int orbit;
  471. X   int (*poll)();
  472. X   {
  473. X   register int c;
  474. X   int number;
  475. X
  476. X   number = ( newtime - sorbit_array[ orbit ]->last_time )
  477. X      / sorbit_array[ orbit ]->ft_inc;
  478. X
  479. X   sprintf( bw_ebuf, FT_CALC, orbit );
  480. X   bw_message( bw_ebuf );
  481. X
  482. X   for ( c = 0; c < number; c++ )
  483. X      {
  484. X
  485. X      or_ssp( sorbit_array[ orbit ]->aorbit, sorbit_array[ orbit ]->ft_t,
  486. X     &x_lat, &x_lon, &x_r, &x_n );
  487. X      sorbit_array[ orbit ]->ft_buffer[ sorbit_array[ orbit ]->ft_bufpos ].latitude  = x_lat;
  488. X      sorbit_array[ orbit ]->ft_buffer[ sorbit_array[ orbit ]->ft_bufpos ].longitude = x_lon;
  489. X      sorbit_array[ orbit ]->ft_buffer[ sorbit_array[ orbit ]->ft_bufpos ].altitude  = x_r;
  490. X      sorbit_array[ orbit ]->last_time += sorbit_array[ orbit ]->ft_inc;
  491. X      sorbit_array[ orbit ]->ft_t += sorbit_array[ orbit ]->ft_inc;
  492. X      ++sorbit_array[ orbit ]->ft_bufpos;
  493. X      if ( sorbit_array[ orbit ]->ft_bufpos == FT_POINTS )
  494. X     {
  495. X     sorbit_array[ orbit ]->ft_bufpos = 0;
  496. X     }
  497. X      ++sorbit_array[ orbit ]->ft_bufstart;
  498. X      if ( sorbit_array[ orbit ]->ft_bufstart == FT_POINTS )
  499. X     {
  500. X     sorbit_array[ orbit ]->ft_bufstart = 0;
  501. X     }
  502. X
  503. #ifdef  OLD_DEBUG
  504. X      sprintf( bw_ebuf, "Calculating forward track for orbit %d, position %d of %d",
  505. X      orbit, c, number );
  506. X      bw_message( bw_ebuf );
  507. #endif
  508. X
  509. X      /* call poll function */
  510. X
  511. X      (*poll) ();
  512. X
  513. X      }
  514. X   }
  515. X
  516. ft_plot( sorbit_array, orbit )
  517. X   struct sfs_orbit **sorbit_array;
  518. X   int orbit;
  519. X   {
  520. X   register int c;
  521. X
  522. X   c = sorbit_array[ orbit ]->ft_bufstart;
  523. X   while ( c != sorbit_array[ orbit ]->ft_bufpos )
  524. X      {
  525. X
  526. #ifdef  OLD_DEBUG
  527. X      sprintf( bw_ebuf, "Draw forward track, point %d, lat %.2lf, lon %.2lf",
  528. X     c,
  529. X     sorbit_array[ orbit ]->ft_buffer[ c ].latitude,
  530. X     sorbit_array[ orbit ]->ft_buffer[ c ].longitude );
  531. X      bw_debug( bw_ebuf );
  532. #endif
  533. X
  534. X      /* Draw the point simply by displaying a line to itself */
  535. X
  536. X      gt_line( sorbit_array[ orbit ]->ft_buffer[ c ].latitude,
  537. X      sorbit_array[ orbit ]->ft_buffer[ c ].longitude,
  538. X      sorbit_array[ orbit ]->ft_buffer[ c ].latitude,
  539. X      sorbit_array[ orbit ]->ft_buffer[ c ].longitude,
  540. X      cl_orbits[ orbit % 6 ], SOLID );
  541. X
  542. X      ++c;
  543. X      if ( c == FT_POINTS )
  544. X     {
  545. X     c = 0;
  546. X     }
  547. X      }
  548. X   }
  549. X
  550. X
  551. X
  552. SHAR_EOF
  553. chmod 0644 sfs/sfs/sfs_ft.c ||
  554. echo 'restore of sfs/sfs/sfs_ft.c failed'
  555. Wc_c="`wc -c < 'sfs/sfs/sfs_ft.c'`"
  556. test 4733 -eq "$Wc_c" ||
  557.     echo 'sfs/sfs/sfs_ft.c: original size 4733, current size' "$Wc_c"
  558. rm -f _shar_wnt_.tmp
  559. fi
  560. # ============= sfs/sfs/sfs_gt.c ==============
  561. if test -f 'sfs/sfs/sfs_gt.c' -a X"$1" != X"-c"; then
  562.     echo 'x - skipping sfs/sfs/sfs_gt.c (File already exists)'
  563.     rm -f _shar_wnt_.tmp
  564. else
  565. > _shar_wnt_.tmp
  566. echo 'x - extracting sfs/sfs/sfs_gt.c (Text)'
  567. sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfs_gt.c' &&
  568. /***************************************************************
  569. X
  570. X    sfs_gt.c        Ground Track Routines for SFS
  571. X
  572. X            Copyright (c) 1991, Ted A. Campbell
  573. X
  574. X            Bywater Software
  575. X            P. O. Box 4023 
  576. X            Duke Station 
  577. X            Durham, NC  27706
  578. X
  579. X            tcamp@hercules.acpub.duke.edu
  580. X
  581. X    Copyright and Permissions Information:
  582. X
  583. X    All U.S. and international copyrights are claimed by the
  584. X    author. The author grants permission to use this code
  585. X    and software based on it under the following conditions:
  586. X    (a) in general, the code and software based upon it may be 
  587. X    used by individuals and by non-profit organizations; (b) it
  588. X    may also be utilized by governmental agencies in any country,
  589. X    with the exception of military agencies; (c) the code and/or
  590. X    software based upon it may not be sold for a profit without
  591. X    an explicit and specific permission from the author, except
  592. X    that a minimal fee may be charged for media on which it is
  593. X    copied, and for copying and handling; (d) the code must be 
  594. X    distributed in the form in which it has been released by the
  595. X    author; and (e) the code and software based upon it may not 
  596. X    be used for illegal activities. 
  597. X
  598. ***************************************************************/
  599. X
  600. #include "stdio.h"
  601. #include "ctype.h"
  602. #include "bw.h"
  603. #include "gr.h"
  604. #include "kb.h"
  605. #include "ui.h"
  606. #include "as.h"
  607. #include "sfs.h"
  608. X
  609. #ifdef  __STDC__
  610. #include "stdlib.h"
  611. #endif
  612. X
  613. #define GT_DIVIDEND     4       /* Size of gt display on x should be this */
  614. #define GT_DIVISOR      2       /* ...divided by this (5/2 = 2.5 * y size */
  615. X
  616. static int gt_dready;           /* Data ready */
  617. static int gt_xsize;            /* Size of ground track map, x */
  618. static int gt_ysize;            /* Size of ground track map, y */
  619. static int gt_mapbase;          /* Bottom of gt map */
  620. static int gt_mapedge;          /* Left edge of groundtrack map */
  621. X
  622. /***************************************************************
  623. X
  624. X   gt_init()
  625. X
  626. X   This function provides all necessary initialization
  627. X   for the ground track system.
  628. X
  629. ***************************************************************/
  630. X
  631. gt_init( sorbit_array, orbit )
  632. X   struct sfs_orbit **sorbit_array;
  633. X   int orbit;
  634. X   {
  635. X   sorbit_array[ orbit ]->gt_bufstart
  636. X      = sorbit_array[ orbit ]->gt_bufpos = 0;
  637. X   gt_dready = FALSE;
  638. X   }
  639. X
  640. /***************************************************************
  641. X
  642. X   gt_update()
  643. X
  644. X   This function updates the ground track circular buffer
  645. X   by adding a new pair of latitude and longitude
  646. X   coordinates to the buffer.
  647. X
  648. ***************************************************************/
  649. X
  650. gt_update( newtime, sorbit_array, n_orbits )
  651. X   long newtime;
  652. X   struct sfs_orbit **sorbit_array;
  653. X   int n_orbits;
  654. X   {
  655. X   register int orbit;
  656. X   static double lat, lon;
  657. X   static long r, n;
  658. X
  659. X   for ( orbit = 0; orbit < n_orbits; ++orbit )
  660. X      {
  661. X
  662. #ifdef    OLD_DEBUG
  663. X      sprintf( bw_ebuf, "DEBUG: update orbit %d", orbit );
  664. X      bw_message( bw_ebuf );
  665. #endif
  666. X
  667. X      if ( sorbit_array[ orbit ] != NULL )
  668. X     {
  669. X     or_ssp( sorbit_array[ orbit ]->aorbit, newtime, &lat, &lon, &r, &n );
  670. X     sorbit_array[ orbit ]->gt_buffer[ sorbit_array[ orbit ]->gt_bufpos ][ 0 ] = lat;
  671. X     sorbit_array[ orbit ]->gt_buffer[ sorbit_array[ orbit ]->gt_bufpos ][ 1 ] = lon;
  672. X     ++sorbit_array[ orbit ]->gt_bufpos;
  673. X     if ( sorbit_array[ orbit ]->gt_bufpos == GT_POINTS )
  674. X        {
  675. X        sorbit_array[ orbit ]->gt_bufpos = 0;
  676. X        }
  677. X     if ( sorbit_array[ orbit ]->gt_bufpos == sorbit_array[ orbit ]->gt_bufstart )
  678. X        {
  679. X        ++sorbit_array[ orbit ]->gt_bufstart;
  680. X        if ( sorbit_array[ orbit ]->gt_bufstart == GT_POINTS )
  681. X           {
  682. X           sorbit_array[ orbit ]->gt_bufstart = 0;
  683. X           }
  684. X        }
  685. X     }              /* end if orbit != NULL */
  686. X      }                 /* end for orbits loop */
  687. X   gt_dready = TRUE;
  688. X
  689. #ifdef    OLD_DEBUG
  690. X   bw_debug( "Orbits updated" );
  691. #endif
  692. X   }
  693. X
  694. /***************************************************************
  695. X
  696. X   gt_draw()
  697. X
  698. X   This function draws the ground track screen.
  699. X   It is called by fo_draw().
  700. X
  701. ***************************************************************/
  702. X
  703. gt_draw( display, uiwind, focus, elements, redraw_screen,
  704. X   s_start, s_end, sorbit_array, n_orbits )
  705. X   struct sfs_display *display;
  706. X   struct uiwindow *uiwind;
  707. X   struct as_focus *focus;      /* orbital focus to display */
  708. X   unsigned int elements;
  709. X   int redraw_screen;
  710. X   struct spj_pt *s_start, *s_end;
  711. X   struct sfs_orbit **sorbit_array;
  712. X   int n_orbits;
  713. X   {
  714. X   register int orbit;
  715. X   int x, y;
  716. X
  717. #ifdef  OLD_DEBUG
  718. X   sprintf( bw_ebuf, "gt_draw(): %d %d %d %d", uiwind->u_x1, uiwind->u_y1,
  719. X      uiwind->u_x2, uiwind->u_y2 );
  720. X   bw_debug( bw_ebuf );
  721. #endif
  722. X
  723. X   bw_message( GT_DRAW );
  724. X
  725. X   if ( redraw_screen == TRUE )
  726. X      {
  727. X
  728. X      /* Prepare the screen */
  729. X
  730. X      gt_prep( uiwind );
  731. X      display->gt_xsize   = gt_xsize;
  732. X      display->gt_ysize   = gt_ysize;
  733. X      display->gt_mapbase = gt_mapbase;
  734. X      display->gt_mapedge = gt_mapedge;
  735. X
  736. #ifdef  OLD_DEBUG
  737. X      bw_debug( "Ready to draw grid" );
  738. #endif
  739. X
  740. X      /* Draw the surface features */
  741. X
  742. X      gt_plot( s_start, s_end, cl_surface, SOLID );
  743. X
  744. X      /* Display the point data if toggled */
  745. X
  746. #ifdef  USEPOINTS
  747. X      if ( ( elements & VI_POINTS ) > 0 )
  748. X     {
  749. X     gt_plot( p_start, p_end, cl_grid, SOLID );
  750. X     }
  751. #endif
  752. X
  753. X      /* Display the point titles if toggled */
  754. X
  755. #ifdef  USEPOINTS
  756. X      if ( ( elements & VI_PTITLES ) > 0 )
  757. X     {
  758. X     gt_titles( uiwind, p_start, p_end, cl_mback, cl_mfore );
  759. X     }
  760. #endif
  761. X
  762. X      /* Show toggle status */
  763. X
  764. X      el_show( GR_PRIMARY, uiwind, elements );
  765. X
  766. X      /* Title the screen */
  767. X
  768. X      sprintf( bw_ebuf, GT_WTITLE,
  769. X     focus->adjective );
  770. X      ui_wtitle( uiwind, bw_ebuf );
  771. X
  772. X     }
  773. X
  774. X   else
  775. X      {
  776. X      gt_xsize = display->gt_xsize;
  777. X      gt_ysize = display->gt_ysize;
  778. X      gt_mapbase = display->gt_mapbase;
  779. X      gt_mapedge = display->gt_mapedge;
  780. X      }
  781. X
  782. X   /* Show the ground track */
  783. X
  784. X   for ( orbit = 0; orbit < n_orbits; ++orbit )
  785. X      {
  786. X      if ( ( sorbit_array[ orbit ] != NULL )
  787. X         && ( sorbit_array[ orbit ]->aorbit->focus == focus ))
  788. X     {
  789. X     gt_track( sorbit_array, orbit, cl_orbits[ orbit % 6 ] );
  790. X     }                              /* end if orbit != NULL */
  791. X      }                                 /* end for orbit loop */
  792. X
  793. X   }
  794. X
  795. /***************************************************************
  796. X
  797. X   gt_prep()
  798. X
  799. X   This routine draws the panel at the bottom of the screen
  800. X   which contains various parameters and is used when the
  801. X   ground track display is in effect.  The routine is called
  802. X   by gt_draw().
  803. X
  804. ***************************************************************/
  805. X
  806. gt_prep( uiwind )
  807. X   struct uiwindow *uiwind;
  808. X   {
  809. X   register int c;
  810. X   int inc;
  811. X   double x;
  812. X   int x_xmax, x_ymax;
  813. X
  814. #ifdef  OLD_DEBUG
  815. X   bw_debug( "gt_prep(): enter" );
  816. #endif
  817. X
  818. X   /***  Blank the entire window area */
  819. X
  820. X   ui_fbox( uiwind->u_x1, uiwind->u_y1,
  821. X      uiwind->u_x2, uiwind->u_y2, BLACK, SOLID );
  822. X
  823. X   /***  First determine if x or y axis must be scaled */
  824. X
  825. X   x_xmax = uiwind->u_x2 - uiwind->u_x1;
  826. X   x_ymax = uiwind->u_y2 - uiwind->u_y1;
  827. X
  828. X   if ( ( x_xmax / 2 ) >
  829. X    ( ( x_ymax * gr_pysize ) / gr_pxsize )
  830. X      )
  831. X
  832. X      {                              /* TRUE = scale x */
  833. X
  834. #ifdef  OLD_DEBUG
  835. X      bw_debug( "Scaling x" );
  836. #endif
  837. X
  838. X      gt_ysize = x_ymax;
  839. X      gt_xsize = 2 * (( gt_ysize * gr_pysize ) / gr_pxsize );
  840. X
  841. X      /***  Calculate gt_mapedge */
  842. X
  843. X      gt_mapedge = uiwind->u_x1 +
  844. X     ( ( x_xmax - gt_xsize ) / 2 );
  845. X
  846. X      /***  Calculate gt_mapbase */
  847. X
  848. X      gt_mapbase = uiwind->u_y1;
  849. X
  850. X      /***  Draw lines demarcating the display within the window */
  851. X
  852. X      gr_line( GR_PRIMARY, gt_mapedge, gt_mapbase, gt_mapedge,
  853. X     uiwind->u_y2, cl_grid, SOLID );
  854. X
  855. X      gr_line( GR_PRIMARY, gt_mapedge + gt_xsize, gt_mapbase,
  856. X     gt_mapedge + gt_xsize, uiwind->u_y2,
  857. X     cl_grid, SOLID );
  858. X
  859. X      }
  860. X
  861. X   else                             /* FALSE = scale y */
  862. X      {
  863. X
  864. #ifdef  OLD_DEBUG
  865. X      bw_debug( "Scaling y" );
  866. #endif
  867. X
  868. X      gt_xsize = x_xmax;
  869. X      gt_ysize = (( gt_xsize * gr_pxsize ) / gr_pysize ) / 2;
  870. X
  871. X      /***  Calculate gt_mapedge */
  872. X
  873. X      gt_mapedge = uiwind->u_x1;
  874. X
  875. X      /***  Calculate gt_mapbase */
  876. X
  877. X      gt_mapbase = uiwind->u_y1 +
  878. X     ( ( x_ymax - gt_ysize ) / 2 );
  879. X
  880. X      /***  Draw lines demarcating the display within the window */
  881. X
  882. X      gr_line( GR_PRIMARY, uiwind->u_x1, gt_mapbase, uiwind->u_x2,
  883. X     gt_mapbase, cl_grid, SOLID );
  884. X
  885. X      gr_line( GR_PRIMARY, uiwind->u_x1, gt_mapbase + gt_ysize,
  886. X     uiwind->u_x2, gt_mapbase + gt_ysize,
  887. X     cl_grid, SOLID );
  888. X
  889. X      }
  890. X
  891. #ifdef  OLD_DEBUG
  892. X   sprintf( bw_ebuf, "x_size %d, y_size %d, mapedge %d, mapbase %d",
  893. X      gt_xsize, gt_ysize, gt_mapedge, gt_mapbase );
  894. X   bw_debug( bw_ebuf );
  895. #endif
  896. X
  897. X   /***  Now draw the latitude and longitude lines. We must draw
  898. X     only a quarter of a line at a time, or gt_line will
  899. X     reject the request. */
  900. X
  901. X   for ( x = -75.0; x < 90.0; x += 15.0 )               /* latitudes */
  902. X      {
  903. X      gt_line( x, -180.0, x, -90.0, cl_grid, GRID );
  904. X      gt_line( x,  -90.0, x,   0.0, cl_grid, GRID );
  905. X      gt_line( x,    0.0, x,  90.0, cl_grid, GRID );
  906. X      gt_line( x,   90.0, x, 180.0, cl_grid, GRID );
  907. X      }
  908. X
  909. X   for ( x = -165.0; x < 180.0; x += 15.0 )             /* longitudes */
  910. X      {
  911. X      gt_line( -90.0, x, -45.0, x, cl_grid, GRID );
  912. X      gt_line( -45.0, x,   0.0, x, cl_grid, GRID );
  913. X      gt_line(   0.0, x,  45.0, x, cl_grid, GRID );
  914. X      gt_line(  45.0, x,  90.0, x, cl_grid, GRID );
  915. X      }
  916. X
  917. #ifdef  OLD_DEBUG
  918. X   bw_debug( "end of gt_prep() " );
  919. #endif
  920. X
  921. X   }
  922. X
  923. /***************************************************************
  924. X
  925. X   gt_plot()
  926. X
  927. X   This routine plots a set of coordinates on the ground
  928. X   track map.  It is called by gt_draw().
  929. X
  930. ***************************************************************/
  931. X
  932. gt_plot( start, end, color, style )
  933. X   struct spj_pt *start, *end;
  934. X   int color, style;
  935. X   {
  936. X   struct spj_pt *current;
  937. X   double prevx, prevy;
  938. X
  939. X   current = start->next;
  940. X
  941. #ifdef  OLD_DEBUG
  942. X   bw_debug( "DEBUG:  Plotting" );
  943. #endif
  944. X
  945. X   prevx = current->longitude;
  946. X   prevy = current->latitude;
  947. X   while ( current != end )
  948. X      {
  949. X      if ( current->code < 1000 )
  950. X     {
  951. X     gt_line( current->latitude, current->longitude,
  952. X        prevy, prevx, color, style );
  953. X     }
  954. X      prevx = current->longitude;
  955. X      prevy = current->latitude;
  956. X      current = current->next;
  957. X      }
  958. X
  959. #ifdef  OLD_DEBUG
  960. X   bw_message( " " );
  961. #endif
  962. X   }
  963. X
  964. gt_titles( uiwind, start, end, background, foreground )
  965. X   struct uiwindow *uiwind;
  966. X   struct spj_pt *start, *end;
  967. X   int background, foreground;
  968. X   {
  969. X   struct spj_pt *current;
  970. X   int x, y;
  971. X
  972. X   /* Turn clipping on */
  973. X
  974. X   gr_clip( GR_PRIMARY, TRUE, gt_mapedge, gt_mapbase,
  975. X      gt_mapedge + gt_xsize, uiwind->u_y2 );
  976. X
  977. X   current = start;
  978. X   while( current != end )
  979. X      {
  980. X      x = ( current->longitude + 180.0 ) * ( gt_xsize / 360.0 );
  981. X      y = ( current->latitude + 90.0 ) * ( gt_ysize / 180.0 );
  982. X      x = gt_mapedge + x;
  983. X
  984. X      gr_text( GR_PRIMARY,
  985. X     x + 3,
  986. X     y - ( ui_grwind->fysize / 2 ),
  987. X     current->name, foreground, background );
  988. X
  989. X      current = current->next;
  990. X      }
  991. X
  992. X   /* Turn clipping off */
  993. X
  994. X   gr_clip( GR_PRIMARY, FALSE, 0, 0, 0, 0 );
  995. X
  996. X   }
  997. X
  998. /***************************************************************
  999. X
  1000. X   gt_track()
  1001. X
  1002. X   This routine draws the spacecraft ground-track path on
  1003. X   the ground track map.  It is called by gt_draw().
  1004. X
  1005. ***************************************************************/
  1006. X
  1007. gt_track( sorbit_array, orbit, color )
  1008. X   struct sfs_orbit **sorbit_array;
  1009. X   int orbit, color;
  1010. X   {
  1011. X   int current;
  1012. X
  1013. X   if ( gt_dready != TRUE )
  1014. X      {
  1015. X      bw_error( GTERR_NODATA );
  1016. X      return BW_ERROR;
  1017. X      }
  1018. X
  1019. X   current = sorbit_array[ orbit ]->gt_bufstart + 1;
  1020. X   if ( current == GT_POINTS )
  1021. X      {
  1022. X      current = 0;
  1023. X      }
  1024. X
  1025. #ifdef  OLD_DEBUG
  1026. X   bw_message( "DEBUG:  Tracking " );
  1027. #endif
  1028. X
  1029. X   while ( current != sorbit_array[ orbit ]->gt_bufpos )
  1030. X      {
  1031. X      if ( current == 0 )
  1032. X     {
  1033. #ifdef  OLD_DEBUG
  1034. X     sprintf( bw_ebuf, "gt_track from x = %.2lf y = %.2lf, to x = %.2lf y = %.2lf, color = %d, style = %d,",
  1035. X        sorbit_array[ orbit ]->gt_buffer[ GT_POINTS - 1 ][ 0 ],
  1036. X        sorbit_array[ orbit ]->gt_buffer[ GT_POINTS - 1 ][ 1 ],
  1037. X        sorbit_array[ orbit ]->gt_buffer[ current       ][ 0 ],
  1038. X        sorbit_array[ orbit ]->gt_buffer[ current       ][ 1 ],
  1039. X        color, SOLID );
  1040. X     bw_debug( bw_ebuf );
  1041. #endif
  1042. X     gt_line( sorbit_array[ orbit ]->gt_buffer[ GT_POINTS - 1 ][ 0 ],
  1043. X          sorbit_array[ orbit ]->gt_buffer[ GT_POINTS - 1 ][ 1 ],
  1044. X          sorbit_array[ orbit ]->gt_buffer[ current       ][ 0 ],
  1045. X          sorbit_array[ orbit ]->gt_buffer[ current       ][ 1 ],
  1046. X          color, SOLID );
  1047. X     }
  1048. X      else
  1049. X     {
  1050. #ifdef  OLD_DEBUG
  1051. X     sprintf( bw_ebuf, "gt_track from x = %.2lf y = %.2lf, to x = %.2lf y = %.2lf, color = %d, style = %d,",
  1052. X        sorbit_array[ orbit ]->gt_buffer[ current - 1   ][ 0 ],
  1053. X        sorbit_array[ orbit ]->gt_buffer[ current - 1   ][ 1 ],
  1054. X        sorbit_array[ orbit ]->gt_buffer[ current       ][ 0 ],
  1055. X        sorbit_array[ orbit ]->gt_buffer[ current       ][ 1 ],
  1056. X        color, SOLID );
  1057. X     bw_debug( bw_ebuf );
  1058. #endif
  1059. X     gt_line( sorbit_array[ orbit ]->gt_buffer[ current - 1 ][ 0 ],
  1060. X          sorbit_array[ orbit ]->gt_buffer[ current - 1 ][ 1 ],
  1061. X          sorbit_array[ orbit ]->gt_buffer[ current     ][ 0 ],
  1062. X          sorbit_array[ orbit ]->gt_buffer[ current     ][ 1 ],
  1063. X          color, SOLID );
  1064. X     }
  1065. X      ++current;
  1066. X      if ( current == GT_POINTS )
  1067. X     {
  1068. X     current = 0;
  1069. X     }
  1070. X      }
  1071. X
  1072. X   /* Now plot the forward track */
  1073. X
  1074. X   ft_plot( sorbit_array, orbit );
  1075. X
  1076. X   }
  1077. X
  1078. /***************************************************************
  1079. X
  1080. X   gt_line()
  1081. X
  1082. X   This routine draws a single line on the ground
  1083. X   track map.
  1084. X
  1085. ***************************************************************/
  1086. X
  1087. gt_line( fromlat, fromlon, tolat, tolon, color, style )
  1088. X   double fromlat, fromlon, tolat, tolon;
  1089. X   int color, style;
  1090. X   {
  1091. X   int x1, y1, x2, y2;
  1092. X
  1093. #ifdef  DEBUG
  1094. X   if ( ( fromlat < -90.0 ) || ( fromlat > 90.0 ))
  1095. X      {
  1096. X      sprintf( bw_ebuf, "gt_line received from latitude %.2lf", fromlat );
  1097. X      bw_error( bw_ebuf );
  1098. X      return BW_ERROR;
  1099. X      }
  1100. X   if ( ( tolat < -90.0 ) || ( tolat > 90.0 ))
  1101. X      {
  1102. X      sprintf( bw_ebuf, "gt_line received to latitude %.2lf", tolat );
  1103. X      bw_error( bw_ebuf );
  1104. X      return BW_ERROR;
  1105. X      }
  1106. X   if ( ( fromlon < -180.0 ) || ( fromlon > 180.0 ))
  1107. X      {
  1108. X      sprintf( bw_ebuf, "gt_line received from longitude %.2lf", fromlon );
  1109. X      bw_error( bw_ebuf );
  1110. X      return BW_ERROR;
  1111. X      }
  1112. X   if ( ( tolon < -180.0 ) || ( tolon > 180.0 ))
  1113. X      {
  1114. X      sprintf( bw_ebuf, "gt_line received to longitude %.2lf", tolon );
  1115. X      bw_error( bw_ebuf );
  1116. X      return BW_ERROR;
  1117. X      }
  1118. #endif
  1119. X
  1120. #ifdef  OLD_DEBUG
  1121. X   sprintf( bw_ebuf, "DEBUG from x = %.2lf, from y = %.2lf, to x = %.2lf, to y = %.2lf, color = %d, style = %d,",
  1122. X      fromlon,
  1123. X      fromlat,
  1124. X      tolon,
  1125. X      tolat,
  1126. X      color, style );
  1127. X   bw_debug( bw_ebuf );
  1128. #endif
  1129. X
  1130. X   x1 = (( fromlon + 180.0 ) * ( gt_xsize / 360.0 ));
  1131. X   x2 = ((   tolon + 180.0 ) * ( gt_xsize / 360.0 ));
  1132. X
  1133. X   if ( abs( x1 - x2 ) > ( gt_xsize / 3 ) )
  1134. X      {
  1135. #ifdef  OLD_DEBUG
  1136. X      sprintf( sfs_tbuf, "DEBUG: gt_line() failed: x1 = %d, x2 = %d",
  1137. X     x1, x2 );
  1138. X      bw_debug( sfs_tbuf );
  1139. X      sprintf( sfs_tbuf, "DEBUG: gt_line() #2: abs() = %d, gt_xsize = %d, gt_xsize / 3 = %d",
  1140. X     abs( x1 - x2), gt_xsize, (gt_xsize / 3) );
  1141. X      bw_debug( sfs_tbuf );
  1142. #endif
  1143. X      return;
  1144. X      }
  1145. X
  1146. X   y1 = (( fromlat + 90.0 ) * ( gt_ysize / 180.0 ));
  1147. X   y2 = ((   tolat + 90.0 ) * ( gt_ysize / 180.0 ));
  1148. X
  1149. X   if ( abs( y1 - y2 ) > ( gt_ysize / 3 ) )
  1150. X      {
  1151. #ifdef  OLD_DEBUG
  1152. X      sprintf( sfs_tbuf, "gt_line() failed: y1 = %d, y2 = %d",
  1153. X     y1, y2 );
  1154. X      bw_debug( sfs_tbuf );
  1155. #endif
  1156. X      return;
  1157. X      }
  1158. X
  1159. #ifdef  OLD_DEBUG
  1160. X   sprintf( sfs_tbuf, "DEBUG x1 = %d, y1 = %d, x2 = %d, y2 = %d, color = %d, style = %d,",
  1161. X      gt_mapedge + x1,
  1162. X      gt_mapbase + y1,
  1163. X      gt_mapedge + x2,
  1164. X      gt_mapbase + y2,
  1165. X      color, style );
  1166. X   bw_debug( sfs_tbuf );
  1167. #endif
  1168. X
  1169. X   gr_line( GR_PRIMARY,
  1170. X      gt_mapedge + x1,
  1171. X      gt_mapbase + y1,
  1172. X      gt_mapedge + x2,
  1173. X      gt_mapbase + y2,
  1174. X      color, style );
  1175. X   }
  1176. SHAR_EOF
  1177. chmod 0644 sfs/sfs/sfs_gt.c ||
  1178. echo 'restore of sfs/sfs/sfs_gt.c failed'
  1179. Wc_c="`wc -c < 'sfs/sfs/sfs_gt.c'`"
  1180. test 15884 -eq "$Wc_c" ||
  1181.     echo 'sfs/sfs/sfs_gt.c: original size 15884, current size' "$Wc_c"
  1182. rm -f _shar_wnt_.tmp
  1183. fi
  1184. # ============= sfs/sfs/sfs_pe.c ==============
  1185. if test -f 'sfs/sfs/sfs_pe.c' -a X"$1" != X"-c"; then
  1186.     echo 'x - skipping sfs/sfs/sfs_pe.c (File already exists)'
  1187.     rm -f _shar_wnt_.tmp
  1188. else
  1189. > _shar_wnt_.tmp
  1190. echo 'x - extracting sfs/sfs/sfs_pe.c (Text)'
  1191. sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfs_pe.c' &&
  1192. /***************************************************************
  1193. X
  1194. X    sfs_pe.c        Distant Perspective Display Routines for
  1195. X            Space Flight Simulator
  1196. X
  1197. X            Copyright (c) 1991, Ted A. Campbell
  1198. X
  1199. X            Bywater Software
  1200. X            P. O. Box 4023 
  1201. X            Duke Station 
  1202. X            Durham, NC  27706
  1203. X
  1204. X            email: tcamp@hercules.acpub.duke.edu
  1205. X
  1206. X    Copyright and Permissions Information:
  1207. X
  1208. X    All U.S. and international copyrights are claimed by the
  1209. X    author. The author grants permission to use this code
  1210. X    and software based on it under the following conditions:
  1211. X    (a) in general, the code and software based upon it may be 
  1212. X    used by individuals and by non-profit organizations; (b) it
  1213. X    may also be utilized by governmental agencies in any country,
  1214. X    with the exception of military agencies; (c) the code and/or
  1215. X    software based upon it may not be sold for a profit without
  1216. X    an explicit and specific permission from the author, except
  1217. X    that a minimal fee may be charged for media on which it is
  1218. X    copied, and for copying and handling; (d) the code must be 
  1219. X    distributed in the form in which it has been released by the
  1220. X    author; and (e) the code and software based upon it may not 
  1221. X    be used for illegal activities. 
  1222. X
  1223. ***************************************************************/
  1224. X
  1225. #include "stdio.h"
  1226. #include "ctype.h"
  1227. #include "bw.h"
  1228. #include "gr.h"
  1229. #include "kb.h"
  1230. #include "ui.h"
  1231. #include "as.h"
  1232. #include "sfs.h"
  1233. X
  1234. #define USEHIDDEN          /* use hidden buffer to draw perspective */
  1235. #define PE_VLAT         0.0
  1236. #define PE_VLON         0.0
  1237. #define PE_ROT          0.0
  1238. X
  1239. /***************************************************************
  1240. X
  1241. X    pe_calc()
  1242. X
  1243. ***************************************************************/
  1244. X
  1245. pe_calc( sorbit_array, n_orbits, poll )
  1246. X   struct sfs_orbit **sorbit_array;
  1247. X   int n_orbits;
  1248. X   int (*poll)();
  1249. X   {
  1250. X   register int orbit, c;
  1251. X   static double x_lat, x_lon;
  1252. X   double save_lif;
  1253. X   static long x_r, x_t, x_n;
  1254. X
  1255. X   for ( orbit = 0; orbit < n_orbits; ++orbit )
  1256. X      {
  1257. X
  1258. X      if ( sorbit_array[ orbit ] != NULL )
  1259. X     {
  1260. X
  1261. X     sprintf( bw_ebuf, PE_CALC,
  1262. X        orbit + 1 );
  1263. X     bw_message( bw_ebuf );
  1264. X
  1265. X     save_lif = sorbit_array[ orbit ]->aorbit->lif;
  1266. X     sorbit_array[ orbit ]->aorbit->lif = 0.0;
  1267. X
  1268. X     sorbit_array[ orbit ]->pe_inc = sorbit_array[ orbit ]->aorbit->period / PE_POINTS;
  1269. X
  1270. X     x_t = 1;
  1271. X
  1272. X     for ( c = 0; c < PE_POINTS; ++c )
  1273. X        {
  1274. X
  1275. X        or_ssp( sorbit_array[ orbit ]->aorbit, x_t,
  1276. X           &x_lat, &x_lon, &x_r, &x_n );
  1277. X
  1278. X        sorbit_array[ orbit ]->pe_buffer[ c ].altitude  = x_r;
  1279. X        sorbit_array[ orbit ]->pe_buffer[ c ].latitude  = x_lat;
  1280. X        sorbit_array[ orbit ]->pe_buffer[ c ].longitude = x_lon;
  1281. X
  1282. X        x_t += sorbit_array[ orbit ]->pe_inc;
  1283. X
  1284. X        /* call poll function */
  1285. X
  1286. X        (*poll) ();
  1287. X
  1288. X        }                   /* end for point++ */
  1289. X
  1290. X     sorbit_array[ orbit ]->aorbit->lif = save_lif;
  1291. X
  1292. X     }                      /* end if orbit != NULL */
  1293. X
  1294. X     }                         /* end while ++orbit */
  1295. X   }                            /* end of function
  1296. X
  1297. /***************************************************************
  1298. X
  1299. X    pe_draw()
  1300. X
  1301. ***************************************************************/
  1302. X
  1303. pe_draw( uiwind, focus, sorbit_array, n_orbits, o_start, o_end, newtime, elements )
  1304. X   struct uiwindow *uiwind;             /* ui  window to draw in */
  1305. X   struct as_focus *focus;              /* orbital focus to display */
  1306. X   struct sfs_orbit **sorbit_array;     /* array of orbits */
  1307. X   int n_orbits;                        /* number of orbits in array */
  1308. X   struct spj_pt *o_start, *o_end;      /* start, end orb display pattern */
  1309. X   long newtime;                        /* current time */
  1310. X   int elements;            /* elements to draw */
  1311. X   {
  1312. X   register int orbit;
  1313. X   static double vlat, vlon, rotation;
  1314. X   static double distance;
  1315. X   static double vert_degrees;          /* calculate vertical degrees */
  1316. X   double max_ap;
  1317. X   int l, c, selected;
  1318. X   int x_screen;
  1319. X
  1320. X   /***  inform the viewer */
  1321. X
  1322. X   bw_message( PE_DRAW );
  1323. X
  1324. X   /***  initial screen setup */
  1325. X
  1326. #ifdef  USEHIDDEN
  1327. X   if ( gr_screens > 1 )
  1328. X      {
  1329. X      x_screen = GR_HIDDEN;
  1330. X      }
  1331. X   else
  1332. X      {
  1333. X      x_screen = GR_PRIMARY;
  1334. X      }
  1335. X   ui_setscreen( x_screen );
  1336. #else
  1337. X   x_screen = GR_PRIMARY;
  1338. #endif
  1339. X
  1340. X   /* calculate vertical degrees */
  1341. X
  1342. X   vert_degrees = HORDEGS * ( ( ( uiwind->u_y2 - (double) uiwind->u_y1 )
  1343. X      * ( gr_pysize / (double) gr_pxsize ) )
  1344. X      / ( uiwind->u_x2 - (double) uiwind->u_x1 ) );
  1345. X
  1346. #ifdef  OLD_DEBUG
  1347. X   sprintf( bw_ebuf, "Vert degrees: %.0lf", vert_degrees );
  1348. X   bw_debug( bw_ebuf );
  1349. #endif
  1350. X
  1351. X   /* Clear the display area */
  1352. X
  1353. X   ui_fbox( uiwind->u_x1, uiwind->u_y1,
  1354. X      uiwind->u_x2, uiwind->u_y2,
  1355. X      BLACK, SOLID );
  1356. X
  1357. X   /* Calculate viewer latitude, longitude, rotation, and distance of display */
  1358. X
  1359. X   vlat = PE_VLAT;
  1360. X   vlon = PE_VLON;
  1361. X   rotation = PE_ROT;
  1362. X   max_ap = 1.0;
  1363. X
  1364. #ifdef  OLD_DEBUG
  1365. X   sprintf( bw_ebuf, "pe_draw(): n_orbits %d", n_orbits );
  1366. X   bw_debug( bw_ebuf );
  1367. #endif
  1368. X
  1369. X   /* find the largest apoapsis among all selected orbits */
  1370. X
  1371. X   selected = n_orbits + 1;
  1372. X   for ( orbit = 0; orbit < n_orbits; ++orbit )
  1373. X      {
  1374. X      if ( ( sorbit_array[ orbit ] != NULL ) 
  1375. X         && ( sorbit_array[ orbit ]->aorbit->focus == focus ))
  1376. X     {
  1377. X
  1378. X         selected = orbit;        /* make sure we find at least
  1379. X                       one selected orbit */
  1380. X     if ( max_ap < sorbit_array[ orbit ]->aorbit->apoapsis )
  1381. X        {
  1382. X        max_ap = sorbit_array[ orbit ]->aorbit->apoapsis;
  1383. #ifdef  OLD_DEBUG
  1384. X        sprintf( bw_ebuf, "pe_draw(): orbit %d, apoapsis = %.2g km",
  1385. X           orbit,
  1386. X           sorbit_array[ orbit ]->aorbit->apoapsis );
  1387. X        bw_debug( bw_ebuf );
  1388. #endif
  1389. X        }
  1390. X     }                /* if orbit selected */
  1391. X      }                    /* for loop */
  1392. X
  1393. #ifdef  DEBUG
  1394. X   if ( selected == ( n_orbits + 1 ) )
  1395. X      {
  1396. X      bw_error( "[pr:] pe_draw(): no orbits initialized" );
  1397. X      return BW_ERROR;
  1398. X      }
  1399. #endif
  1400. X
  1401. X   /* initial distance is max_ap plus focal radius */
  1402. X
  1403. X   distance = max_ap + sorbit_array[ selected ]->aorbit->focus->radius;
  1404. X
  1405. X   /* increase distance until the entire image will fit in the screen */
  1406. X
  1407. X   while( spj_angrad( distance, max_ap + sorbit_array[ selected ]->aorbit->focus->radius )
  1408. X      > ( vert_degrees / 2.0 ) )
  1409. X      {
  1410. X
  1411. X      distance *= 2.0;
  1412. X
  1413. #ifdef  OLD_DEBUG
  1414. X   sprintf( bw_ebuf, "pe_draw(): distance %.0lf km; ang. radius %.2lf deg",
  1415. X      distance, spj_angrad( distance, sorbit_array[ selected ]->aorbit->focus->radius ));
  1416. X   bw_debug( bw_ebuf );
  1417. #endif
  1418. X
  1419. X      }
  1420. X
  1421. X   /* Show the orbits */
  1422. X
  1423. X   pe_plot( x_screen, uiwind, sorbit_array, n_orbits, vlat, vlon, rotation,
  1424. X      distance, o_start, o_end, newtime, focus );
  1425. X
  1426. X   /***  Show crosshairs */
  1427. X
  1428. #ifdef  BLOCKEDOUT
  1429. X   pe_crosshair( uiwind, HORDEGS, x_screen );
  1430. #endif
  1431. X
  1432. X   /* Show toggle status */
  1433. X
  1434. X   el_show( x_screen, uiwind, elements );
  1435. X
  1436. X   /***  blit and return screen to original state */
  1437. X
  1438. #ifdef  USEHIDDEN
  1439. X   if ( gr_screens > 1 )
  1440. X      {
  1441. X      gr_blit( GR_HIDDEN, GR_PRIMARY, uiwind->u_x1, uiwind->u_y1,
  1442. X     uiwind->u_x2, uiwind->u_y2 );
  1443. X      }
  1444. X   ui_setscreen( GR_PRIMARY );
  1445. #endif
  1446. X
  1447. X   /* Title the screen */
  1448. X
  1449. X   sprintf( bw_ebuf, PE_WTITLE,
  1450. X      focus->name,
  1451. X      distance, sorbit_array[ selected ]->pe_inc );
  1452. X   ui_wtitle( uiwind, bw_ebuf );
  1453. X
  1454. X   }
  1455. X
  1456. /***************************************************************
  1457. X
  1458. X    pe_plot()
  1459. X
  1460. X    This routine draws all orbits as they appear in space.
  1461. X
  1462. ***************************************************************/
  1463. X
  1464. pe_plot( screen, uiwind, sorbit_array, n_orbits, vlat, vlon, rotation, vdis,
  1465. X   o_start, o_end, newtime, focus )
  1466. X   int screen;
  1467. X   struct uiwindow *uiwind;             /* ui  window to draw in */
  1468. X   struct sfs_orbit **sorbit_array;
  1469. X   int n_orbits;
  1470. X   double vlat, vlon, rotation;
  1471. X   double vdis;
  1472. X   struct spj_pt *o_start, *o_end;      /* start, end orb display pattern */
  1473. X   long newtime;
  1474. X   struct as_focus *focus;
  1475. X   {
  1476. X   register int orbit, c;
  1477. X   static double x, y;
  1478. X   static int v;
  1479. X   double prevx, prevy;
  1480. X   int prevv;
  1481. X   static struct uiwindow *oldwind = NULL; /* save window pointer to avoid recalculation */
  1482. X   static int x_midx, x_midy;           /* x, y mid points of window */
  1483. X   static double x_xfactor, x_yfactor;  /* factors for x, y expansion in window */
  1484. X   static double vert_degrees;          /* calculate vertical degrees */
  1485. X   int selected;
  1486. X   long x_tio;                          /* time into orbit */
  1487. X
  1488. X   /* set up the window if necessary */
  1489. X
  1490. X   if ( uiwind != oldwind )
  1491. X      {
  1492. X      x_xfactor = ( uiwind->u_x2 - (double) uiwind->u_x1 ) / HORDEGS;
  1493. X      vert_degrees = HORDEGS * ( ( ( uiwind->u_y2 - (double) uiwind->u_y1 )
  1494. X     * ( gr_pysize / (double) gr_pxsize ) )
  1495. X     / ( uiwind->u_x2 - (double) uiwind->u_x1 ) );
  1496. X      x_yfactor = ( uiwind->u_y2 - (double) uiwind->u_y1 ) / vert_degrees;
  1497. X      x_midx = uiwind->u_x1 + (( uiwind->u_x2 - (double) uiwind->u_x1 ) / 2.0 );
  1498. X      x_midy = uiwind->u_y1 + (( uiwind->u_y2 - (double) uiwind->u_y1 ) / 2.0 );
  1499. X      oldwind = uiwind;
  1500. X      }
  1501. X
  1502. X   /* Show the far side of each orbit */
  1503. X
  1504. X   selected = n_orbits + 1;
  1505. X   for ( orbit = 0; orbit < n_orbits; ++orbit )
  1506. X      {
  1507. X      if ( ( sorbit_array[ orbit ] != NULL )
  1508. X         && ( sorbit_array[ orbit ]->aorbit->focus == focus ))
  1509. X     {
  1510. #ifdef  OLD_DEBUG
  1511. X         sprintf( bw_ebuf, "Draw far side, orbit %d", orbit );
  1512. X         bw_debug( bw_ebuf );
  1513. #endif
  1514. X     selected = orbit;
  1515. X     x_tio = newtime % (long) sorbit_array[ orbit ]->aorbit->period;
  1516. X     pe_show( screen, sorbit_array, orbit, x_tio,
  1517. X        vlat, vlon, vdis, rotation,
  1518. X        x_xfactor, x_yfactor, x_midx, x_midy,
  1519. X        SPJ_FARSIDE, cl_orbits[ orbit % 6 ], SOLID );
  1520. X     }
  1521. X      }
  1522. X
  1523. X   /* Show the orb of the planet */
  1524. X
  1525. X   pe_orb( uiwind, screen,
  1526. X      sorbit_array[ selected ]->aorbit->focus->radius,
  1527. X      vdis, cl_grid, x_midx, x_midy, x_xfactor, x_yfactor );
  1528. X
  1529. X   /* Now show the near side of each orbit */
  1530. X
  1531. X   for ( orbit = 0; orbit < n_orbits; ++orbit )
  1532. X      {
  1533. X      if ( ( sorbit_array[ orbit ] != NULL )
  1534. X         && ( sorbit_array[ orbit ]->aorbit->focus == focus ))
  1535. X     {
  1536. #ifdef  OLD_DEBUG
  1537. X         sprintf( bw_ebuf, "Draw near side, orbit %d", orbit );
  1538. X         bw_debug( bw_ebuf );
  1539. #endif
  1540. X     x_tio = newtime % (long) sorbit_array[ orbit ]->aorbit->period;
  1541. X     pe_show( screen, sorbit_array, orbit, x_tio,
  1542. X        vlat, vlon, vdis, rotation,
  1543. X        x_xfactor, x_yfactor, x_midx, x_midy,
  1544. X        SPJ_NEARSIDE, cl_orbits[ orbit % 6 ], SOLID );
  1545. X     }
  1546. X      }
  1547. X
  1548. X   }
  1549. X
  1550. /***************************************************************
  1551. X
  1552. X    pe_show()
  1553. X
  1554. X    This routine draws the front or back side of a specific
  1555. X    orbit as it appears in space.
  1556. X
  1557. ***************************************************************/
  1558. X
  1559. pe_show( screen, sorbit_array, orbit, tio, vlat, vlon, vdis, rotation,
  1560. X   xfactor, yfactor, midx, midy,
  1561. X   side, color, style )
  1562. X   int screen;
  1563. X   struct sfs_orbit **sorbit_array;
  1564. X   int orbit;
  1565. X   long tio;
  1566. X   double vlat, vlon, vdis, rotation;
  1567. X   double xfactor, yfactor;
  1568. X   int midx, midy;
  1569. X   int side;
  1570. X   int color, style;
  1571. X   {
  1572. X   register int c;
  1573. X   static double x, y;
  1574. X   double prevx, prevy;
  1575. X   static int s;
  1576. X   int x_noline;
  1577. X
  1578. X   spj_point( sorbit_array[ orbit ]->pe_buffer[ 0 ].latitude,
  1579. X      sorbit_array[ orbit ]->pe_buffer[ 0 ].longitude,
  1580. X      sorbit_array[ orbit ]->pe_buffer[ 0 ].altitude,
  1581. X      vlat, vlon, vdis, rotation, side,
  1582. X      &x, &y, &s );
  1583. X   prevx = x;
  1584. X   prevy = y;
  1585. X   x_noline = TRUE;
  1586. X
  1587. X   c = 0;
  1588. X   while ( c < PE_POINTS )
  1589. X      {
  1590. X
  1591. X      s = 255;
  1592. X
  1593. X      /* Get coordinates for the point */
  1594. X
  1595. X      spj_point( sorbit_array[ orbit ]->pe_buffer[ c ].latitude,
  1596. X       sorbit_array[ orbit ]->pe_buffer[ c ].longitude,
  1597. X       sorbit_array[ orbit ]->pe_buffer[ c ].altitude,
  1598. X       vlat, vlon, vdis, rotation, side,
  1599. X       &x, &y, &s );
  1600. X
  1601. #ifdef  OLD_DEBUG
  1602. X      sprintf( bw_ebuf, "sp_show(): x = %.2lf, prevx = %.2lf, y = %.2lf, prevy = %.2lf",
  1603. X     x, prevx, y, prevy );
  1604. X      bw_debug( bw_ebuf );
  1605. #endif
  1606. X
  1607. X      /* show the point */
  1608. X
  1609. X      if ( s == side )
  1610. X     {
  1611. X     if ( ( ( c * sorbit_array[ orbit ]->pe_inc ) < tio )
  1612. X        && ( x_noline != TRUE ) )
  1613. X        {
  1614. X        gr_line( screen,
  1615. X           midx + ( (int) ( x     * xfactor )),
  1616. X           midy + ( (int) ( y     * yfactor )),
  1617. X           midx + ( (int) ( prevx * xfactor )),
  1618. X           midy + ( (int) ( prevy * yfactor )),
  1619. X           color, SOLID );
  1620. X        x_noline = FALSE;
  1621. X        }
  1622. X     else
  1623. X        {
  1624. X        gr_pixel( screen,
  1625. X           midx + ( (int) ( x * xfactor )),
  1626. X           midy + ( (int) ( y * yfactor )),
  1627. X           color );
  1628. X        x_noline = FALSE;
  1629. X        }
  1630. X     }
  1631. X
  1632. X      /* point is not on the side selected; thus set x_noline */
  1633. X
  1634. X      else
  1635. X     {
  1636. X     x_noline = TRUE;
  1637. X     }
  1638. X
  1639. X      /* save x and y values and increment the counter */
  1640. X
  1641. X      prevx = x;
  1642. X      prevy = y;
  1643. X      ++c;
  1644. X      }
  1645. X
  1646. X   }
  1647. X
  1648. /***************************************************************
  1649. X
  1650. X    pe_orb()
  1651. X
  1652. X    This routine draws the orb of the planet for the
  1653. X    distant perspective display.
  1654. X
  1655. ***************************************************************/
  1656. X
  1657. pe_orb( uiwind, screen, radius, distance, color, midx, midy,
  1658. X   xfactor, yfactor )
  1659. X   struct uiwindow *uiwind;             /* ui  window to draw in */
  1660. X   int screen;
  1661. X   double radius, distance;
  1662. X   int color;
  1663. X   int midx, midy;
  1664. X   double xfactor, yfactor;
  1665. X   {
  1666. X   double x_angrad;                     /* angular radius */
  1667. X   int x_yrad;                          /* radius on y axis */
  1668. X
  1669. X   /*** 1. Calculate angular radius and y axis radius */
  1670. X
  1671. X   x_angrad = spj_angrad( distance, radius );
  1672. X   x_yrad   = (int) ( x_angrad * yfactor );
  1673. X
  1674. #ifdef  DEBUG
  1675. X   if ( x_yrad < 1 )
  1676. X      {
  1677. X      sprintf( bw_ebuf, "pe_orb(): x_yrad = %d", x_yrad );
  1678. X      bw_error( bw_ebuf );
  1679. X      }
  1680. #endif
  1681. X
  1682. X   /*** 1. Blank the orb area */
  1683. X
  1684. X   gr_circle( screen, midx, midy, x_yrad, WHITE, SOLID );
  1685. X   gr_circle( screen, midx, midy, x_yrad, BLACK, SOLID );
  1686. X
  1687. X   /*** 2. Show the orb outline */
  1688. X
  1689. X   gr_circle( screen, midx, midy, x_yrad, color, HOLLOW );
  1690. X
  1691. X   }
  1692. X
  1693. pe_crosshair( uiwind, hor_deg, screen )
  1694. X   struct uiwindow *uiwind;             /* ui window for display */
  1695. X   double hor_deg;                      /* degrees of horizontal axis */
  1696. X   int screen;                          /* screen to draw to */
  1697. X   {
  1698. X   static double vert_degrees;          /* calculate vertical degrees */
  1699. X   int x_midx, x_midy;                  /* mid points of x, y axes */
  1700. X   register int x_deg;                  /* counter for degrees */
  1701. X   int x_xsize, x_ysize;                /* total x and y sizes of display */
  1702. X
  1703. X   /* calculate vertical degrees */
  1704. X
  1705. X   vert_degrees = hor_deg * ( ( ( uiwind->u_y2 - (double) uiwind->u_y1 )
  1706. X      * ( gr_pysize / (double) gr_pxsize ) )
  1707. X      / ( uiwind->u_x2 - (double) uiwind->u_x1 ) );
  1708. X
  1709. X   /* calculate mid points */
  1710. X
  1711. X   x_midx = uiwind->u_x1 + (( uiwind->u_x2 - (double) uiwind->u_x1 ) / 2.0 );
  1712. X   x_midy = uiwind->u_y1 + (( uiwind->u_y2 - (double) uiwind->u_y1 ) / 2.0 );
  1713. X   x_xsize = uiwind->u_x2 - uiwind->u_x1;
  1714. X   x_ysize = uiwind->u_y2 - uiwind->u_y1;
  1715. X
  1716. X   /* show vertical crosshairs */
  1717. X
  1718. X   gr_line( screen, x_midx, uiwind->u_y1, x_midx, uiwind->u_y2,
  1719. X      cl_marker, GRID );
  1720. X   for ( x_deg = 10; x_deg < ( hor_deg / 2 ); x_deg += 10 )
  1721. X      {
  1722. X      gr_line( screen,
  1723. X     (int) ( x_midx + (( x_deg * x_xsize ) / hor_deg )),
  1724. X     uiwind->u_y1,
  1725. X     (int) ( x_midx + (( x_deg * x_xsize ) / hor_deg )),
  1726. X     uiwind->u_y2,
  1727. X     cl_marker, GRID );
  1728. X      gr_line( screen,
  1729. X     (int) ( x_midx - (( x_deg * x_xsize ) / hor_deg )),
  1730. X     uiwind->u_y1,
  1731. X     (int) ( x_midx - (( x_deg * x_xsize ) / hor_deg )),
  1732. X     uiwind->u_y2,
  1733. X     cl_marker, GRID );
  1734. X      }
  1735. X
  1736. X   /* show horizontal crosshairs */
  1737. X
  1738. X   gr_line( screen, uiwind->u_x1, x_midy, uiwind->u_x2, x_midy,
  1739. X      cl_marker, GRID );
  1740. X   for ( x_deg = 10; x_deg < ( vert_degrees / 2 ); x_deg += 10 )
  1741. X      {
  1742. X      gr_line( screen,
  1743. X     uiwind->u_x1,
  1744. X     (int) ( x_midy + (( x_deg * x_ysize ) / vert_degrees )),
  1745. X     uiwind->u_x2,
  1746. X     (int) ( x_midy + (( x_deg * x_ysize ) / vert_degrees )),
  1747. X     cl_marker, GRID );
  1748. X      gr_line( screen,
  1749. X     uiwind->u_x1,
  1750. X     (int) ( x_midy - (( x_deg * x_ysize ) / vert_degrees )),
  1751. X     uiwind->u_x2,
  1752. X     (int) ( x_midy - (( x_deg * x_ysize ) / vert_degrees )),
  1753. X     cl_marker, GRID );
  1754. X      }
  1755. X
  1756. X   }
  1757. X
  1758. X
  1759. /***************************************************************
  1760. X
  1761. X    el_toggle()             Toggle Simulation Elements
  1762. X
  1763. ***************************************************************/
  1764. X
  1765. el_toggle( command, elements )
  1766. X   int command;                         /* command (letter) entered */
  1767. X   int *elements;                      /* pointer to simulation elements */
  1768. X   {
  1769. X   register int c;
  1770. X
  1771. X   c = toupper( command );
  1772. X
  1773. X   switch( c )
  1774. X      {
  1775. X      case    'O':
  1776. X     if ( ( *elements & VI_ORBOUTLINE ) > 0  )
  1777. X        {
  1778. X        *elements &= ~( VI_ORBOUTLINE );
  1779. X        }
  1780. X     else
  1781. X        {
  1782. X        *elements |= VI_ORBOUTLINE;
  1783. X        }
  1784. X     break;
  1785. X      case    'C':
  1786. X     if ( ( *elements & VI_CROSSH ) > 0  )
  1787. X        {
  1788. X        *elements &= ~( VI_CROSSH );
  1789. X        }
  1790. X     else
  1791. X        {
  1792. X        *elements |= VI_CROSSH;
  1793. X        }
  1794. X     break;
  1795. X      case    'G':
  1796. X     if ( ( *elements & VI_GRIDFRONT ) > 0 )
  1797. X        {
  1798. X        *elements = (*elements) & ~( VI_GRIDFRONT );
  1799. X        }
  1800. X     else
  1801. X        {
  1802. X        *elements = (*elements) | VI_GRIDFRONT;
  1803. X        }
  1804. X     break;
  1805. X      case    'S':
  1806. X     if ( ( *elements & VI_SURFRONT ) > 0  )
  1807. X        {
  1808. X        *elements &= ~( VI_SURFRONT );
  1809. X        }
  1810. X     else
  1811. X        {
  1812. X        *elements |= VI_SURFRONT;
  1813. X        }
  1814. X     break;
  1815. X      }
  1816. X   }
  1817. X
  1818. /***************************************************************
  1819. X
  1820. X    el_show()             Show Toggle Elements
  1821. X
  1822. ***************************************************************/
  1823. X
  1824. el_show( screen, uiwind, elements )
  1825. X   int screen;
  1826. X   struct uiwindow *uiwind;
  1827. X   unsigned int elements;
  1828. X   {
  1829. X   char x_buf[ 64 ];
  1830. X   int x, y, l;
  1831. X
  1832. X   /* calculate initial position of display streng */
  1833. X
  1834. X   sprintf( x_buf, "%s:   MMMMM", SFS_TOGGLE );
  1835. X   l = gr_strlen( x_buf );
  1836. X   x = uiwind->u_x2 - ( l + 2 );
  1837. X   y = uiwind->u_y2 - ( ui_grwind->fysize + 2 );
  1838. X
  1839. X   /* blank the area */
  1840. X
  1841. X   gr_rectangle( screen, x - 2, y - 1, x + l, y + ui_grwind->fysize + 1,
  1842. X      cl_mback, SOLID );
  1843. X
  1844. X   /* display string without toggles */
  1845. X
  1846. X   sprintf( x_buf, "%s:  ", SFS_TOGGLE );
  1847. X   gr_text( screen, x, y, x_buf, cl_mfore, cl_mback );
  1848. X
  1849. X   /* increment x to first toggle position */
  1850. X
  1851. X   l = gr_strlen( x_buf );
  1852. X   x += l;
  1853. X
  1854. X   /* show grid toggle status */
  1855. X
  1856. X   if ( ( elements & VI_GRIDFRONT ) > 0 )
  1857. X      {
  1858. X      gr_text( screen, x, y, "G", cl_mfore, cl_mback );
  1859. X      }
  1860. X   else
  1861. X      {
  1862. X      gr_text( screen, x, y, "G", cl_mback, cl_mfore );
  1863. X      }
  1864. X
  1865. X   /* increment x to next character position */
  1866. X
  1867. X   x += gr_strlen( "G" ) + 2;
  1868. X      
  1869. X   /* show surface toggle status */
  1870. X
  1871. X   if ( ( elements & VI_SURFRONT ) > 0 )
  1872. X      {
  1873. X      gr_text( screen, x, y, "S", cl_mfore, cl_mback );
  1874. X      }
  1875. X   else
  1876. X      {
  1877. X      gr_text( screen, x, y, "S", cl_mback, cl_mfore );
  1878. X      }
  1879. X
  1880. X   /* increment x to next character position */
  1881. X
  1882. X   x += gr_strlen( "S" ) + 2;
  1883. X      
  1884. X   /* show orb toggle status */
  1885. X
  1886. X   if ( ( elements & VI_ORBOUTLINE ) > 0 )
  1887. X      {
  1888. X      gr_text( screen, x, y, "O", cl_mfore, cl_mback );
  1889. X      }
  1890. X   else
  1891. X      {
  1892. X      gr_text( screen, x, y, "O", cl_mback, cl_mfore );
  1893. X      }
  1894. X
  1895. X   /* increment x to next character position */
  1896. X
  1897. X   x += gr_strlen( "O" ) + 2;
  1898. X      
  1899. X   /* show crosshair toggle status */
  1900. X
  1901. X   if ( ( elements & VI_CROSSH ) > 0 )
  1902. X      {
  1903. X      gr_text( screen, x, y, "C", cl_mfore, cl_mback );
  1904. X      }
  1905. X   else
  1906. X      {
  1907. X      gr_text( screen, x, y, "C", cl_mback, cl_mfore );
  1908. X      }
  1909. X
  1910. X   }
  1911. X
  1912. X
  1913. SHAR_EOF
  1914. chmod 0644 sfs/sfs/sfs_pe.c ||
  1915. echo 'restore of sfs/sfs/sfs_pe.c failed'
  1916. Wc_c="`wc -c < 'sfs/sfs/sfs_pe.c'`"
  1917. test 19001 -eq "$Wc_c" ||
  1918.     echo 'sfs/sfs/sfs_pe.c: original size 19001, current size' "$Wc_c"
  1919. rm -f _shar_wnt_.tmp
  1920. fi
  1921. # ============= sfs/sfs/sfs_pr.c ==============
  1922. if test -f 'sfs/sfs/sfs_pr.c' -a X"$1" != X"-c"; then
  1923.     echo 'x - skipping sfs/sfs/sfs_pr.c (File already exists)'
  1924.     rm -f _shar_wnt_.tmp
  1925. else
  1926. > _shar_wnt_.tmp
  1927. echo 'x - extracting sfs/sfs/sfs_pr.c (Text)'
  1928. sed 's/^X//' << 'SHAR_EOF' > 'sfs/sfs/sfs_pr.c' &&
  1929. /***************************************************************
  1930. X
  1931. X    sfs_pr.c        Program Interpreter for
  1932. X            Space Flight Simulator
  1933. X
  1934. X            Copyright (c) 1991, Ted A. Campbell
  1935. X
  1936. X            Bywater Software
  1937. X            P. O. Box 4023
  1938. X            Duke Station
  1939. X            Durham, NC  27706
  1940. X
  1941. X            email: tcamp@hercules.acpub.duke.edu
  1942. X
  1943. X    Copyright and Permissions Information:
  1944. X
  1945. X    All U.S. and international copyrights are claimed by the
  1946. X    author. The author grants permission to use this code
  1947. X    and software based on it under the following conditions:
  1948. X    (a) in general, the code and software based upon it may be
  1949. X    used by individuals and by non-profit organizations; (b) it
  1950. X    may also be utilized by governmental agencies in any country,
  1951. X    with the exception of military agencies; (c) the code and/or
  1952. X    software based upon it may not be sold for a profit without
  1953. X    an explicit and specific permission from the author, except
  1954. X    that a minimal fee may be charged for media on which it is
  1955. X    copied, and for copying and handling; (d) the code must be
  1956. X    distributed in the form in which it has been released by the
  1957. X    author; and (e) the code and software based upon it may not
  1958. X    be used for illegal activities.
  1959. X
  1960. ***************************************************************/
  1961. X
  1962. #include "stdio.h"
  1963. #include "time.h"
  1964. #include "ctype.h"
  1965. #include "bw.h"
  1966. #include "gr.h"
  1967. #include "kb.h"
  1968. #include "ui.h"
  1969. #include "as.h"
  1970. #include "sfs.h"
  1971. X
  1972. #ifdef  __STDC__
  1973. #include "malloc.h"
  1974. #include "stdlib.h"
  1975. #else
  1976. extern  char * malloc();
  1977. #define size_t   int
  1978. #define time_t   long
  1979. #endif
  1980. X
  1981. #define FDFILESIZE 128
  1982. #define FILE_DELIMITER  ";---------------------------------------\n"
  1983. X
  1984. extern   double atof();
  1985. extern   int    atoi();
  1986. extern   long   atol();
  1987. extern   struct as_focus * pr_getfd();
  1988. extern char *fntolc();
  1989. X
  1990. #define MAXARGS    4
  1991. X
  1992. static   char   arguments[ MAXARGS ][ 64 ];
  1993. X
  1994. sfs_pr( filename, pr_name, sorbit_array, n_orbits )
  1995. X   char *filename;                      /* name of program file */
  1996. X   char *pr_name;                       /* buffer for program name */
  1997. X   struct sfs_orbit **sorbit_array;     /* pointer to array of sfs orbit structures */
  1998. X   int n_orbits;                        /* number of orbit structures in arrays */
  1999. X   {
  2000. X   FILE *data;
  2001. X   static char buffer[ 128 ];
  2002. X   register int orbit;
  2003. X   static char fdfile[ FDFILESIZE ];
  2004. X
  2005. X   /* set up a default focal data file */
  2006. X
  2007. X   strcpy( fdfile, DEFAULTFD );        /* default focal data file */
  2008. X
  2009. X   /* deallocate any allocated orbit memory */
  2010. X
  2011. X   for ( orbit = 0; orbit < n_orbits; ++orbit )
  2012. X      {
  2013. X      if ( sorbit_array[ orbit ] != NULL )
  2014. X     {
  2015. X
  2016. #ifdef  OLD_DEBUG
  2017. X     sprintf( bw_ebuf, "Freeing memory for orbit %d", orbit );
  2018. X     bw_debug( bw_ebuf );
  2019. #endif
  2020. X
  2021. X     free( sorbit_array[ orbit ]->aorbit->focus->name );
  2022. X     free( sorbit_array[ orbit ]->aorbit->focus->adjective );
  2023. X     free( sorbit_array[ orbit ]->aorbit->focus->fdfile );
  2024. X     free( sorbit_array[ orbit ]->aorbit->focus );
  2025. X     free( sorbit_array[ orbit ]->aorbit );
  2026. X     free( sorbit_array[ orbit ]->name );
  2027. X     free( sorbit_array[ orbit ] );
  2028. X     sorbit_array[ orbit ] = NULL;
  2029. X     }
  2030. X      }
  2031. X
  2032. X   /* Open the program file */
  2033. X
  2034. X   if ( ( data = fopen( filename, "rb" )) == NULL )
  2035. X      {
  2036. X      sprintf( bw_ebuf, PRERR_OPEN, filename );
  2037. X      bw_error( bw_ebuf );
  2038. X      return BW_ERROR;
  2039. X      }
  2040. X
  2041. X   /* Get the program name -- always first line of file */
  2042. X
  2043. X   as_fgets( pr_name, 127, data );
  2044. X   pr_stripcr( pr_name );
  2045. X
  2046. X   /* Inform the viewer */
  2047. X
  2048. X   sprintf( bw_ebuf, PR_NOTICE,
  2049. X      filename, pr_name );
  2050. X   bw_message( bw_ebuf );
  2051. X
  2052. X   /* Parse each line of the file */
  2053. X
  2054. X   while( feof( data ) == FALSE )
  2055. X      {
  2056. X      as_fgets( buffer, 127, data );
  2057. X      if ( feof( data ) == FALSE )
  2058. X     {
  2059. X     pr_parse( buffer, fdfile, sorbit_array, n_orbits );
  2060. SHAR_EOF
  2061. true || echo 'restore of sfs/sfs/sfs_pr.c failed'
  2062. fi
  2063. echo 'End of  part 18'
  2064. echo 'File sfs/sfs/sfs_pr.c is continued in part 19'
  2065. echo 19 > _shar_seq_.tmp
  2066. exit 0
  2067. exit 0 # Just in case...
  2068. -- 
  2069. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2070. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2071. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2072. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2073.