home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume6 / conquer4 / part13 / forms.c < prev    next >
C/C++ Source or Header  |  1989-07-06  |  26KB  |  906 lines

  1. /*conquer : Copyright (c) 1988 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. /*    screen subroutines    */
  14.  
  15. #include <ctype.h>
  16. #include "header.h"
  17. #include "data.h"
  18.  
  19. extern FILE    *fexe, *fnews;
  20. extern short    country,redraw;
  21. extern long    startgold;
  22.  
  23. static char helplist[MAXHELP][20]={"Commands", "General Info",
  24.     "Military","Magic","Designations","Other"};
  25.  
  26. #define RPT_LINES 14
  27. #define RPT_COLS 13
  28. #define BUF_LINES 10
  29. #define BUF_COLS 15
  30. #define MAXINROW ((COLS-BUF_COLS)/RPT_COLS)
  31. #define MAXINSCR (((LINES-BUF_LINES)/RPT_LINES)*MAXINROW)
  32. void
  33. showscore()
  34. {
  35.     int i;
  36.     int done=FALSE;
  37.     int xpos,ypos;
  38.     int count,count2;   /*number of time through the loop on this screen*/
  39.     int nationid;          /*current nation id */
  40.  
  41.     count2=1;
  42.     while(done==FALSE) {
  43.         clear();
  44.         standout();
  45.         mvaddstr(0,(COLS/2)-10,"NATION SCORE SCREEN");
  46.         standend();
  47.  
  48.         nationid=count2;
  49.         xpos=BUF_COLS;
  50.         ypos=3;
  51.         count=0;
  52.         while((nationid<NTOTAL)&&(count<MAXINSCR)){
  53.             if((nationid<NTOTAL)
  54.             &&(isntn(ntn[nationid].active))) {
  55.                 if (count%MAXINROW==0) {
  56.                     /* display header information */
  57.                     mvaddstr(ypos,0,"nationid is:");
  58.                     mvaddstr(ypos+1,0,"name is:");
  59.                     mvaddstr(ypos+2,0,"leader:");
  60.                     mvaddstr(ypos+3,0,"race:");
  61.                     mvaddstr(ypos+4,0,"class:");
  62.                     mvaddstr(ypos+5,0,"alignment:");
  63.                     mvaddstr(ypos+6,0,"score:");
  64.                     mvaddstr(ypos+7,0,"talons:");
  65.                     mvaddstr(ypos+8,0,"military:");
  66.                     mvaddstr(ypos+9,0,"civilians:");
  67.                     mvaddstr(ypos+10,0,"sectors:");
  68.                     mvaddstr(ypos+11,0,"npc nation:");
  69.                 }
  70.  
  71.                 /* display nation information */
  72.                 mvprintw(ypos,xpos,"%d",nationid);
  73.                 standout();
  74.                 mvprintw(ypos+1,xpos,"%s",ntn[nationid].name);
  75.                 standend();
  76.                 mvprintw(ypos+2,xpos,"%s",ntn[nationid].leader);
  77.                 for(i=1;i<8;i++)
  78.                     if(ntn[nationid].race==*(races+i)[0])
  79.                         mvprintw(ypos+3,xpos,"%s",*(races+i));
  80.                 mvprintw(ypos+4,xpos,"%s",*(Class+ntn[nationid].class));
  81.                 mvprintw(ypos+5,xpos,"%s",allignment[npctype(ntn[nationid].active)]);
  82.                 mvprintw(ypos+6,xpos,"%ld",ntn[nationid].score);
  83.                 mvprintw(ypos+7,xpos,"%ld",ntn[nationid].tgold);
  84.                 mvprintw(ypos+8,xpos,"%ld",ntn[nationid].tmil);
  85.                 mvprintw(ypos+9,xpos,"%ld",ntn[nationid].tciv);
  86.                 mvprintw(ypos+10,xpos,"%d",ntn[nationid].tsctrs);
  87.                 if(isnpc(ntn[nationid].active))
  88.                     mvprintw(ypos+11,xpos,"Yes");
  89.                 else mvprintw(ypos+11,xpos,"No");
  90.                 count++;
  91.                 if(count<MAXINSCR && count%MAXINROW==0) {
  92.                     ypos+=RPT_LINES;
  93.                     xpos=BUF_COLS;
  94.                 } else {
  95.                     xpos+=RPT_COLS;
  96.                 }
  97.             }
  98.             nationid++;
  99.         }
  100.         standout();
  101.         mvaddstr(LINES-6,(COLS/2)-12,"HIT ANY KEY TO CONTINUE");
  102.         mvaddstr(LINES-5,(COLS/2)-9,"HIT SPACE IF DONE");
  103.         standend();
  104.         refresh();
  105.         if (getch()==' ') done=TRUE;
  106.         else {
  107.             /* go to start of next page in list */
  108.             while(nationid<NTOTAL && !isntn(ntn[nationid].active))
  109.                 nationid++;
  110.             if(nationid==NTOTAL) count2=1;
  111.             else count2=nationid;
  112.         }
  113.     }
  114. }
  115.  
  116. #define    MAXINCOL    (LINES-10)
  117. #define    MAXONSCR    (MAXINCOL*(COLS/40))
  118. void
  119. diploscrn()
  120. {
  121.     int i,j;
  122.     char k,name[20];
  123.     short nation, offset, count, count2, temp;
  124.     short isgod=FALSE;
  125.     long    bribecost;
  126.     if(country==0) {
  127.         isgod=TRUE;
  128.         if (get_god()) return;
  129.     }
  130.     count2=1;
  131.     while(1){
  132.         count=1;
  133.         offset=0;
  134.         clear();
  135.         standout();
  136.         mvaddstr(0,(COLS/2)-12,"NATION DIPLOMACY SUMMARY");
  137.         standend();
  138.         mvaddstr(2,0,"                BY YOU,        TO YOU");
  139.         for(i=count2;i<NTOTAL && count<MAXONSCR;i++)
  140.         if((isntnorp(ntn[i].active))&&(i!=country)) {
  141.             if(count%MAXINCOL==0) {
  142.                 offset+=40;
  143.                 mvaddstr(2,offset,"                BY YOU,        TO YOU");
  144.                 count++;
  145.             }
  146.             mvprintw(count%MAXINCOL+2,offset, "%d. %s",i,ntn[i].name);
  147.             if((curntn->dstatus[i]==WAR)
  148.             ||(curntn->dstatus[i]==JIHAD)) standout();
  149.             mvprintw(count%MAXINCOL+2,offset+14, "=> %s",*(diploname+curntn->dstatus[i]));
  150.             standend();
  151.             if((ntn[i].dstatus[country]==WAR)
  152.             ||(ntn[i].dstatus[country]==JIHAD)) standout();
  153.             mvprintw(count%MAXINCOL+2,offset+28, "=> %s",*(diploname+ntn[i].dstatus[country]));
  154.             standend();
  155.             count++;
  156.         }
  157.  
  158.         /* display options */
  159.         standout();
  160.         mvaddstr(LINES-7,0,"HIT RETURN KEY TO CHANGE STATUS; HIT SPACE IF DONE");
  161.         mvprintw(LINES-6,0,"HIT 'B' KEY TO BRIBE NPC NATION (cost=$%ld per 1000 Mil.)",BRIBE);
  162.         mvaddstr(LINES-5,0,"ANY OTHER KEY TO CONTINUE:");
  163.         standend();
  164.         refresh();
  165.         k=getch();
  166.         if(k==' ') {
  167.             if(isgod==TRUE) reset_god();
  168.             return;
  169.         }
  170.         if((k!='B')&&(k!='\r')&&(k!='\n')) {
  171.             /* find start for next listing */
  172.             for(; i<NTOTAL && (!isntnorp(ntn[i].active)||i==country); i++) ;
  173.             if(i==NTOTAL) count2=1;
  174.             else count2=i;
  175.             continue;
  176.         }
  177.         if(k=='B'){
  178.             if(curntn->tgold<=BRIBE){
  179.                 mvaddstr(LINES-3,0,"NOT ENOUGH GOLD");
  180.                 refresh();
  181.                 getch();
  182.                 if(isgod==TRUE) reset_god();
  183.                 return;
  184.             }
  185.             mvaddstr(LINES-4,0,"BRIBES DONT ALWAYS WORK (only the update will show)");
  186.             mvaddstr(LINES-3,0,"WHAT NATION:");
  187.             refresh();
  188.             nation = get_country();
  189.  
  190.             /* may only change with NPCs */
  191.             if((nation<=0)
  192.             ||(nation>=NTOTAL)
  193.             ||(!isnpc(ntn[nation].active))){
  194.                 errormsg("NOT NON PLAYER COUNTRY");
  195.                 if(isgod==TRUE) reset_god();
  196.                 return;
  197.             }
  198.             if(ntn[country].dstatus[nation]==UNMET){
  199.                 errormsg("YOU HAVE NOT MET COUNTRY");
  200.                 if(isgod==TRUE) reset_god();
  201.                 return;
  202.             }
  203.             if((isgod!=TRUE)
  204.                 &&((ntn[nation].dstatus[country]==ALLIED)
  205.                 ||(ntn[nation].dstatus[country]==JIHAD)
  206.                 ||(ntn[nation].dstatus[country]==UNMET)
  207.                 ||(ntn[nation].dstatus[country]==TREATY))){
  208.                 errormsg("Sorry, you can't bribe them");
  209.                 return;
  210.             }
  211.  
  212.             if( isgod==TRUE ) {
  213.                 bribecost = 0;
  214.             } else if( ntn[nation].tmil > 1000 ) {
  215.                 bribecost = BRIBE * ntn[nation].tmil / 1000;
  216.             } else    bribecost = BRIBE;
  217.             mvprintw(LINES-3,0,"This will cost %ld gold talons. continue (y or n)",bribecost);
  218.             refresh();
  219.  
  220.             if( getch() != 'y' ) return;
  221.             if(curntn->tgold<=bribecost){
  222.                 errormsg("Sorry Not Enough Gold");
  223.                 if(isgod==TRUE) reset_god();
  224.                 return;
  225.             }
  226.             curntn->tgold-=bribecost;
  227.  
  228.             sprintf(name,"%s%d",exefile,nation);
  229.             if ((fm=fopen(name,"a+"))==NULL) {
  230.                 printf("error opening news file\n");
  231.                 exit(FAIL);
  232.             }
  233.             BRIBENATION;
  234.             mailclose();
  235.  
  236.             ntn[nation].dstatus[country]--;
  237.  
  238.             if(isgod==TRUE) reset_god();
  239.             return;
  240.         }
  241.         mvaddstr(LINES-3,0,"WHAT NATION:");
  242.         refresh();
  243.         nation = get_country();
  244.         /* can't change with nomads...*/
  245.         if((nation<=0)||(nation>NTOTAL)||(!isntnorp(ntn[nation].active))){
  246.             if(isgod==TRUE) reset_god();
  247.             return;
  248.         }
  249.         if((isgod==FALSE)
  250.             &&(curntn->tgold < BREAKJIHAD )
  251.             &&(((curntn->dstatus[nation]==TREATY)
  252.             &&(ntn[nation].dstatus[country]<WAR))
  253.             ||(curntn->dstatus[nation]==JIHAD))) {
  254.  
  255.             mvprintw(LINES-1,0,"Sorry, need %d talons to change status with ntn %s",BREAKJIHAD,ntn[nation].name);
  256.             clrtoeol();
  257.                 mvaddstr(LINES-1, 60, "PRESS ANY KEY");
  258.             refresh();
  259.             getch();
  260.             if(isgod==TRUE) reset_god();
  261.             return;
  262.         } else if (isgod==FALSE && curntn->dstatus[nation]==UNMET) {
  263.             errormsg("Sorry, you have not met that nation yet.");
  264.             if(isgod==TRUE) reset_god();
  265.             return;
  266.         } else {
  267.             clear();
  268.             mvaddstr(0,0,"WHAT NEW STATUS");
  269.             j=2;
  270.             mvprintw(j++,0,"1) TREATY (%d talons to break)",BREAKJIHAD);
  271.             mvaddstr(j++,0,"2) ALLIED");
  272.             mvaddstr(j++,0,"3) FRIENDLY");
  273.             mvaddstr(j++,0,"4) NEUTRAL");
  274.             mvaddstr(j++,0,"5) HOSTILE");
  275.             mvaddstr(j++,0,"6) WAR");
  276.             mvprintw(j++,0,"7) JIHAD (%d talons to break):",BREAKJIHAD);
  277.             j++;
  278.             for( i=1; i<=NTOTAL; i++ )
  279.                 if((isntnorp(ntn[i].active)) && (ntn[nation].dstatus[i]==TREATY))
  280.                 mvprintw(j++,10,"%s has treaty with %s",ntn[nation].name,ntn[i].name);
  281.  
  282.             j++;
  283.             mvaddstr(j++,0,"INPUT:");
  284.             refresh();
  285.             temp = get_number();
  286.             if((temp<=UNMET)||(temp>JIHAD)
  287.             ||((isgod==FALSE)&&(temp==UNMET))){
  288.                 mvprintw(23,0,"SORRY, Invalid inputs -- hit return");
  289.                 refresh();
  290.                 getch();
  291.                 if(isgod==TRUE) reset_god();
  292.                 return;
  293.             }
  294.  
  295.             if(((curntn->dstatus[nation]==TREATY)&&(temp!=TREATY))
  296.             ||(( curntn->dstatus[nation]==JIHAD)&&(temp!=JIHAD)))
  297.                     curntn->tgold -= BREAKJIHAD;
  298.  
  299.             curntn->dstatus[nation]=temp;
  300.             EADJDIP(country,nation);
  301.  
  302.             if((temp>HOSTILE)
  303.             &&(ispc(ntn[nation].active))
  304.             &&(ntn[nation].dstatus[country]<WAR)) {
  305.                 mailopen(nation);
  306.                 fprintf(fm,"Message to %s from CONQUER\n",ntn[nation].name);
  307.                 fprintf(fm,"    During the %s of Year %d,\n",PSEASON(TURN),YEAR(TURN));
  308.                 fprintf(fm,"      %s declared war on you\n",curntn->name);
  309.                 mailclose();
  310.             }
  311.  
  312.             /*prevent ron from being sneaky*/
  313.             if((temp>HOSTILE)
  314.             &&(isactive(ntn[nation].active))
  315.             &&(ntn[nation].dstatus[country]<WAR)) {
  316.                 ntn[nation].dstatus[country]=WAR;
  317.                 EADJDIP(nation,country);
  318.                 for( i=1; i<=NTOTAL; i++ )
  319.                 if(ntn[i].dstatus[nation]==TREATY){
  320.                     ntn[i].dstatus[country]=WAR;
  321.                     EADJDIP(i,country);
  322.                     mailopen(country);
  323.                     fprintf(fm,"Message to %s from %s\n",ntn[country].name,ntn[i].name);
  324.                     switch( rand()%4 ) {
  325.                     case 0: fprintf(fm,"You just attacked my friend %s - your loss!!!\n",ntn[nation].name);
  326.                         break;
  327.                     case 1: fprintf(fm,"Our imperial forces will assist %s!!!\n",ntn[nation].name);
  328.                         fprintf(fm,"in repulsing your toy armies!!!\n");
  329.                         break;
  330.                     case 2: fprintf(fm,"Sucker - your aggression against %s is your doom!!!\n",ntn[nation].name);
  331.                         break;
  332.                     case 3: fprintf(fm,"We deplore your aggression against %s and are taking\n",ntn[nation].name);
  333.                         fprintf(fm,"appropriate counter measures!!! DIE!!!\n");
  334.                         break;
  335.                     }
  336.                     mailclose();
  337.                 }
  338.             }
  339.         }
  340.     }
  341. }
  342.  
  343. int terror_adj=0;
  344. void
  345. change()
  346. {
  347.     float temp;
  348.     char string[10], command[80];
  349.     int i, intval;
  350.     long    cost,men;
  351.     short armynum;
  352.     char passwd[PASSLTH+1];
  353.     short isgod=FALSE;
  354.     FILE *fp;
  355. #ifdef OGOD
  356.     FILE *ftmp;
  357. #endif OGOD
  358.     char filename[80];
  359.  
  360.     if(country==0) {
  361.         isgod=TRUE;
  362.         if (get_god()) return;
  363.     }
  364.     fp=fopen("temp","w");
  365.     fprintf(fp,"LINE %d FILE %s\n",__LINE__,__FILE__);
  366.     clear();
  367.     standout();
  368.     mvaddstr(0,(COLS/2)-10,"NATION STATS SUMMARY");
  369.     mvprintw(3,0,"nation name is %s",curntn->name);
  370.     mvprintw(4,0,"allignment is %s",allignment[npctype(curntn->active)]);
  371.     if (isgod==TRUE)
  372.         mvprintw(5,0,"active is %d",curntn->active);
  373.     mvprintw(6,0,"tax_rate...... %2d%%",curntn->tax_rate);
  374.     mvprintw(7,0,"inflation..... %2d%%",curntn->inflation);
  375.     i=10*curntn->tax_rate-curntn->popularity-curntn->terror-3*curntn->charity;
  376.     if( i<0 ) i=0;
  377.     mvprintw(8,0,"peasant revolt %2d%%",(i*PREVOLT)/100);
  378.     i=5*curntn->tax_rate - curntn->prestige;
  379.     if( i<0 ) i=0;
  380.     mvprintw(9,0,"other revolt.. %2d%%",(i*PREVOLT)/100);
  381.     standend();
  382.     mvprintw(10,0,"capitol loc: x is %d",curntn->capx);
  383.     mvprintw(11,0,"             y is %d",curntn->capy);
  384.     mvprintw(12,0,"leader is %s",curntn->leader);
  385.     mvprintw(13,0,"class is %s",*(Class+curntn->class));
  386.     if(ispc( curntn->active ) )
  387.         addstr(" (PC)");
  388.     else if(isnpc( curntn->active ) )
  389.         addstr(" (NPC)");
  390.     else    addstr(" (MON)");
  391.     mvprintw(14,0,"nations mark is...%c ",curntn->mark);
  392.     fprintf(fp,"LINE %d FILE %s\n",__LINE__,__FILE__);
  393.     for(i=1;i<8;i++) if(curntn->race==*(races+i)[0]){
  394.         mvprintw(15,0, "nation race is....%s  ",*(races+i));
  395.         break;
  396.     }
  397.  
  398.     fprintf(fp,"LINE %d FILE %s\n",__LINE__,__FILE__);
  399.     mvprintw(3,COLS/2-12, "terror........ %3d",curntn->terror);
  400.     mvprintw(4,COLS/2-12, "popularity.... %3d",curntn->popularity);
  401.     mvprintw(5,COLS/2-12, "prestige...... %3d",curntn->prestige);
  402.     fprintf(fp,"LINE %d FILE %s\n",__LINE__,__FILE__);
  403.     fflush( fp );
  404.     mvprintw(6,COLS/2-12, "knowledge..... %3d",curntn->knowledge);
  405.     fprintf(fp,"LINE %d FILE %s\n",__LINE__,__FILE__);
  406.     fflush( fp );
  407.     temp = P_EATRATE;
  408.     mvprintw(7,COLS/2-12, "eatrate.......%3.2f",temp);
  409.     fprintf(fp,"LINE %d FILE %s\n",__LINE__,__FILE__);
  410.     fflush( fp );
  411.     mvprintw(8,COLS/2-12, "wealth........ %3d",curntn->wealth);
  412.     fprintf(fp,"LINE %d FILE %s\n",__LINE__,__FILE__);
  413.     fflush( fp );
  414.     mvprintw(9,COLS/2-12,"charity....... %2d%%",curntn->charity);
  415.     fprintf(fp,"LINE %d FILE %s\n",__LINE__,__FILE__);
  416.     fflush( fp );
  417.     mvprintw(10,COLS/2-12,"communication.%3.2f",(float) P_NTNCOM);
  418.     fprintf(fp,"LINE %d FILE %s\n",__LINE__,__FILE__);
  419.     mvprintw(11,COLS/2-12,"reputation.... %3d",curntn->reputation);
  420.     mvprintw(12,COLS/2-12,"spoilrate.....%3d%%",curntn->spoilrate);
  421.     mvprintw(13,COLS/2-12,"farm ability.. %3d",curntn->farm_ability);
  422.     mvprintw(14,COLS/2-12,"mine ability.. %3d",curntn->mine_ability);
  423.     mvprintw(15,COLS/2-12,"poverty rate.. %2d%%",curntn->poverty);
  424.     fprintf(fp,"LINE %d FILE %s\n",__LINE__,__FILE__);
  425.     mvprintw(16,COLS/2-12,"power......... %3d",curntn->power);
  426.     fprintf(fp,"LINE %d FILE %s\n",__LINE__,__FILE__);
  427.  
  428.     if (country!=0) {
  429.         mvprintw(16,0,"score currently...%ld",curntn->score);
  430.         mvprintw(3,COLS-30, "attack bonus.........%+4d%%",curntn->aplus);
  431.         mvprintw(4,COLS-30, "defense bonus........%+4d%%",curntn->dplus);
  432.         mvprintw(12,COLS-30,"total soldiers....%8ld",curntn->tmil);
  433.     } else {
  434.         mvprintw(16,0,"turn currently....%ld",TURN);
  435.         mvprintw(3,COLS-30, "mercs attack bonus....+%2d%%",MERCATT);
  436.         mvprintw(4,COLS-30, "mercs defense bonus...+%2d%%",MERCDEF);
  437.         mvprintw(12,COLS-30,"total mercs.......%8ld",MERCMEN);
  438.     }
  439.     fprintf(fp,"LINE %d FILE %s\n",__LINE__,__FILE__);
  440.  
  441.       mvprintw(5,COLS-30, "maximum move rate.......%2d",curntn->maxmove);
  442.       mvprintw(6,COLS-30, "reproduction rate......%2d%%",curntn->repro);
  443.       mvprintw(8,COLS-30, "gold talons......$%8ld",curntn->tgold);
  444.  
  445.     mvprintw(9,COLS-30,"jewels ..........$%8ld",curntn->jewels);
  446.     mvprintw(10,COLS-30,"metal & minerals..%8ld",curntn->metals);
  447.     fprintf(fp,"LINE %d FILE %s\n",__LINE__,__FILE__);
  448.     if(curntn->tfood<2*curntn->tciv) standout();
  449.     mvprintw(11,COLS-30,"food in granary...%8ld",curntn->tfood);
  450.     standend();
  451.  
  452.     mvprintw(13,COLS-30,"total civilians...%8ld",curntn->tciv);
  453.     mvprintw(14,COLS-30,"total ships..........%5d",curntn->tships);
  454.     mvprintw(15,COLS-30,"total sectors........%5d",curntn->tsctrs);
  455.     mvprintw(16,COLS-30,"spell points.........%5d",curntn->spellpts);
  456.  
  457.     standout();
  458.     mvaddstr(LINES-6,COLS/2-26,"HIT 'B' FOR BUDGET SCREEN, 'P' FOR PRODUCTION SCREEN");
  459.     mvaddstr(LINES-5,COLS/2-25,"1) NAME 2) PASSWD 3) TAX RATE 4) CHARITY 5) TERROR");
  460.     if(magic(country,VAMPIRE)!=1)
  461.         mvaddstr(LINES-4,COLS/2-21,"6) ADD TO COMBAT BONUS");
  462.     else    mvaddstr(LINES-4,COLS/2-22,"CANT ADD TO COMBAT BONUS");
  463.     addstr(" 7) TOGGLE PC <-> NPC");
  464.  
  465. #ifdef OGOD
  466.      if(isgod==TRUE) mvaddstr(LINES-3,COLS/2-24,"HIT 8 TO DESTROY NATION OR 9 TO CHANGE COMMODITY");
  467. #else OGOD
  468.       if(isgod==TRUE) mvaddstr(LINES-3,COLS/2-11,"HIT 8 TO DESTROY NATION");
  469. #endif OGOD
  470.     else mvaddstr(LINES-3,COLS/2-14,"HIT ANY OTHER KEY TO CONTINUE");
  471.     standend();
  472.     refresh();
  473.     switch(getch()){
  474.     case '1': /*get name*/
  475.         clear();
  476.         mvaddstr(0,0,"what name would you like:");
  477.         clrtoeol();
  478.         refresh();
  479.         get_nname(string);
  480.         if((strlen(string)<=1)||(strlen(string)>NAMELTH)){
  481.             errormsg("invalid name");
  482.             if(isgod==TRUE) reset_god();
  483.             return;
  484.         }
  485.         /*check if already used*/
  486.         else for(i=1;i<(country-1);i++){
  487.             if((strcmp(ntn[i].name,string)==0)&&(i!=country)) {
  488.                 errormsg("name already used");
  489.                 if(isgod==TRUE) reset_god();
  490.                 fclose(fp); return;
  491.             }
  492.         }
  493.         errormsg("new name can be used following next update");
  494.         strcpy(curntn->name,string);
  495.         ECHGNAME;
  496.         break;
  497.     case '2': /*change password */
  498.         clear();
  499.         if(isgod!=TRUE){
  500.             mvaddstr(0,0,"what is your current password:");
  501.             refresh();
  502.             gets(command);
  503.             strncpy(passwd,crypt(command,SALT),PASSLTH);
  504.             if((strncmp(passwd,ntn[0].passwd,PASSLTH)!=0)
  505.                 &&(strncmp(passwd,curntn->passwd,PASSLTH)!=0)){
  506.                 errormsg("invalid password");
  507.                 fclose(fp); return;
  508.             }
  509.         }
  510.         mvaddstr(2,0,"what is your new password:");
  511.         refresh();
  512.         gets(command);
  513.         if((strlen(command)>PASSLTH)||(strlen(command)<2)) {
  514.             errormsg("invalid new password");
  515.             if(isgod==TRUE) reset_god();
  516.             fclose(fp); return;
  517.         }
  518.         strncpy(passwd,command,PASSLTH);
  519.         mvaddstr(4,0,"reenter your new password:");
  520.         refresh();
  521.         gets(command);
  522.         if(strncmp(passwd,command,PASSLTH)!=0) {
  523.             if(isgod==TRUE) reset_god();
  524.             fclose(fp); return;
  525.         }
  526.         errormsg("new password can be used following next update");
  527.         strncpy(curntn->passwd,crypt(command,SALT),PASSLTH);
  528.         ECHGPAS;
  529.         break;
  530.     case '3': /* change tax rate */
  531.         standout();
  532.         mvaddstr(LINES-1,0,"WHAT TAX RATE DO YOU WISH:");
  533.         standend();
  534.         refresh();
  535.         intval = get_number();
  536.         if( intval < 0 )
  537.             errormsg("ERROR - negative tax rate");
  538.         else if( intval > 20 )
  539.             errormsg("NO WAY! the peasants will revolt!!!");
  540.         else if( intval > 10 && (curntn->tsctrs<20 || curntn->score<20) )
  541.             errormsg("Sorry, you may not go above 10% yet");
  542.         else {
  543.             curntn->tax_rate = (unsigned char) intval;
  544.             NADJNTN;
  545.         }
  546.         break;
  547.     case '4':    /* charity */
  548.         standout();
  549.         mvaddstr(LINES-1,0,"GIVE WHAT PERCENT OF YOUR INCOME TO THE POOR:");
  550.         standend();
  551.         refresh();
  552.         intval = get_number();
  553.         if(( intval < 0 ) ||( intval > 100 ))
  554.             errormsg("ERROR - invalid charity rate");
  555.         /* this will protect from both underflow and overflow */
  556.         else if((int)curntn->popularity + 2*(intval - (int)curntn->charity)>100)
  557.             errormsg("ERROR - you may not increase charity that much");
  558.         else if((int)curntn->popularity + 2*(intval - (int)curntn->charity)<0)
  559.             errormsg("ERROR - you may not decrease charity that much");
  560.         else {
  561.             curntn->popularity += (unsigned char) 2*(intval - (int) curntn->charity);
  562.             curntn->charity = intval;
  563.             NADJNTN;
  564.         }
  565.         break;
  566.     case '5':    /* terror */
  567.         mvaddstr(LINES-2,0,"YOU CAN TERRORIZE YOUR PEOPLE AN ADDITONAL 1-5%:");
  568.         standout();
  569.         mvaddstr(LINES-1,0,"HOW MUCH MORE TO TERRORIZE THEM: ");
  570.         standend();
  571.         refresh();
  572.         intval = get_number();
  573.         if( intval < 0 )
  574.             errormsg("ERROR - negative input");
  575.         else if( intval+curntn->terror > 100 )
  576.             errormsg("Cant go over 100 terror!!!");
  577.         else if((intval > curntn->popularity )
  578.         || (intval > curntn->reputation ))
  579.             errormsg("Sorry - this would cause underflow");
  580.         else if(intval>5) {
  581.             errormsg("That is over the allowed 5%");
  582.         } else if(terror_adj>0) {
  583.             errormsg("Terror may only be adjusted once per turn");
  584.         } else if(intval>0) {
  585.             terror_adj++;
  586.             curntn->terror += (unsigned char) intval;
  587.             curntn->popularity -= (unsigned char) intval;
  588.             curntn->reputation -= (unsigned char) (intval+1)/2;
  589.             NADJNTN2;
  590.         }
  591.         break;
  592.     case '6':    /* combat bonus */
  593.         if(magic(country,VAMPIRE)==1) {
  594.             errormsg("VAMPIRES CAN'T ADD TO COMBAT BONUS");
  595.             break;
  596.         }
  597.         if(magic(country,WARLORD)==1)      intval=30;
  598.         else if(magic(country,CAPTAIN)==1) intval=20;
  599.         else if(magic(country,WARRIOR)==1) intval=10;
  600.         else intval=0;
  601.         men=0;
  602.         for(armynum=0;armynum<MAXARM;armynum++)
  603.             if((P_ASOLD>0)&&(P_ATYPE<MINLEADER)) men+=P_ASOLD;
  604.         men = max( men, 1500);
  605.         armynum = max( curntn->aplus-intval, 10 );
  606.         cost = METALORE*men*armynum*armynum/100;
  607.         if( curntn->race == ORC) cost*=3;
  608.         mvprintw(LINES-1,0,"Do You Wish Spend %ld Metal On Attack (enter y or n):",cost);
  609.         refresh();
  610.         if(getch()=='y'){
  611.             if(curntn->metals> cost){
  612.                 curntn->aplus+=1;
  613.                 I_APLUS;
  614.                 curntn->metals-=cost;
  615.             } else {
  616.                 errormsg("SORRY");
  617.             }
  618.         }
  619.         armynum = max( curntn->dplus-intval, 10 ) / 10;
  620.         cost=METALORE*men*armynum*armynum;
  621.         if( curntn->race == ORC) cost*=3;
  622.         mvprintw(LINES-1,0,"Do You Wish Spend %ld Metal On Defense (enter y or n):",cost);
  623.         refresh();
  624.         if(getch()=='y'){
  625.             if(curntn->metals>cost){
  626.                 curntn->dplus+=1;
  627.                 I_DPLUS;
  628.                 curntn->metals-=cost;
  629.             } else {
  630.                 errormsg("SORRY");
  631.             }
  632.         }
  633.         break;
  634.     case '7':
  635.         if( startgold != curntn->tgold ) {
  636.             errormsg("Sorry: you have already made some moves this turn!");
  637.             break;
  638.         } else if(ispc(curntn->active)) {
  639.             errormsg("Note: you get no mail while playing as an NPC!");
  640.             curntn->active *= 4;
  641.         } else if(isnpc(curntn->active))
  642.             curntn->active /= 4;
  643.         NADJNTN;
  644.         break;
  645.     case '8':
  646.         if(isgod==TRUE){
  647.             clear();
  648.             mvaddstr(LINES-1,0,"DO YOU WANT TO DESTROY THIS NATION (y or n)");
  649.             refresh();
  650.  
  651.             if(getch()=='y') {
  652.                 /* save to last turns news file */
  653.                 sprintf(filename,"%s%d",newsfile,TURN-1);
  654.                 if ((fnews=fopen(filename,"a+"))==NULL) {
  655.                     printf("error opening news file\n");
  656.                     exit(FAIL);
  657.                 }
  658.                 destroy(country);
  659.                 fclose(fnews);
  660.                 sprintf(command,"%s/%s",DEFAULTDIR, sortname);
  661.                 sprintf(command,"%s %s %s", command, filename, filename);
  662.                 system(command);
  663.             }
  664.         }
  665.         break;
  666. #ifdef OGOD
  667.     case '9':
  668.         if (isgod==TRUE) {
  669.             /* open the target country's files */
  670.             sprintf(filename,"%s%d",exefile,country);
  671.             if ((ftmp=fopen(filename,"a"))==NULL) {
  672.                 beep();
  673.                 errormsg("error opening country's file");
  674.                 reset_god();
  675.                 fclose(fp); return;
  676.             }
  677.             /* adjust commodities */
  678.             mvaddstr(LINES-2,0,"CHANGE: 1) Gold 2) Jewels 3) Iron 4) Food ?");
  679.             clrtoeol();
  680.             refresh();
  681.             switch(getch()) {
  682.             case '1':
  683.                 mvaddstr(LINES-1,0,"WHAT IS NEW VALUE FOR TREASURY? ");
  684.                 refresh();
  685.                 curntn->tgold = (long) get_number();
  686.                 fprintf(ftmp,"L_NGOLD\t%d \t%d \t%ld \t0 \t0 \t%s\n", XNAGOLD ,country,curntn->tgold,"null");
  687.                 break;
  688.             case '2':
  689.                 mvaddstr(LINES-1,0,"WHAT IS NEW AMOUNT OF JEWELS? ");
  690.                 refresh();
  691.                 curntn->jewels = (long) get_number();
  692.                 fprintf(ftmp,"L_NJWLS\t%d \t%d \t%ld \t0 \t0 \t%s\n", XNARGOLD ,country,curntn->jewels,"null");
  693.                 break;
  694.             case '3':
  695.                 mvaddstr(LINES-1,0,"WHAT IS NEW AMOUNT OF METAL? ");
  696.                 refresh();
  697.                 curntn->metals = (long) get_number();
  698.                 fprintf(ftmp,"L_NMETAL\t%d \t%d \t%ld \t0 \t0 \t%s\n", XNAMETAL ,country,curntn->metals,"null");
  699.                 break;
  700.             case '4':
  701.                 mvaddstr(LINES-1,0,"WHAT IS NEW AMOUNT OF FOOD? ");
  702.                 refresh();
  703.                 curntn->tfood = (long) get_number();
  704.                 break;
  705.             default:
  706.                 break;
  707.             }
  708.             fclose(ftmp);
  709.         }
  710.         break;
  711. #endif OGOD
  712.     case 'p':
  713.     case 'P': produce(); fclose(fp); return;
  714.     case 'b':
  715.     case 'B': budget(); fclose(fp); return;
  716.     default:
  717.         if(isgod==TRUE) reset_god();
  718.         fclose(fp);
  719.         return;
  720.     }
  721.     if(isgod==TRUE) reset_god();
  722.     fclose(fp);
  723.     change();
  724. }
  725.  
  726. void
  727. help()
  728. {
  729.     int lineno;
  730.     FILE *fp, *fopen();
  731.     int i,xcnt,ycnt,done=FALSE;
  732.     char line[80],fname[80];
  733.  
  734.     /*find out which helpfile to read in */
  735.     clear_bottom(0);
  736.     ycnt = LINES - 3;
  737.     xcnt = 0;
  738.     mvaddstr(LINES-4,0,"Help on which topic:");
  739.     for (i=0;i<MAXHELP;i++) {
  740.         sprintf(line,"  %d) %s",i,helplist[i]);
  741.         mvaddstr(ycnt,xcnt,line);
  742.         xcnt += 20;
  743.         if (i==2) {
  744.             xcnt = 0;
  745.             ycnt ++;
  746.         }
  747.     }
  748.     refresh();
  749.     i = getch()-'0';
  750.  
  751.     /* quick exit on invalid entry */
  752.     if (i<0 || i>MAXHELP) {
  753.         redraw=FALSE;
  754.         makebottom();
  755.         return;
  756.     }
  757.  
  758.     /*open help file*/
  759.     sprintf(fname,"%s/%s%d",DEFAULTDIR,helpfile,i);
  760.     if ((fp=fopen(fname,"r"))==NULL) {
  761.         mvprintw(0,0,"\nerror on read of %s\n",fname);
  762.         refresh();
  763.         getch();
  764.         return;
  765.     }
  766.  
  767.     while(done==FALSE){
  768.         /*read in screen (until DONE statement)*/
  769.         fgets(line,80,fp);
  770.         if(strncmp(line,"DONE",4)==0) done=TRUE;
  771.         else {
  772.             clear();
  773.             lineno=0;
  774.             while(strncmp(line,"END",3)!=0) {
  775.                 if(lineno==0) {
  776.                     /* highlight topic line */
  777.                     for(i=0;line[i]==' ';i++) ;
  778.                     i--;          /* back up 1 */
  779.                     standout();
  780.                     mvaddstr(lineno,i,line+i);
  781.                     /* add a blank space on the end */
  782.                     mvaddch(lineno,strlen(line)-1,' ');
  783.                     standend();
  784.                 } else mvaddstr(lineno,0,line);
  785.                 lineno++;
  786.                 if(lineno>LINES-3) strcpy(line,"END");
  787.                 else fgets(line,80,fp);
  788.             }
  789.             standout();
  790.             /* help screen 80 col format; constants needed */
  791.             mvaddstr(LINES-2,16,"HIT ANY KEY TO CONTINUE HELP SCREENS");
  792.             mvaddstr(LINES-1,21,"TO END HELP HIT SPACE KEY");
  793.             standend();
  794.             refresh();
  795.             if(getch()==' ') done=TRUE;
  796.         }
  797.     }
  798.     fclose(fp);
  799. }
  800.  
  801. void
  802. newspaper()
  803. {
  804.     int lineno;
  805.     FILE *fp, *fopen();
  806.     int newpage,choice,done=FALSE;
  807.     short pagenum=1;
  808.     int i,ydist,xdist;
  809.     char line[80],name[80];
  810.  
  811.     /* check to make sure that there are newspapers */
  812.     if (TURN==0) {
  813.         clear_bottom(0);
  814.         errormsg("no news to read");
  815.         redraw=FALSE;
  816.         makebottom();
  817.         return;
  818.     }
  819.  
  820.     clear_bottom(0);
  821.     ydist=LINES-3;
  822.     xdist=0;
  823.     /* check for all newspapers up until the current turn */
  824.     for (i=TURN-1;i>=0 && i>=TURN-MAXNEWS;i--) {
  825.         sprintf(line,"   %d) %s of Year %d",TURN-i,
  826.             PSEASON(i), YEAR(i));
  827.         /* align all strings */
  828.         mvprintw(ydist,xdist,"%s",line);
  829.         xdist += strlen(line);
  830.         if (xdist>60) {
  831.             xdist=0;
  832.             ydist++;
  833.         }
  834.     }
  835.     mvaddstr(LINES-4,0,"Read Which Newspaper:");
  836.     standend();
  837.     refresh();
  838.     /* get the choice */
  839.     choice = getch() - '0';
  840.     /* make sure the choice is valid */
  841.     if (choice<1 || choice > MAXNEWS) {
  842.         makebottom();
  843.         redraw=FALSE;
  844.         return;
  845.     }
  846.  
  847.     sprintf(name,"%s%d",newsfile,TURN-choice);
  848.     if ((fp=fopen(name,"r"))==NULL) {
  849.         clear_bottom(0);
  850.         sprintf(line,"unable to open news file <%s>",name);
  851.         errormsg(line);
  852.         redraw=FALSE;
  853.         makebottom();
  854.         return;
  855.     }
  856.  
  857.     /*open and read one page */
  858.     newpage=FALSE;
  859.     line[0]='\0';
  860.     strcpy(name,"");
  861.  
  862.     /*clear out any proceeding blanks*/
  863.     while(done==FALSE && strlen(name)==0)
  864.         if(fgets(name,80,fp)==NULL) done=TRUE;
  865.  
  866.     while(done==FALSE){
  867.         if(newpage==FALSE){
  868.             clear();
  869.             lineno=5;
  870.             newpage=TRUE;
  871.             standout();
  872.             mvprintw(0,23,"CONQUER NEWS REPORT  page %d",pagenum);
  873.             mvprintw(1,28,"%s of Year %d",PSEASON(TURN-choice),YEAR(TURN-choice));
  874.             mvprintw(3,37-strlen(name)/2,"%s",name+2);
  875.             standend();
  876.             /* display any pending non-blank lines */
  877.             if(strcmp(line,name)!=0 && strlen(line)>2)
  878.                 mvaddstr(lineno++,0,line+2);
  879.         } else if(fgets(line,80,fp)==NULL) done=TRUE;
  880.         else {
  881.             if(line[1]!='.') {
  882.                 strcpy(name,line);
  883.                 newpage=FALSE;
  884.                 pagenum++;
  885.             } else {
  886.                 if(todigit(line[0])!=pagenum) {
  887.                     newpage=FALSE;
  888.                     pagenum=todigit(line[0]);
  889.                 }
  890.                 else if(lineno>LINES-4) newpage=FALSE;
  891.                 else if(strlen(line)>2) mvaddstr(lineno++,0,line+2);
  892.             }
  893.         }
  894.         if(newpage==FALSE||done==TRUE){
  895.             standout();
  896.             /* constants since news is 80 col format */
  897.             mvaddstr(LINES-2,24,"HIT ANY KEY TO CONTINUE");
  898.             mvaddstr(LINES-1,25,"TO END NEWS HIT SPACE");
  899.             standend();
  900.             refresh();
  901.             if(getch()==' ') done=TRUE;
  902.         }
  903.     }
  904.     fclose(fp);
  905. }
  906.