[Freeciv-commits] r25290 - /trunk/server/techtools.c
Author: jtn Date: Fri Jun 27 21:09:29 2014 New Revision: 25290 URL: http://svn.gna.org/viewcvs/freeciv?rev=25290view=rev Log: Prevent tech loss of tech which is root_req for some other known tech. Reported by Matthias Pfafferodt (syntron@gna). See gna bug #19176. Modified: trunk/server/techtools.c Modified: trunk/server/techtools.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/techtools.c?rev=25290r1=25289r2=25290view=diff == --- trunk/server/techtools.c(original) +++ trunk/server/techtools.cFri Jun 27 21:09:29 2014 @@ -641,16 +641,26 @@ static Tech_type_id pick_random_tech_to_lose(struct player* plr) { bv_techs eligible_techs; - int chosen, eligible = 0; - - BV_CLR_ALL(eligible_techs); + int chosen, eligible = advance_count(); + + BV_SET_ALL(eligible_techs); advance_index_iterate(A_FIRST, i) { -/* Never lose self root_req techs */ -if (advance_required(i, AR_ROOT) != i - player_invention_state(plr, i) == TECH_KNOWN) { - BV_SET(eligible_techs, i); - eligible++; +if (player_invention_state(plr, i) != TECH_KNOWN) { + if (BV_ISSET(eligible_techs, i)) { +eligible--; +BV_CLR(eligible_techs, i); + } +} else { + /* Never lose techs that are root_req for a currently known tech + * (including self root_req) */ + Tech_type_id root = advance_required(i, AR_ROOT); + if (root != A_NONE) { +if (BV_ISSET(eligible_techs, root)) { + eligible--; + BV_CLR(eligible_techs, root); +} + } } } advance_index_iterate_end; @@ -1294,8 +1304,20 @@ bool tech_transfer(struct player *plr_recv, struct player *plr_donor, Tech_type_id tech) { - if (fc_rand(100) game.server.techlost_donor) { -forget_tech_transfered(plr_donor, tech); + if (game.server.techlost_donor 0) { +/* Don't let donor lose tech if it's root_req for some other known + * tech */ +bool donor_can_lose = TRUE; +advance_index_iterate(A_FIRST, i) { + if (player_invention_state(plr_donor, i) == TECH_KNOWN + advance_required(i, AR_ROOT) == tech) { +donor_can_lose = FALSE; +break; + } +} advance_index_iterate_end; +if (donor_can_lose fc_rand(100) game.server.techlost_donor) { + forget_tech_transfered(plr_donor, tech); +} } if (fc_rand(100) game.server.techlost_recv) { ___ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits
[Freeciv-commits] r25289 - /trunk/server/techtools.c
Author: jtn Date: Fri Jun 27 21:09:26 2014 New Revision: 25289 URL: http://svn.gna.org/viewcvs/freeciv?rev=25289view=rev Log: Prevent tech loss removing self root_req techs. See bug #22161. Modified: trunk/server/techtools.c Modified: trunk/server/techtools.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/techtools.c?rev=25289r1=25288r2=25289view=diff == --- trunk/server/techtools.c(original) +++ trunk/server/techtools.cFri Jun 27 21:09:26 2014 @@ -52,7 +52,7 @@ /* Define this to add information about tech upkeep. */ #undef TECH_UPKEEP_DEBUGGING -static Tech_type_id pick_random_tech_researched(struct player* plr); +static Tech_type_id pick_random_tech_to_lose(struct player* plr); static void player_tech_lost(struct player* plr, Tech_type_id tech); static void forget_tech_transfered(struct player *pplayer, Tech_type_id tech); @@ -594,7 +594,7 @@ tech = A_FUTURE; research-future_tech--; } else { - tech = pick_random_tech_researched(plr); + tech = pick_random_tech_to_lose(plr); if (tech != A_NONE) { notify_player(plr, NULL, E_TECH_GAIN, ftc_server, @@ -636,27 +636,33 @@ } / - Returns a random researched tech. -/ -static Tech_type_id pick_random_tech_researched(struct player* plr) -{ - int chosen, researched = 0; + Choose a random tech for player to lose. +/ +static Tech_type_id pick_random_tech_to_lose(struct player* plr) +{ + bv_techs eligible_techs; + int chosen, eligible = 0; + + BV_CLR_ALL(eligible_techs); advance_index_iterate(A_FIRST, i) { -if (player_invention_state(plr, i) == TECH_KNOWN) { - researched++; +/* Never lose self root_req techs */ +if (advance_required(i, AR_ROOT) != i + player_invention_state(plr, i) == TECH_KNOWN) { + BV_SET(eligible_techs, i); + eligible++; } } advance_index_iterate_end; - if (researched == 0) { -/* no technology at all */ + if (eligible == 0) { +/* no researched technology at all */ return A_NONE; } - chosen = fc_rand(researched) + 1; + chosen = fc_rand(eligible) + 1; advance_index_iterate(A_FIRST, i) { -if (player_invention_state(plr, i) == TECH_KNOWN) { +if (BV_ISSET(eligible_techs, i)) { chosen--; if (chosen == 0) { return i; ___ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits
[Freeciv-commits] r25292 - /branches/S2_5/server/techtools.c
Author: jtn Date: Fri Jun 27 21:11:59 2014 New Revision: 25292 URL: http://svn.gna.org/viewcvs/freeciv?rev=25292view=rev Log: Prevent tech loss of tech which is root_req for some other known tech. Reported by Matthias Pfafferodt (syntron@gna). See gna bug #19176. Modified: branches/S2_5/server/techtools.c Modified: branches/S2_5/server/techtools.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/techtools.c?rev=25292r1=25291r2=25292view=diff == --- branches/S2_5/server/techtools.c(original) +++ branches/S2_5/server/techtools.cFri Jun 27 21:11:59 2014 @@ -560,16 +560,26 @@ static Tech_type_id pick_random_tech_to_lose(struct player* plr) { bv_techs eligible_techs; - int chosen, eligible = 0; - - BV_CLR_ALL(eligible_techs); + int chosen, eligible = advance_count(); + + BV_SET_ALL(eligible_techs); advance_index_iterate(A_FIRST, i) { -/* Never lose self root_req techs */ -if (advance_required(i, AR_ROOT) != i - player_invention_state(plr, i) == TECH_KNOWN) { - BV_SET(eligible_techs, i); - eligible++; +if (player_invention_state(plr, i) != TECH_KNOWN) { + if (BV_ISSET(eligible_techs, i)) { +eligible--; +BV_CLR(eligible_techs, i); + } +} else { + /* Never lose techs that are root_req for a currently known tech + * (including self root_req) */ + Tech_type_id root = advance_required(i, AR_ROOT); + if (root != A_NONE) { +if (BV_ISSET(eligible_techs, root)) { + eligible--; + BV_CLR(eligible_techs, root); +} + } } } advance_index_iterate_end; @@ -1221,8 +1231,20 @@ bool tech_transfer(struct player *plr_recv, struct player *plr_donor, Tech_type_id tech) { - if (fc_rand(100) game.server.techlost_donor) { -forget_tech_transfered(plr_donor, tech); + if (game.server.techlost_donor 0) { +/* Don't let donor lose tech if it's root_req for some other known + * tech */ +bool donor_can_lose = TRUE; +advance_index_iterate(A_FIRST, i) { + if (player_invention_state(plr_donor, i) == TECH_KNOWN + advance_required(i, AR_ROOT) == tech) { +donor_can_lose = FALSE; +break; + } +} advance_index_iterate_end; +if (donor_can_lose fc_rand(100) game.server.techlost_donor) { + forget_tech_transfered(plr_donor, tech); +} } if (fc_rand(100) game.server.techlost_recv) { ___ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits
[Freeciv-commits] r25291 - /branches/S2_5/server/techtools.c
Author: jtn Date: Fri Jun 27 21:11:56 2014 New Revision: 25291 URL: http://svn.gna.org/viewcvs/freeciv?rev=25291view=rev Log: Prevent tech loss removing self root_req techs. See bug #22161. Modified: branches/S2_5/server/techtools.c Modified: branches/S2_5/server/techtools.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/server/techtools.c?rev=25291r1=25290r2=25291view=diff == --- branches/S2_5/server/techtools.c(original) +++ branches/S2_5/server/techtools.cFri Jun 27 21:11:56 2014 @@ -51,7 +51,7 @@ /* Define this to add information about tech upkeep. */ #undef TECH_UPKEEP_DEBUGGING -static Tech_type_id pick_random_tech_researched(struct player* plr); +static Tech_type_id pick_random_tech_to_lose(struct player* plr); static void player_tech_lost(struct player* plr, Tech_type_id tech); static void forget_tech_transfered(struct player *pplayer, Tech_type_id tech); @@ -513,7 +513,7 @@ tech = A_FUTURE; research-future_tech--; } else { - tech = pick_random_tech_researched(plr); + tech = pick_random_tech_to_lose(plr); if (tech != A_NONE) { notify_player(plr, NULL, E_TECH_GAIN, ftc_server, @@ -555,27 +555,33 @@ } / - Returns a random researched tech. -/ -static Tech_type_id pick_random_tech_researched(struct player* plr) -{ - int chosen, researched = 0; + Choose a random tech for player to lose. +/ +static Tech_type_id pick_random_tech_to_lose(struct player* plr) +{ + bv_techs eligible_techs; + int chosen, eligible = 0; + + BV_CLR_ALL(eligible_techs); advance_index_iterate(A_FIRST, i) { -if (player_invention_state(plr, i) == TECH_KNOWN) { - researched++; +/* Never lose self root_req techs */ +if (advance_required(i, AR_ROOT) != i + player_invention_state(plr, i) == TECH_KNOWN) { + BV_SET(eligible_techs, i); + eligible++; } } advance_index_iterate_end; - if (researched == 0) { -/* no technology at all */ + if (eligible == 0) { +/* no researched technology at all */ return A_NONE; } - chosen = fc_rand(researched) + 1; + chosen = fc_rand(eligible) + 1; advance_index_iterate(A_FIRST, i) { -if (player_invention_state(plr, i) == TECH_KNOWN) { +if (BV_ISSET(eligible_techs, i)) { chosen--; if (chosen == 0) { return i; ___ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits
[Freeciv-commits] r25293 - /branches/S2_4/server/techtools.c
Author: jtn Date: Fri Jun 27 21:12:59 2014 New Revision: 25293 URL: http://svn.gna.org/viewcvs/freeciv?rev=25293view=rev Log: Prevent tech loss removing self root_req techs. See bug #22161. Modified: branches/S2_4/server/techtools.c Modified: branches/S2_4/server/techtools.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_4/server/techtools.c?rev=25293r1=25292r2=25293view=diff == --- branches/S2_4/server/techtools.c(original) +++ branches/S2_4/server/techtools.cFri Jun 27 21:12:59 2014 @@ -51,7 +51,7 @@ /* Define this to add information about tech upkeep. */ #undef TECH_UPKEEP_DEBUGGING -static Tech_type_id pick_random_tech_researched(struct player* plr); +static Tech_type_id pick_random_tech_to_lose(struct player* plr); static Tech_type_id pick_random_tech(struct player* plr); static void player_tech_lost(struct player* plr, Tech_type_id tech); static void forget_tech_transfered(struct player *pplayer, Tech_type_id tech); @@ -488,7 +488,8 @@ research-future_tech); research-future_tech--; } else { - Tech_type_id tech = pick_random_tech_researched(plr); + Tech_type_id tech = pick_random_tech_to_lose(plr); + if (tech != A_NONE) { notify_player(plr, NULL, E_TECH_GAIN, ftc_server, _(Insufficient science output. We lost %s.), @@ -520,27 +521,33 @@ } / - Returns a random researched tech. -/ -static Tech_type_id pick_random_tech_researched(struct player* plr) -{ - int chosen, researched = 0; + Choose a random tech for player to lose. +/ +static Tech_type_id pick_random_tech_to_lose(struct player* plr) +{ + bv_techs eligible_techs; + int chosen, eligible = 0; + + BV_CLR_ALL(eligible_techs); advance_index_iterate(A_FIRST, i) { -if (player_invention_state(plr, i) == TECH_KNOWN) { - researched++; +/* Never lose self root_req techs */ +if (advance_required(i, AR_ROOT) != i + player_invention_state(plr, i) == TECH_KNOWN) { + BV_SET(eligible_techs, i); + eligible++; } } advance_index_iterate_end; - if (researched == 0) { -/* no technology at all */ + if (eligible == 0) { +/* no researched technology at all */ return A_NONE; } - chosen = fc_rand(researched) + 1; + chosen = fc_rand(eligible) + 1; advance_index_iterate(A_FIRST, i) { -if (player_invention_state(plr, i) == TECH_KNOWN) { +if (BV_ISSET(eligible_techs, i)) { chosen--; if (chosen == 0) { return i; ___ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits