|
Line 0
Link Here
|
|
|
1 |
Fix SAR selection of ship sizes for missions |
| 2 |
https://github.com/pioneerspacesim/pioneer/commit/008e30a857036a8cc40c42bf89ef68e65b47a41e |
| 3 |
|
| 4 |
--- data/modules/SearchRescue/SearchRescue.lua.orig 2017-10-01 00:01:47 UTC |
| 5 |
+++ data/modules/SearchRescue/SearchRescue.lua |
| 6 |
@@ -613,7 +613,20 @@ local createTargetShipParameters = funct |
| 7 |
---- loading drive, weapons etc. |
| 8 |
if flavour.id == 1 or flavour.id == 6 then |
| 9 |
for i,shipdef in pairs(shipdefs) do |
| 10 |
- if shipdef.capacity / 10 < 1 then shipdefs[i] = nil end |
| 11 |
+ |
| 12 |
+ -- get mass of hyperdrive if this ship has a default drive |
| 13 |
+ -- if no default drive assume lowest mass drive |
| 14 |
+ -- higher mass drives will only be fitted later at ship creation if capacity is huge |
| 15 |
+ local drive = Equipment.hyperspace['hyperdrive_'..tostring(shipdef.hyperdriveClass)] |
| 16 |
+ if not drive then |
| 17 |
+ local drives = {} |
| 18 |
+ for i = 9, 1, -1 do |
| 19 |
+ table.insert(drives, Equipment.hyperspace['hyperdrive_'..tostring(i)]) |
| 20 |
+ end |
| 21 |
+ table.sort(drives, function (a,b) return a.capabilities.mass < b.capabilities.mass end) |
| 22 |
+ drive = drives[1] |
| 23 |
+ end |
| 24 |
+ if (shipdef.capacity-drive.capabilities.mass) / 10 < 1 then shipdefs[i] = nil end |
| 25 |
end |
| 26 |
elseif flavour.pickup_pass > 0 then |
| 27 |
for i,shipdef in pairs(shipdefs) do |
| 28 |
@@ -661,7 +674,16 @@ local createTargetShipParameters = funct |
| 29 |
if flavour.id == 1 or flavour.id == 6 then |
| 30 |
local any_pass = rand:Integer(0,1) |
| 31 |
if any_pass > 0 then |
| 32 |
- pickup_pass = rand:Integer(1, math.min((shipdef.capacity / 10)+1, max_pass)) |
| 33 |
+ local drive = Equipment.hyperspace['hyperdrive_'..tostring(shipdef.hyperdriveClass)] |
| 34 |
+ if not drive then |
| 35 |
+ local drives = {} |
| 36 |
+ for i = 9, 1, -1 do |
| 37 |
+ table.insert(drives, Equipment.hyperspace['hyperdrive_'..tostring(i)]) |
| 38 |
+ end |
| 39 |
+ table.sort(drives, function (a,b) return a.capabilities.mass < b.capabilities.mass end) |
| 40 |
+ drive = drives[1] |
| 41 |
+ end |
| 42 |
+ pickup_pass = rand:Integer(1, math.min(((shipdef.capacity-drive.capabilities.mass) / 10)+1, max_pass)) |
| 43 |
else |
| 44 |
pickup_pass = 0 |
| 45 |
end |
| 46 |
@@ -709,22 +731,25 @@ local createTargetShip = function (missi |
| 47 |
ship:SetPattern(pattern) |
| 48 |
|
| 49 |
-- load a hyperdrive |
| 50 |
- local default_drive = Equipment.hyperspace['hyperdrive_'..tostring(shipdef.hyperdriveClass)] |
| 51 |
- if default_drive then |
| 52 |
- ship:AddEquip(default_drive) |
| 53 |
- else |
| 54 |
- local drive |
| 55 |
+ -- 1st try: default drive for this ship class |
| 56 |
+ -- 2nd try: largest drive possible that doesn't take more than a 10th of available room |
| 57 |
+ -- fallback: smallest drive |
| 58 |
+ local drives = {} |
| 59 |
+ local drive = Equipment.hyperspace['hyperdrive_'..tostring(shipdef.hyperdriveClass)] |
| 60 |
+ if not drive then |
| 61 |
for i = 9, 1, -1 do |
| 62 |
- drive = Equipment.hyperspace['hyperdrive_'..tostring(i)] |
| 63 |
- if shipdef.capacity / 10 > drive.capabilities.mass then |
| 64 |
- ship:AddEquip(drive) |
| 65 |
- break |
| 66 |
- end |
| 67 |
+ table.insert(drives, Equipment.hyperspace['hyperdrive_'..tostring(i)]) |
| 68 |
end |
| 69 |
- if not drive then |
| 70 |
- ship:AddEquip(Equipment.hyperspace['hyperdrive_1']) |
| 71 |
+ table.sort(drives, function (a,b) return a.capabilities.mass < b.capabilities.mass end) |
| 72 |
+ for i = #drives, 1, -1 do |
| 73 |
+ local test_drive = drives[i] |
| 74 |
+ if shipdef.capacity / 10 > test_drive.capabilities.mass then |
| 75 |
+ drive = test_drive |
| 76 |
+ end |
| 77 |
end |
| 78 |
end |
| 79 |
+ if not drive then drive = drives[1] end |
| 80 |
+ ship:AddEquip(drive) |
| 81 |
|
| 82 |
-- add thruster fuel |
| 83 |
if mission.flavour.id == 2 or mission.flavour.id == 4 or mission.flavour.id == 5 then |