Grays kill AI faster.
[crack-attack.git] / src / LoseBar.cxx
blob4926695b8248ecab67e1a52f5a33e9be6258db3f
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 <GL/glut.h>
29 #include <cassert>
31 #ifndef _WIN32
32 #else
33 # include <glext.h>
34 #endif
36 using namespace std;
38 #include "Game.h"
39 #include "Creep.h"
40 #include "Displayer.h"
41 #include "LoseBar.h"
43 GLfloat LoseBar::bar;
44 int LoseBar::fade_timer;
45 int LoseBar::state;
47 void LoseBar::initialize ( )
49 bar = 0.0f;
50 fade_timer = 0;
51 state = LB_INACTIVE;
55 void LoseBar::gameStart ( )
57 // at the start of the game, fade to inactive
58 if (state == LB_LOW_ALERT)
59 enterLowToInactiveFade();
60 else if (state == LB_HIGH_ALERT)
61 enterHighToInactiveFade();
64 void LoseBar::timeStep ( )
66 // update state
68 // if we're not on alert
69 if (state
70 & (LB_INACTIVE | LB_FADE_LOW_TO_INACTIVE | LB_FADE_HIGH_TO_INACTIVE)) {
72 // if we're done fading
73 if (state & (LB_FADE_LOW_TO_INACTIVE | LB_FADE_HIGH_TO_INACTIVE)
74 && --fade_timer == 0)
75 state = LB_INACTIVE;
77 // if we should be on alert
78 if (Creep::creep_freeze) {
79 // no check for high alert is needed
80 state = LB_LOW_ALERT;
81 fade_timer = 0;
84 // if we are on low alert
85 } else if (state == LB_LOW_ALERT) {
87 // if we no longer should be on alert
88 if (!Creep::creep_freeze)
89 enterLowToInactiveFade();
91 // if we should enter high alert
92 else if (Creep::loss_alarm <= GC_LOSS_DELAY_ELIMINATION)
93 state = LB_HIGH_ALERT;
95 // if we are on high alert
96 } else if (state == LB_HIGH_ALERT) {
98 // if we no longer should be on alert
99 if (!Creep::creep_freeze)
100 enterHighToInactiveFade();
102 // if we are fading because of a high alert reset
103 } else if (state == LB_FADE_RESET_HIGH) {
104 if (--fade_timer == 0)
105 state = LB_HIGH_ALERT;
108 // calculate the bar value
110 if (state & (LB_LOW_ALERT | LB_HIGH_ALERT))
111 if (state & LB_LOW_ALERT)
112 bar = (GC_LOSS_DELAY - Creep::loss_alarm)
113 * (1.0f / (GLfloat) (GC_LOSS_DELAY - GC_LOSS_DELAY_ELIMINATION));
114 else
115 bar = (GC_LOSS_DELAY_ELIMINATION - Creep::loss_alarm)
116 * (1.0f / (GLfloat) GC_LOSS_DELAY_ELIMINATION);