3 * Daniel Nelson - 10/13/0
5 * Copyright (C) 2000 Daniel Nelson
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
25 * Handles the level lights' states.
28 #include "LevelLights.h"
32 #include "Communicator.h"
33 #include "MetaState.h"
34 #include "ComputerPlayer.h"
36 int LevelLights::death_flash_alarm
[2];
37 LevelLight
LevelLights::lights
[2][LL_NUMBER_LEVEL_LIGHTS
];
39 void LevelLights::initialize ( )
41 for (int n
= 0; n
< LL_NUMBER_LEVEL_LIGHTS
; n
++) {
42 lights
[LL_LOCAL_LIGHTS
][n
].state
= LS_BLUE
;
43 lights
[LL_OPPONENT_LIGHTS
][n
].state
= LS_BLUE
;
46 death_flash_alarm
[LL_LOCAL_LIGHTS
] = -1;
47 death_flash_alarm
[LL_OPPONENT_LIGHTS
] = -1;
50 void LevelLights::gameStart ( )
53 for (n
= 0; n
< Grid::top_effective_row
; n
++) {
54 setRed(lights
[LL_LOCAL_LIGHTS
][n
]);
55 setRed(lights
[LL_OPPONENT_LIGHTS
][n
]);
57 for ( ; n
< LL_NUMBER_LEVEL_LIGHTS
; n
++) {
58 setBlue(lights
[LL_LOCAL_LIGHTS
][n
]);
59 setBlue(lights
[LL_OPPONENT_LIGHTS
][n
]);
63 void LevelLights::timeStep ( )
65 // loop through the level light sets
66 for (int set
= 2; set
--; ) {
68 // loop through the set's level lights
69 for (int n
= LL_NUMBER_LEVEL_LIGHTS
; n
--; ) {
70 LevelLight
&light
= lights
[set
][n
];
72 // see if we're finished fading
73 if (light
.state
& (LS_FADE_TO_RED
| LS_FADE_TO_BLUE
))
74 if (!light
.fade_alarm
--) {
75 light
.state
|= ((light
.state
& LS_FADE_TO_RED
) ? LS_RED
: LS_BLUE
);
76 light
.state
&= ~(LS_FADE_TO_RED
| LS_FADE_TO_BLUE
);
79 // see if we're finished impact flashing
80 if (light
.state
& LS_IMPACT_FLASH
)
81 if (!light
.flash_alarm
--)
82 light
.state
&= ~LS_IMPACT_FLASH
;
86 // if we're death flashing and done with a flash and should continue
87 if (death_flash_alarm
[LL_LOCAL_LIGHTS
] != -1
88 && !death_flash_alarm
[LL_LOCAL_LIGHTS
]--
89 && (MetaState::state
& MS_GAME_PLAY
)
90 && Grid::checkSafeHeightViolation())
91 death_flash_alarm
[LL_LOCAL_LIGHTS
] = DC_LEVEL_LIGHT_DEATH_FLASH_TIME
;
93 // if we're death flashing and done with a flash and should continue
94 if (death_flash_alarm
[LL_OPPONENT_LIGHTS
] != -1
95 && !death_flash_alarm
[LL_OPPONENT_LIGHTS
]--
96 && (MetaState::state
& MS_GAME_PLAY
)
97 && Communicator::checkLevelLightRecvBit(LC_DEATH_FLASH_MASK
))
98 death_flash_alarm
[LL_OPPONENT_LIGHTS
] = DC_LEVEL_LIGHT_DEATH_FLASH_TIME
;
101 void LevelLights::handleAI ()
103 if (ComputerPlayer::checkLevelLightDying() && death_flash_alarm
[LL_OPPONENT_LIGHTS
] == -1)
104 death_flash_alarm
[LL_OPPONENT_LIGHTS
] = DC_LEVEL_LIGHT_DEATH_FLASH_TIME
;
105 for (int n
= LL_NUMBER_LEVEL_LIGHTS
; n
--; ) {
106 if (lights
[LL_OPPONENT_LIGHTS
][n
].state
& (LS_RED
| LS_FADE_TO_RED
)) {
107 if (ComputerPlayer::checkLevelLightBlue(n
))
108 setBlue(lights
[LL_OPPONENT_LIGHTS
][n
]);
110 if (!ComputerPlayer::checkLevelLightBlue(n
))
111 setRed(lights
[LL_OPPONENT_LIGHTS
][n
]);
113 if (ComputerPlayer::impact()) {
114 setFlashing(lights
[LL_OPPONENT_LIGHTS
][ComputerPlayer::levelLightImpact()]);