handleRocketSignal method
- SamModel sm,
- SamReq req
we have received a signal from the child Missile.
We use this to generate a log message and send to the parent.
We also use this to inspect the state of the Bank by looking at the remaining child Missiles. When the number of unspent missiles is 0 we flip ourself into a BK.ssDepleted state.
Implementation
void handleRocketSignal(SamModel sm,SamReq req) {
assert(log("rocketSignal ${req.signal}"));
var signal = req.signal as RK;
Rocket r = req.stepParms['src'];
assert(log("signal $signal $sm processed src=${r.rocketName}"));
String msg = "${r.rocketName} ";
switch(signal) {
case RK.sgLaunching: msg += " launched"; break;
case RK.sgAborting: msg += " launch aborted"; break;
case RK.sgPausing: msg += " launch paused"; break;
//case RK.sgCounting: msg += " countdown started/resumed"; break;
default:msg += "signal $signal not defined"; break;
}
sm.parent.presentNow(BK.sgLogReq,stepParms:{'src':sm,'msg':msg});
// Check to see if need to signal depleted
int numGood = 0;
for(Missile m in sm.kids) if (m.isState([RK.ssReady,RK.ssCounting,RK.ssWaiting,RK.ssPaused])) numGood += 1;
if (numGood == 0) sm.flipState(BK.ssDepleted);
}