#include #include #include #include #include int MAXBUFFERLENGTH; #include "FILEMAN.CPP" //arrotonda un numero in virgola mobile in intero long round(double num) { long tmp; tmp = long(num); if(((num-float(tmp))*1000)>=500) tmp++; return tmp; } //calcola la popolazione dopo un tot di ore long pop_end(long pop_start, float pop_growth, long hours) { return round(float(pop_start)*pow(float(1)+pop_growth/100, hours)); } //calcola le ore necessarie per raggiungere la popolazione indicata long hours_to_pop(long population, float pop_growth, long pop_end) { long hours; hours = 0; while(population < pop_end) { population = population+round(float(population)*pop_growth/100); hours++; } return hours; } //calcola le ore necessarie per raggiungere un tot indicato long hours_to(long what, long growth, long end) { long hours; hours = 0; while(what < end) { what = what+growth; hours++; } return hours; } //inserisce i dati di base void setup(long &population, float &pop_growth, long &metal, long &metal_growth, long &mineral, long &mineral_growth) { cout << "Initialization..." << endl; cout << "Insert Actual Population (" << population << "): "; cin >> population; cout << "Insert Population Growth per hour (" << pop_growth << "%): "; cin >> pop_growth; cout << "Insert Actual Metals (" << metal << "): "; cin >> metal; cout << "Insert actual Metals Production per hour: (" << metal_growth << "): "; cin >> metal_growth; cout << "Insert Actual Minerals: (" << mineral << "): "; cin >> mineral; cout << "Insert actual Metarals Production per hour: (" << mineral_growth << "): "; cin >> mineral_growth; cout << "Completed!" << endl; } void save(Fileman &planetstd, long population, float pop_growth, long metal, long metal_growth, long mineral, long mineral_growth) { char num[10]; ltoa(population, num, 10); planetstd.Write(num, 1, 1); ltoa(round(pop_growth*1000), num, 10); planetstd.Write(num, 1); ltoa(metal, num, 10); planetstd.Write(num, 1); ltoa(metal_growth, num, 10); planetstd.Write(num, 1); ltoa(mineral, num, 10); planetstd.Write(num, 1); ltoa(mineral_growth, num, 10); planetstd.Write(num, 1); } int main() { long population = 0; float pop_growth = 0; long metal = 0; long metal_growth = 0; long mineral = 0; long mineral_growth = 0; long tmp; int ch; char c; MAXBUFFERLENGTH=1000; Fileman planetstd("darkman.inf"); cout << "Loading 'darkman.inf'..." << endl; if(!planetstd.Exists()) { cout << "WARNING: Unable to find the file!" << endl; setup(population, pop_growth, metal, metal_growth, mineral, mineral_growth); save(planetstd, population, pop_growth, metal, metal_growth, mineral, mineral_growth); } else { if(planetstd.ReadLine()) population = atol(planetstd.buffer); planetstd.ReadLine(); if(planetstd.ReadLine()) pop_growth = float(atol(planetstd.buffer))/1000; planetstd.ReadLine(); if(planetstd.ReadLine()) metal = atol(planetstd.buffer); planetstd.ReadLine(); if(planetstd.ReadLine()) metal_growth = atol(planetstd.buffer); planetstd.ReadLine(); if(planetstd.ReadLine()) mineral = atol(planetstd.buffer); planetstd.ReadLine(); if(planetstd.ReadLine()) mineral_growth = atol(planetstd.buffer); cout << "Completed." << endl; } //setup(population, pop_growth, metal, metal_growth, mineral, mineral_growth); do { cout << endl << "DARKMAN - ver 0.2 alpha - by Rogue" << endl << endl; cout << "Actual Population: " << population << endl; cout << "Actual Population Growth: " << pop_growth << endl; cout << "Actual Metals: " << metal << endl; cout << "Actual Metals Growth: " << metal_growth << endl; cout << "Actual Minerals: " << mineral << endl; cout << "Actual Minerals Growth: " << mineral_growth << endl; cout << endl; cout << "[1] Population after x hours" << endl; cout << "[2] Hours to match x population" << endl << endl; cout << "[3] Metals after x hours" << endl; cout << "[4] Hours to match x metals" << endl << endl; cout << "[5] Minerals after x hours" << endl; cout << "[6] Hours to match x minerals" << endl << endl; cout << "[8] Setup" << endl << endl; cout << "[9] Save" << endl << endl; cout << "[0] Quit" << endl; cout << ">"; cin >> ch; if(ch==1) { cout << "Insert hours: "; cin >> tmp; cout << "Final population will be " << pop_end(population, pop_growth, tmp) << endl; cin >> c; } else if(ch==2) { cout << "Insert final population: "; cin >> tmp; cout << "You'll need " << hours_to_pop(population, pop_growth, tmp) << " hours" << endl; cin >> c; } else if(ch==3) { cout << "Insert hours: "; cin >> tmp; cout << "Final metals will be " << metal+metal_growth*tmp << endl; cin >> c; } else if(ch==4) { cout << "Insert final metals: "; cin >> tmp; cout << "You'll need " << hours_to(metal, metal_growth, tmp) << " hours" << endl; cin >> c; } else if(ch==5) { cout << "Insert hours: "; cin >> tmp; cout << "Final minerals will be " << mineral+mineral_growth*tmp << endl; cin >> c; } else if(ch==6) { cout << "Insert final minerals: "; cin >> tmp; cout << "You'll need " << hours_to(mineral, mineral_growth, tmp) << " hours" << endl; cin >> c; } else if(ch==8) { setup(population, pop_growth, metal, metal_growth, mineral, mineral_growth); } else if(ch==9) { save(planetstd, population, pop_growth, metal, metal_growth, mineral, mineral_growth); } }while(ch); return 0; }