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_BUILDING_SETTINGS_H
21 #define WL_LOGIC_MAP_OBJECTS_TRIBES_BUILDING_SETTINGS_H
22 
23 #include <string>
24 
25 #include "logic/widelands.h"
26 #include "map_io/tribes_legacy_lookup_table.h"
27 
28 class FileRead;
29 class FileWrite;
30 
31 namespace Widelands {
32 
33 class Game;
34 class MilitarySiteDescr;
35 class ProductionSiteDescr;
36 enum class StockPolicy;
37 class TrainingSiteDescr;
38 class TribeDescr;
39 class WarehouseDescr;
40 
41 struct BuildingSettings {
BuildingSettingsBuildingSettings42 	BuildingSettings(const std::string& name, const TribeDescr& tribe)
43 	   : tribe_(tribe), descr_(name) {
44 	}
~BuildingSettingsBuildingSettings45 	virtual ~BuildingSettings() {
46 	}
47 
48 	static BuildingSettings* load(const Game&,
49 	                              const TribeDescr&,
50 	                              FileRead&,
51 	                              const TribesLegacyLookupTable& tribes_lookup_table);
52 
53 	virtual void save(const Game&, FileWrite&) const;
54 	virtual void read(const Game&, FileRead&, const TribesLegacyLookupTable&);
55 
applyBuildingSettings56 	virtual void apply(const BuildingSettings&) {
57 	}
58 
59 protected:
60 	const TribeDescr& tribe_;
61 
62 private:
63 	const std::string descr_;
64 };
65 
66 struct ProductionsiteSettings : public BuildingSettings {
67 	ProductionsiteSettings(const ProductionSiteDescr& descr, const TribeDescr& tribe);
~ProductionsiteSettingsProductionsiteSettings68 	~ProductionsiteSettings() override {
69 	}
70 	void apply(const BuildingSettings&) override;
71 
72 	void save(const Game&, FileWrite&) const override;
73 	void read(const Game&, FileRead&, const TribesLegacyLookupTable& tribes_lookup_table) override;
74 
75 	struct InputQueueSetting {
76 		const uint32_t max_fill;
77 		uint32_t desired_fill;
78 		int32_t priority;
79 	};
80 	std::map<DescriptionIndex, InputQueueSetting> ware_queues;
81 	std::map<DescriptionIndex, InputQueueSetting> worker_queues;
82 	bool stopped;
83 };
84 
85 struct MilitarysiteSettings : public BuildingSettings {
86 	MilitarysiteSettings(const MilitarySiteDescr&, const TribeDescr& tribe);
~MilitarysiteSettingsMilitarysiteSettings87 	~MilitarysiteSettings() override {
88 	}
89 	void apply(const BuildingSettings&) override;
90 
91 	void save(const Game&, FileWrite&) const override;
92 	void read(const Game&, FileRead&, const TribesLegacyLookupTable& tribes_lookup_table) override;
93 
94 	const uint32_t max_capacity;
95 	uint32_t desired_capacity;
96 	bool prefer_heroes;
97 };
98 
99 struct TrainingsiteSettings : public ProductionsiteSettings {
100 	TrainingsiteSettings(const TrainingSiteDescr&, const TribeDescr& tribe);
~TrainingsiteSettingsTrainingsiteSettings101 	~TrainingsiteSettings() override {
102 	}
103 	void apply(const BuildingSettings&) override;
104 
105 	void save(const Game&, FileWrite&) const override;
106 	void read(const Game&, FileRead&, const TribesLegacyLookupTable& tribes_lookup_table) override;
107 
108 	const uint32_t max_capacity;
109 	uint32_t desired_capacity;
110 };
111 
112 struct WarehouseSettings : public BuildingSettings {
113 	WarehouseSettings(const WarehouseDescr&, const TribeDescr& tribe);
~WarehouseSettingsWarehouseSettings114 	~WarehouseSettings() override {
115 	}
116 	void apply(const BuildingSettings&) override;
117 
118 	void save(const Game&, FileWrite&) const override;
119 	void read(const Game&, FileRead&, const TribesLegacyLookupTable& tribes_lookup_table) override;
120 
121 	std::map<DescriptionIndex, StockPolicy> ware_preferences;
122 	std::map<DescriptionIndex, StockPolicy> worker_preferences;
123 	const bool launch_expedition_allowed;
124 	bool launch_expedition;
125 };
126 
127 }  // namespace Widelands
128 
129 #endif  // end of include guard: WL_LOGIC_MAP_OBJECTS_TRIBES_BUILDING_SETTINGS_H
130