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();
}
示例#2
0
int month_left() 
{
  return 12 - current_month();
  /*
   * Alt. solution:
    
   int this_month =  current_month(); 
   return 12 - this_month;
  */
}
/* 
 * 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 ) );
    }
}
示例#4
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 ) );
    }
}
示例#5
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);
}