diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/common/city.h freeciv/common/city.h --- FreecivCVS/common/city.h Fri Jul 30 22:32:41 1999 +++ freeciv/common/city.h Mon Aug 16 11:49:46 1999 @@ -84,6 +84,10 @@ #define CITY_MAP_SIZE 5 +#define city_map_in_radius(x, y) \ + (((x > 0) && (x < 4) && (y >= 0) && (y <= 4)) || \ + ((x >= 0) && (x <= 4) && (y > 0) && (y < 4))) + #define city_map_iterate(x, y) \ for (y=0;yterrain != T_OCEAN) + { + ixy = (x + (y * map.xsize)) * (game.nplayers + 1); + if (ptile->city) + { + ixyp = ixy + ptile->city->owner; + lamap[ixyp] = 1; + lamap[ixy + game.nplayers] = 1; + } + else if (ptile->worked) + { + ixyp = ixy + ptile->worked->owner; + lamap[ixyp] = 1; + lamap[ixy + game.nplayers] = 1; + } + else if (unit_list_size (&(ptile->units)) > 0) + { + ixyp = ixy + (unit_list_get (&(ptile->units), 0))->owner; + lamap[ixyp] = 1; + lamap[ixy + game.nplayers] = 1; + } + else + { + for (p = 0; p < game.nplayers; p++) + { + pplayer = &(game.players[p]); + if (map_get_known (x, y, pplayer)) + { + city_list_iterate (pplayer->cities, pcity) { + ixyp = ixy + p; + cx = map_to_city_x (pcity, x); + cy = map_to_city_y (pcity, y); + if (city_map_in_radius (cx, cy)) + { + lamap[ixyp] += 1; + lamap[ixy + game.nplayers] += 1; + } + } + city_list_iterate_end; + } + } + } + } + } + } + + /* return the lamap */ + + return (lamap); +} + +/************************************************************************** +Frees an allocated lamap. +**************************************************************************/ + +static void free_landarea_map(int *lamap) +{ + if (lamap) + { + free (lamap); + } +} + +/************************************************************************** +Computes and returns the given player's land area (per a lamap). +**************************************************************************/ + +static int get_player_landarea(int *lamap, struct player *pplayer) +{ + int area = 0; + int x, y, ip, is; + if (lamap && pplayer) + { + for (y = 0; y < map.ysize; y++) + { + for (x = 0; x < map.xsize; x++) + { + ip = pplayer->player_no + + ((x + (y * map.xsize)) * (game.nplayers + 1)); + is = game.nplayers + + ((x + (y * map.xsize)) * (game.nplayers + 1)); + if (lamap[ip] && (lamap[ip] == lamap[is])) + { + area++; + } + } + } + } + + return (area * 1000); +} + +/************************************************************************** +... +**************************************************************************/ int research_time(struct player *pplayer) { @@ -57,6 +182,10 @@ return timemod*pplayer->research.researchpoints*game.techlevel; } +/************************************************************************** +... +**************************************************************************/ + int total_player_citizens(struct player *pplayer) { return (pplayer->score.happy @@ -74,6 +203,13 @@ { int i; struct city *pcity; + static int *lamap = NULL; + + if (pplayer->player_no == 0) { + free_landarea_map(lamap); + lamap = build_landarea_map(); + } + pplayer->score.happy=0; /* done */ pplayer->score.content=0; /* done */ pplayer->score.unhappy=0; /* done */ @@ -83,7 +219,8 @@ pplayer->score.wonders=0; /* done */ pplayer->score.techs=0; /* done */ pplayer->score.techout=0; /* done */ - pplayer->score.landmass=0; + pplayer->score.landarea=0; + pplayer->score.population=0; pplayer->score.cities=0; /* done */ pplayer->score.units=0; /* done */ pplayer->score.pollution=0; /* done */ @@ -95,10 +232,10 @@ pplayer->score.happy+=pcity->ppl_happy[4]; pplayer->score.content+=pcity->ppl_content[4]; pplayer->score.unhappy+=pcity->ppl_unhappy[4]; - pplayer->score.taxmen+=pcity->ppl_taxman; pplayer->score.scientists+=pcity->ppl_scientist; pplayer->score.elvis+=pcity->ppl_elvis; + pplayer->score.population+=city_population(pcity); pplayer->score.cities++; pplayer->score.pollution+=pcity->pollution; pplayer->score.techout+=(1+pcity->science_total); @@ -110,6 +247,13 @@ pplayer->score.literacy+=(city_population(pcity)/2); } city_list_iterate_end; + + pplayer->score.landarea=get_player_landarea(lamap, pplayer); + if (pplayer->player_no == (game.nplayers - 1)) { + free_landarea_map(lamap); + lamap = NULL; + } + for (i=0;iscore.techs++; @@ -132,6 +276,7 @@ pplayer->score.spaceship += (int)(100 * pplayer->spaceship.habitation * pplayer->spaceship.success_rate); } + return (total_player_citizens(pplayer) +pplayer->score.happy +pplayer->score.techs*2 diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/common/player.h freeciv/common/player.h --- FreecivCVS/common/player.h Mon Aug 16 07:40:57 1999 +++ freeciv/common/player.h Mon Aug 16 07:52:03 1999 @@ -109,7 +109,8 @@ int wonders; int techs; int techout; - int landmass; + int landarea; + int population; int cities; int units; int pollution; diff -ru -X /home/jjm/cvs/no.freeciv FreecivCVS/server/plrhand.c freeciv/server/plrhand.c --- FreecivCVS/server/plrhand.c Sun Aug 15 10:07:59 1999 +++ freeciv/server/plrhand.c Mon Aug 16 15:35:37 1999 @@ -198,6 +198,30 @@ "Wonders of the World", buffer); } +static int rank_population(struct player *pplayer) +{ + int basis=pplayer->score.population; + int place=1; + int i; + for (i=0;ibasis) + place++; + } + return place; +} + +static int rank_landarea(struct player *pplayer) +{ + int basis=pplayer->score.landarea; + int place=1; + int i; + for (i=0;ibasis) + place++; + } + return place; +} + static int rank_calc_research(struct player *pplayer) { return (pplayer->score.techout*100)/(1+research_time(pplayer)); @@ -293,16 +317,51 @@ return place; } -static char *number_to_string(int x) +static char *value_units(char *val, char *uni) { - static char buf[4]; - buf[3]=0; - if (x<0 || x>99) x=0; - sprintf(buf, "%dth",x); - if (x==1) { buf[1]='s'; buf[2]='t';} - if (x==2) { buf[1]='n'; buf[2]='d';} - if (x==3) { buf[1]='r'; buf[2]='d';} - return buf; + static char buf[64] = "??"; + + if ((strlen (val) + strlen (uni) + 1) > sizeof (buf)) + { + return (buf); + } + + sprintf (buf, "%s%s", val, uni); + + return (buf); +} + +static char *number_to_ordinal_string(int num, int parens) +{ + static char buf[16]; + char *fmt; + + fmt = parens ? "(%d%s)" : "%d%s"; + + switch (num) + { + case 1: + sprintf (buf, fmt, num, "st"); + break; + case 2: + sprintf (buf, fmt, num, "nd"); + break; + case 3: + sprintf (buf, fmt, num, "rd"); + break; + default: + if (num > 0) + { + sprintf (buf, fmt, num, "th"); + } + else + { + strcpy (buf, parens ? "(??th)" : "??th"); + } + break; + } + + return (buf); } void do_dipl_cost(struct player *pplayer) @@ -322,32 +381,55 @@ void demographics_report(struct player *pplayer) { char civbuf[1024]; - char buffer[4096]; - char buf2[4096]; - buffer[0]=0; + char buffer[4096] = ""; + char *outptr = buffer; + char *fmt = "%-18s %-18s %6s\n"; sprintf(civbuf,"The %s of the %s", get_government_name(pplayer->government), get_race_name_plural(pplayer->race)); - sprintf(buf2, "%-20s:%d%% (%s)\n", "Research Speed", rank_calc_research(pplayer), number_to_string(rank_research(pplayer))); - strcat(buffer, buf2); - - sprintf(buf2, "%-20s:%d%% (%s)\n", "Literacy",rank_calc_literacy(pplayer), number_to_string(rank_literacy(pplayer))); - strcat(buffer, buf2); - sprintf(buf2, "%-20s:%d M. MFG (%s)\n", "Production", pplayer->score.mfg, number_to_string(rank_production(pplayer))); - strcat(buffer, buf2); - sprintf(buf2, "%-20s:%d M. BNP (%s)\n", "Economics", pplayer->score.bnp, number_to_string(rank_economics(pplayer))); - strcat(buffer, buf2); + outptr = strchr (outptr, '\0'); + sprintf(outptr, fmt, "Population", + int_to_text (pplayer->score.population), + number_to_ordinal_string(rank_population(pplayer), TRUE)); + + outptr = strchr (outptr, '\0'); + sprintf(outptr, fmt, "Land Area", + value_units (int_to_text (pplayer->score.landarea), " sq. mi."), + number_to_ordinal_string(rank_landarea(pplayer), TRUE)); + + outptr = strchr (outptr, '\0'); + sprintf(outptr, fmt, "Research Speed", + value_units (int_to_text (rank_calc_research(pplayer)), "%"), + number_to_ordinal_string(rank_research(pplayer), TRUE)); + + outptr = strchr (outptr, '\0'); + sprintf(outptr, fmt, "Literacy", + value_units (int_to_text (rank_calc_literacy(pplayer)), "%"), + number_to_ordinal_string(rank_literacy(pplayer), TRUE)); + + outptr = strchr (outptr, '\0'); + sprintf(outptr, fmt, "Production", + value_units (int_to_text (pplayer->score.mfg), " M tons"), + number_to_ordinal_string(rank_production(pplayer), TRUE)); + + outptr = strchr (outptr, '\0'); + sprintf(outptr, fmt, "Economics", + value_units (int_to_text (pplayer->score.bnp), " M goods"), + number_to_ordinal_string(rank_economics(pplayer), TRUE)); - sprintf(buf2, "%-20s:%d Months (%s)\n", "Military service", rank_calc_mil_service(pplayer), number_to_string(rank_mil_service(pplayer))); - strcat(buffer, buf2); + outptr = strchr (outptr, '\0'); + sprintf(outptr, fmt, "Military Service", + value_units (int_to_text (rank_calc_mil_service(pplayer)), " months"), + number_to_ordinal_string(rank_mil_service(pplayer), TRUE)); + + outptr = strchr (outptr, '\0'); + sprintf(outptr, fmt, "Pollution", + value_units (int_to_text (pplayer->score.pollution), " tons"), + number_to_ordinal_string(rank_pollution(pplayer), TRUE)); - sprintf(buf2, "%-20s:%d Tons (%s)\n", "Pollution", pplayer->score.pollution, number_to_string(rank_pollution(pplayer))); - strcat(buffer, buf2); - - page_player(pplayer, "Demographics Report:", - civbuf, buffer); + page_player (pplayer, "Demographics Report:", civbuf, buffer); } /* create a log file of the civilizations so you can see what was happening */