/* * countdown.slo * * Do an audible countdown to mission failure. * */ // the human player public INT player; // how many stages for the countdown public INT numSoundSets, numStages[2]; // what times to play each sound for the countdown public INT stageTime[2][15]; // the sounds to play as each time point is reached // the first dimension controls which sound set is used public SOUND stageSound[2][15]; private INT timeLeft, currStage, currSoundSet, prevTime; private BOOL done; // do an event as soon as possible trigger now(wait, 0); // pause between testing for the next sound trigger nextSoundPause(every, 5); trigger checkTime(every, 20); event initStage; event playStageSound; event timeReset; event start(CALL_GAMEINIT) { setEventTrigger(initStage, now); //currSoundSet = -1; } // setup the correct stage level for the event timer event initStage(inactive) { if (currSoundSet >= numSoundSets) { currSoundSet = 0; } // skip down to the current sound set currStage = numStages[currSoundSet] - 1; timeLeft = missionTimeRemaining(); prevTime = timeLeft; setEventTrigger(timeReset, checkTime); done = FALSE; while ( not done ) { if (currStage >= 0) { //don't bother if timer not set if (timeLeft <= stageTime[currSoundSet][currStage]) { currStage = currStage - 1; } else { done = TRUE; } } else { done = TRUE; } } setEventTrigger(playStageSound, nextSoundPause); } // see if the time for the next stage has been reached event playStageSound(inactive) { if (currStage >= 0) { //don't bother if timer not set if ((timeLeft <= stageTime[currSoundSet][currStage]) and (timeLeft != 0)) { playSound(stageSound[currSoundSet][currStage], player); currStage = currStage - 1; } /* else if ( currStage < (numStages[currSoundSet] - 1) ) { if (timeLeft > stageTime[currSoundSet][currStage + 1]) { setEventTrigger(playStageSound, inactive); setEventTrigger(initStage, now); } } */ } } event timeReset(inactive) { timeLeft = missionTimeRemaining(); // test for the mission timer being reset if (timeLeft > prevTime) { // change to the next sound set currSoundSet = currSoundSet + 1; setEventTrigger(playStageSound, inactive); setEventTrigger(initStage, now); } prevTime = timeLeft; }