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 
time_clock(reset)13 void time_clock(reset)
14 int reset;
15 {
16   int env;
17   pml ml, *prev;
18 
19   if (++Tick > 60) {
20     Tick = 0;
21     minute_status_check(); /* see about some player statuses each minute */
22     if (++Time % 10 == 0) tenminute_check();
23   }
24 
25   if (reset) Tick = (Player.click = 0);
26 
27   env = Current_Environment;
28   while ((Tick == Player.click) && (Current_Environment != E_COUNTRYSIDE) &&
29     Current_Environment == env) {
30     if (! gamestatusp(SKIP_PLAYER))
31       do {
32 	resetgamestatus(SKIP_MONSTERS);
33 	if ((! Player.status[SLEPT])  &&
34 	    (Current_Environment != E_COUNTRYSIDE)) p_process();
35       } while (gamestatusp(SKIP_MONSTERS) &&
36 	       (Current_Environment != E_COUNTRYSIDE));
37     else resetgamestatus(SKIP_PLAYER);
38     Player.click = (Player.click + Command_Duration) % 60;
39   }
40 
41   /* klugy but what the heck. w/o this line, if the player caused
42   a change-environment to the country, the monsters on the old Level
43   will still act, causing all kinds of anomalies and core dumps,
44   intermittently. However, any other environment change will reset
45   Level appropriately, so only have to check for countryside */
46 
47   if (Current_Environment != E_COUNTRYSIDE) {
48 
49     prev = &(Level->mlist);
50     ml = *prev;
51     while (ml)
52       if (ml->m->hp > 0) {
53 	/* following is a hack until I discover source of phantom monsters */
54 	if (Level->site[ml->m->x][ml->m->y].creature != ml->m)
55 	  fix_phantom(ml->m);
56 	if (Tick == ml->m->click) {
57 	  ml->m->click += ml->m->speed;
58 	  while (ml->m->click > 60) ml->m->click -= 60;
59 	  m_pulse(ml->m);
60 	}
61 	prev = &(ml->next);
62 	ml = ml->next;
63       }
64       else if (ml->m != Arena_Monster) {
65 	*prev = ml->next;
66 	free((char *) ml->m);
67 	free((char *) ml);
68 	ml = *prev;
69       }
70       else
71 	ml = ml->next;
72   }
73 }
74 
75 
76 
77 
78 
79 /* remedies occasional defective monsters */
fix_phantom(m)80 void fix_phantom(m)
81 struct monster *m;
82 {
83   if (Level->site[m->x][m->y].creature == NULL) {
84     mprint("You hear a sound like a sigh of relief....");
85     Level->site[m->x][m->y].creature = m;
86   }
87   else {
88     mprint("You hear a puff of displaced air....");
89     findspace(&(m->x),&(m->y),-1);
90     Level->site[m->x][m->y].creature = m;
91     m_death(m);
92   }
93 }
94