| 1 |
/* |
| 2 |
* Copyright (C) 2004 Ivo Danihelka ([email protected]) |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
*/ |
| 9 |
#include "Planner.h" |
| 10 |
|
| 11 |
#include "ScriptState.h" |
| 12 |
#include "CommandQueue.h" |
| 13 |
#include "DialogStack.h" |
| 14 |
|
| 15 |
#include "SubTitleAgent.h" |
| 16 |
#include "ScriptCmd.h" |
| 17 |
#include "dialog-script.h" |
| 18 |
#include "options-script.h" |
| 19 |
|
| 20 |
//----------------------------------------------------------------- |
| 21 |
Planner::Planner() |
| 22 |
{ |
| 23 |
m_plan = new CommandQueue(); |
| 24 |
m_dialogs = new DialogStack(); |
| 25 |
registerScriptFuncs(); |
| 26 |
} |
| 27 |
//----------------------------------------------------------------- |
| 28 |
void |
| 29 |
Planner::registerScriptFuncs() |
| 30 |
{ |
| 31 |
m_script->registerFunc("game_planAction", script_game_planAction); |
| 32 |
m_script->registerFunc("game_isPlanning", script_game_isPlanning); |
| 33 |
m_script->registerFunc("game_killPlan", script_game_killPlan); |
| 34 |
|
| 35 |
m_script->registerFunc("dialog_isDialog", script_dialog_isDialog); |
| 36 |
m_script->registerFunc("dialog_addFont", script_dialog_addFont); |
| 37 |
m_script->registerFunc("dialog_addDialog", script_dialog_addDialog); |
| 38 |
m_script->registerFunc("model_isTalking", script_model_isTalking); |
| 39 |
m_script->registerFunc("model_talk", script_model_talk); |
| 40 |
m_script->registerFunc("model_killSound", script_model_killSound); |
| 41 |
|
| 42 |
m_script->registerFunc("sound_playMusic", script_sound_playMusic); |
| 43 |
m_script->registerFunc("sound_stopMusic", script_sound_stopMusic); |
| 44 |
|
| 45 |
m_script->registerFunc("options_getParam", script_options_getParam); |
| 46 |
} |
| 47 |
//----------------------------------------------------------------- |
| 48 |
Planner::~Planner() |
| 49 |
{ |
| 50 |
//NOTE: planned ScriptCmd must be removed before script |
| 51 |
delete m_plan; |
| 52 |
delete m_dialogs; |
| 53 |
} |
| 54 |
//----------------------------------------------------------------- |
| 55 |
/** |
| 56 |
* Execute next action. |
| 57 |
* @return true for finished plan |
| 58 |
*/ |
| 59 |
bool |
| 60 |
Planner::satisfyPlan() |
| 61 |
{ |
| 62 |
m_dialogs->updateStack(); |
| 63 |
m_plan->executeFirst(); |
| 64 |
return m_plan->empty(); |
| 65 |
} |
| 66 |
//----------------------------------------------------------------- |
| 67 |
void |
| 68 |
Planner::killPlan() |
| 69 |
{ |
| 70 |
m_dialogs->killTalks(); |
| 71 |
SubTitleAgent::agent()->killTalks(); |
| 72 |
interruptPlan(); |
| 73 |
} |
| 74 |
//----------------------------------------------------------------- |
| 75 |
void |
| 76 |
Planner::interruptPlan() |
| 77 |
{ |
| 78 |
m_plan->removeAll(); |
| 79 |
} |
| 80 |
//----------------------------------------------------------------- |
| 81 |
void |
| 82 |
Planner::planAction(int funcRef) |
| 83 |
{ |
| 84 |
m_plan->planCommand(new ScriptCmd(m_script, funcRef)); |
| 85 |
} |
| 86 |
//----------------------------------------------------------------- |
| 87 |
/** |
| 88 |
* Return true when there is a planned command in queue. |
| 89 |
*/ |
| 90 |
bool |
| 91 |
Planner::isPlanning() const |
| 92 |
{ |
| 93 |
return !m_plan->empty(); |
| 94 |
} |
| 95 |
|