home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume7 / omega3 / part18 / ovillage.c < prev   
C/C++ Source or Header  |  1989-07-20  |  7KB  |  291 lines

  1. /* omega copyright (C) by Laurence Raphael Brothers, 1987,1988,1989 */
  2. /* ovillage.c */
  3. /* some functions to make the village levels */
  4.  
  5. #include "oglob.h"
  6.  
  7.  
  8. /* loads the village level into Level*/
  9. void load_village(villagenum)
  10. int villagenum;
  11. {
  12.   int i,j;
  13.   char site;
  14.   
  15.   FILE *fd;
  16.   
  17.  
  18.   TempLevel = Level;
  19.   if (ok_to_free(TempLevel)) {
  20. #ifndef MSDOS
  21.     free((char *) TempLevel);
  22. #endif
  23.     TempLevel = NULL;
  24.   }
  25.  
  26.   assign_village_function(0,0,TRUE);
  27.  
  28. #ifndef MSDOS
  29.   Level = ((plv) malloc(sizeof(levtype)));
  30. #else
  31.   msdos_changelevel(TempLevel,0,-1);
  32.   Level = &TheLevel;
  33. #endif
  34.   clear_level(Level);
  35.   Level->environment = E_VILLAGE;
  36.   strcpy(Str3,OMEGALIB);
  37.   switch(villagenum) {
  38. #ifndef MSDOS
  39.   case 1:strcat(Str3,"ovillage1.dat");break;
  40.   case 2:strcat(Str3,"ovillage2.dat");break;
  41.   case 3:strcat(Str3,"ovillage3.dat");break;
  42.   case 4:strcat(Str3,"ovillage4.dat");break;
  43.   case 5:strcat(Str3,"ovillage5.dat");break;
  44.   case 6:strcat(Str3,"ovillage6.dat");break;
  45. #else
  46.   case 1:strcat(Str3,"ovillag1.dat");break;
  47.   case 2:strcat(Str3,"ovillag2.dat");break;
  48.   case 3:strcat(Str3,"ovillag3.dat");break;
  49.   case 4:strcat(Str3,"ovillag4.dat");break;
  50.   case 5:strcat(Str3,"ovillag5.dat");break;
  51.   case 6:strcat(Str3,"ovillag6.dat");break;
  52. #endif
  53.   }
  54.   fd = fopen(Str3,"r");
  55.   for(j=0;j<LENGTH;j++) {
  56.     for(i=0;i<WIDTH;i++) {
  57.       lset(i,j,SEEN);
  58.       site = getc(fd);
  59.       switch(site) {
  60.       case 'f':
  61.     Level->site[i][j].locchar = FLOOR;
  62.     make_food_bin(i,j);
  63.     break;
  64.       case 'g':
  65.     Level->site[i][j].locchar = FLOOR;
  66.     Level->site[i][j].p_locf = L_GRANARY;
  67.     break;
  68.       case 'h':
  69.     Level->site[i][j].locchar = FLOOR;
  70.     make_horse(i,j);
  71.     break;
  72.       case 'S':
  73.     Level->site[i][j].locchar = FLOOR;
  74.     Level->site[i][j].p_locf = L_STABLES;
  75.     break;
  76.       case 'H':
  77.     Level->site[i][j].locchar = FLOOR;
  78.     make_merchant(i,j);
  79.     break;
  80.       case 'C':
  81.     Level->site[i][j].locchar = FLOOR;
  82.     Level->site[i][j].p_locf = L_COMMONS;
  83.     break;
  84.       case 's':
  85.     Level->site[i][j].locchar = FLOOR;
  86.     make_sheep(i,j);
  87.     break;
  88.       case 'x':
  89.     assign_village_function(i,j,FALSE);
  90.     break;
  91.       case 'X':
  92.     Level->site[i][j].locchar = FLOOR;
  93.     Level->site[i][j].p_locf = L_COUNTRYSIDE;
  94.     break;
  95.       case 'G':
  96.     Level->site[i][j].locchar = FLOOR;
  97.     make_guard(i,j);
  98.     break;
  99.       case '^':
  100.     Level->site[i][j].locchar = FLOOR;
  101.     Level->site[i][j].p_locf = L_TRAP_SIREN;
  102.     break;
  103.       case '"':
  104.     Level->site[i][j].locchar = HEDGE;
  105.     Level->site[i][j].p_locf = L_HEDGE;
  106.     break;
  107.       case '~':
  108.     Level->site[i][j].locchar = WATER;
  109.     Level->site[i][j].p_locf = L_WATER;
  110.     break;
  111.       case '+':
  112.     Level->site[i][j].locchar = WATER;
  113.     Level->site[i][j].p_locf = L_CHAOS;
  114.     break;
  115.       case '\'':
  116.     Level->site[i][j].locchar = HEDGE;
  117.     Level->site[i][j].p_locf = L_TRIFID;
  118.     break;
  119.       case '!':
  120.     special_village_site(i,j,villagenum);
  121.     break;
  122.       case '#':
  123.     Level->site[i][j].locchar = WALL;
  124.     Level->site[i][j].aux = 100;
  125.     break;
  126.       default:
  127.     Level->site[i][j].p_locf = L_NO_OP;
  128.     Level->site[i][j].locchar = site;
  129.     break;
  130.       }
  131.       if (loc_statusp(i,j,SECRET))
  132.     Level->site[i][j].showchar = '#';
  133.       else Level->site[i][j].showchar = Level->site[i][j].locchar;
  134.     }
  135.     fscanf(fd,"\n");
  136.   }
  137.   fclose(fd);
  138. }
  139.  
  140. void make_guard(i,j)
  141. int i,j;
  142. {
  143.   pml tml = ((pml) (malloc(sizeof(mltype))));
  144.   tml->m = (Level->site[i][j].creature = make_creature(ML0+3));
  145.   tml->m->x = i;
  146.   tml->m->y = j;
  147.   tml->next = Level->mlist;
  148.   Level->mlist = tml;
  149. }
  150.  
  151. void make_sheep(i,j)
  152. int i,j;
  153. {
  154.   pml tml = ((pml) (malloc(sizeof(mltype))));
  155.   tml->m = (Level->site[i][j].creature = make_creature(SHEEP));
  156.   tml->m->x = i;
  157.   tml->m->y = j;
  158.   tml->next = Level->mlist;
  159.   Level->mlist = tml;
  160. }
  161.  
  162. void make_food_bin(i,j)
  163. int i,j;
  164.   pol tol;
  165.   int k;
  166.  
  167.   for(k=0;k<10;k++) {
  168.     tol = ((pol) malloc(sizeof(oltype)));
  169.     tol->thing = ((pob) malloc(sizeof(objtype)));
  170.     make_food(tol->thing,15); /* grain */
  171.     tol->next = Level->site[i][j].things;
  172.     Level->site[i][j].things = tol;
  173.   }
  174. }
  175.  
  176. void make_horse(i,j)
  177. int i,j;
  178. {
  179.   pml tml = ((pml) (malloc(sizeof(mltype))));
  180.   tml->m = (Level->site[i][j].creature = make_creature(HORSE));
  181.   tml->m->x = i;
  182.   tml->m->y = j;
  183.   tml->next = Level->mlist;
  184.   Level->mlist = tml;
  185. }
  186.  
  187.  
  188. void make_merchant(i,j)
  189. int i,j;
  190. {
  191.   pml tml = ((pml) (malloc(sizeof(mltype))));
  192.   tml->m = (Level->site[i][j].creature = make_creature(ML0+6));
  193.   tml->m->x = i;
  194.   tml->m->y = j;
  195.   tml->next = Level->mlist;
  196.   Level->mlist = tml;
  197. }
  198.  
  199.  
  200. void assign_village_function(x,y,setup)
  201. int x,y,setup;
  202. {
  203.   static int next=0;
  204.   static int permutation[24]; /* number of x's in village map */
  205.   int i,j,k;
  206.  
  207.  
  208.   if (setup) {
  209.     next = 0;
  210.     for(i=0;i<24;i++)
  211.       permutation[i] = i;
  212.     for(i=0;i<24;i++) {
  213.       j = permutation[i];
  214.       k = random_range(24);
  215.       permutation[i] = permutation[k];
  216.       permutation[k] = j;
  217.     }
  218.   }
  219.   else {
  220.  
  221.     lset(x,y+1,STOPS);
  222.     lset(x+1,y,STOPS);
  223.     lset(x-1,y,STOPS);
  224.     lset(x,y-1,STOPS);
  225.     
  226.     
  227.     switch(permutation[next++]) {
  228.     case 0:
  229.       Level->site[x][y].locchar = OPEN_DOOR;
  230.       Level->site[x][y].p_locf = L_ARMORER;
  231.       break;
  232.     case 1:
  233.       Level->site[x][y].locchar = OPEN_DOOR;
  234.       Level->site[x][y].p_locf = L_HEALER;
  235.       break;
  236.     case 2: 
  237.       Level->site[x][y].locchar = OPEN_DOOR;
  238.       Level->site[x][y].p_locf = L_TAVERN;
  239.       break;
  240.     case 3:
  241.       Level->site[x][y].locchar = OPEN_DOOR;
  242.       Level->site[x][y].p_locf = L_COMMANDANT;
  243.       break;
  244.     case 4:
  245.       Level->site[x][y].locchar = OPEN_DOOR;
  246.       Level->site[x][y].p_locf = L_CARTOGRAPHER;
  247.       break;
  248.     default:
  249.       Level->site[x][y].locchar = CLOSED_DOOR;
  250.       if (random_range(2))
  251.     Level->site[x][y].p_locf = L_HOVEL;
  252.  
  253.       if (random_range(2)) 
  254.     Level->site[x][y].aux = LOCKED;
  255.       else Level->site[x][y].p_locf = L_HOUSE;
  256.       break;
  257.     }
  258.   }
  259. }  
  260.   
  261.  
  262. void special_village_site(i,j,villagenum)
  263. int i,j,villagenum;
  264. {
  265.   if (villagenum == 1) {
  266.     Level->site[i][j].locchar = ALTAR;
  267.     Level->site[i][j].p_locf = L_LAWSTONE;
  268.   }
  269.   if (villagenum == 2) {
  270.     Level->site[i][j].locchar = ALTAR;
  271.     Level->site[i][j].p_locf = L_BALANCESTONE;
  272.   }
  273.   else if (villagenum == 3) {
  274.     Level->site[i][j].locchar = ALTAR; 
  275.     Level->site[i][j].p_locf = L_CHAOSTONE; 
  276.   }
  277.   else if (villagenum == 4) {
  278.     Level->site[i][j].locchar = ALTAR; 
  279.     Level->site[i][j].p_locf = L_VOIDSTONE; 
  280.   }
  281.   else if (villagenum == 5) {
  282.     Level->site[i][j].locchar = ALTAR; 
  283.     Level->site[i][j].p_locf = L_SACRIFICESTONE; 
  284.   }
  285.   else if (villagenum == 6) {
  286.     Level->site[i][j].locchar = ALTAR; 
  287.     Level->site[i][j].p_locf = L_MINDSTONE; 
  288.   }
  289. }
  290.