File: coreprofile.lua

package info (click to toggle)
naev 0.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 386,084 kB
  • sloc: ansic: 93,149; xml: 87,292; python: 2,347; sh: 904; makefile: 654; lisp: 162; awk: 4
file content (79 lines) | stat: -rw-r--r-- 4,529 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
-- Helper script to quickly equip a ship with a core profile, for mission purposes.
-- Takes a pilot and a profile name, and re-specs that pilot according to the profile.
-- 
-- Example usage: p:coreProfile("medium")
function pilot.coreProfile(p, profile)
   -- Table of profiles indexed by profile name.
   -- Each profile contains core outfits for all sizes. The script will use the largest possible.
   local profiles =  {
                  low = 
                        {
                           small = {hull = "Unicorp D-4 Light Plating", engine = "Unicorp Hawk 300 Engine", system = "Unicorp PT-200 Core System"},
                           medium = {hull = "Unicorp D-8 Medium Plating",  engine = "Unicorp Falcon 1200 Engine", system = "Unicorp PT-600 Core System"},
                           large = {hull = "Unicorp D-20 Heavy Plating",  engine = "Unicorp Eagle 6500 Engine", system = "Unicorp PT-1000 Core System"}
                        },
                  medium = 
                        {
                           small = {hull = "S&K Light Combat Plating",  engine = "Nexus Dart 300 Engine", system = "Milspec Orion 2301 Core System"},
                           medium = {hull = "S&K Medium Combat Plating",  engine = "Nexus Arrow 550 Engine", system = "Milspec Orion 3701 Core System"},
                           large = {hull = "S&K Heavy Combat Plating",  engine = "Nexus Bolt 4500 Engine", system = "Milspec Hermes 5402 Core System"}
                        },
                  high = 
                        {
                           small = {hull = "S&K Light Combat Plating",  engine = "Tricon Zephyr Engine", system = "Milspec Orion 5501 Core System"},
                           medium = {hull = "S&K Medium-Heavy Combat Plating",  engine = "Tricon Cyclone Engine", system = "Milspec Orion 5501 Core System"},
                           large = {hull = "S&K Superheavy Combat Plating",  engine = "Tricon Typhoon Engine", system = "Milspec Orion 9901 Core System"}
                        },
                  low_trader = 
                        {
                           small = {hull = "S&K Small Cargo Hull",  engine = "Melendez Ox Engine", system = "Unicorp PT-200 Core System"},
                           medium = {hull = "S&K Medium Cargo Hull",  engine = "Melendez Buffalo Engine", system = "Unicorp PT-600 Core System"},
                           large = {hull = "S&K Large Cargo Hull",  engine = "Melendez Mammoth Engine", system = "Unicorp PT-1000 Core System"}
                        },
                  high_trader = 
                        {
                           small = {hull = "S&K Small Cargo Hull",  engine = "Melendez Ox XL Engine", system = "Milspec Orion 2301 Core System"},
                           medium = {hull = "S&K Medium Cargo Hull",  engine = "Melendez Buffalo XL Engine", system = "Milspec Orion 3701 Core System"},
                           large = {hull = "S&K Large Cargo Hull",  engine = "Melendez Mammoth XL Engine", system = "Milspec Orion 4801 Core System"}
                        },
               }
   
   -- Before doing anything drastic, make sure the profile passed is valid.
   if profiles[profile] == nil then
      warn( string.format( _("pilot.coreProfile: %s is not a valid profile"), profile ) )
      return
   end
   
   profile = profiles[profile]
   
   -- Strip the cores, but leave all other equipment intact.
   p:rmOutfit("cores")
   
   local sizes = {"large", "medium", "small"}
   local ctypes = {"hull", "engine", "system"}

   -- For checking whether all cores were properly populated.
   local equipped = {}
   for _, ctype in ipairs(ctypes) do
      equipped[ctype] = 0
   end
   
   -- Attempt to fit the cores in the selected profile onto the ship.
   -- Start with the large slots and work down to the small ones.
   for _, size in ipairs(sizes) do
      for _, ctype in ipairs(ctypes) do
      local success = 0
         repeat -- This is in a repeat..until loop, because it's possible for the ship to have multiple core slots of the same type.
            success = p:addOutfit(profile[size][ctype])
            equipped[ctype] = equipped[ctype] + success
         until success == 0
      end
   end
   
   -- Now we must make sure all core types got at least one core outfit, and if not, warn.
   for _, ctype in ipairs(ctypes) do
      if equipped[ctype] == 0 then
         warn( string.format(_("pilot.coreProfile: failed to equip %s core on pilot %s."), ctype, p:name() ) )
      end
   end
end