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 */
22
23 #include "bladerunner/waypoints.h"
24
25 #include "bladerunner/savefile.h"
26
27 namespace BladeRunner {
28
Waypoints(BladeRunnerEngine * vm,int count)29 Waypoints::Waypoints(BladeRunnerEngine *vm, int count) {
30 _vm = vm;
31 _count = count;
32 _waypoints.resize(count);
33 }
34
getXYZ(int waypointId,float * x,float * y,float * z) const35 void Waypoints::getXYZ(int waypointId, float *x, float *y, float *z) const {
36 *x = 0;
37 *y = 0;
38 *z = 0;
39
40 if (waypointId < 0 || waypointId >= _count || !_waypoints[waypointId].present) {
41 return;
42 }
43
44 *x = _waypoints[waypointId].position.x;
45 *y = _waypoints[waypointId].position.y;
46 *z = _waypoints[waypointId].position.z;
47 }
48
getSetId(int waypointId) const49 int Waypoints::getSetId(int waypointId) const {
50 if (waypointId < 0 || waypointId >= _count || !_waypoints[waypointId].present) {
51 return -1;
52 }
53 return _waypoints[waypointId].setId;
54 }
55
set(int waypointId,int setId,Vector3 position)56 bool Waypoints::set(int waypointId, int setId, Vector3 position) {
57 if (waypointId < 0 || waypointId >= _count) {
58 return false;
59 }
60
61 _waypoints[waypointId].setId = setId;
62 _waypoints[waypointId].position = position;
63 _waypoints[waypointId].present = true;
64
65 return true;
66 }
67
reset(int waypointId)68 bool Waypoints::reset(int waypointId) {
69 if (waypointId < 0 || waypointId >= _count) {
70 return false;
71 }
72
73 _waypoints[waypointId].setId = -1;
74 _waypoints[waypointId].position.x = 0;
75 _waypoints[waypointId].position.y = 0;
76 _waypoints[waypointId].position.z = 0;
77 _waypoints[waypointId].present = false;
78
79 return true;
80 }
81
getX(int waypointId) const82 float Waypoints::getX(int waypointId) const {
83 return _waypoints[waypointId].position.x;
84 }
85
getY(int waypointId) const86 float Waypoints::getY(int waypointId) const {
87 return _waypoints[waypointId].position.y;
88 }
89
getZ(int waypointId) const90 float Waypoints::getZ(int waypointId) const {
91 return _waypoints[waypointId].position.z;
92 }
93
save(SaveFileWriteStream & f)94 void Waypoints::save(SaveFileWriteStream &f) {
95 f.writeInt(_count);
96 for (int i = 0; i < _count; ++i) {
97 Waypoint &w = _waypoints[i];
98 f.writeInt(w.setId);
99 f.writeVector3(w.position);
100 f.writeInt(w.present);
101 }
102 }
103
load(SaveFileReadStream & f)104 void Waypoints::load(SaveFileReadStream &f) {
105 _count = f.readInt();
106 for (int i = 0; i < _count; ++i) {
107 Waypoint &w = _waypoints[i];
108 w.setId = f.readInt();
109 w.position = f.readVector3();
110 w.present = f.readInt();
111 }
112 }
113
114 } // End of namespace BladeRunner
115