[Freeciv-Dev] Re: civserver segfault with new research system (PR#1221)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
is there an enum out there somewhere that gives a bit more info on 0,1,2
on tech_leakage?
-mike
On Mon, Jan 14, 2002 at 10:24:04AM +0100, Raimar Falke wrote:
> On Sun, Jan 13, 2002 at 03:34:55AM -0800, rf13@xxxxxxxxxxxxxxxxxxxxxx wrote:
>
> And here is the patch. Please test since I added another assert since
> we have to be sure that no barbarian contributes to
> game.global_advances.
>
> Raimar
>
> --
> email: rf13@xxxxxxxxxxxxxxxxx
> "The two rules for success in life are:
> 1) Never tell them everything you know."
> ? rc
> ? diff
> ? whole_diff
> ? msgfmt1.diff
> ? tech_info1.diff
> ? no_tech_loss1.diff
> ? local_warmap131201.diff
> ? queue
> ? unit_move_turns1.diff
> Index: common/tech.c
> ===================================================================
> RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
> retrieving revision 1.32
> diff -u -r1.32 tech.c
> --- common/tech.c 2002/01/11 13:50:49 1.32
> +++ common/tech.c 2002/01/14 09:17:05
> @@ -53,6 +53,8 @@
> void set_invention(struct player *pplayer, Tech_Type_id tech,
> enum tech_state value)
> {
> + assert(!is_barbarian(pplayer));
> +
> if (pplayer->research.inventions[tech].state == value) {
> return;
> }
> @@ -344,31 +346,36 @@
> **************************************************************************/
> int base_total_bulbs_required(struct player *pplayer, Tech_Type_id tech)
> {
> - int cost;
> -
> - assert(!is_barbarian(pplayer));
> + int cost, tech_cost_style = game.rgame.tech_cost_style;
>
> if (get_invention(pplayer, tech) == TECH_KNOWN) {
> return 0;
> }
> +
> + if (tech > game.num_tech_types) {
> + /* Future techs use style 0 */
> + tech_cost_style = 0;
> + }
> +
> + if (tech_cost_style == 2 && advances[tech].preset_cost == -1) {
> + /* No preset, using style 1 */
> + tech_cost_style = 1;
> + }
>
> - if (tech > game.num_tech_types || game.rgame.tech_cost_style == 0) {
> - /* Future tech or cost_style 0 */
> + switch (tech_cost_style) {
> + case 0:
> cost = pplayer->research.techs_researched * game.researchcost;
> - } else if (game.rgame.tech_cost_style == 1
> - || (game.rgame.tech_cost_style == 2
> - && advances[tech].preset_cost == -1)) {
> - /* cost_style 1 or cost_style 2 with unset value */
> + break;
> + case 1:
> cost = advances[tech].num_reqs * game.researchcost;
> - } else if (game.rgame.tech_cost_style == 2) {
> - /* cost_style 2 with set value */
> - cost =
> - advances[tech].preset_cost * game.researchcost /
> + break;
> + case 2:
> + cost = (advances[tech].preset_cost * game.researchcost) /
> GAME_DEFAULT_RESEARCHCOST;
> - } else {
> - /* other */
> - freelog(LOG_ERROR, "Invalid tech_cost_style %d",
> - game.rgame.tech_cost_style);
> + break;
> + default:
> + freelog(LOG_ERROR, "Invalid tech_cost_style %d %d",
> + game.rgame.tech_cost_style, tech_cost_style);
> assert(0);
> exit(1);
> }
> @@ -378,28 +385,47 @@
> cost *= 2;
> }
>
> - if (game.rgame.tech_leakage == 0) {
> + switch (game.rgame.tech_leakage) {
> + case 0:
> /* no change */
> - } else if (game.rgame.tech_leakage == 1) {
> - int players = get_num_human_and_ai_players();
> - cost = ((players - game.global_advances[tech]) * cost) / players;
> - } else if (game.rgame.tech_leakage == 2) {
> - int players = 0, players_with_tech = 0;
> -
> - /* Find out how many players have tech */
> - players_iterate(other) {
> - if (!player_has_embassy(pplayer, other)) {
> - continue;
> + break;
> +
> + case 1:
> + {
> + int players = get_num_human_and_ai_players();
> + if (players > 0) {
> + /* Every non barbarian-only game */
> + assert(players >= game.global_advances[tech]);
> + cost = ((players - game.global_advances[tech]) * cost) / players;
> }
> + }
> + break;
>
> - players++;
> - if (get_invention(other, tech) == TECH_KNOWN) {
> - players_with_tech++;
> + case 2:
> + {
> + int players = 0, players_with_tech = 0;
> +
> + /* Find out how many players have tech */
> + players_iterate(other) {
> + if (!player_has_embassy(pplayer, other)) {
> + continue;
> + }
> +
> + players++;
> + if (get_invention(other, tech) == TECH_KNOWN) {
> + players_with_tech++;
> + }
> }
> - } players_iterate_end;
> + players_iterate_end;
>
> - cost = ((players - players_with_tech) * cost) / players;
> - } else {
> + if (players > 0) {
> + /* The player has an embassy with at least one other player */
> + cost = ((players - players_with_tech) * cost) / players;
> + }
> + }
> + break;
> +
> + default:
> freelog(LOG_ERROR, "Invalid tech_leakage %d", game.rgame.tech_leakage);
> assert(0);
> exit(1);
[Freeciv-Dev] Re: civserver segfault with new research system (PR#1221), Justin Moore, 2002/01/16
|
|