void showScenarioByName(stream *f, str nme) { Scenario scen = findScenario(nme); if (scen) showScenario(f, scen); }
/* * Functions may become resolved only after the corresponding module * has been loaded. This should be announced as part of the module * prelude code. * Beware that after the update, we also have to adjust the client records. * They contain a copy of the functions addresses. */ void updateScenario(str nme, str fnme, MALfcn fcn) { int phase = -1; Scenario scen = findScenario(nme); if (scen == NULL) return; if (scen->initSystem && strcmp(scen->initSystem, fnme) == 0) scen->initSystemCmd = fcn; if (scen->exitSystem && strcmp(scen->exitSystem, fnme) == 0) scen->exitSystemCmd = fcn; if (scen->initClient && strcmp(scen->initClient, fnme) == 0) { scen->initClientCmd = fcn; phase = MAL_SCENARIO_INITCLIENT; } if (scen->exitClient && strcmp(scen->exitClient, fnme) == 0) { scen->exitClientCmd = fcn; phase = MAL_SCENARIO_EXITCLIENT; } if (scen->reader && strcmp(scen->reader, fnme) == 0) { scen->readerCmd = fcn; phase = MAL_SCENARIO_READER; } if (scen->parser && strcmp(scen->parser, fnme) == 0) { scen->parserCmd = fcn; phase = MAL_SCENARIO_PARSER; } if (scen->optimizer && strcmp(scen->optimizer, fnme) == 0) { scen->optimizerCmd = fcn; phase = MAL_SCENARIO_OPTIMIZE; } if (scen->tactics && strcmp(scen->tactics, fnme) == 0) { scen->tacticsCmd = fcn; phase = MAL_SCENARIO_SCHEDULER; } if (scen->callback && strcmp(scen->callback, fnme) == 0) { scen->callbackCmd = fcn; phase = MAL_SCENARIO_CALLBACK; } if (scen->engine && strcmp(scen->engine, fnme) == 0) { scen->engineCmd = fcn; phase = MAL_SCENARIO_ENGINE; } if (phase != -1) { Client c1; for (c1 = mal_clients; c1 < mal_clients + MAL_MAXCLIENTS; c1++) { if (c1->scenario && strcmp(c1->scenario, scen->name) == 0) c1->phase[phase] = fcn; if (c1->oldscenario && strcmp(c1->oldscenario, scen->name) == 0) c1->oldphase[phase] = fcn; } } }
void exitScenario(Client c) { Scenario scen = scenarioRec; if (c->scenario == 0) return; scen = findScenario(c->scenario); if (scen->exitSystemCmd) (*scen->exitSystemCmd) (c); c->scenario = NULL; }
void resetScenario(Client c) { int i; Scenario scen = scenarioRec; if (c->scenario == 0) return; scen = findScenario(c->scenario); if (scen != NULL && scen->exitClientCmd) (*scen->exitClientCmd) (c); c->scenario = c->oldscenario; for (i = 0; i < SCENARIO_PROPERTIES; i++) { c->state[i] = c->oldstate[i]; c->phase[i] = c->oldphase[i]; } c->oldscenario = 0; }
/* * @- * Setting a new scenario calls for saving the previous state * and execution of the initClientScenario routine. */ str setScenario(Client c, str nme) { int i; str msg; Scenario scen = scenarioRec; scen = findScenario(nme); if (scen == NULL) throw(MAL, "setScenario", SCENARIO_NOT_FOUND " '%s'", nme); if (c->scenario) { c->oldscenario = c->scenario; for (i = 0; i < 7; i++) { c->oldstate[i] = c->state[i]; c->oldphase[i] = c->phase[i]; } } for (i = 0; i < 7; i++) c->state[i] = 0; msg = initScenario(c, scen); if (msg) { /* error occurred, reset the scenario , assume default always works */ c->scenario = c->oldscenario; for (i = 0; i < 7; i++) { c->state[i] = c->oldstate[i]; c->phase[i] = c->oldphase[i]; c->oldstate[i] = NULL; c->oldphase[i] = NULL; } c->oldscenario = NULL; return msg; } return MAL_SUCCEED; }
str getScenarioLanguage(Client c){ Scenario scen= findScenario(c->scenario); if( scen) return scen->language; return "mal"; }