home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / conqsrc.lha / Conquest / src / update.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-04  |  4.8 KB  |  216 lines

  1. /* Update.c: Routines for updating */
  2. #include <stdio.h>
  3. #include "defs.h"
  4. #include "structs.h"
  5. #include "vars.h"
  6. #include "protos.h"
  7.  
  8. void update_board(int x, int y, toption option)
  9. {
  10.   int screen_x, screen_y;
  11.  
  12.   if (terminal_type != hardcopy) 
  13.   {
  14.     screen_x = 3*x + 1;
  15.     screen_y = 16 - y;
  16.     switch (option)
  17.     {
  18.      case left:
  19.       point(screen_x,screen_y);
  20.       putchar(board[x][y].enemy);
  21.       break;
  22.       
  23.      case right:
  24.       point(screen_x+2,screen_y);
  25.       putchar(board[x][y].tf);
  26.       break;
  27.       
  28.      case both:
  29.       point(screen_x, screen_y);
  30.       printf("%c%c%c", board[x][y].enemy,board[x][y].star, board[x][y].tf);
  31.       break;
  32.     }
  33.   }
  34. }
  35.  
  36. void up_year()
  37. {
  38.   point(39,18);
  39.   turn++;
  40.   if (terminal_type == hardcopy)
  41.     printf("Year ");
  42.   printf("%3d", turn);
  43.  
  44.   point(48,19);
  45.   production_year++;
  46.   if (terminal_type == hardcopy)
  47.     printf("Production year ");
  48.   printf("%d", production_year);
  49. }
  50.  
  51. /* Remove empty taskforces */
  52. void zero_tf(tteam tm, int tf_num)
  53. {
  54.   int x, y, i;
  55.  
  56.   if (tf[tm][tf_num].dest != 0) 
  57.   {
  58.     x = tf[tm][tf_num].x;  
  59.     y = tf[tm][tf_num].y;
  60.     if ((tf[tm][tf_num].s+tf[tm][tf_num].t+
  61.      tf[tm][tf_num].c+tf[tm][tf_num].b) == 0)
  62.     {
  63.       if (tf[tm][tf_num].eta == 0) 
  64.     tf_stars[tf[tm][tf_num].dest][tm]--;
  65.  
  66.       tf[tm][tf_num].dest=0;
  67.  
  68.       if (tm==player)
  69.       {
  70.     board[x][y].tf=' ';
  71.  
  72.     for(i=1; i<=26; i++) 
  73.     {
  74.       if ((tf[player][i].dest !=0) &&
  75.           (tf[player][i].x == x) && (tf[player][i].y == y))
  76.       {
  77.         if (board[x][y].tf == ' ')
  78.           board[x][y].tf = i + 'a' - 1;
  79.         else if (board[x][y].tf != i + 'a' - 1)
  80.           board[x][y].tf = '*';
  81.       }
  82.     }
  83.     update_board(x,y,right);
  84.       }
  85.     }
  86.   }
  87. }
  88.  
  89. void check_game_over()
  90. {
  91.   boolean dead[2];
  92.   boolean quit_game;
  93.   int total[2], transports[2], inhabs[2];
  94.   tteam team; 
  95.   int tfnum, starnum; 
  96.   struct stplanet *pplan;
  97.   
  98.   quit_game = game_over;
  99.   for (team = ENEMY; team <= player; team++) 
  100.   {
  101.     transports[team] = 0;
  102.     inhabs[team] = 0;
  103.     for (tfnum = 1 ; tfnum<=26; tfnum++)
  104.     {
  105.       if (tf[team][tfnum].dest != 0)
  106.     transports[team] += tf[team][tfnum].t;
  107.     }
  108.   }
  109.   for (starnum = 1 ; starnum<=nstars; starnum++)
  110.   {
  111.     pplan = stars[starnum].first_planet;
  112.     while (pplan != nil)
  113.     {
  114.       switch (pplan->team)
  115.       {
  116.        case player: 
  117.     inhabs[player] += pplan->iu;
  118.     break;
  119.        case ENEMY: 
  120.     inhabs[ENEMY] += pplan->iu;
  121.     break;
  122.       }
  123.       pplan = pplan->next;
  124.     }
  125.   }
  126.  
  127.   for (team = ENEMY ; team<=player; team++)
  128.   {
  129.     total[team] = inhabs[team] + transports[team];
  130.     dead[team] = (total[team]==0);
  131.   }
  132.   if ((!dead[player]) && (!dead[ENEMY]) && (turn >= 40)) 
  133.   {
  134.     dead[ENEMY] = total[player] / total[ENEMY] >= 8;
  135.     dead[player] = total[ENEMY] / total[player] >= 8;
  136.   }
  137.  
  138.   game_over = (dead[player] || dead[ENEMY] || (turn>100) || quit_game);
  139.   if (game_over) 
  140.   {
  141.     clear_screen();
  142.     printf("*** Game over ***\n");
  143.     printf("Player: Population in transports:%3d", transports[player]);
  144.     printf("  IU's on colonies: %3d  TOTAL: %3d\n", inhabs[player], total[player]);
  145.     putchar('\n');
  146.     printf("Enemy:  Population in transports:%3d", transports[ENEMY]);
  147.     printf("  IU's on colonies: %3d  TOTAL: %3d\n", inhabs[ENEMY], total[ENEMY]);
  148.     if ((total[ENEMY] > total[player]) || quit_game)
  149.       printf("**** THE ENEMY HAS CONQUERED THE GALAXY ***\n");
  150.     else if ((total[player] > total[ENEMY]))
  151.       printf("*** PLAYER WINS- YOU HAVE SAVED THE GALAXY! ***\n");
  152.     else
  153.       printf("*** DRAWN ***\n");
  154.     get_char();
  155.   }
  156. }
  157.  
  158. void revolt(int starnum)
  159. {
  160.   tplanet *pplan;
  161.   
  162.   if (col_stars[starnum][ENEMY]+col_stars[starnum][player] == 0)
  163.     return;
  164.   
  165.   for (pplan = stars[starnum].first_planet; pplan; pplan = pplan->next)
  166.   {
  167.     if ((pplan->conquered) && (!any_bc(pplan->team, starnum)))
  168.     {
  169.       col_stars[starnum][pplan->team]--;
  170.       col_stars[starnum][OTHER_PLAYER(pplan->team)]++;
  171.       pplan->team = OTHER_PLAYER(pplan->team);
  172.       pplan->conquered = false;
  173.       pplan->psee_capacity = pplan->capacity;
  174.       on_board(stars[starnum].x,stars[starnum].y);
  175.     }
  176.   }
  177. }
  178.  
  179. void invest()
  180. {
  181.   int newborn,starnum; 
  182.   struct stplanet  *pplan;
  183.  
  184.   production_year = 0;
  185.   point(33,20);
  186.   printf("* investment *  ");
  187.  
  188.   for (starnum = 1; starnum<=nstars; starnum++)
  189.   {
  190.     for (pplan = stars[starnum].first_planet; pplan; pplan=pplan->next)
  191.     {
  192.       if ((pplan->esee_team == player) &&
  193.       (pplan->capacity > 10) &&
  194.       (pplan->esee_def < 12))
  195.     pplan->esee_def++;
  196.  
  197.       if ((pplan->team) != none) 
  198.       {
  199.     newborn = round((pplan->inhabitants) * growth_rate[pplan->team] *
  200.             (1-((pplan->inhabitants)/(pplan->capacity))));
  201.     if (pplan->conquered)
  202.       newborn = newborn / 2;
  203.  
  204.     pplan->inhabitants= (pplan->inhabitants) + newborn;
  205.     pplan->iu = pplan->iu + newborn;
  206.  
  207.     if (pplan->team==ENEMY)
  208.       inv_enemy(stars[starnum].x, stars[starnum].y,pplan);
  209.     else
  210.       inv_player(stars[starnum].x, stars[starnum].y,pplan);
  211.       }
  212.     }
  213.   }
  214.   battle();
  215. }
  216.