Index: client/packhand.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v retrieving revision 1.196 diff -u -b -r1.196 packhand.c --- client/packhand.c 2001/10/18 16:45:31 1.196 +++ client/packhand.c 2001/11/28 12:48:25 @@ -2086,6 +2086,7 @@ game.rgame.nuke_contamination = packet->nuke_contamination; game.rgame.granary_food_ini = packet->granary_food_ini; game.rgame.granary_food_inc = packet->granary_food_inc; + game.rgame.tech_cost_style = packet->tech_cost_style; } /************************************************************************** Index: client/gui-gtk/repodlgs.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/repodlgs.c,v retrieving revision 1.41 diff -u -b -r1.41 repodlgs.c --- client/gui-gtk/repodlgs.c 2001/10/09 18:57:00 1.41 +++ client/gui-gtk/repodlgs.c 2001/11/28 12:48:26 @@ -453,6 +453,10 @@ - game.num_tech_types); data=text; } + my_snprintf(text, sizeof(text), "%s (%d)", + data, + tech_cost(game.player_ptr,GPOINTER_TO_INT(g_list_nth_data(sorting_list, i)))); + data = text; item = gtk_menu_item_new_with_label(data); gtk_menu_append(GTK_MENU(popupmenu), item); Index: server/ruleset.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v retrieving revision 1.82 diff -u -b -r1.82 ruleset.c --- server/ruleset.c 2001/10/26 07:33:23 1.82 +++ server/ruleset.c 2001/11/28 12:48:28 @@ -2195,6 +2195,15 @@ game.rgame.granary_food_inc); game.rgame.granary_food_inc = 100; } + game.rgame.tech_cost_style = + secfile_lookup_int(&file, "civstyle.tech_cost_style"); + if (game.rgame.tech_cost_style<0 || + game.rgame.tech_cost_style>3) { + freelog(LOG_ERROR, "Bad value %i for tech_cost_style. Using 0.", + game.rgame.tech_cost_style); + game.rgame.tech_cost_style = 0; + } + /* * Load global initial techs @@ -2523,6 +2532,7 @@ misc_p.nuke_contamination = game.rgame.nuke_contamination; misc_p.granary_food_ini = game.rgame.granary_food_ini; misc_p.granary_food_inc = game.rgame.granary_food_inc; + misc_p.tech_cost_style = game.rgame.tech_cost_style; assert(sizeof(misc_p.global_init_techs) == sizeof(game.rgame.global_init_techs)); Index: common/game.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/game.c,v retrieving revision 1.113 diff -u -b -r1.113 game.c --- common/game.c 2001/11/23 17:27:07 1.113 +++ common/game.c 2001/11/28 12:48:28 @@ -420,7 +420,7 @@ int research_time(struct player *pplayer) { int timemod=(game.year>0) ? 2:1; - return timemod*pplayer->research.researchpoints*game.researchcost; + return timemod*tech_cost(pplayer, pplayer->research.researching); } /************************************************************************** Index: common/game.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/game.h,v retrieving revision 1.90 diff -u -b -r1.90 game.h --- common/game.h 2001/10/26 07:33:23 1.90 +++ common/game.h 2001/11/28 12:48:28 @@ -184,6 +184,7 @@ int nuke_contamination; int granary_food_ini; int granary_food_inc; + int tech_cost_style; /* * Advances given to all players at game start. Index: common/packets.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/packets.c,v retrieving revision 1.166 diff -u -b -r1.166 packets.c --- common/packets.c 2001/10/18 16:45:32 1.166 +++ common/packets.c 2001/11/28 12:48:29 @@ -3754,6 +3754,7 @@ cptr=put_uint8(cptr, packet->nuke_contamination); cptr=put_uint8(cptr, packet->granary_food_ini); cptr=put_uint8(cptr, packet->granary_food_inc); + cptr=put_uint8(cptr, packet->tech_cost_style); if (has_capability("init_techs", pc->capability)) { cptr = put_tech_list(cptr, packet->global_init_techs); } @@ -3784,6 +3785,7 @@ iget_uint8(&iter, &packet->nuke_contamination); iget_uint8(&iter, &packet->granary_food_ini); iget_uint8(&iter, &packet->granary_food_inc); + iget_uint8(&iter, &packet->tech_cost_style); if (has_capability("init_techs", pc->capability)) { iget_tech_list(&iter, packet->global_init_techs); } Index: common/packets.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/packets.h,v retrieving revision 1.98 diff -u -b -r1.98 packets.h --- common/packets.h 2001/10/18 16:45:33 1.98 +++ common/packets.h 2001/11/28 12:48:30 @@ -787,6 +787,7 @@ int nuke_contamination; int granary_food_ini; int granary_food_inc; + int tech_cost_style; int global_init_techs[MAX_NUM_TECH_LIST]; }; Index: common/tech.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v retrieving revision 1.29 diff -u -b -r1.29 tech.c --- common/tech.c 2001/09/06 21:23:08 1.29 +++ common/tech.c 2001/11/28 12:48:30 @@ -232,3 +232,64 @@ return ((research_time(pplayer) + res - 1) / res); } + +/************************************************************************** + Function to determine cost for technology. + Equation is determined from game.rgame.tech_cost_style + 0 == Old style. Every tech increases cost by game.researchcost. + 1 == Cost is game.researchcost*(1+numparenttechs). + 2 == Cost is (numplayers-civswithtech)/numplayers*costinstyle1 + 3 == Cost is (numplayers-civsincontactwithtech)/numplayers*costinstyle1 +**************************************************************************/ +int tech_cost(struct player *pplayer, int tech) +{ + if (game.rgame.tech_cost_style > 0) { + int advance_count[A_LAST]; + int i; + for (i = 0; i < A_LAST; ++i) + advance_count[i] = 0; + if (tech > game.num_tech_types) // future tech + return tech * game.researchcost; + + if (game.rgame.tech_cost_style == 1) + return tech_cost_recursive(pplayer, tech, advance_count); + else if (game.rgame.tech_cost_style == 2) { + int players = get_num_human_and_ai_players(); + float mul = (players - game.global_advances[tech]) / (float) players; + return mul * tech_cost_recursive(pplayer, tech, advance_count); + } else if (game.rgame.tech_cost_style == 3) { + int playerswithtech = 0; + int players = get_num_human_and_ai_players(); + float mul; + for (i = 0; i < players; ++i) { // Find out how many players have tech + if (!player_has_embassy(pplayer, &(game.players[i]))) + continue; + if (game.players[i].research.inventions[tech] == TECH_KNOWN) + ++playerswithtech; + } + mul = (players - playerswithtech) / (float) players; + return mul * tech_cost_recursive(pplayer, tech, advance_count); + } + } else { + return pplayer->research.researchpoints * game.researchcost; + } +} + +/************************************************************************** + Count cost for technology recursively. + Result is researchcost*(1+numparents) +**************************************************************************/ +int tech_cost_recursive(struct player *pplayer, int tech, int *advance_count) +{ + int price = 0; + if (tech == 0) + return 0; + if (advance_count[tech]) // No double counting of parents + + return 0; + + advance_count[tech] = 1; + price += tech_cost_recursive(pplayer, advances[tech].req[0], advance_count); + price += tech_cost_recursive(pplayer, advances[tech].req[1], advance_count); + return price += game.researchcost; +} Index: common/tech.h =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/tech.h,v retrieving revision 1.24 diff -u -b -r1.24 tech.h --- common/tech.h 2001/09/08 12:54:53 1.24 +++ common/tech.h 2001/11/28 12:48:30 @@ -84,6 +84,8 @@ enum tech_flag_id tech_flag_from_str(char *s); int find_tech_by_flag(int index, enum tech_flag_id flag); int tech_turns_to_advance(struct player *pplayer); +int tech_cost(struct player *pplayer, int tech); +int tech_cost_recursive(struct player *pplayer, int tech, int *advance_count); extern struct advance advances[];