[comp.sources.misc] v07i081: Whales and Plankton, part 08/13

allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (07/19/89)

Posting-number: Volume 7, Issue 81
Submitted-by: loy@gtx.UUCP (Bob Loy)
Archive-name: whpl/part08

# whpl08of13.shar
#---cut here---cut here---cut here---cut here---cut here---
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files.
# This archive created: Sat Jan 14 04:04:49 MST 1989
export PATH; PATH=/bin:$PATH
echo shar: extracting "'whpl.c2'" '(28498 characters)'
if test -f 'whpl.c2'
then
	echo shar: will not over-write existing file "'whpl.c2'"
else
sed 's/^X//' << \SHAR_EOF > 'whpl.c2'
X
X/*---------------------------------------------------------------------------*
X Top-level Declaration - includes, defines, externs & globals.
X*----------------------------------------------------------------------------*/
X
X#include "whpl.h"
X
X            /* EXTERNS FROM */
X      /* Functions From libraries: */
X   extern  void    qsort();
X   extern  char   *calloc(), *realloc();
X
X      /* Functions From rando.c: */
X   extern  short   nextrand();
X   extern  long    randout();
X   extern  long    randsize();
X
X      /* Functions From whio.c: */
X   extern  void    kidsout();
X
X      /* Functions From whx.c: */
X   extern  void    finish();
X
X
X            /* EXTERNS TO */
X      /* Functions To whio.c: */
X   int     qlohi();
X
X      /* Variables To whio.c: */
X   char    ingentyp[7] = INGENTYP;    /* Init for whales' hunt, feed, count,
X                                            and any other genetypes */
X   short   endexwarn = FALSE;         /*  Warning of .enrec overflow */
X
X      /* Functions To whx.c: */
X   void    whaleload();
X   void    countwhales();
X   void    clearlocarr();
X   void    plankplace();
X   int     countplank();
X   void    plankgrow();
X   void    plankgrow();
X   int     whaleplace();
X   void    whaledie();
X   void    mate();
X
X      /* Variables To whx.c: */
X   FILE   *whin;                      /*  Pointer to whale input file */
X   char    whinfile[40];              /*  Holds name of whale in-file */
X   char    whinstr[99];               /*  For lines read from whale in-file */
X   Uint    hgpcflg = HGPERCHR;        /*  Maximum hunt genes per chromosome */
X   Uint    fgpcflg = FGPERCHR;        /*  Maximum feed genes per chromosome */
X   Uchar  *secarr;                    /*  Scratch array for locarr, below*/
X
X      /* Variables To Everywhere: */
X   int     debug = 5;           /*  Debug level from 0 - 9; 9 prints all */
X   Uint    daterun = DATRUN;    /*  ID stamp for whales & filenames */
X   Uchar  *locarr;              /*  Main location array covering the planet
X                                       "Wa-Tor" */
X   Uint    area = AREA;         /*  Overall size of "Wa-Tor" */
X   Uint    vbias = VBIAS;       /*  Horizontal width of "Wa-Tor" (should
X                                       divide area evenly) */
X   whale_type   *whale;         /*  Start of main array of whale structs */
X   Uint    whale_size = sizeof(whale_type);  /* Whale struct size */
X   Uint    numwh = NUMWH;   /*  Number of current whales in array
X                                             pointed to by *whale */
X   Uint    truwh = NUMWH;   /*  Number of current live whales */
X   Uint    malwh;           /*  Number of current live males  */
X   Uint    femwh;           /*  Number of current live females */
X   int     year = 0;            /*  Holds num of mate cycles in run */
X   int     dielim = DIELIM;     /*  Compared to whale.die; how many times
X                                       whales can be below the death percen-
X                                       tile cut-off and get away with it */
X
X            /* GLOBALS */
X   static  int     mom, pop, baby;      /*  Used in mate routines */
X   static  Ushort  noclone;             /*  Used in mate routines */
X   static  short   collisions = 0;      /*  Check for too many recursive
X                                                     collision() calls */
X
X/*---------------------------------------------------------------------------*
X@
X@@  int   qhilo(two int pointers) - Compare function for qsort(). 
X@   return:  As required by qsort()
X@   caller:  femsort(), allsort()
X@   proc  :  This function has qsort() leave highest values in lowest
X@               array spots
X@
X@*---------------------------------------------------------------------------*/
X
Xint
Xqhilo(ptr1, ptr2)
X  int    *ptr1, *ptr2;
X{
X  if (*ptr1 < *ptr2)
X      return(1);
X  else if (*ptr1 > *ptr2)
X      return(-1);
X  else
X      return(0);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  int   qlohi(two int pointers) - Compare function for qsort(). 
X@   return:  As required by qsort()
X@   caller:  quiklist(), lastuff()
X@   proc  :  This function has qsort() leave lowest values in lowest
X@               array spots
X@
X@*---------------------------------------------------------------------------*/
X
Xint
Xqlohi(ptr1, ptr2)
X  int    *ptr1, *ptr2;
X{
X  if (*ptr1 > *ptr2)
X      return(1);
X  else if (*ptr1 < *ptr2)
X      return(-1);
X  else
X      return(0);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  int   testloc(limit) - For debugging; tests writing past area limits.
X@   return:   0  if passed value is within limits
X@            -1  if passed value is beyond array bounds, lower or higher
X@   caller:  none in ver 1.10
X@
X@*---------------------------------------------------------------------------*/
X
Xint
Xtestloc(n)
X  int     n;
X{
X  if ((n < 0) || (n >= area))
X      return(-1);
X  return(0);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  quiklist() - Outputs list used for debugging.
X@   input :  Whole whale list
X@   output:  Same format as "whs*" stat files
X@   caller:  none in ver 1.10
X@   calls :  whaleout(), qlohi(); qsort(), calloc(),  may call finish()
X@
X@*---------------------------------------------------------------------------*/
X 
Xvoid
Xquiklist()
X{
X  register  int     j;
X  energarr *enerlist;
X
X  enerlist = (energarr *) calloc((numwh), (sizeof(energarr)));
X  if (enerlist == NULL)
X    {
X      if (debug >= 2)
X          fprintf(stderr, "\nquiklist(): enerlist calloc problems.\n");
X      finish(8);
X    }
X  for (j = 0; j < numwh; j++)
X    {
X      enerlist[j].ener = whale[j].energy;
X      enerlist[j].whal = j;
X    }
X  qsort((char*)enerlist, (numwh), sizeof(energarr), qlohi);
X  fprintf(stdout, "\n");
X  fprintf(stdout,
X          "   energy, ansave, orat, age, die,                    whale\n");
X  for (j = numwh - 1; j >= 0; j--)
X    {
X      fprintf(stdout, "  %7d %7d %5d  %3d  %3d   ",
X              enerlist[j].ener,
X              whale[enerlist[j].whal].ancesave,
X              whale[enerlist[j].whal].offratio,
X              whale[enerlist[j].whal].age,
X              whale[enerlist[j].whal].die);
X      whaleout(enerlist[j].whal, stdout, 1);
X    }
X  fprintf(stderr, "\n");
X  fprintf(stderr,
X          "   energy, ansave, orat, age, die,                    whale\n");
X  for (j = numwh - 1; j >= 0; j--)
X    {
X      fprintf(stderr, "  %7d %7d %5d  %3d  %3d   ",
X              enerlist[j].ener,
X              whale[enerlist[j].whal].ancesave,
X              whale[enerlist[j].whal].offratio,
X              whale[enerlist[j].whal].age,
X              whale[enerlist[j].whal].die);
X      whaleout(enerlist[j].whal, stderr, 1);
X    }
X  free((char*) enerlist);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  Ushort geneval() - Returns value of countgene or extragene.
X@   input :  Unsigned char from 'a' thru 'z'
X@   caller:  Uncalled in version 1.10
X@   return:  Unsigned short from 0 thru 25
X@
X@*---------------------------------------------------------------------------*/
X
XUshort
Xgeneval(ugene)
X  Uchar   ugene;
X{
X  Ushort  gv;
X
X  if (ugene < 'a' || ugene > 'z')
X    {
X      if (debug >= 2)
X          fprintf(stderr, "geneval(): bad char passed:  %c\n", ugene);
X    }
X  if (ugene == 'z')   /* 'z' equals value of zero */
X      ugene = '`';
X  ugene -= '`';
X  gv = (Ushort) ugene;
X  return(gv);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  int   boundstest(index) - Coerces values to be within area limits.
X@   caller:  attract(), collision(), movewhale(), plankgrow1(), plankgrow2()
X@   return:  proper value of passed parameter
X@
X@*---------------------------------------------------------------------------*/
X
Xint 
Xboundstest(n)
X  register  int     n;
X{
X  if (n < 0)
X      n = n + area;
X  if (n >= area)
X      n = n - area;
X  return(n);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  clearlocarr() - Clears locarr[area], the array covering "Wa-Tor".
X@   output:  Fills locarr[] with ascii spaces
X@   caller:  main()
X@   proc  :  Yeah, I cheated and used a single-dimensional array rather than
X@               a 2-D array, as it is somewhat simpler to deal with (constant
X@               vbias is used to section off the rows within the 1-D array).
X@            This introduces a very slight bias into the top-bottom & left-
X@               right contiguities of the Wa-Tor grid, as a whale always
X@               swimming horizontally will eventually spiral across the whole
X@               face of the planet, while one swimming vertically will stay
X@               stuck in one track.
X@            I've never worried about it; if anyone wants to rewrite whpl
X@               using a 2-D array, I'm all for it!
X@
X@   Note  :  Be sure vbias divides evenly into area to create a true rectangle
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xclearlocarr()
X{
X  register  int     j;
X
X  for (j = 0; j < area; j++)
X      locarr[j] = ' ';
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  loadsecarr(fill) - Fills secarr[area], scratch array for locarr[].
X@   output:  Fills secarr[] with ascii value of passed parameter
X@   caller:  mate(), plankgrow(), plankplace()
X@   proc  :  See  proc  comment for clearlocarr()
X@
X@   Note  :  See  Note  in clearlocarr()
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xloadsecarr(fill)
X  register  char    fill;
X{
X  register  int     j;
X
X  for (j = 0; j < area; j++)
X      secarr[j] = fill;
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  int   countplank() - Counts the plankton in the locarr[] array.
X@   caller:  finish(), interim(), whaledie(), look(), mate(), plankcall(),
X@               main()
X@   return:  The count
X@
X@*---------------------------------------------------------------------------*/
X
Xint
Xcountplank()
X{
X  register  int     j;
X  register  int     k = 0;
X
X  for (j = 0; j < area; j++)
X    {
X      if (locarr[j] == '.')
X          k++;
X    }
X  return(k);
X}     
X 
X/*---------------------------------------------------------------------------*
X@
X@@  void  plankplace(density, resolution [and speed] ) - Inits plankton.
X@   input :  locarr[] array, maybe secarr[]
X@   output:  Randomly seeded plankton in locarr[area]
X@   caller:  main()
X@   calls :  loadsecarr(), nextrand() or randout()
X@   proc  :  Fast version (passed parm resolution = 0) makes use of fastest,
X@               six-bit random number function nextrand()
X@            Slower version (passed parm resolution = 1) can seed with
X@               sparser density, down to one part in 4096
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xplankplace(dens, resol)
X  int     dens, resol;
X{
X  register  int     j;
X  Ushort   chomp;
X
X  switch(resol)
X    {
X          /*  For density of X part in 64:  */
X      case 0 :
X          for (j = 0; j < area; j++)
X            {
X              chomp = nextrand();
X              if (chomp < dens)
X                  locarr[j] = '.';
X            }
X          break;
X          /*  For density of X part in 4096:  */
X      case 1 :
X          loadsecarr(' ');
X          for (j = 0; j < area; j++)
X            {
X              chomp = (Ushort)(randout() & 0xFFF);
X              if (chomp < dens)
X                  secarr[j] = '.';
X            }
X          for (j = 0; j < area; j++)
X            {
X              if (secarr[j] == '.')
X                  locarr[j] = '.';
X            }
X          break;
X      default:
X          if (debug >= 2)
X              fprintf(stderr, "\n  plankplace():  case:  default\n");
X          break;
X    }
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  plankgrow2() - One possible plankton growth function.
X@   input :  locarr[] and secarr[] arrays
X@   output:  Increased plankton count in locarr[]
X@   caller:  plankgrow(), which chooses which plankgrowX() function is called
X@   calls :  nextrand(), boundstest()
X@   proc  :  "Fuzzy" growth function; each plankton "pixel" found in locarr[]
X@               randomly spawns another one two pixels away
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xplankgrow2()
X{
X  register  int     j, n;
X  short   nibl;
X 
X  for (j = 0; j < area; j++)
X    {
X      if (locarr[j] == '.')
X        {
X          nibl = nextrand() & 0xF;
X          switch(nibl)
X            {
X              case 0 :
X                  n = (j - 2*vbias) - 2*HBIAS;
X                  break;
X              case 1 :
X                  n = (j - vbias) - 2*HBIAS;
X                  break;
X              case 2 :
X                  n = (j - 2*vbias);
X                  break;
X              case 3 :
X                  n = (j - 2*vbias) - HBIAS;
X                  break;
X              case 4 :
X                  n = (j - 2*vbias) + 2*HBIAS;
X                  break;
X              case 5 :
X                  n = (j - 2*vbias) + HBIAS;
X                  break;
X              case 6 :
X                  n = (j + 2*HBIAS);
X                  break;
X              case 7 :
X                  n = (j + 2*HBIAS) - vbias;
X                  break;
X              case 8 :
X                  n = (j + 2*vbias) + 2*HBIAS;
X                  break;
X              case 9 :
X                  n = (j + vbias) + 2*HBIAS;
X                  break;
X              case 10 :
X                  n = (j + 2*vbias);
X                  break;
X              case 11 :
X                  n = (j + 2*vbias) + HBIAS;
X                  break;
X              case 12 :
X                  n = (j + 2*vbias) - 2*HBIAS;
X                  break;
X              case 13 :
X                  n = (j + 2*vbias) - HBIAS;
X                  break;
X              case 14 :
X                  n = (j - 2*HBIAS);
X                  break;
X              case 15 :
X                  n = (j - 2*HBIAS) + vbias;
X                  break;
X              default:
X                  if (debug >= 2)
X                      fprintf(stderr, "\n  plankgrow2():  case:  default\n");
X                  break;
X            }
X          n = boundstest(n);
X          secarr[n] = '.';
X        }
X    }
X  for (j = 0; j < area; j++)
X    {
X      if (secarr[j] == '.')
X          locarr[j] = '.';
X    }
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  plankgrow1() - One possible plankton growth function.
X@   input :  locarr[] and secarr[] arrays
X@   output:  Increased plankton count in locarr[]
X@   caller:  plankgrow(), which chooses which plankgrowX() function is called
X@   calls :  nextrand(), boundstest()
X@   proc  :  "Sharp" growth function; each plankton "pixel" found in locarr[]
X@               randomly spawns another one in a neighboring pixel
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xplankgrow1()
X{
X  register  int     j, n;
X  short   nibl;
X
X  for (j = 0; j < area; j++)
X    {
X      if (locarr[j] == '.')
X        {
X          nibl = nextrand() & 0x7;
X          switch(nibl)
X            {
X              case 0 :
X                  n = (j - vbias) - HBIAS;
X                  break;
X              case 1 :
X                  n = (j - vbias);
X                  break;
X              case 2 :
X                  n = (j - vbias) + HBIAS;
X                  break;
X              case 3 :
X                  n = (j + HBIAS);
X                  break;
X              case 4 :
X                  n = (j + vbias) + HBIAS;
X                  break;
X              case 5 :
X                  n = (j + vbias);
X                  break;
X              case 6 :
X                  n = (j + vbias) - HBIAS;
X                  break;
X              case 7 :
X                  n = (j - HBIAS);
X                  break;
X              default:
X                  if (debug >= 2)
X                      fprintf(stderr, "\n  plankgrow1():  case:  default\n");
X                  break;
X            }
X          n = boundstest(n);
X          secarr[n] = '.';
X        }
X    }
X  for (j = 0; j < area; j++)
X    {
X      if (secarr[j] == '.')
X          locarr[j] = '.';
X    }
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  plankgrow(switch) - Chooses which plankgrowX() function is called.
X@   caller:  plankcall(), main()
X@   calls :  One of 4 possible plankton growth functions
X@               (only two implemented as of version 1.10:
X@               plankgrow1(), plankgrow2())
X@   proc  :  Loads secarr[] array with ascii blanks prior using the passed
X@               parameter to select which function to call
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xplankgrow(swit)
X  int     swit;
X{
X  loadsecarr(' ');
X  swit = swit & 0x3;
X  switch(swit)
X    {
X      case 0 :
X          if (debug >= 2)
X              fprintf(stderr, "\n  pg(sw):  no case 0 yet  \n");
X          break;
X      case 1 :
X          plankgrow1();
X          break;
X      case 2 :
X          plankgrow2();
X          break;
X      case 3 :
X          if (debug >= 2)
X              fprintf(stderr, "\n  plankgrow(sw):  no case 3 yet  \n");
X          break;
X      default:
X          if (debug >= 2)
X              fprintf(stderr, "\n  plankgrow(sw):  case:  default\n");
X          break;
X    }
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  countwhales() - Counts live whales of both sexes.
X@   input :  Whole whale list
X@   output:  Updates malwh and femwh
X@   caller:  whaledie(), mate(), interim(), finish(), main()
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xcountwhales()
X{
X  register  int     j;
X
X  malwh = 0;
X  femwh = 0;
X  for (j = 0; j < numwh; j++)
X    {
X      if (whale[j].sex == 'M' && whale[j].energy > 9999)
X          malwh++;
X      else if (whale[j].sex == 'F' && whale[j].energy > 9999)
X          femwh++;
X    }
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  int   whaleplace() - Randomly assigns locarr[] locations to whales.
X@   return:  Random location
X@   caller:  whaleload(), mate(), main()
X@   calls :  randsize()
X@
X@*---------------------------------------------------------------------------*/
X
Xint
Xwhaleplace()
X{
X  register  Uint    slice;
X
X  do{
X      slice = (Uint)randsize(area);
X    } while (slice > area);
X  return(slice);
X}
X
X/*---------------------------------------------------------------------------*
X@
X@@  void  whaleload(whale, how) - Fills whale structures.
X@   input :  Reads in some info not used in program, for completeness
X@   output:  Filled structure for given whale, dependent on 'how' flag passed
X@            Tests and may reset global flags hgpcflg & fgpcflg
X@   caller:  mate(), whaleinit()
X@   calls :  whaleplace(), randout()
X@   proc  :  May create new whales, fill them from file read, or generate
X@               them during mating, based on passed 'how' flag
X@
X@*---------------------------------------------------------------------------*/
X
Xvoid
Xwhaleload(j, how)
X  register  int   j;
X  short   how;
X{
X  register  int     k;
X  static    char    blankgns[7] = "      ";
X
X  if (how == 1)          /* Init by reading from file */
X    {
X      Uint    selfd;
X      Uint    selfg;
X      Uint    selfm;
X      char    genes[7];
X      char    die[2];
X      char    sex[2];
X      int     age;
X      int     ofr;
X      int     rtg;
X      int     erec[20];
X      short   edex;
X      short   hg[16];
X      short   fg[16];
X      int     lsr;
X      short   df[20];
X      short   tl[20];
X      short   rk[20];
X      int     asav;
X      short   amax;
X      short   amin;
X      Uint    fathd;
X      Uint    fathg;
X      Uint    fathm;
X      char    fgns[7];
X      Uint    mothd;
X      Uint    mothg;
X      Uint    mothm;
X      char    mgns[7];
X      short   chidex;
X      short   alchldn;
X      Uint    ofd[50];
X      Uint    ofg[50];
X      Uint    ofm[50];
X      char    ogns[50][7];
X      char    cgns[7];
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%*s%u%u%u%s",
X              &selfd, &selfg, &selfm, genes);
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%s%s%d%d%d", die, sex, &age, &ofr, &rtg);
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd",
X              &hg[0],&hg[1],&hg[2],&hg[3],&hg[4],&hg[5],&hg[6],&hg[7],
X              &hg[8],&hg[9],&hg[10],&hg[11],&hg[12],&hg[13],&hg[14],&hg[15]);
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd",
X              &fg[0],&fg[1],&fg[2],&fg[3],&fg[4],&fg[5],&fg[6],&fg[7],
X              &fg[8],&fg[9],&fg[10],&fg[11],&fg[12],&fg[13],&fg[14],&fg[15]);
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%*s%hd", &edex);
X      for (k = 0; k < edex; k++)
X        {
X          fgets(whinstr, 97, whin);
X          sscanf(whinstr, "%d", &erec[k]);
X        }
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%*s%d", &lsr);
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd",
X              &df[0],&tl[0],&rk[0], &df[1],&tl[1],&rk[1],
X              &df[2],&tl[2],&rk[2], &df[3],&tl[3],&rk[3]);
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd",
X              &df[4],&tl[4],&rk[4], &df[5],&tl[5],&rk[5],
X              &df[6],&tl[6],&rk[6], &df[7],&tl[7],&rk[7]);
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd",
X              &df[8],&tl[8],&rk[8], &df[9],&tl[9],&rk[9],
X              &df[10],&tl[10],&rk[10], &df[11],&tl[11],&rk[11]);
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd",
X              &df[12],&tl[12],&rk[12], &df[13],&tl[13],&rk[13],
X              &df[14],&tl[14],&rk[14], &df[15],&tl[15],&rk[15]);
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd%hd",
X              &df[16],&tl[16],&rk[16], &df[17],&tl[17],&rk[17],
X              &df[18],&tl[18],&rk[18], &df[19],&tl[19],&rk[19]);
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%*s%d%hd%hd", &asav, &amax, &amin);
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%u%u%u%s", &fathd, &fathg, &fathm, fgns);
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%u%u%u%s", &mothd, &mothg, &mothm, mgns);
X      fgets(whinstr, 97, whin);
X      sscanf(whinstr, "%*s%hd%hd", &chidex, &alchldn);
X      for (k = 0; k < chidex; k++)
X        {
X          fgets(whinstr, 97, whin);
X          sscanf(whinstr, "%u%u%u%s", &ofd[k], &ofg[k], &ofm[k], cgns);
X          strncpy(&ogns[k][0], cgns, 7);
X        }
X          /* Begin assigning input to whale[j]: */
X      for (k = 0; k < 20; k++)
X        {
X          if (k < edex)
X              whale[j].enrec[k] = erec[k];
X          else
X              whale[j].enrec[k] = 0;
X        }
X      if (edex == 20)
X        {
X          if (debug >= 2)
X            {
X              fprintf(stderr,
X                      "\nwhaleload(): wh[%d].enrec array is FULL\n", j);
X              fprintf(stderr, " *** WILL OVERWRITE IN PROGRAM ***\n");
X            }
X          edex = 19;
X          endexwarn++;
X        }
X      whale[j].endex = edex;
X      whale[j].age = age;
X      whale[j].sex = sex[0];
X      for (k = 0; k < 20; k++)
X        {
X          whale[j].comp[k].diff = df[k];
X          whale[j].comp[k].totl = tl[k];
X          whale[j].comp[k].rank = rk[k];
X        }
X      whale[j].ancesave = asav;
X      whale[j].ancesmax = amax;
X      whale[j].ancesmin = amin;
X      whale[j].father.datrun = fathd;
X      whale[j].father.gennum = fathg;
X      whale[j].father.mutate = fathm;
X      strncpy(whale[j].father.gns, fgns, 7);
X      whale[j].mother.datrun = mothd;
X      whale[j].mother.gennum = mothg;
X      whale[j].mother.mutate = mothm;
X      strncpy(whale[j].mother.gns, mgns, 7);
X      whale[j].self.datrun = selfd;
X      whale[j].self.gennum = selfg;
X      whale[j].self.mutate = selfm;
X      strncpy(whale[j].self.gns, genes, 7);
X      if (chidex == 49)
X        {
X          if (debug >= 2)
X            {
X              fprintf(stderr,
X                      "\nwhaleload(): wh[%d].offspr array is FULL\n", j);
X              fprintf(stderr, " *** MAY WRAP AROUND IN PROGRAM ***\n");
X            }
X        }
X      for (k = 0; k < 50; k++)
X        {
X          if (k < chidex)
X            {
X              whale[j].offspr[k].datrun = ofd[k];
X              whale[j].offspr[k].gennum = ofg[k];
X              whale[j].offspr[k].mutate = ofm[k];
X              strncpy(whale[j].offspr[k].gns, &ogns[k][0], 7);
X            }
X          else
X            {
X              whale[j].offspr[k].datrun = 0;
X              whale[j].offspr[k].gennum = 0;
X              whale[j].offspr[k].mutate = 0;
X              strncpy(whale[j].offspr[k].gns, blankgns, 7);
X            }
X        }
X      whale[j].childex = chidex;
X      whale[j].allchldn = alchldn;
X      whale[j].hunttype = genes[0];
X      whale[j].hgperchr = genes[1];
X      whale[j].feedtype = genes[2];
X      whale[j].fgperchr = genes[3];
X      for (k = 0; k < 16; k++)
X          whale[j].huntgene[k] = hg[k];
X      for (k = 0; k < 16; k++)
X          whale[j].feedgene[k] = fg[k];
X          /* Force to "zero" in whpl.c version 1.10:  ----*/
X      whale[j].countgene = 'z';
X      whale[j].extragene = 'z';
X/*------- Otherwise... ---------------
X      whale[j].countgene = genes[4];
X      whale[j].extragene = genes[5];
X--------------------------------------*/
X    }
X  if (how == 0)                 /* Init as newly created whales */
X    {
X      if (j % 2)
X          whale[j].sex = 'M';
X      else
X          whale[j].sex = 'F';
X      whale[j].father.datrun = 0;
X      whale[j].father.gennum = 0;
X      whale[j].father.mutate = 0;
X      strncpy(whale[j].father.gns, blankgns, 7);
X      whale[j].mother.datrun = 0;
X      whale[j].mother.gennum = 0;
X      whale[j].mother.mutate = 0;
X      strncpy(whale[j].mother.gns, blankgns, 7);
X      whale[j].hunttype = ingentyp[0];
X      whale[j].hgperchr = ingentyp[1];
X      whale[j].feedtype = ingentyp[2];
X      whale[j].fgperchr = ingentyp[3];
X          /* Force to "zero" in whpl.c version 1.10:  ----*/
X      ingentyp[4] = 'z';
X      ingentyp[5] = 'z';
X      strncpy(whale[j].self.gns, ingentyp, 7);
X      if (whale[j].hgperchr != '0')
X        {
X          for (k = 0; k < 16; k++)
X              whale[j].huntgene[k] = randout() & 0x3F;
X        }
X      else
X        {
X          for (k = 0; k < 16; k++)
X              whale[j].huntgene[k] = -1;
X        }
X      if (whale[j].fgperchr != '0')
X        {
X          for (k = 0; k < 16; k++)
X              whale[j].feedgene[k] = randout() & 0x3F;
X        }
X      else
X        {
X          for (k = 0; k < 16; k++)
X              whale[j].feedgene[k] = -1;
X        }
X    }
X  if (how == 0 || how == 2)     /* Init as newly created or as babies */
X    {
X      for (k = 0; k < 20; k++)
X        {
X          whale[j].enrec[k] = 0;
X        }
X      whale[j].endex = 0;
X      whale[j].age = 0;
X      whale[j].self.datrun = daterun;
X      whale[j].self.gennum = GENNUM + 10000 * year + j;
X      whale[j].self.mutate = 1000000000;
X      for (k = 0; k < 20; k++)
X        {
X          whale[j].comp[k].diff = 0;
X          whale[j].comp[k].totl = 0;
X          whale[j].comp[k].rank = 0;
X        }
X      whale[j].ancesave = 0;
X      whale[j].ancesmax = 0;
X      whale[j].ancesmin = 0;
X      for (k = 0; k < 50; k++)
X        {
X          whale[j].offspr[k].datrun = 0;
X          whale[j].offspr[k].gennum = 0;
X          whale[j].offspr[k].mutate = 0;
X          strncpy(whale[j].offspr[k].gns, blankgns, 7);
X        }
X      whale[j].childex = 0;
X      whale[j].allchldn = 0;
X          /* Force to "zero" in whpl.c version 1.10:  ----*/
X      whale[j].countgene = 'z';
X      whale[j].extragene = 'z';
X/*------- Otherwise... ---------------
X      whale[j].countgene = ingentyp[4];
X      whale[j].extragene = ingentyp[5];
X--------------------------------------*/
X    }
X  whale[j].sortfield = 0;
X  whale[j].energy = 1000000;
X  whale[j].die = 0;
X  whale[j].offratio = 0;
X  whale[j].rating = 0;
X  whale[j].lastrat = 0;
X  whale[j].huntdex = 0;
X  whale[j].feeddex = 0;
X  whale[j].lastfed = 1000000;
X  whale[j].huntfeed = 'H';
X  whale[j].locatn = whaleplace();
X  if (hgpcflg < whale[j].hgperchr - '0')
X      hgpcflg = whale[j].hgperchr - '0';
X  if (fgpcflg < whale[j].fgperchr - '0')
X      fgpcflg = whale[j].fgperchr - '0';
X}
SHAR_EOF
if test 28498 -ne "`wc -c < 'whpl.c2'`"
then
	echo shar: error transmitting "'whpl.c2'" '(should have been 28498 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0
---

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                |
             Bob Loy            |     Life is the detour you take on the
    ...!sun!sunburn!gtx!loy     |     way to where you're really going.
                                |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~