diff -rNu -X diff_ignore freeciv-1.12.0/common/Makefile.am freeciv-scorelog/common/Makefile.am --- freeciv-1.12.0/common/Makefile.am Thu May 31 11:02:55 2001 +++ freeciv-scorelog/common/Makefile.am Tue Aug 14 17:00:11 2001 @@ -64,6 +64,8 @@ registry.h \ sbuffer.c \ sbuffer.h \ + scorelog.c \ + scorelog.h \ shared.c \ shared.h \ spaceship.c \ diff -rNu -X diff_ignore freeciv-1.12.0/common/game.c freeciv-scorelog/common/game.c --- freeciv-1.12.0/common/game.c Tue Jun 26 14:10:42 2001 +++ freeciv-scorelog/common/game.c Tue Aug 14 17:00:11 2001 @@ -28,6 +28,7 @@ #include "mem.h" #include "nation.h" #include "player.h" +#include "scorelog.h" #include "shared.h" #include "spaceship.h" #include "support.h" @@ -745,6 +746,8 @@ game.default_government = G_MAGIC; /* flag */ game.government_when_anarchy = G_MAGIC; /* flag */ game.ai_goal_government = G_MAGIC; /* flag */ + + game.civscore_log = create_scorelog(); sz_strlcpy(game.demography, GAME_DEFAULT_DEMOGRAPHY); sz_strlcpy(game.allow_connect, GAME_DEFAULT_ALLOW_CONNECT); diff -rNu -X diff_ignore freeciv-1.12.0/common/game.h freeciv-scorelog/common/game.h --- freeciv-1.12.0/common/game.h Mon Jul 2 10:28:03 2001 +++ freeciv-scorelog/common/game.h Tue Aug 14 17:00:11 2001 @@ -42,6 +42,7 @@ struct unit; struct city; +struct civscore; #define OVERFLIGHT_NOTHING 1 #define OVERFLIGHT_FRIGHTEN 2 @@ -135,6 +136,8 @@ int playable_nation_count; int styles_count; + struct civscore *civscore_log; + struct { char techs[MAX_LEN_NAME]; char units[MAX_LEN_NAME]; @@ -335,7 +338,7 @@ #define GAME_DEFAULT_SCORELOG 0 #define GAME_MIN_SCORELOG 0 -#define GAME_MAX_SCORELOG 1 +#define GAME_MAX_SCORELOG 3 #define GAME_DEFAULT_SPACERACE 1 #define GAME_MIN_SPACERACE 0 diff -rNu -X diff_ignore freeciv-1.12.0/common/scorelog.c freeciv-scorelog/common/scorelog.c --- freeciv-1.12.0/common/scorelog.c Wed Dec 31 19:00:00 1969 +++ freeciv-scorelog/common/scorelog.c Tue Aug 14 17:00:11 2001 @@ -0,0 +1,309 @@ +/********************************************************************** + Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +***********************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include "city.h" +#include "connection.h" +#include "fcintl.h" +#include "government.h" +#include "idex.h" +#include "log.h" +#include "map.h" +#include "mem.h" +#include "nation.h" +#include "player.h" +#include "shared.h" +#include "spaceship.h" +#include "support.h" +#include "tech.h" +#include "unit.h" + +#include "game.h" +#include "scorelog.h" + +char *tags[] = { + "pop", + "bnp", + "mfg", + "cities", + "techs", + "munits", + "settlers", /* "original" tags end here */ + + "wonders", + "techout", + "landarea", + "settledarea", + "pollution", + "literacy", + "spaceship", /* new 1.8.2 tags end here */ + + "gold", + "taxrate", + "scirate", + "luxrate", + + "riots", + "happypop", + "contentpop", + "unhappypop", + + "taxmen", + "scientists", + "elvis", + "gov", + "corruption" /* new 1.11.5 tags end here*/ +}; +int num_tags = sizeof(tags) / sizeof(tags[0]); + +static void resize_log(struct civscore *c_log) { + int i = 0, j = 0; + int num_players = 0; + int new_size = 0; + + if(!c_log) + return; + + /* We grow the array exponentially */ + if((c_log->data_cap < MIN_SCORELOG_ENTRIES) || !c_log->data) { + new_size = MIN_SCORELOG_ENTRIES; + } + else { + new_size = c_log->num_turns * 2; + } + + c_log->data = (struct year_log *)fc_realloc(c_log->data, + new_size * sizeof(struct year_log)); + + /* How many non-barbarians do we have? */ + for(i = 0, num_players = 0;i < game.nplayers;i++) { + if(is_barbarian(&(game.players[i]))) + continue; + num_players++; + } + + /* Allocate memory for the two-dimensional array for each year */ + for(i = c_log->num_turns;i < new_size;i++) { + struct year_log *tmp_log = &(c_log->data[i]); + + /* Properties are on the 'X' axis, players on the 'Y'. + * And, yes, sizeof(int **) == sizeof(int *), but just to help + * keep track of things ... */ + tmp_log->values = (int **)fc_malloc(num_tags * sizeof(int **)); + for(j = 0;j < num_tags;j++) { + tmp_log->values[j] = (int *)fc_malloc(num_players * sizeof(int *)); + } + } + + c_log->data_cap = new_size; + + return; +} + +/* Initialization routine for the scorelog */ +struct civscore* create_scorelog(void) { + struct civscore *new_log; + + new_log = fc_malloc(sizeof(struct civscore)); + new_log->data = NULL; + new_log->num_turns = 0; + new_log->data_cap = 0; + + return new_log; +} + +/* Cleans out all the sub-arrays within the data structure */ +void destroy_scorelog(struct civscore *c_log) { + int i = 0, j = 0; + struct year_log *tmp_log = NULL; + + if(!c_log || !c_log->data) + return; + + /* Go turn by turn, cleaning out the sub-array for each tag for each turn */ + for(i = 0;i < c_log->data_cap;i++) { + tmp_log = &(c_log->data[i]); + if(!tmp_log->values) + continue; + + for(j = 0;j < num_tags;j++) { + if(tmp_log->values[j]) { + free(tmp_log->values[j]); + tmp_log->values[j] = NULL; + } + } + + free(tmp_log->values); + tmp_log->values = NULL; + } + + /* Now delete the entire scorelog array */ + free(c_log->data); + c_log->data = NULL; + c_log->num_turns = 0; + c_log->data_cap = 0; +} + +/* Put all the info from this turn into a new year entry. */ +void scorelog_add_curr_year(struct civscore *c_log) { + int i = 0, j = 0; + int val = 0; + struct player *pptr = NULL; + struct year_log *yptr = NULL; + + if(!c_log) + return; + + /* We avoid having an extensive initialization function by wrapping + * it into the resizing function. */ + if(!c_log->data_cap || (c_log->num_turns == c_log->data_cap)) + resize_log(c_log); + + /* For quick access while iterating through the data */ + yptr = &(c_log->data[c_log->num_turns]); + yptr->year = game.year; + + /* Most of this was lifted from report.c */ + for(i = 0;i < num_tags;i++) { + for(j = 0;j < game.nplayers;j++) { + if(is_barbarian(&(game.players[j]))) + continue; + + pptr = &(game.players[j]); + + switch(i) { + case 0: + val = total_player_citizens(pptr); + break; + case 1: + val = pptr->score.bnp; + break; + case 2: + val = pptr->score.mfg; + break; + case 3: + val = pptr->score.cities; + break; + case 4: + val = pptr->score.techs; + break; + case 5: + val = 0; + unit_list_iterate(pptr->units, punit) + if(is_military_unit(punit)) + val++; + unit_list_iterate_end; + break; + case 6: + val = 0; + unit_list_iterate(pptr->units, punit) + if(unit_flag(punit->type, F_CITIES)) + val++; + unit_list_iterate_end; + break; + case 7: + val = pptr->score.wonders; + break; + case 8: + val = pptr->score.techout; + break; + case 9: + val = pptr->score.landarea; + break; + case 10: + val = pptr->score.settledarea; + break; + case 11: + val = pptr->score.pollution; + break; + case 12: + val = pptr->score.literacy; + break; + case 13: + val = pptr->score.spaceship; + break; + case 14: /* gold */ + val = pptr->economic.gold; + break; + case 15: /* taxrate */ + val = pptr->economic.tax; + break; + case 16: /* scirate */ + val = pptr->economic.science; + break; + case 17: /* luxrate */ + val = pptr->economic.luxury; + break; + case 18: /* riots */ + val = 0; + city_list_iterate (pptr->cities, pcity) + if(pcity->anarchy > 0) + val++; + city_list_iterate_end; + break; + case 19: /* happypop */ + val = pptr->score.happy; + break; + case 20: /* contentpop */ + val = pptr->score.content; + break; + case 21: /* unhappypop */ + val = pptr->score.unhappy; + break; + case 22: /* taxmen */ + val = pptr->score.taxmen; + break; + case 23: /* scientists */ + val = pptr->score.scientists; + break; + case 24: /* elvis */ + val = pptr->score.elvis; + break; + case 25: /* gov */ + val = pptr->government; + break; + case 26: /* corruption */ + val = 0; + city_list_iterate(pptr->cities, pcity) + val+=pcity->corruption; + city_list_iterate_end; + break; + default: + val = 0; /* -Wall demands we init this somewhere! */ + } + + /* Store our data in the matrix */ + yptr->values[i][j] = val; + } + } + + c_log->num_turns++; +} + +void scorelog_copy_year(struct civscore *c_log, struct year_log *one_year) { + if(!c_log || !one_year) + return; + + if(!c_log->data_cap || (c_log->num_turns == c_log->data_cap)) + resize_log(c_log); + + memcpy(&(c_log->data[c_log->num_turns]), one_year, sizeof(struct year_log)); + c_log->num_turns++; +} diff -rNu -X diff_ignore freeciv-1.12.0/common/scorelog.h freeciv-scorelog/common/scorelog.h --- freeciv-1.12.0/common/scorelog.h Wed Dec 31 19:00:00 1969 +++ freeciv-scorelog/common/scorelog.h Tue Aug 14 17:00:11 2001 @@ -0,0 +1,41 @@ +/********************************************************************** + Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +***********************************************************************/ + +#ifndef FC__SCORELOG_H +#define FC__SCORELOG_H + +#include "shared.h" + +#define MIN_SCORELOG_ENTRIES 8 + +struct year_log { + int year; + int **values; +}; + +struct civscore { + struct year_log *data; + int num_turns; + int data_cap; +}; + +/* These are the tags previously in report.c */ +extern char *tags[]; +extern int num_tags; + +extern struct civscore* create_scorelog(void); +extern void destroy_scorelog(struct civscore *c_log); +extern void scorelog_add_curr_year(struct civscore *c_log); +extern void scorelog_copy_year(struct civscore *c_log, struct year_log *one_year); + +#endif /* FC__SCORELOG_H */ diff -rNu -X diff_ignore freeciv-1.12.0/server/report.c freeciv-scorelog/server/report.c --- freeciv-1.12.0/server/report.c Mon Jul 2 08:44:50 2001 +++ freeciv-scorelog/server/report.c Tue Aug 14 17:00:11 2001 @@ -29,6 +29,7 @@ #include "version.h" #include "report.h" +#include "scorelog.h" enum historian_type { HISTORIAN_RICHEST=0, @@ -966,45 +967,6 @@ static FILE *fp = NULL; static int disabled = 0; - /* add new tags only at end of this list; - maintaining the order of old tags is critical */ - static char *tags[] = - { - "pop", - "bnp", - "mfg", - "cities", - "techs", - "munits", - "settlers", /* "original" tags end here */ - - "wonders", - "techout", - "landarea", - "settledarea", - "pollution", - "literacy", - "spaceship", /* new 1.8.2 tags end here */ - - "gold", - "taxrate", - "scirate", - "luxrate", - - "riots", - "happypop", - "contentpop", - "unhappypop", - - "taxmen", - "scientists", - "elvis", - "gov", - "corruption", /* new 1.11.5 tags end here*/ - - NULL /* end of list */ - }; - if (disabled) { return; @@ -1059,7 +1021,7 @@ } else { - if (!(tags[foms])) + if (foms < num_tags) { freelog (LOG_ERROR, "Too many entries in scorelog header!"); @@ -1187,7 +1149,7 @@ goto log_civ_score_disable; } fprintf (fp, magic, VERSION_STRING); - for (i = 0; tags[i]; i++) + for (i = 0; i < num_tags; i++) { fprintf (fp, "%d %s\n", i, tags[i]); } @@ -1216,7 +1178,7 @@ } } - for (i = 0; tags[i]; i++) + for (i = 0; i < num_tags; i++) { for (n = 0; n < game.nplayers; n++) { @@ -1359,8 +1321,10 @@ for (i=0;i