继续完善接口。
This commit is contained in:
parent
e3b0a9e158
commit
a432a0a090
2
.gitignore
vendored
2
.gitignore
vendored
@ -339,3 +339,5 @@ ASALocalRun/
|
|||||||
|
|
||||||
# BeatPulse healthcheck temp database
|
# BeatPulse healthcheck temp database
|
||||||
healthchecksdb
|
healthchecksdb
|
||||||
|
/Pop Engine/.DS_Store
|
||||||
|
/Pop Engine/._.DS_Store
|
||||||
|
BIN
Pop Engine/._Career.cpp
Normal file
BIN
Pop Engine/._Career.cpp
Normal file
Binary file not shown.
BIN
Pop Engine/._Career.h
Normal file
BIN
Pop Engine/._Career.h
Normal file
Binary file not shown.
BIN
Pop Engine/._Engine.cpp
Normal file
BIN
Pop Engine/._Engine.cpp
Normal file
Binary file not shown.
BIN
Pop Engine/._Engine.h
Normal file
BIN
Pop Engine/._Engine.h
Normal file
Binary file not shown.
BIN
Pop Engine/._Land.cpp
Normal file
BIN
Pop Engine/._Land.cpp
Normal file
Binary file not shown.
BIN
Pop Engine/._Land.h
Normal file
BIN
Pop Engine/._Land.h
Normal file
Binary file not shown.
BIN
Pop Engine/._Market.cpp
Normal file
BIN
Pop Engine/._Market.cpp
Normal file
Binary file not shown.
BIN
Pop Engine/._Market.h
Normal file
BIN
Pop Engine/._Market.h
Normal file
Binary file not shown.
BIN
Pop Engine/._Need.cpp
Normal file
BIN
Pop Engine/._Need.cpp
Normal file
Binary file not shown.
BIN
Pop Engine/._Need.h
Normal file
BIN
Pop Engine/._Need.h
Normal file
Binary file not shown.
BIN
Pop Engine/._Pop Engine.cpp
Normal file
BIN
Pop Engine/._Pop Engine.cpp
Normal file
Binary file not shown.
BIN
Pop Engine/._Pop Engine.vcxproj
Normal file
BIN
Pop Engine/._Pop Engine.vcxproj
Normal file
Binary file not shown.
BIN
Pop Engine/._Pop Engine.vcxproj.filters
Normal file
BIN
Pop Engine/._Pop Engine.vcxproj.filters
Normal file
Binary file not shown.
BIN
Pop Engine/._Population.cpp
Normal file
BIN
Pop Engine/._Population.cpp
Normal file
Binary file not shown.
BIN
Pop Engine/._Population.h
Normal file
BIN
Pop Engine/._Population.h
Normal file
Binary file not shown.
BIN
Pop Engine/._Production.cpp
Normal file
BIN
Pop Engine/._Production.cpp
Normal file
Binary file not shown.
BIN
Pop Engine/._Production.h
Normal file
BIN
Pop Engine/._Production.h
Normal file
Binary file not shown.
BIN
Pop Engine/._SellProduction.cpp
Normal file
BIN
Pop Engine/._SellProduction.cpp
Normal file
Binary file not shown.
BIN
Pop Engine/._SellProduction.h
Normal file
BIN
Pop Engine/._SellProduction.h
Normal file
Binary file not shown.
@ -1 +1,5 @@
|
|||||||
#include "Career.h"
|
#include "Career.h"
|
||||||
|
|
||||||
|
shared_ptr<Production> Career::get_production(){
|
||||||
|
return pdt;
|
||||||
|
}
|
||||||
|
@ -10,6 +10,7 @@ using namespace std;
|
|||||||
class Career
|
class Career
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
shared_ptr<Production> get_production(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// The prodution which this career makes.
|
// The prodution which this career makes.
|
||||||
|
@ -1 +1,5 @@
|
|||||||
#include "Land.h"
|
#include "Land.h"
|
||||||
|
|
||||||
|
shared_ptr<Market> Land::get_market(){
|
||||||
|
return mkt;
|
||||||
|
}
|
||||||
|
@ -4,14 +4,18 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Population.h"
|
|
||||||
#include "Production.h"
|
#include "Production.h"
|
||||||
|
|
||||||
|
class Market;
|
||||||
|
|
||||||
|
class Population;
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class Land
|
class Land
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
shared_ptr<Market> get_market(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vector<unique_ptr<Population>> pops;
|
vector<unique_ptr<Population>> pops;
|
||||||
|
@ -1 +1,37 @@
|
|||||||
#include "Market.h"
|
#include "Market.h"
|
||||||
|
#include "Production.h"
|
||||||
|
#include "SellProduction.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
|
shared_ptr<SellProduction> Market::get_sell_production(shared_ptr<Production> p_pdt){
|
||||||
|
auto p_sl_pdt_i = sl_pdts.find(p_pdt);
|
||||||
|
|
||||||
|
return p_sl_pdt_i->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<Market> Market::get_parent_market(){
|
||||||
|
return pae_mkts;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
shared_ptr<PermitManager> Market::ask_for_selling_right(shared_ptr<Population> p_pop, shared_ptr<Production> p_pdt) {
|
||||||
|
shared_ptr<PermitManager> p_pm(new PermitManager(p_pop, p_pdt, this));
|
||||||
|
pmt_mgrs_buying.push_back(p_pm);
|
||||||
|
return p_pm;
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<PermitManager> Market::ask_for_buying_right(shared_ptr<Population> p_pop) {
|
||||||
|
shared_ptr<PermitManager> p_pm(new PermitManager(p_pop, this));
|
||||||
|
pmt_mgrs_buying.push_back(p_pm);
|
||||||
|
return p_pm;
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<Request> Market::send_production_to_sell(shared_ptr<PermitManager> p_pm, float price, float amount) {
|
||||||
|
shared_ptr<Request> 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;
|
||||||
|
}
|
@ -2,22 +2,121 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "Population.h"
|
#include "Population.h"
|
||||||
#include "SellProduction.h"
|
#include "SellProduction.h"
|
||||||
|
#include "Land.h"
|
||||||
|
|
||||||
using namespace std;
|
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<Money, Goods> MarketReturn;
|
||||||
|
// Information about price and need of a certain procuction in the market.
|
||||||
|
typedef pair<const Money, const Goods> 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<Population> p_pop;
|
||||||
|
const shared_ptr<Production> p_dpt;
|
||||||
|
const Market* p_mkt;
|
||||||
|
|
||||||
|
using PPOP = shared_ptr<Population>;
|
||||||
|
using PPDT = shared_ptr<Production>;
|
||||||
|
|
||||||
|
// 市场购买许可
|
||||||
|
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<PermitManager> p_pmt;
|
||||||
|
const shared_ptr<Production> pdt;
|
||||||
|
|
||||||
|
|
||||||
|
Request(shared_ptr<PermitManager> 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
|
class Market
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
unique_ptr<MarketInfo> get_selling_production_info(shared_ptr<Production> p_pdt);
|
||||||
|
|
||||||
|
shared_ptr<Request> send_production_to_sell(shared_ptr<PermitManager> p_pm, float price,float amount);
|
||||||
|
MarketReturn get_money_from_selling(shared_ptr<Request> p_req);
|
||||||
|
MarketReturn cancel_selling_request(SellingPermit spmt_id);
|
||||||
|
|
||||||
|
// 获得市场销售准入证书
|
||||||
|
shared_ptr<PermitManager> ask_for_selling_right(shared_ptr<Population> p_pop, shared_ptr<Production> p_pdt);
|
||||||
|
// 获得市场购买准入证书
|
||||||
|
shared_ptr<PermitManager> ask_for_buying_right(shared_ptr<Population> p_pop);
|
||||||
|
|
||||||
|
void buy_production(BuyingPermit bpmt_id, string pdt_name, float money);
|
||||||
|
shared_ptr<Market> get_parent_market(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Selling productions in the market.
|
// Selling productions in the market.
|
||||||
vector<unique_ptr<SellProduction>> sl_pdts;
|
map<shared_ptr<Production>, shared_ptr<SellProduction>> sl_pdts;
|
||||||
|
// Lands in this market
|
||||||
|
vector<shared_ptr<Land>> lands;
|
||||||
// Children markets.
|
// Children markets.
|
||||||
vector<shared_ptr<Market>> sub_mkts;
|
vector<shared_ptr<Market>> sub_mkts;
|
||||||
// Parent market.
|
// Parent market.
|
||||||
shared_ptr<Market> pae_mkts;
|
shared_ptr<Market> pae_mkts;
|
||||||
|
|
||||||
|
vector<shared_ptr<PermitManager>> pmt_mgrs_selling, pmt_mgrs_buying;
|
||||||
|
|
||||||
|
shared_ptr<SellProduction> get_sell_production(shared_ptr<Production> p_pdt);
|
||||||
|
void process_request(void);
|
||||||
|
void exchange_production(void);
|
||||||
|
void transfer_production(void);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ class Need
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Certain kinds of production which one of those careers need to matain their lives.
|
// Certain kinds of production which one of those careers need to matain their lives.
|
||||||
vector<pair<shared_ptr<Production>, float>> base_pdts;
|
vector<pair<shared_ptr<Production>, float>> base_pdts;
|
||||||
|
@ -1 +1,8 @@
|
|||||||
#include "Population.h"
|
#include "Population.h"
|
||||||
|
#include "Production.h"
|
||||||
|
#include "Market.h"
|
||||||
|
|
||||||
|
|
||||||
|
void Population::work(){
|
||||||
|
goods = pop * ability / career->get_production()->get_value();
|
||||||
|
}
|
||||||
|
@ -1,34 +1,47 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#include "Career.h"
|
#include "Career.h"
|
||||||
#include "Market.h"
|
#include "Market.h"
|
||||||
|
#include "Land.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
// The number to identify certain population.
|
||||||
|
typedef uint32_t PopID;
|
||||||
|
|
||||||
class Population
|
class Population
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Population group working to get production.
|
// Population group working to get production.
|
||||||
void work(void);
|
void work(void);
|
||||||
// Sell production to get money.
|
// Sell production to get money.
|
||||||
void sell(void);
|
void sell_production(void);
|
||||||
// Give part of the money to nation.
|
// Give part of the money to nation.
|
||||||
void tax(void);
|
void give_tax(void);
|
||||||
// Buy the production the population needed from the market.
|
// Buy the production the population needed from the market.
|
||||||
void buy(void);
|
void buy_needing(void);
|
||||||
// Part of the population move to another land
|
// Part of the population move to another land
|
||||||
void move(void);
|
void move_away(void);
|
||||||
//Part of the population changes the career
|
//Part of the population changes the career
|
||||||
void increase(void);
|
void increase(void);
|
||||||
private:
|
private:
|
||||||
// Career of this population group.
|
// Career of this population group.
|
||||||
shared_ptr<Career> career;
|
shared_ptr<Career> career;
|
||||||
|
// The land which the population belongs to.
|
||||||
|
shared_ptr<Land> land;
|
||||||
|
|
||||||
|
// Ability to make production.
|
||||||
|
float ability;
|
||||||
// The number of people of this population group.
|
// The number of people of this population group.
|
||||||
float pop;
|
float pop;
|
||||||
// Money rest from all recycle.
|
// Money rest from all recycle.
|
||||||
float money;
|
float money;
|
||||||
|
// Goods which this population makes.
|
||||||
|
float goods;
|
||||||
|
|
||||||
|
PopID pop_id;
|
||||||
|
|
||||||
};
|
};
|
@ -1 +1,9 @@
|
|||||||
#include "Production.h"
|
#include "Production.h"
|
||||||
|
|
||||||
|
float Production::get_value(){
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
string Production::get_name(){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
@ -9,6 +9,8 @@ using namespace std;
|
|||||||
class Production
|
class Production
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
float get_value(void);
|
||||||
|
string get_name(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Raw material to make this production.
|
// Raw material to make this production.
|
||||||
|
@ -1 +1,36 @@
|
|||||||
#include "SellProduction.h"
|
#include "SellProduction.h"
|
||||||
|
|
||||||
|
void SellProduction::new_request(shared_ptr<Request> 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<Price, PriceList>& 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,14 +1,52 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Production.h"
|
#include "Production.h"
|
||||||
class SellProduction :
|
#include "Market.h"
|
||||||
public Production
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
using std::pair;
|
||||||
|
using std::map;
|
||||||
|
|
||||||
|
class SellProduction
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
using Amount = float;
|
||||||
|
using Price = float;
|
||||||
|
using PriceList = pair<Price, Amount>;
|
||||||
|
using PriceMap = pair<Price, PriceList>;
|
||||||
|
|
||||||
|
SellProduction(shared_ptr<Production> pt_pdt) : p_pdt(pt_pdt) {}
|
||||||
|
|
||||||
|
// 委托请求接口
|
||||||
|
void new_request(shared_ptr<Request> pn_req);
|
||||||
|
bool cancel_request(shared_ptr<Request> pn_req);
|
||||||
|
|
||||||
|
const float get_average_price();
|
||||||
|
const float get_selling_amount();
|
||||||
|
const float get_buying_amount();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float num;
|
// 价位表
|
||||||
float price;
|
map<Price, PriceList> pce_s_lst, pce_b_lst;
|
||||||
float need;
|
// 产品指针
|
||||||
shared_ptr<Production> type;
|
shared_ptr<Production> p_pdt;
|
||||||
|
// 销售交易委托
|
||||||
|
vector<shared_ptr<Request>> reqs_sl;
|
||||||
|
// 购买交易委托
|
||||||
|
vector<shared_ptr<Request>> 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<Price, PriceList>& pce_map, Price price, Amount amount);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user