ConfigMgr::ConfigMgr(std::string configPath) { try { loadGoods(configPath + "/goods.xml"); Log::info(_("Loaded goods.")); loadCarrierMapObjectTypes(configPath + "/carriers.xml"); Log::info(_("Loaded carrier mapObjectTypes.")); loadMapObjectTypes(configPath + "/map-objects.xml"); Log::info(_("Loaded mapObjectTypes.")); loadShipMapObjectTypes(configPath + "/ships.xml"); Log::info(_("Loaded ship mapObjectTypes.")); loadPopulationTiers(configPath + "/population-tiers.xml"); Log::info(_("Loaded population tiers.")); loadTilesConfig(configPath + "/tiles.xml"); Log::info(_("Loaded tiles.")); } catch (const rapidxml::parse_error& e) { // Fehler beim Parsen einer XML. // TODO e.what() kommt immer auf Englisch zurück. Das muss übersetzt werden. Idee: künstlich Phrasen anlegen throw ErrorInConfigException(string_sprintf(_("Error while loading the configuration: %s."), e.what())); } }
int main(void){ /************************** Initializing variables ***************************/ int i, j; //Misc counter int workforcePercentage; // Total amount of the population that is // workforce. int growthPercentage; // Total amount of population growth float taxCollection; // Money Collected from Taxes. float productionCost; // Cost to produce resources int consumed; // Amount of the Good Consumed. float goodReserve; // Amount of a Good to Reserve float fluxFactor; // Fluctuation Factor float fluxPrice; // Good price based on the fluctuation systemDemographics SystemData; // System Demographics production Products; // Produced Product data /******************************* Main Program ********************************/ // Seeding Randomizer srand(time(NULL)); // Loading Settings printf("Loading Config.ini...."); if(loadConfig()){ exit(0); } printf("Done.\n"); // Connecting to DB printf("Connecting to DB..."); if(connectToDB()){ exit(0); } printf("Done.\n"); // Loading Goods printf("Loading Goods..."); loadGoods(); printf("Done.\n"); // Setting Good Rates productionRate = malloc(numberOfGoods * sizeof(goodRate)); consumptionRate = malloc(numberOfGoods * sizeof(goodRate)); productionFactor = malloc(numberOfGoods * sizeof(goodRate)); // Loading Rates printf("Loading Consumption and Production Rates..."); if(loadRates()){ exit(0); } printf("Done.\n"); // Loading Markets printf("Loading Markets..."); loadDestinations(); if(loadMarkets()){ exit(0); } printf("Done.\n"); // Cycling through each market for(i = 0; i < numberOfDestinations; i++){ // Loading Demographic Data SystemData = loadSystemDemographics(destinations[i].destinationID); // Setting Growth growthPercentage = ((rand() % 10) + 1) * ((rand() % 2) ? 1:-1); SystemData.pop += round(SystemData.pop * ((float)growthPercentage/100)); // Setting Workforce workforcePercentage = ((rand() % 25) + 1); SystemData.workPop = round(SystemData.pop * ((float)workforcePercentage / 100)); // Collecting Taxes taxCollection = (SystemData.workPop * SystemData.taxes); SystemData.funds += (SystemData.workPop * taxCollection); updateDemographics(SystemData); //Producing/Consuming Goods productionCost = 0; for(j = 0; j < numberOfGoods; j++){ Products = produceGood(SystemData.systemID, goodsID[j], SystemData.workPop); // Removing workers used to produce this good from work popultion (SystemData.workPop -= Products.workers); if(SystemData.workPop < 0){ SystemData.workPop = 0; } // Updating Total Production Cost for the System productionCost += Products.cost; // Calculating Consumption Amount of the Good consumed = ((SystemData.pop * consumptionRateForGood(goodsID[j])) * (0 -1)); // Updating System's Stock updateStock(SystemData.systemID, goodsID[j], consumed); // Determining Amount to reserve goodReserve = ((float)consumed * (0 - 1)) * TICKS_TO_RESERVE_FOR; // Calculating Factor fluxFactor = 1 - ((stockLevel(SystemData.systemID, goodsID[j]) - goodReserve)/goodReserve); // Calculating New Sell Price fluxPrice = fluxFactor * goodPrice(goodsID[j], SystemData.systemID); // Did it cost more to produce then the current Sell Price if(goodPrice(goodsID[j], SystemData.systemID) - calculateProductionCost(SystemData.systemID, goodsID[j]) < 0){ // Add the difference to the new Sell Price. fluxPrice += (calculateProductionCost(SystemData.systemID, goodsID[j]) - goodPrice(goodsID[j], SystemData.systemID)); } // Update New Sell Price updatePrice(SystemData.systemID, goodsID[j], fluxPrice); } // Good Cycle for() // Update Taxes if(taxCollection - productionCost < 0){ updateTaxes(SystemData.systemID, 1); } else { updateTaxes(SystemData.systemID, -1); } }// Markets Cycle for() // Clearing memory printf("Clearing Memory..."); mysql_free_result(result); iniparser_freedict(settings); free(destinations); free(markets); printf("Done.\n"); return 0; }