-
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
190 additions
and
16 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,25 @@ | ||
#include "MarketInstance.hpp" | ||
|
||
#include "openvic-simulation/economy/GoodDefinition.hpp" | ||
#include "openvic-simulation/economy/GoodInstance.hpp" | ||
#include "openvic-simulation/economy/trading/MarketSellOrder.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.get_quantity(), market_sell_order.get_after_trade()); | ||
} | ||
|
||
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(); | ||
}; | ||
} |
13 changes: 13 additions & 0 deletions
13
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,13 @@ | ||
#include "MarketSellOrder.hpp" | ||
|
||
using namespace OpenVic; | ||
|
||
MarketSellOrder::MarketSellOrder( | ||
GoodDefinition const& new_good, | ||
const fixed_point_t new_quantity, | ||
const std::function<void(const SellResult)> new_after_trade | ||
): | ||
good { &new_good }, | ||
quantity { new_quantity }, | ||
after_trade { new_after_trade } | ||
{} |
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
#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 MarketSellOrder { | ||
private: | ||
GoodDefinition const* const PROPERTY(good); | ||
const fixed_point_t PROPERTY(quantity); | ||
const std::function<void(const SellResult)> PROPERTY(after_trade); | ||
|
||
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
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
Oops, something went wrong.