1 /* 2 * Copyright (C) 2002-2020 by the Widelands Development Team 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 * 18 */ 19 20 #ifndef WL_LOGIC_MAP_OBJECTS_TRIBES_FERRY_H 21 #define WL_LOGIC_MAP_OBJECTS_TRIBES_FERRY_H 22 23 #include <memory> 24 25 #include "base/macros.h" 26 #include "logic/map_objects/tribes/carrier.h" 27 28 namespace Widelands { 29 30 struct FerryFleet; 31 struct Waterway; 32 struct Coords; 33 34 class FerryDescr : public CarrierDescr { 35 public: 36 FerryDescr(const std::string& init_descname, const LuaTable& table, const Tribes& tribes); ~FerryDescr()37 ~FerryDescr() override { 38 } 39 40 uint32_t movecaps() const override; 41 42 protected: 43 Bob& create_object() const override; 44 45 private: 46 DISALLOW_COPY_AND_ASSIGN(FerryDescr); 47 }; 48 49 /** 50 * A ferry is a very special worker that rows along waterways. 51 * It works exactly like a carrier, except that it swims. 52 */ 53 struct Ferry : public Carrier { 54 friend struct MapBobdataPacket; 55 56 MO_DESCR(FerryDescr) 57 58 explicit Ferry(const FerryDescr& ferry_descr); ~FerryFerry59 ~Ferry() override { 60 } 61 62 bool init(EditorGameBase&) override; 63 void set_economy(Game&, Economy*, WareWorker); 64 65 FerryFleet* get_fleet() const; 66 67 Waterway* get_destination(Game& game) const; 68 void set_destination(Game& game, Waterway* ww); 69 70 void init_auto_task(Game& game) override; 71 void start_task_unemployed(Game&); 72 void start_task_row(Game&, Waterway*); 73 74 bool unemployed(); 75 76 private: 77 friend struct FerryFleet; 78 FerryFleet* fleet_; 79 80 std::unique_ptr<Coords> destination_; 81 82 bool init_fleet(); 83 void set_fleet(FerryFleet* fleet); 84 85 static const Task taskUnemployed; 86 static const Task taskRow; 87 void unemployed_update(Game&, State&); 88 void row_update(Game&, State&); 89 90 uint32_t unemployed_since_; 91 92 protected: 93 void cleanup(EditorGameBase&) override; 94 95 struct Loader : public Carrier::Loader { 96 public: LoaderFerry::Loader97 Loader() { 98 } 99 void load(FileRead&) override; 100 101 protected: 102 const Task* get_task(const std::string& name) override; 103 }; 104 105 Loader* create_loader() override; 106 107 public: 108 void do_save(EditorGameBase&, MapObjectSaver&, FileWrite&) override; 109 }; 110 } // namespace Widelands 111 112 #endif // end of include guard: WL_LOGIC_MAP_OBJECTS_TRIBES_FERRY_H 113