aboutsummaryrefslogtreecommitdiff
path: root/engines/mads/action.cpp
blob: 9a8080761b039db65e633af513a9f441ecee422b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "common/scummsys.h"
#include "mads/mads.h"
#include "mads/action.h"
#include "mads/scene.h"

namespace MADS {

MADSAction::MADSAction(MADSEngine *vm) : _vm(vm) {
	clear();
	_currentAction = VERB_NONE;
	_startWalkFlag = false;
	_statusTextIndex = -1;
	_selectedAction = 0;
	_inProgress = false;
}

void MADSAction::clear() {
	_v83338 = 1;
	_actionMode = ACTMODE_NONE;
	_actionMode2 = ACTMODE2_0;
	_v86F42 = 0;
	_v86F4E = 0;
	_articleNumber = 0;
	_lookFlag = false;
	_v86F4A = 0;
	_selectedRow = -1;
	_hotspotId = -1;
	_v86F3A = -1;
	_v86F4C = -1;
	_action.verbId = -1;
	_action.objectNameId = -1;
	_action.indirectObjectId = -1;
	_textChanged = true;
	_walkFlag = false;
}

void MADSAction::appendVocab(int vocabId, bool capitalise) {
	/*
	char *s = _statusText + strlen(_statusText);
	vocabStr = _madsVm->globals()->getVocab(vocabId);
	strcpy(s, vocabStr);
	if (capitalise)
		*s = toupper(*s);

	strcat(s, " ");
	*/
}

void MADSAction::set() {
	/*
	int hotspotCount = _madsVm->scene()->getSceneResources().hotspots->size();
	bool flag = false; // FIXME: unused
	strcpy(_statusText, "");

	_currentAction = -1;
	_action.objectNameId = -1;
	_action.indirectObjectId = -1;

	if (_actionMode == ACTMODE_TALK) {
		// Handle showing the conversation selection. Rex at least doesn't actually seem to use this
		if (_selectedRow >= 0) {
			const char *desc = _madsVm->_converse[_selectedRow].desc;
			if (desc)
				strcpy(_statusText, desc);
		}
	} else if (_lookFlag && (_selectedRow == 0)) {
		// Two 'look' actions in succession, so the action becomes 'Look around'
		strcpy(_statusText, lookAroundStr);
	} else {
		if ((_actionMode == ACTMODE_OBJECT) && (_selectedRow >= 0) && (_flags1 == 2) && (_flags2 == 0)) {
			// Use/to action
			int selectedObject = _madsVm->scene()->getInterface()->getSelectedObject();
			MadsObject *objEntry = _madsVm->globals()->getObject(selectedObject);

			_action.objectNameId = objEntry->_descId;
			_currentAction = objEntry->_vocabList[_selectedRow].vocabId;

			// Set up the status text stirng
			strcpy(_statusText, useStr);
			appendVocab(_action.objectNameId);
			strcpy(_statusText, toStr);
			appendVocab(_currentAction);
		} else {
			// Handling for if an action has been selected
			if (_selectedRow >= 0) {
				if (_actionMode == ACTMODE_VERB) {
					// Standard verb action
					_currentAction = verbList[_selectedRow].verb;
				} else {
					// Selected action on an inventory object
					int selectedObject = _madsVm->scene()->getInterface()->getSelectedObject();
					MadsObject *objEntry = _madsVm->globals()->getObject(selectedObject);

					_currentAction = objEntry->_vocabList[_selectedRow].vocabId;
				}

				appendVocab(_currentAction, true);

				if (_currentAction == kVerbLook) {
					// Add in the word 'add'
					strcat(_statusText, atStr);
					strcat(_statusText, " ");
				}
			}

			// Handling for if a hotspot has been selected/highlighted
			if ((_hotspotId >= 0) && (_selectedRow >= 0) && (_articleNumber > 0) && (_flags1 == 2)) {
				flag = true;

				strcat(_statusText, englishMADSArticleList[_articleNumber]);
				strcat(_statusText, " ");
			}

			if (_hotspotId >= 0) {
				if (_selectedRow < 0) {
					int verbId;

					if (_hotspotId < hotspotCount) {
						// Get the verb Id from the hotspot
						verbId = (*_madsVm->scene()->getSceneResources().hotspots)[_hotspotId].getVerbID();
					} else {
						// Get the verb Id from the scene object
						verbId = (*_madsVm->scene()->getSceneResources().dynamicHotspots)[_hotspotId - hotspotCount].getVerbID();
					}

					if (verbId > 0) {
						// Set the specified action
						_currentAction = verbId;
						appendVocab(_currentAction, true);
					} else {
						// Default to a standard 'walk to'
						_currentAction = kVerbWalkTo;
						strcat(_statusText, walkToStr);
					}
				}

				if ((_actionMode2 == ACTMODE2_2) || (_actionMode2 == ACTMODE2_5)) {
					// Get name from given inventory object
					int objectId = _madsVm->scene()->getInterface()->getInventoryObject(_hotspotId);
					_action.objectNameId = _madsVm->globals()->getObject(objectId)->_descId;
				} else if (_hotspotId < hotspotCount) {
					// Get name from scene hotspot
					_action.objectNameId = (*_madsVm->scene()->getSceneResources().hotspots)[_hotspotId].getVocabID();
				} else {
					// Get name from temporary scene hotspot
					_action.objectNameId = (*_madsVm->scene()->getSceneResources().dynamicHotspots)[_hotspotId].getVocabID();
				}
				appendVocab(_action.objectNameId);
			}
		}

		if ((_hotspotId >= 0) && (_articleNumber > 0) && !flag) {
			if (_articleNumber == -1) {
				if (_v86F3A >= 0) {
					int articleNum = 0;

					if ((_v86F42 == 2) || (_v86F42 == 5)) {
						int objectId = _madsVm->scene()->getInterface()->getInventoryObject(_hotspotId);
						articleNum = _madsVm->globals()->getObject(objectId)->_article;
					} else if (_v86F3A < hotspotCount) {
						articleNum = (*_madsVm->scene()->getSceneResources().hotspots)[_hotspotId].getArticle();
					} else {

					}
				}

			} else if ((_articleNumber == kVerbLook) || (_vm->getGameType() != GType_RexNebular) ||
				(strcmp(_madsVm->globals()->getVocab(_action.indirectObjectId), fenceStr) != 0)) {
				// Write out the article
				strcat(_statusText, englishMADSArticleList[_articleNumber]);
			} else {
				// Special case for a 'fence' entry in Rex Nebular
				strcat(_statusText, overStr);
			}

			strcat(_statusText, " ");
		}

		// Append object description if necessary
		if (_v86F3A >= 0)
			appendVocab(_action.indirectObjectId);

		// Remove any trailing space character
		int statusLen = strlen(_statusText);
		if ((statusLen > 0) && (_statusText[statusLen - 1] == ' '))
			_statusText[statusLen - 1] = '\0';
	}

	_textChanged = true;
	*/
}

void MADSAction::refresh() {
	/*
	// Exit immediately if nothing has changed
	if (!_textChanged)
		return;

	// Remove any old copy of the status text
	if (_statusTextIndex >= 0) {
		_owner._textDisplay.expire(_statusTextIndex);
		_statusTextIndex = -1;
	}

	if (_statusText[0] != '\0') {
		if ((_owner._screenObjects._v832EC == 0) || (_owner._screenObjects._v832EC == 2)) {
			Font *font = _madsVm->_font->getFont(FONT_MAIN_MADS);
			int textSpacing = -1;

			int strWidth = font->getWidth(_statusText);
			if (strWidth > 320) {
				// Too large to fit, so fall back on interface font
				font = _madsVm->_font->getFont(FONT_INTERFACE_MADS);
				strWidth = font->getWidth(_statusText, 0);
				textSpacing = 0;
			}

			// Add a new text display entry to display the status text at the bottom of the screen area
			uint colors = (_vm->getGameType() == GType_DragonSphere) ? 0x0300 : 0x0003;

			_statusTextIndex = _owner._textDisplay.add(160 - (strWidth / 2),
				MADS_SURFACE_HEIGHT + _owner._posAdjust.y - 13, colors, textSpacing, _statusText, font);
		}
	}

	_textChanged = false;
	*/
}

void MADSAction::startAction() {
	/*
	_madsVm->_player.moveComplete();

	_inProgress = true;
	_v8453A = ABORTMODE_0;
	_savedFields.selectedRow = _selectedRow;
	_savedFields.articleNumber = _articleNumber;
	_savedFields.actionMode = _actionMode;
	_savedFields.actionMode2 = _actionMode2;
	_savedFields.lookFlag = _lookFlag;
	int savedHotspotId = _hotspotId;
	int savedV86F3A = _v86F3A;
	int savedV86F42 = _v86F42;

	// Copy the action to be active
	_activeAction = _action;
	strcpy(_dialogTitle, _statusText);

	if ((_savedFields.actionMode2 == ACTMODE2_4) && (savedV86F42 == 0))
		_v8453A = ABORTMODE_1;

	_startWalkFlag = false;
	int hotspotId = -1;
	HotSpotList &dynHotspots = *_madsVm->scene()->getSceneResources().dynamicHotspots;
	HotSpotList &hotspots = *_madsVm->scene()->getSceneResources().hotspots;

	if (!_savedFields.lookFlag && (_madsVm->scene()->_screenObjects._v832EC != 1)) {
		if (_savedFields.actionMode2 == ACTMODE2_4)
			hotspotId = savedHotspotId;
		else if (savedV86F42 == 4)
			hotspotId = savedV86F3A;

		if (hotspotId >= hotspots.size()) {
			HotSpot &hs = dynHotspots[hotspotId - hotspots.size()];
			if ((hs.getFeetX() == -1) || (hs.getFeetX() == -3)) {
				if (_v86F4A && ((hs.getFeetX() == -3) || (_savedFields.selectedRow < 0))) {
					_startWalkFlag = true;
					_madsVm->scene()->_destPos = _madsVm->scene()->_customDest;
				}
			} else if ((hs.getFeetX() >= 0) && ((_savedFields.actionMode == ACTMODE_NONE) || (hs.getCursor() < 2))) {
				_startWalkFlag = true;
				_madsVm->scene()->_destPos.x = hs.getFeetX();
				_madsVm->scene()->_destPos.y = hs.getFeetY();
			}
			_madsVm->scene()->_destFacing = hs.getFacing();
			hotspotId = -1;
		}
	}

	if (hotspotId >= 0) {
		HotSpot &hs = hotspots[hotspotId];
		if ((hs.getFeetX() == -1) || (hs.getFeetX() == -3)) {
			if (_v86F4A && ((hs.getFeetX() == -3) || (_savedFields.selectedRow < 0))) {
				_startWalkFlag = true;
				_madsVm->scene()->_destPos = _madsVm->scene()->_customDest;
			}
		} else if ((hs.getFeetX() >= 0) && ((_savedFields.actionMode == ACTMODE_NONE) || (hs.getCursor() < 2))) {
			_startWalkFlag = true;
			_madsVm->scene()->_destPos.x = hs.getFeetX();
			_madsVm->scene()->_destPos.y = hs.getFeetY();
		}
		_madsVm->scene()->_destFacing = hs.getFacing();
	}

	_walkFlag = _startWalkFlag;
	*/
}

void MADSAction::checkAction() {
	/*
	if (isAction(kVerbLookAt) || isAction(kVerbThrow))
		_startWalkFlag = 0;
	*/
}

bool MADSAction::isAction(int verbId, int objectNameId, int indirectObjectId) {
	/*
	if (_activeAction.verbId != verbId)
		return false;
	if ((objectNameId != 0) && (_activeAction.objectNameId != objectNameId))
		return false;
	if ((indirectObjectId != 0) && (_activeAction.indirectObjectId != indirectObjectId))
		return false;
	*/
	return true;
}

void MADSAction::checkActionAtMousePos() {
	warning("TODO: checkActionAtMousePos");
}

} // End of namespace MADS