cc: more accurate payout determination

This commit is contained in:
Crypto City 2020-11-15 22:55:46 +00:00
parent ba682aa23f
commit 49b4385eae

View File

@ -1342,16 +1342,12 @@ static void add_cities(const BlockchainDB &db, cc_command_game_update_t &cg, gam
}
}
uint64_t total_shares[NUM_ROLES] = {0};
uint64_t share_payout[NUM_ROLES] = {0};
uint64_t total_paid = 0;
// accumulate per role
for (const auto &e: active_buildings_per_city[city])
total_shares[std::get<2>(e)] += std::get<3>(e);
for (int role = 1; role < NUM_ROLES; ++role)
if (total_shares[role] > 0)
share_payout[role] = total_payout[role] / total_shares[role];
for (const auto &e: active_buildings_per_city[city])
{
const uint32_t flag_id = std::get<0>(e);
@ -1359,7 +1355,11 @@ static void add_cities(const BlockchainDB &db, cc_command_game_update_t &cg, gam
const uint8_t role = std::get<2>(e);
const uint64_t shares = std::get<3>(e);
const uint64_t payout = shares * share_payout[role];
if (total_shares[role] == 0)
continue;
uint64_t hi, lo = mul128(shares, total_payout[role], &hi);
div128_64(hi, lo, total_shares[role], &hi, &lo, NULL, NULL);
const uint64_t payout = lo;
if (payout)
{
events.add(cg, owner, flag_id) << "Gets " << cryptonote::print_money(payout) << " payout for " << shares << "/" << total_shares[role] << " shares (" << cc::get_role_name(role) << ")";