Fixes for datatype size on amd64.
[crack-attack.git] / src / LoseBar.cxx
blob9846e505906e8fb8534a7c6ce9c3146bdf8fe51b
1 /*
2 * LoseBar.cxx
3 * Daniel Nelson - 3/1/2
5 * Copyright (C) 2002 Daniel Nelson
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Daniel Nelson - aluminumangel.org
22 * 174 W. 18th Ave.
23 * Columbus, OH 43210
25 * Handles the losebar.
28 #include "LoseBar.h"
30 #include <GL/glut.h>
32 #include "glext.h"
34 #include "Game.h"
35 #include "Creep.h"
36 #include "Displayer.h"
38 GLfloat LoseBar::bar;
39 int LoseBar::fade_timer;
40 int LoseBar::state;
42 void LoseBar::initialize ( )
44 bar = 0.0f;
45 fade_timer = 0;
46 state = LB_INACTIVE;
50 void LoseBar::gameStart ( )
52 // at the start of the game, fade to inactive
53 if (state == LB_LOW_ALERT)
54 enterLowToInactiveFade();
55 else if (state == LB_HIGH_ALERT)
56 enterHighToInactiveFade();
59 void LoseBar::timeStep ( )
61 // update state
63 // if we're not on alert
64 if (state
65 & (LB_INACTIVE | LB_FADE_LOW_TO_INACTIVE | LB_FADE_HIGH_TO_INACTIVE)) {
67 // if we're done fading
68 if (state & (LB_FADE_LOW_TO_INACTIVE | LB_FADE_HIGH_TO_INACTIVE)
69 && --fade_timer == 0)
70 state = LB_INACTIVE;
72 // if we should be on alert
73 if (Creep::creep_freeze) {
74 // no check for high alert is needed
75 state = LB_LOW_ALERT;
76 fade_timer = 0;
79 // if we are on low alert
80 } else if (state == LB_LOW_ALERT) {
82 // if we no longer should be on alert
83 if (!Creep::creep_freeze)
84 enterLowToInactiveFade();
86 // if we should enter high alert
87 else if (Creep::loss_alarm <= GC_LOSS_DELAY_ELIMINATION)
88 state = LB_HIGH_ALERT;
90 // if we are on high alert
91 } else if (state == LB_HIGH_ALERT) {
93 // if we no longer should be on alert
94 if (!Creep::creep_freeze)
95 enterHighToInactiveFade();
97 // if we are fading because of a high alert reset
98 } else if (state == LB_FADE_RESET_HIGH) {
99 if (--fade_timer == 0)
100 state = LB_HIGH_ALERT;
103 // calculate the bar value
105 if (state & (LB_LOW_ALERT | LB_HIGH_ALERT))
106 if (state & LB_LOW_ALERT)
107 bar = (GC_LOSS_DELAY - Creep::loss_alarm)
108 * (1.0f / (GLfloat) (GC_LOSS_DELAY - GC_LOSS_DELAY_ELIMINATION));
109 else
110 bar = (GC_LOSS_DELAY_ELIMINATION - Creep::loss_alarm)
111 * (1.0f / (GLfloat) GC_LOSS_DELAY_ELIMINATION);