Commit 6fca7e91 authored by Colomban Wendling's avatar Colomban Wendling

LibOVCC: don't identify players by their nick when counting points

parent 03dfabc9
......@@ -324,10 +324,10 @@ namespace OVCC
uint n = 0; /* number of objects */
uint counts = 0; /* scoring ticks */
var list = Datalist<int>();
/* init datalist */
var table = new HashTable<Player, int>(null, null);
/* init table */
foreach (var p in this.players) {
list.set_data (p.nick, 0);
table.insert (p, 0);
}
/* loop on each TileObject */
foreach (var o in components) {
......@@ -339,7 +339,7 @@ namespace OVCC
}
/* handle occupied objects */
if (o.occupant != null) {
var cur = list.get_data (o.occupant.player.nick);
var cur = table.lookup (o.occupant.player);
switch (o.occupant.kind) {
case PawnKind.NORMAL:
cur++;
......@@ -348,42 +348,33 @@ namespace OVCC
cur+=2;
break;
}
list.set_data (o.occupant.player.nick, cur);
table.insert (o.occupant.player, cur);
/* removing pawn now is efficient and not wrong */
if (components.nth_data(0).otype != TileObjectType.FIELD) {
remove_pawn (o.occupant);
}
}
}
var scorers = new SList<string>();
var scorers = new SList<Player>();
uint current_power = 0;
/* compute list of players that score */
list.foreach ((k) => {
var power = list.id_get_data(k);
table.foreach ((k, v) => {
var power = v;
/* if that player is stronger, remember only him for now */
if (power > current_power) {
current_power = power;
scorers = new SList<string>();
scorers.prepend (k.to_string ());
scorers = new SList<Player>();
scorers.prepend (k);
}
/* if that player is equal in power to the current, store him too */
else if (power == current_power) {
scorers.prepend (k.to_string());
scorers.prepend (k);
}
});
/* check that we actually found someone */
if (current_power > 0) {
/* make each player in the list actually score */
foreach (var nick in scorers) {
Player player = null;
/* get the player from his nick */
foreach (var p in players) {
if (p.nick == nick) {
player = p;
break;
}
}
assert (player != null);
foreach (var player in scorers) {
/* handle small cities */
if (n == 2) {
player.score += 2;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment