LCOV - code coverage report
Current view: top level - omega-rpg-0.90-pa9 - village.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 112 195 57.4 %
Date: 2017-09-08 22:00:26 Functions: 3 8 37.5 %
Branches: 45 76 59.2 %

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

Generated by: LCOV version 1.11