Exemplo n.º 1
0
/* Turn a number of serfs into knight for the given player. */
int
player_promote_serfs_to_knights(player_t *player, int number)
{
    int promoted = 0;

    for (int i = 1; i < game.max_serf_index && number > 0; i++) {
        if (SERF_ALLOCATED(i)) {
            serf_t *serf = game_get_serf(i);
            if (serf->state == SERF_STATE_IDLE_IN_STOCK &&
                    SERF_PLAYER(serf) == player->player_num &&
                    SERF_TYPE(serf) == SERF_GENERIC) {
                inventory_t *inv = game_get_inventory(serf->s.idle_in_stock.inv_index);
                if (inv->resources[RESOURCE_SWORD] > 0 &&
                        inv->resources[RESOURCE_SHIELD] > 0) {
                    inv->resources[RESOURCE_SWORD] -= 1;
                    inv->resources[RESOURCE_SHIELD] -= 1;
                    inv->spawn_priority -= 1;
                    inv->serfs[SERF_GENERIC] = 0;

                    serf->type = (SERF_KNIGHT_0 << 2) | (serf->type & 3);

                    player->serf_count[SERF_GENERIC] -= 1;
                    player->serf_count[SERF_KNIGHT_0] += 1;
                    player->total_military_score += 1;

                    promoted += 1;
                    number -= 1;
                }
            }
        }
    }

    return promoted;
}
Exemplo n.º 2
0
/* Turn a number of serfs into knight for the given player. */
int
player_promote_serfs_to_knights(player_t *player, int number)
{
	int promoted = 0;

	for (uint i = 1; i < game.max_serf_index && number > 0; i++) {
		if (SERF_ALLOCATED(i)) {
			serf_t *serf = game_get_serf(i);
			if (serf->state == SERF_STATE_IDLE_IN_STOCK &&
			    SERF_PLAYER(serf) == player->player_num &&
			    SERF_TYPE(serf) == SERF_GENERIC) {
				inventory_t *inv = game_get_inventory(serf->s.idle_in_stock.inv_index);
				if (inv->resources[RESOURCE_SWORD] > 0 &&
				    inv->resources[RESOURCE_SHIELD] > 0) {
					inv->resources[RESOURCE_SWORD] -= 1;
					inv->resources[RESOURCE_SHIELD] -= 1;
					inv->generic_count -= 1;
					inv->serfs[SERF_GENERIC] = 0;

					serf_set_type(serf, SERF_KNIGHT_0);

					promoted += 1;
					number -= 1;
				}
			}
		}
	}

	return promoted;
}