/*
* Copyright (C) 2004-2025 by the Widelands Development Team
*
* 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, see .
*
*/
#ifndef WL_ECONOMY_ROUTE_H
#define WL_ECONOMY_ROUTE_H
#include
#include "economy/iroute.h"
#include "io/fileread.h"
#include "io/filewrite.h"
#include "logic/map_objects/map_object.h"
namespace Widelands {
class EditorGameBase;
class MapObjectLoader;
struct Flag;
struct MapObjectSaver;
/**
* Route stores a route from flag to flag.
* The number of steps is the number of flags stored minus one.
*/
struct Route : public IRoute {
friend struct Router;
friend class Request;
Route() = default;
void init(int32_t) override;
[[nodiscard]] int32_t get_totalcost() const {
return totalcost_;
}
[[nodiscard]] int32_t get_nrsteps() const {
return route_.size() - 1;
}
Flag& get_flag(EditorGameBase&, std::vector::size_type) const;
Flag* get_flag_raw(EditorGameBase&, std::vector::size_type) const;
void trim_start(int32_t count);
void truncate(int32_t count);
struct LoadData {
std::vector flags;
};
void load(LoadData&, FileRead&);
void load_pointers(const LoadData&, MapObjectLoader&);
void save(FileWrite&, EditorGameBase&, MapObjectSaver&);
void insert_as_first(RoutingNode* node) override;
private:
int32_t totalcost_{0};
std::vector> route_; ///< includes start and end flags
};
} // namespace Widelands
#endif // end of include guard: WL_ECONOMY_ROUTE_H