LCOV - code coverage report
Current view: top level - omega-rpg-0.90-pa9 - time.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 37 51 72.5 %
Date: 2017-08-31 19:31:11 Functions: 1 2 50.0 %
Branches: 29 40 72.5 %

           Branch data     Line data    Source code
       1                 :            : /* omega copyright (c) 1987,1988,1989 by Laurence Raphael Brothers */
       2                 :            : /* time.c */
       3                 :            : 
       4                 :            : /* this file deals with the passage of time in omega */
       5                 :            : 
       6                 :            : #include "glob.h"
       7                 :            : 
       8                 :            : /* This function coordinates monsters and player actions, as well as
       9                 :            : random events. Each tick is a second. There are therefore 60 ticks to
      10                 :            : the minute and 60 minutes to the hour.
      11                 :            : */
      12                 :            : 
      13                 :       3824 : void time_clock(int reset)
      14                 :            : {
      15                 :            :   int env;
      16                 :            :   pml ml, *prev;
      17                 :            : 
      18                 :       3824 :   ++Tick;
      19                 :            : 
      20         [ +  + ]:       3824 :   if (Tick > 60)
      21                 :            :     {
      22                 :         62 :       Tick = 0;
      23                 :         62 :       minute_status_check(); /* see about some player statuses each minute */
      24                 :            : 
      25                 :         62 :       ++Time;
      26         [ +  + ]:         62 :       if (0 == (Time % 10)) tenminute_check();
      27                 :            :     }
      28                 :            : 
      29         [ +  + ]:       3824 :   if (reset) Tick = (Player.click = 0);
      30                 :            : 
      31                 :       3824 :   env = Current_Environment;
      32 [ +  + ][ +  - ]:       4816 :   while ((Tick == Player.click) && (Current_Environment != E_COUNTRYSIDE) &&
                 [ +  - ]
      33                 :        997 :     Current_Environment == env) {
      34         [ +  - ]:        997 :     if (! gamestatusp(SKIP_PLAYER))
      35                 :            :       do {
      36                 :       1182 :         resetgamestatus(SKIP_MONSTERS);
      37 [ +  - ][ +  - ]:       1182 :         if ((! Player.status[SLEPT])  && 
      38                 :       1182 :             (Current_Environment != E_COUNTRYSIDE)) p_process(); 
      39         [ +  - ]:        185 :       } while (gamestatusp(SKIP_MONSTERS) && 
      40         [ +  + ]:       1177 :                (Current_Environment != E_COUNTRYSIDE));
      41                 :          0 :     else resetgamestatus(SKIP_PLAYER);
      42                 :        992 :     Player.click = (Player.click + Command_Duration) % 60;
      43                 :            :   }
      44                 :            : 
      45                 :            :   /* klugy but what the heck. w/o this line, if the player caused
      46                 :            :   a change-environment to the country, the monsters on the old Level
      47                 :            :   will still act, causing all kinds of anomalies and core dumps,
      48                 :            :   intermittently. However, any other environment change will reset
      49                 :            :   Level appropriately, so only have to check for countryside */
      50                 :            : 
      51         [ +  + ]:       3819 :   if (Current_Environment != E_COUNTRYSIDE) {
      52                 :            : 
      53                 :       3809 :     prev = &(Level->mlist);
      54                 :       3809 :     ml = *prev;
      55         [ +  + ]:      55228 :     while (ml)
      56         [ +  + ]:      51419 :       if (ml->m->hp > 0) {
      57                 :            :         /* following is a hack until I discover source of phantom monsters */
      58         [ -  + ]:      51413 :         if (Level->site[ml->m->x][ml->m->y].creature != ml->m)
      59                 :          0 :           fix_phantom(ml->m); 
      60         [ +  + ]:      51413 :         if (Tick == ml->m->click) {
      61                 :      14013 :           ml->m->click += ml->m->speed;
      62         [ +  + ]:      14853 :           while (ml->m->click > 60) ml->m->click -= 60;
      63                 :      14013 :           m_pulse(ml->m);
      64                 :            :         }
      65                 :      51413 :         prev = &(ml->next);
      66                 :      51413 :         ml = ml->next;
      67                 :            :       }
      68         [ +  - ]:          6 :       else if (ml->m != Arena_Monster) {
      69                 :          6 :         *prev = ml->next;
      70                 :            :         /* DAG free the monstring & corpsestr if allocated */
      71         [ -  + ]:          6 :         if ( m_statusp( ml->m, ALLOC ) )
      72                 :            :         {
      73                 :          0 :           free( ml->m->monstring );
      74                 :          0 :           free( ml->m->corpsestr );
      75                 :            :         }
      76                 :          6 :         free((char *) ml->m);
      77                 :          6 :         free((char *) ml);
      78                 :          6 :         ml = *prev;
      79                 :            :       }
      80                 :            :       else
      81                 :          0 :         ml = ml->next;
      82                 :            :   }
      83                 :       3819 : }
      84                 :            : 
      85                 :            : 
      86                 :            : /* remedies occasional defective monsters */
      87                 :          0 : void fix_phantom(pmt m)
      88                 :            : {
      89         [ #  # ]:          0 :   if (Level->site[m->x][m->y].creature == NULL) {
      90                 :          0 :     mprint("You hear a sound like a sigh of relief....");
      91                 :          0 :     Level->site[m->x][m->y].creature = m;
      92                 :            :   }
      93                 :            :   else {
      94                 :          0 :     mprint("You hear a puff of displaced air....");
      95                 :          0 :     findspace(&(m->x),&(m->y),-1);
      96                 :          0 :     Level->site[m->x][m->y].creature = m;
      97                 :          0 :     m_death(m);
      98                 :            : 
      99                 :            :  /* PGM: shouldn't this be 
     100                 :            :   * m_remove? m_death causes an experience gain.*/
     101                 :            : 
     102                 :            :   }
     103                 :          0 : }

Generated by: LCOV version 1.11