Stock tuning parts
This commit is contained in:
parent
05c8e66668
commit
b045f76a26
@ -90,14 +90,36 @@ game::DrivableVehicle& game::OpenWorld::SpawnRandomVehicle()
|
||||
// vehicle.SetNametag("bot (" + std::to_string(vehicle.GetEntNum()) + ")");
|
||||
|
||||
auto& tuning_list = vehicle.GetTuningList();
|
||||
auto& colors = tuning_list->groups[0].parts;
|
||||
|
||||
size_t random_color = rand() % colors.size();
|
||||
// make random tuning
|
||||
std::vector<std::string> suitable_part_ids;
|
||||
for (const auto& group : tuning_list->groups)
|
||||
{
|
||||
suitable_part_ids.clear();
|
||||
|
||||
auto item = colors.begin();
|
||||
std::advance( item, random_color);
|
||||
bool add_nonstock = rand() % 100 < 3;
|
||||
|
||||
tuning.parts["primarycolor"] = item->second.id;
|
||||
for (const auto& part : group.parts)
|
||||
{
|
||||
if (part.second.stock || add_nonstock)
|
||||
suitable_part_ids.push_back(part.first);
|
||||
}
|
||||
|
||||
if (suitable_part_ids.empty())
|
||||
continue;
|
||||
|
||||
size_t random_part = rand() % suitable_part_ids.size();
|
||||
tuning.parts[group.id] = suitable_part_ids[random_part];
|
||||
}
|
||||
|
||||
// auto& colors = tuning_list->groups[0].parts;
|
||||
|
||||
// size_t random_color = rand() % colors.size();
|
||||
|
||||
// auto item = colors.begin();
|
||||
// std::advance( item, random_color);
|
||||
|
||||
// tuning.parts["primarycolor"] = item->second.id;
|
||||
|
||||
vehicle.SetTuning(tuning);
|
||||
|
||||
|
||||
@ -158,7 +158,7 @@ std::unique_ptr<const game::VehicleTuningList> game::VehicleTuningList::LoadFrom
|
||||
auto process_command = [&](const std::string& command, std::istringstream& iss) {
|
||||
if (command == "group")
|
||||
{
|
||||
VehicleTuningGroup group;
|
||||
VehicleTuningGroup group{};
|
||||
iss >> group.id;
|
||||
group.displayname = assets::ParseString(iss);
|
||||
|
||||
@ -172,7 +172,7 @@ std::unique_ptr<const game::VehicleTuningList> game::VehicleTuningList::LoadFrom
|
||||
if (!current_group)
|
||||
throw std::runtime_error("tuning list: part without active group");
|
||||
|
||||
VehicleTuningPart part;
|
||||
VehicleTuningPart part{};
|
||||
iss >> part.id >> part.price;
|
||||
part.displayname = assets::ParseString(iss);
|
||||
|
||||
@ -180,6 +180,19 @@ std::unique_ptr<const game::VehicleTuningList> game::VehicleTuningList::LoadFrom
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (command == "stock")
|
||||
{
|
||||
if (!current_group)
|
||||
throw std::runtime_error("tuning list: stock without active group");
|
||||
|
||||
std::string part_id;
|
||||
iss >> part_id;
|
||||
auto part_it = current_group->parts.find(part_id);
|
||||
if (part_it == current_group->parts.end())
|
||||
throw std::runtime_error("tuning list: stock references unknown part " + part_id);
|
||||
|
||||
part_it->second.stock = true;
|
||||
}
|
||||
else if (command == "default")
|
||||
{
|
||||
tuninglist->default_funcs.emplace_back(ParseTuningFunction(iss));
|
||||
|
||||
@ -44,6 +44,7 @@ struct VehicleTuningPart
|
||||
std::string id;
|
||||
std::string displayname;
|
||||
uint32_t price;
|
||||
bool stock;
|
||||
|
||||
std::vector<VehicleTuningFunction> funcs;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user