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.
31 #include "LevelLights.h"
33 #include "Communicator.h"
34 #include "MetaState.h"
35 #include "ComputerPlayer.h"
37 int LevelLights::death_flash_alarm
[2];
38 LevelLight
LevelLights::lights
[2][LL_NUMBER_LEVEL_LIGHTS
];
40 void LevelLights::initialize ( )
42 for (int n
= 0; n
< LL_NUMBER_LEVEL_LIGHTS
; n
++) {
43 lights
[LL_LOCAL_LIGHTS
][n
].state
= LS_BLUE
;
44 lights
[LL_OPPONENT_LIGHTS
][n
].state
= LS_BLUE
;
47 death_flash_alarm
[LL_LOCAL_LIGHTS
] = -1;
48 death_flash_alarm
[LL_OPPONENT_LIGHTS
] = -1;
51 void LevelLights::gameStart ( )
54 for (n
= 0; n
< Grid::top_effective_row
; n
++) {
55 setRed(lights
[LL_LOCAL_LIGHTS
][n
]);
56 setRed(lights
[LL_OPPONENT_LIGHTS
][n
]);
58 for ( ; n
< LL_NUMBER_LEVEL_LIGHTS
; n
++) {
59 setBlue(lights
[LL_LOCAL_LIGHTS
][n
]);
60 setBlue(lights
[LL_OPPONENT_LIGHTS
][n
]);
64 void LevelLights::timeStep ( )
66 // loop through the level light sets
67 for (int set
= 2; set
--; ) {
69 // loop through the set's level lights
70 for (int n
= LL_NUMBER_LEVEL_LIGHTS
; n
--; ) {
71 LevelLight
&light
= lights
[set
][n
];
73 // see if we're finished fading
74 if (light
.state
& (LS_FADE_TO_RED
| LS_FADE_TO_BLUE
))
75 if (!light
.fade_alarm
--) {
76 light
.state
|= ((light
.state
& LS_FADE_TO_RED
) ? LS_RED
: LS_BLUE
);
77 light
.state
&= ~(LS_FADE_TO_RED
| LS_FADE_TO_BLUE
);
80 // see if we're finished impact flashing
81 if (light
.state
& LS_IMPACT_FLASH
)
82 if (!light
.flash_alarm
--)
83 light
.state
&= ~LS_IMPACT_FLASH
;
87 // if we're death flashing and done with a flash and should continue
88 if (death_flash_alarm
[LL_LOCAL_LIGHTS
] != -1
89 && !death_flash_alarm
[LL_LOCAL_LIGHTS
]--
90 && (MetaState::state
& MS_GAME_PLAY
)
91 && Grid::checkSafeHeightViolation())
92 death_flash_alarm
[LL_LOCAL_LIGHTS
] = DC_LEVEL_LIGHT_DEATH_FLASH_TIME
;
94 // if we're death flashing and done with a flash and should continue
95 if (death_flash_alarm
[LL_OPPONENT_LIGHTS
] != -1
96 && !death_flash_alarm
[LL_OPPONENT_LIGHTS
]--
97 && (MetaState::state
& MS_GAME_PLAY
)
98 && Communicator::checkLevelLightRecvBit(LC_DEATH_FLASH_MASK
))
99 death_flash_alarm
[LL_OPPONENT_LIGHTS
] = DC_LEVEL_LIGHT_DEATH_FLASH_TIME
;
102 void LevelLights::handleAI ()
104 if (ComputerPlayer::checkLevelLightDying() && death_flash_alarm
[LL_OPPONENT_LIGHTS
] == -1)
105 death_flash_alarm
[LL_OPPONENT_LIGHTS
] = DC_LEVEL_LIGHT_DEATH_FLASH_TIME
;
106 for (int n
= LL_NUMBER_LEVEL_LIGHTS
; n
--; ) {
107 if (lights
[LL_OPPONENT_LIGHTS
][n
].state
& (LS_RED
| LS_FADE_TO_RED
)) {
108 if (ComputerPlayer::checkLevelLightBlue(n
))
109 setBlue(lights
[LL_OPPONENT_LIGHTS
][n
]);
111 if (!ComputerPlayer::checkLevelLightBlue(n
))
112 setRed(lights
[LL_OPPONENT_LIGHTS
][n
]);
114 if (ComputerPlayer::impact()) {
115 setFlashing(lights
[LL_OPPONENT_LIGHTS
][ComputerPlayer::levelLightImpact()]);