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-09-18 20:02:26 Functions: 1 2 50.0 %
Branches: 27 40 67.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                 :        128 : void time_clock(int reset)
      14                 :            : {
      15                 :            :   int env;
      16                 :            :   pml ml, *prev;
      17                 :            : 
      18                 :        128 :   ++Tick;
      19                 :            : 
      20         [ +  + ]:        128 :   if (Tick > 60)
      21                 :            :     {
      22                 :          2 :       Tick = 0;
      23                 :          2 :       minute_status_check(); /* see about some player statuses each minute */
      24                 :            : 
      25                 :          2 :       ++Time;
      26         [ -  + ]:          2 :       if (0 == (Time % 10)) tenminute_check();
      27                 :            :     }
      28                 :            : 
      29         [ -  + ]:        128 :   if (reset) Tick = (Player.click = 0);
      30                 :            : 
      31                 :        128 :   env = Current_Environment;
      32 [ +  + ][ +  - ]:        153 :   while ((Tick == Player.click) && (Current_Environment != E_COUNTRYSIDE) &&
                 [ +  - ]
      33                 :         25 :     Current_Environment == env) {
      34         [ +  - ]:         25 :     if (! gamestatusp(SKIP_PLAYER))
      35                 :            :       do {
      36                 :         30 :         resetgamestatus(SKIP_MONSTERS);
      37 [ +  - ][ +  - ]:         30 :         if ((! Player.status[SLEPT])  && 
      38                 :         30 :             (Current_Environment != E_COUNTRYSIDE)) p_process(); 
      39         [ +  - ]:          5 :       } while (gamestatusp(SKIP_MONSTERS) && 
      40         [ +  + ]:         30 :                (Current_Environment != E_COUNTRYSIDE));
      41                 :          0 :     else resetgamestatus(SKIP_PLAYER);
      42                 :         25 :     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         [ +  + ]:        128 :   if (Current_Environment != E_COUNTRYSIDE) {
      52                 :            : 
      53                 :        127 :     prev = &(Level->mlist);
      54                 :        127 :     ml = *prev;
      55         [ +  + ]:       1739 :     while (ml)
      56         [ +  + ]:       1613 :       if (ml->m->hp > 0) {
      57                 :            :         /* following is a hack until I discover source of phantom monsters */
      58         [ -  + ]:       1611 :         if (Level->site[ml->m->x][ml->m->y].creature != ml->m)
      59                 :          0 :           fix_phantom(ml->m); 
      60         [ +  + ]:       1611 :         if (Tick == ml->m->click) {
      61                 :        322 :           ml->m->click += ml->m->speed;
      62         [ +  + ]:        334 :           while (ml->m->click > 60) ml->m->click -= 60;
      63                 :        322 :           m_pulse(ml->m);
      64                 :            :         }
      65                 :       1610 :         prev = &(ml->next);
      66                 :       1610 :         ml = ml->next;
      67                 :            :       }
      68         [ +  - ]:          2 :       else if (ml->m != Arena_Monster) {
      69                 :          2 :         *prev = ml->next;
      70                 :            :         /* DAG free the monstring & corpsestr if allocated */
      71         [ -  + ]:          2 :         if ( m_statusp( ml->m, ALLOC ) )
      72                 :            :         {
      73                 :          0 :           free( ml->m->monstring );
      74                 :          0 :           free( ml->m->corpsestr );
      75                 :            :         }
      76                 :          2 :         free((char *) ml->m);
      77                 :          2 :         free((char *) ml);
      78                 :          2 :         ml = *prev;
      79                 :            :       }
      80                 :            :       else
      81                 :          0 :         ml = ml->next;
      82                 :            :   }
      83                 :        127 : }
      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