Hi,
While i love this mod and use it always now, one thing that bugs me is how slow some of the vehicles are when they are self driving.
Looking at the code, you have this limited to 50 - i am unsure if this is 50kph or tiles/s, but meh.
I've written this code which will work out a vehicles max speed that the player is currently in, using this you could allow auto driven vehicles to drive at their valid speeds.
local player = game.player
local vehicle = player.vehicle
if ( vehicle ) then
local tileUnderVehicle = player.surface.get_tile(player.position)
if ( tileUnderVehicle ) then
if not global.vehMaxSpeeds then global.vehMaxSpeeds = {}
if ( global.vehMaxSpeeds[vehicle.name] ) then
-- just return the stored speeds, so we dont have to calc again
return global.vehMaxSpeeds[vehicle.name]
end
-- Setup defaults
local consumption_modifier = 1
local fuel_speed_modifier = 1
local grid_speed_bonus = 1
local sticker_speed_modifiers = 1
local proto_effectivity_modifier = 1
local car_friction = 1
local sticker_friction_modifier = 1
-- Get vehicles prototype engine details
local prototype = vehicle.prototype
local consumption = prototype.consumption
local proto_effectivity = prototype.effectivity
local burner_effectivity = prototype.burner_prototype.effectivity
local friction = prototype.friction_force
local terrain_friction_modifier = prototype.terrain_friction_modifier
local tile_fiction_modifier = tileUnderVehicle.prototype.vehicle_friction_modifier
local vehicle_weight = prototype.weight
-- Do some crazy math
local acceleration_eng_per_tick = (consumption * consumption_modifier * proto_effectivity * proto_effectivity_modifier * burner_effectivity * fuel_speed_modifier * sticker_speed_modifiers)
local friction_modifier = (1 - friction * (1 + terrain_friction_modifier * (tile_fiction_modifier - 1) ) * car_friction * sticker_friction_modifier)
local max_energy = acceleration_eng_per_tick * friction_modifier * friction_modifier / (1-friction_modifier*friction_modifier)
-- Max speed in tiles/s and kph
local max_speed_tiles_sec = math.sqrt(max_energy/0.5/vehicle_weight)
local max_speed_kph = max_speed_tiles_sec * 3.6
-- Store the max speed, so we dont have to calculate it later
-- You can always clear the global max speeds data on mod init, so that it calculates it once every game at least, so if a mod updates a vehicles speed, you can re-read it.
global.vehMaxSpeeds[vehicle.name] = max_speed_kph
game.print("Vehicle " .. vehicle.name .. " max speed: " .. max_speed_tiles_sec .. " tiles/s | " .. max_speed_kph .. " kph")
end
end