00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "LevelScript.h"
00010
00011 #include "V2.h"
00012 #include "Room.h"
00013 #include "ScriptState.h"
00014
00015 #include "ScriptCmd.h"
00016 #include "LogicException.h"
00017 #include "Cube.h"
00018 #include "Unit.h"
00019
00020 #include "game-script.h"
00021 #include "level-script.h"
00022
00023 #include <memory>
00024
00025
00026
00027
00028
00029 LevelScript::LevelScript(Level *aLevel)
00030 {
00031 m_level = aLevel;
00032 registerGameFuncs();
00033 }
00034
00035
00036
00037
00038
00039
00040
00041 Command *
00042 LevelScript::createCommand(int funcRef)
00043 {
00044 return new ScriptCmd(m_script, funcRef);
00045 }
00046
00047
00048
00049
00050
00051 void
00052 LevelScript::updateScript()
00053 {
00054 m_script->doString("script_update()");
00055 satisfyPlan();
00056 }
00057
00058 void
00059 LevelScript::interruptPlan()
00060 {
00061 Planner::interruptPlan();
00062
00063
00064 room()->checkActive();
00065 room()->unBusyUnits();
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075 int
00076 LevelScript::addModel(Cube *new_model, Unit *new_unit)
00077 {
00078 std::auto_ptr<Cube> ptr_model(new_model);
00079 std::auto_ptr<Unit> ptr_unit(new_unit);
00080
00081 ptr_model->takeDialogs(dialogs());
00082 return room()->addModel(ptr_model.release(), ptr_unit.release());
00083 }
00084
00085 Cube *
00086 LevelScript::getModel(int model_index)
00087 {
00088 return room()->getModel(model_index);
00089 }
00090
00091
00092
00093
00094 Cube *
00095 LevelScript::askField(const V2 &loc)
00096 {
00097 return room()->askField(loc);
00098 }
00099
00100
00101 void
00102 LevelScript::addSound(const std::string &name, const Path &file)
00103 {
00104 room()->addSound(name, file);
00105 }
00106
00107 void
00108 LevelScript::playSound(const std::string &name, int volume)
00109 {
00110 room()->playSound(name, volume);
00111 }
00112
00113
00114
00115
00116 void
00117 LevelScript::registerGameFuncs()
00118 {
00119 m_script->registerFunc("game_setRoomWaves", script_game_setRoomWaves);
00120 m_script->registerFunc("game_addModel", script_game_addModel);
00121 m_script->registerFunc("game_getCycles", script_game_getCycles);
00122 m_script->registerFunc("game_addDecor", script_game_addDecor);
00123 m_script->registerFunc("game_setScreenShift", script_game_setScreenShift);
00124 m_script->registerFunc("game_changeBg", script_game_changeBg);
00125 m_script->registerFunc("game_checkActive", script_game_checkActive);
00126 m_script->registerFunc("game_setFastFalling", script_game_setFastFalling);
00127
00128 m_script->registerFunc("model_addAnim", script_model_addAnim);
00129 m_script->registerFunc("model_runAnim", script_model_runAnim);
00130 m_script->registerFunc("model_setAnim", script_model_setAnim);
00131 m_script->registerFunc("model_useSpecialAnim", script_model_useSpecialAnim);
00132 m_script->registerFunc("model_countAnims", script_model_countAnims);
00133 m_script->registerFunc("model_setEffect", script_model_setEffect);
00134 m_script->registerFunc("model_getLoc", script_model_getLoc);
00135 m_script->registerFunc("model_getAction", script_model_getAction);
00136 m_script->registerFunc("model_getState", script_model_getState);
00137 m_script->registerFunc("model_getDir", script_model_getDir);
00138 m_script->registerFunc("model_getTouchDir", script_model_getTouchDir);
00139 m_script->registerFunc("model_isAlive", script_model_isAlive);
00140 m_script->registerFunc("model_isOut", script_model_isOut);
00141 m_script->registerFunc("model_isLeft", script_model_isLeft);
00142 m_script->registerFunc("model_isAtBorder", script_model_isAtBorder);
00143 m_script->registerFunc("model_getW", script_model_getW);
00144 m_script->registerFunc("model_getH", script_model_getH);
00145 m_script->registerFunc("model_setGoal", script_model_setGoal);
00146 m_script->registerFunc("model_change_turnSide",
00147 script_model_change_turnSide);
00148 m_script->registerFunc("model_setViewShift",
00149 script_model_setViewShift);
00150 m_script->registerFunc("model_getViewShift",
00151 script_model_getViewShift);
00152 m_script->registerFunc("model_setBusy", script_model_setBusy);
00153 m_script->registerFunc("model_equals", script_model_equals);
00154
00155 m_script->registerFunc("sound_addSound", script_sound_addSound);
00156 m_script->registerFunc("sound_playSound", script_sound_playSound);
00157
00158 registerLevelFuncs();
00159 }
00160
00161 void
00162 LevelScript::registerLevelFuncs()
00163 {
00164 m_script->registerFunc("level_save", script_level_save);
00165 m_script->registerFunc("level_load", script_level_load);
00166
00167 m_script->registerFunc("level_action_move", script_level_action_move);
00168 m_script->registerFunc("level_action_save", script_level_action_save);
00169 m_script->registerFunc("level_action_load", script_level_action_load);
00170 m_script->registerFunc("level_action_restart", script_level_action_restart);
00171
00172 m_script->registerFunc("level_createRoom", script_level_createRoom);
00173 m_script->registerFunc("level_getRestartCounter",
00174 script_level_getRestartCounter);
00175 m_script->registerFunc("level_getDepth", script_level_getDepth);
00176 m_script->registerFunc("level_isNewRound", script_level_isNewRound);
00177 m_script->registerFunc("level_isSolved", script_level_isSolved);
00178 m_script->registerFunc("level_newDemo", script_level_newDemo);
00179 m_script->registerFunc("level_planShow", script_level_planShow);
00180 m_script->registerFunc("level_isShowing", script_level_isShowing);
00181 }
00182