00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "dialog-script.h"
00010
00011 class Actor;
00012
00013 #include "Log.h"
00014 #include "Path.h"
00015 #include "FishDialog.h"
00016 #include "DialogStack.h"
00017 #include "SubTitleAgent.h"
00018 #include "SoundAgent.h"
00019 #include "Planner.h"
00020 #include "Color.h"
00021
00022 #include "def-script.h"
00023
00024
00025 inline Planner *
00026 getPlanner(lua_State *L)
00027 {
00028 return dynamic_cast<Planner*>(script_getLeader(L));
00029 }
00030
00031 inline DialogStack *
00032 getDialogs(lua_State *L)
00033 {
00034 return getPlanner(L)->dialogs();
00035 }
00036
00037
00038
00039
00040
00041 int
00042 script_game_planAction(lua_State *L) throw()
00043 {
00044 BEGIN_NOEXCEPTION;
00045 luaL_checktype(L, 1, LUA_TFUNCTION);
00046 int funcRef = luaL_ref(L, LUA_REGISTRYINDEX);
00047
00048 getPlanner(L)->planAction(funcRef);
00049 END_NOEXCEPTION;
00050 return 0;
00051 }
00052
00053
00054
00055
00056 int
00057 script_game_isPlanning(lua_State *L) throw()
00058 {
00059 BEGIN_NOEXCEPTION;
00060 bool planning = getPlanner(L)->isPlanning();
00061 lua_pushboolean(L, planning);
00062 END_NOEXCEPTION;
00063
00064 return 1;
00065 }
00066
00067
00068
00069
00070 int
00071 script_game_killPlan(lua_State *L) throw()
00072 {
00073 BEGIN_NOEXCEPTION;
00074 getPlanner(L)->interruptPlan();
00075 END_NOEXCEPTION;
00076 return 0;
00077 }
00078
00079
00080
00081
00082
00083 int
00084 script_dialog_isDialog(lua_State *L) throw()
00085 {
00086 BEGIN_NOEXCEPTION;
00087 bool isDialog = getDialogs(L)->isDialog();
00088 lua_pushboolean(L, isDialog);
00089 END_NOEXCEPTION;
00090
00091 return 1;
00092 }
00093
00094
00095
00096
00097 int
00098 script_dialog_addFont(lua_State *L) throw()
00099 {
00100 BEGIN_NOEXCEPTION;
00101 const char *name = luaL_checkstring(L, 1);
00102 int red = luaL_checkint(L, 2);
00103 int green = luaL_checkint(L, 3);
00104 int blue = luaL_checkint(L, 4);
00105
00106 SubTitleAgent::agent()->addFont(name, new Color(red, green, blue));
00107
00108 END_NOEXCEPTION;
00109 return 0;
00110 }
00111
00112
00113
00114
00115 int
00116 script_dialog_addDialog(lua_State *L) throw()
00117 {
00118 BEGIN_NOEXCEPTION;
00119 const char *name = luaL_checkstring(L, 1);
00120 const char *lang = luaL_checkstring(L, 2);
00121 const char *soundfile = luaL_checkstring(L, 3);
00122 const char *fontname = luaL_optstring(L, 4, "");
00123 const char *subtitle = luaL_optstring(L, 5, "");
00124
00125 FishDialog *dialog =
00126 new FishDialog(lang, soundfile, subtitle, fontname);
00127 getDialogs(L)->addDialog(name, dialog);
00128
00129 END_NOEXCEPTION;
00130 return 0;
00131 }
00132
00133
00134
00135
00136 int
00137 script_model_isTalking(lua_State *L) throw()
00138 {
00139 BEGIN_NOEXCEPTION;
00140 int model_index = luaL_checkint(L, 1);
00141
00142 bool talking = getDialogs(L)->isTalking(model_index);
00143 lua_pushboolean(L, talking);
00144 END_NOEXCEPTION;
00145
00146 return 1;
00147 }
00148
00149
00150
00151
00152 int
00153 script_model_talk(lua_State *L) throw()
00154 {
00155 BEGIN_NOEXCEPTION;
00156 int model_index = luaL_checkint(L, 1);
00157 const char *name = luaL_checkstring(L, 2);
00158 int volume = luaL_optint(L, 3, 75);
00159 int loops = luaL_optint(L, 4, 0);
00160 bool dialogFlag = lua_toboolean(L, 5);
00161
00162 getDialogs(L)->actorTalk(model_index, name, volume, loops, dialogFlag);
00163 END_NOEXCEPTION;
00164 return 0;
00165 }
00166
00167
00168
00169
00170 int
00171 script_model_killSound(lua_State *L) throw()
00172 {
00173 BEGIN_NOEXCEPTION;
00174 int model_index = luaL_checkint(L, 1);
00175
00176 getDialogs(L)->killSound(model_index);
00177 END_NOEXCEPTION;
00178 return 0;
00179 }
00180
00181
00182
00183
00184
00185 int
00186 script_sound_playMusic(lua_State *L) throw()
00187 {
00188 BEGIN_NOEXCEPTION;
00189 const char *music_name = luaL_checkstring(L, 1);
00190
00191 SoundAgent::agent()->playMusic(Path::dataReadPath(music_name), NULL);
00192 END_NOEXCEPTION;
00193 return 0;
00194 }
00195
00196
00197
00198
00199 int
00200 script_sound_stopMusic(lua_State *L) throw()
00201 {
00202 BEGIN_NOEXCEPTION;
00203 SoundAgent::agent()->stopMusic();
00204 END_NOEXCEPTION;
00205 return 0;
00206 }
00207