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
|
/***************************************************************************
* Copyright (C) 2005-2013 by the FIFE team *
* http://www.fifengine.net *
* This file is part of FIFE. *
* *
* FIFE is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library 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 *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
// Standard C++ library includes
// 3rd party library includes
// FIFE includes
// These includes are split up in two parts, separated by one empty line
// First block: files included from the FIFE root src directory
// Second block: files included from the same folder
#include "util/log/logger.h"
#include "model/metamodel/object.h"
#include "model/structures/location.h"
#include "route.h"
namespace FIFE {
static Logger _log(LM_STRUCTURES);
Route::Route(const Location& start, const Location& end):
m_status(ROUTE_CREATED),
m_startNode(start),
m_endNode(end),
m_walked(0),
m_sessionId(-1),
m_rotation(0),
m_replanned(false),
m_costId(""),
m_object(NULL) {
}
Route::~Route() {
}
void Route::setRouteStatus(RouteStatusInfo status) {
if (m_status != status) {
m_status = status;
}
}
RouteStatusInfo Route::getRouteStatus() {
return m_status;
}
void Route::setStartNode(const Location& node) {
m_startNode = node;
if (m_status != ROUTE_CREATED) {
m_status = ROUTE_CREATED;
if (!m_path.empty()) {
m_path.clear();
}
m_walked = 1;
}
}
const Location& Route::getStartNode() {
return m_startNode;
}
void Route::setEndNode(const Location& node) {
if (m_status != ROUTE_CREATED) {
m_status = ROUTE_CREATED;
if (!m_path.empty()) {
m_startNode = *m_current;
m_path.clear();
}
m_walked = 1;
}
m_endNode = node;
}
const Location& Route::getEndNode() {
return m_endNode;
}
const Location& Route::getCurrentNode() {
if (m_path.empty()) {
return m_startNode;
}
if (m_current == m_path.end()) {
return m_path.back();
}
return *m_current;
}
const Location& Route::getPreviousNode() {
if (m_path.empty()) {
return m_startNode;
}
if (m_current != m_path.begin()) {
--m_current;
const Location& loc = *m_current;
++m_current;
return loc;
}
return *m_current;
}
const Location& Route::getNextNode() {
if (m_path.empty()) {
return m_startNode;
}
if (m_current != m_path.end()) {
++m_current;
if (m_current != m_path.end()) {
const Location& loc = *m_current;
--m_current;
return loc;
}
--m_current;
}
return *m_current;
}
bool Route::walkToNextNode(int32_t step) {
if (m_path.empty() || step == 0) {
return false;
}
int32_t pos = static_cast<int32_t>(m_walked) + step;
if (pos > static_cast<int32_t>(m_path.size()) || pos < 0) {
return false;
}
if (step > 0) {
for (int32_t i = 0; i < step; ++i, ++m_current);
} else {
for (int32_t i = 0; i > step; --i, --m_current);
}
m_walked += step;
return true;
}
bool Route::reachedEnd() {
if (m_path.empty()) {
return true;
}
return m_current == m_path.end();
}
void Route::setPath(const Path& path) {
m_path = path;
if (!m_path.empty()) {
m_status = ROUTE_SOLVED;
m_current = m_path.begin();
m_startNode = m_path.front();
m_endNode = m_path.back();
}
if (!isMultiCell()) {
m_replanned = false;
}
m_walked = 1;
}
Path Route::getPath() {
return m_path;
}
void Route::cutPath(uint32_t length) {
if (length == 0) {
if (!m_path.empty()) {
m_startNode = *m_current;
m_endNode = *m_current;
m_path.clear();
m_current = m_path.end();
}
m_status = ROUTE_CREATED;
m_walked = 1;
m_replanned = true;
return;
} else if (length >= m_path.size()) {
return;
}
uint32_t newend = m_walked + length - 1;
if (newend > m_path.size()) {
return;
}
m_path.resize(newend);
m_endNode = m_path.back();
m_replanned = true;
}
void Route::setReplanned(bool replanned) {
m_replanned = replanned;
}
bool Route::isReplanned() {
return m_replanned;
}
uint32_t Route::getPathLength() {
return m_path.size();
}
uint32_t Route::getWalkedLength() {
return m_walked;
}
void Route::setSessionId(int32_t id) {
m_sessionId = id;
}
int32_t Route::getSessionId() {
return m_sessionId;
}
void Route::setRotation(int32_t rotation) {
m_rotation = rotation;
}
int32_t Route::getRotation() {
return m_rotation;
}
void Route::setCostId(const std::string& cost) {
m_costId = cost;
}
const std::string& Route::getCostId() {
return m_costId;
}
bool Route::isMultiCell() {
if (m_object) {
return m_object->isMultiObject();
}
return false;
}
void Route::setOccupiedArea(const std::vector<ModelCoordinate>& area) {
m_area = area;
}
const std::vector<ModelCoordinate>& Route::getOccupiedArea() {
return m_area;
}
std::vector<ModelCoordinate> Route::getOccupiedCells(int32_t rotation) {
if (m_object) {
return m_object->getMultiObjectCoordinates(rotation);
}
std::vector<ModelCoordinate> coords;
return coords;
}
int32_t Route::getZStepRange() {
if (!m_object) {
return -1;
}
return m_object->getZStepRange();
}
bool Route::isAreaLimited() {
if (m_object) {
if (!m_object->getWalkableAreas().empty()) {
return true;
}
}
return false;
}
const std::list<std::string> Route::getLimitedAreas() {
std::list<std::string> areas;
if (m_object) {
areas = m_object->getWalkableAreas();
}
return areas;
}
void Route::setObject(Object* obj) {
m_object = obj;
}
Object* Route::getObject() {
return m_object;
}
} // FIFE
|