1 /*
2  * Copyright (C) 2004-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_ECONOMY_SUPPLY_H
21 #define WL_ECONOMY_SUPPLY_H
22 
23 #include "economy/trackptr.h"
24 #include "logic/map_objects/tribes/wareworker.h"
25 #include "logic/widelands.h"
26 
27 namespace Widelands {
28 
29 struct PlayerImmovable;
30 class Game;
31 class Request;
32 class Warehouse;
33 class WareInstance;
34 class Worker;
35 
36 enum class SupplyProviders { kWarehouse, kFlagOrRoad, kShip };
37 
38 /**
39  * A Supply is a virtual base class representing something that can offer
40  * wares of any type for any purpose.
41  *
42  * Subsequent calls to get_position() can return different results.
43  * If a Supply is "active", it should be transferred to a possible Request
44  * quickly. Basically, supplies in warehouses (or unused supplies that are
45  * being carried into a warehouse) are inactive, and supplies that are just
46  * sitting on a flag are active.
47  *
48  * Important note: The implementation of Supply is responsible for adding
49  * and removing itself from Economies. This rule holds true for Economy
50  * changes.
51  */
52 struct Supply : public Trackable {
53 	virtual PlayerImmovable* get_position(Game&) = 0;
54 
55 	/**
56 	 * Indicates whether this supply is active as explained above (out
57 	 * on the road network).
58 	 */
59 	virtual bool is_active() const = 0;
60 
61 	/**
62 	 * Return the type of player im/movable where the ware is now (warehouse,
63 	 * flag or ship).
64 	 */
65 	virtual SupplyProviders provider_type(Game*) const = 0;
66 
67 	/**
68 	 * Indicates whether this supply is in storage or on its way to
69 	 * storage.
70 	 *
71 	 * If this is \c false, somebody needs to find this supply a warehouse.
72 	 */
73 	virtual bool has_storage() const = 0;
74 
75 	/**
76 	 * Gets the ware type of this supply.
77 	 *
78 	 * \note This is only valid if \ref has_storage returns \c false.
79 	 */
80 	virtual void get_ware_type(WareWorker& type, DescriptionIndex& ware) const = 0;
81 
82 	/**
83 	 * Send this to the given warehouse.
84 	 *
85 	 * Sets up all the required transfers; assumes that \ref has_storage
86 	 * returns \c false.
87 	 */
88 	virtual void send_to_storage(Game&, Warehouse* wh) = 0;
89 
90 	/**
91 	 * \return the number of wares or workers that can be launched right
92 	 * now for the thing requested by the given request
93 	 */
94 	virtual uint32_t nr_supplies(const Game&, const Request&) const = 0;
95 
96 	/**
97 	 * Prepare an ware to satisfy the given request. Note that the caller
98 	 * must assign a transfer to the launched ware.
99 	 *
100 	 * \throw wexception if the request is not an ware request or no such
101 	 * ware is available in the supply.
102 	 */
103 	virtual WareInstance& launch_ware(Game&, const Request&) = 0;
104 
105 	/**
106 	 * Prepare a worker to satisfy the given request. Note that the caller
107 	 * must assign a transfer to the launched ware.
108 	 *
109 	 * \throw wexception if the request is not a worker request or no such
110 	 * worker is available in the supply.
111 	 */
112 	virtual Worker& launch_worker(Game&, const Request&) = 0;
113 };
114 }  // namespace Widelands
115 
116 #endif  // end of include guard: WL_ECONOMY_SUPPLY_H
117