aboutsummaryrefslogtreecommitdiff
path: root/engines/pegasus/items/biochips/pegasuschip.cpp
blob: fa551fce30c5b7747cd834e3bb3b591242ee37bc (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
/* 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.
 *
 * Additional copyright for this file:
 * Copyright (C) 1995-1997 Presto Studios, Inc.
 *
 * 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 "pegasus/energymonitor.h"
#include "pegasus/gamestate.h"
#include "pegasus/pegasus.h"
#include "pegasus/items/biochips/pegasuschip.h"
#include "pegasus/neighborhood/tsa/fulltsa.h"
#include "pegasus/neighborhood/tsa/tinytsa.h"

namespace Pegasus {

PegasusChip::PegasusChip(const ItemID id, const NeighborhoodID neighborhood, const RoomID room, const DirectionConstant direction) :
		BiochipItem(id, neighborhood, room, direction), _recallSpot(kPegasusRecallSpotID) {
	_recallSpot.setArea(Common::Rect(kAIMiddleAreaLeft + 116, kAIMiddleAreaTop + 63, kAIMiddleAreaLeft + 184, kAIMiddleAreaTop + 91));
	_recallSpot.setHotspotFlags(kPegasusBiochipSpotFlag);
	g_allHotspots.push_back(&_recallSpot);
	setItemState(kPegasusTSA00);
}

PegasusChip::~PegasusChip() {
	g_allHotspots.removeOneHotspot(kPegasusRecallSpotID);
}

void PegasusChip::select() {
	BiochipItem::select();
	setUpPegasusChip();
}

void PegasusChip::setUpPegasusChip() {
	switch (GameState.getCurrentNeighborhood()) {
	case kCaldoriaID:
		setItemState(kPegasusCaldoria);
		break;
	case kFullTSAID:
	case kFinalTSAID:
	case kTinyTSAID:
		setItemState(kPegasusTSA10);
		break;
	case kPrehistoricID:
		if (((PegasusEngine *)g_engine)->playerHasItemID(kHistoricalLog))
			setItemState(kPegasusPrehistoric00);
		else
			setItemState(kPegasusPrehistoric10);
		break;
	case kMarsID:
		if (GameState.getMarsFinished())
			setItemState(kPegasusMars00);
		else
			setItemState(kPegasusMars10);
		break;
	case kWSCID:
		if (GameState.getWSCFinished())
			setItemState(kPegasusWSC00);
		else
			setItemState(kPegasusWSC10);
		break;
	case kNoradAlphaID:
	case kNoradDeltaID:
		if (GameState.getNoradFinished())
			setItemState(kPegasusNorad00);
		else
			setItemState(kPegasusNorad10);
		break;
	}
}

// Only does something if the chip should be announcing that the time zone is finished...
void PegasusChip::setUpPegasusChipRude() {
	switch (GameState.getCurrentNeighborhood()) {
	case kPrehistoricID:
		if (((PegasusEngine *)g_engine)->playerHasItemID(kHistoricalLog))
			setItemState(kPegasusPrehistoric00);
		break;
	case kMarsID:
		if (GameState.getMarsFinished())
			setItemState(kPegasusMars00);
		break;
	case kWSCID:
		if (GameState.getWSCFinished())
			setItemState(kPegasusWSC00);
		break;
	case kNoradAlphaID:
	case kNoradDeltaID:
		if (GameState.getNoradFinished())
			setItemState(kPegasusNorad00);
		break;
	}
}

void PegasusChip::activatePegasusHotspots() {
	switch (GameState.getCurrentNeighborhood()) {
	case kPrehistoricID:
		// WORKAROUND: Don't allow the player to recall if they don't have
		// the historical log. Otherwise, gameplay is broken when returning
		// to the TSA.
		if (!((PegasusEngine *)g_engine)->playerHasItemID(kHistoricalLog))
			return;
		// fall through
	case kMarsID:
	case kWSCID:
	case kNoradAlphaID:
	case kNoradDeltaID:
		_recallSpot.setActive();
		break;
	}
}

void PegasusChip::clickInPegasusHotspot() {
	PegasusEngine *vm = (PegasusEngine *)g_engine;

	ItemState thisState = getItemState();
	ItemState hiliteState;

	switch (thisState) {
	case kPegasusPrehistoric00:
		hiliteState = kPegasusPrehistoric01;
		break;
	case kPegasusPrehistoric10:
		hiliteState = kPegasusPrehistoric11;
		break;
	case kPegasusMars00:
		hiliteState = kPegasusMars01;
		break;
	case kPegasusMars10:
		hiliteState = kPegasusMars11;
		break;
	case kPegasusNorad00:
		hiliteState = kPegasusNorad01;
		break;
	case kPegasusNorad10:
		hiliteState = kPegasusNorad11;
		break;
	case kPegasusWSC00:
		hiliteState = kPegasusWSC01;
		break;
	case kPegasusWSC10:
		hiliteState = kPegasusWSC11;
		break;
	default:
		error("Invalid pegasus chip state");
	}

	// WORKAROUND: The original called setItemState() here. However,
	// since we're overriding select() to call setUpPegasusChip(),
	// the highlighted frame is never displayed! So, we're manually
	// setting the state and selecting the item. Also of note is that
	// setItemState() for this class is effectively useless since it
	// always gets overriden in the select() function. The only reason
	// that this doesn't end in infinite recursion is because setItemState()
	// has a check against the current state to make sure you don't call
	// select() again. </rant>
	_itemState = hiliteState;
	BiochipItem::select();

	uint32 time = g_system->getMillis();
	while (g_system->getMillis() < time + 500) {
		vm->refreshDisplay();
		g_system->delayMillis(10);
	}

	setItemState(thisState);

	if (!((Neighborhood *)g_neighborhood)->okayToJump())
		return;

	if (g_energyMonitor)
		g_energyMonitor->stopEnergyDraining();

	if (GameState.getTSAState() == kPlayerWentToPrehistoric || GameState.allTimeZonesFinished())
		vm->jumpToNewEnvironment(kFullTSAID, kTSA37, kNorth);
	else
		vm->jumpToNewEnvironment(kTinyTSAID, kTinyTSA37, kNorth);
}

} // End of namespace Pegasus