aboutsummaryrefslogtreecommitdiff
path: root/engines/pegasus/neighborhood/mars/shuttleenergymeter.cpp
blob: cd08dbae6a4b587088e819243bee1e2e5f3ad71d (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
/* 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/neighborhood/mars/constants.h"
#include "pegasus/neighborhood/mars/shuttleenergymeter.h"

namespace Pegasus {

ShuttleEnergyMeter::ShuttleEnergyMeter() : FaderAnimation(kNoDisplayElement) {
	setBounds(kShuttleEnergyLeft, kShuttleEnergyTop, kShuttleEnergyLeft + kShuttleEnergyWidth,
			kShuttleEnergyTop + kShuttleEnergyHeight);
	setDisplayOrder(kShuttleStatusOrder);
	setFaderValue(0);
}

void ShuttleEnergyMeter::initShuttleEnergyMeter() {
	_meterImage.getImageFromPICTFile("Images/Mars/Shuttle Energy.pict");
	_lowWarning.getImageFromPICTFile("Images/Mars/Shuttle Low Energy.pict");
	startDisplaying();
	show();
}

void ShuttleEnergyMeter::disposeShuttleEnergyMeter() {
	stopFader();
	hide();
	stopDisplaying();
	_meterImage.deallocateSurface();
	_lowWarning.deallocateSurface();
}

void ShuttleEnergyMeter::draw(const Common::Rect &) {
	int32 currentValue = getFaderValue();

	Common::Rect r1, r2, bounds;
	getBounds(bounds);

	if (currentValue < kLowShuttleEnergy) {
		_lowWarning.getSurfaceBounds(r1);
		r2 = r1;
		r2.moveTo(bounds.left, bounds.top);
		_lowWarning.copyToCurrentPort(r1, r2);
	}

	_meterImage.getSurfaceBounds(r1);
	r1.right = r1.left + r1.width() * currentValue / kFullShuttleEnergy;
	r2 = r1;
	r2.moveTo(bounds.left + 102, bounds.top + 6);
	_meterImage.copyToCurrentPort(r1, r2);
}

void ShuttleEnergyMeter::powerUpMeter() {
	FaderMoveSpec moveSpec;
	moveSpec.makeTwoKnotFaderSpec(kThirtyTicksPerSecond, 0, 0, 45, kFullShuttleEnergy);
	startFader(moveSpec);
}

void ShuttleEnergyMeter::setEnergyValue(const int32 value) {
	stopFader();
	FaderMoveSpec moveSpec;
	moveSpec.makeTwoKnotFaderSpec(kFifteenTicksPerSecond, value * 3, value, kFullShuttleEnergy * 3, kFullShuttleEnergy);
	startFader(moveSpec);
}

void ShuttleEnergyMeter::drainForTractorBeam() {
	stopFader();
	TimeValue startTime = 0, stopTime;
	int32 startValue = getFaderValue(), stopValue;

	if (startValue < kTractorBeamEnergy) {
		stopTime = startValue * kTractorBeamTime / kTractorBeamEnergy;
		stopValue = 0;
	} else {
		stopTime = kTractorBeamTime;
		stopValue = startValue - kTractorBeamEnergy;
	}

	FaderMoveSpec moveSpec;
	moveSpec.makeTwoKnotFaderSpec(kTractorBeamScale, startTime, startValue, stopTime, stopValue);
	startFader(moveSpec);
}

int32 ShuttleEnergyMeter::getEnergyValue() const {
	return getFaderValue();
}

void ShuttleEnergyMeter::dropEnergyValue(const int32 delta) {
	setEnergyValue(getFaderValue() - delta);
}

bool ShuttleEnergyMeter::enoughEnergyForTractorBeam() const {
	return getEnergyValue() >= kTractorBeamEnergy;
}

} // End of namespace Pegasus