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-08 22:00:26 Functions: 1 2 50.0 %
Branches: 28 40 70.0 %

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