diff --git a/.gitignore b/.gitignore index 051f093..ab148c2 100644 --- a/.gitignore +++ b/.gitignore @@ -339,3 +339,5 @@ ASALocalRun/ # BeatPulse healthcheck temp database healthchecksdb +/Pop Engine/.DS_Store +/Pop Engine/._.DS_Store diff --git a/Pop Engine/._Career.cpp b/Pop Engine/._Career.cpp new file mode 100644 index 0000000..b68d0d8 Binary files /dev/null and b/Pop Engine/._Career.cpp differ diff --git a/Pop Engine/._Career.h b/Pop Engine/._Career.h new file mode 100644 index 0000000..41d42f6 Binary files /dev/null and b/Pop Engine/._Career.h differ diff --git a/Pop Engine/._Engine.cpp b/Pop Engine/._Engine.cpp new file mode 100644 index 0000000..8b2e237 Binary files /dev/null and b/Pop Engine/._Engine.cpp differ diff --git a/Pop Engine/._Engine.h b/Pop Engine/._Engine.h new file mode 100644 index 0000000..2d600e1 Binary files /dev/null and b/Pop Engine/._Engine.h differ diff --git a/Pop Engine/._Land.cpp b/Pop Engine/._Land.cpp new file mode 100644 index 0000000..3c62811 Binary files /dev/null and b/Pop Engine/._Land.cpp differ diff --git a/Pop Engine/._Land.h b/Pop Engine/._Land.h new file mode 100644 index 0000000..881e9ee Binary files /dev/null and b/Pop Engine/._Land.h differ diff --git a/Pop Engine/._Market.cpp b/Pop Engine/._Market.cpp new file mode 100644 index 0000000..22f4214 Binary files /dev/null and b/Pop Engine/._Market.cpp differ diff --git a/Pop Engine/._Market.h b/Pop Engine/._Market.h new file mode 100644 index 0000000..d8e26e7 Binary files /dev/null and b/Pop Engine/._Market.h differ diff --git a/Pop Engine/._Need.cpp b/Pop Engine/._Need.cpp new file mode 100644 index 0000000..e7f769c Binary files /dev/null and b/Pop Engine/._Need.cpp differ diff --git a/Pop Engine/._Need.h b/Pop Engine/._Need.h new file mode 100644 index 0000000..73029b7 Binary files /dev/null and b/Pop Engine/._Need.h differ diff --git a/Pop Engine/._Pop Engine.cpp b/Pop Engine/._Pop Engine.cpp new file mode 100644 index 0000000..d502b83 Binary files /dev/null and b/Pop Engine/._Pop Engine.cpp differ diff --git a/Pop Engine/._Pop Engine.vcxproj b/Pop Engine/._Pop Engine.vcxproj new file mode 100644 index 0000000..fb262cd Binary files /dev/null and b/Pop Engine/._Pop Engine.vcxproj differ diff --git a/Pop Engine/._Pop Engine.vcxproj.filters b/Pop Engine/._Pop Engine.vcxproj.filters new file mode 100644 index 0000000..a61bab7 Binary files /dev/null and b/Pop Engine/._Pop Engine.vcxproj.filters differ diff --git a/Pop Engine/._Population.cpp b/Pop Engine/._Population.cpp new file mode 100644 index 0000000..19c2586 Binary files /dev/null and b/Pop Engine/._Population.cpp differ diff --git a/Pop Engine/._Population.h b/Pop Engine/._Population.h new file mode 100644 index 0000000..9866333 Binary files /dev/null and b/Pop Engine/._Population.h differ diff --git a/Pop Engine/._Production.cpp b/Pop Engine/._Production.cpp new file mode 100644 index 0000000..2a33176 Binary files /dev/null and b/Pop Engine/._Production.cpp differ diff --git a/Pop Engine/._Production.h b/Pop Engine/._Production.h new file mode 100644 index 0000000..5f2410b Binary files /dev/null and b/Pop Engine/._Production.h differ diff --git a/Pop Engine/._SellProduction.cpp b/Pop Engine/._SellProduction.cpp new file mode 100644 index 0000000..554bd73 Binary files /dev/null and b/Pop Engine/._SellProduction.cpp differ diff --git a/Pop Engine/._SellProduction.h b/Pop Engine/._SellProduction.h new file mode 100644 index 0000000..892f08b Binary files /dev/null and b/Pop Engine/._SellProduction.h differ diff --git a/Pop Engine/Career.cpp b/Pop Engine/Career.cpp index 47455ff..b65b668 100644 --- a/Pop Engine/Career.cpp +++ b/Pop Engine/Career.cpp @@ -1 +1,5 @@ #include "Career.h" + +shared_ptr Career::get_production(){ + return pdt; +} diff --git a/Pop Engine/Career.h b/Pop Engine/Career.h index ce2fe44..aeac983 100644 --- a/Pop Engine/Career.h +++ b/Pop Engine/Career.h @@ -10,6 +10,7 @@ using namespace std; class Career { public: + shared_ptr get_production(void); private: // The prodution which this career makes. diff --git a/Pop Engine/Land.cpp b/Pop Engine/Land.cpp index a6fc3f7..ee2f8a4 100644 --- a/Pop Engine/Land.cpp +++ b/Pop Engine/Land.cpp @@ -1 +1,5 @@ #include "Land.h" + +shared_ptr Land::get_market(){ + return mkt; +} diff --git a/Pop Engine/Land.h b/Pop Engine/Land.h index c8e4db8..97e0fe3 100644 --- a/Pop Engine/Land.h +++ b/Pop Engine/Land.h @@ -4,14 +4,18 @@ #include #include -#include "Population.h" #include "Production.h" +class Market; + +class Population; + using namespace std; class Land { public: + shared_ptr get_market(void); private: vector> pops; diff --git a/Pop Engine/Market.cpp b/Pop Engine/Market.cpp index 10d2cdd..310c8e2 100644 --- a/Pop Engine/Market.cpp +++ b/Pop Engine/Market.cpp @@ -1 +1,37 @@ #include "Market.h" +#include "Production.h" +#include "SellProduction.h" + +#include +#include + + +shared_ptr Market::get_sell_production(shared_ptr p_pdt){ + auto p_sl_pdt_i = sl_pdts.find(p_pdt); + + return p_sl_pdt_i->second; +} + +shared_ptr Market::get_parent_market(){ + return pae_mkts; +} + + +shared_ptr Market::ask_for_selling_right(shared_ptr p_pop, shared_ptr p_pdt) { + shared_ptr p_pm(new PermitManager(p_pop, p_pdt, this)); + pmt_mgrs_buying.push_back(p_pm); + return p_pm; +} + +shared_ptr Market::ask_for_buying_right(shared_ptr p_pop) { + shared_ptr p_pm(new PermitManager(p_pop, this)); + pmt_mgrs_buying.push_back(p_pm); + return p_pm; +} + +shared_ptr Market::send_production_to_sell(shared_ptr p_pm, float price, float amount) { + shared_ptr pn_req(new Request(p_pm, price, amount)); + auto p_spt = get_sell_production(p_pm->p_dpt); + p_spt->new_request(pn_req); + return pn_req; +} \ No newline at end of file diff --git a/Pop Engine/Market.h b/Pop Engine/Market.h index 1238433..fe9f786 100644 --- a/Pop Engine/Market.h +++ b/Pop Engine/Market.h @@ -2,22 +2,121 @@ #include #include +#include #include "Population.h" #include "SellProduction.h" +#include "Land.h" using namespace std; +#define BUY_DEFINE 0 +#define SELL_DEFINE 1 + +using Goods = float; +using Money = float; +// Money, Goods which the market returns to the seller or customer. +typedef pair MarketReturn; +// Information about price and need of a certain procuction in the market. +typedef pair MarketInfo; +// The Right to sell in this market. +typedef uint32_t SellingPermit; +// The Right to buy producrtion in this market. +typedef uint32_t BuyingPermit; + +typedef uint32_t Permit; +// The number to identify certain population. +typedef uint32_t PopID; + + +// 市场准入证书 +struct PermitManager { + const uint16_t type; + const shared_ptr p_pop; + const shared_ptr p_dpt; + const Market* p_mkt; + + using PPOP = shared_ptr; + using PPDT = shared_ptr; + + // 市场购买许可 + PermitManager(PPOP pt_pop, PPDT pt_pdt, Market *pt_mkt) : type(BUY_DEFINE), p_pop(pt_pop), p_dpt(pt_pdt), p_mkt(pt_mkt) {} + // 市场销售许可 + PermitManager(PPOP pt_pop, Market *pt_mkt) : type(SELL_DEFINE), p_pop(pt_pop), p_mkt(pt_mkt) {} +}; + +class SellProduction; + +// 交易委托 +struct Request { + friend class SellProduction; + + const uint16_t type; + const shared_ptr p_pmt; + const shared_ptr pdt; + + + Request(shared_ptr pt_pmt, float price, float amount) : type(pt_pmt->type), p_pmt(pt_pmt), pdt(pt_pmt->p_dpt) { + this->price = price; + this->amount = amount; + this->active = true; + } + + ~Request() = default; + + // 销售者或者购买者查询交易委托所用接口 + const float show_money() { return money; } + const float show_amount() { return amount; } + +private: + float money; + float amount; + float price; + bool active; + + // 取消交易委托 + void cancel() { + this->active = false; + } + +}; + class Market { public: + unique_ptr get_selling_production_info(shared_ptr p_pdt); + + shared_ptr send_production_to_sell(shared_ptr p_pm, float price,float amount); + MarketReturn get_money_from_selling(shared_ptr p_req); + MarketReturn cancel_selling_request(SellingPermit spmt_id); + + // 获得市场销售准入证书 + shared_ptr ask_for_selling_right(shared_ptr p_pop, shared_ptr p_pdt); + // 获得市场购买准入证书 + shared_ptr ask_for_buying_right(shared_ptr p_pop); + + void buy_production(BuyingPermit bpmt_id, string pdt_name, float money); + shared_ptr get_parent_market(void); + + + private: // Selling productions in the market. - vector> sl_pdts; + map, shared_ptr> sl_pdts; + // Lands in this market + vector> lands; // Children markets. vector> sub_mkts; // Parent market. shared_ptr pae_mkts; + + vector> pmt_mgrs_selling, pmt_mgrs_buying; + + shared_ptr get_sell_production(shared_ptr p_pdt); + void process_request(void); + void exchange_production(void); + void transfer_production(void); + }; diff --git a/Pop Engine/Need.h b/Pop Engine/Need.h index 04bc91a..c716270 100644 --- a/Pop Engine/Need.h +++ b/Pop Engine/Need.h @@ -10,6 +10,7 @@ using namespace std; class Need { public: + private: // Certain kinds of production which one of those careers need to matain their lives. diff --git a/Pop Engine/Population.cpp b/Pop Engine/Population.cpp index 437c3aa..13928fd 100644 --- a/Pop Engine/Population.cpp +++ b/Pop Engine/Population.cpp @@ -1 +1,8 @@ #include "Population.h" +#include "Production.h" +#include "Market.h" + + +void Population::work(){ + goods = pop * ability / career->get_production()->get_value(); +} diff --git a/Pop Engine/Population.h b/Pop Engine/Population.h index 2630ee6..880e24f 100644 --- a/Pop Engine/Population.h +++ b/Pop Engine/Population.h @@ -1,34 +1,47 @@ #pragma once #include +#include #include "Career.h" #include "Market.h" +#include "Land.h" using namespace std; +// The number to identify certain population. +typedef uint32_t PopID; + class Population { public: // Population group working to get production. void work(void); // Sell production to get money. - void sell(void); + void sell_production(void); // Give part of the money to nation. - void tax(void); + void give_tax(void); // Buy the production the population needed from the market. - void buy(void); + void buy_needing(void); // Part of the population move to another land - void move(void); + void move_away(void); //Part of the population changes the career void increase(void); private: // Career of this population group. shared_ptr career; - + // The land which the population belongs to. + shared_ptr land; + + // Ability to make production. + float ability; // The number of people of this population group. float pop; // Money rest from all recycle. float money; + // Goods which this population makes. + float goods; + + PopID pop_id; -}; \ No newline at end of file +}; diff --git a/Pop Engine/Production.cpp b/Pop Engine/Production.cpp index 6b6addf..4e0dd21 100644 --- a/Pop Engine/Production.cpp +++ b/Pop Engine/Production.cpp @@ -1 +1,9 @@ #include "Production.h" + +float Production::get_value(){ + return value; +} + +string Production::get_name(){ + return name; +} diff --git a/Pop Engine/Production.h b/Pop Engine/Production.h index da3e766..724b668 100644 --- a/Pop Engine/Production.h +++ b/Pop Engine/Production.h @@ -9,6 +9,8 @@ using namespace std; class Production { public: + float get_value(void); + string get_name(void); private: // Raw material to make this production. diff --git a/Pop Engine/SellProduction.cpp b/Pop Engine/SellProduction.cpp index 62da52b..7c21d8d 100644 --- a/Pop Engine/SellProduction.cpp +++ b/Pop Engine/SellProduction.cpp @@ -1 +1,36 @@ #include "SellProduction.h" + +void SellProduction::new_request(shared_ptr pn_req) { + if (pn_req->type == SELL_DEFINE) { + reqs_sl.push_back(pn_req); + update_selling_map(pn_req->price, pn_req->amount); + } + else + { + reqs_by.push_back(pn_req); + update_buying_map(pn_req->price, pn_req->amount); + } +} + +inline void SellProduction::update_buying_map(Price price, Amount amount) +{ + update_map(pce_b_lst, price, amount); +} + +inline void SellProduction::update_selling_map(Price price, Amount amount) +{ + update_map(pce_s_lst, price, amount); +} + +void SellProduction::update_map(map& pce_map, Price price, Amount amount) +{ + auto pcemp_i = pce_s_lst.find(price); + if (pcemp_i == pce_s_lst.end()) { + pce_s_lst.insert(PriceMap(price, PriceList(price, amount))); + } + else { + pcemp_i->second.second += amount; + } +} + + diff --git a/Pop Engine/SellProduction.h b/Pop Engine/SellProduction.h index 8bbba2d..e9862db 100644 --- a/Pop Engine/SellProduction.h +++ b/Pop Engine/SellProduction.h @@ -1,14 +1,52 @@ #pragma once #include "Production.h" -class SellProduction : - public Production +#include "Market.h" + +#include + +using std::pair; +using std::map; + +class SellProduction { public: + using Amount = float; + using Price = float; + using PriceList = pair; + using PriceMap = pair; + SellProduction(shared_ptr pt_pdt) : p_pdt(pt_pdt) {} + + // 委托请求接口 + void new_request(shared_ptr pn_req); + bool cancel_request(shared_ptr pn_req); + + const float get_average_price(); + const float get_selling_amount(); + const float get_buying_amount(); + + private: - float num; - float price; - float need; - shared_ptr type; + // 价位表 + map pce_s_lst, pce_b_lst; + // 产品指针 + shared_ptr p_pdt; + // 销售交易委托 + vector> reqs_sl; + // 购买交易委托 + vector> reqs_by; + // 交易统计 + float buy_amt = 0.0, sell_amt = 0.0; + // 平均价格 + float price_avg = 0.0; + + // 更新价位表接口 + void update_buying_map(Price price, Amount amount); + void update_selling_map(Price price, Amount amount); + void update_map(map& pce_map, Price price, Amount amount); + + + + };