home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume2 / conquest / part05 / forms.c < prev    next >
C/C++ Source or Header  |  1987-10-26  |  13KB  |  497 lines

  1. /*conquest 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.  
  14. /*    screen subroutines    */
  15.  
  16. /*include files*/
  17. #include <ctype.h>
  18. #include "header.h"
  19.  
  20. extern FILE *fexe;
  21. extern short country;
  22.  
  23. showscore()
  24. {
  25.     int i;
  26.     int done=0;
  27.     int position;
  28.     int count;        /*number of time through the loop on this screen*/
  29.     int nationid;        /*current nation id */
  30.  
  31.     nationid=1;
  32.     while((done==0)&&(nationid<MAXNTN)) {
  33.         clear();
  34.         standout();
  35.         mvaddstr(0,(COLS/2)-10,"NATION SCORE SCREEN");
  36.         standend();
  37.         mvaddstr(3,0,"nationid is:");
  38.         mvaddstr(4,0,"name is:");
  39.         mvaddstr(5,0,"leader:");
  40.         mvaddstr(6,0,"race:");
  41.         mvaddstr(7,0,"class:");
  42.         mvaddstr(8,0,"score:");
  43.         mvaddstr(9,0,"gold:");
  44.         mvaddstr(10,0,"military:");
  45.         mvaddstr(11,0,"civilians:");
  46.         mvaddstr(12,0,"sectors:");
  47.         mvaddstr(13,0,"ships:");
  48.  
  49.         count=0;
  50.         position=2;
  51.         while((nationid<MAXNTN)&&(count<5)){
  52.             if((nationid<MAXNTN)&&(ntn[nationid].active!=0)) {
  53.                 position+=13;
  54.                 mvprintw(3,position,"%d",nationid);
  55.                 standout();
  56.                 mvprintw(4,position,"%s",ntn[nationid].name);
  57.                 standend();
  58.                 mvprintw(5,position,"%s",ntn[nationid].leader);
  59.                 for(i=1;i<8;i++)
  60.                     if(ntn[nationid].race==*(races+i)[0])
  61.                         mvprintw(6,position,"%s",*(races+i));
  62.                 if(ntn[nationid].active>=2) mvprintw(7,position,"NPC");
  63.                 else mvprintw(7,position,"%s",*(Class+ntn[nationid].class));
  64.                 mvprintw(8,position,"%d",ntn[nationid].score);
  65.                 mvprintw(9,position,"%d",ntn[nationid].tgold);
  66.                 mvprintw(10,position,"%d",ntn[nationid].tmil);
  67.                 mvprintw(11,position,"%d",ntn[nationid].tciv);
  68.                 mvprintw(12,position,"%d",ntn[nationid].tsctrs);
  69.                 mvprintw(13,position,"%d",ntn[nationid].tships);
  70.                 count++;
  71.             }
  72.             nationid++;
  73.         }
  74.         standout();
  75.         mvaddstr(18,(COLS/2)-12,"HIT ANY KEY TO CONTINUE");
  76.         mvaddstr(19,(COLS/2)-9,"HIT SPACE IF DONE");
  77.         standend();
  78.         refresh();
  79.         if (getch()==' ') done=1;
  80.     }
  81. }
  82.  
  83. diploscrn()
  84. {
  85.     int i;
  86.     char k;
  87.     short nation, offset, count, olddip, oldnat, temp;
  88.     FILE *fp, *fopen();
  89.     short isgod=0;
  90.     if(country==0) {
  91.         isgod=1;
  92.         clear();
  93.         mvaddstr(0,0,"WHAT NATION NUMBER:");
  94.         refresh();
  95.         echo();
  96.         scanw("%hd",&country);
  97.         noecho();
  98.     }
  99.     while(1){
  100.         count=1;
  101.         offset=0;
  102.         clear();
  103.         standout();
  104.         mvaddstr(0,(COLS/2)-10,"NATION DIPLOMACY SUMMARY");
  105.         standend();
  106.         mvaddstr(2,0,"                BY YOU,        TO YOU");
  107.         for(i=1;i<MAXNTN+4;i++) if((ntn[i].active>0)&&(i!=country)) {
  108.             if(count%14==0) {
  109.                 offset+=40;
  110.                 mvaddstr(2,40,"                BY YOU,        TO YOU");
  111.                 count++;
  112.             }
  113.             mvprintw(count%14+2,offset, "%d. %s",i,ntn[i].name);
  114.             mvprintw(count%14+2,offset+14, "=> %s",*(diploname+ntn[country].dstatus[i]));
  115.             mvprintw(count%14+2,offset+28, "=> %s",*(diploname+ntn[i].dstatus[country]));
  116.             count++;
  117.         }
  118.         standout();
  119.         mvaddstr(17,0,"HIT RETURN KEY TO CHANGE STATUS");
  120.         mvprintw(18,0,"HIT 'B' KEY TO BRIBE WARING NPC NATION (%d GOLD/level)",BRIBE);
  121.         mvaddstr(19,0,"ANY OTHER KEY TO CONTINUE:");
  122.         standend();
  123.         refresh();
  124.         k=getch();
  125.         if((k!='\n')&&(k!='B')) {
  126.             if(isgod==1) country=0;
  127.             return;
  128.         }
  129.         if(k=='B'){
  130.             if(ntn[country].tgold<=BRIBE){
  131.                 mvaddstr(21,0,"NOT ENOUGH GOLD");
  132.                 refresh();
  133.                 getch();
  134.                 return;
  135.             }
  136.             mvaddstr(20,0,"BRIBES WORK 50% (only the update will show)");
  137.             mvaddstr(21,0,"WHAT NATION NUMBER:");
  138.             refresh();
  139.             echo();
  140.             scanw("%hd",&nation);
  141.             noecho();
  142.             if(ntn[country].active>=2){
  143.                 mvaddstr(22,0,"NOT NON PLAYER COUNTRY");
  144.                 refresh();
  145.                 getch();
  146.                 return;
  147.             }
  148.             if((nation<=0)||(nation>MAXNTN)){
  149.                 if(isgod==1) country=0;
  150.                 return;
  151.             }
  152.             if((isgod!=1)&&((ntn[nation].dstatus[country]==ALLIED)||(ntn[nation].dstatus[country]==JIHAD)||(ntn[nation].dstatus[country]==CONFEDERACY))){
  153.                 mvaddstr(22,0,"CANT CHANGE THEIR STATUS");
  154.                 refresh();
  155.                 getch();
  156.                 return;
  157.             }
  158.             ntn[nation].dstatus[country]--;
  159.             ntn[country].tgold-=BRIBE;
  160.             ntn[nation].tgold+=BRIBE;
  161.             EADJDIP;
  162.             oldnat=country;
  163.             country=nation;
  164.             nation=oldnat;
  165.             fprintf(fexe,"NGOLD\t%hd \t%d \t%d \t0 \t0 \t%s\n",XNAGOLD ,country,ntn[country].tgold,"null");
  166.             EADJDIP;
  167.             country=oldnat;
  168.             return;
  169.         }
  170.         mvaddstr(21,0,"WHAT NATION NUMBER:");
  171.         refresh();
  172.         echo();
  173.         scanw("%hd",&nation);
  174.         if((nation<=0)||(nation>MAXNTN)){
  175.             noecho();
  176.             if(isgod==1) country=0;
  177.             return;
  178.         }
  179.         noecho();
  180.         if((isgod==0)&&(((ntn[country].dstatus[nation]==CONFEDERACY)&&(ntn[nation].dstatus[country]<WAR))||(ntn[country].dstatus[nation]==JIHAD))) {
  181.             mvprintw(23,0,"SORRY, Can't change status on ntn %s -- hit return",ntn[nation].name);
  182.             refresh();
  183.             getch();
  184.             return;
  185.         }
  186.         else{
  187.             clear();
  188.             mvaddstr(0,0,"WHAT NEW STATUS");
  189.             mvaddstr(2,0,"1) CONFEDERACY (irrevocable)");
  190.             mvaddstr(3,0,"2) ALLIED");
  191.             mvaddstr(4,0,"3) FRIENDLY");
  192.             mvaddstr(5,0,"4) NEUTRAL");
  193.             mvaddstr(6,0,"5) HOSTILE");
  194.             mvaddstr(7,0,"6) WAR");
  195.             mvaddstr(8,0,"7) JIHAD (irrevocable):");
  196.             mvaddstr(12,0,"INPUT:");
  197.             refresh();
  198.             scanw("%hd",&temp);
  199.             if((temp<1)||(temp>7)){
  200.                 mvprintw(23,0,"SORRY, Invalid inputs -- hit return");
  201.                 refresh();
  202.                 getch();
  203.                 return;
  204.             }
  205.             ntn[country].dstatus[nation]=temp;
  206.             EADJDIP;
  207.  
  208.             /*prevent ron from being sneaky*/
  209.             if((temp>HOSTILE)&&(ntn[nation].active>2)&&(ntn[nation].dstatus[country]<WAR)) {
  210.                 olddip=ntn[nation].dstatus[country];
  211.                 oldnat=country;
  212.                 country=nation;
  213.                 nation=oldnat;
  214.                 ntn[country].dstatus[nation]=WAR;
  215.                 EADJDIP;
  216.                 ntn[country].dstatus[nation]=olddip;
  217.                 oldnat=country;
  218.                 country=nation;
  219.                 nation=oldnat;
  220.             }
  221.             else if((temp>HOSTILE)&&(ntn[nation].active==1)&&(ntn[nation].dstatus[country]<WAR)) {
  222.                 if ((fp=fopen(MSGFILE,"a+"))==NULL) {
  223.                     mvprintw(4,0,"error opening %s",MSGFILE);
  224.                     refresh();
  225.                     getch();
  226.                     return;
  227.                 }
  228.                 fprintf(fp,"%s %s Declared war on you\n",ntn[nation].name,ntn[country].name);
  229.                 fputs("END\n",fp);
  230.                 fclose(fp);
  231.             }
  232.         }
  233.     }
  234. }
  235.  
  236. change()
  237. {
  238.     char string[10];
  239.     int i;
  240.     short armynum;
  241.     char passwd[8];
  242.     short isgod=0;
  243.  
  244.     if(country==0) {
  245.         isgod=1;
  246.         clear();
  247.         mvaddstr(0,0,"SUPER USER; FOR WHAT NATION NUMBER:");
  248.         refresh();
  249.         echo();
  250.         scanw("%hd",&country);
  251.         noecho();
  252.     }
  253.     clear();
  254.     mvaddstr(0,(COLS/2)-10,"NATION STATS SUMMARY");
  255.     mvprintw(5,0,"1. nation name is %s   ",ntn[country].name);
  256.     mvprintw(6,0,"2. password is XXXXXXXX");
  257.     mvprintw(12,0,"capital loc: x is %d",ntn[country].capx);
  258.     mvprintw(13,0,"             y is %d",ntn[country].capy);
  259.     mvprintw(14,0,"leader is %s",ntn[country].leader);
  260.     mvprintw(15,0,"class is %s",*(Class+ntn[country].class));
  261.     mvprintw(16,0,"nations mark is...%c ",ntn[country].mark);
  262.     for(i=1;i<8;i++) if(ntn[country].race==*(races+i)[0])
  263.         mvprintw(17,0, "nation race is....%s  ",*(races+i));
  264.     mvprintw(18,0,"score currently...%d",ntn[country].score);
  265.  
  266.     mvprintw(4,(COLS/2), "attack bonus...........+%2d",ntn[country].aplus);
  267.     mvprintw(5,(COLS/2), "defense bonus..........+%2d",ntn[country].dplus);
  268.     mvprintw(6,(COLS/2), "maximum move rate.......%2d",ntn[country].maxmove);
  269.     mvprintw(7,(COLS/2), "reproduction rate......%2d%%",ntn[country].repro);
  270.     mvprintw(9,(COLS/2), "gold talons........$%5ld",ntn[country].tgold);
  271.     mvprintw(10,(COLS/2),"jewels ............$%5ld",ntn[country].jewels);
  272.     mvprintw(11,(COLS/2),"iron & minerals......%5ld",ntn[country].tiron);
  273.     if(ntn[country].tfood<2*ntn[country].tciv) standout();
  274.     mvprintw(12,(COLS/2),"food in granary......%5ld",ntn[country].tfood);
  275.     standend();
  276.  
  277.     mvprintw(13,(COLS/2),"total soldiers.......%5ld",ntn[country].tmil);
  278.     mvprintw(14,(COLS/2),"total civilians......%5ld",ntn[country].tciv);
  279.     mvprintw(15,(COLS/2),"total ships..........%5d",ntn[country].tships);
  280.     mvprintw(16,(COLS/2),"total sectors........%5d",ntn[country].tsctrs);
  281.  
  282.     standout();
  283.     mvaddstr(19,(COLS/2)-9, "HIT ANY KEY TO CONTINUE");
  284.     mvaddstr(20,(COLS/2)-15,"HIT 1 or 2 TO CHANGE NAME or PASSWD");
  285.     mvaddstr(21,(COLS/2)-15,"HIT 3 TO CHANGE ADD TO COMBAT BONUS");
  286.     if(isgod==1) mvaddstr(21,(COLS/2)-9,"HIT 4 TO DESTROY NATION");
  287.  
  288.     standend();
  289.     refresh();
  290.     switch(getch()){
  291.     case '1': /*get name*/
  292.         clear();
  293.         echo();
  294.         mvaddstr(0,0,"what name would you like:");
  295.         clrtoeol();
  296.         refresh();
  297.         scanw("%s",string);
  298.         if((strlen(string)<=1)||(strlen(string)>=10)){
  299.             beep();
  300.             mvaddstr(2,0,"invalid name--hit return");
  301.             noecho();
  302.             refresh();
  303.             getch();
  304.             if(isgod==1) country=0;
  305.             return;
  306.         }
  307.         /*check if already used*/
  308.         else for(i=1;i<(country-1);i++){
  309.             if((strcmp(ntn[i].name,string)==0)&&(i!=country)) {
  310.                 mvaddstr(2,0,"name already used--hit return");
  311.                 beep();
  312.                 noecho();
  313.                 refresh();
  314.                 getch();
  315.                 if(isgod==1) country=0;
  316.                 return;
  317.             }
  318.         }
  319.         strcpy(ntn[country].name,string);
  320.         noecho();
  321.         ECHGNAME;
  322.         break;
  323.     case '2': /*change password */
  324.         clear();
  325.         if(isgod!=1){
  326.             mvaddstr(0,0,"what is your current password:");
  327.             refresh();
  328.             scanw("%s",string);
  329.             strcpy(passwd,crypt(string,SALT));
  330.             if((strncmp(passwd,ntn[0].passwd,PASSLTH)!=0)&&(strncmp(passwd,ntn[country].passwd,PASSLTH)!=0)){
  331.                 beep();
  332.                 mvaddstr(2,0,"invalid password--hit return");
  333.                 refresh();
  334.                 getch();
  335.                 if(isgod==1) country=0;
  336.                 return;
  337.             }
  338.         }
  339.         mvaddstr(2,0,"what is your new password:");
  340.         refresh();
  341.         scanw("%s",string);
  342.         if((strlen(string)>8)||(strlen(string)<2)) {
  343.             beep();
  344.             mvaddstr(2,0,"invalid new password--hit return");
  345.             refresh();
  346.             getch();
  347.             if(isgod==1) country=0;
  348.             return;
  349.         }
  350.         mvaddstr(4,0,"reenter your new password:");
  351.         refresh();
  352.         scanw("%s",passwd);
  353.         if(strcmp(passwd,string)!=0) {
  354.             if(isgod==1) country=0;
  355.             return;
  356.         }
  357.         ECHGPAS;
  358.         strncpy(ntn[country].passwd,crypt(string,SALT),PASSLTH);
  359.         break;
  360.     case '3':
  361.         for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD>0) i+=ASOLD;
  362.         if(i<1500) i=1500;
  363.         mvprintw(0,0,"DO YOU WISH SPEND %d IRON ON ATTACK (enter y or n):",IRONORE*i);
  364.         refresh();
  365.         if(getch()=='y'){
  366.             if(ntn[country].tiron>IRONORE*i){
  367.                 ntn[country].aplus+=1;
  368.                 I_APLUS;
  369.                 ntn[country].tiron-=IRONORE*i;
  370.             }
  371.         }
  372.         mvprintw(0,0,"DO YOU WISH SPEND %d IRON ON DEFENSE (enter y or n):",IRONORE*i);
  373.         refresh();
  374.         if(getch()=='y'){
  375.             if(ntn[country].tiron>IRONORE*i){
  376.                 ntn[country].dplus+=1;
  377.                 I_DPLUS;
  378.                 ntn[country].tiron-=IRONORE*i;
  379.             }
  380.         }
  381.         break;
  382.     case '4':
  383.         if(isgod==1){
  384.             clear();
  385.             mvaddstr(0,0,"DO YOU WANT TO DESTROY THIS NATION (y or n)");
  386.             refresh();
  387.             if(getch()=='y') destroy();
  388.         }
  389.         break;
  390.     default:
  391.         if(isgod==1) country=0;
  392.         return;
  393.     }
  394.     if(isgod==1) country=0;
  395. }
  396.  
  397. help()
  398. {
  399.     int lineno;
  400.     FILE *fp, *fopen();
  401.     int done=0;
  402.     char line[80];
  403.  
  404.     /*open .help file*/
  405.     if ((fp=fopen(HELPFILE,"r"))==NULL) {
  406.         mvaddstr(0,0,"\nerror on read \n");
  407.         refresh();
  408.         getch();
  409.         return;
  410.     }
  411.  
  412.     while(done==0){
  413.         /*read in screen (until DONE statement)*/
  414.         fgets(line,80,fp);
  415.         if(strncmp(line,"DONE",4)==0) done=1;
  416.         else {
  417.             clear();
  418.             lineno=0;
  419.             while(strncmp(line,"END",3)!=0) {
  420.                 mvaddstr(lineno,0,line);
  421.                 lineno++;
  422.                 if(lineno>LINES-3) strcpy(line,"END");
  423.                 else fgets(line,80,fp);
  424.             }
  425.             standout();
  426.             mvaddstr(LINES-2,(COLS/2)-14,"HIT SPACE TO CONTINUE HELP SCREENS");
  427.             mvaddstr(LINES-1,(COLS/2)-12,"TO END HELP HIT ANY OTHER KEY");
  428.             standend();
  429.             refresh();
  430.             if(getch()!=' ') done=1;
  431.         }
  432.     }
  433.     fclose(fp);
  434. }
  435.  
  436. newspaper()
  437. {
  438.     int lineno;
  439.     FILE *fp, *fopen();
  440.     int newpage,done;
  441.     short pagenum=1;
  442.     char line[80];
  443.     char title[80];
  444.  
  445.     clear();
  446.     if ((fp=fopen(NEWSFILE,"r"))==NULL) {
  447.         mvaddstr(0,0,"error on read ");
  448.         refresh();
  449.         getch();
  450.         return;
  451.     }
  452.  
  453.     /*open and read one page */
  454.     done=0;
  455.     newpage=0;
  456.     if(fgets(title,80,fp)==NULL) done=1;
  457.     while(done==0){
  458.         if(newpage==0){
  459.             clear();
  460.             lineno=5;
  461.             newpage=1;
  462.             standout();
  463.             mvprintw(0,20,"CONQUEST NEWS REPORT   page %d",pagenum);
  464.             mvaddstr(1,23,"ALL THE NEWS THAT FITS");
  465.             mvprintw(3,20,"%s",title+2);
  466.             standend();
  467.         }
  468.  
  469.         if(fgets(line,80,fp)==NULL) done=1;
  470.         else {
  471.             if(line[1]!='.') {
  472.                 strcpy(title,line);
  473.                 newpage=0;
  474.                 pagenum++;
  475.             }
  476.             else {
  477.                 mvaddstr(lineno++,0,line+2);
  478.                 if(todigit(line[0])!=pagenum) {
  479.                     newpage=0;
  480.                     pagenum=todigit(line[0]);
  481.                 }
  482.                 else if(lineno>LINES-3) newpage=0;
  483.             }
  484.         }
  485.  
  486.         if(newpage==0||done==1){
  487.             standout();
  488.             mvaddstr(LINES-2,(COLS/2)-13,"HIT ANY KEY TO CONTINUE");
  489.             mvaddstr(LINES-1,(COLS/2)-12,"TO END NEWS HIT SPACE");
  490.             standend();
  491.             refresh();
  492.             if(getch()==' ') done=1;
  493.         }
  494.     }
  495.     fclose(fp);
  496. }
  497.