Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

src/timer.c

Go to the documentation of this file.
00001 /* {{{
00002  * CalcRogue, a roguelike game for PCs, calculators and PDAs
00003  * Copyright (C) 2003 Jim Babcock
00004  * 
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  * }}} */
00019 // timer.c
00022 
00023 #include "crogue.h"
00024 
00025 //{{{
00026 void init_timers(void)
00027 {
00028     int i;
00029     for(i=0; i<NUM_STATMOD_TIMERS; i++)
00030         w->plr.stat_timers[i].desc = NULL;
00031 }
00032 //}}}
00033 //{{{
00034 void apply_timers(void)
00035 {
00036     int i;
00037     for(i=0; i<NUM_STATMOD_TIMERS; i++)
00038         if(w->plr.stat_timers[i].desc)
00039         {
00040             switch(w->plr.stat_timers[i].type)
00041             {
00042                 case TIMER_STAT:
00043                     apply_stat_mod_desc(NULL, &w->plr.stat_timers[i].desc->stat.effect, 0);
00044                     break;
00045                 case TIMER_FUNC:
00046                     if(w->plr.stat_timers[i].desc->func.apply)
00047                         w->plr.stat_timers[i].desc->func.apply();
00048                     break;
00049             }
00050         }
00051 }
00052 //}}}
00053 //{{{
00054 int remove_expired_timers(void)
00055 {
00056     int ret=0, i;
00057     for(i=0; i<NUM_STATMOD_TIMERS; i++)
00058         if(w->plr.stat_timers[i].expiry < w->time && w->plr.stat_timers[i].desc)
00059         {
00060             switch(w->plr.stat_timers[i].type)
00061             {
00062                 case TIMER_STAT:
00063                     if(w->plr.stat_timers[i].desc->stat.expire_message)
00064                         message(w->plr.stat_timers[i].desc->stat.expire_message);
00065                     break;
00066                 case TIMER_FUNC:
00067                     if(w->plr.stat_timers[i].desc->func.expire)
00068                         w->plr.stat_timers[i].desc->func.expire();
00069                     break;
00070             }
00071             w->plr.stat_timers[i].desc = NULL;
00072             ret=1;
00073         }
00074     return ret;
00075 }
00076 //}}}
00077 //{{{
00078 void add_timer(const timer_desc *desc, uint duration)
00079 {
00080     int i;
00081     
00082     for(i=0; i<NUM_STATMOD_TIMERS; i++)
00083     {
00084         if(w->plr.stat_timers[i].desc == desc)
00085         {
00086             if(w->plr.stat_timers[i].expiry < duration+w->time)
00087                 w->plr.stat_timers[i].expiry = duration+w->time;
00088             goto timer_done;
00089         }
00090     }
00091     for(i=0; i<NUM_STATMOD_TIMERS; i++)
00092     {
00093         if(w->plr.stat_timers[i].desc == NULL)
00094         {
00095             w->plr.stat_timers[i].type = desc->stat.type;
00096             w->plr.stat_timers[i].desc = desc;
00097             w->plr.stat_timers[i].expiry = duration+w->time;
00098             goto timer_done;
00099         }
00100     }
00101 timer_done:
00102     update_player();
00103 }
00104 //}}}
00105 

Generated on Thu May 20 13:12:11 2004 for CalcRogue by doxygen 1.3.6