aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/economy/GoodInstance.hpp
blob: e9f22987e49b18fcec7f6e41c61e4b043ffa4b97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once

#include <vector>

#include "openvic-simulation/economy/GoodDefinition.hpp"
#include "openvic-simulation/economy/trading/SellResult.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#include "openvic-simulation/types/HasIdentifier.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
#include "openvic-simulation/utility/Getters.hpp"

namespace OpenVic {
   struct GoodInstanceManager;

   struct GoodInstance : HasIdentifierAndColour {
      friend struct GoodInstanceManager;

   private:
      GoodDefinition const& PROPERTY(good_definition);
      fixed_point_t PROPERTY(price);
      bool PROPERTY(is_available);
      fixed_point_t supply_running_total;
      fixed_point_t PROPERTY(total_supply_yesterday);
      std::vector<fixed_point_t> PROPERTY(market_sell_order_quantities);
      std::vector<std::function<void(SellResult)>> PROPERTY(market_sell_order_callbacks);
      
      GoodInstance(GoodDefinition const& new_good_definition);

   public:
      GoodInstance(GoodInstance&&) = default;

      void add_market_sell_order(const fixed_point_t quantity, const std::function<void(SellResult)> callback);
      void clear_orders();
   };

   struct GoodInstanceManager {
   private:
      IdentifierRegistry<GoodInstance> IDENTIFIER_REGISTRY(good_instance);

   public:
      IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS(good_instance);
      bool setup(GoodDefinitionManager const& good_definition_manager);
   };
}