getInstalledVehicleData
Definition
-- @/lua/ge/extensions/core/multiSpawn.lua:134
local function getInstalledVehicleData(params) -- gets all vehicles and creates the initial data
params = params or {allMods = false, allConfigs = true}
params.filters = params.filters or deepcopy(defaultFilters)
local minPop = params.minPop or 0
local vehData, configData = {}, {}
for _, model in pairs(core_vehicles.getModelList().models) do
local officialModel = isOfficialSource(model)
if params.allMods or officialModel then
table.clear(configData)
local defaultConfig = model.default_pc
local defaultPop, defaultPopFactor = 0, 1
local country = model.Country and string.lower(model.Country) or 'default'
if country ~= 'default' then
if not vehData.countryCounts then vehData.countryCounts = {} end
vehData.countryCounts[country] = (vehData.countryCounts[country] or 0) + 1 -- counts each country of origin entry (ratios will affect probability of selection)
end
for _, config in pairs(core_vehicles.getModel(model.key).configs) do
local officialConfig = isOfficialSource(config)
if params.allMods or officialConfig then
local configCopy = deepcopy(config)
if type(configCopy.Population) ~= 'number' then
if not officialModel or not officialConfig then
configCopy.Population = 10000 -- improves chance of selecting mod configs, if applicable (old: 5000)
else
configCopy.Population = 0
end
end
local popValue = configCopy.Population
if popValue >= minPop then
configCopy.Name = model.Name -- enables filtering by name
configCopy.Type = config.Type or model.Type -- this way is not good, "Type" should only be a model property
configCopy.Country = model.Country -- improves selection of domestic models
configCopy['Derby Class'] = model['Derby Class'] -- enables filtering by class
local popFactor = getPopulationFactor(configCopy, params)
if popFactor > 0 then -- population value must be greater than zero to enable entry into table
if popValue > defaultPop then -- searches for the maximum population value to apply to model data
defaultPop = popValue
defaultPopFactor = popFactor
end
if params.allConfigs or config.key == defaultConfig then
table.insert(configData, {
config = config.key,
popBase = popValue,
popFactor = popFactor
})
end
end
end
end
end
if configData[1] then
table.insert(vehData, {
model = model.key,
country = country,
popBase = defaultPop,
popFactor = defaultPopFactor,
configData = deepcopy(configData)
})
end
end
end
return vehData
end
Callers
@/lua/ge/extensions/core/multiSpawn.lua
if params.country then params.country = string.lower(params.country) end
local vehData = getInstalledVehicleData(params)