home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume2 / conquest / part02 / magic.c < prev    next >
C/C++ Source or Header  |  1987-10-26  |  9KB  |  354 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. /*create a new login for a new player*/
  14. #include "header.h"
  15. #include <ctype.h>
  16.  
  17. extern short country;
  18. extern short redraw;
  19. extern FILE *fexe;
  20. extern FILE *fnews;
  21.  
  22. /*give player one new magic power in current magic (powers)*/
  23. /*do nothing if that player has that power or it is not permitted*/
  24. /*getmagic() returns the value of the power gained, and stores it in power*/
  25.  
  26. getmagic()
  27. {
  28. short newpower;
  29.     newpower=rand()%MAXPOWER;
  30.     switch(newpower){
  31.     case WARRIOR:
  32.     case CAPTAIN:
  33.     case WARLORD:
  34.         if(magic(country,WARRIOR)!=1){
  35.             ntn[country].powers*=WARRIOR;
  36.             return(WARRIOR);
  37.         }
  38.         else if(magic(country,CAPTAIN)!=1){
  39.             ntn[country].powers*=CAPTAIN;
  40.             return(CAPTAIN);
  41.         }
  42.         else if(magic(country,WARLORD)!=1){
  43.             ntn[country].powers*=WARLORD;
  44.             return(WARLORD);
  45.         }
  46.         break;
  47.     case MI_MONST:
  48.     case AV_MONST:
  49.     case MA_MONST:
  50.         if(ntn[country].race!=ORC) return(1);
  51.         if(magic(country,MI_MONST)!=1){
  52.             ntn[country].powers*=MI_MONST;
  53.             return(MI_MONST);
  54.         }
  55.         else if(magic(country,AV_MONST)!=1){
  56.             ntn[country].powers*=AV_MONST;
  57.             return(AV_MONST);
  58.         }
  59.         else if(magic(country,MA_MONST)==1){
  60.             ntn[country].powers*=MA_MONST;
  61.             return(MA_MONST);
  62.         }
  63.         break;
  64.     case SPY:
  65.     case KNOWALL:
  66.     case DERVISH:
  67.     case HIDDEN:
  68.     case ARCHITECT:
  69.     case URBAN:
  70.     case THE_VOID:
  71.     case HEALER:
  72.     case ARCHER:
  73.     case CAVALRY:
  74.         if(magic(country,newpower)==1) return(1);
  75.         ntn[country].powers*=newpower;
  76.         return(newpower);
  77.     case DESTROYER:
  78.         if((ntn[country].race!=ELF)&&(magic(country,DESTROYER)!=1)){
  79.             ntn[country].powers*=DESTROYER;
  80.             return(DESTROYER);
  81.         }
  82.         break;
  83.     case VAMPIRE:
  84.         if((ntn[country].race!=ELF)&&(magic(country,VAMPIRE)!=1)){
  85.             ntn[country].powers*=VAMPIRE;
  86.             return(VAMPIRE);
  87.         }
  88.         break;
  89.     case MINER:
  90.         if((ntn[country].race!=ELF)&&(ntn[country].race!=DWARF)&&(magic(country,MINER)!=1)){
  91.             ntn[country].powers*=MINER;
  92.             return(MINER);
  93.         }
  94.     case STEEL:
  95.         if(magic(country,STEEL)==1) return(1);
  96.         if(magic(country,MINER)!=1) return(1);
  97.         ntn[country].powers*=STEEL;
  98.         return(STEEL);
  99.     case BREEDER:
  100.         if(magic(country,BREEDER)==1) return(1);
  101.         if(ntn[country].race!=ORC) return(1);
  102.         ntn[country].powers*=BREEDER;
  103.         return(BREEDER);
  104.     }
  105.     return(1);
  106. }
  107.  
  108. /*form to interactively get a magic power*/
  109. domagic()
  110. {
  111.     short x,count,done=0,loop=0;
  112.     short isgod=0;
  113.     short overmax=0;
  114.     if(country==0) {
  115.         isgod=1;
  116.         clear();
  117.         mvaddstr(0,0,"WHAT NATION NUMBER:");
  118.         refresh();
  119.         echo();
  120.         scanw("%hd",&country);
  121.         noecho();
  122.     }
  123.  
  124.     while(done==0){
  125.         clear();
  126.         count=3;
  127.         redraw=TRUE;
  128.         standout();
  129.         mvprintw(0,(COLS/2)-15,"MAGIC POWERS FOR %s",ntn[country].name);
  130.         standend();
  131.         /*print the powers that you have*/
  132.         if(magic(country,WARRIOR)==1)
  133.             mvaddstr(count++,0,"you have WARRIOR power (Fighter Level 1)");
  134.         if(magic(country,CAPTAIN)==1)
  135.             mvaddstr(count++,0,"you have CAPTAIN power (Fighter Level 2)");
  136.         if(magic(country,WARLORD)==1)
  137.             mvaddstr(count++,0,"you have WARLORD power (Fighter Level 3)");
  138.         if(magic(country,MI_MONST)==1)
  139.             mvaddstr(count++,0,"you have MINOR MONSTER power");
  140.         if(magic(country,AV_MONST)==1)
  141.             mvaddstr(count++,0,"you have AVERAGE MONSTER power");
  142.         if(magic(country,MA_MONST)==1) 
  143.             mvaddstr(count++,0,"you have MAJOR MONSTER power");
  144.         if(magic(country,SPY)==1) 
  145.             mvaddstr(count++,0,"you have SPY power");
  146.         if(magic(country,KNOWALL)==1)
  147.             mvaddstr(count++,0,"you have KNOWALL power");
  148.         if(magic(country,DERVISH)==1) 
  149.             mvaddstr(count++,0,"you have DERVISH power");
  150.         if(magic(country,DESTROYER)==1)
  151.             mvaddstr(count++,0,"you have DESTROYER power");
  152.         if(magic(country,HIDDEN)==1) 
  153.             mvaddstr(count++,0,"you have HIDDEN power");
  154.         if(magic(country,THE_VOID)==1)
  155.             mvaddstr(count++,0,"you have THE_VOID power");
  156.         if(magic(country,ARCHITECT)==1)
  157.             mvaddstr(count++,0,"you have ARCHITECT power");
  158.         if(magic(country,VAMPIRE)==1)
  159.             mvaddstr(count++,0,"you have VAMPIRE power");
  160.         if(magic(country,HEALER)==1)
  161.             mvaddstr(count++,0,"you have HEALER power");
  162.         if(magic(country,MINER)==1) 
  163.             mvaddstr(count++,0,"you have MINER power");
  164.         if(magic(country,URBAN)==1)
  165.             mvaddstr(count++,0,"you have URBAN power");
  166.         if(magic(country,STEEL)==1)
  167.             mvaddstr(count++,0,"you have STEEL power");
  168.         if(magic(country,ARCHER)==1)
  169.             mvaddstr(count++,0,"you have ARCHER power");
  170.         if(magic(country,CAVALRY)==1)
  171.             mvaddstr(count++,0,"you have CAVALRY power");
  172.         if(magic(country,BREEDER)==1)
  173.             mvaddstr(count++,0,"you have BREEDER power");
  174.         standout();
  175.         if(count>=PCPOWERS+3){
  176.         mvaddstr(count++,0,"YOU HAVE THE MAXIMUM NUMBER OF POWERS");
  177.         mvaddstr(count++,0,"  NEW POWERS COST DOUBLE AND ARE INVALID UNLESS THEY");
  178.         mvaddstr(count++,0,"  AUGMENT EXISTING FIGHTER OR MONSTER POWERS (hit any char)");
  179.         standend();
  180.         overmax=1;
  181.         }
  182.  
  183.         if(ntn[country].race==ORC){
  184.         mvprintw(count++,0,"DO YOU WISH TO TAKE OVER A NPC NATION (enter y or n):");
  185.         mvaddstr(count++,0,"  Base 10 percent for 100K Jewels if Confederacy and the same race");
  186.         refresh();
  187.         if(getch()=='y'){
  188.         mvprintw(count++,0,"SORRY; NOT IMPLEMENTED YET");
  189.         }
  190.         }
  191.  
  192.         count++;
  193.         mvprintw(count++,0,"DO YOU WISH TO BUY A RANDOM NEW POWER FOR %d JEWELS (enter y or n):",JWL_MGK);
  194.         standend();
  195.         refresh();
  196.         if(getch()=='y'){
  197.             if(((ntn[country].jewels>JWL_MGK)&&(overmax==0))||(ntn[country].jewels>2*JWL_MGK)) {
  198.             while(loop==0) if((x=getmagic())!=1){
  199.                 if((ntn[country].powers<=1)||(x<1)){
  200.                 mvprintw(count++,0,"ERROR ON POWER #%d",x);
  201.                 }
  202.                 else if(overmax==1){
  203.                     ntn[country].jewels-=2*JWL_MGK;
  204.                     if(((magic(country,WARRIOR)==1)&&((x==CAPTAIN)||(x==WARLORD)))||((magic(country,MI_MONST)==1)&&((x==AV_MONST)||(x==MA_MONST)))){
  205.                         CHGMGK;
  206.                         exenewmgk(x);
  207.                     }
  208.                     else {
  209.                     mvprintw(count++,0,"USELESS POWER (number %d)",x);
  210.                     ntn[country].powers/=x;
  211.                     }
  212.                 }
  213.                 else {
  214.                     ntn[country].jewels-=JWL_MGK;
  215.                     mvprintw(count++,0,"YOU NOW HAVE POWER #%d",x);
  216.                     CHGMGK;
  217.                     exenewmgk(x);
  218.                 }
  219.                 refresh();
  220.                 getch();
  221.                 loop=1;
  222.             }
  223.             }
  224.             else {
  225.                 mvaddstr(count++,0,"NOT ENOUGH JEWELS -- hit any key");
  226.                 refresh();
  227.                 getch();
  228.                 done=1;
  229.             }
  230.         }
  231.         else done=1;
  232.     }
  233.     if(isgod==1) country=0;
  234. }
  235.  
  236. /*do magic for both npcs and pcs in update*/
  237. /*if target is 0 then it will be picked randomly*/
  238. takeover(percent,target)
  239. {
  240. int loop=1,y,save;
  241.     save=country;
  242.     country=target;
  243.     if(rand()%100<percent){
  244.         loop=0;
  245.         y=0;
  246.         if (target==0) while(loop==0){
  247.             y++;
  248.             country=rand()%MAXNTN;
  249.             if((ntn[country].race==ntn[save].race)&&(ntn[country].active>=2)) loop=1;
  250.             else if(y>=500) {
  251.                 country=save;
  252.                 return;
  253.             }
  254.         }
  255.         sct[ntn[country].capx][ntn[country].capy].owner=save;
  256.         fprintf(fnews,"1.\tnation %s taken over by %s\n",ntn[country].name,ntn[save].name);
  257.         destroy();
  258.     }
  259.     country=save;
  260. }
  261.  
  262. /*execute new magic*/
  263. exenewmgk(newpower)
  264. {
  265.     short x,y;
  266.     switch(newpower){
  267.         case WARRIOR:
  268.             ntn[country].aplus+=10;
  269.             ntn[country].dplus+=10;
  270.             break;
  271.         case CAPTAIN:
  272.             ntn[country].aplus+=10;
  273.             ntn[country].dplus+=10;
  274.             break;
  275.         case WARLORD:
  276.             ntn[country].aplus+=10;
  277.             ntn[country].dplus+=10;
  278.             break;
  279.         case HEALER:
  280.             if(ntn[country].race==ORC) {
  281.                 if(ntn[country].repro<=11)
  282.                     ntn[country].repro+=2;
  283.                 else    ntn[country].repro=13;
  284.             }
  285.             else if(ntn[country].repro<=8){
  286.                 ntn[country].repro=10;
  287.             }
  288.             else if(ntn[country].repro==9){
  289.                 ntn[country].repro=10;
  290.                 ntn[country].dplus+=5;
  291.             }
  292.             else if(ntn[country].repro>=10){
  293.                 ntn[country].dplus+=10;
  294.             }
  295.             break;
  296.         case DESTROYER:
  297.             for(x=ntn[country].capx-3;x<=ntn[country].capx+3;x++) {
  298.                 for(y=ntn[country].capy-3;y<=ntn[country].capy+3;y++){
  299.                     if((x>0)&&(y>0)&&(x<MAPX)&&(y<MAPY)&&(sct[x][y].altitude!=WATER)&&(isdigit(sct[x][y].vegitation)==0)){
  300.                         sct[x][y].vegitation=DESERT;
  301.                         sct[x][y].designation=DESERT;
  302.                     }
  303.                 }
  304.             }
  305.             break;
  306.         case MI_MONST:
  307.         case AV_MONST:
  308.         case MA_MONST:
  309.         case SPY:
  310.         case KNOWALL:
  311.         case DERVISH:
  312.         case HIDDEN:
  313.         case THE_VOID:
  314.         case ARCHITECT:
  315.         case MINER:
  316.             break;
  317.         case VAMPIRE:
  318.             ntn[country].aplus-=35;
  319.             ntn[country].dplus-=35;
  320.             ntn[country].maxmove-=2;
  321.             break;
  322.         case URBAN:
  323.             if(ntn[country].race==ORC) {
  324.                 ntn[country].repro+=3;
  325.                 if(ntn[country].repro>=13){
  326.                 ntn[country].maxmove+=2*(ntn[country].repro-13);
  327.                 ntn[country].repro=13;
  328.                 }
  329.             }
  330.             else if(ntn[country].repro<=9){
  331.                 ntn[country].repro+=3;
  332.             }
  333.             else {
  334.                 ntn[country].maxmove+=2*(ntn[country].repro-9);
  335.                 ntn[country].repro=12;
  336.             }
  337.             break;
  338.         case STEEL:
  339.             break;
  340.         case ARCHER:
  341.             ntn[country].dplus+=10;
  342.             break;
  343.         case CAVALRY:
  344.             ntn[country].aplus+=10;
  345.             ntn[country].maxmove+=6;
  346.             break;
  347.         case BREEDER:
  348.             ntn[country].repro+=3;
  349.             ntn[country].dplus-=10;
  350.             ntn[country].dplus-=10;
  351.             break;
  352.     }
  353. }
  354.