? diff Index: client/gui-gtk/citydlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v retrieving revision 1.91 diff -u -r1.91 citydlg.c --- client/gui-gtk/citydlg.c 2001/08/25 10:34:01 1.91 +++ client/gui-gtk/citydlg.c 2001/09/12 10:21:12 @@ -1843,7 +1843,8 @@ char *now; my_snprintf(buf, sizeof(buf), _("%s - %s citizens"), - pdialog->pcity->name, int_to_text(city_population(pdialog->pcity))); + pdialog->pcity->name, + int_to_text(city_population(pdialog->pcity), 3)); now=GTK_FRAME(pdialog->cityname_label)->label; if (strcmp(now, buf)) { Index: client/gui-gtk/gui_main.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.c,v retrieving revision 1.91 diff -u -r1.91 gui_main.c --- client/gui-gtk/gui_main.c 2001/08/29 10:32:23 1.91 +++ client/gui-gtk/gui_main.c 2001/09/12 10:21:13 @@ -908,7 +908,7 @@ my_snprintf(buf, sizeof(buf), _("%s People\nYear: %s Turn: %d\nGold: %d\nNet Income: %d\n" "Tax:%d Lux:%d Sci:%d\nResearching %s: %d/%d"), - int_to_text(civ_population(game.player_ptr)), + int_to_text(civ_population(game.player_ptr), 3), textyear(game.year),game.turn, game.player_ptr->economic.gold, turn_gold_difference, Index: client/gui-gtk/mapview.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v retrieving revision 1.97 diff -u -r1.97 mapview.c --- client/gui-gtk/mapview.c 2001/09/12 09:12:07 1.97 +++ client/gui-gtk/mapview.c 2001/09/12 10:21:14 @@ -492,7 +492,7 @@ my_snprintf(buffer, sizeof(buffer), _("Population: %s\nYear: %s\n" "Gold %d\nTax: %d Lux: %d Sci: %d"), - int_to_text(civ_population(game.player_ptr)), + int_to_text(civ_population(game.player_ptr), 3), textyear(game.year), game.player_ptr->economic.gold, game.player_ptr->economic.tax, game.player_ptr->economic.luxury, Index: client/gui-mui/citydlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v retrieving revision 1.36 diff -u -r1.36 citydlg.c --- client/gui-mui/citydlg.c 2001/08/22 21:30:16 1.36 +++ client/gui-mui/citydlg.c 2001/09/12 10:21:15 @@ -1729,10 +1729,13 @@ if (pdialog->name_transparentstring) { set(pdialog->name_transparentstring,MUIA_TransparentString_Contents, pdialog->pcity->name); - settextf(pdialog->title_text, _("%s citizens"), int_to_text(city_population(pdialog->pcity))); + settextf(pdialog->title_text, _("%s citizens"), + int_to_text(city_population(pdialog->pcity), 0)); } else { - settextf(pdialog->title_text, _("%s - %s citizens"), pdialog->pcity->name, int_to_text(city_population(pdialog->pcity))); + settextf(pdialog->title_text, _("%s - %s citizens"), + pdialog->pcity->name, + int_to_text(city_population(pdialog->pcity), 0)); } } Index: client/gui-mui/mapview.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/mapview.c,v retrieving revision 1.31 diff -u -r1.31 mapview.c --- client/gui-mui/mapview.c 2001/09/12 09:12:08 1.31 +++ client/gui-mui/mapview.c 2001/09/12 10:21:16 @@ -216,7 +216,8 @@ { int d; - settextf(main_people_text, _("Population: %s"), int_to_text(civ_population(game.player_ptr))); + settextf(main_people_text, _("Population: %s"), + int_to_text(civ_population(game.player_ptr), 0)); settextf(main_year_text, _("Year: %s"), textyear(game.year)); settextf(main_gold_text, _("Gold: %d"), game.player_ptr->economic.gold); settextf(main_tax_text, _("Tax:%d Lux:%d Sci:%d"), Index: client/gui-win32/mapview.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/mapview.c,v retrieving revision 1.3 diff -u -r1.3 mapview.c --- client/gui-win32/mapview.c 2001/09/12 09:12:09 1.3 +++ client/gui-win32/mapview.c 2001/09/12 10:21:17 @@ -487,7 +487,7 @@ HDC hdc; my_snprintf(buffer, sizeof(buffer), _("Population: %s\nYear: %s\nGold %d\nTax: %d Lux: %d Sci: %d"), - int_to_text( civ_population( game.player_ptr ) ), + int_to_text(civ_population(game.player_ptr), 0), textyear( game.year ), game.player_ptr->economic.gold, game.player_ptr->economic.tax, Index: client/gui-xaw/citydlg.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v retrieving revision 1.54 diff -u -r1.54 citydlg.c --- client/gui-xaw/citydlg.c 2001/08/22 07:53:26 1.54 +++ client/gui-xaw/citydlg.c 2001/09/12 10:21:19 @@ -1884,7 +1884,8 @@ String now; my_snprintf(buf, sizeof(buf), _("%s - %s citizens"), - pdialog->pcity->name, int_to_text(city_population(pdialog->pcity))); + pdialog->pcity->name, + int_to_text(city_population(pdialog->pcity), 0)); XtVaGetValues(pdialog->cityname_label, XtNlabel, &now, NULL); if(strcmp(now, buf)) { Index: client/gui-xaw/gui_main.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/gui_main.c,v retrieving revision 1.58 diff -u -r1.58 gui_main.c --- client/gui-xaw/gui_main.c 2001/08/29 10:32:25 1.58 +++ client/gui-xaw/gui_main.c 2001/09/12 10:21:19 @@ -691,7 +691,7 @@ "Net Income: %d\n" "Tax:%d Lux:%d Sci:%d\n" "Researching %s: %d/%d"), - int_to_text(civ_population(game.player_ptr)), + int_to_text(civ_population(game.player_ptr), 0), textyear(game.year), game.turn, game.player_ptr->economic.gold, turn_gold_difference, Index: client/gui-xaw/mapview.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v retrieving revision 1.78 diff -u -r1.78 mapview.c --- client/gui-xaw/mapview.c 2001/09/12 09:12:11 1.78 +++ client/gui-xaw/mapview.c 2001/09/12 10:21:20 @@ -264,7 +264,7 @@ "Year: %s\n" "Gold: %d\n" "Tax:%d Lux:%d Sci:%d"), - int_to_text(civ_population(game.player_ptr)), + int_to_text(civ_population(game.player_ptr), 0), textyear(game.year), game.player_ptr->economic.gold, game.player_ptr->economic.tax, Index: common/city.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/city.c,v retrieving revision 1.119 diff -u -r1.119 city.c --- common/city.c 2001/09/12 09:12:11 1.119 +++ common/city.c 2001/09/12 10:21:22 @@ -414,18 +414,12 @@ /************************************************************************** -... + Returns how many thousand citizen live in this city. **************************************************************************/ int city_population(struct city *pcity) { -/* - int i; - int res=0; - for (i=1;i<=pcity->size;i++) res+=i; - return res*10000; -*/ /* Sum_{i=1}^{n} i == n*(n+1)/2 */ - return pcity->size * (pcity->size+1) * 5000; + return pcity->size * (pcity->size + 1) * 5; } /************************************************************************** Index: common/game.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/game.c,v retrieving revision 1.106 diff -u -r1.106 game.c --- common/game.c 2001/09/02 13:37:57 1.106 +++ common/game.c 2001/09/12 10:21:22 @@ -562,7 +562,7 @@ } /************************************************************************** -Count the # of citizen in a civilisation. +Count the # of thousand citizen in a civilisation. **************************************************************************/ int civ_population(struct player *pplayer) { Index: common/player.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/player.h,v retrieving revision 1.63 diff -u -r1.63 player.h --- common/player.h 2001/09/02 10:24:28 1.63 +++ common/player.h 2001/09/12 10:21:22 @@ -75,7 +75,7 @@ int techout; int landarea; int settledarea; - int population; + int population; /* in thounsand of citizen */ int cities; int units; int pollution; Index: common/shared.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/shared.c,v retrieving revision 1.65 diff -u -r1.65 shared.c --- common/shared.c 2001/09/06 21:23:07 1.65 +++ common/shared.c 2001/09/12 10:21:23 @@ -164,10 +164,11 @@ /*************************************************************** Returns a statically allocated string containing a nicely-formatted - version of the given number according to the user's locale. - (Only works for numbers >= zero.) + version of the given number according to the user's locale. (Only + works for numbers >= zero.) The actually number used for the + formatting is: nr*10^decade_exponent ***************************************************************/ -char *int_to_text(int nr) +char *int_to_text(int nr, int decade_exponent) { static char buf[64]; /* Note that we'll be filling this in right to left. */ char *grp = grouping; @@ -175,6 +176,7 @@ int cnt; assert(nr >= 0); + assert(decade_exponent >= 0); if (nr == 0) { return "0"; @@ -184,11 +186,20 @@ *(--ptr) = '\0'; cnt = 0; - while (nr != 0) { - int dig = nr % 10; + while (nr != 0 && decade_exponent >= 0) { + int dig; + assert(ptr > buf); + + if (decade_exponent > 0) { + dig = 0; + decade_exponent--; + } else { + dig = nr % 10; + nr /= 10; + } + *(--ptr) = '0' + dig; - nr /= 10; cnt++; if (nr != 0 && cnt == *grp) { Index: common/shared.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/shared.h,v retrieving revision 1.86 diff -u -r1.86 shared.h --- common/shared.h 2001/09/06 21:23:08 1.86 +++ common/shared.h 2001/09/12 10:21:23 @@ -63,7 +63,7 @@ char * get_option(const char *option_name,char **argv,int *i,int argc); int is_option(const char *option_name,char *option); -char *int_to_text(int nr); +char *int_to_text(int nr, int decade_exponent); char *get_sane_name(char *name); char *textyear(int year); int compare_strings(const void *first, const void *second); Index: server/report.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/report.c,v retrieving revision 1.11 diff -u -r1.11 report.c --- server/report.c 2001/09/06 21:23:08 1.11 +++ server/report.c 2001/09/12 10:21:24 @@ -653,8 +653,8 @@ if (selcols & DEM_COL_QUANTITY) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_quan, - int_to_text (pplayer->score.population)); + my_snprintf(outptr, nleft, fmt_quan, + int_to_text(pplayer->score.population, 0)); } if (selcols & DEM_COL_RANK) { @@ -666,18 +666,18 @@ player_has_embassy(pplayer, (best_player = best_population())) ) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_best, - get_nation_name_plural(best_player->nation), - int_to_text(best_player->score.population) ); + my_snprintf(outptr, nleft, fmt_best, + get_nation_name_plural(best_player->nation), + int_to_text(best_player->score.population, 0)); } break; case DEM_KEY_ROW_LAND_AREA: if (selcols & DEM_COL_QUANTITY) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_quan, - value_units (int_to_text (pplayer->score.landarea), - _(" sq. mi."))); + my_snprintf(outptr, nleft, fmt_quan, + value_units(int_to_text(pplayer->score.landarea, 0), + _(" sq. mi."))); } if (selcols & DEM_COL_RANK) { @@ -689,19 +689,21 @@ player_has_embassy(pplayer, (best_player = best_landarea())) ) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_best, - get_nation_name_plural(best_player->nation), - value_units (int_to_text(best_player->score.landarea), - _(" sq. mi."))); + my_snprintf(outptr, nleft, fmt_best, + get_nation_name_plural(best_player->nation), + value_units(int_to_text + (best_player->score.landarea, 0), + _(" sq. mi."))); } break; case DEM_KEY_ROW_SETTLED_AREA: if (selcols & DEM_COL_QUANTITY) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_quan, - value_units (int_to_text (pplayer->score.settledarea), - _(" sq. mi."))); + my_snprintf(outptr, nleft, fmt_quan, + value_units(int_to_text + (pplayer->score.settledarea, 0), + _(" sq. mi."))); } if (selcols & DEM_COL_RANK) { @@ -714,19 +716,20 @@ player_has_embassy(pplayer, (best_player = best_settledarea())) ) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_best, - get_nation_name_plural(best_player->nation), - value_units (int_to_text(best_player->score.settledarea), - _(" sq. mi."))); + my_snprintf(outptr, nleft, fmt_best, + get_nation_name_plural(best_player->nation), + value_units(int_to_text + (best_player->score.settledarea, 0), + _(" sq. mi."))); } break; case DEM_KEY_ROW_RESEARCH_SPEED: if (selcols & DEM_COL_QUANTITY) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_quan, - value_units (int_to_text (rank_calc_research(pplayer)), - "%")); + my_snprintf(outptr, nleft, fmt_quan, + value_units(int_to_text + (rank_calc_research(pplayer), 0), "%")); } if (selcols & DEM_COL_RANK) { @@ -738,19 +741,20 @@ player_has_embassy(pplayer, (best_player = best_research())) ) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_best, - get_nation_name_plural(best_player->nation), - value_units(int_to_text(rank_calc_research(best_player)), - "%")); + my_snprintf(outptr, nleft, fmt_best, + get_nation_name_plural(best_player->nation), + value_units(int_to_text + (rank_calc_research(best_player), 0), + "%")); } break; case DEM_KEY_ROW_LITERACY: if (selcols & DEM_COL_QUANTITY) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_quan, - value_units (int_to_text (rank_calc_literacy(pplayer)), - "%")); + my_snprintf(outptr, nleft, fmt_quan, + value_units(int_to_text + (rank_calc_literacy(pplayer), 0), "%")); } if (selcols & DEM_COL_RANK) { @@ -762,19 +766,21 @@ player_has_embassy(pplayer, (best_player = best_literacy())) ) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_best, - get_nation_name_plural(best_player->nation), - value_units(int_to_text(rank_calc_literacy(best_player)), - "%")); + my_snprintf(outptr, nleft, fmt_best, + get_nation_name_plural(best_player->nation), + value_units(int_to_text + (rank_calc_literacy(best_player), 0), + "%")); } break; case DEM_KEY_ROW_PRODUCTION: if (selcols & DEM_COL_QUANTITY) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_quan, - value_units (int_to_text (MAX(0,pplayer->score.mfg)), - _(" M tons"))); + my_snprintf(outptr, nleft, fmt_quan, + value_units(int_to_text + (MAX(0, pplayer->score.mfg), 0), + _(" M tons"))); } if (selcols & DEM_COL_RANK) { @@ -786,19 +792,20 @@ player_has_embassy(pplayer, (best_player = best_production())) ) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_best, - get_nation_name_plural(best_player->nation), - value_units(int_to_text(MAX(0,best_player->score.mfg)), - _(" M tons"))); + my_snprintf(outptr, nleft, fmt_best, + get_nation_name_plural(best_player->nation), + value_units(int_to_text + (MAX(0, best_player->score.mfg), 0), + _(" M tons"))); } break; case DEM_KEY_ROW_ECONOMICS: if (selcols & DEM_COL_QUANTITY) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_quan, - value_units (int_to_text (pplayer->score.bnp), - _(" M goods"))); + my_snprintf(outptr, nleft, fmt_quan, + value_units(int_to_text(pplayer->score.bnp, 0), + _(" M goods"))); } if (selcols & DEM_COL_RANK) { @@ -810,19 +817,20 @@ player_has_embassy(pplayer, (best_player = best_economics())) ) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_best, - get_nation_name_plural(best_player->nation), - value_units(int_to_text(best_player->score.bnp), - _(" M goods"))); + my_snprintf(outptr, nleft, fmt_best, + get_nation_name_plural(best_player->nation), + value_units(int_to_text(best_player->score.bnp, 0), + _(" M goods"))); } break; case DEM_KEY_ROW_MILITARY_SERVICE: if (selcols & DEM_COL_QUANTITY) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_quan, - value_units (int_to_text (rank_calc_mil_service(pplayer)), - _(" months"))); + my_snprintf(outptr, nleft, fmt_quan, + value_units(int_to_text + (rank_calc_mil_service(pplayer), 0), + _(" months"))); } if (selcols & DEM_COL_RANK) { @@ -835,19 +843,20 @@ player_has_embassy(pplayer, (best_player = best_mil_service())) ) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_best, - get_nation_name_plural(best_player->nation), - value_units(int_to_text(rank_calc_mil_service(best_player)), - _(" months"))); + my_snprintf(outptr, nleft, fmt_best, + get_nation_name_plural(best_player->nation), + value_units(int_to_text + (rank_calc_mil_service(best_player), 0), + _(" months"))); } break; case DEM_KEY_ROW_POLLUTION: if (selcols & DEM_COL_QUANTITY) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_quan, - value_units (int_to_text (pplayer->score.pollution), - _(" tons"))); + my_snprintf(outptr, nleft, fmt_quan, + value_units(int_to_text(pplayer->score.pollution, 0), + _(" tons"))); } if (selcols & DEM_COL_RANK) { @@ -859,10 +868,11 @@ player_has_embassy(pplayer, (best_player = best_pollution())) ) { outptr = end_of_strn (outptr, &nleft); - my_snprintf (outptr, nleft, fmt_best, - get_nation_name_plural(best_player->nation), - value_units (int_to_text(best_player->score.pollution), - _(" tons"))); + my_snprintf(outptr, nleft, fmt_best, + get_nation_name_plural(best_player->nation), + value_units(int_to_text + (best_player->score.pollution, 0), + _(" tons"))); } break; }