forked from townforge/townforge
avoid using duplicate merchant ship names at the same time
This commit is contained in:
parent
c19f9dc5c0
commit
fb997bf2e6
@ -863,7 +863,21 @@ static void add_cities(const BlockchainDB &db, uint8_t version, cc_command_game_
|
||||
msd.price = item.price;
|
||||
msd.weight = item.weight;
|
||||
msd.sold = 0;
|
||||
cc::get_random_merchant_ship_flavour_text(msd.ship_name, msd.origin, cd.id, db.get_cc_random_seed());
|
||||
|
||||
std::vector<std::string> used_names;
|
||||
for (uint32_t sn_city: cities)
|
||||
{
|
||||
for (uint32_t sn_channel: trade_channels)
|
||||
{
|
||||
uint64_t sn_height, sn_price;
|
||||
std::string sn_ship_name, sn_origin;
|
||||
uint32_t sn_item, sn_amount, sn_sold;
|
||||
std::vector<uint64_t> sn_nonces;
|
||||
if (db.get_cc_merchant_ship_data(sn_city, sn_channel, sn_height, sn_ship_name, sn_origin, sn_item, sn_amount, sn_price, sn_sold, sn_nonces))
|
||||
used_names.push_back(std::move(sn_ship_name));
|
||||
}
|
||||
}
|
||||
cc::get_random_merchant_ship_flavour_text(msd.ship_name, msd.origin, cd.id, db.get_cc_random_seed(), used_names);
|
||||
|
||||
std::map<uint32_t, uint32_t> item_balances;
|
||||
CHECK_AND_ASSERT_THROW_MES(db.get_cc_account_item_balances(cd.treasury, item_balances), "Error getting treasury data");
|
||||
|
@ -113,7 +113,7 @@ uint32_t get_random_merchant_ship_item(const std::vector<merchant_ship_available
|
||||
return 0;
|
||||
}
|
||||
|
||||
void get_random_merchant_ship_flavour_text(std::string &ship_name, std::string &origin, uint32_t city, const crypto::hash &seed)
|
||||
void get_random_merchant_ship_flavour_text(std::string &ship_name, std::string &origin, uint32_t city, const crypto::hash &seed, const std::vector<std::string> &avoid_names)
|
||||
{
|
||||
uint8_t data[sizeof(crypto::hash) + sizeof(uint32_t) + 1], *ptr = data;
|
||||
memcpy(ptr, &seed, sizeof(crypto::hash));
|
||||
@ -127,8 +127,14 @@ void get_random_merchant_ship_flavour_text(std::string &ship_name, std::string &
|
||||
uint64_t r = SWAP64LE(*(uint64_t*)&res);
|
||||
|
||||
const size_t num_ship_names = sizeof(ship_names) / sizeof(ship_names[0]);
|
||||
const uint32_t ship_name_index = (r & 0xffff) % num_ship_names;
|
||||
ship_name = ship_names[ship_name_index];
|
||||
uint32_t ship_name_index = (r & 0xffff) % num_ship_names;
|
||||
for (size_t attempt = 0; attempt < num_ship_names; ++attempt)
|
||||
{
|
||||
ship_name = ship_names[ship_name_index];
|
||||
if (std::find(avoid_names.begin(), avoid_names.end(), ship_name) == avoid_names.end())
|
||||
break;
|
||||
ship_name_index = (ship_name_index + 1) % num_ship_names;
|
||||
}
|
||||
r >>= 16;
|
||||
|
||||
const size_t num_origins = sizeof(origins) / sizeof(origins[0]);
|
||||
|
@ -27,7 +27,7 @@ struct merchant_ship_available_item_t
|
||||
|
||||
bool get_merchant_ship_available_items(const cryptonote::BlockchainDB &db, std::vector<merchant_ship_available_item_t> &available_items, uint8_t version);
|
||||
uint32_t get_random_merchant_ship_item(const std::vector<merchant_ship_available_item_t> &items, uint32_t city, const crypto::hash &seed);
|
||||
void get_random_merchant_ship_flavour_text(std::string &ship_name, std::string &origin, uint32_t city, const crypto::hash &seed);
|
||||
void get_random_merchant_ship_flavour_text(std::string &ship_name, std::string &origin, uint32_t city, const crypto::hash &seed, const std::vector<std::string> &avoid);
|
||||
void generate_merchant_ship_transaction(cryptonote::transaction &tx, uint32_t idx, uint32_t num_transactions, uint32_t account, uint64_t height, uint32_t item, uint32_t amount, uint64_t price, uint64_t nonce);
|
||||
void generate_merchant_ship_transactions(std::vector<cryptonote::transaction> &transactions, uint32_t account, uint64_t height, uint32_t item, uint32_t amount, uint64_t price, const std::vector<uint64_t> &nonces);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user