From a432a0a090ea6cd2616a826f7db3be8dcab813b0 Mon Sep 17 00:00:00 2001 From: saturneric Date: Thu, 22 Aug 2019 23:56:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E5=AE=8C=E5=96=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + Pop Engine/._Career.cpp | Bin 0 -> 4096 bytes Pop Engine/._Career.h | Bin 0 -> 4096 bytes Pop Engine/._Engine.cpp | Bin 0 -> 4096 bytes Pop Engine/._Engine.h | Bin 0 -> 4096 bytes Pop Engine/._Land.cpp | Bin 0 -> 4096 bytes Pop Engine/._Land.h | Bin 0 -> 4096 bytes Pop Engine/._Market.cpp | Bin 0 -> 4096 bytes Pop Engine/._Market.h | Bin 0 -> 4096 bytes Pop Engine/._Need.cpp | Bin 0 -> 4096 bytes Pop Engine/._Need.h | Bin 0 -> 4096 bytes Pop Engine/._Pop Engine.cpp | Bin 0 -> 4096 bytes Pop Engine/._Pop Engine.vcxproj | Bin 0 -> 4096 bytes Pop Engine/._Pop Engine.vcxproj.filters | Bin 0 -> 4096 bytes Pop Engine/._Population.cpp | Bin 0 -> 4096 bytes Pop Engine/._Population.h | Bin 0 -> 4096 bytes Pop Engine/._Production.cpp | Bin 0 -> 4096 bytes Pop Engine/._Production.h | Bin 0 -> 4096 bytes Pop Engine/._SellProduction.cpp | Bin 0 -> 4096 bytes Pop Engine/._SellProduction.h | Bin 0 -> 4096 bytes Pop Engine/Career.cpp | 4 + Pop Engine/Career.h | 1 + Pop Engine/Land.cpp | 4 + Pop Engine/Land.h | 6 +- Pop Engine/Market.cpp | 36 +++++++++ Pop Engine/Market.h | 101 +++++++++++++++++++++++- Pop Engine/Need.h | 1 + Pop Engine/Population.cpp | 7 ++ Pop Engine/Population.h | 25 ++++-- Pop Engine/Production.cpp | 8 ++ Pop Engine/Production.h | 2 + Pop Engine/SellProduction.cpp | 35 ++++++++ Pop Engine/SellProduction.h | 50 ++++++++++-- 33 files changed, 268 insertions(+), 14 deletions(-) create mode 100644 Pop Engine/._Career.cpp create mode 100644 Pop Engine/._Career.h create mode 100644 Pop Engine/._Engine.cpp create mode 100644 Pop Engine/._Engine.h create mode 100644 Pop Engine/._Land.cpp create mode 100644 Pop Engine/._Land.h create mode 100644 Pop Engine/._Market.cpp create mode 100644 Pop Engine/._Market.h create mode 100644 Pop Engine/._Need.cpp create mode 100644 Pop Engine/._Need.h create mode 100644 Pop Engine/._Pop Engine.cpp create mode 100644 Pop Engine/._Pop Engine.vcxproj create mode 100644 Pop Engine/._Pop Engine.vcxproj.filters create mode 100644 Pop Engine/._Population.cpp create mode 100644 Pop Engine/._Population.h create mode 100644 Pop Engine/._Production.cpp create mode 100644 Pop Engine/._Production.h create mode 100644 Pop Engine/._SellProduction.cpp create mode 100644 Pop Engine/._SellProduction.h 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 0000000000000000000000000000000000000000..b68d0d8602059facad2a5ef7afd1c7b4624a1e22 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wMg?WDB5a0m{L|rIPb=^%4sTa#Hnj5{pYpi&Ill5=&B*1A;+%f~tdJLG;a<#Zn-8 z6pV(zXb6mkz-S1JhQMeDjE2By2#kinXb6mkz-S1Jh5)V*0ChG&7!2e>GBS%5ic*X7 zON)|I71HvHvK2D(N>cMmGV}8ib8;#ba#GVu6q0fh^Rj_`VW_SlO`-Z9?iCpZx&QwG Dos%h! literal 0 HcmV?d00001 diff --git a/Pop Engine/._Career.h b/Pop Engine/._Career.h new file mode 100644 index 0000000000000000000000000000000000000000..41d42f65ca0d0eb861bbda53a89edc8cfa574db2 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wMg?WDB5a0m{L|rIPb=^%4sTa#Hnj5{pYpi&Ill5=&B*1A;+%rd0*Sg6NdsMs^TA z3PwXEOnfZB%IXRUIIjLzS3Q0MMdD+0eFjUu&rcnJ4_lgXI-2eXo D{!1wS literal 0 HcmV?d00001 diff --git a/Pop Engine/._Engine.cpp b/Pop Engine/._Engine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8b2e237bdf6fcf66c22594949db8ecd0efbd669a GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wMg?WDB5a0m{L|rIPb=^%4sTa#Hnj5{pYpi&Ill5=&B*1A;+%!YYDdLG%YcMUaa| z!DtAKhQMeDjE2By2#kinXb6mkz-S1JhQMeDjE2By2;d9>P-hc_!9Xq~BePhcD784h zv?w`MAuYcsTOl*ABsH%jGe0jeC#O;&CpE1^At@&@FB{kwhUyy96srH>UXfvt`~M#R DJO(J9 literal 0 HcmV?d00001 diff --git a/Pop Engine/._Engine.h b/Pop Engine/._Engine.h new file mode 100644 index 0000000000000000000000000000000000000000..2d600e1d5afeab1f8605713368128f425aecc5d5 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wNsPWM`sj0htaG7hqtJO3u&KODrhJN!80qEG{W6PEAQkEJ;-k2!`tU0;D4u7|aps za#KqZfoc-1vVC2A5|dJM;>%Nu%rjETa00%*``0EAw)U6HQHkn&*@U#e&RA zw>b*(5yPi7moA9A31{mWS2m^{xGrhwy>+(q=Q{@v$=ozJ)Vbr|f+m)$>MP8dZ?~Ni zj)~9Q5cFV%`J-8UVXC)z1e~h3HkGJ7+`l2~6?f7ik&XJ=cW(Tf_fIMJxSHTRkl~|X zGz3ONU^E0qLtr!nMnhmU1V%$(Gz3ONU^E0qLtwx{0N4=)bw(jTE+iwfSfMDjIKQ+g zIaMJozbIQFGp{5yuOu@+FEJ;lQXwZbtwbRyCowM@*cXOr8_G1Q|KUE7VUYX(9{_Qb BYheHY literal 0 HcmV?d00001 diff --git a/Pop Engine/._Land.cpp b/Pop Engine/._Land.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3c62811854d713a6aa9301ed5a9a452885091341 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wNsPWM`sj0htaG7hqtJO3u&KODrhJN!80qEG{W6PEAQkEJ;-k2!`tU0;D4u7|aps za#KqZfoc-1vVC2A5|dJM;>%Nu%rjETa00%*``0EAw)U6HQHknzy$F#e&RI zSk4Z#kAdM+=+fjEG3C{#rd-gV!>RBi@HUdDEcwpZ`_e$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wNsPWM`sj0htaG7hqtJO3u&KODrhJN!80qEG{W6PEAQkEJ;-k2!`tU0;D4u7|aps za#KqZfoc-1vVC2A5|dJM;>%Nu%rjETa00%*``0EAw)U6HQHknwcttVnJp} z*$aTU44)Qko5FYE>}KcaYxfT>jl4WL@{(%F)S~j*Bgyys?(G*(xfOZx&&gX?KSyNE zTWUP<_qA>=hmwd%;S(mXX1(9;GK2`4cDTb?27cvh|1{ppI zMnhmU1V%$(Gz3ONU^E0qLtr!nMnhmU1V%$(Gz11L1b`h;P-heZ$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wNsPWM`sj0htaG7hqtJO3u&KODrhJN!80qEG{W6PEAQkEJ;-k2!`tU0;D4u7|aps za#KqZfoc-1vVC2A5|dJM;>%Nu%rjETa00%*``0EAw)U6HQHknwx5aVnJp# z_HgTi=ua9)7oY!kt#bQ$*U-$=6=L)EwWaGcS?`b2wapWBKYRQBsm)qzUMP0Gp7QB| zh3$I_p=Fw@l6JUnmq~ogGVOqE`o~12Qy)%GG!w9OR^X3cw>i$desS<5xfN0%!$-kr z2#kinXb6mkz-S1JhQMeDjE2By2#kinXb6mkz<`ASup$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wNsPWM`sj0htaG7hqtJO3u&KODrhJN!80qEG{W6PEAQkEJ;-k2!`tU0;D4u7|aps za#KqZfoc-1vVC2A5|dJM;>%Nu%rjETa00%*``0EAw)U6HQHknwM7u#e&Rw zv2r%ZUWQLk_t!lM_*y6az?#G`5 zr*rBGdEP!LTl=8jbIz4E+s=#aGuFN73SIsgWcVl; z4S~@R7!85Z5Eu=C(GVC7fzc2c4S~@R7!85Z5E!r!0Cq${olyvo3(3eVRwzm>&Mz%W zPE|$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wMg?WDB5a0m{L|rIPb=^%4sTa#Hnj5{pYpi&Ill5=&B*1A;+%!rFskLG)1>Q&|u_ z3PwXEOnfZB%IXRUIIjLzS3Q0MMdD+0eFjUu&rcnJ4_lgXI-2eXo DHeM*d literal 0 HcmV?d00001 diff --git a/Pop Engine/._Need.h b/Pop Engine/._Need.h new file mode 100644 index 0000000000000000000000000000000000000000..73029b7f7d999388eaf60eebcf267959c97f7ba7 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wNsPWM`sj0htaG7hqtJO3u&KODrhJN!80qEG{W6PEAQkEJ;-k2!`tU0;D4u7|aps za#KqZfoc-1vVC2A5|dJM;>%Nu%rjETa00%*``0EAw)U6HQHkn(y}o#e&Rw zZhuG~M1OMeYhwSSo^oVYfxDHvRfJx?AoE>5C-DjP*OT*ItA)y2LMNZiZ1+6zJ}7(j zKXEJmm5Uw*d@P^jA?$K?%B9r}^X`}&RDEi)dl6@ymHnlMg-(js4odePkXZvVd=!j^ zz-S1JhQMeDjE2By2#kinXb6mkz-S1JhQMeD3|I&NJEEY@C!Z2+^nMU$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wMg?WDB5a0m{L|rIPb=^%4sTa#Hnj5{pYpi&Ill5=&B*1A;+%%-e!uLG({83y^C@ z!DtAKhQMeDjE2By2#kinXb6mkz-S1JhQMeDjE2By2;d9>P-hc_!9Xq~BePhcD784h zv?w`MAuYcsTOl*ABsH%jGe0jeC#O;&CpE1^At@&@FB{kwhUyy96srH>UXfvt`~M#R DI&LV? literal 0 HcmV?d00001 diff --git a/Pop Engine/._Pop Engine.vcxproj b/Pop Engine/._Pop Engine.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..fb262cdad37b61655f21f2f9447bd135889949ed GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wMg?WDB5a0m{L|rIPb=^%4sTa#Hnj5{pYpi&Ill5=&B*1A;+%t~mt7g6QOXllejP zC>RZa(GVC7fzc2c4S~@R7!85Z5Eu=C(GVC7fzc2c4FOys0P1XlFc`>%WMmdA6r~pD zmlh?bDx~EXWh-Rnm89mCWaj53=Hyf=!cbj9nnLwI+$%B+a{vDW E051b6r~m)} literal 0 HcmV?d00001 diff --git a/Pop Engine/._Pop Engine.vcxproj.filters b/Pop Engine/._Pop Engine.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..a61bab7dc3b4a7fb167ee2417f05bd36b955d2db GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wMg?WDB5a0m{L|rIPb=^%4sTa#Hnj5{pYpi&Ill5=&B*1A;+%E;2B>oSaI9oYb@ug`}Lsylh}!7^-VXQ>gxjdqsvp?*D%P D``sy& literal 0 HcmV?d00001 diff --git a/Pop Engine/._Population.cpp b/Pop Engine/._Population.cpp new file mode 100644 index 0000000000000000000000000000000000000000..19c2586eee1701af335fa5a0524280810b0d6380 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wNsPWM`sj0htaG7hqtJO3u&KODrhJN!80qEG{W6PEAQkEJ;-k2!`tU0;D4u7|aps za#KqZfoc-1vVC2A5|dJM;>%Nu%rjETa00%*``0EAw)U6HQHknu{xgVnJs0 zCNI?j(VtRx&EjNbJ6^E;_2Z3epKpp>d-VE-tiIxpT%A=H`PW|g@sY_#^Kg^cnetQ2 z9-HOD#1+!dOqW?%6gKT9vq{I@e-r-R%Q?|d^ReN@Gs{(S+U9f0IS$->`1;*ykl~|X zGz3ONU^E0qLtr!nMnhmU1V%$(Gz3ONU^E0qLtwx{0N4=)bw(jTE+iwfSfMDjIKQ+g zIaMJozbIQFGp{5yuOu@+FEJ;lQXwZbtwbRyCowM@*cXOr8_G1Q|KUE7VUYX(9{`R< Ba9#ia literal 0 HcmV?d00001 diff --git a/Pop Engine/._Population.h b/Pop Engine/._Population.h new file mode 100644 index 0000000000000000000000000000000000000000..98663331a7f0c98757ea3691eced1399b974cfc4 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wNsPWM`sj0htaG7hqtJO3u&KODrhJN!80qEG{W6PEAQkEJ;-k2!`tU0;D4u7|aps za#KqZfoc-1vVC2A5|dJM;>%Nu%rjETa00%*``0EAw)U6HQHkn%gRaVnJr{ zd7jV*(Vrggv$eb8$kDmv{T|O{XXcz<965E4;u+KMi@a}x4|8eT&spLB`b+-Kc{#I- z=Sxk96yB}TczAtz{4}|2j^_@^RqDwFeTGFUYfk#aTsghE?$M*fo5!nuTi*!;89oX| zLtr!nMnhmU1V%$(Gz3ONU^E0qLtr!nMnhmU1O_YwfE`g#XA}bDLNYRo6^c@e^Gl18 zQx($ki?S6m^GZ_lN;32F5_57Y6>?J3N)(cE67#ZwePNikp-iLtAMO(w2D$(L0p8(l Ae*gdg literal 0 HcmV?d00001 diff --git a/Pop Engine/._Production.cpp b/Pop Engine/._Production.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2a3317616275d53a34118fc1c31c1e6ba4be1d64 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wMg?WDB5a0m{L|rIPb=^%4sTa#Hnj5{pYpi&Ill5=&B*1A;+%epdy>f@tkGK|COO z6pV(zXb6mkz-S1JhQMeDjE2By2#kinXb6mkz-S1Jh5)V*0ChG&7!2e>GBS%5ic*X7 zON)|I71HvHvK2D(N>cMmGV}8ib8;#ba#GVu6q0fh^Rj_`VW_SlO`-Z9?iCpZx&QwG DOb02M literal 0 HcmV?d00001 diff --git a/Pop Engine/._Production.h b/Pop Engine/._Production.h new file mode 100644 index 0000000000000000000000000000000000000000..5f2410b5d495618a6e80950ad19dae14394746ca GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wMg?WDB5a0m{L|rIPb=^%4sTa#Hnj5{pYpi&Ill5=&B*1A;+%E>{J`g6K&zri+8< zQ7{?;qaiRF0;3@?8UmvsFd71*Aut*OqaiRF0;3@?8UnaN0Myw8VK9&j$;d2LC`v8P zFD*(=RY=P(%2vqCD@n~O$;{77%*m-#$Vp8rQAo;3%*zJ$g`v8JG==JaxL0Ht$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wNsPWM`sj0htaG7hqtJO3u&KODrhJN!80qEG{W6PEAQkEJ;-k2!`tU0;D4u7|aps za#KqZfoc-1vVC2A5|dJM;>%Nu%rjETa00%*``0EAw)U6HQHknp+!#VnJpF zP36`E(Vu27v;TOu|Ky^YZlg2(hw93=9RJ@x?_Elu$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103v0xDsI z=wMg?WDB5a0m{L|rIPb=^%4sTa#Hnj5{pYpi&Ill5=&B*1A;+%9@PiMg6O|DZ}Woa zQ7{?;qaiRF0;3@?8UmvsFd71*Aut*OqaiRF0;3@?8UnaN0Myw8VK9&j$;d2LC`v8P zFD*(=RY=P(%2vqCD@n~O$;{77%*m-#$Vp8rQAo;3%*zJ$g`v8JG==JaxL0Ht 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); + + + + };