home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume6 / gb / patch1 / enrol.c < prev    next >
C/C++ Source or Header  |  1989-07-06  |  8KB  |  281 lines

  1. /*
  2.  * Galactic Bloodshed (Robert Chansky, smq@b)
  3.  * enrol.c -- initializes to owner one sector and planet. 
  4.  */
  5.  
  6. #include "vars.h"
  7. #include "races.h"
  8. #include <signal.h>
  9. #include <strings.h>
  10. #include <curses.h>
  11. #include <errno.h>
  12. extern int errno;
  13. extern char desshow();
  14.  
  15. struct stype {
  16.     char here;
  17.     char x,y;
  18.     int count;
  19. };
  20.  
  21. /* compatibility schematic for sectors.  Note that plated sectors are
  22.    compatible with everything.  */
  23. float Likes[DES_PLATED+1][DES_PLATED+1] = {
  24.                /* DES_SEA     DES_LAND   DES_MOUNT  DES_GAS DES_ICE DES_PLATED*/
  25. /*DES_SEA  */      1.0,        0.0,        0.0,       0.3,     0.05,    1.0,
  26. /*DES_LAND */      0.0,        1.0,        0.5,       0.0,     0.1,     1.0,
  27. /*DES_MOUNT*/      0.0,        0.5,        1.0,       0.0,     0.7,     1.0,
  28. /*DES_GAS  */      0.5,        0.0,        0.0,       1.0,     0.0,     1.0,
  29. /*DES_ICE  */      0.15,       0.25,       0.7,       0.0,     1.0,     1.0,
  30. /*DES_PLATED*/     1.0,        1.0,        1.0,       1.0,     1.0,     1.0
  31. };
  32.  
  33.  
  34. enroll(loginname)
  35. char *loginname;
  36. {
  37. int x,y, or;
  38. int pnum,star=0,found=0,i,j,enroll_pdata,
  39.     enroll_sectdata, enroll_stardata,mask,ppref;
  40. char str[100], c;
  41. sectortype *sect;
  42. struct stype secttypes[DES_PLATED+1];
  43. planettype *planet;
  44. FILE *fd;
  45.  
  46.  
  47. if ( (Playernum=Numraces()+1) >= MAXPLAYERS) {
  48.     printf("There are already %d players; No more allowed.\n",Playernum);
  49.     exit(-1);
  50. }
  51.  
  52.  
  53.  
  54.  printf("There is still space for player %d.", Playernum);
  55.  printf("\n\tenroll(y/n)\?");
  56.  
  57.  c = getchr(); getchr();
  58.  if (c!='y') {
  59.     printf("why did you come here, then?\n");
  60.     endwin();
  61.     exit(0);
  62.  }
  63.  
  64.    /* look at enroll screen */
  65.  sprintf(str, "%s %s", PAGER, ENROLL_FL);
  66.  system(str);
  67.  printf("\n  Live on what type planet:(e)arthtype, (g)asgiant, (a)irless? ");
  68.  c = getchr(); getchr();
  69.  switch (c) {
  70.     case 'e': ppref = TYPE_EARTH;
  71.          break;
  72.     case 'a': ppref = TYPE_AIRLESS;
  73.          break;
  74.     case 'g': ppref = TYPE_GASGIANT;
  75.          break;
  76.     default: printf("Oh well.\n");
  77.          exit(-1);
  78.          break;
  79.  }
  80.  
  81.     /* find first planet of right type */
  82. star = 0; found = 0;
  83. while (!found && star<Sdata.numstars) {
  84.  for (or=i=0; i<howmanybytes(Playernum); i++ )
  85.     or |= Stars[star]->explored[i];
  86.       /* make sure no one has explored the star */
  87.  if (!or) {
  88.      pnum = 0;
  89.      while (!found && pnum<Stars[star]->numplanets) {
  90.         printf(" getting st %d pl #%d\n",star, pnum);
  91.         openpdata(&enroll_pdata);
  92.         getplanet(enroll_pdata,&planet,Stars[star]->planetpos[pnum]);
  93.         if (planet->type==ppref) {
  94.             printf(" yep.\n");
  95.             found = 1;
  96.         } else {
  97.             printf(" nope.\n");
  98.             close(enroll_pdata);
  99.             free(planet);
  100.             pnum++;
  101.         }
  102.      }
  103.  }
  104.  if (!found)
  105.      star++;
  106. }
  107. printf(" star %d, pl %d\n", star,pnum);
  108.  
  109.  
  110.  if (!found) {
  111.     printf(" Uhoh, there don't seem to be any of that type of planet left.\n");
  112.     printf("  Try a different one...\n");
  113.     endwin();
  114.     exit(0);
  115.  }
  116.  
  117.  Race = Malloc(racetype);
  118.  Bzero(*Race);
  119.  
  120.  tty_off();
  121.  printf("\n\nEnter a name for your race:");
  122.  dots(RNAMESIZE);
  123.  scanf("%[^\n]",str); 
  124.  getchr();
  125.  printf("\n\nwait...\n");
  126.  
  127.  strncpy(Race->name, str, RNAMESIZE);
  128.  
  129.  Race->homelevel = Race->deflevel = LEVEL_PLAN;
  130.  Race->homesystem = Race->defsystem = star;
  131.  Race->homeplanetnum = Race->defplanetnum = pnum;
  132.  
  133.     /* make conditions preferred by your people set to (more or less) 
  134.        those of the planet : higher the concentration of gas, the higher
  135.        percentage difference between planet and race */
  136.  for (j=0; j<=OTHER; j++)
  137.     Race->conditions[j] = planet->conditions[j]; /*+ int_rand( round_rand(-planet->conditions[j]*2.0), round_rand(planet->conditions[j]*2.0) )*/
  138.  
  139.  
  140.  for (i=0; i<MAXPLAYERS; i++)
  141.    /* messages from autoreport, player #1 are decodable */
  142.     if (i==Playernum || i==1)
  143.         Race->translate[i] = 100;    /* you can talk to own race */
  144.     else
  145.         Race->translate[i] = 1;
  146.  
  147.   i = 5; found = 0;
  148.   tty_on();
  149.   do {
  150.     if (i<=0) {
  151.         printf("Too long.  bye\n");
  152.         exit(0);
  153.     }
  154.  
  155.     Race->tech = 0;
  156.     Race->overbirthrate = float_rand() * 0.01;
  157.         /* your race is like "the Thing" */
  158.     if (Race->Thing = !int_rand(0,10) ) {
  159.         Race->mass = 1.0;
  160.         Race->birthrate = float_rand()*0.25 + 0.55;
  161.         Race->fighters = int_rand(7,9);
  162.         Race->IQ = int_rand(30,60);
  163.         Race->nonhomebodies = 0.99;
  164.         Race->number_sexes = 1;
  165.         Race->metabolism = float_rand() * 0.25 + 0.52;
  166.     } else {
  167.         Race->birthrate = float_rand()*0.25 + 0.25;
  168.         Race->mass = 0.5 + 1.5 * float_rand();
  169.         Race->fighters = int_rand(1,3)+int_rand(1,3);
  170.         Race->IQ = int_rand(103,220);
  171.         Race->nonhomebodies = 0.70 + float_rand()*0.20;
  172.         Race->metabolism = float_rand() * 0.25 + 0.875;
  173.         Race->number_sexes = int_rand(1,int_rand(2,int_rand(3,9)));
  174.     }
  175.     clear();
  176.     move(0,0); 
  177.     printw("%s\n", Race->Thing ? "MESOMORPHIC" : "");
  178.     printw("       Birthrate: %.3f\n",Race->birthrate);
  179.     printw("Fighting ability: %d\n",Race->fighters);
  180.     printw("              IQ: %d\n",Race->IQ);
  181.     printw("      Metabolism: %.2f\n",Race->metabolism);
  182.     printw("    Adventurists: %.2f\n",Race->nonhomebodies);
  183.     printw("            Mass: %.2f\n",Race->mass);
  184.     if (!Race->Thing)
  185.         printw(" Number of sexes: %d (min req'd for colonization)\n",Race->number_sexes);
  186.     printw("\n\n  (%d re-rolls left) space to reroll:", --i);
  187.     refresh();
  188.     if (getchr()!=' ')
  189.         found = 1;
  190.    } while (!found);
  191.  
  192.  bzero((char *)secttypes, sizeof(secttypes));
  193.  
  194.  opensectdata(&enroll_sectdata);
  195.  getsmap(enroll_sectdata,Smap,planet->sectormappos,planet->Maxx*planet->Maxy);
  196.  
  197.  printf("\nChoose a primary sector preference.  Your race will prefer to live\non this type of sector.\n");
  198.  
  199.  PermuteSects(planet);
  200.  Getxysect(planet, 0, 0, 1);
  201.  while (Getxysect(planet,&x,&y,0)) {
  202.     secttypes[Sector(*planet,x,y).des].count++;
  203.     if (!secttypes[Sector(*planet,x,y).des].here) {
  204.         secttypes[Sector(*planet,x,y).des].here = 1;
  205.         secttypes[Sector(*planet,x,y).des].x = x;
  206.         secttypes[Sector(*planet,x,y).des].y = y;
  207.     }
  208.  }
  209.  
  210.  Playernum = 1;
  211.  planet->is_explored = 1;
  212.  for (i=DES_SEA; i<=DES_PLATED; i++)
  213.     if (secttypes[i].here) {
  214.         Sector(*planet,secttypes[i].x,secttypes[i].y).is_wasted = 0;
  215.         printf("(%2d): %c  (%d sectors)\n", i,
  216.              desshow(planet, secttypes[i].x,secttypes[i].y),
  217.              secttypes[i].count);
  218.     }
  219.  planet->is_explored = 0;
  220.  
  221.  printf("\nchoice: ");
  222.  scanf("%d", &i);
  223.  if (i<DES_SEA || i>DES_PLATED || !secttypes[i].here) {
  224.     printf("Forget it.\n");
  225.     endwin();
  226.     exit(0);
  227.  }
  228.  
  229.  sect = &Sector(*planet,secttypes[i].x,secttypes[i].y);
  230.  Race->likesbest = i;
  231.  for (j=DES_SEA; j<=DES_PLATED; j++)
  232.     Race->likes[j] = Likes[i][j];
  233.  
  234.     Playernum = Race->Playernum = Numraces() + 1;
  235.  
  236.     mask = sigblock(SIGINT | SIGQUIT | SIGSTOP);
  237.  
  238.     putrace(Race);
  239.  
  240.     planet->info[Playernum-1].numsectsowned = 1;
  241.     planet->is_explored = 0;
  242.     planet->info[Playernum-1].explored = 1;
  243.     /*planet->info[Playernum-1].autorep = 1;*/
  244.  
  245.  
  246.     sect->owner = Playernum;
  247.     sect->popn = planet->popn = Race->number_sexes * 5;
  248.     sect->fert = 100;
  249.     sect->eff = 10;
  250.  
  251.     putsector(enroll_sectdata,sect,planet->sectormappos+(secttypes[i].y*planet->Maxx+secttypes[i].x)*sizeof(sectortype));
  252.     close(enroll_sectdata);
  253.  
  254.     putplanet(enroll_pdata,planet,Stars[star]->planetpos[pnum-1]);
  255.     close(enroll_pdata);
  256.  
  257.         /* make star explored and stuff */
  258.     openstardata(&enroll_stardata);
  259.      getstar(enroll_stardata,&Stars[star],star);
  260.       setbit(Stars[star]->explored,Playernum);
  261.       setbit(Stars[star]->inhabited,Playernum);
  262.       Stars[star]->AP[Playernum] = 5;
  263.      putstar(enroll_stardata,Stars[star],star);
  264.     close(enroll_stardata);
  265.  
  266.     fd = fopen(PLAYERDATAFL,"a");
  267.     fprintf(fd,"%s\n",loginname );
  268.     fclose(fd);
  269.  
  270.         sigsetmask(mask);
  271.  
  272.     printf("You are player %d.\n",Playernum);
  273.     printf("Your race has been created on sector %d,%d on\n",
  274.                         secttypes[i].x,secttypes[i].y);
  275.     printf("Planet %d of star %s.\n",pnum+1,Stars[star]->name);
  276.  
  277.     /* chdir to your new home planet */
  278.     docommand("cs");
  279.  
  280. }
  281.