-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
208 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "MarketInstance.hpp" | ||
|
||
using namespace OpenVic; | ||
|
||
bool MarketInstance::setup(GoodInstanceManager& new_good_instance_manager) { | ||
good_instance_manager = &new_good_instance_manager; | ||
return true; | ||
} | ||
|
||
void MarketInstance::place_market_sell_order(const MarketSellOrder market_sell_order) { | ||
GoodDefinition const* const good = market_sell_order.get_good(); | ||
GoodInstance* const good_instance = good_instance_manager->get_good_instance_by_identifier(good->get_identifier()); | ||
good_instance->add_market_sell_order(market_sell_order); | ||
} | ||
|
||
void MarketInstance::execute_orders() { | ||
std::vector<GoodInstance>& good_instances = good_instance_manager->get_good_instances(); | ||
for (GoodInstance& good_instance : good_instances) { | ||
good_instance.execute_orders(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include "openvic-simulation/economy/GoodInstance.hpp" | ||
#include "openvic-simulation/economy/trading/MarketSellOrder.hpp" | ||
|
||
namespace OpenVic { | ||
struct MarketInstance { | ||
private: | ||
GoodInstanceManager* PROPERTY(good_instance_manager); | ||
public: | ||
bool setup(GoodInstanceManager& new_good_instance_manager); | ||
void place_market_sell_order(const MarketSellOrder market_sell_order); | ||
void execute_orders(); | ||
}; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/openvic-simulation/economy/trading/MarketSellOrder.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "MarketSellOrder.hpp" | ||
|
||
using namespace OpenVic; | ||
|
||
GoodMarketSellOrder::GoodMarketSellOrder( | ||
const fixed_point_t new_quantity, | ||
const std::function<void(const SellResult)> new_after_trade | ||
): | ||
quantity { new_quantity }, | ||
after_trade { new_after_trade } | ||
{} | ||
|
||
MarketSellOrder::MarketSellOrder( | ||
GoodDefinition const& new_good, | ||
const fixed_point_t new_quantity, | ||
const std::function<void(const SellResult)> new_after_trade | ||
): GoodMarketSellOrder(new_quantity, new_after_trade), | ||
good { &new_good } | ||
{} |
32 changes: 32 additions & 0 deletions
32
src/openvic-simulation/economy/trading/MarketSellOrder.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include "openvic-simulation/economy/GoodDefinition.hpp" | ||
#include "openvic-simulation/economy/trading/SellResult.hpp" | ||
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp" | ||
#include "openvic-simulation/utility/Getters.hpp" | ||
|
||
namespace OpenVic { | ||
struct GoodMarketSellOrder { | ||
private: | ||
const fixed_point_t PROPERTY(quantity); | ||
const std::function<void(const SellResult)> PROPERTY(after_trade); | ||
|
||
public: | ||
GoodMarketSellOrder( | ||
const fixed_point_t new_quantity, | ||
const std::function<void(const SellResult)> new_after_trade | ||
); | ||
}; | ||
|
||
struct MarketSellOrder : GoodMarketSellOrder { | ||
private: | ||
GoodDefinition const* const PROPERTY(good); | ||
|
||
public: | ||
MarketSellOrder( | ||
GoodDefinition const& new_good, | ||
const fixed_point_t new_quantity, | ||
const std::function<void(const SellResult)> new_after_trade | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "SellResult.hpp" | ||
|
||
using namespace OpenVic; | ||
|
||
SellResult::SellResult( | ||
const fixed_point_t new_quantity_sold, | ||
const fixed_point_t new_money_gained | ||
) : | ||
quantity_sold { new_quantity_sold }, | ||
money_gained { new_money_gained } | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp" | ||
|
||
namespace OpenVic { | ||
struct SellResult { | ||
private: | ||
fixed_point_t PROPERTY(quantity_sold); | ||
fixed_point_t PROPERTY(money_gained); | ||
public: | ||
SellResult( | ||
const fixed_point_t new_quantity_sold, | ||
const fixed_point_t new_money_gained | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.