Skip to content

Commit

Permalink
Simplified random station selection for delivery missions
Browse files Browse the repository at this point in the history
  • Loading branch information
robothauler authored and Webster Sheets committed Sep 18, 2024
1 parent 9b6c6c2 commit bf2b13d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
6 changes: 2 additions & 4 deletions data/modules/Assassination/Assassination.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,14 @@ end
local nearbysystems
local makeAdvert = function (station)
if nearbysystems == nil then
nearbysystems = Game.system:GetNearbySystems(max_ass_dist, function (s) return #s:GetStationPaths() > 0 end)
nearbysystems = MissionUtils.GetNearbyStationPaths(Game.system, max_ass_dist)
end
if #nearbysystems == 0 then return end
local client = Character.New()
local targetIsfemale = Engine.rand:Integer(1) == 1
local target = l["TITLE_"..Engine.rand:Integer(1, num_titles)-1] .. " " .. NameGen.FullName(targetIsfemale)
local flavour = Engine.rand:Integer(1, #flavours)
local nearbysystem = nearbysystems[Engine.rand:Integer(1,#nearbysystems)]
local nearbystations = nearbysystem:GetStationPaths()
local location = nearbystations[Engine.rand:Integer(1,#nearbystations)]
local location = nearbysystems[Engine.rand:Integer(1,#nearbysystems)]
local dist = location:DistanceTo(Game.system)
local time = Engine.rand:Number(7*60*60*24, 35*60*60*24)
local due = time + MissionUtils.TravelTime(dist, location) * Engine.rand:Number(0.5, 1.5)
Expand Down
12 changes: 4 additions & 8 deletions data/modules/CargoRun/CargoRun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ end
local nearbysystems

local makeAdvert = function (station)
local reward, due, location, nearbysystem, dist, nearbystations, amount
local reward, due, location, dist, nearbystations, amount
local risk, wholesaler, pickup, branch, cargotype, missiontype, timeout
local client = Character.New()
local urgency = Engine.rand:Number(0, 1)
Expand All @@ -354,7 +354,6 @@ local makeAdvert = function (station)

branch, cargotype = randomCargo()
if localdelivery then
nearbysystem = Game.system
-- discard stations closer than 1000m and further than 20AU
nearbystations = findNearbyStations(station, 1000, 1.4960e11 * 20)
if #nearbystations == 0 then return nil end
Expand All @@ -375,14 +374,11 @@ local makeAdvert = function (station)
end
else
if nearbysystems == nil then
nearbysystems = Game.system:GetNearbySystems(max_delivery_dist, function (s) return #s:GetStationPaths() > 0 end)
nearbysystems = MissionUtils.GetNearbyStationPaths(Game.system, max_delivery_dist)
end
if #nearbysystems == 0 then return nil end

nearbysystem = nearbysystems[Engine.rand:Integer(1,#nearbysystems)]
dist = nearbysystem:DistanceTo(Game.system)
nearbystations = nearbysystem:GetStationPaths()
location = nearbystations[Engine.rand:Integer(1,#nearbystations)]
location = nearbysystems[Engine.rand:Integer(1,#nearbysystems)]
dist = location:DistanceTo(Game.system)
wholesaler = Engine.rand:Number(0, 1) > 0.75 and true or false

if wholesaler then
Expand Down
16 changes: 6 additions & 10 deletions data/modules/DeliverPackage/DeliverPackage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,9 @@ local placeAdvert = function (station, ad)
ads[ref] = ad
end

-- return statement is nil if no advert was created, else it is bool:
-- true if a localdelivery, false for non-local
-- return statement is the created advert or nil
local makeAdvert = function (station, manualFlavour, nearbystations)
local reward, due, location, nearbysystem, dist, timeout
local reward, due, location, dist, timeout
local client = Character.New()

-- set flavour manually if a second arg is given
Expand All @@ -262,7 +261,6 @@ local makeAdvert = function (station, manualFlavour, nearbystations)
local risk = flavours[flavour].risk

if flavours[flavour].localdelivery then
nearbysystem = Game.system
if nearbystations == nil then
-- discard stations closer than 1000m and further than 20AU
nearbystations = findNearbyStations(station, 1000, 1.4960e11 * 20)
Expand All @@ -273,13 +271,11 @@ local makeAdvert = function (station, manualFlavour, nearbystations)
due =(60*60*18 + MissionUtils.TravelTimeLocal(dist)) * (1.5-urgency) * Engine.rand:Number(0.9,1.1)
else
if nearbysystems == nil then
nearbysystems = Game.system:GetNearbySystems(max_delivery_dist, function (s) return #s:GetStationPaths() > 0 end)
nearbysystems = MissionUtils.GetNearbyStationPaths(Game.system, max_delivery_dist)
end
if #nearbysystems == 0 then return nil end
nearbysystem = nearbysystems[Engine.rand:Integer(1,#nearbysystems)]
dist = nearbysystem:DistanceTo(Game.system)
local nearbystations = nearbysystem:GetStationPaths()
location = nearbystations[Engine.rand:Integer(1,#nearbystations)]
location = nearbysystems[Engine.rand:Integer(1,#nearbysystems)]
dist = location:DistanceTo(Game.system)
reward = ((dist / max_delivery_dist) * typical_reward * (1+risk) * (1.5+urgency) * Engine.rand:Number(0.8,1.2))
due = MissionUtils.TravelTime(dist, location) * (1.5-urgency) * Engine.rand:Number(0.9,1.1)
end
Expand Down Expand Up @@ -310,7 +306,7 @@ end

local onCreateBB = function (station)
if nearbysystems == nil then
nearbysystems = Game.system:GetNearbySystems(max_delivery_dist, function (s) return #s:GetStationPaths() > 0 end)
nearbysystems = MissionUtils.GetNearbyStationPaths(Game.system, max_delivery_dist)
end
local nearbystations = findNearbyStations(station, 1000, 1.4960e11 * 20)
local num = Engine.rand:Integer(0, math.ceil(Game.system.population))
Expand Down

0 comments on commit bf2b13d

Please sign in to comment.