Symphony Of Empires
building.cpp
Go to the documentation of this file.
1 // Symphony of Empires
2 // Copyright (C) 2021, Symphony of Empires contributors
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (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, see <https://www.gnu.org/licenses/>.
16 //
17 // ----------------------------------------------------------------------------
18 // Name:
19 // building.cpp
20 //
21 // Abstract:
22 // Does some important stuff.
23 // ----------------------------------------------------------------------------
24 
25 #include <algorithm>
26 #include "eng3d/serializer.hpp"
27 
28 #include "building.hpp"
29 #include "world.hpp"
30 #include "province.hpp"
31 
33 bool Building::can_do_output(const Province& province, const std::vector<CommodityId>& inputs) const {
34  auto& world = World::get_instance();
35  // Check that we have enough stockpile
36  for(const auto& commodity : world.commodities)
37  if(std::find(std::begin(inputs), std::end(inputs), commodity.get_id()) != std::end(inputs))
38  if(province.products[commodity].supply == 0.f)
39  return false;
40  return this->level > 0.f;
41 }
42 
43 void Building::work_on_unit(const UnitType& unit_type) {
44  this->working_unit_type_id = unit_type.get_id();
45  this->req_goods_for_unit = unit_type.req_goods;
46  this->_is_wrking_on_unit = true;
47 }
A single province, which is used to simulate economy in a "bulk-tiles" way instead of doing economica...
Definition: province.hpp:48
std::vector< Product > products
Definition: province.hpp:109
static World & get_instance()
Definition: world.hpp:121
float level
Definition: building.hpp:167
bool _is_wrking_on_unit
Definition: building.hpp:170
std::vector< std::pair< CommodityId, float > > req_goods_for_unit
Definition: building.hpp:174
UnitTypeId working_unit_type_id
Definition: building.hpp:171
void work_on_unit(const UnitType &unit_type)
Definition: building.cpp:43
bool can_do_output(const Province &province, const std::vector< CommodityId > &inputs) const
Checks if the building can produce output (if it has enough input)
Definition: building.cpp:33
constexpr Id get_id() const
Definition: entity.hpp:152
Defines a type of unit, it can be a tank, garrison, infantry, etc this is moddable via a lua script a...
Definition: unit.hpp:44
std::vector< std::pair< CommodityId, float > > req_goods
Definition: unit.hpp:54