From 57056b9625b7a75ffddcdaba0a7c5913cf74603c Mon Sep 17 00:00:00 2001 From: Saturneric Date: Tue, 1 Sep 2020 00:17:06 +0800 Subject: [PATCH] Add --- army.cpp | 72 ++++++++++++++++++++++++++++++++ army.h | 34 ++++++++++++++++ event.cpp | 10 +++++ event.h | 42 +++++++++++++++++++ factory.cpp | 52 ++++++++++++++++++++++++ factory.h | 29 +++++++++++++ game.cpp | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++ game.h | 61 ++++++++++++++++++++++++++++ land.cpp | 88 ++++++++++++++++++++++++++++++++++++++++ land.h | 34 ++++++++++++++++ main.cpp | 17 ++++++++ nation.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++ nation.h | 70 ++++++++++++++++++++++++++++++++ 13 files changed, 719 insertions(+) create mode 100644 army.cpp create mode 100644 army.h create mode 100644 event.cpp create mode 100644 event.h create mode 100644 factory.cpp create mode 100644 factory.h create mode 100644 game.cpp create mode 100644 game.h create mode 100644 land.cpp create mode 100644 land.h create mode 100644 main.cpp create mode 100644 nation.cpp create mode 100644 nation.h diff --git a/army.cpp b/army.cpp new file mode 100644 index 0000000..6aae0d4 --- /dev/null +++ b/army.cpp @@ -0,0 +1,72 @@ +// +// army.cpp +// nation_war +// +// Created by Saturneric on 17/1/16. +// Copyright © 2017年 Bakantu Eric. All rights reserved. +// + +#include "game.h" +#include "event.h" + +list amy_vec; + +army::army(class nation *p_ntn, class land *p_lnd, int t_amyofe, int num){ + pm_lnd = p_lnd; + pm_ntn = p_ntn; + amyofe = t_amyofe; + sldmun = num; + sldeqp = p_ntn->amyeqp; + amycst = p_ntn->amycst; + amy_vec.push_back(this); +} + +army::~army(void){ + remove(amy_vec.begin(), amy_vec.end(), this); + delete this; +} + +int army::upgrade(void){ + sldmun = amyofe * (pm_ntn->amypeo); + sldeqp = pm_ntn->amyeqp; + amycst = pm_ntn->amycst; + return 0; +} + +int army::fight(void){ + return sldmun*sldeqp; +} + +int army::kill(int num){ + if (num <= sldmun){ + sldmun -= num; + } + else return -1; + return 0; +} + +int army::add(int num){ + if ((sldmun + num) <= (pm_ntn->amypeo * amyofe)){ + if (pm_lnd->manpow >= num){ + sldmun += num; + } + else return -1; + } + else return -1; + return 0; +} + +int army::move(class land *toland){ + addarmymove(pm_lnd, toland, this); + return 0; +} + +int army::amy_cost(void){ + return (sldmun * (1+pm_ntn->embezzle) * amycst) + (amyofe * pm_ntn->amyoffcst); +} + +int army::del(void){ + remove(amy_vec.begin(), amy_vec.end(), this); + return 0; +} + diff --git a/army.h b/army.h new file mode 100644 index 0000000..d99a1e8 --- /dev/null +++ b/army.h @@ -0,0 +1,34 @@ +// +// army.h +// nation_war +// +// Created by Saturneric on 17/1/16. +// Copyright © 2017年 Bakantu Eric. All rights reserved. +// + +#ifndef army_h +#define army_h + +class army { +public: + int sldmun; + int amyofe; + int sldeqp; + int amycst; + int armyv; + class land *pm_lnd; + class nation *pm_ntn; + + int upgrade(void); + int move(class land *toland); + int amy_cost(void); + int fight(void); + int kill(int num); + int add(int num); + int del(void); + army(class nation *p_ntn, class land *p_lnd, int t_amyofe, int num); + ~army(void); +}; + + +#endif /* army_h */ diff --git a/event.cpp b/event.cpp new file mode 100644 index 0000000..6400095 --- /dev/null +++ b/event.cpp @@ -0,0 +1,10 @@ +// +// event.cpp +// nation_war +// +// Created by Saturneric on 17/1/21. +// Copyright © 2017年 Bakantu Eric. All rights reserved. +// + +#include "game.h" + diff --git a/event.h b/event.h new file mode 100644 index 0000000..6590214 --- /dev/null +++ b/event.h @@ -0,0 +1,42 @@ +// +// event.h +// nation_war +// +// Created by Saturneric on 17/1/16. +// Copyright © 2017年 Bakantu Eric. All rights reserved. +// + +#ifndef event_h +#define event_h + +class war{ + class army *f_amy; + class army *s_amy; + int f_rand; + int s_rand; + +public: + war(class army *pf_amy, class army *ps_amy); + class army *fight(void); + +}; + +class move{ + class army *p_amy; + class land *f_lnd; + class land *t_lnd; + +public: + move(class army *p_amy, class land *f_lnd, class land *t_lnd); + int go(void); +}; + +class event{ + int time; + void *(func()); + void *value; +public: + event(int time, void *(func()), void *value); +}; + +#endif /* event_h */ diff --git a/factory.cpp b/factory.cpp new file mode 100644 index 0000000..ff772ba --- /dev/null +++ b/factory.cpp @@ -0,0 +1,52 @@ +// +// factory.cpp +// nation_war +// +// Created by Saturneric on 17/1/16. +// Copyright © 2017年 Bakantu Eric. All rights reserved. +// + + +#include "game.h" + +list ftc_vec; + +factory::factory(class land *p_lnd, class nation *p_ntn, int t_plcnum, int num){ + pm_ntn = p_ntn; + pm_lnd = p_lnd; + plcnum = t_plcnum; + mpw = num; + pdt = p_ntn->pdteff; + ftc_vec.push_back(this); +} + +factory::~factory(void){ + remove(ftc_vec.begin(),ftc_vec.end(),this); + delete this; +} + +int factory::setmpw(int num){ + if(num < plcnum*pdt){ + mpw = num; + } + return 0; +} + +int factory::upgrade(void){ + pdt = pm_ntn->pdteff; + return 0; +} + +int factory::setplc(int num){ + if (num < 0) return -1; + if (num * pm_ntn->plcpeo < mpw){ + mpw = num * pm_ntn->plcpeo; + } + plcnum = num; + return 0; +} + +int factory::getpdt(void){ + return (mpw * pdt * (1 - pm_ntn->embezzle)) - (plcnum * pm_ntn->plcoffcst); +} + diff --git a/factory.h b/factory.h new file mode 100644 index 0000000..5d9ea37 --- /dev/null +++ b/factory.h @@ -0,0 +1,29 @@ +// +// factory.h +// nation_war +// +// Created by Saturneric on 17/1/16. +// Copyright © 2017年 Bakantu Eric. All rights reserved. +// + +#ifndef factory_h +#define factory_h + +class factory { +public: + int mpw; + int plcnum; + int pdt; + class land *pm_lnd; + class nation *pm_ntn; + + int setmpw(int num); + int getpdt(void); + int upgrade(void); + int setplc(int num); + + factory(class land *p_lnd, class nation *p_ntn, int t_plcnum, int num); + ~factory(void); +}; + +#endif /* factory_h */ diff --git a/game.cpp b/game.cpp new file mode 100644 index 0000000..e06defd --- /dev/null +++ b/game.cpp @@ -0,0 +1,115 @@ +// +// game.cpp +// nation_war +// +// Created by Saturneric on 17/1/21. +// Copyright © 2017年 Bakantu Eric. All rights reserved. +// + + +#include "game.h" + +list route_vec; +list armymove_vec; + + +route::route(class land *f_lnd, class land *t_lnd, int distance){ + this->f_lnd = f_lnd; + this->t_lnd = t_lnd; + this->distance = distance; + route_vec.push_back(this); +} + +int mdistance; +list dway; + +list findway(class land *f_lnd, class land *t_lnd){ + dway.clear(); + mdistance = 0; + listntway; + getway(f_lnd, t_lnd, 0, ntway); + return dway; +} + +int getway(class land *f_lnd, class land *t_lnd,int tdistance, listtway){ + class land *pt_lnd; + while (pt_lnd == t_lnd){ + for(list::iterator lit = route_vec.begin(); lit != route_vec.end(); lit++){ + if ((*lit)->f_lnd == f_lnd){ + tdistance += (*lit)->distance; + tway.push_back(*lit); + if ((*lit)->t_lnd == t_lnd){ + if (mdistance == 0){ + dway = tway; + mdistance = tdistance; + tway.pop_back(); + } + else { + if (tdistance < mdistance){ + dway = tway; + mdistance = tdistance; + } + tway.pop_back(); + tdistance -= (*lit)->distance; + } + } + else{ + listntway; + copy(tway.begin(), tway.end(), back_inserter(ntway)); + if (mdistance != 0){ + if (tdistance > mdistance){ + tway.pop_back(); + tdistance -= (*lit)->distance; + } + else{ + getway((*lit)->f_lnd, t_lnd, tdistance, ntway); + } + } + else{ + getway((*lit)->f_lnd, t_lnd, tdistance, ntway); + } + } + } + } + } + tway.clear(); + return 0; +} + +armymove::armymove(class land *templand, class land *toland, listway, class army *parmy){ + armymove_vec.push_back(this); + this->templnd = templand; + this->tolnd = toland; + this->way = way; + proute = way.begin(); + lastdistance = (*proute)->distance; + this->parmy = parmy; +} + +int armymove::golnd(void){ + lastdistance -= parmy->armyv; + if (lastdistance <= 0){ + templnd = (*proute)->t_lnd; + parmy->pm_lnd = templnd; + if (proute != way.end()){ + proute++; + lastdistance = (*proute)->distance; + } + else{ + return -1; + } + } + return 0; +} + +int addarmymove(class land *templand, class land *toland, class army *parmy){ + list way = findway(templand, toland); + armymove *tam = new armymove(templand, toland, way, parmy); + armymove_vec.push_back(tam); + return 0; +} + +int engine(void){ + + return 0; +} diff --git a/game.h b/game.h new file mode 100644 index 0000000..9f24a90 --- /dev/null +++ b/game.h @@ -0,0 +1,61 @@ +// +// game.h +// nation_war +// +// Created by Saturneric on 17/1/17. +// Copyright © 2017年 Bakantu Eric. All rights reserved. +// + +#ifndef game_h +#define game_h + +#include +#include +#include +#include +#include + +#include "nation.h" +#include "factory.h" +#include "army.h" +#include "land.h" +#include "event.h" + + +using namespace std; + +extern list ftc_vec; +extern list ntn_vec; +extern list land_vec; +extern list amy_vec; +extern list event_vec; +extern list route_vec; + +class route { + +public: + class land *f_lnd; + class land *t_lnd; + int distance; + route(class land *f_lnd, class land *t_lnd, int distance); +}; + +class armymove { + class land *templnd; + class land *tolnd; + int lastdistance; + class army *parmy; + list::iterator proute; + list way; + +public: + int golnd(void); + armymove(class land *templand, class land *toland, listway, class army *parmy); +}; + +int getway(class land *f_lnd, class land *t_lnd, int tdistance, listtway); +list findway(class land *f_lnd, class land *t_lnd); +int addarmymove(class land *templand, class land *toland, class army *parmy); +#endif /* game_h */ + +int engine(void); diff --git a/land.cpp b/land.cpp new file mode 100644 index 0000000..6482155 --- /dev/null +++ b/land.cpp @@ -0,0 +1,88 @@ +// +// land.cpp +// nation_war +// +// Created by Saturneric on 17/1/16. +// Copyright © 2017年 Bakantu Eric. All rights reserved. +// + +#include "game.h" + +list land_vec; + +land::land(){ + srand((unsigned int)time(NULL)); + manpow = rand()%500; + mpwmax = rand()%2500 + 800; + mpwplus = rand()%15; + resource = rand()%1000; + resmax = rand()%8000; + resplus = rand()%50; + pm_ntn = NULL; + fctinit = rand()%4; + fctnum = 0; + land_vec.push_back(this); +} + + +land::~land(void){ + remove(land_vec.begin(),land_vec.end(),this); + delete this; +} +int land::resrec(void){ + if (resource + resplus < resmax){ + resource += resplus; + } + else{ + resource = resmax; + } + return 0; +} + +int land::mpwrec(void){ + if (manpow + mpwplus < mpwmax){ + manpow += mpwplus; + } + else { + manpow = mpwmax; + } + return 0; +} + +int land::getmpw(int num){ + if (num <= manpow){ + manpow -= num; + } + else return -1; + return 0; +} + +int land::getres(int num){ + if (num <= resource){ + resource -= num; + } + else return -1; + return 0; +} + +class nation *target_ntn = NULL; + +bool ntn_fct(const class factory *p_fct) { + if (p_fct->pm_ntn == target_ntn){ + return true; + } + return false; +} + +int land::cgentn(class nation *p_ntn){ + if (p_ntn != NULL){ + target_ntn = pm_ntn; + remove_if(ftc_vec.begin(),ftc_vec.end(),ntn_fct); + target_ntn = NULL; + pm_ntn = p_ntn; + fctnum = 0; + } + else return -1; + return 0; +} + diff --git a/land.h b/land.h new file mode 100644 index 0000000..56d1996 --- /dev/null +++ b/land.h @@ -0,0 +1,34 @@ +// +// land.h +// nation_war +// +// Created by Saturneric on 17/1/16. +// Copyright © 2017年 Bakantu Eric. All rights reserved. +// + +#ifndef land_h +#define land_h + +class land { +public: + int manpow; + int mpwplus; + int mpwmax; + int resource; + int resplus; + int resmax; + int fctnum; + int fctinit; + class nation *pm_ntn; + + int resrec(void); + int mpwrec(void); + int getmpw(int num); + int getres(int num); + int cgentn(class nation *p_ntn); + + land(void); + ~land(void); +}; + +#endif /* land_h */ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e4a26cc --- /dev/null +++ b/main.cpp @@ -0,0 +1,17 @@ +// +// main.cpp +// nation_war +// +// Created by Saturneric on 17/1/16. +// Copyright © 2017年 Bakantu Eric. All rights reserved. +// + +#include "game.h" + + +using namespace std; + +int main(int argc, const char * argv[]) { + + return 0; +} diff --git a/nation.cpp b/nation.cpp new file mode 100644 index 0000000..c0c97e4 --- /dev/null +++ b/nation.cpp @@ -0,0 +1,95 @@ +// +// nation.cpp +// nation_war +// +// Created by Saturneric on 17/1/16. +// Copyright © 2017年 Bakantu Eric. All rights reserved. +// + +#include "game.h" + +list ntn_vec; + + +nation::nation(int s_id){ + amycst = 1; + fund = 1000; + embezzle = 0.5; + pdteff = 10; + n_id = s_id; + plcpeo = 20; + amypeo = 50; + amyeqp = 1; + amyoffcst = 15; + plcoffcst = 10; + lndplus = 2; +} + +int nation::send_fund(int send){ + fund += send; + return 0; +} + +int nation::set_amy(int sld_num,int mf_num, class land *p_land){ + if (sld_num <= p_land->manpow && p_land->pm_ntn == this){ + new army(this, p_land, mf_num, sld_num); + p_land->getmpw(sld_num); + } + else return -1; + return 0; +} + +int nation::set_fct(int mpw_num, int pf_num,class land *p_land){ + if (mpw_num <= p_land->manpow && p_land->pm_ntn == this){ + if (p_land->fctnum < (p_land->fctinit+this->lndplus)){ + new factory(p_land,this,pf_num,mpw_num); + p_land->getmpw(mpw_num); + } + else return -2; + } + else return -1; + return 0; +} + +int pdt_tech_def::upd_fct(class nation *p_ntn){ + if (p_ntn->fund - fctgde * fctgde * 100 >= 0){ + p_ntn->fund -= fctgde * fctgde * 100; + p_ntn->pdteff = p_ntn->pdteff * fctgde; + } + else return -1; + return 0; +} + +int pdt_tech_def::upd_lnd(class nation *p_ntn){ + if (p_ntn->fund - lndgde * lndgde * 100 >= 0){ + p_ntn->fund -= lndgde * lndgde * 100; + p_ntn->lndplus += 1; + } + return 0; +} + +int ofc_tech_def::ugd_plc(class nation *p_ntn){ + if (p_ntn->fund - plcgde * plcgde * 150 >= 0){ + p_ntn->fund -= plcgde * plcgde * 150; + plcgde += 1; + p_ntn->plcpeo *= plcgde; + } + return 0; +} + +int ofc_tech_def::ugd_amy(class nation *p_ntn){ + if (p_ntn->fund - amygde * amygde * 100 >= 0) { + p_ntn->fund -= amygde * amygde * 100; + p_ntn->amypeo *= amygde * amygde * 0.6; + } + return 0; +} + +int ofc_tech_def::ugd_spy(class nation *p_ntn){ + if (p_ntn->fund - spygde * spygde * 50){ + p_ntn->fund -= spygde * spygde * 50; + p_ntn->embezzle *= 0.85; + + } + return 0; +} diff --git a/nation.h b/nation.h new file mode 100644 index 0000000..de80bb9 --- /dev/null +++ b/nation.h @@ -0,0 +1,70 @@ +// +// nation.h +// nation_war +// +// Created by Saturneric on 17/1/16. +// Copyright © 2017年 Bakantu Eric. All rights reserved. +// + +#ifndef nation_h +#define nation_h + + +class pdt_tech_def { + int pdtgde; + int fctgde; + int lndgde; +public: + int upd_fct(class nation *p_ntn); + int upd_lnd(class nation *p_ntn); +}; + +class ofc_tech_def { + int plcgde; + int amygde; + int emogde; + int spygde; +public: + int ugd_plc(class nation *p_ntn); + int ugd_amy(class nation *p_ntn); + int ugd_spy(class nation *p_ntn); +}; + +class amy_tech_def { + int maxgde; + int eqpgde; + +public: + int upd_eqp(class nation *p_ntn); +}; + +class nation { +public: + int fund; + double embezzle; + double pdteff; + int amyeqp; + int n_id; + int plcpeo; + int amypeo; + int amycst; + int plcoffcst; + int amyoffcst; + int lndplus; + + class pdt_tech_def m_ptd; + class ofc_tech_def m_otd; + class amy_tech_def m_atd; + + int send_fund(int send); + int set_amy(int sld_num,int mf_num, class land *p_land); + int set_fct(int mpw_num, int pf_num,class land *p_land); + nation(int s_id); + ~nation(void); + +}; + + + + +#endif /* nation_h */