1 //=============================================================================
2 //
3 // Adventure Game Studio (AGS)
4 //
5 // Copyright (C) 1999-2011 Chris Jones and 2011-20xx others
6 // The full list of copyright holders can be found in the Copyright.txt
7 // file, which is part of this source code distribution.
8 //
9 // The AGS source code is provided under the Artistic License 2.0.
10 // A copy of this license can be found in the file License.txt and at
11 // http://www.opensource.org/licenses/artistic-license-2.0.php
12 //
13 //=============================================================================
14
15 #include "ac/common.h"
16 #include "ac/runtime_defines.h"
17 #include "ac/speech.h"
18
user_to_internal_skip_speech(SkipSpeechStyle userval)19 int user_to_internal_skip_speech(SkipSpeechStyle userval)
20 {
21 switch (userval)
22 {
23 case kSkipSpeechKeyMouseTime:
24 return SKIP_AUTOTIMER | SKIP_KEYPRESS | SKIP_MOUSECLICK;
25 case kSkipSpeechKeyTime:
26 return SKIP_AUTOTIMER | SKIP_KEYPRESS;
27 case kSkipSpeechTime:
28 return SKIP_AUTOTIMER;
29 case kSkipSpeechKeyMouse:
30 return SKIP_KEYPRESS | SKIP_MOUSECLICK;
31 case kSkipSpeechMouseTime:
32 return SKIP_AUTOTIMER | SKIP_MOUSECLICK;
33 case kSkipSpeechKey:
34 return SKIP_KEYPRESS;
35 case kSkipSpeechMouse:
36 return SKIP_MOUSECLICK;
37 default:
38 quit("user_to_internal_skip_speech: unknown userval");
39 return 0;
40 }
41 }
42
internal_skip_speech_to_user(int internal_val)43 SkipSpeechStyle internal_skip_speech_to_user(int internal_val)
44 {
45 if (internal_val & SKIP_AUTOTIMER)
46 {
47 internal_val &= ~SKIP_AUTOTIMER;
48 if (internal_val == (SKIP_KEYPRESS | SKIP_MOUSECLICK))
49 {
50 return kSkipSpeechKeyMouseTime;
51 }
52 else if (internal_val == SKIP_KEYPRESS)
53 {
54 return kSkipSpeechKeyTime;
55 }
56 else if (internal_val == SKIP_MOUSECLICK)
57 {
58 return kSkipSpeechMouseTime;
59 }
60 return kSkipSpeechTime;
61 }
62 else
63 {
64 if (internal_val == (SKIP_KEYPRESS | SKIP_MOUSECLICK))
65 {
66 return kSkipSpeechKeyMouse;
67 }
68 else if (internal_val == SKIP_KEYPRESS)
69 {
70 return kSkipSpeechKey;
71 }
72 else if (internal_val == SKIP_MOUSECLICK)
73 {
74 return kSkipSpeechMouse;
75 }
76 }
77 return kSkipSpeechUndefined;
78 }
79
80 //=============================================================================
81 //
82 // Script API Functions
83 //
84 //=============================================================================
85
86 #include "ac/gamesetupstruct.h"
87 #include "ac/gamestate.h"
88 #include "ac/global_audio.h"
89 #include "ac/global_display.h"
90 #include "debug/out.h"
91 #include "script/script_api.h"
92 #include "script/script_runtime.h"
93
94 extern GameSetupStruct game;
95 extern GameState play;
96
Sc_Speech_GetAnimationStopTimeMargin(const RuntimeScriptValue * params,int32_t param_count)97 RuntimeScriptValue Sc_Speech_GetAnimationStopTimeMargin(const RuntimeScriptValue *params, int32_t param_count)
98 {
99 API_VARGET_INT(play.close_mouth_speech_time);
100 }
101
Sc_Speech_SetAnimationStopTimeMargin(const RuntimeScriptValue * params,int32_t param_count)102 RuntimeScriptValue Sc_Speech_SetAnimationStopTimeMargin(const RuntimeScriptValue *params, int32_t param_count)
103 {
104 API_VARSET_PINT(play.close_mouth_speech_time);
105 }
106
Sc_Speech_GetCustomPortraitPlacement(const RuntimeScriptValue * params,int32_t param_count)107 RuntimeScriptValue Sc_Speech_GetCustomPortraitPlacement(const RuntimeScriptValue *params, int32_t param_count)
108 {
109 API_VARGET_INT(play.speech_portrait_placement);
110 }
111
Sc_Speech_SetCustomPortraitPlacement(const RuntimeScriptValue * params,int32_t param_count)112 RuntimeScriptValue Sc_Speech_SetCustomPortraitPlacement(const RuntimeScriptValue *params, int32_t param_count)
113 {
114 API_VARSET_PINT(play.speech_portrait_placement);
115 }
116
Sc_Speech_GetDisplayPostTimeMs(const RuntimeScriptValue * params,int32_t param_count)117 RuntimeScriptValue Sc_Speech_GetDisplayPostTimeMs(const RuntimeScriptValue *params, int32_t param_count)
118 {
119 API_VARGET_INT(play.speech_display_post_time_ms);
120 }
121
Sc_Speech_SetDisplayPostTimeMs(const RuntimeScriptValue * params,int32_t param_count)122 RuntimeScriptValue Sc_Speech_SetDisplayPostTimeMs(const RuntimeScriptValue *params, int32_t param_count)
123 {
124 API_VARSET_PINT(play.speech_display_post_time_ms);
125 }
126
Sc_Speech_GetGlobalSpeechAnimationDelay(const RuntimeScriptValue * params,int32_t param_count)127 RuntimeScriptValue Sc_Speech_GetGlobalSpeechAnimationDelay(const RuntimeScriptValue *params, int32_t param_count)
128 {
129 API_VARGET_INT(play.talkanim_speed);
130 }
131
Sc_Speech_SetGlobalSpeechAnimationDelay(const RuntimeScriptValue * params,int32_t param_count)132 RuntimeScriptValue Sc_Speech_SetGlobalSpeechAnimationDelay(const RuntimeScriptValue *params, int32_t param_count)
133 {
134 if (game.options[OPT_GLOBALTALKANIMSPD] == 0)
135 quit("!Speech.GlobalSpeechAnimationDelay cannot be set when global speech animation speed is not enabled; set Speech.UseGlobalSpeechAnimationDelay first!");
136 API_VARSET_PINT(play.talkanim_speed);
137 }
138
Sc_Speech_GetPortraitXOffset(const RuntimeScriptValue * params,int32_t param_count)139 RuntimeScriptValue Sc_Speech_GetPortraitXOffset(const RuntimeScriptValue *params, int32_t param_count)
140 {
141 API_VARGET_INT(play.speech_portrait_x);
142 }
143
Sc_Speech_SetPortraitXOffset(const RuntimeScriptValue * params,int32_t param_count)144 RuntimeScriptValue Sc_Speech_SetPortraitXOffset(const RuntimeScriptValue *params, int32_t param_count)
145 {
146 API_VARSET_PINT(play.speech_portrait_x);
147 }
148
Sc_Speech_GetPortraitY(const RuntimeScriptValue * params,int32_t param_count)149 RuntimeScriptValue Sc_Speech_GetPortraitY(const RuntimeScriptValue *params, int32_t param_count)
150 {
151 API_VARGET_INT(play.speech_portrait_y);
152 }
153
Sc_Speech_SetPortraitY(const RuntimeScriptValue * params,int32_t param_count)154 RuntimeScriptValue Sc_Speech_SetPortraitY(const RuntimeScriptValue *params, int32_t param_count)
155 {
156 API_VARSET_PINT(play.speech_portrait_y);
157 }
158
Sc_Speech_GetStyle(const RuntimeScriptValue * params,int32_t param_count)159 RuntimeScriptValue Sc_Speech_GetStyle(const RuntimeScriptValue *params, int32_t param_count)
160 {
161 API_VARGET_INT(game.options[OPT_SPEECHTYPE]);
162 }
163
164 extern RuntimeScriptValue Sc_SetSpeechStyle(const RuntimeScriptValue *params, int32_t param_count);
165
Sc_Speech_GetSkipKey(const RuntimeScriptValue * params,int32_t param_count)166 RuntimeScriptValue Sc_Speech_GetSkipKey(const RuntimeScriptValue *params, int32_t param_count)
167 {
168 API_VARGET_INT(play.skip_speech_specific_key);
169 }
170
Sc_Speech_SetSkipKey(const RuntimeScriptValue * params,int32_t param_count)171 RuntimeScriptValue Sc_Speech_SetSkipKey(const RuntimeScriptValue *params, int32_t param_count)
172 {
173 API_VARSET_PINT(play.skip_speech_specific_key);
174 }
175
Sc_Speech_GetSkipStyle(const RuntimeScriptValue * params,int32_t param_count)176 RuntimeScriptValue Sc_Speech_GetSkipStyle(const RuntimeScriptValue *params, int32_t param_count)
177 {
178 API_SCALL_INT(GetSkipSpeech);
179 }
180
181 extern RuntimeScriptValue Sc_SetSkipSpeech(const RuntimeScriptValue *params, int32_t param_count);
182
Sc_Speech_GetTextAlignment(const RuntimeScriptValue * params,int32_t param_count)183 RuntimeScriptValue Sc_Speech_GetTextAlignment(const RuntimeScriptValue *params, int32_t param_count)
184 {
185 API_VARGET_INT(play.speech_text_align);
186 }
187
Sc_Speech_SetTextAlignment(const RuntimeScriptValue * params,int32_t param_count)188 RuntimeScriptValue Sc_Speech_SetTextAlignment(const RuntimeScriptValue *params, int32_t param_count)
189 {
190 API_VARSET_PINT(play.speech_text_align);
191 }
192
Sc_Speech_GetUseGlobalSpeechAnimationDelay(const RuntimeScriptValue * params,int32_t param_count)193 RuntimeScriptValue Sc_Speech_GetUseGlobalSpeechAnimationDelay(const RuntimeScriptValue *params, int32_t param_count)
194 {
195 API_VARGET_INT(game.options[OPT_GLOBALTALKANIMSPD]);
196 }
197
Sc_Speech_SetUseGlobalSpeechAnimationDelay(const RuntimeScriptValue * params,int32_t param_count)198 RuntimeScriptValue Sc_Speech_SetUseGlobalSpeechAnimationDelay(const RuntimeScriptValue *params, int32_t param_count)
199 {
200 API_VARSET_PINT(game.options[OPT_GLOBALTALKANIMSPD]);
201 }
202
Sc_Speech_GetVoiceMode(const RuntimeScriptValue * params,int32_t param_count)203 RuntimeScriptValue Sc_Speech_GetVoiceMode(const RuntimeScriptValue *params, int32_t param_count)
204 {
205 API_SCALL_INT(GetVoiceMode);
206 }
207
208 extern RuntimeScriptValue Sc_SetVoiceMode(const RuntimeScriptValue *params, int32_t param_count);
209
RegisterSpeechAPI()210 void RegisterSpeechAPI()
211 {
212 ccAddExternalStaticFunction("Speech::get_AnimationStopTimeMargin", Sc_Speech_GetAnimationStopTimeMargin);
213 ccAddExternalStaticFunction("Speech::set_AnimationStopTimeMargin", Sc_Speech_SetAnimationStopTimeMargin);
214 ccAddExternalStaticFunction("Speech::get_CustomPortraitPlacement", Sc_Speech_GetCustomPortraitPlacement);
215 ccAddExternalStaticFunction("Speech::set_CustomPortraitPlacement", Sc_Speech_SetCustomPortraitPlacement);
216 ccAddExternalStaticFunction("Speech::get_DisplayPostTimeMs", Sc_Speech_GetDisplayPostTimeMs);
217 ccAddExternalStaticFunction("Speech::set_DisplayPostTimeMs", Sc_Speech_SetDisplayPostTimeMs);
218 ccAddExternalStaticFunction("Speech::get_GlobalSpeechAnimationDelay", Sc_Speech_GetGlobalSpeechAnimationDelay);
219 ccAddExternalStaticFunction("Speech::set_GlobalSpeechAnimationDelay", Sc_Speech_SetGlobalSpeechAnimationDelay);
220 ccAddExternalStaticFunction("Speech::get_PortraitXOffset", Sc_Speech_GetPortraitXOffset);
221 ccAddExternalStaticFunction("Speech::set_PortraitXOffset", Sc_Speech_SetPortraitXOffset);
222 ccAddExternalStaticFunction("Speech::get_PortraitY", Sc_Speech_GetPortraitY);
223 ccAddExternalStaticFunction("Speech::set_PortraitY", Sc_Speech_SetPortraitY);
224 ccAddExternalStaticFunction("Speech::get_SkipKey", Sc_Speech_GetSkipKey);
225 ccAddExternalStaticFunction("Speech::set_SkipKey", Sc_Speech_SetSkipKey);
226 ccAddExternalStaticFunction("Speech::get_SkipStyle", Sc_Speech_GetSkipStyle);
227 ccAddExternalStaticFunction("Speech::set_SkipStyle", Sc_SetSkipSpeech);
228 ccAddExternalStaticFunction("Speech::get_Style", Sc_Speech_GetStyle);
229 ccAddExternalStaticFunction("Speech::set_Style", Sc_SetSpeechStyle);
230 ccAddExternalStaticFunction("Speech::get_TextAlignment", Sc_Speech_GetTextAlignment);
231 ccAddExternalStaticFunction("Speech::set_TextAlignment", Sc_Speech_SetTextAlignment);
232 ccAddExternalStaticFunction("Speech::get_UseGlobalSpeechAnimationDelay", Sc_Speech_GetUseGlobalSpeechAnimationDelay);
233 ccAddExternalStaticFunction("Speech::set_UseGlobalSpeechAnimationDelay", Sc_Speech_SetUseGlobalSpeechAnimationDelay);
234 ccAddExternalStaticFunction("Speech::get_VoiceMode", Sc_Speech_GetVoiceMode);
235 ccAddExternalStaticFunction("Speech::set_VoiceMode", Sc_SetVoiceMode);
236
237 /* -- Don't register more unsafe plugin symbols until new plugin interface is designed --*/
238 }
239