//TOWNSHIP BETA E.0.03.07 BY ABCgfed
//CODING LOGS:
//E.0.00.00 FOPEN STARTING
//E.0.00.01 MEMORIZE UPDATE
//E.0.00.02 INPUT-LENGTH UPDATE
//E.0.00.03 FUNCTIONAL SETTING
//E.0.01.00 CROPS STARTING
//E.0.01.01 CHARACTER_BASIC_FUNCTION UPDATE
//E.0.01.02 LAND_BASIC_FUNCTION UPDATE
//E.0.01.03 QUERY_FUNCTION(CROP) UPDATE
//E.0.01.04 LAND_GROWING_TIME_CNT UPDATE
//E.0.01.05 REMAINED_TIME_SHOWING_SYSTEM UPDATE
//E.0.01.06 CROP_LEGELLY_PLANTED_JUDGE UPDATE
//E.0.01.07 "LAND.TXT"_UNEXPECTED_EXIT FIXED
//E.0.01.08 CROP_LOST_AFTER_HARVESTED FIXED
//E.0.01.09 SELFHELP_SELLS UPDATE
//E.0.01.10 ALL_CROPS_QUERY UPDATE
//E.0.01.11 FILE_FCLOSE FIXED
//E.0.02.00 CHARACTER_LEVEL STARTED
//E.0.02.01 CHARACTER_LEVEL_UPGRADE UPDATE
//E.0.03.00 PRODUCT STARTING
//E.0.03.01 FACTORY_TYPE STARTING
//E.0.03.02 PRODUCT_DATA UPDATE
//E.0.03.03 PRODUCT_PRODUCING UPDATE
//E.0.03.04 TOO_MANY_PRODUCTS_IN_QUEUE FIXED
//E.0.03.05 PRODUCT_ORDER UPDATE
//E.0.03.06 PRODUCT_QUERY STARTING
//E.0.03.07 PRODUCT_NOT_COLLECTED FIXED
//1 wheat;
//2 corn bread;
//3 bean egg;
//4 muffin;
//5 milk cream;
//6 carrot butter;
//7 suger_cane suger;
//8 waffle;
//9 pudding;
//10 roast_corn cheese;
//11 pork;
//12 lavender puresuger;
//13 roast_pork;
//14 cabbage noodle;
//15 vegenoodle;
//16 apple butter_and_corn;
//17 wool yarn;
//18 cotton beefburger syrup fabric bacon_noodle;
//19 rose flowercake shirt;
//WHAT TO START_
//SET "PLANTLOG.TXT" AS "0-0-0-0-0-0- "
#include<iostream>
#include<time.h>
using namespace std;
string factoryname[20]={"","bakery","feed_mill","dairy_factory","suger_factory","fast_food_restaurant","noodle_restaurant","tailor's_shop"};
string animal_farm_name[10]={"","chicken_coop","cowshed","sheep_coop","pig_farm"};
string productname[40]={"","bread","chicken_feed","egg","muffin","cow_feed","milk","cream","butter","brown_suger","waffle","pudding","roast_corn","pig_feed","pork","suger","roast_pork","noodle","vegenoodle","butter_and_corn","sheep_feed","wool","yarn","baconburger","syrup","fabric","bacon_noodle","flowercake","shirt"};
int factoryline[40]={0,3,3,3,2,2,2,2,2,2,2};
int factoryboard[40]={0,6,6,6,6,6,6,6,6,6,6};
int productlist[40]={0};
int producttime[40]={0,300,300,1200,1800,600,3600,1200,1800,1200,3600,1800,1800,1200,14400,2400,3600,3600,5400,3600,1800,21600,3600,7200,5400,7200,7200,7200,5400};
int producttype[40]={0,1,2,101,1,2,102,3,3,4,1,5,6,2,103,4,5,7,7,6,2,104,8,5,4,8,7,1,8};
int productexp[40]={0,3,4,5,6,7,8,9,10,11,12,0,0,0,0,0,0,0};
int product_allowed_level[30]={0,1,1,3,4,7,8,9,10,12,14,15,16,17,18,19,22,26,28};
int product_allowed=0;
int product_inline[40][30]={0};
int plantlist[20]={0};
int planttime[20]={0,120,300,1200,600,1800,3600,10800,57600,9000,64800};
int plantvalue[20]={0,1,2,3,2,4,7,9,11,8,13};
string plantname[20]={"","wheat","corn","bean","carrot","suger_cane","lavender","cabbage","apple","cotton","rose"};
int plantexp[20]={0,1,1,2,2,3,4,6,9,5,10};
int planttype[20]={0,0,0,0,0,0,0,0,1,0,1};
int upgradeexp[30]={0,10,20,40,80,160,320,640,1160,1840,2620,3690,5100,6640,8690,10580,13920,17950,22190,27320,34680};
int plant_allowed_level[30]={0,1,2,3,3,3,4,5,5,5,5,5,6,6,7,7,8,8,9,10};
int plant_allowed=0;
int factoryused[40]={0};
int factorywait[40]={0};
int landnum;
long long processing[200]={0};
long long coin,exp,level,sparespace;
string cnttime(long long num){
string ans="";
if(num<60){
ans=to_string(num);
ans=ans+" sec";
return ans;
}
else if(num<3600){
ans=to_string(num/60);
ans=ans+" min ";
ans=ans+to_string(num%60);
ans=ans+" sec";
return ans;
}
else if(num<86400){
ans=to_string(num/3600);
ans=ans+" hour ";
ans=ans+to_string((num%3600)/60);
ans=ans+" min ";
ans=ans+to_string(num%60);
ans=ans+" sec";
return ans;
}
else{
ans=to_string(num/86400);
ans=ans+" day ";
ans=ans+to_string((num%86400)/3600);
ans=ans+" hour ";
ans=ans+to_string((num%3600)/60);
ans=ans+" min ";
ans=ans+to_string(num%60);
ans=ans+" sec";
return ans;
}
}
void plant_cnt_reset(){
FILE *b=fopen("plantlog.txt","r");
char inp;
int his=0;
// plant_allowed=0;
int cnt=0;
while(1){
fscanf(b,"%c",&inp);
if(inp==' ')break;
if(inp=='-'){
// plant_allowed++;
cnt++;
plantlist[cnt]=his;
his=0;
}
else{
his*=10;
his+=inp-'0';
}
}
//for(int i=1;i<=plant_allowed;i++)cout<<plantlist[i]<<" ";
//cout<<endl;
fclose(b);
b=NULL;
return;
}
void product_cnt_reset(){
FILE *b=fopen("productlog.txt","r");
char inp;
int his=0;
// plant_allowed=0;
int cnt=0;
while(1){
fscanf(b,"%c",&inp);
if(inp==' ')break;
if(inp=='-'){
// plant_allowed++;
cnt++;
productlist[cnt]=his;
his=0;
}
else{
his*=10;
his+=inp-'0';
}
}
//for(int i=1;i<=plant_allowed;i++)cout<<plantlist[i]<<" ";
//cout<<endl;
fclose(b);
b=NULL;
return;
}
void plant_manual_change(){
cout<<"Enter the plant to change:"<<endl;
for(int i=1;i<=plant_allowed;i++)cin>>plantlist[i];
FILE *c=fopen("plantlog.txt","w");
string s;
for(int i=1;i<=plant_allowed;i++){
string num="";
while(plantlist[i]>0){
char k='0'+(plantlist[i]%10);
num=k+num;
plantlist[i]/=10;
}
s=s+num;
s=s+'-';
}
//cin>>s;
s=s+' ';
fprintf(c,"%s",s.c_str());
fclose(c);
cout<<"Done."<<endl;
}
void plant_auto_change(){
FILE *c=fopen("plantlog.txt","w");
string s;
for(int i=1;i<=plant_allowed;i++){
string num="";
while(plantlist[i]>0){
char k='0'+(plantlist[i]%10);
num=k+num;
plantlist[i]/=10;
}
if(num=="")num="0";
s=s+num;
s=s+'-';
}
//cin>>s;
s=s+' ';
fprintf(c,"%s",s.c_str());
//cout<<"**"<<s<<endl;
fclose(c);
plant_cnt_reset();
cout<<"Done."<<endl;
}
void product_auto_change(){
FILE *c=fopen("productlog.txt","w");
string s;
for(int i=1;i<=product_allowed;i++){
string num="";
while(productlist[i]>0){
char k='0'+(productlist[i]%10);
num=k+num;
productlist[i]/=10;
}
if(num=="")num="0";
s=s+num;
s=s+'-';
}
//cin>>s;
s=s+' ';
fprintf(c,"%s",s.c_str());
//cout<<"**"<<s<<endl;
fclose(c);
product_cnt_reset();
cout<<"Done."<<endl;
}
void character_query(){
string s;
FILE *b=fopen("character.txt","r");
int cnty[10]={0};
int cnt=0;
char inp;
int his=0;
while(1){
fscanf(b,"%c",&inp);
if(inp==' ')break;
if(inp=='-'){
cnt++;
cnty[cnt]=his;
his=0;
}
else{
his*=10;
his+=inp-'0';
}
}
level=cnty[1];
plant_allowed=plant_allowed_level[level];
product_allowed=product_allowed_level[level];
sparespace=cnty[2];
exp=cnty[3];
coin=cnty[4];
landnum=cnty[5];
cout<<"Your farm is now at level "<<level<<" with "<<sparespace<<" spare spaces, "<<upgradeexp[level]-exp<<" exp is still needed to upgrade your farm. You still have "<<coin<<" coins."<<endl;
fclose(b);
b=NULL;
return;
}
void character_change(){
string s="";
FILE *b=fopen("character.txt","w");
int cnty[10]={0};
if(exp>=upgradeexp[level]){
level++;
plant_allowed=plant_allowed_level[level];
product_allowed=product_allowed_level[level];
cout<<"You have successfully upgraded your farm to level "<<level<<"!"<<endl<<"Congradulations!"<<endl;
}
cnty[1]=level;
cnty[2]=sparespace;
cnty[3]=exp;
cnty[4]=coin;
cnty[5]=landnum;
for(int i=1;i<6;i++){
string num="";
while(cnty[i]>0){
char k='0'+(cnty[i]%10);
num=k+num;
cnty[i]/=10;
}
if(num=="")num="0";
s=s+num;
s=s+'-';
}
//cin>>s;
s=s+' ';
//cout<<s<<endl;
fprintf(b,"%s",s.c_str());
fclose(b);
b=NULL;
return;
}
void farming(){
int minu=0;
FILE *b=fopen("land.txt","r");
char inp;
long long his=0;
int land_used=0;
while(1){
fscanf(b,"%c",&inp);
if(inp==' ')break;
if(inp=='-'){
land_used++;
processing[land_used]=his;
his=0;
}
else{
his*=10;
his+=inp-'0';
}
}
land_used/=2;
for(int i=1;i<=land_used;i++){
if(time(NULL)-processing[i*2]<planttime[processing[i*2-1]])cout<<"A field which is producing "<<plantname[processing[i*2-1]]<<" still needs "<<cnttime(planttime[processing[i*2-1]]-(time(NULL)-processing[i*2]))<<" to be harvested."<<endl;
else {
cout<<"A field which is producing "<<plantname[processing[i*2-1]]<<" is mature. Enter '1' to harvest it."<<endl;
string ansa;
cin>>ansa;
if(ansa=="1"){
if(1/*barn is enough*/){
plantlist[processing[i*2-1]]++;
exp+=plantexp[processing[i*2-1]];
character_change();
processing[i*2]=0;
minu++;
plant_auto_change();
}
else{
}
}
}
}
cout<<endl;
fclose(b);
b=NULL;
while(landnum-land_used+minu>0){
cout<<"Enter the crop you'd like to grow. Enter '0' to return."<<endl;
string ansa;
cin>>ansa;
if(ansa=="0"){
break;
}
for(int i=1;i<=plant_allowed;i++){
if(ansa==plantname[i]){
int numc;
cin>>numc;
if(planttype[i]==1){
cout<<"This type of plant is not planted here."<<endl;
break;
}
for(int j=0;j<numc;j++){
land_used++;
processing[land_used*2-1]=i;
processing[land_used*2]=time(NULL);
if(landnum-land_used+minu<=0) break;
}
}
}
}
string s="";
for(int i=1;i<=land_used;i++){
if(processing[i*2]==0) continue;
string num="";
while(processing[i*2-1]>0){
char k='0'+(processing[i*2-1]%10);
num=k+num;
processing[i*2-1]/=10;
}
s=s+num;
s=s+'-';
num="";
while(processing[i*2]>0){
char k='0'+(processing[i*2]%10);
num=k+num;
processing[i*2]/=10;
}
s=s+num;
s=s+'-';
}
//cin>>s;
s=s+' ';
//cout<<s<<endl;
FILE *d=fopen("land.txt","w");
fprintf(d,"%s",s.c_str());
cout<<"Done."<<endl;
fclose(d);
d=NULL;
//for(int i=0;i<=plant_allowed;i++)cout<<plantlist[i]<<" ";
//cout<<endl;
return;
}
void producing(){
for(int i=0;i<35;i++){
for(int j=0;j<25;j++)product_inline[i][j]=0;
factoryused[i]=0;
factorywait[i]=0;
}
int minu=0;
FILE *b=fopen("factory.txt","r");
char inp;
long long his=0;
for(int i=0;i<15;i++){
factoryused[i]=0;
}
// int land_used=0;
int cnt=0;
while(1){
fscanf(b,"%c",&inp);
if(inp==' ')break;
if(inp=='-'){
cnt++;
if(cnt%2==1){
if(producttype[his]<100){
factoryused[producttype[his]]++;
product_inline[producttype[his]][factoryused[producttype[his]]]=(cnt+1)/2;
}
else{
}
}
else{
if(his>time(NULL))factorywait[producttype[processing[cnt-1]]]++;
}
processing[cnt]=his;
his=0;
}
else{
his*=10;
his+=inp-'0';
}
}
cnt/=2;
for(int i=1;i<=cnt;i++){
if(processing[i*2]!=9999999999&&time(NULL)-processing[i*2]<producttime[processing[i*2-1]])cout<<"Production of "<<productname[processing[i*2-1]]<<" still needs "<<cnttime(producttime[processing[i*2-1]]-(time(NULL)-processing[i*2]))<<" to be finished."<<endl;
else if(processing[i*2]==9999999999)cout<<"Order to produce "<<productname[processing[i*2-1]]<<" is still waiting in the producing queue."<<endl<<"The "<<factoryname[producttype[processing[i*2-1]]]<<" doesn't have enough space to produce "<<productname[processing[i*2-1]]<<". Please take off something from the board."<<endl;
else {
cout<<"The order to produce "<<productname[processing[i*2-1]]<<" is finished. Enter '1' to collect it."<<endl;
string ansa;
cin>>ansa;
if(ansa=="1"){
if(1/*barn is enough*/){
factoryused[producttype[processing[i*2-1]]]--;
productlist[processing[i*2-1]]++;
exp+=productexp[processing[i*2-1]];
character_change();
processing[i*2]=0;
product_auto_change();
long long histime=0;
for(int j=1;j<25;j++){
if(product_inline[producttype[processing[i*2-1]]][j]==0)break;
if(processing[product_inline[producttype[i]][j]*2]+producttime[processing[product_inline[producttype[i]][j]*2-1]]>time(NULL)&&processing[product_inline[producttype[i]][j]*2]+producttime[processing[product_inline[producttype[i]][j]*2-1]]!=9999999999){
histime=processing[product_inline[producttype[i]][j]*2]+producttime[processing[product_inline[producttype[i]][j]*2-1]];
}
}
for(int j=1;j<25;j++){
if(product_inline[producttype[processing[i*2-1]]][j]==0)break;
if(processing[product_inline[producttype[processing[i*2-1]]][j]*2]==9999999999){
processing[product_inline[producttype[processing[i*2-1]]][j]*2]=histime;
break;
}
}
}
else{
}
}
}
}
cout<<endl;
fclose(b);
b=NULL;
while(1){
cout<<"Enter the stuff you'd like to produce. Enter '0' to return."<<endl;
string ansa;
cin>>ansa;
if(ansa=="0"){
break;
}
for(int i=1;i<=product_allowed;i++){
if(ansa==productname[i]){
// int numc;
// cin>>numc;
if(producttype[i]>100){
// anim;
cout<<"This type of stuff is not planted here."<<endl;
break;
}
// for(int j=0;j<numc;j++){
// cnt++;
// processing[cnt*2-1]=i;
// processing[cnt*2]=time(NULL);
// if(landnum-cnt+minu<=0) break;
// }
long long histime=0;
int in_line=0;
for(int j=1;j<25;j++){
cout<<j<<" "<<in_line<<endl;
if(product_inline[producttype[processing[i*2-1]]][j]==0)break;
if(processing[product_inline[producttype[i]][j]*2]+producttime[processing[product_inline[producttype[i]][j]*2-1]]>time(NULL)){
histime=processing[product_inline[producttype[i]][j]*2]+producttime[processing[product_inline[producttype[i]][j]*2-1]];
in_line++;
}
}
if(in_line>=factoryline[producttype[i]]||factoryused[producttype[i]]>=factoryboard[producttype[i]]+factoryline[producttype[i]]){
cout<<"Producing queue is full."<<endl;
break;
}
if(factoryused[producttype[i]]>=factoryboard[producttype[i]]){
cnt++;
processing[cnt*2-1]=i;
processing[cnt*2]=9999999999;
factoryused[producttype[i]]++;
product_inline[producttype[i]][factoryused[producttype[i]]]=cnt;
// cout<<"aaa"<<cnt<<endl;
}
else{
cnt++;
processing[cnt*2-1]=i;
processing[cnt*2]=max(histime,time(NULL));
factoryused[producttype[i]]++;
product_inline[producttype[i]][factoryused[producttype[i]]]=cnt;
// cout<<"bbb"<<cnt<<endl;
}
// if(landnum-cnt+minu<=0) break;
}
}
}
string s="";
for(int i=1;i<=cnt;i++){
if(processing[i*2]==0) continue;
string num="";
while(processing[i*2-1]>0){
char k='0'+(processing[i*2-1]%10);
num=k+num;
processing[i*2-1]/=10;
}
s=s+num;
s=s+'-';
num="";
while(processing[i*2]>0){
char k='0'+(processing[i*2]%10);
num=k+num;
processing[i*2]/=10;
}
s=s+num;
s=s+'-';
}
//cin>>s;
s=s+' ';
//cout<<s<<endl;
FILE *d=fopen("factory.txt","w");
fprintf(d,"%s",s.c_str());
cout<<"Done."<<endl;
fclose(d);
d=NULL;
//for(int i=0;i<=plant_allowed;i++)cout<<plantlist[i]<<" ";
//cout<<endl;
return;
}
int main(){
cout<<endl<<" TOWNSHIP E.0.03.07 BY ABCgfed "<<endl;
for(int i=0;i<700000000;i+=2){
if(i%5840000==0)cout<<'-';
}
for(int i=0;i<100000000;i++);
cout<<endl;
plant_cnt_reset();
product_cnt_reset();
character_query();
while(1){
string order;
cin>>order;
if(order=="exist"){
break;
}
else if(order=="cheat"){
plant_manual_change();
}
else if(order=="query"){
cout<<"Enter the type to search for:"<<endl;
string ans;
cin>>ans;
if(ans=="crop"){
cout<<"Enter the thing to search for(in crop):"<<endl;
string target;
cin>>target;
int checkpoint=0;
if(target=="all"){
cout<<"Still Remain:"<<endl;
for(int i=1;i<=plant_allowed;i++){
cout<<" "<<plantname[i]<<" x"<<plantlist[i]<<endl;
}
checkpoint++;
}
for(int i=1;i<=plant_allowed;i++){
if(target==plantname[i]){
cout<<"Still Remain: "<<plantlist[i]<<endl;
//for(int u=0;u<plant_allowed;u++)cout<<plantlist[u]<<" ";
//cout<<endl;
checkpoint=1;
}
}
if(checkpoint==0){
cout<<"Not Exist."<<endl;
}
}
else if(ans=="item"||ans=="stuff"){
cout<<"Enter the thing to search for(in item):"<<endl;
string target;
cin>>target;
int checkpoint=0;
if(target=="all"){
cout<<"Still Remain:"<<endl;
for(int i=1;i<=product_allowed;i++){
cout<<" "<<productname[i]<<" x"<<productlist[i]<<endl;
}
checkpoint++;
}
for(int i=1;i<=product_allowed;i++){
if(target==productname[i]){
cout<<"Still Remain: "<<productlist[i]<<endl;
//for(int u=0;u<plant_allowed;u++)cout<<plantlist[u]<<" ";
//cout<<endl;
checkpoint=1;
}
}
if(checkpoint==0){
cout<<"Not Exist."<<endl;
}
}
else if(ans=="character"){
character_query();
}
else{
}
}
else if(order=="operate"){
cout<<"Enter the act you're going to do:"<<endl;
string ans;
cin>>ans;
if(ans=="farming"){
farming();
}
else if(ans=="producing"){
producing();
}
else if(ans=="raising"){
}
else if(ans=="selling"){
cout<<"Enter the type ready to sell:"<<endl;
string ans;
cin>>ans;
if(ans=="crop"){
cout<<"Enter the thing ready to sell(in crop):"<<endl;
string target;
int sellnum=0;
cin>>target>>sellnum;
int checkpoint=0;
int i=1;
for(;i<=plant_allowed;i++){
if(target==plantname[i]){
//cout<<"Still Remain: "<<plantlist[i]<<endl;
if(plantlist[i]<sellnum){
checkpoint=2;
break;
}
else{
plantlist[i]-=sellnum;
plant_auto_change();
coin+=(plantvalue[i]*sellnum);
character_change();
cout<<"Coin: "<<coin-(plantvalue[i]*sellnum)<<" -> "<<coin<<endl<<target<<": "<<plantlist[i]+sellnum<<" -> "<<plantlist[i]<<endl;
}
checkpoint=1;
}
}
if(checkpoint==0){
cout<<"Not Exist."<<endl;
}
if(checkpoint==2){
cout<<"Not enough "<<target<<". Still remain: "<<plantlist[i]<<endl;
}
}
else if(ans=="item"){
}
}
else{
}
}
else{
//
}
}
return 0;
}
剪贴板
剪贴板 182drcm3
剪贴板信息
剪贴板信息
- 收录
- 更新