Incidencia #48306

citizens_convert() not weighting nationalities by the number of citizens

Abrir Fecha: 2023-06-27 18:03 Última actualización: 2024-08-26 14:35

Informador:
Propietario:
(Ninguno)
Tipo:
Estado:
Open
Componente:
Hito:
(Ninguno)
Prioridad:
5 - Medium
Gravedad:
5 - Medium
Resolución:
Ninguno
Fichero:
Ninguno

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 History (2/2 Histories)

2023-06-27 18:03 Updated by: cazfi
  • New Ticket "citizens_convert() not weighting nationalities by the number of citizens" created
2024-08-26 14:35 Updated by: None
Comentario

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

}

Attachment File List

No attachments

Editar

Please login to add comment to this ticket » Entrar