void updateDate()
{
    std::ostringstream dateText;

    int day = total_time % NUMOF_DAYS_IN_MONTH +1; // 1..NUMOF_DAYS_IN_MONTH
    day = 1 + ( 29 * day / NUMOF_DAYS_IN_MONTH ); // 1..30
    dateText << day << ". ";

    dateText << current_month( total_time );
    dateText << " "<< current_year( total_time );

    Component* root = getGameView();
    if( !root ) return;
    while( root->getParent() )
        root = root->getParent();

    if( dateText.str() == lastDateText ){
        return;
    }
    Component* dateParagraphComponent = 0;
    dateParagraphComponent = root->findComponent( "dateParagraph" );
    if( dateParagraphComponent == 0 )
    {   return;}
    Paragraph* dateParagraph = getParagraph( *root, "dateParagraph");
    if( !dateParagraph )
    {   return;}
    dateParagraph->setText( dateText.str() );
    lastDateText = dateText.str();
}
Beispiel #2
0
/*
 *
 * Test program 
 *
 */
int main ()
{
  printf("Current year: %d\n", current_year());
  printf("Months left:  %d\n", month_left());
  printf("max:          %d\n", max(12, 13));

  print_current_date();
  
  return(0);
}
/* 
 * Save game statistics to RESULTS_FILENAME. Do NOT translate text here!
 * That way the files can be used for highscores.
 */
void Dialog::saveGameStats(){
    //open File
    char *s;
    if ((s = (char *) malloc (lc_save_dir_len + strlen (LC_SAVE_DIR)
			      + strlen (RESULTS_FILENAME) + 64)) == 0)
	malloc_failure ();
    sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, RESULTS_FILENAME);

    std::ofstream results( s );
    free( s );
    
    // Fill in Fields.
    int maxlength = 567;
    char* outf = (char *) malloc ( maxlength );
    int group_count[NUM_OF_GROUPS];
    count_all_groups (group_count);
    if (cheat_flag){
        results << "----- IN TEST MODE -------"  << std::endl;
    }
    snprintf (outf, maxlength, "Game statistics from LinCity-NG Version %s", PACKAGE_VERSION);
    results << outf << std::endl;
    if (strlen (given_scene) > 3){
	    snprintf (outf, maxlength, "Initial loaded scene - %s", given_scene);
        results << outf << std::endl;
    }
    if (sustain_flag){
	    snprintf (outf, maxlength, "Economy is sustainable");
        results << outf << std::endl;
    }
    snprintf (outf, maxlength, "Population  %d  of which  %d  are not housed."
	     ,housed_population + people_pool, people_pool);
    results << outf << std::endl;
    snprintf (outf, maxlength,
	     "Max population %d  Number evacuated %d Total births %d"
	     ,max_pop_ever, total_evacuated, total_births);
    results << outf << std::endl;
    snprintf (outf, maxlength,
	     "Date %02d/%04d  Money %8d   Tech-level %5.1f (%5.1f)",
	     1 + ((total_time % NUMOF_DAYS_IN_YEAR) / NUMOF_DAYS_IN_MONTH), current_year(total_time), total_money,
	     (float) tech_level * 100.0 / MAX_TECH_LEVEL,
	     (float) highest_tech_level * 100.0 / MAX_TECH_LEVEL);
    results << outf << std::endl;
    snprintf (outf, maxlength,
	     " Deaths by starvation %7d   History %8.3f",
	     total_starve_deaths, starve_deaths_history);
    results << outf << std::endl;
    snprintf (outf, maxlength,
	     "Deaths from pollution %7d   History %8.3f",
	     total_pollution_deaths, pollution_deaths_history);
    results << outf << std::endl;
    snprintf (outf, maxlength, "Years of unemployment %7d   History %8.3f",
	     total_unemployed_years, unemployed_history);
    results << outf << std::endl;
    snprintf (outf, maxlength, "Rockets launched %2d  Successful launches %2d",
	     rockets_launched, rockets_launched_success);
    results << outf << std::endl;
    results << "" << std::endl;

    snprintf (outf, maxlength, "    Residences %4d         Markets %4d            Farms %4d",
	     group_count[GROUP_RESIDENCE_LL] + 
	     group_count[GROUP_RESIDENCE_ML] + 
	     group_count[GROUP_RESIDENCE_HL] + 
	     group_count[GROUP_RESIDENCE_LH] + 
	     group_count[GROUP_RESIDENCE_MH] + 
	     group_count[GROUP_RESIDENCE_HH],
	     group_count[GROUP_MARKET],
	     group_count[GROUP_ORGANIC_FARM]);
    results << outf << std::endl;
    snprintf (outf, maxlength, "   Water wells %4d", group_count[GROUP_WATERWELL]);
    results << outf << std::endl;
    snprintf (outf, maxlength, "     Monuments %4d         Schools %4d     Universities %4d"
	     ,group_count[GROUP_MONUMENT], group_count[GROUP_SCHOOL]
	     ,group_count[GROUP_UNIVERSITY]);
    results << outf << std::endl;
    snprintf (outf, maxlength, " Fire stations %4d           Parks %4d    Sports fields %4d"
	     ,group_count[GROUP_FIRESTATION], group_count[GROUP_PARKLAND]
	     ,group_count[GROUP_CRICKET]);
    results << outf << std::endl;
    snprintf (outf, maxlength, "Health centres %4d            Tips %4d         Shanties %4d",
	     group_count[GROUP_HEALTH], group_count[GROUP_TIP],
	     group_count[GROUP_SHANTY]);
    results << outf << std::endl;
    results << "" << std::endl;

    snprintf (outf, maxlength, "     Windmills %4d     Coal powers %4d     Solar powers %4d",
	     group_count[GROUP_WINDMILL],
	     group_count[GROUP_COAL_POWER],
	     group_count[GROUP_SOLAR_POWER]);
    results << outf << std::endl;
    snprintf (outf, maxlength, "   Substations %4d     Power lines %4d            Ports %4d"
	     ,group_count[GROUP_SUBSTATION], group_count[GROUP_POWER_LINE]
	     ,group_count[GROUP_PORT]);
    results << outf << std::endl;
    snprintf (outf, maxlength, "        Tracks %4d           Roads %4d             Rail %4d"
	     ,group_count[GROUP_TRACK], group_count[GROUP_ROAD]
	     ,group_count[GROUP_RAIL]);
    results << outf << std::endl;
    results << "" << std::endl;

    snprintf (outf, maxlength, "     Potteries %4d     Blacksmiths %4d            Mills %4d"
	     ,group_count[GROUP_POTTERY], group_count[GROUP_BLACKSMITH]
	     ,group_count[GROUP_MILL]);
    results << outf << std::endl;
    snprintf (outf, maxlength, "    Light inds %4d      Heavy inds %4d        Recyclers %4d"
	     ,group_count[GROUP_INDUSTRY_L], group_count[GROUP_INDUSTRY_H]
	     ,group_count[GROUP_RECYCLE]);
    results << outf << std::endl;
    snprintf (outf, maxlength, "    Coal mines %4d       Ore mines %4d         Communes %4d"
	     ,group_count[GROUP_COALMINE], group_count[GROUP_OREMINE]
	     ,group_count[GROUP_COMMUNE]);
    results << outf << std::endl;
    results << "" << std::endl;
    
    //close File
    results.close();
        
    free( outf );
}
/* 
 * Show game statistics in dialog and write them to RESULTS_FILENAME.
 *
 * gamestats.xml has 11 lines 
 * statistic_text1 
 * [...]
 * statistic_text11
 * and 15 lines in a Table with 6 columns
 * statistic_text_1_1  statistic_number_1_1  statistic_text_1_2  statistic_number_1_2  statistic_text_1_3  statistic_number_1_3
 * [...]
//  * statistic_text_15_1 statistic_number_15_1 statistic_text_15_2 statistic_number_15_2 statistic_text_15_3 statistic_number_15_3
 */
void Dialog::gameStats(){
     saveGameStats();
     if( !desktop ) {
        std::cerr << "No desktop found.\n";
        return;
    }
    bool useExisting = false;
    myDialogComponent = desktop->findComponent("GameStats");
    if( myDialogComponent == 0){
        try {
            myDialogComponent = loadGUIFile( "gui/gamestats.xml" );
            assert( myDialogComponent != 0);
            registerDialog();
        } catch(std::exception& e) {
            std::cerr << "Couldn't display message 'gamestats': "
                << e.what() << "\n";
            return;
        }
    } else {
        useExisting = true;
    }
    
    // Fill in Fields.
    int line = 1;
    int maxlength = 567;
    char* outf = (char *) malloc ( maxlength );
    int group_count[NUM_OF_GROUPS];
    count_all_groups (group_count);
    if (cheat_flag){
        setParagraphN( "statistic_text", line++, _("----- IN TEST MODE -------") );
    }
    snprintf (outf, maxlength, _("Game statistics from LinCity-NG Version %s"), PACKAGE_VERSION);
    setParagraphN( "statistic_text", line++, outf );
    if (strlen (given_scene) > 3){
	    snprintf (outf, maxlength, _("Initial loaded scene - %s"), given_scene);
        setParagraphN( "statistic_text", line++, outf );
    }
    if (sustain_flag){
	    snprintf (outf, maxlength, _("Economy is sustainable"));
        setParagraphN( "statistic_text", line++, outf );
    }
    snprintf (outf, maxlength, _("Population  %d  of which  %d  are not housed.")
	     ,housed_population + people_pool, people_pool);
    setParagraphN( "statistic_text", line++, outf );
    snprintf (outf, maxlength,
	     _("Max population %d  Number evacuated %d Total births %d")
	     ,max_pop_ever, total_evacuated, total_births);
    setParagraphN( "statistic_text", line++, outf );
    snprintf (outf, maxlength,
	     _("Date %s %04d  Money %8d   Tech-level %5.1f (%5.1f)"),
	     current_month(total_time), current_year(total_time), total_money,
	     (float) tech_level * 100.0 / MAX_TECH_LEVEL,
	     (float) highest_tech_level * 100.0 / MAX_TECH_LEVEL);
    setParagraphN( "statistic_text", line++, outf );
    snprintf (outf, maxlength,
	     _("Deaths by starvation %7d   History %8.3f"),
	     total_starve_deaths, starve_deaths_history);
    setParagraphN( "statistic_text", line++, outf );
    snprintf (outf, maxlength,
	     _("Deaths from pollution %7d   History %8.3f"),
	     total_pollution_deaths, pollution_deaths_history);
    setParagraphN( "statistic_text", line++, outf );
    snprintf (outf, maxlength, _("Years of unemployment %7d   History %8.3f"),
	     total_unemployed_years, unemployed_history);
    setParagraphN( "statistic_text", line++, outf );
    snprintf (outf, maxlength, _("Rockets launched %2d  Successful launches %2d"),
	     rockets_launched, rockets_launched_success);
    setParagraphN( "statistic_text", line++, outf );

    while( line <= 11 ){ //clear remaining lines
        setParagraphN( "statistic_text", line++, "" );
    }
    free( outf );

    setTableRC("statistic", 1, 1, _("Residences"),
	     group_count[GROUP_RESIDENCE_LL] + 
	     group_count[GROUP_RESIDENCE_ML] + 
	     group_count[GROUP_RESIDENCE_HL] + 
	     group_count[GROUP_RESIDENCE_LH] + 
	     group_count[GROUP_RESIDENCE_MH] + 
	     group_count[GROUP_RESIDENCE_HH]);
    setTableRC("statistic", 1, 2, _("Markets"), group_count[GROUP_MARKET] );
    setTableRC("statistic", 1, 3, _("Farms"), group_count[GROUP_ORGANIC_FARM]);
    
    setTableRC("statistic", 2, 1, _("Water wells"), group_count[GROUP_WATERWELL]);
    setTableRC("statistic", 2, 2, "", "");
    setTableRC("statistic", 2, 3, "", "");

    setTableRC("statistic", 3, 1, "", "");
    setTableRC("statistic", 3, 2, "", "");
    setTableRC("statistic", 3, 3, "", "");

    setTableRC("statistic", 4, 1, _("Monuments"), group_count[GROUP_MONUMENT]); 
    setTableRC("statistic", 4, 2, _("Schools"),  group_count[GROUP_SCHOOL]);
    setTableRC("statistic", 4, 3, _("Universities"), group_count[GROUP_UNIVERSITY]);

    setTableRC("statistic", 5, 1, _("Fire stations"), group_count[GROUP_FIRESTATION]);
    setTableRC("statistic", 5, 2, _("Parks"), group_count[GROUP_PARKLAND]);
    setTableRC("statistic", 5, 3, _("Sports fields"), group_count[GROUP_CRICKET]);

    setTableRC("statistic", 6, 1, _("Health centres"), group_count[GROUP_HEALTH]);
    setTableRC("statistic", 6, 2, _("Tips"), group_count[GROUP_TIP]);
    setTableRC("statistic", 6, 3, _("Shanties"), group_count[GROUP_SHANTY]);

    setTableRC("statistic", 7, 1, "", "");
    setTableRC("statistic", 7, 2, "", "");
    setTableRC("statistic", 7, 3, "", "");

    setTableRC("statistic", 8, 1, _("Windmills"), group_count[GROUP_WINDMILL]);
    setTableRC("statistic", 8, 2, _("Coal powers"), group_count[GROUP_COAL_POWER]);
    setTableRC("statistic", 8, 3, _("Solar powers"), group_count[GROUP_SOLAR_POWER]);

    setTableRC("statistic", 9, 1, _("Substations"), group_count[GROUP_SUBSTATION]);
    setTableRC("statistic", 9, 2, _("Power lines"), group_count[GROUP_POWER_LINE]);
    setTableRC("statistic", 9, 3, _("Ports"), group_count[GROUP_PORT]);

    setTableRC("statistic", 10, 1, _("Tracks"), group_count[GROUP_TRACK]);
    setTableRC("statistic", 10, 2, _("Roads"), group_count[GROUP_ROAD]);
    setTableRC("statistic", 10, 3, _("Rail"), group_count[GROUP_RAIL]);

    setTableRC("statistic", 11, 1, "", "");
    setTableRC("statistic", 11, 2, "", "");
    setTableRC("statistic", 11, 3, "", "");

    setTableRC("statistic", 12, 1, _("Potteries"), group_count[GROUP_POTTERY]);
    setTableRC("statistic", 12, 2, _("Blacksmiths"), group_count[GROUP_BLACKSMITH]);
    setTableRC("statistic", 12, 3, _("Mills"), group_count[GROUP_MILL]);

    setTableRC("statistic", 13, 1, _("Light inds"), group_count[GROUP_INDUSTRY_L]);
    setTableRC("statistic", 13, 2, _("Heavy inds"), group_count[GROUP_INDUSTRY_H]);
    setTableRC("statistic", 13, 3, _("Recyclers"), group_count[GROUP_RECYCLE]);

    setTableRC("statistic", 14, 1, _("Coal mines"), group_count[GROUP_COALMINE]);
    setTableRC("statistic", 14, 2, _("Ore mines"), group_count[GROUP_OREMINE]);
    setTableRC("statistic", 14, 3, _("Communes"), group_count[GROUP_COMMUNE]);

    setTableRC("statistic", 15, 1, "", "");
    setTableRC("statistic", 15, 2, "", "");
    setTableRC("statistic", 15, 3, "", "");
   
    if( !useExisting ){
        // connect signals
        Button* noButton = getButton( *myDialogComponent, "Okay" );
        noButton->clicked.connect( makeCallback( *this, &Dialog::closeDialogButtonClicked ) );
    }
}
Beispiel #5
0
/*
 * Save game statistics to RESULTS_FILENAME. Do NOT translate text here!
 * That way the files can be used for highscores.
 */
void Dialog::saveGameStats(){
    //open File
    char *s;
    if ((s = (char *) malloc (lc_save_dir_len + strlen (LC_SAVE_DIR)
                  + strlen (RESULTS_FILENAME) + 64)) == 0)
    malloc_failure ();
    sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, RESULTS_FILENAME);

    std::ofstream results( s );
    free( s );

    // Fill in Fields.
    int maxlength = 567;
    char* outf = (char *) malloc ( maxlength );
    //int group_count[NUM_OF_GROUPS];
    //count_all_groups (group_count);
    if (cheat_flag){
        results << "----- IN TEST MODE -------"  << std::endl;
    }
    snprintf (outf, maxlength, "Game statistics from LinCity-NG Version %s", PACKAGE_VERSION);
    results << outf << std::endl;
    if (strlen (given_scene) > 3){
        snprintf (outf, maxlength, "Initial loaded scene - %s", given_scene);
        results << outf << std::endl;
    }
    if (sustain_flag){
        snprintf (outf, maxlength, "%s", "Economy is sustainable");
        results << outf << std::endl;
    }
    snprintf (outf, maxlength, "Population  %d  of which  %d  are not housed."
         ,population + people_pool, people_pool);
    results << outf << std::endl;
    snprintf (outf, maxlength,
         "Max population %d  Number evacuated %d Total births %d"
         ,max_pop_ever, total_evacuated, total_births);
    results << outf << std::endl;
    snprintf (outf, maxlength,
         "Date %02d/%04d  Money %8d   Tech-level %5.1f (%5.1f)",
         1 + ((total_time % NUMOF_DAYS_IN_YEAR) / NUMOF_DAYS_IN_MONTH), current_year(total_time), total_money,
         (float) tech_level * 100.0 / MAX_TECH_LEVEL,
         (float) highest_tech_level * 100.0 / MAX_TECH_LEVEL);
    results << outf << std::endl;
    snprintf (outf, maxlength,
         " Deaths by starvation %7d   History %8.3f",
         total_starve_deaths, starve_deaths_history);
    results << outf << std::endl;
    snprintf (outf, maxlength,
         "Deaths from pollution %7d   History %8.3f",
         total_pollution_deaths, pollution_deaths_history);
    results << outf << std::endl;
    snprintf (outf, maxlength, "Years of unemployment %7d   History %8.3f",
         total_unemployed_years, unemployed_history);
    results << outf << std::endl;
    snprintf (outf, maxlength, "Rockets launched %2d  Successful launches %2d",
         rockets_launched, rockets_launched_success);
    results << outf << std::endl;
    results << "" << std::endl;

    snprintf (outf, maxlength, "    Residences %4d         Markets %4d            Farms %4d",
         Counted<Residence>::getInstanceCount(),
         Counted<Market>::getInstanceCount(),
         Counted<Organic_farm>::getInstanceCount());
    results << outf << std::endl;
    snprintf (outf, maxlength, "   Water wells %4d     Wind powers %4d",
    Counted<Waterwell>::getInstanceCount(),Counted<Windpower>::getInstanceCount());
    results << outf << std::endl;
    snprintf (outf, maxlength, "     Monuments %4d         Schools %4d     Universities %4d"
         ,Counted<Monument>::getInstanceCount(), Counted<School>::getInstanceCount()
         ,Counted<University>::getInstanceCount());
    results << outf << std::endl;
    snprintf (outf, maxlength, " Fire stations %4d           Parks %4d    Sports fields %4d"
         ,Counted<FireStation>::getInstanceCount(), Counted<Parkland>::getInstanceCount()
         ,Counted<Cricket>::getInstanceCount());
    results << outf << std::endl;
    snprintf (outf, maxlength, "Health centres %4d            Tips %4d         Shanties %4d",
         Counted<HealthCentre>::getInstanceCount(), Counted<Tip>::getInstanceCount(),
         Counted<Shanty>::getInstanceCount());
    results << outf << std::endl;
    results << "" << std::endl;

    snprintf (outf, maxlength, "     Windmills %4d     Coal powers %4d     Solar powers %4d",
         Counted<Windmill>::getInstanceCount(),
         Counted<Coal_power>::getInstanceCount(),
         Counted<SolarPower>::getInstanceCount());
    results << outf << std::endl;
    snprintf (outf, maxlength, "   Substations %4d     Power lines %4d            Ports %4d"
         ,Counted<Substation>::getInstanceCount(), Counted<Powerline>::getInstanceCount()
         ,Counted<Port>::getInstanceCount());
    results << outf << std::endl;
    snprintf (outf, maxlength, "        Tracks %4d           Roads %4d             Rail %4d"
         ,Counted<Track>::getInstanceCount(), Counted<Road>::getInstanceCount()
         ,Counted<Road>::getInstanceCount());
    results << outf << std::endl;
    results << "" << std::endl;

    snprintf (outf, maxlength, "     Potteries %4d     Blacksmiths %4d            Mills %4d"
         ,Counted<Pottery>::getInstanceCount(), Counted<Blacksmith>::getInstanceCount()
         ,Counted<Mill>::getInstanceCount());
    results << outf << std::endl;
    snprintf (outf, maxlength, "    Light inds %4d      Heavy inds %4d        Recyclers %4d"
         ,Counted<IndustryLight>::getInstanceCount(), Counted<IndustryHeavy>::getInstanceCount()
         ,Counted<Recycle>::getInstanceCount());
    results << outf << std::endl;
    snprintf (outf, maxlength, "    Coal mines %4d       Ore mines %4d         Communes %4d"
         ,Counted<Coalmine>::getInstanceCount(), Counted<Oremine>::getInstanceCount()
         ,Counted<Commune>::getInstanceCount());
    results << outf << std::endl;
    results << "" << std::endl;

    //close File
    results.close();

    free( outf );
}
Beispiel #6
0
/*
 * Show game statistics in dialog and write them to RESULTS_FILENAME.
 *
 * gamestats.xml has 11 lines
 * statistic_text1
 * [...]
 * statistic_text11
 * and 15 lines in a Table with 6 columns
 * statistic_text_1_1  statistic_number_1_1  statistic_text_1_2  statistic_number_1_2  statistic_text_1_3  statistic_number_1_3
 * [...]
//  * statistic_text_15_1 statistic_number_15_1 statistic_text_15_2 statistic_number_15_2 statistic_text_15_3 statistic_number_15_3
 */
void Dialog::gameStats(){
     saveGameStats();
     if( !desktop ) {
        std::cerr << "No desktop found.\n";
        return;
    }
    bool useExisting = false;
    myDialogComponent = desktop->findComponent("GameStats");
    if( myDialogComponent == 0){
        try {
            myDialogComponent = loadGUIFile( "gui/gamestats.xml" );
            assert( myDialogComponent != 0);
            registerDialog();
        } catch(std::exception& e) {
            std::cerr << "Couldn't display message 'gamestats': "
                << e.what() << "\n";
            return;
        }
    } else {
        useExisting = true;
    }

    // Fill in Fields.
    int line = 1;
    int maxlength = 567;
    char* outf = (char *) malloc ( maxlength );
    if (cheat_flag){
        setParagraphN( "statistic_text", line++, _("----- IN TEST MODE -------") );
    }
    snprintf (outf, maxlength,"%s %s", _("Game statistics from LinCity-NG Version"), PACKAGE_VERSION);
    setParagraphN( "statistic_text", line++, outf );
    if (strlen (given_scene) > 3){
        snprintf (outf, maxlength,"%s - %s", _("Initial loaded scene"), given_scene);
        setParagraphN( "statistic_text", line++, outf );
    }
    if (sustain_flag){
        snprintf (outf, maxlength, "%s", _("Economy is sustainable"));
        setParagraphN( "statistic_text", line++, outf );
    }
    snprintf (outf, maxlength, "%s %d %s %d %s.",
        _("Population"), population + people_pool, _("of which"),  people_pool, _("are not housed"));
    setParagraphN( "statistic_text", line++, outf );
    snprintf (outf, maxlength, "%s %d %s %d %s %d",
        _("Max population"), max_pop_ever,  _("Number evacuated"), total_evacuated, _("Total births"), total_births);
    setParagraphN( "statistic_text", line++, outf );
    snprintf (outf, maxlength, "%s %s %04d %s %8d %s %5.1f (%5.1f)",
        _("Date"),  current_month(total_time), current_year(total_time),
        _("Money"), total_money, _("Tech-level"),
        (float) tech_level * 100.0 / MAX_TECH_LEVEL,
        (float) highest_tech_level * 100.0 / MAX_TECH_LEVEL);
    setParagraphN( "statistic_text", line++, outf );
    snprintf (outf, maxlength, "%s %7d %s %8.3f",
        _("Deaths by starvation"), total_starve_deaths,
        _("History"), starve_deaths_history);
    setParagraphN( "statistic_text", line++, outf );
    snprintf (outf, maxlength, "%s %7d   %s %8.3f",
        _("Deaths from pollution"), total_pollution_deaths,
        _("History"), pollution_deaths_history);
    setParagraphN( "statistic_text", line++, outf );
    snprintf (outf, maxlength, "%s %7d   %s %8.3f",
        _("Years of unemployment"), total_unemployed_years,
        _("History"), unemployed_history);
    setParagraphN( "statistic_text", line++, outf );
    snprintf (outf, maxlength, "%s %2d  %s %2d",
        _("Rockets launched"), rockets_launched,
        _("Successful launches"), rockets_launched_success);
    setParagraphN( "statistic_text", line++, outf );

    while( line <= 11 ){ //clear remaining lines
        setParagraphN( "statistic_text", line++, "" );
    }
    free( outf );

    setTableRC("statistic", 1, 1, _("Residences"),
        Counted<Residence>::getInstanceCount());
    setTableRC("statistic", 1, 2, _("Markets"), Counted<Market>::getInstanceCount());
    setTableRC("statistic", 1, 3, _("Farms"), Counted<Organic_farm>::getInstanceCount());

    setTableRC("statistic", 2, 1, _("Water wells"), Counted<Waterwell>::getInstanceCount());
    setTableRC("statistic", 2, 2, _("Wind powers"), Counted<Windpower>::getInstanceCount());
    setTableRC("statistic", 2, 3, "", "");

    setTableRC("statistic", 3, 1, "", "");
    setTableRC("statistic", 3, 2, "", "");
    setTableRC("statistic", 3, 3, "", "");

    setTableRC("statistic", 4, 1, _("Monuments"), Counted<Monument>::getInstanceCount());
    setTableRC("statistic", 4, 2, _("Schools"),  Counted<School>::getInstanceCount());
    setTableRC("statistic", 4, 3, _("Universities"), Counted<University>::getInstanceCount());

    setTableRC("statistic", 5, 1, _("Fire stations"), Counted<FireStation>::getInstanceCount());
    setTableRC("statistic", 5, 2, _("Parks"), Counted<Parkland>::getInstanceCount());
    setTableRC("statistic", 5, 3, _("Sports fields"), Counted<Cricket>::getInstanceCount());

    setTableRC("statistic", 6, 1, _("Health centres"), Counted<HealthCentre>::getInstanceCount());
    setTableRC("statistic", 6, 2, _("Tips"), Counted<Tip>::getInstanceCount());
    setTableRC("statistic", 6, 3, _("Shanties"), Counted<Shanty>::getInstanceCount());

    setTableRC("statistic", 7, 1, "", "");
    setTableRC("statistic", 7, 2, "", "");
    setTableRC("statistic", 7, 3, "", "");

    setTableRC("statistic", 8, 1, _("Windmills"),  Counted<Windmill>::getInstanceCount());
    setTableRC("statistic", 8, 2, _("Coal powers"), Counted<Coal_power>::getInstanceCount());
    setTableRC("statistic", 8, 3, _("Solar powers"), Counted<SolarPower>::getInstanceCount());

    setTableRC("statistic", 9, 1, _("Substations"), Counted<Substation>::getInstanceCount());
    setTableRC("statistic", 9, 2, _("Power lines"), Counted<Powerline>::getInstanceCount());
    setTableRC("statistic", 9, 3, _("Ports"), Counted<Port>::getInstanceCount());

    setTableRC("statistic", 10, 1, _("Tracks"), Counted<Track>::getInstanceCount());
    setTableRC("statistic", 10, 2, _("Roads"), Counted<Road>::getInstanceCount());
    setTableRC("statistic", 10, 3, _("Rail"), Counted<Rail>::getInstanceCount());

    setTableRC("statistic", 11, 1, "", "");
    setTableRC("statistic", 11, 2, "", "");
    setTableRC("statistic", 11, 3, "", "");

    setTableRC("statistic", 12, 1, _("Potteries"), Counted<Pottery>::getInstanceCount());
    setTableRC("statistic", 12, 2, _("Blacksmiths"), Counted<Blacksmith>::getInstanceCount());
    setTableRC("statistic", 12, 3, _("Mills"), Counted<Mill>::getInstanceCount());

    setTableRC("statistic", 13, 1, _("Light inds"), Counted<IndustryLight>::getInstanceCount());
    setTableRC("statistic", 13, 2, _("Heavy inds"), Counted<IndustryHeavy>::getInstanceCount());
    setTableRC("statistic", 13, 3, _("Recyclers"), Counted<Recycle>::getInstanceCount());

    setTableRC("statistic", 14, 1, _("Coal mines"), Counted<Coalmine>::getInstanceCount());
    setTableRC("statistic", 14, 2, _("Ore mines"), Counted<Oremine>::getInstanceCount());
    setTableRC("statistic", 14, 3, _("Forests"), Counted<Commune>::getInstanceCount());

    setTableRC("statistic", 15, 1, "", "");
    setTableRC("statistic", 15, 2, "", "");
    setTableRC("statistic", 15, 3, "", "");

    if( !useExisting ){
        // connect signals
        Button* noButton = getButton( *myDialogComponent, "Okay" );
        noButton->clicked.connect( makeCallback( *this, &Dialog::closeDialogButtonClicked ) );
    }
}
Beispiel #7
0
int
compile_results (void)
{
    char *s;
    FILE *outf;
    int group_count[NUM_OF_GROUPS];

    if ((s = (char *) malloc (lc_save_dir_len + strlen (LC_SAVE_DIR)
			      + strlen (RESULTS_FILENAME) + 64)) == 0)
	malloc_failure ();

    sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, RESULTS_FILENAME);

    count_all_groups (group_count);
    if ((outf = fopen (s, "w")) == 0)
    {
	printf (_("Unable to open %s\n"), RESULTS_FILENAME);
	free (s);
	return (0);
    }
    if (cheat_flag)
	fprintf (outf, _("----- IN TEST MODE -------\n"));
    fprintf (outf, _("Game statistics from LinCity Version %s\n"), VERSION);
    if (strlen (given_scene) > 3)
	fprintf (outf, _("Initial loaded scene - %s\n"), given_scene);
    if (sustain_flag)
	fprintf (outf, _("Economy is sustainable\n"));
    fprintf (outf, _("Population  %d  of which  %d  are not housed.\n")
	     ,housed_population + people_pool, people_pool);
    fprintf (outf,
	     _("Max population %d  Number evacuated %d Total births %d\n")
	     ,max_pop_ever, total_evacuated, total_births);
    fprintf (outf,
	     _(" Date  %s %04d   Money %8d   Tech-level %5.1f (%5.1f)\n"),
	     current_month(total_time), current_year(total_time), total_money,
	     (float) tech_level * 100.0 / MAX_TECH_LEVEL,
	     (float) highest_tech_level * 100.0 / MAX_TECH_LEVEL);
    fprintf (outf,
	     _(" Deaths by starvation %7d   History %8.3f\n"),
	     total_starve_deaths, starve_deaths_history);
    fprintf (outf,
	     _("Deaths from pollution %7d   History %8.3f\n"),
	     total_pollution_deaths, pollution_deaths_history);
    fprintf (outf, _("Years of unemployment %7d   History %8.3f\n"),
	     total_unemployed_years, unemployed_history);
    fprintf (outf, _("Rockets launched %2d  Successful launches %2d\n"),
	     rockets_launched, rockets_launched_success);
    fprintf (outf, "\n");
    fprintf (outf, _("    Residences %4d         Markets %4d            Farms %4d\n"),
	     group_count[GROUP_RESIDENCE_LL] + 
	     group_count[GROUP_RESIDENCE_ML] + 
	     group_count[GROUP_RESIDENCE_HL] + 
	     group_count[GROUP_RESIDENCE_LH] + 
	     group_count[GROUP_RESIDENCE_MH] + 
	     group_count[GROUP_RESIDENCE_HH],
	     group_count[GROUP_MARKET],
	     group_count[GROUP_ORGANIC_FARM]);
    fprintf (outf, _("        Tracks %4d           Roads %4d             Rail %4d\n")
	     ,group_count[GROUP_TRACK], group_count[GROUP_ROAD]
	     ,group_count[GROUP_RAIL]);
    fprintf (outf, _("     Potteries %4d     Blacksmiths %4d            Mills %4d\n")
	     ,group_count[GROUP_POTTERY], group_count[GROUP_BLACKSMITH]
	     ,group_count[GROUP_MILL]);
    fprintf (outf, _("     Monuments %4d         Schools %4d     Universities %4d\n")
	     ,group_count[GROUP_MONUMENT], group_count[GROUP_SCHOOL]
	     ,group_count[GROUP_UNIVERSITY]);
    fprintf (outf, _(" Fire stations %4d           Parks %4d     Cricket gnds %4d\n")
	     ,group_count[GROUP_FIRESTATION], group_count[GROUP_PARKLAND]
	     ,group_count[GROUP_CRICKET]);
    fprintf (outf, _("    Coal mines %4d       Ore mines %4d         Communes %4d\n")
	     ,group_count[GROUP_COALMINE], group_count[GROUP_OREMINE]
	     ,group_count[GROUP_COMMUNE]);
    fprintf (outf, _("     Windmills %4d     Coal powers %4d     Solar powers %4d\n"),
	     group_count[GROUP_WINDMILL],
	     group_count[GROUP_COAL_POWER],
	     group_count[GROUP_SOLAR_POWER]);
    fprintf (outf, _("   Substations %4d     Power lines %4d            Ports %4d\n")
	     ,group_count[GROUP_SUBSTATION], group_count[GROUP_POWER_LINE]
	     ,group_count[GROUP_PORT]);
    fprintf (outf, _("    Light inds %4d      Heavy inds %4d        Recyclers %4d\n")
	     ,group_count[GROUP_INDUSTRY_L], group_count[GROUP_INDUSTRY_H]
	     ,group_count[GROUP_RECYCLE]);
    fprintf (outf, _("Health centres %4d            Tips %4d         Shanties %4d\n"),
	     group_count[GROUP_HEALTH], group_count[GROUP_TIP],
	     group_count[GROUP_SHANTY]);
    fclose (outf);
    free (s);
    return (1);
}
int main( int argc, char** argv ) {
	assert( argc > 2 );
	daw::history::pump_model_t pump_model( argv[1] );
	
	auto data = read_file( argv[2] );

	std::vector<uint8_t> v;
	for( size_t n = 0; n < data.size( ); n += 2 ) {
		while( std::isspace( data[n] ) ) {
			++n;
		}
		char tmp[3] = { data[n], data[n + 1], 0 };
		v.push_back( static_cast<uint8_t>(strtol( tmp, nullptr, 16 )) );
	}
	if( v.back( ) == 0 ) {
		v.pop_back( ); // null terminator
	}
	v.pop_back( ); // crc
	v.pop_back( ); // crc
	auto range = daw::range::make_range( v.data( ), v.data( ) + v.size( ) );

	std::vector<std::unique_ptr<daw::history::history_entry_obj>> entries;
	size_t pos = 0;

	auto good_item = []( auto const & i ) {
		if( !i ) {
			return false;
		}
		if( !i->timestamp( ) ) {
			return false;
		}
		return i->timestamp( )->date( ).year( ) == current_year( );
	};

	auto reasonible_year = []( auto const & i ) {
		if( i->timestamp( ) ) {
			auto item_year = i->timestamp( )->date( ).year( );
			auto this_year = current_year( );
			if( item_year < this_year - 2 ) {
				return false;
			}
			if( item_year > this_year + 2 ) {
				return false;
			}
		}
		return true;	// Not all items have timestamps
	};

	while( !range.at_end( ) ) {
		auto item = daw::history::create_history_entry( range, pump_model, pos );

		if( item ) {
			if( item->op_code( ) == 0x0 ) {
				continue;
			}
			std::cout << std::dec << std::dec << pos+1 << "/" << v.size( ) << ": ";
			if( !reasonible_year( item ) ) {
				std::cerr << "WARNING: The year does not look correct, outside of plus or minute 2 years from current system year\n";
			}
			std::cout << item->encode( );
			entries.push_back( std::move( item ) );
		} else {
			std::cout << std::dec << std::dec << pos+1 << "/" << v.size( ) << ": ";
			std::cout << "ERROR: data( ";
			auto err_start = pos;
			safe_advance( range, 1 );
			while( !range.at_end( ) && (range[0] == 0 || !(item = daw::history::create_history_entry( range, pump_model, pos )) || !good_item( item ) )) {
				safe_advance( range, 1 );
				++pos;
			}
			auto offset = item ? item->size( ) - 1 : 0;
			std::cout << (pos-(err_start+offset)) << " ) { ";
			std::cout << daw::range::make_range( v.data( ) + err_start, v.data( ) + pos - offset ).to_hex_string( ) << " }\n";
			if( !range.at_end( ) ) {
				std::cout << std::dec << std::dec << (pos-offset)+1 << "/" << v.size( ) << ": " << item->encode( );
				entries.push_back( std::move( item ) );
			}
		}
		std::cout << "\n\n";
	}
	return EXIT_SUCCESS;
}