Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/BTAxis/naev
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Aug 21, 2012
2 parents 8ba68ce + 36421f1 commit 2f8ff61
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 32 deletions.
79 changes: 79 additions & 0 deletions dat/scripts/coreprofile.lua
@@ -0,0 +1,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 C-2 Light Plating", engine = "Unicorp KRD-B12 Engine", system = "Unicorp PT-200 Core System"},
medium = {hull = "Unicorp D-8 Medium Plating", engine = "Unicorp KRD-G15 Engine", system = "Unicorp PT-600 Core System"},
large = {hull = "Unicorp C-16 Heavy Plating", engine = "Unicorp KRD-T20 Engine", system = "Unicorp PT-1200 Core System"}
},
medium =
{
small = {hull = "Schafer & Kane Light Combat Plating", engine = "Tricon Naga Mk3 Engine", system = "Milspec Orion 2301 Core System"},
medium = {hull = "Schafer & Kane Medium Combat Plating Alpha", engine = "Tricon Centaur Mk2 Engine", system = "Milspec Orion 3701 Core System"},
large = {hull = "Schafer & Kane Heavy Combat Plating Alpha", engine = "Tricon Harpy Mk1 Engine", system = "Milspec Gemini 3308 Core System"}
},
high =
{
small = {hull = "Schafer & Kane Light Combat Plating", engine = "Tricon Naga Mk9 Engine", system = "Milspec Orion 5501 Core System"},
medium = {hull = "Schafer & Kane Medium Combat Plating Gamma", engine = "Tricon Centaur Mk7 Engine", system = "Milspec Orion 5501 Core System"},
large = {hull = "Schafer & Kane Heavy Combat Plating Gamma", engine = "Tricon Harpy Mk11 Engine", system = "Milspec Orion 9901 Core System"}
},
low_trader =
{
small = {hull = "Unicorp Small Cargo Hull", engine = "Unicorp JNS-44K Engine", system = "Unicorp PT-200 Core System"},
medium = {hull = "Unicorp Medium Cargo Hull", engine = "Unicorp JNS-54K Engine", system = "Unicorp PT-600 Core System"},
large = {hull = "Unicorp Large Cargo Hull", engine = "Unicorp JNS-99K Engine", system = "Unicorp PT-1200 Core System"}
},
high_trader =
{
small = {hull = "Schafer & Kane Small Cargo Hull", engine = "Tricon Oxen Engine", system = "Milspec Orion 2302 Core System"},
medium = {hull = "Schafer & Kane Medium Cargo Hull", engine = "Tricon Buffalo Engine", system = "Milspec Orion 3702 Core System"},
large = {hull = "Schafer & Kane Large Cargo Hull", engine = "Tricon Mammoth Engine", system = "Milspec Orion 4802 Core System"}
},
}

-- Before doing anything drastic, make sure the profile passed is valid.
if profiles[profile] == nil then
warn("(pilot.coreProfile) Warning: " .. profile .. " is not a valid 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("(pilot.coreProfile) Warning: failed to equip " .. ctype .. " core on pilot " .. p:name() .. ".")
end
end
end
60 changes: 30 additions & 30 deletions dat/tech.xml
Expand Up @@ -684,10 +684,10 @@
</tech>
<tech name="Systems Low">
<item>Previous Generation Small Systems</item>
<item>Basic Small Systems</item>
<item>Previous Generation Medium Systems</item>
<item>Basic Medium Systems</item>
<item>Previous Generation Large Systems</item>
<item>Basic Small Systems</item>
<item>Basic Medium Systems</item>
<item>Basic Large Systems</item>
<item>Unicorp PT-100 Core System</item>
<item>Unicorp PT-200 Core System</item>
Expand All @@ -698,47 +698,47 @@
</tech>
<tech name="Systems Medium">
<item>Unicorp RX-14 Core System</item>
<item>Unicorp JX-16 Core System</item>
<item>Unicorp EX-19 Core System</item>
<item>Unicorp RX-26 Core System</item>
<item>Unicorp JX-30 Core System</item>
<item>Unicorp EX-24 Core System</item>
<item>Unicorp RX-71 Core System</item>
<item>Unicorp JX-16 Core System</item>
<item>Unicorp JX-30 Core System</item>
<item>Unicorp JX-66 Core System</item>
<item>Unicorp EX-19 Core System</item>
<item>Unicorp EX-24 Core System</item>
<item>Unicorp EX-80 Core System</item>
</tech>
<tech name="Systems High">
<item>Milspec Orion 2301 Core System</item>
<item>Milspec Orion 2302 Core System</item>
<item>Milspec Gemini 2501 Core System</item>
<item>Milspec Taurus 2520 Core System</item>
<item>Milspec Vespa 2544 Core System</item>
<item>Milspec Orion 3701 Core System</item>
<item>Milspec Orion 3702 Core System</item>
<item>Milspec Orion 4801 Core System</item>
<item>Milspec Orion 4802 Core System</item>
<item>Milspec Gemini 2501 Core System</item>
<item>Milspec Gemini 3308 Core System</item>
<item>Milspec Taurus 2520 Core System</item>
<item>Milspec Taurus 3323 Core System</item>
<item>Milspec Vespa 2544 Core System</item>
<item>Milspec Vespa 3380 Core System</item>
</tech>
<tech name="Systems Elite">
<item>Milspec Orion 5501 Core System</item>
<item>Milspec Orion 5502 Core System</item>
<item>Milspec Orion 8801 Core System</item>
<item>Milspec Orion 8802 Core System</item>
<item>Milspec Gemini 5050 Core System</item>
<item>Milspec Taurus 4909 Core System</item>
<item>Milspec Vespa 6114 Core System</item>
<item>Milspec Orion 9901 Core System</item>
<item>Milspec Orion 9902 Core System</item>
<item>Milspec Orion 9903 Core System</item>
<item>Milspec Gemini 5050 Core System</item>
<item>Milspec Taurus 4909 Core System</item>
<item>Milspec Vespa 6114 Core System</item>
</tech>
<tech name="Engines Low">
<item>Beat Up Small Engine</item>
<item>Manufacturer Small Engine</item>
<item>Beat Up Medium Engine</item>
<item>Manufacturer Medium Engine</item>
<item>Beat Up Large Engine</item>
<item>Manufacturer Small Engine</item>
<item>Manufacturer Medium Engine</item>
<item>Manufacturer Large Engine</item>
<item>Unicorp KRD-B10 Engine</item>
<item>Unicorp KRD-B12 Engine</item>
Expand All @@ -749,30 +749,30 @@
</tech>
<tech name="Engines Medium">
<item>Unicorp EXA-49F Engine</item>
<item>Unicorp AUR-50A Engine</item>
<item>Unicorp JNS-44K Engine</item>
<item>Unicorp EXA-66F Engine</item>
<item>Unicorp AUR-70A Engine</item>
<item>Unicorp JNS-54K Engine</item>
<item>Unicorp EXA-71F Engine</item>
<item>Unicorp AUR-50A Engine</item>
<item>Unicorp AUR-70A Engine</item>
<item>Unicorp AUR-79A Engine</item>
<item>Unicorp JNS-44K Engine</item>
<item>Unicorp JNS-54K Engine</item>
<item>Unicorp JNS-99K Engine</item>
</tech>
<tech name="Engines High">
<item>Tricon Naga Mk3 Engine</item>
<item>Tricon Naga Mk5 Engine</item>
<item>Tricon Crane Engine</item>
<item>Tricon Albatross Engine</item>
<item>Tricon Oxen Engine</item>
<item>Tricon Centaur Mk2 Engine</item>
<item>Tricon Centaur Mk3 Engine</item>
<item>Tricon Kolibri Engine</item>
<item>Tricon Antelope Engine</item>
<item>Tricon Buffalo Engine</item>
<item>Tricon Harpy Mk1 Engine</item>
<item>Tricon Harpy Mk6 Engine</item>
<item>Tricon Crane Engine</item>
<item>Tricon Kolibri Engine</item>
<item>Tricon Raven Engine</item>
<item>Tricon Albatross Engine</item>
<item>Tricon Antelope Engine</item>
<item>Tricon Kraken Engine</item>
<item>Tricon Oxen Engine</item>
<item>Tricon Buffalo Engine</item>
<item>Tricon Mammoth Engine</item>
</tech>
<tech name="Engines Elite">
Expand All @@ -786,10 +786,10 @@
</tech>
<tech name="Hulls Low">
<item>Patchwork Light Plating</item>
<item>Unmodified Small Hull</item>
<item>Patchwork Medium Plating</item>
<item>Unmodified Medium Hull</item>
<item>Patchwork Heavy Plating</item>
<item>Unmodified Small Hull</item>
<item>Unmodified Medium Hull</item>
<item>Unmodified Large Hull</item>
<item>Unicorp D-2 Light Plating</item>
<item>Unicorp C-2 Light Plating</item>
Expand All @@ -799,21 +799,21 @@
</tech>
<tech name="Hulls Medium">
<item>Unicorp B-2 Light Plating</item>
<item>Unicorp Small Cargo Hull</item>
<item>Unicorp C-8 Medium Plating</item>
<item>Unicorp Medium Cargo Hull</item>
<item>Unicorp B-16 Heavy Plating</item>
<item>Unicorp Small Cargo Hull</item>
<item>Unicorp Medium Cargo Hull</item>
<item>Unicorp Large Cargo Hull</item>
</tech>
<tech name="Hulls High">
<item>Schafer &amp; Kane Light Combat Plating</item>
<item>Schafer &amp; Kane Small Cargo Hull</item>
<item>Schafer &amp; Kane Medium Combat Plating Alpha</item>
<item>Schafer &amp; Kane Medium Combat Plating Beta</item>
<item>Schafer &amp; Kane Medium Cargo Hull</item>
<item>Schafer &amp; Kane Medium Stealth Plating</item>
<item>Schafer &amp; Kane Heavy Combat Plating Alpha</item>
<item>Schafer &amp; Kane Heavy Combat Plating Beta</item>
<item>Schafer &amp; Kane Small Cargo Hull</item>
<item>Schafer &amp; Kane Medium Cargo Hull</item>
<item>Schafer &amp; Kane Large Cargo Hull</item>
</tech>
<tech name="Hulls Elite">
Expand Down
19 changes: 19 additions & 0 deletions src/console.c
Expand Up @@ -70,9 +70,11 @@ static int cli_firstline = 1; /**< Is this the first line? */
*/
static int cli_script( lua_State *L );
static int cli_printOnly( lua_State *L );
static int cli_warn( lua_State *L );
static const luaL_Reg cli_methods[] = {
{ "print", cli_printOnly },
{ "script", cli_script },
{ "warn", cli_warn },
{NULL, NULL}
}; /**< Console only functions. */

Expand Down Expand Up @@ -129,6 +131,23 @@ static int cli_printCore( lua_State *L, int cli_only )
}


/**
* @brief Barebones warn implementation for Lua, allowing scripts to print warnings to stderr.
*
* @luafunc warn()
*/
static int cli_warn( lua_State *L )
{
const char *msg;

msg = luaL_checkstring(L,1);
fprintf(stderr, "%s\n", msg);
LOG("\er%s\e0", msg);

return 0;
}


/**
* @brief Replacement for the internal Lua print to print to both the console and the terminal.
*/
Expand Down
16 changes: 14 additions & 2 deletions src/nlua_pilot.c
Expand Up @@ -2490,9 +2490,11 @@ static int pilotL_addOutfit( lua_State *L )
/**
* @brief Removes an outfit from a pilot.
*
* "all" will remove all outfits.
* "all" will remove all outfits except cores.
* "cores" will remove all cores, but nothing else.
*
* @usage p:rmOutfit( "all" ) -- Leaves the pilot naked (except for cores).
* @usage p:rmOutfit( "cores" ) -- Strips the pilot of its cores, leaving it dead in space.
* @usage p:rmOutfit( "Neutron Disruptor" ) -- Removes a neutron disruptor.
* @usage p:rmOutfit( "Neutron Disruptor", 2 ) -- Removes two neutron disruptor.
*
Expand All @@ -2518,7 +2520,7 @@ static int pilotL_rmOutfit( lua_State *L )
if (lua_gettop(L) > 2)
q = luaL_checkint(L,3);

/* If outfit is "all", we remove everything. */
/* If outfit is "all", we remove everything except cores. */
if (strcmp(outfit,"all")==0) {
for (i=0; i<p->noutfits; i++) {
if (p->outfits[i]->sslot->required)
Expand All @@ -2528,6 +2530,16 @@ static int pilotL_rmOutfit( lua_State *L )
}
pilot_calcStats( p ); /* Recalculate stats. */
}
/* If outfit is "cores", we remove cores only. */
else if (strcmp(outfit,"cores")==0) {
for (i=0; i<p->noutfits; i++) {
if (!p->outfits[i]->sslot->required)
continue;
pilot_rmOutfitRaw( p, p->outfits[i] );
removed++;
}
pilot_calcStats( p ); /* Recalculate stats. */
}
else {
/* Get the outfit. */
o = outfit_get( outfit );
Expand Down

0 comments on commit 2f8ff61

Please sign in to comment.