#48306: citizens_convert() not weighting nationalities by the number of citizens Open Date: 2023-06-27 18:03 Last Update: 2024-08-26 14:35 URL for this Ticket: https://osdn.net//projects/freeciv/ticket/48306 RSS feed for this Ticket: https://osdn.net/ticket/ticket_rss.php?group_id=12505&tid=48306 --------------------------------------------------------------------- Last Changes/Comment on this Ticket: 2024-08-26 14:35 Updated by: Anonymous Comment: I checked on GitHub citizenshand.c, and maybe, instead of making a list of all the foreign nationalities, we're going to go through each citizen one by one using this function called citizens_iterate. As we go through each one, we'll keep a count of how many citizens we've seen so far. Then, we'll generate a random number between 1 and that total count. We'll also keep track of which citizen we're currently looking at, and if the random number matches the number of the citizen we're on, we'll convert that citizen to a new nationality using the citizens_nation_move function. What do you think? (another option is using fc_weighted_rand or something similar) void citizens_convert(struct city *pcity) { int total_citizens = 0; struct player_slot *pslot; fc_assert_ret(pcity); if (!game.info.citizen_nationality) { return; } if (!citizen_convert_check(pcity)) { return; } if (citizens_nation_foreign(pcity) == 0) { /* Only our own citizens. */ return; } /* Count total citizens */ citizens_iterate(pcity, citizen_slot) { total_citizens++; } citizens_iterate_end; /* Pick a random citizen */ int random_citizen = fc_rand(total_citizens) + 1; int current_citizen = 0; citizens_iterate(pcity, citizen_slot) { current_citizen++; if (current_citizen == random_citizen) { pslot = citizen_slot; break; } } citizens_iterate_end; // rest of the code } --------------------------------------------------------------------- Ticket Status: Reporter: cazfi Owner: (None) Type: Bugs Status: Open Priority: 5 - Medium MileStone: (None) Component: Server Severity: 5 - Medium Resolution: None --------------------------------------------------------------------- Ticket details: At least surprisingly, if not erroneously, citizens_convert() converts citizen of a random nationality, not random citizen. The difference this makes is that all nationalities get the same weight, regardless how many citizens there are. If there's 1 citizen on nationality A and 5 citizens of nationality B, the citizen of A has 50% chance of getting converted and each citizen of B has 10% chance of getting converted. -- Ticket information of Freeciv project Freeciv Project is hosted on OSDN Project URL: https://osdn.net/projects/freeciv/ OSDN: https://osdn.net URL for this Ticket: https://osdn.net/projects/freeciv/ticket/48306 RSS feed for this Ticket: https://osdn.net/ticket/ticket_rss.php?group_id=12505&tid=48306