home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume3 / conquer / part01 / newlogin.c < prev    next >
C/C++ Source or Header  |  1988-01-23  |  26KB  |  938 lines

  1. /*conquer is copyrighted 1986 by Ed Barlow.
  2.  *  I spent a long time writing this code & I hope that you respect this.  
  3.  *  I give permission to alter the code, but not to copy or redistribute
  4.  *  it without my explicit permission.  If you alter the code, 
  5.  *  please document changes and send me a copy, so all can have it.  
  6.  *  This code, to the best of my knowledge works well,  but it is my first
  7.  *  'C' program and should be treated as such.  I disclaim any
  8.  *  responsibility for the codes actions (use at your own risk).  I guess
  9.  *  I am saying "Happy gaming", and am trying not to get sued in the process.
  10.  *                                                Ed
  11.  */
  12.  
  13. /*create a new login for a new player*/
  14. #include <ctype.h>
  15.  
  16. #include "header.h"
  17. #include "data.h"
  18.  
  19. extern FILE *fexe, *fopen();
  20. extern short country;
  21.  
  22. newlogin()
  23. {
  24.     /* use points to create empire, add if late starter*/
  25.     int points;
  26.     char tempc[10];
  27.     int n;
  28.     int valid=1;  /*valid == 0 means continue loop*/
  29.     int temp;
  30.     int more=0;     /*0 if add another player*/
  31.     int loop;
  32.     int x;
  33.     char tempo[8];
  34.     char passwd[8];
  35.     register i;
  36.  
  37.     printf("\nPreparing to add player\n");
  38.     printf("break at any time to abort\n");
  39.  
  40.     while(more==0) {
  41.         points=MAXPTS;
  42.         /*find valid nation number type*/
  43.         for(i=1;i<MAXNTN;i++)
  44.             if(ntn[i].active==0) {
  45.                 country=i;
  46.                 break;
  47.             }
  48.         printf("first valid nation id is %d\n",country);
  49.  
  50.         if(i==MAXNTN) {
  51.             beep();
  52.             printf("error, cant add new nation\n");
  53.             return;
  54.         }
  55.  
  56.         /* open output for future printing*/
  57.         sprintf(tempc,"%s%d",exefile,i);
  58.         if ((fexe=fopen(tempc,"a"))==NULL) {
  59.             beep();
  60.             printf("error opening %s\n",tempc);
  61.             exit(1);
  62.         }
  63.  
  64.         ntn[country].active=1;
  65.  
  66.         valid=0;
  67.         /*get name*/
  68.         while(valid==0) {
  69.             valid=1;
  70.             printf("\nwhat name would you like your nation to have:");
  71.             scanf("%9s",ntn[country].name);
  72.  
  73.             if((strlen(ntn[country].name)<=1)
  74.              ||(strlen(ntn[country].name)>NAMELTH)){
  75.                 printf("\ninvalid name");
  76.                 valid=0;
  77.             }
  78.  
  79.             /*check if already used*/
  80.             if((strcmp(ntn[country].name,"god")==0)
  81.             ||(strcmp(ntn[country].name,"unowned")==0)){
  82.                 printf("\nname already used");
  83.                 valid=0;
  84.             }
  85.  
  86.             for(i=1;i<(country-1);i++)
  87.                 if(strcmp(ntn[i].name,ntn[country].name)==0) {
  88.                     printf("\nname already used");
  89.                     valid=0;
  90.                 }
  91.         }
  92.  
  93.         /*get password*/
  94.         valid=0;
  95.         while(valid==0) {
  96.             printf("\nwhat is your nations password:");
  97.             scanf("%7s",passwd);
  98.             if((strlen(passwd)>PASSLTH)||(strlen(passwd)<2)) {
  99.                 beep();
  100.                 printf("\ninvalid password (too short or long)");
  101.             }
  102.             else {
  103.                 printf("\nreenter your nations password:");
  104.                 scanf("%7s",ntn[country].passwd);
  105.             }
  106.             if(strcmp(passwd,ntn[country].passwd)==0) valid=1;
  107.         }
  108.         strncpy(ntn[country].passwd,crypt(passwd,SALT),PASSLTH);
  109.  
  110.         /*get your name*/
  111.         valid=0;
  112.         while(valid==0) {
  113.             valid=1;
  114.             printf("\nenter either YOUR name (j_smith) or the name of your nations leader (gandalf...)");
  115.             printf("\n\t(maximum 10 characters, no spaces):");
  116.             scanf("%9s",tempc);
  117.             if((strlen(tempc)>=10)||(strlen(tempc)<2)) {
  118.                 beep();
  119.                 printf("\ninvalid name (too short or long)");
  120.                 valid=0;
  121.             }
  122.             else strcpy(ntn[country].leader,tempc);
  123.         }
  124.  
  125.         valid=0;
  126.         while(valid==0) {
  127.             valid=1;
  128.             printf("\nwhat race would you like to be:");
  129.             printf("\n\tchoose (d)warf,(e)lf,(o)rc,(h)uman:");
  130.             scanf("%1s",tempo);
  131.             switch(tempo[0]) {
  132.             case 'd':
  133.                 printf("\ndwarf chosen\n");
  134.                 /*MINER POWER INATE TO DWARVES*/
  135.                 printf("you have magical MINING skills\n");
  136.                 ntn[country].powers=MINER;
  137.                 x=MINER;
  138.                 CHGMGK;
  139.                 points -= getclass(DWARF);
  140.                 ntn[country].race=DWARF;
  141.                 ntn[country].tgold=100000;    /*1   pts*/
  142.                 ntn[country].tfood=12000;     /*0   pts*/
  143.                 ntn[country].jewels=10000;     /*0   pts*/
  144.                 ntn[country].tiron=10000;     /*0   pts*/
  145.                 ntn[country].tciv= 6000;    /*6   pts*/
  146.                 ntn[country].tmil= 1500;    /*1.5 pts*/
  147.                 ntn[country].repro=   4;    /*4   pts*/
  148.                 ntn[country].maxmove= 6;    /*1.5 pts*/
  149.                 ntn[country].aplus=   20;    /*2   pts*/
  150.                 ntn[country].dplus=   20;    /*2   pts*/
  151.                 ntn[country].location=RANDOM;    /*0+  pts*/
  152.                 points-=18;
  153.                 break;
  154.             case 'e':
  155.                 printf("\nelf chosen\n");
  156.                 printf("you have magical cloaking skills\n");
  157.                 ntn[country].powers=THE_VOID;
  158.                 x=THE_VOID;
  159.                 CHGMGK;
  160.                 points -= getclass(ELF);
  161.                 ntn[country].race=ELF;
  162.                 ntn[country].tgold=100000;    /*1  pts*/
  163.                 ntn[country].tfood=12000;
  164.                 ntn[country].jewels=10000;
  165.                 ntn[country].tiron=10000;
  166.                 ntn[country].tciv=7000;    /*7    pts*/
  167.                 ntn[country].tmil=200;        /*0   pts*/
  168.                 ntn[country].repro=3;        /*3   pts*/
  169.                 ntn[country].maxmove=8;        /*2   pts*/
  170.                 ntn[country].aplus=10;         /*1   pts*/
  171.                 ntn[country].dplus=40;        /*4   pts*/
  172.                 ntn[country].location=FAIR;    /*1   pts*/
  173.                 points-=20;    /* VOID COSTS ADDITIONAL PT*/
  174.                 break;
  175.             case 'o':
  176.                 printf("\norc chosen\n");
  177.                 /*MINOR MONSTER POWER INATE TO ORCS*/
  178.                 printf("your leader is a minor monster (army 0 is very potent)\n");
  179.                 ntn[country].powers=MI_MONST;
  180.                 x=MI_MONST;
  181.                 CHGMGK;
  182.                 points -= getclass(ORC);
  183.                 ntn[country].race=ORC;
  184.                 ntn[country].tgold=1000;    /*0   pts*/
  185.                 ntn[country].tfood=12000;
  186.                 ntn[country].jewels=10000;
  187.                 ntn[country].tiron=10000;
  188.                 ntn[country].tciv=4000;    /*4   pts*/
  189.                 ntn[country].tmil=2500;    /*2.5 pts*/
  190.                 ntn[country].repro=10;    /*10  pts*/
  191.                 ntn[country].maxmove=6;    /*1.5 pts*/
  192.                 ntn[country].aplus=00;    /*0   pts*/
  193.                 ntn[country].dplus=00;    /*0   pts*/
  194.                 ntn[country].location=RANDOM;    /*0   pts*/
  195.                 points-=18;
  196.                 break;
  197.             case 'h':
  198.                 printf("\nhuman chosen\n");
  199.                 ntn[country].race=HUMAN;
  200.                 /*WARRIOR POWER INATE TO HUMANS*/
  201.                 printf("you have magical WARRIOR skills\n");
  202.                 ntn[country].powers=WARRIOR;
  203.                 x=WARRIOR;
  204.                 CHGMGK;
  205.                 points -= getclass(HUMAN);
  206.                 ntn[country].tgold=1000;    /*0  pts*/
  207.                 ntn[country].tfood=12000;    /*0   pts*/
  208.                 ntn[country].jewels=10000;    /*0   pts*/
  209.                 ntn[country].tiron=10000;    /*0   pts*/
  210.                 ntn[country].tciv=6000;        /*6   pts*/
  211.                 ntn[country].tmil=1000;        /*1   pts*/
  212.                 ntn[country].repro=5;        /*5   pts*/
  213.                 ntn[country].maxmove=10;    /*2.5 pts*/
  214.                 ntn[country].aplus=10;    /*1   pts*/
  215.                 ntn[country].dplus=10;    /*1   pts*/
  216.                 ntn[country].location=RANDOM;    /*0   pts*/
  217.                 points-=18;
  218.                 break;
  219.             default:
  220.                 printf("\ninvalid race\n ");
  221.                 valid=0;
  222.             }
  223.         }
  224.  
  225.         ntn[country].mark=(*ntn[country].name);
  226.         printf("\ntesting first letter of name (%c) for nation mark...",ntn[country].mark);
  227.         valid=1;
  228.         while(valid==1) {
  229.             valid=0;
  230.             if((isprint(ntn[country].mark)==0)
  231.             ||(isspace(ntn[country].mark)!=0)) {
  232.                 printf("\n%c is not a graphical character",ntn[country].mark);
  233.                 valid=1;
  234.             }
  235.             if(valid==0) for(i=0;i<=3;i++) if(ntn[country].mark==(*(ele+i))) {
  236.                 printf("\n%c is an altitude character",ntn[country].mark);
  237.                 valid=1;
  238.             }
  239.             if(valid==0) for(i=0;i<=11;i++) if(ntn[country].mark==(*(veg+i))) {
  240.                 printf("\n%c is a vegetation character", ntn[country].mark );
  241.                 valid=1;
  242.             }
  243.             if(valid==0) for(i=1;i<country;i++) if(ntn[i].mark==ntn[country].mark) {
  244.                 printf("\n%c is an already used character",ntn[country].mark);
  245.                 valid=1;
  246.             }
  247.             if(valid==0) if(ntn[i].mark=='*') {
  248.                 printf("\n'*' is invalid character");
  249.                 valid=1;
  250.             }
  251.             if(valid==1){
  252.                 printf("\nplease reenter new national mark for maps:");
  253.                 printf("\n (this can be any printing key like ! or O)");
  254.                 scanf("%1s",tempc);
  255.                 ntn[country].mark=(*tempc);
  256.             }
  257.             else printf("\nvalid...");
  258.         }
  259.  
  260.         printf("mark currently is %c\n",ntn[country].mark);
  261.  
  262.         while(points>0) {
  263.             printf("\n\nwhat would you like to buy with your remaining %d points\n\n",points);
  264.             printf("\t1. population (1000/pt):\t\tnow have %ld civilians\n",ntn[country].tciv);
  265.             printf("\t2. more gold ($100000/pt):\t\tnow have %ld gold pieces\n",ntn[country].tgold);
  266.             printf("\t3. better location:\t\t\tlocation is now is %c\n",ntn[country].location);
  267.             printf("\t4. more soldiers (1000/pt):\t\tnow have %ld soldiers\n",ntn[country].tmil);
  268.             printf("\t5. better attack (10%%/pt):\t\tnow is +%d\n ",ntn[country].aplus);
  269.             printf("\t6. better defence (10%%/pt):\t\tnow is +%d\n",ntn[country].dplus);
  270.             printf("\t7. higher reproduction (1%%/pt):\t\trate is now %d%%\n",ntn[country].repro);
  271.             printf("\t8. higher movement (4/pt): \t\tnow move %d sectors\n",ntn[country].maxmove);
  272.             printf("\t9. double raw recourses (1 pt): \tfood now %ld\n",ntn[country].tfood);
  273.             printf("\t                                \tjewels now %ld\n",ntn[country].jewels);
  274.             printf("\t                                \tiron now %ld\n",ntn[country].tiron);
  275.             printf("\t10. additional random magic power (1 pt)\n");
  276.  
  277.  
  278.             printf("\nWhat option to buy:");
  279.             scanf("%d",&n);
  280.             switch(n) {
  281.  
  282.             case 1:
  283.                 printf("additional population costs 1 pt per 1000\n");
  284.                 printf("how many points to spend on population:");
  285.                 scanf("%d",&temp);
  286.                 putchar('\n');
  287.                 if(points >= temp) {
  288.                     points -= temp;
  289.                     ntn[country].tciv+=temp*1000;
  290.                 }
  291.                 else printf("You dont have enough points left");
  292.                 break;
  293.             case 2:
  294.                 printf("you now have $%ld\n",ntn[country].tgold);
  295.                 printf("and can buy gold at $100000 per point\n");
  296.                 printf("how many points to spend on added gold:");
  297.                 scanf("%d",&temp);
  298.                 putchar('\n');
  299.                 if(points>=temp)
  300.                 {
  301.                     points-=temp;
  302.                     ntn[country].tgold+=temp*100000;
  303.                 }
  304.                 else printf("You dont have enough points left");
  305.                 break;
  306.             case 3:
  307.                 printf("you now are in %c location\n",ntn[country].location);
  308.                 printf("  R=random, F=fair, G=good\n");
  309.                 if(ntn[country].location==RANDOM){
  310.                     printf("2pts for (g)ood location or 1pts for (f)air\n");
  311.                 }
  312.                 if(ntn[country].location==FAIR){
  313.                     printf("1pts for (g)ood location\n");
  314.                 }
  315.                 if(ntn[country].location==GREAT) return;
  316.  
  317.                 printf("what type of location do you wish:");
  318.                 scanf("%1s",tempo);
  319.                 switch(tempo[0]) {
  320.                 case 'g':
  321.                 case GREAT:
  322.                     if(ntn[country].location==FAIR){
  323.                         printf("1pts for (g)ood location\n");
  324.                         if(points>=1) {
  325.                             points -=1;
  326.                             ntn[country].location=GREAT;
  327.                         }
  328.                         else printf("You dont have enough points left");
  329.                     }
  330.                     else {
  331.                         if(points>=2) {
  332.                             points -=2;
  333.                             ntn[country].location=GREAT;
  334.                         }
  335.                         else printf("You dont have enough points left");
  336.                     }
  337.                     break;
  338.                 case 'f':
  339.                 case FAIR:
  340.                     if(ntn[country].location==RANDOM){
  341.                         if(points>=1) {
  342.                             points -=1;
  343.                             ntn[country].location=FAIR;
  344.                         }
  345.                         else printf("You dont have enough points left");
  346.                     }
  347.                     else printf("\nlocation unchanged\n");
  348.                     break;
  349.                 default:
  350.                     printf("\nlocation unchanged\n");
  351.                 }
  352.                 putchar('\n');
  353.                 break;
  354.             case 4:
  355.                 printf("you start with %ld soldiers\n",ntn[country].tmil);
  356.                 printf("additional military costs 1 /  1000\n");
  357.                 printf("how many points you wish:");
  358.                 scanf("%d",&temp);
  359.                 putchar('\n');
  360.                 if(points >= temp) {
  361.                     points -= temp;
  362.                     ntn[country].tmil+=temp*1000;
  363.                 }
  364.                 else printf("You dont have enough points left");
  365.                 break;
  366.             case 5:
  367.                 if(magic(country,VAMPIRE)==1) {
  368.                 printf("you have vampire power and cant add to combat bonus\n");
  369.                 break;
  370.                 }
  371.                 printf("now have %d percent attack bonus\n",ntn[country].aplus);
  372.                 printf("an additional 10 percent per point\n");
  373.                 printf("how many points you wish:");
  374.                 scanf("%d",&temp);
  375.                 putchar('\n');
  376.                 if(points >= temp) {
  377.                     points -= temp;
  378.                     ntn[country].aplus+=temp*10;
  379.                 }
  380.                 else printf("You dont have enough points left");
  381.                 break;
  382.             case 6:
  383.                 if(magic(country,VAMPIRE)==1) {
  384.                 printf("you have vampire power and cant add to combat bonus\n");
  385.                 break;
  386.                 }
  387.                 printf("now have %d percent defence bonus\n",ntn[country].dplus);
  388.                 printf("an additional 10 percent per point\n");
  389.                 printf("how many points you wish:");
  390.                 scanf("%d",&temp);
  391.                 putchar('\n');
  392.                 if(points >= temp) {
  393.                     points -= temp;
  394.                     ntn[country].dplus+=temp*10;
  395.                 }
  396.                 else printf("You dont have enough points left");
  397.                 break;
  398.             case 7:
  399.                 printf("repro rate costs 1 per percent\n");
  400.                 printf("you now have %d percent\n",ntn[country].repro);
  401.                 if((ntn[country].race!=ORC)
  402.                 &&(ntn[country].repro>10)){
  403.                     printf("you have the maximum rate");
  404.                     break;
  405.                 }
  406.                 printf("how many points you wish:");
  407.                 scanf("%d",&temp);
  408.                 putchar('\n');
  409.                 if(points >= temp) {
  410.                     if((ntn[country].race!=ORC)
  411.                     &&(ntn[country].repro+temp>10)){
  412.                     printf("that exceeds the 10%% limit");
  413.                     }
  414.                     else {
  415.                     points -= temp;
  416.                     ntn[country].repro+=temp;
  417.                     }
  418.                 }
  419.                 else printf("You dont have enough points left");
  420.                 break;
  421.             case 8:
  422.                 printf("additional movement costs 1 per +4 sct/turn\n");
  423.                  printf("you start with a rate of %d\n",ntn[country].maxmove);
  424.                  printf("you now have a rate of %d\n",ntn[country].maxmove+4);
  425.                 putchar('\n');
  426.                 if(points >= 1) {
  427.                     points -= 1;
  428.                     ntn[country].maxmove+=4;
  429.                 }
  430.                 else printf("You dont have enough points left");
  431.                 break;
  432.             case 9:
  433.                 printf("doubling raw materials\n");
  434.                 if((ntn[country].tfood<8000000)
  435.                 &&(points >0)) {
  436.                     points--;
  437.                     ntn[country].tfood*=2;
  438.                     ntn[country].jewels*=2;
  439.                     ntn[country].tiron*=2;
  440.                 }
  441.                 else printf("sorry\n");
  442.                 break;
  443.             case 10:
  444.                 printf("choosing basic magic at 1 point cost\n");
  445.                 printf("log in and read the magic screen to be informed of your powers\n");
  446.                 if(points >0) {
  447.                     points--;
  448.                     loop=0;
  449.                     while(loop==0) if((x=getmagic())!=0){
  450.                         CHGMGK;
  451.                         loop=1;
  452.                     }
  453.                 }
  454.                 else printf("sorry not enough points\n");
  455.                 break;
  456.             default:
  457.                 printf("invalid option\n");
  458.             }
  459.         }
  460.  
  461.         ntn[country].powers=0;;
  462.         printnat();
  463.         printf("\nhit 'y' if OK?");
  464.         getchar();
  465.         if(getchar()!='y'){
  466.             ntn[country].active=0;
  467.             getchar();
  468.             printf("\n OK, nation deleted\n");
  469.             printf("\nhit return to add another nation");
  470.             printf("\nhit any other key to continue?");
  471.             if(getchar()=='\n') more=0;
  472.             else more=1;
  473.             putchar('\n');
  474.         }
  475.         else {
  476.             place();
  477.             getchar();
  478.             printf("\nNation is now added to world");
  479.             printf("\nhit return to add another nation");
  480.             printf("\nhit any other key to continue?");
  481.             if(getchar()=='\n') more=0;
  482.             else more=1;
  483.             putchar('\n');
  484.         }
  485.         fclose(fexe);
  486.     }
  487.     writedata();
  488. }
  489.  
  490. printnat()
  491. {
  492.     int i;
  493.     i=country;
  494.     printf("about to print stats for nation %d\n\n",i);
  495.     printf("name is %10s\n",ntn[i].name);
  496.     printf("leader is %10s\n",ntn[i].leader);
  497.     printf("total sctrs %2d\n",ntn[i].tsctrs);
  498.     printf("class is %8s\n",*(Class+ntn[i].class));
  499.     printf("mark is %c\n",ntn[i].mark);
  500.     printf("race is %c\n",ntn[i].race);
  501.     printf("attack plus is +%2d\n",ntn[i].aplus);
  502.     printf("defence plus is +%2d\n",ntn[i].dplus);
  503.     printf("gold is %5ld\n",ntn[i].tgold);
  504.     printf("maxmove is %2d sctrs\n",ntn[i].maxmove);
  505.     printf("jewels is %2ld\n",ntn[i].jewels);
  506.     printf("# military %5ld\n",ntn[i].tmil);
  507.     printf("# civilians %5ld\n",ntn[i].tciv);
  508.     printf("repro is %2d percent\n",ntn[i].repro);
  509.     printf("total iron %5ld\n",ntn[i].tiron);
  510.     printf("total food %5ld\n",ntn[i].tfood);
  511.     printf("total ships %2d\n",ntn[i].tships);
  512. }
  513.  
  514. /*PLACE NATION*/
  515. place()
  516. {
  517.     int placed=0;
  518.     int t;
  519.     int temp;
  520.     int n; /*count vbl for inf loop*/
  521.     short armynum=0;
  522.     register i,j,x,y;
  523.  
  524.     n=0;
  525.     updmove(ntn[country].race);
  526.     switch(ntn[country].location) {
  527.     case OOPS:
  528.         while ((placed == 0)&&(n++<2000)){
  529.             if(ntn[country].active==1){
  530.                 x = (rand()%(MAPX-8))+4;
  531.                 y = (rand()%(MAPY-8))+4;
  532.             }
  533.             else {
  534.                 x = (rand()%(MAPX-2))+1;
  535.                 y = (rand()%(MAPY-2))+1;
  536.             }
  537.             if(is_habitable(x,y)) placed=1;
  538.  
  539.             for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++)
  540.                 if(sct[i][j].owner!=0) placed=0;
  541.             temp=0;
  542.             for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++)
  543.                 if(sct[i][j].altitude==WATER) temp++;
  544.             if(temp>=7) placed=0;
  545.  
  546.             if((movecost[x][y]<=0)||(movecost[x][y]>5)) placed=0;
  547.         }
  548.         break;
  549.     case RANDOM:
  550.         while ((placed == 0)&&(n++<2000)){
  551.             if(ntn[country].active==1){
  552. #if (MAPX>12)
  553.                 x = rand()%(MAPX-12)+6;
  554.                 y = rand()%(MAPY-12)+6;
  555. #else
  556.                 x = rand()%(MAPX-8)+4;
  557.                 y = rand()%(MAPY-8)+4;
  558. #endif
  559.                 if(is_habitable(x,y)) placed=1;
  560.                 /*important that no countries near*/
  561.                 for(i=x-4;i<=x+4;i++) for(j=y-4;j<=y+4;j++)
  562.                     if((sct[i][j].owner<MAXNTN)
  563.                     &&(sct[i][j].owner!=0)) placed=0;
  564.             }
  565.             else {
  566.                 x = (rand()%(MAPX-6))+3;
  567.                 y = (rand()%(MAPY-6))+3;
  568.                 if(is_habitable(x,y)) placed=1;
  569.                 /*important that no countries near*/
  570.                 for(i=x-2;i<=x+2;i++) for(j=y-2;j<=y+2;j++)
  571.                     if((sct[i][j].owner<MAXNTN)
  572.                     &&(sct[i][j].owner!=0)) placed=0;
  573.             }
  574.             temp=0;
  575.             for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++)
  576.                 if(sct[i][j].altitude==WATER) temp++;
  577.             if(temp>=7) placed=0;
  578.             for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++)
  579.                 if(sct[i][j].owner!=0) placed=0;
  580.             if((movecost[x][y]<=0)||(movecost[x][y]>4)) placed=0;
  581.         }
  582.         if (placed==1) for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++)
  583.             if(sct[i][j].altitude!=WATER) sct[i][j].vegetation=GOOD;
  584.         break;
  585.     case FAIR:
  586.         while ((placed == 0)&&(n++<2000)) {
  587.             if(ntn[country].active==1){
  588. #if (MAPX>24)
  589.                 x = rand()%(MAPX-24)+12;
  590.                 y = rand()%(MAPY-24)+12;
  591. #else
  592.                 x = rand()%(MAPX-14)+7;
  593.                 y = rand()%(MAPY-14)+7;
  594. #endif
  595.             }
  596.             else {
  597.                 x = rand()%(MAPX-10)+5;
  598.                 y = rand()%(MAPY-10)+5;
  599.             }
  600.  
  601.             if(is_habitable(x,y)) placed=1;
  602.  
  603.             for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++)
  604.                 if(sct[i][j].owner!=0) placed=0;
  605.  
  606.             if((movecost[x][y]>0)&&(movecost[x][y]<=4)){
  607. #if(PWATER>50)
  608.                 temp=0;
  609.                 for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++)
  610.                     if(sct[i][j].altitude==WATER) temp++;
  611.                 if(temp>=7) placed=0;
  612.  
  613.                 /*important that no countries near*/
  614.                 for(i=x-3;i<=x+3;i++) for(j=y-3;j<=y+3;j++){
  615.                 if((sct[i][j].owner<MAXNTN)
  616.                     &&(sct[i][j].owner!=0)) placed=0;
  617.                 }
  618. #else
  619.                 temp=0;
  620.                 for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++)
  621.                     if(sct[i][j].altitude==WATER) temp++;
  622.                 if(temp>=5) placed=0;
  623.  
  624.                 /*important that no countries near*/
  625.                 for(i=x-2;i<=x+2;i++) for(j=y-2;j<=y+2;j++){
  626.                 if((sct[i][j].owner<MAXNTN)
  627.                     &&(sct[i][j].owner!=0)) placed=0;
  628.                 }
  629. #endif
  630.             }
  631.             else placed=0;
  632.         }
  633.         if (placed==1) for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++)
  634.             if(sct[i][j].altitude!=WATER) sct[i][j].vegetation=GOOD;
  635.         break;
  636.     case GREAT:
  637.         placed = 0;
  638.         while ((placed == 0) && (n++<2000)){
  639.             if(ntn[country].active==1){
  640. #if (MAPX>40)
  641.                 x = rand()%(MAPX-40)+20;
  642.                 y = rand()%(MAPY-40)+20;
  643. #else
  644.                 x = rand()%(MAPX-18)+9;
  645.                 y = rand()%(MAPY-18)+9;
  646. #endif
  647.  
  648.                 if(is_habitable(x,y)) placed=1;
  649.                 /*important that no countries near*/
  650.                 for(i=x-4;i<=x+4;i++) for(j=y-4;j<=y+4;j++){
  651.                 if((sct[i][j].owner<MAXNTN)
  652.                     &&(sct[i][j].owner!=0)) placed=0;
  653.                 }
  654.             }
  655.             else {
  656. #if (MAPX>24)
  657.                 x = rand()%(MAPX-24)+12;
  658.                 y = rand()%(MAPY-24)+12;
  659. #else
  660.                 x = rand()%(MAPX-12)+6;
  661.                 y = rand()%(MAPY-12)+6;
  662. #endif
  663.                 if(is_habitable(x,y)) placed=1;
  664.                 /*important that no countries near*/
  665.                 for(i=x-2;i<=x+2;i++) for(j=y-2;j<=y+2;j++){
  666.                 if((sct[i][j].owner<MAXNTN)
  667.                     &&(sct[i][j].owner!=0)) placed=0;
  668.                 }
  669.             }
  670.  
  671.             for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++)
  672.                 if(sct[i][j].owner!=0) placed=0;
  673.  
  674.             if((movecost[x][y]>0)&&(movecost[x][y]<4)){
  675.                 temp=0;
  676. #if(PWATER>50)
  677.                 /*if any water within 2 sectors placed = 0*/
  678.                 for(i=x-2;i<=x+2;i++) for(j=y-2;j<=y+2;j++)
  679.                     if(movecost[x][y]<0) temp++;
  680.                 if(temp>=18) placed=0;
  681. #else 
  682.                 for(i=x-2;i<=x+1;i++) for(j=y-2;j<=y+1;j++)
  683.                     if(movecost[x][y]<0) temp++;
  684.                 if(temp>=15) placed=0;
  685. #endif
  686.  
  687.                 if (placed==1) switch(ntn[country].race) {
  688.                 case DWARF:
  689.                     sct[x][y].altitude=MOUNTAIN;
  690.                     sct[x][y].designation=MOUNTAIN;
  691.                     for(i=x-1;i<=x+1;i++) 
  692.                     for(j=y-1;j<=y+1;j++) 
  693.                     if((i!=x)&&(j!=y)
  694.                     &&(sct[i][j].altitude!=WATER)){
  695.                         if (rand()%3==0) {
  696.                         sct[i][j].altitude=MOUNTAIN;
  697.                         sct[i][j].designation=MOUNTAIN;
  698.                         sct[i][j].gold=rand()%6;
  699.                         sct[i][j].iron=rand()%6;
  700.                         }
  701.                         else {
  702.                         sct[i][j].altitude=HILL;
  703.                         sct[i][j].designation=HILL;
  704.                         sct[i][j].iron=rand()%4;
  705.                         sct[i][j].gold=rand()%4;
  706.                         }
  707.                     }
  708.                     break;
  709.                 case ELF:
  710.                     sct[x][y].vegetation = FORREST;
  711.                     for(i=x-1;i<=x+1;i++) 
  712.                     for(j=y-1;j<=y+1;j++) 
  713.                     if((i!=x)&&(j!=y)
  714.                     &&(sct[i][j].altitude!=WATER)) {
  715.                         if (rand()%3==0)
  716.                         sct[i][j].vegetation=FORREST;
  717.                         else sct[i][j].vegetation=WOOD;
  718.  
  719.                         if (rand()%2==0)
  720.                             sct[i][j].gold=rand()%8;
  721.                         else sct[i][j].gold=rand()%4;
  722.                     }
  723.                     break;
  724.                 case ORC:
  725.                     sct[x][y].altitude=MOUNTAIN;
  726.                     for(i=x-1;i<=x+1;i++) 
  727.                     for(j=y-1;j<=y+1;j++) 
  728.                     if((i!=x)&&(j!=y)
  729.                     &&(sct[i][j].altitude!=WATER)) {
  730.                         if (rand()%3==0) {
  731.                         sct[i][j].altitude=MOUNTAIN;
  732.                         sct[i][j].designation=MOUNTAIN;
  733.                         }
  734.                         else {
  735.                         sct[i][j].altitude=HILL;
  736.                         sct[i][j].designation=HILL;
  737.                         }
  738.                         if (rand()%2==0){
  739.                             sct[i][j].iron=rand()%8;
  740.                             sct[i][j].gold=rand()%8;
  741.                         }
  742.                         else {
  743.                             sct[i][j].iron=rand()%4;
  744.                             sct[i][j].gold=rand()%4;
  745.                         }
  746.                     }
  747.                     break;
  748.                 case HUMAN:
  749.                     sct[x][y].altitude = CLEAR;
  750.                     for(i=x-1;i<=x+1;i++) 
  751.                     for(j=y-1;j<=y+1;j++) 
  752.                     if((i!=x)&&(j!=y)
  753.                     &&(sct[i][j].altitude!=WATER)) {
  754.                         if (rand()%2==0)
  755.                         sct[x][y].altitude = CLEAR;
  756.  
  757.                         if (rand()%2==0)
  758.                         sct[i][j].vegetation=WOOD;
  759.                         else 
  760.                         sct[i][j].vegetation=GOOD;
  761.  
  762.                         if (rand()%2==0)
  763.                         sct[i][j].gold=rand()%7+1;
  764.                         else 
  765.                         sct[i][j].iron=rand()%7+1;
  766.                     }
  767.                     break;
  768.                 }
  769.             }
  770.             else placed=0;
  771.         }
  772.     }
  773.  
  774.     /*done with one try*/
  775.     if(placed==1) {
  776.         ntn[country].capx = x;
  777.         ntn[country].capy = y;
  778.         sct[x][y].designation=DCAPITOL;
  779.         sct[x][y].owner=country;
  780.         sct[x][y].people=ntn[country].tciv;
  781.         sct[x][y].fortress=5;
  782.  
  783.         /* put all military into armies of 100 */
  784.         armynum=0;
  785.         temp= (int) ntn[country].tmil;
  786.         ASOLD= (int) ntn[country].tmil/3;
  787.         temp-=ASOLD;
  788.         ASTAT=GARRISON;
  789.         AMOVE=0;
  790.         AXLOC=ntn[country].capx;
  791.         AYLOC=ntn[country].capy;
  792.         armynum++;
  793.         while ((armynum < MAXARM-1)&&(temp>0)) {
  794.             if(temp>100){
  795.                 ASOLD=100;
  796.                 temp-=100;
  797.             }
  798.             else {
  799.                 ASOLD=temp;
  800.                 temp=0;
  801.             }
  802.             AXLOC=ntn[country].capx;
  803.             AYLOC=ntn[country].capy;
  804.             ASTAT=DEFEND;
  805.             AMOVE=ntn[country].maxmove;
  806.             armynum++;
  807.         }
  808.         if(temp>0) {
  809.             armynum=0;
  810.             ASOLD+=temp;
  811.         }
  812.  
  813.         /* give you some terain to start with: pc nations get more*/
  814.         if ((ntn[country].active>=2)&&(ntn[country].location==GREAT))
  815.             t=1;
  816.         else if (ntn[country].active>=2) t=0;
  817.         else if (ntn[country].location==OOPS) t=0;
  818.         else if (ntn[country].location==RANDOM) t=0;
  819.         else if (ntn[country].location==FAIR) t=1;
  820.         else if (ntn[country].location==GREAT) t=2;
  821.         else printf("error");
  822.  
  823.         for(i=x-t;i<=x+t;i++) for(j=y-t;j<=y+t;j++)
  824.             if((movecost[i][j]>=0)
  825.             &&(sct[i][j].owner==0)
  826.             &&(sct[i][j].people==0)) {
  827.                 sct[i][j].owner=country;
  828.                 sct[i][j].designation=DFARM;
  829.             }
  830.     }
  831.     else {
  832.         if(ntn[country].location==OOPS) printf("ERROR\n");
  833.         else if(ntn[country].location==RANDOM) {
  834.             printf("RANDOM PLACE FAILED, TRYING TO PLACE AGAIN\n");
  835.             ntn[country].location=OOPS;
  836.             place();
  837.         }
  838.         else if(ntn[country].location==FAIR) {
  839.             printf("FAIR PLACE FAILED, TRYING AGAIN - adding 1000 people to nation\n");
  840.             /*give back one point -> 1000 people*/
  841.             ntn[country].tciv+=1000;
  842.             ntn[country].location=RANDOM;
  843.             place();
  844.         }
  845.         else if(ntn[country].location==GREAT) {
  846.             printf("GOOD PLACE FAILED, TRYING AGAIN - adding 1000 people to nation\n");
  847.             /*give back one point -> 1000 people*/
  848.             ntn[country].tciv+=1000;
  849.             ntn[country].location=FAIR;
  850.             place();
  851.         }
  852.     }
  853. }
  854.  
  855. /*get class routine*/
  856. /* return the number of points needed */
  857. getclass(race)
  858. {
  859.     short check=0;
  860.     int x;
  861.     short tmp;
  862.     while(check==0){
  863.         printf("what type of nation would you like to be\n");
  864.         if(race!=ORC){
  865.             printf("1. king      (Humans, Dwarves, and Elves)\n");
  866.             printf("2. emperor   (Humans, Dwarves, and Elves)\n");
  867.             printf("3. wizard    (Humans, Dwarves, and Elves)........Cost = 1 Point\n");
  868.             printf("\tA wizard will have the magical SPY power automatically. \n");
  869.         }
  870.         if(race==HUMAN){
  871.             printf("4. theocracy (Humans Only).......................Cost = 2 Points\n");
  872.             printf("\tA theocracy will have the magical HEALER power automatically. \n");
  873.         }
  874.         if((race==HUMAN)||(race==ORC))
  875.             printf("5. pirate    (Humans & Orcs Only)\n");
  876.         if((race==ELF)||(race==DWARF))
  877.             printf("6. trader    (Elves & Dwarves Only)\n");
  878.         if((race==HUMAN)||(race==ORC))
  879.             printf("7. tyrant    (Humans & Orcs Only)\n");
  880.         if(race==ORC){
  881.             printf("8. demon     (Orcs Only).........................Cost = 2 Points\n");
  882.             printf("\tA demon will have the magical DESTROYER power automatically\n");
  883.             printf("9. dragon    (Orcs Only).........................Cost = 2 Points\n");
  884.             printf("\tA dragon will have the magical MAJOR MONSTER power automatically\n");
  885.             printf("10. shadow    (Orcs Only)........................Cost = 1 Point\n");
  886.             printf("\tA shadow will have the magical HIDDEN power automatically\n");
  887.         }
  888.         printf("\tinput:");
  889.         scanf("%hd",&tmp);
  890.         if((tmp>=1)&&(tmp<=10)) {
  891.             if((race==HUMAN)&&((tmp<6)||(tmp==7))) check=1;
  892.             else if((race==DWARF)&&((tmp<=3)||(tmp==6))) check=1;
  893.             else if((race==ELF)&&((tmp==6)||(tmp<=3))) check=1;
  894.             else if((race==ORC)&&((tmp==5)||(tmp>6))) check=1;
  895.             else printf("bad input \n\n\n");
  896.         } 
  897.         else printf("\tinvalid input\n\n\n");
  898.     }
  899.     ntn[country].class=tmp;
  900.     switch(tmp){
  901.     case 3: 
  902.         printf("\nwizards have the magical SPY power automatically");
  903.         ntn[country].powers|=SPY;
  904.         x=SPY;
  905.         CHGMGK;
  906.         return(1);
  907.     case 4: 
  908.         printf("\ntheocracies have magical HEALER power automatically. ");
  909.         ntn[country].powers|=HEALER;
  910.         x=HEALER;
  911.         CHGMGK;
  912.         return(2);
  913.     case 8: 
  914.         printf("\ndemons have the magical DESTROYER power automatically");
  915.         ntn[country].powers|=DESTROYER;
  916.         x=DESTROYER;
  917.         CHGMGK;
  918.         return(2);
  919.     case 9: 
  920.         printf("\ndragons have the magical MAJOR MONSTER power automatically");
  921.         ntn[country].powers|=AV_MONST;
  922.         x=AV_MONST;
  923.         CHGMGK;
  924.         ntn[country].powers|=MA_MONST;
  925.         x=MA_MONST;
  926.         CHGMGK;
  927.         return(2);
  928.     case 10: 
  929.         printf("\nshadows have the magical HIDDEN power automatically");
  930.         ntn[country].powers|=HIDDEN;
  931.         x=HIDDEN;
  932.         CHGMGK;
  933.         return(1);
  934.     default:
  935.         return(0);
  936.     }
  937. }
  938.