LCOV - code coverage report
Current view: top level - omega-rpg-0.90-pa9 - lev.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 55 329 16.7 %
Date: 2017-09-08 22:00:26 Functions: 3 10 30.0 %
Branches: 31 248 12.5 %

           Branch data     Line data    Source code
       1                 :            : /* omega copyright (c) 1987,1988,1989 by Laurence Raphael Brothers */
       2                 :            : /* lev.c */
       3                 :            : 
       4                 :            : #include "glob.h"
       5                 :            : 
       6                 :            : /* Functions dealing with dungeon and country levels aside from actual
       7                 :            : level structure generation */
       8                 :            : 
       9                 :            : 
      10                 :            : /* monsters for tactical encounters */
      11                 :          2 : void make_country_monsters(Symbol terrain)
      12                 :            : {
      13                 :          2 :   pml tml,ml=NULL;
      14                 :            :   static int plains[10] = 
      15                 :            :     {BUNNY,BUNNY,HORNET,QUAIL,HAWK,DEER,WOLF,LION,BRIGAND,RANDOM};
      16                 :            : /*    {BUNNY,BUNNY,BLACKSNAKE,HAWK,IMPALA,WOLF,LION,BRIGAND,RANDOM};*/
      17                 :            :   /* DG changed (WDT: I'd like to see a blacksnake). */
      18                 :            :   static int forest[10] =
      19                 :            :    {BUNNY,QUAIL,HAWK,BADGER,DEER,DEER,WOLF,BEAR,BRIGAND,RANDOM};
      20                 :            :   static int jungle[10] =
      21                 :            :     {ANTEATER,PARROT,MAMBA,ANT,ANT,HYENA,HYENA,ELEPHANT,LION,RANDOM};
      22                 :            :   static int river[10] =
      23                 :            :     {QUAIL,TROUT,TROUT,MANOWAR,BASS,BASS,CROC,CROC,BRIGAND,RANDOM};
      24                 :            :   static int swamp[10] =
      25                 :            :     {BASS,BASS,CROC,CROC,BOGTHING,ANT,ANT,RANDOM,RANDOM,RANDOM};
      26                 :            :   static int desert[10] =
      27                 :            :     {HAWK,HAWK,CAMEL,CAMEL,HYENA,HYENA,LION,LION,RANDOM,RANDOM};
      28                 :            :   static int tundra[10] =
      29                 :            :     {WOLF,WOLF,BEAR,BEAR,DEER,DEER,RANDOM,RANDOM,RANDOM,RANDOM};
      30                 :            :   static int mountain[10] =
      31                 :            :     {BUNNY,SHEEP,WOLF,WOLF,HAWK,HAWK,HAWK,RANDOM,RANDOM,RANDOM};
      32                 :            :   static int village[10] =
      33                 :            :     {GUARD,SHEEP,SHEEP,MERCHANT,ITIN_MERCH,ZERO_NPC,MEND_PRIEST,HAWK,HORSE,RANDOM};
      34                 :            :   static int city[10] =
      35                 :            :     {GUARD,GUARD,GUARD,SHEEP,HORSE,MERCHANT,ITIN_MERCH,ZERO_NPC,MEND_PRIEST,RANDOM};
      36                 :            :   static int road_day[10] = 
      37                 :            :     {GUARD,MERCHANT,ITIN_MERCH,MEND_PRIEST,WEREHUMAN,HAWK,WOLF,GRUNT,SNEAK_THIEF,RANDOM};
      38                 :            :   static int road_night[10] = 
      39                 :            :     {DEER,WOLF,GOBLIN,SNEAK_THIEF,APPR_NINJA,BRIGAND,WEREHUMAN,GENIN,RANDOM,RANDOM};
      40                 :            :   int *monsters,i,nummonsters;
      41                 :            : 
      42                 :          2 :   nummonsters = (random_range(5)+1) * (random_range(3)+1);
      43                 :            : 
      44   [ -  -  -  -  :          2 :   switch(terrain) {
          -  -  -  -  -  
                -  +  - ]
      45                 :          0 :   case PLAINS: monsters = plains; break;
      46                 :          0 :   case FOREST: monsters = forest; break;
      47                 :          0 :   case JUNGLE: monsters = jungle; break;
      48                 :          0 :   case RIVER: monsters = river; break;
      49                 :          0 :   case SWAMP: monsters = swamp; break;
      50                 :            :   case MOUNTAINS:
      51                 :            :   case PASS: 
      52                 :          0 :   case VOLCANO: monsters = mountain; break;
      53                 :          0 :   case DESERT: monsters = desert; break;
      54                 :          0 :   case TUNDRA: monsters = tundra; break;
      55                 :          0 :   case VILLAGE: monsters = village; break;
      56                 :          0 :   case CITY: monsters = city; break;
      57                 :            :   case ROAD:
      58         [ +  + ]:          2 :     if (nighttime())
      59                 :          1 :       monsters = road_night;
      60                 :            :     else
      61                 :          1 :       monsters = road_day;
      62                 :          2 :     break;
      63                 :          0 :   default: monsters = NULL;
      64                 :            :   }
      65         [ +  + ]:         21 :   for(i=0;i<nummonsters;i++) {
      66                 :         19 :     tml = ((pml) checkmalloc(sizeof(mltype)));
      67                 :         19 :     tml->m = ((pmt) checkmalloc(sizeof(montype)));
      68         [ -  + ]:         19 :     if (monsters == NULL) tml->m = 
      69                 :          0 :       m_create(random_range(Level->level_width),random_range(Level->level_length),TRUE,difficulty());
      70                 :            :     else {
      71                 :         19 :       tml->m = make_creature(*(monsters+random_range(10)));
      72                 :         19 :       tml->m->x = random_range(Level->level_width);
      73                 :         19 :       tml->m->y = random_range(Level->level_length);
      74                 :            :     }
      75                 :         19 :     Level->site[tml->m->x][tml->m->y].creature = tml->m;
      76                 :         19 :     tml->m->sense = Level->level_width;
      77         [ -  + ]:         19 :     if (m_statusp(tml->m,ONLYSWIM)) {
      78                 :          0 :       Level->site[tml->m->x][tml->m->y].locchar = WATER;
      79                 :          0 :       Level->site[tml->m->x][tml->m->y].p_locf = L_WATER;
      80                 :          0 :       lset(tml->m->x, tml->m->y, CHANGED);
      81                 :            :     }
      82                 :            : 
      83                 :         19 :     tml->next = ml;
      84                 :         19 :     ml = tml;
      85                 :            :   }
      86                 :          2 :   Level->mlist = ml;
      87                 :          2 : }
      88                 :            : 
      89                 :            : /* monstertype is more or less Current_Dungeon */
      90                 :            : /* The caves and sewers get harder as you penetrate them; the castle
      91                 :            : is completely random, but also gets harder as it is explored;
      92                 :            : the astral and the volcano just stay hard... */
      93                 :          0 : void populate_level(int monstertype)
      94                 :            : {
      95                 :            :   pml head,tml;
      96                 :            :   int i,j,k;
      97                 :            :   int monsterid;
      98                 :            :   int nummonsters;
      99                 :            : 
     100                 :          0 :   monsterid = RANDOM;
     101                 :          0 :   nummonsters=(random_range(difficulty()/3)+1)*3+8;
     102                 :            : 
     103         [ #  # ]:          0 :   if (monstertype == E_CASTLE) nummonsters += 10;
     104         [ #  # ]:          0 :   else if (monstertype == E_ASTRAL) nummonsters += 10;
     105         [ #  # ]:          0 :   else if (monstertype == E_VOLCANO) nummonsters += 20;
     106                 :            : 
     107                 :          0 :   head = tml = checkmalloc(sizeof(mltype));
     108                 :            : 
     109         [ #  # ]:          0 :   for(k=0;k<nummonsters;k++) {
     110                 :            : 
     111                 :          0 :     findspace(&i,&j,-1);
     112                 :            : 
     113   [ #  #  #  #  :          0 :     switch(monstertype) {
                   #  # ]
     114                 :            :     case E_CAVES:
     115         [ #  # ]:          0 :       if (Level->depth*10+random_range(100) > 150) 
     116                 :          0 :         monsterid = GOBLIN_SHAMAN;
     117         [ #  # ]:          0 :       else if (Level->depth*10+random_range(100) > 100) 
     118                 :          0 :         monsterid = GOBLIN_CHIEF; /* Goblin Chieftain */
     119         [ #  # ]:          0 :       else if (random_range(100) > 50) monsterid = GOBLIN;
     120                 :          0 :       else monsterid = RANDOM; /* IE, random monster */
     121                 :          0 :       break;
     122                 :            :     case E_SEWERS:
     123         [ #  # ]:          0 :       if (! random_range(3)) monsterid = -1;
     124   [ #  #  #  #  :          0 :       else switch(random_range(Level->depth+3)) {
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     125                 :          0 :       case 0: monsterid = SEWER_RAT; break;
     126                 :          0 :       case 1: monsterid = AGGRAVATOR; break; /* aggravator fungus */
     127                 :          0 :       case 2: monsterid = BLIPPER; break; /* blipper rat */
     128                 :          0 :       case 3: monsterid = NIGHT_GAUNT; break;
     129                 :          0 :       case 4: monsterid = NASTY; break; /* transparent nasty */
     130                 :          0 :       case 5: monsterid = MURK; break; /* murk fungus */
     131                 :          0 :       case 6: monsterid = CATOBLEPAS; break;
     132                 :          0 :       case 7: monsterid = ACID_CLOUD; break;
     133                 :          0 :       case 8: monsterid = DENEBIAN; break; /* denebian slime devil */
     134                 :          0 :       case 9: monsterid = CROC; break; /* giant crocodile */
     135                 :          0 :       case 10: monsterid = TESLA; break; /* tesla monster */
     136                 :          0 :       case 11: monsterid = SHADOW; break; /* shadow spirit */
     137                 :          0 :       case 12: monsterid = BOGTHING; break; /* bogthing */
     138                 :          0 :       case 13: monsterid = WATER_ELEM; break; /* water elemental */
     139                 :          0 :       case 14: monsterid = TRITON; break;
     140                 :          0 :       case 15: monsterid = ROUS; break;
     141                 :          0 :       default: monsterid = RANDOM; break; /* whatever seems good */
     142                 :            :       }
     143                 :          0 :       break;
     144                 :            :     case E_ASTRAL:
     145         [ #  # ]:          0 :       if (random_range(2)) /* random astral creatures */
     146   [ #  #  #  #  :          0 :         switch(random_range(12)) {
          #  #  #  #  #  
             #  #  #  # ]
     147                 :          0 :         case 0: monsterid = THOUGHTFORM; break;
     148                 :          0 :         case 1: monsterid = FUZZY; break; /* astral fuzzy */
     149                 :          0 :         case 2: monsterid = BAN_SIDHE; break;
     150                 :          0 :         case 3: monsterid = GRUE; break; /* astral grue */
     151                 :          0 :         case 4: monsterid = SHADOW; break; /* shadow spirit */
     152                 :          0 :         case 5: monsterid = ASTRAL_VAMP; break; /* astral vampire */
     153                 :          0 :         case 6: monsterid = MANABURST; break;
     154                 :          0 :         case 7: monsterid = RAKSHASA; break;
     155                 :          0 :         case 8: monsterid = ILL_FIEND; break; /* illusory fiend */
     156                 :          0 :         case 9: monsterid = MIRRORMAST; break; /* mirror master */
     157                 :          0 :         case 10: monsterid = ELDER_GRUE; break; /* elder etheric grue */
     158                 :          0 :         case 11: monsterid = SHADOW_SLAY; break; /* shadow slayer */
     159                 :            :         }
     160 [ #  # ][ #  # ]:          0 :       else if (random_range(2) && (Level->depth == 1)) /* plane of earth */
     161                 :          0 :         monsterid = EARTH_ELEM; /* earth elemental */
     162 [ #  # ][ #  # ]:          0 :       else if (random_range(2) && (Level->depth == 2)) /* plane of air */
     163                 :          0 :         monsterid = AIR_ELEM;  /* air elemental */
     164 [ #  # ][ #  # ]:          0 :       else if (random_range(2) && (Level->depth == 3)) /* plane of water */
     165                 :          0 :         monsterid = WATER_ELEM;  /* water elemental */
     166 [ #  # ][ #  # ]:          0 :       else if (random_range(2) && (Level->depth == 4)) /* plane of fire */
     167                 :          0 :         monsterid = FIRE_ELEM;  /* fire elemental */
     168 [ #  # ][ #  # ]:          0 :       else if (random_range(2) && (Level->depth == 5)) /* deep astral */
     169   [ #  #  #  #  :          0 :         switch (random_range(12)) {
          #  #  #  #  #  
             #  #  #  # ]
     170                 :          0 :         case 0:monsterid = NIGHT_GAUNT; break;
     171                 :          0 :         case 1:monsterid = SERV_LAW; break; /* servant of law */
     172                 :          0 :         case 2:monsterid = SERV_CHAOS; break; /* servant of chaos */
     173                 :          0 :         case 3:monsterid = FROST_DEMON; break; /* lesser frost demon */
     174                 :          0 :         case 4:monsterid = OUTER_DEMON; break; /* outer circle demon */
     175                 :          0 :         case 5:monsterid = DEMON_SERP; break; /* demon serpent */
     176                 :          0 :         case 6:monsterid = ANGEL; break;
     177                 :          0 :         case 7:monsterid = INNER_DEMON; break; /* inner circle demon */
     178                 :          0 :         case 8:monsterid = FDEMON_L; break; /* frost demon lord */
     179                 :          0 :         case 9:monsterid = HIGH_ANGEL; break;
     180                 :          0 :         case 10:monsterid = DEMON_PRINCE; break; /* prime circle demon */
     181                 :          0 :         case 11:monsterid = ARCHANGEL; break;
     182                 :            :         }
     183                 :          0 :       else monsterid = RANDOM;
     184                 :          0 :       break;
     185                 :            :     case E_VOLCANO:
     186         [ #  # ]:          0 :       if (random_range(2)) {
     187                 :          0 :         do monsterid = random_range(ML10-ML4)+ML4;
     188         [ #  # ]:          0 :         while (Monsters[monsterid].uniqueness != COMMON);
     189                 :            :       }
     190   [ #  #  #  #  :          0 :       else switch(random_range(Level->depth/2+2)) { /* evil & fire creatures */
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
     191                 :          0 :       case 0: monsterid = HAUNT; break;
     192                 :          0 :       case 1: monsterid = INCUBUS; break;
     193                 :          0 :       case 2: monsterid = DRAGONETTE; break;
     194                 :          0 :       case 3: monsterid = FROST_DEMON; break;
     195                 :          0 :       case 4: monsterid = SPECTRE; break;
     196                 :          0 :       case 5: monsterid = LAVA_WORM; break;
     197                 :          0 :       case 6: monsterid = FIRE_ELEM; break;
     198                 :          0 :       case 7: monsterid = LICHE; break;
     199                 :          0 :       case 8: monsterid = RAKSHASA; break;
     200                 :          0 :       case 9: monsterid = DEMON_SERP; break;
     201                 :          0 :       case 10: monsterid = NAZGUL; break;
     202                 :          0 :       case 11: monsterid = FLAME_DEV; break;
     203                 :          0 :       case 12: monsterid = LOATHLY; break;
     204                 :          0 :       case 13: monsterid = ZOMBIE; break;
     205                 :          0 :       case 14: monsterid = INNER_DEMON; break;
     206                 :          0 :       case 15: monsterid = BAD_FAIRY; break; 
     207                 :          0 :       case 16: monsterid = DRAGON; break; 
     208                 :          0 :       case 17: monsterid = FDEMON_L; break; 
     209                 :          0 :       case 18: monsterid = SHADOW_SLAY; break; 
     210                 :          0 :       case 19: monsterid = DEATHSTAR; break; 
     211                 :          0 :       case 20: monsterid = VAMP_LORD; break; 
     212                 :          0 :       case 21: monsterid = DEMON_PRINCE; break; 
     213                 :          0 :       default: monsterid = RANDOM; break;
     214                 :            :       }
     215                 :          0 :       break;      
     216                 :            :     case E_CASTLE: 
     217         [ #  # ]:          0 :       if (random_range(4)==1) {
     218         [ #  # ]:          0 :         if (difficulty() < 5)
     219                 :          0 :           monsterid = ENCHANTOR;
     220         [ #  # ]:          0 :         else if (difficulty() < 6)
     221                 :          0 :           monsterid = NECROMANCER;
     222         [ #  # ]:          0 :         else if (difficulty() < 8)
     223                 :          0 :           monsterid = FIRE_ELEM;
     224                 :          0 :         else monsterid = THAUMATURGIST;
     225                 :            :       }
     226                 :          0 :       else monsterid = RANDOM;
     227                 :          0 :     break;
     228                 :            : 
     229                 :          0 :     default: monsterid = RANDOM; break;
     230                 :            :     }
     231                 :            :     
     232         [ #  # ]:          0 :     if (monsterid != RANDOM)
     233                 :          0 :       Level->site[i][j].creature = make_creature(monsterid);
     234                 :            :     else
     235                 :          0 :       Level->site[i][j].creature = m_create(i,j,TRUE,difficulty());
     236                 :            : 
     237                 :          0 :     Level->site[i][j].creature->x = i;
     238                 :          0 :     Level->site[i][j].creature->y = j;
     239                 :            :     
     240         [ #  # ]:          0 :     if (m_statusp(Level->site[i][j].creature,ONLYSWIM)) {
     241                 :          0 :       Level->site[i][j].locchar = WATER;
     242                 :          0 :       Level->site[i][j].p_locf = L_WATER;
     243                 :          0 :       lset(i, j, CHANGED);
     244                 :            :     }
     245                 :            :     
     246                 :          0 :     tml->next = ((pml) checkmalloc(sizeof(mltype)));
     247                 :          0 :     tml->next->m = Level->site[i][j].creature;
     248                 :          0 :     tml = tml->next;
     249                 :            :   }
     250                 :            :   
     251         [ #  # ]:          0 :   if (Level->mlist==NULL) {
     252                 :          0 :     tml->next = NULL;
     253                 :          0 :     Level->mlist = head->next;
     254                 :            :   }
     255                 :            :   else {
     256                 :          0 :     tml->next = Level->mlist;
     257                 :          0 :     Level->mlist = head->next;
     258                 :            :   }
     259                 :          0 : }
     260                 :            : 
     261                 :            : 
     262                 :            : 
     263                 :            : /* Add a wandering monster possibly */
     264                 :          0 : void wandercheck(void)
     265                 :            : {
     266                 :            :   int x,y;
     267                 :            :   pml tml;
     268         [ #  # ]:          0 :   if (random_range(MaxDungeonLevels) < difficulty()) {
     269                 :          0 :     findspace(&x,&y,-1);
     270                 :          0 :     tml = ((pml) checkmalloc(sizeof(mltype)));
     271                 :          0 :     tml->next = Level->mlist;
     272                 :          0 :     tml->m = Level->site[x][y].creature = m_create(x,y,WANDERING,difficulty());
     273                 :          0 :     Level->mlist = tml;    
     274                 :            :   }
     275                 :          0 : }
     276                 :            : 
     277                 :            : 
     278                 :            : 
     279                 :            : /* call make_creature and place created monster on Level->mlist and Level */
     280                 :          0 : void make_site_monster(int i, int j, int mid)
     281                 :            : {
     282                 :          0 :   pml ml = ((pml) checkmalloc(sizeof(mltype)));
     283                 :            :   pmt m;
     284         [ #  # ]:          0 :   if (mid > -1)  Level->site[i][j].creature = (m = make_creature(mid));
     285                 :          0 :   else Level->site[i][j].creature = (m = m_create(i,j,WANDERING,difficulty()));
     286                 :          0 :   m->x = i;
     287                 :          0 :   m->y = j;
     288                 :          0 :   ml->m = m;
     289                 :          0 :   ml->next = Level->mlist;
     290                 :          0 :   Level->mlist = ml;
     291                 :          0 : }
     292                 :            : 
     293                 :            : 
     294                 :            : /* make and return an appropriate monster for the level and depth*/
     295                 :            : /* called by populate_level, doesn't actually add to mlist for some reason*/
     296                 :            : /* eventually to be more intelligent */
     297                 :          0 : pmt m_create(int x, int y, int kind, int level)
     298                 :            : {
     299                 :            :   pmt newmonster;
     300                 :            :   int monster_range;
     301                 :            :   int mid;
     302                 :            : 
     303   [ #  #  #  #  :          0 :   switch(level) {
          #  #  #  #  #  
                   #  # ]
     304                 :          0 :     case 0:monster_range = ML1; break;
     305                 :          0 :     case 1:monster_range = ML2; break;
     306                 :          0 :     case 2:monster_range = ML3; break;
     307                 :          0 :     case 3:monster_range = ML4; break;
     308                 :          0 :     case 4:monster_range = ML5; break;
     309                 :          0 :     case 5:monster_range = ML6; break;
     310                 :          0 :     case 6:monster_range = ML7; break;
     311                 :          0 :     case 7:monster_range = ML8; break;
     312                 :          0 :     case 8:monster_range = ML9; break;
     313                 :          0 :     case 9:monster_range = ML10; break;
     314                 :          0 :     default:monster_range = NUMMONSTERS; break;
     315                 :            :   }
     316                 :            : 
     317                 :            :   do 
     318                 :          0 :     mid = random_range(monster_range);
     319         [ #  # ]:          0 :   while (Monsters[mid].uniqueness != COMMON); 
     320                 :          0 :   newmonster = make_creature(mid);
     321                 :            : 
     322                 :            :   /* no duplicates of unique monsters */
     323         [ #  # ]:          0 :   if (kind == WANDERING) m_status_set(newmonster,WANDERING);
     324                 :          0 :   newmonster->x = x;
     325                 :          0 :   newmonster->y = y;
     326                 :          0 :   return(newmonster);
     327                 :            : }
     328                 :            : 
     329                 :            : 
     330                 :            : 
     331                 :            : /* make creature # mid, totally random if mid == -1 */
     332                 :            : /* make creature allocates space for the creature */
     333                 :         19 : pmt make_creature(int mid)
     334                 :            : {
     335                 :         19 :   pmt newmonster = ((pmt) checkmalloc(sizeof(montype)));
     336                 :            :   pob ob;
     337                 :            :   int i,treasures;
     338                 :            : 
     339         [ +  + ]:         19 :   if (mid == -1) mid = random_range(ML9);
     340                 :         19 :   *newmonster = Monsters[mid];
     341 [ +  - ][ +  - ]:         19 :   if ((mid == ANGEL) || (mid == HIGH_ANGEL) || (mid == ARCHANGEL)) {
                 [ -  + ]
     342                 :            :     /* aux1 field of an angel is its deity */
     343         [ #  # ]:          0 :     if (Current_Environment == E_TEMPLE)
     344                 :          0 :       newmonster->aux1 = Country[LastCountryLocX][LastCountryLocY].aux;
     345                 :            :     else
     346                 :          0 :       newmonster->aux1 = random_range(6)+1;
     347                 :          0 :     newmonster->monstring = angeltype( mid, newmonster->aux1 );
     348                 :            :   }
     349 [ +  - ][ +  + ]:         19 :   else if (mid == ZERO_NPC || mid == WEREHUMAN) { 
     350                 :            :     /* generic 0th level human, or a were-human */
     351                 :          1 :     newmonster->corpsestr = mancorpse();
     352                 :            :     /* DAG use same (static data) string, after "dead " part */
     353                 :          1 :     newmonster->monstring = (newmonster->corpsestr)+5;
     354                 :            :   }
     355         [ -  + ]:         18 :   else if ((newmonster->monchar&0xff) == '!') {
     356                 :            :     /* the nymph/satyr and incubus/succubus */
     357 [ #  # ][ #  # ]:          0 :     if (Player.preference == 'f' ||
     358         [ #  # ]:          0 :         (Player.preference != 'm' && random_range(2))) {
     359                 :          0 :       newmonster->monchar = 'n'|CLR(RED);
     360                 :          0 :       newmonster->monstring = "nymph";
     361                 :          0 :       newmonster->corpsestr = "dead nymph";
     362                 :            :     }
     363                 :            :     else {
     364                 :          0 :       newmonster->monchar = 's'|CLR(RED);
     365                 :          0 :       newmonster->monstring = "satyr";
     366                 :          0 :       newmonster->corpsestr = "dead satyr";
     367                 :            :     }
     368         [ #  # ]:          0 :     if (newmonster->id == INCUBUS) {
     369         [ #  # ]:          0 :       if ((newmonster->monchar&0xff) == 'n')
     370                 :          0 :         newmonster->corpsestr = "dead succubus";
     371                 :          0 :       else newmonster->corpsestr = "dead incubus";
     372                 :            :     }
     373                 :            :   }
     374         [ -  + ]:         19 :   if (mid == NPC)
     375                 :          0 :     make_log_npc(newmonster);
     376         [ -  + ]:         19 :   else if (mid == HISCORE_NPC)
     377                 :          0 :     make_hiscore_npc(newmonster, random_range(16)); /* Number of Hiscorers! PGM */
     378                 :            :   else {
     379         [ +  + ]:         19 :     if (newmonster->sleep < random_range(100))
     380                 :         11 :       m_status_set(newmonster,AWAKE);
     381 [ +  + ][ +  - ]:         19 :     if (newmonster->startthing > -1 &&
     382                 :          8 :       Objects[newmonster->startthing].uniqueness <= UNIQUE_MADE) {
     383                 :          8 :       ob = ((pob) checkmalloc(sizeof(objtype)));    
     384                 :          8 :       *ob = Objects[newmonster->startthing];
     385                 :          8 :       m_pickup(newmonster,ob);
     386                 :            :     }
     387                 :            :     /* DAG -- monster with treasure of 1 would be same as 0, shouldn't be. */
     388                 :         19 :     treasures = random_range(newmonster->treasure +1);
     389         [ +  + ]:         29 :     for(i=0;i<treasures;i++) {
     390                 :            :       do {
     391                 :         10 :         ob = (pob) (create_object(newmonster->level));
     392         [ -  + ]:         10 :         if (ob->uniqueness != COMMON) {
     393                 :          0 :           Objects[ob->id].uniqueness = UNIQUE_UNMADE;
     394                 :          0 :           free_obj(ob, TRUE);
     395                 :          0 :           ob = NULL;
     396                 :            :         }
     397         [ -  + ]:         10 :       } while (!ob);
     398                 :         10 :       m_pickup(newmonster,ob);
     399                 :            :     }
     400                 :            :   }
     401                 :         19 :   newmonster->click = (Tick + 1) % 50;
     402                 :         19 :   return(newmonster);
     403                 :            : }
     404                 :            : 
     405                 :            : 
     406                 :            : /* drop treasures randomly onto level */
     407                 :          0 : void stock_level(void)
     408                 :            : {
     409                 :          0 :   int i,j,k,numtreasures=2*random_range(difficulty()/4)+4;
     410                 :            : 
     411                 :            :   /* put cash anywhere, including walls, put other treasures only on floor */
     412         [ #  # ]:          0 :   for (k=0;k<numtreasures+10;k++) {
     413                 :            :     do {
     414                 :          0 :       i = random_range(Level->level_width);
     415                 :          0 :       j = random_range(Level->level_length);
     416         [ #  # ]:          0 :     } while (Level->site[i][j].locchar != FLOOR);
     417                 :          0 :     make_site_treasure(i,j,difficulty());
     418                 :          0 :     i = random_range(Level->level_width);
     419                 :          0 :     j = random_range(Level->level_length);
     420                 :          0 :     Level->site[i][j].things = ((pol) checkmalloc(sizeof(oltype)));
     421                 :          0 :     Level->site[i][j].things->thing = ((pob) checkmalloc(sizeof(objtype)));
     422                 :          0 :     make_cash(Level->site[i][j].things->thing,difficulty());
     423                 :          0 :     Level->site[i][j].things->next = NULL;
     424                 :            :     /* caves have more random cash strewn around */
     425         [ #  # ]:          0 :     if (Current_Dungeon == E_CAVES) {
     426                 :          0 :       i = random_range(Level->level_width);
     427                 :          0 :       j = random_range(Level->level_length);
     428                 :          0 :       Level->site[i][j].things = ((pol) checkmalloc(sizeof(oltype)));
     429                 :          0 :       Level->site[i][j].things->thing = ((pob) checkmalloc(sizeof(objtype)));
     430                 :          0 :       make_cash(Level->site[i][j].things->thing,difficulty());
     431                 :          0 :       Level->site[i][j].things->next = NULL;
     432                 :          0 :       i = random_range(Level->level_width);
     433                 :          0 :       j = random_range(Level->level_length);
     434                 :          0 :       Level->site[i][j].things = ((pol) checkmalloc(sizeof(oltype)));
     435                 :          0 :       Level->site[i][j].things->thing = ((pob) checkmalloc(sizeof(objtype)));
     436                 :          0 :       make_cash(Level->site[i][j].things->thing,difficulty());
     437                 :          0 :       Level->site[i][j].things->next = NULL;
     438                 :            :     }
     439                 :            :   }
     440                 :          0 : }
     441                 :            : 
     442                 :            : 
     443                 :            : /* make a new object (of at most level itemlevel) at site i,j on level*/
     444                 :          0 : void make_site_treasure(int i, int j, int itemlevel)
     445                 :            : {
     446                 :          0 :   pol tmp = ((pol) checkmalloc(sizeof(oltype)));
     447                 :          0 :   tmp->thing = ((pob) create_object(itemlevel));
     448                 :          0 :   tmp->next = Level->site[i][j].things;
     449                 :          0 :   Level->site[i][j].things = tmp;
     450                 :          0 : }
     451                 :            : 
     452                 :            : /* make a specific new object at site i,j on level*/
     453                 :          0 : void make_specific_treasure(int i, int j, int itemid)
     454                 :            : {
     455                 :            :   pol tmp;
     456         [ #  # ]:          0 :   if (Objects[itemid].uniqueness == UNIQUE_TAKEN)
     457                 :          0 :     return;
     458                 :          0 :   tmp = ((pol) checkmalloc(sizeof(oltype)));
     459                 :          0 :   tmp->thing = ((pob) checkmalloc(sizeof(objtype)));
     460                 :          0 :   *(tmp->thing) = Objects[itemid];
     461                 :          0 :   tmp->next = Level->site[i][j].things;
     462                 :          0 :   Level->site[i][j].things = tmp;
     463                 :            : }
     464                 :            : 
     465                 :            : 
     466                 :            : 
     467                 :            : #ifndef MSDOS_SUPPORTED_ANTIQUE
     468                 :            : /* returns a "level of difficulty" based on current environment
     469                 :            :    and depth in dungeon. Is somewhat arbitrary. value between 1 and 10.
     470                 :            :    May not actually represent real difficulty, but instead level
     471                 :            :    of items, monsters encountered.    */
     472                 :      49158 : int difficulty(void)
     473                 :            : {
     474                 :      49158 :   int depth = 1;
     475         [ +  - ]:      49158 :   if (Level != NULL) depth = Level->depth;
     476   [ -  +  +  +  :      49158 :   switch(Current_Environment) {
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
                   -  - ]
     477                 :          0 :   case E_COUNTRYSIDE: return(7);
     478                 :       8192 :   case E_CITY: return(3);
     479                 :      24577 :   case E_VILLAGE: return(1);
     480                 :      16389 :   case E_TACTICAL_MAP: return(7);
     481                 :          0 :   case E_SEWERS: return(depth/6)+3;
     482                 :          0 :   case E_CASTLE: return(depth/4)+4;
     483                 :          0 :   case E_CAVES: return(depth/3)+1;
     484                 :          0 :   case E_VOLCANO: return(depth/4)+5;
     485                 :          0 :   case E_ASTRAL: return(8);
     486                 :          0 :   case E_ARENA: return(5);
     487                 :          0 :   case E_HOVEL: return(3);
     488                 :          0 :   case E_MANSION: return(7);
     489                 :          0 :   case E_HOUSE: return(5);
     490                 :          0 :   case E_DLAIR: return(9);
     491                 :          0 :   case E_ABYSS: return(10);
     492                 :          0 :   case E_STARPEAK: return(9);
     493                 :          0 :   case E_CIRCLE: return(8);
     494                 :          0 :   case E_MAGIC_ISLE: return(8);
     495                 :          0 :   case E_TEMPLE: return(8);
     496                 :            : 
     497                 :            :   case E_PALACE:  /* varies by phase of moon */
     498                 :            :     {
     499                 :          0 :       int diff = 0;
     500   [ #  #  #  #  :          0 :       switch(Phase/2) {
             #  #  #  # ]
     501                 :          0 :       case 0: diff = 0; break;
     502                 :          0 :       case 1: case 11: diff = 1; break;
     503                 :          0 :       case 2: case 10: diff = 2; break;
     504                 :          0 :       case 3: case 9:  diff = 3; break;
     505                 :          0 :       case 4: case 8:  diff = 5; break;
     506                 :          0 :       case 5: case 7:  diff = 6; break;
     507                 :          0 :       case 6: diff = 7; break;
     508                 :            :       }
     509                 :          0 :       return( min( ((depth+diff)/3)+4,9));
     510                 :            :     }
     511                 :          0 :   default: return(3);
     512                 :            :   }
     513                 :            : }
     514                 :            : #endif

Generated by: LCOV version 1.11