1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * System variable handling.
22  */
23 
24 #include "tinsel/dw.h"
25 #include "tinsel/graphics.h"
26 #include "tinsel/dialogs.h"
27 #include "tinsel/strres.h"
28 #include "tinsel/sysvar.h"
29 #include "tinsel/tinsel.h"
30 
31 #include "common/textconsole.h"
32 
33 namespace Tinsel {
34 
35 // Return for SYS_Platform
36 typedef enum { DOS_PC, WIN_PC, APPLE_MAC, SONY_PSX, SEGA_SATURN } platform;
37 
38 //----------------- GLOBAL GLOBAL DATA --------------------
39 
40 extern int NewestSavedGame();
41 
42 //----------------- LOCAL GLOBAL DATA --------------------
43 
44 // These vars are reset upon engine destruction
45 
46 static int g_systemVars[SV_TOPVALID];
47 static SCNHANDLE g_systemStrings[SS_MAX_VALID];
48 
49 //----------------- FUNCTIONS --------------------------------
50 
ResetVarsSysVar()51 void ResetVarsSysVar() {
52 	memset(g_systemVars, 0, sizeof(g_systemVars));
53 	memset(g_systemStrings, 0, sizeof(g_systemStrings));
54 }
55 
56 /**
57  * Initializes the system variable list
58  */
59 
InitSysVars()60 void InitSysVars() {
61 	int initialSystemVars[SV_TOPVALID] = {
62 	    INV_1, // Default inventory
63 
64 	    10,  // Y-offset of Conversation(TOP)
65 	    320, // Y-offset of Conversation(BOT)
66 	    15,  // Minimum distance from side
67 	    10,  // Minimum distance from top
68 	    115, // Distance above actor
69 	    10,  // Distance below actor
70 
71 	    0, // Current language **READ ONLY**
72 	    0, // Sample language **READ ONLY**
73 	    0, // Current state **READ ONLY**
74 	    0, // Saved Game Exists **READ ONLY**
75 
76 	    true, // Should Conversation() wait for scroll? [TRUE]
77 	    true, // Should Talk()/Say() wait for scroll? [TRUE]
78 
79 	    true, // Enable PointTag()
80 	    true, // Enable cursor with PrintCursor()
81 
82 	    100, // SV_SCROLL_XTRIGGER
83 	    0,   // SV_SCROLL_XDISTANCE
84 	    16,  // SV_SCROLL_XSPEED
85 	    40,  // SV_SCROLL_YTRIGGERTOP
86 	    40,  // SV_SCROLL_YTRIGGERBOT
87 	    0,   // SV_SCROLL_YDISTANCE
88 	    16,  // SV_SCROLL_YSPEED
89 
90 	    2, // Speech Delay
91 	    2, // Music dim factor
92 
93 	    0, // if set, default actor's text color gets poked in here
94 
95 	    0, // user 1
96 	    0, // user 2
97 	    0, // user 3
98 	    0, // user 4
99 	    0, // user 5
100 	    0, // user 6
101 
102 	    0, // SYS_MinimumXoffset
103 	    0, // SYS_MaximumXoffset
104 	    0, // SYS_MinimumYoffset
105 	    0, // SYS_MaximumYoffset
106 
107 	    0, // SYS_DefaultFxDimFactor
108 	    0, // SYS_SceneFxDimFactor
109 
110 	    0x606060, // SYS_HighlightRGB
111 	    WIN_PC,   // SYS_Platform,
112 	    0,        // SYS_Debug
113 
114 	    0,     // ISV_DIVERT_ACTOR
115 	    false, // ISV_NO_BLOCKING
116 
117 	    0, // ISV_GHOST_ACTOR
118 	    0, // ISV_GHOST_BASE
119 	    0  // ISV_GHOST_COLOR
120 	};
121 
122 	memcpy(g_systemVars, initialSystemVars, sizeof(g_systemVars));
123 
124 	g_systemVars[SV_SCROLL_XDISTANCE] = SCREEN_WIDTH / 2;
125 	g_systemVars[SV_SCROLL_YDISTANCE] = SCREEN_BOX_HEIGHT1 / 2;
126 }
127 
128 /**
129  * SetSysVar
130  */
131 
SetSysVar(int varId,int newValue)132 void SetSysVar(int varId, int newValue) {
133 	if (varId < 0 || varId >= SV_TOPVALID)
134 		error("SetSystemVar(): out of range identifier");
135 
136 	switch (varId) {
137 	case SV_LANGUAGE:
138 	case SV_SAMPLE_LANGUAGE:
139 	case SV_SUBTITLES:
140 	case SV_SAVED_GAME_EXISTS:
141 	case SYS_Platform:
142 	case SYS_Debug:
143 		error("SetSystemVar(): read only identifier");
144 
145 	default:
146 		g_systemVars[varId] = newValue;
147 	}
148 }
149 
SysVar(int varId)150 int SysVar(int varId) {
151 	if (varId < 0 || varId >= SV_TOPVALID)
152 		error("SystemVar(): out of range identifier");
153 
154 	switch (varId) {
155 	case SV_LANGUAGE:
156 		return TextLanguage();
157 
158 	case SV_SAMPLE_LANGUAGE:
159 		return SampleLanguage();
160 
161 	case SV_SUBTITLES:
162 		// FIXME: This isn't currently defined
163 		return false;
164 		//return _vm->_config->_useSubtitles;
165 
166 	case SV_SAVED_GAME_EXISTS:
167 		return NewestSavedGame() != -1;
168 
169 	case SYS_Debug:
170 		// FIXME: This isn't currently defined
171 		return false;
172 		//return bDebuggingAllowed;
173 
174 	default:
175 		return g_systemVars[varId];
176 	}
177 }
178 
SaveSysVars(int * pSv)179 void SaveSysVars(int *pSv) {
180 	memcpy(pSv, g_systemVars, sizeof(g_systemVars));
181 }
182 
RestoreSysVars(int * pSv)183 void RestoreSysVars(int *pSv) {
184 	memcpy(g_systemVars, pSv, sizeof(g_systemVars));
185 }
186 
SetSysString(int number,SCNHANDLE hString)187 void SetSysString(int number, SCNHANDLE hString) {
188 	assert(number >= 0 && number < SS_MAX_VALID);
189 
190 	g_systemStrings[number] = hString;
191 }
192 
SysString(int number)193 SCNHANDLE SysString(int number) {
194 	assert(number >= 0 && number < SS_MAX_VALID);
195 
196 	return g_systemStrings[number];
197 }
198 
199 /**
200  * Gets the no blocking flag. Note that for convenience, the systemVars array
201  * entry is used even for Tinsel 1, which originally used a separate variable.
202  */
GetNoBlocking()203 bool GetNoBlocking() {
204 	return SysVar(ISV_NO_BLOCKING);
205 }
206 
207 /**
208  * Sets the no blocking flag. Note that for convenience, the systemVars array
209  * entry is used even for Tinsel 1, which originally used a separate variable.
210  */
SetNoBlocking(bool flag)211 void SetNoBlocking(bool flag) {
212 	SetSysVar(ISV_NO_BLOCKING, flag);
213 }
214 
215 } // End of namespace Tinsel
216