aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/game/chicken_dispensor.cpp
blob: 89873dcc4d0f5f5b715b933137219a58c882a3ae (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
/* 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 "titanic/game/chicken_dispensor.h"
#include "titanic/carry/chicken.h"
#include "titanic/core/project_item.h"
#include "titanic/pet_control/pet_control.h"

namespace Titanic {

BEGIN_MESSAGE_MAP(CChickenDispensor, CBackground)
	ON_MESSAGE(StatusChangeMsg)
	ON_MESSAGE(MovieEndMsg)
	ON_MESSAGE(ActMsg)
	ON_MESSAGE(LeaveViewMsg)
	ON_MESSAGE(EnterViewMsg)
	ON_MESSAGE(MouseDragStartMsg)
	ON_MESSAGE(TurnOff)
END_MESSAGE_MAP()

CChickenDispensor::CChickenDispensor() : CBackground(),
	_disabled(false), _dispenseMode(DISPENSE_NONE), _dispensed(false) {
}

void CChickenDispensor::save(SimpleFile *file, int indent) {
	file->writeNumberLine(1, indent);
	file->writeNumberLine(_disabled, indent);
	file->writeNumberLine(_dispenseMode, indent);
	file->writeNumberLine(_dispensed, indent);
	CBackground::save(file, indent);
}

void CChickenDispensor::load(SimpleFile *file) {
	file->readNumber();
	_disabled = file->readNumber();
	_dispenseMode = (DispenseMode)file->readNumber();
	_dispensed = file->readNumber();

	CBackground::load(file);
}

bool CChickenDispensor::StatusChangeMsg(CStatusChangeMsg *msg) {
	msg->execute("SGTRestLeverAnimation");
	DispenseMode dispenseMode = _dispensed ? DISPENSE_NONE : _dispenseMode;
	CPetControl *pet = getPetControl();
	CGameObject *obj;

	for (obj = pet->getFirstObject(); obj; obj = pet->getNextObject(obj)) {
		if (obj->isEquals("Chicken")) {
			petDisplayMessage(1, ONE_CHICKEN_PER_CUSTOMER);
			return true;
		}
	}

	for (obj = getMailManFirstObject(); obj; obj = getNextMail(obj)) {
		if (obj->isEquals("Chicken")) {
			petDisplayMessage(1, ONE_CHICKEN_PER_CUSTOMER);
			return true;
		}
	}

	switch (dispenseMode) {
	case DISPENSE_NONE:
		petDisplayMessage(1, ONE_ALLOCATED_CHICKEN_PER_CUSTOMER);
		break;

	case DISPENSE_HOT:
	case DISPENSE_COLD:
		_dispensed = true;
		setVisible(true);

		if (_disabled) {
			playMovie(0, 12, MOVIE_NOTIFY_OBJECT | MOVIE_WAIT_FOR_FINISH);
			playSound("z#400.wav");
		} else {
			playMovie(12, 16, MOVIE_NOTIFY_OBJECT | MOVIE_WAIT_FOR_FINISH);
		}
		break;

	default:
		break;
	}

	return true;
}

bool CChickenDispensor::MovieEndMsg(CMovieEndMsg *msg) {
	int movieFrame = getMovieFrame();
	
	if (movieFrame == 16) {
		// Dispensed a chicken
		_cursorId = CURSOR_HAND;
		playSound("b#50.wav", 50);
		CActMsg actMsg("Dispense Chicken");
		actMsg.execute("Chicken");

		if (_dispenseMode == DISPENSE_HOT) {
			// A properly hot chicken is dispensed, no further ones will be
			// until the current one is used up, and the fuse in Titania's
			// fusebox is removed and replaced
			_dispenseMode = DISPENSE_NONE;
		} else {
			// WORKAROUND: If the fuse for the dispensor is removed in Titania's fusebox,
			// make the dispensed chicken already cold
			CChicken::_temperature = 0;
		}
	} else if (_dispensed) {
		// Chicken dispensed whilst dispensor is "disabled", which basically
		// spits the chicken out at high speed directly into the SuccUBus
		_cursorId = CURSOR_ARROW;
		loadFrame(0);
		setVisible(false);
		if (_dispenseMode == DISPENSE_COLD)
			_dispensed = false;
	} else {
		// Doors closing as the view is being left
		loadFrame(0);
		setVisible(false);
		changeView("SgtLobby.Node 1.N");
	}

	return true;
}

bool CChickenDispensor::ActMsg(CActMsg *msg) {
	if (msg->_action == "EnableObject")
		_disabled = false;
	else if (msg->_action == "DisableObject")
		_disabled = true;
	else if (msg->_action == "IncreaseQuantity")
		_dispenseMode = DISPENSE_COLD;
	else if (msg->_action == "DecreaseQuantity")
		_dispenseMode = DISPENSE_HOT;

	return true;
}

bool CChickenDispensor::LeaveViewMsg(CLeaveViewMsg *msg) {
	return true;
}

bool CChickenDispensor::EnterViewMsg(CEnterViewMsg *msg) {
	playSound("b#51.wav");
	_dispensed = false;
	_cursorId = CURSOR_ARROW;
	return true;
}

bool CChickenDispensor::MouseDragStartMsg(CMouseDragStartMsg *msg) {
	if (getMovieFrame() == 16) {
		setVisible(false);
		loadFrame(0);
		_cursorId = CURSOR_ARROW;
		_dispensed = true;

		CVisibleMsg visibleMsg;
		visibleMsg.execute("Chicken");
		CPassOnDragStartMsg passMsg(msg->_mousePos, 1);
		passMsg.execute("Chicken");

		msg->_dragItem = getRoot()->findByName("Chicken");
	}

	return true;
}

bool CChickenDispensor::TurnOff(CTurnOff *msg) {
	if (getMovieFrame() != 16)
		setVisible(false);
	playMovie(16, 12, MOVIE_NOTIFY_OBJECT | MOVIE_WAIT_FOR_FINISH);
	_dispensed = false;

	return true;
}

} // End of namespace Titanic