Skip to content

Commit

Permalink
Workaround to add corp missions to easyEdit islands
Browse files Browse the repository at this point in the history
corpMissions lib is kept but no longer used, and the custom corpIslandMissions is used instead to allow missions to be added based on what island easyEdit has put in a given slot (if easyEdit enabled). Mod now requires easyEdit to ensure that easyEdit is loaded first, so island mission lists get built before I inject mine.
  • Loading branch information
tos-x committed Apr 13, 2023
1 parent 5e0c965 commit 71c1430
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 31 deletions.
172 changes: 172 additions & 0 deletions mods/other/mods/IslandMissions/scripts/corpIslandMissions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@

----------------------------------------------------------------------------------------
-- Corp Missions v1.0* - code library
--
-- Edited by tosx into Corp Island Missions
-- Includes logic to compare with easyEdit corp names
-- Your mod must include the following in its init, so easyEdit will load first:
-- requirements = { "easyEdit" },
--
-- Vanilla easyEdit corp names that are used as input argument:
-- archive
-- rst
-- pinnacle
-- detritus
-- ...or custom easyEdit corporation name
-- True vanilla corp names that also still function as inputs (no easyEdit equivalent):
-- Corp_Grass
-- Corp_Desert
-- Corp_Snow
-- Corp_Factory
----------------------------------------------------------------------------------------
-- small library intended to provide functions to add/remove mission to corporations.
-- required to make mission mods compatible with island replacement mods.
--
-- NOTE that islands do not get swapped until after init, so if you want to add
-- a mission to a custom corporation on an island, you need to do so at load.
--
----------------------------------------------------------------------------------------


-- Usage:
----------------------------------------------------------------------------------------
-- place the following at the top of any lua file that wants to use the library.
--
-- local path = mod_loader.mods[modApi.currentMod].scriptPath
-- local corpMissions = require(path .."corpMissions")
--
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------


-- Signature of all addition functions:
----------------------------------------------------------------------------------------
-- corpMissions.Add_Missions_High(mission, corp, force)
----------------------------------------------------------------------------------------
-- adds a mission to a corporation.
-- if corp is nil, the mission will be added to all default corps.
--
-- arg - type - description
-- ------ ----------- ------------------------------------------------------------
-- mission - string - mission we want to add.
-- corp - string - corporation we want to add the mission to.
-- force - boolean - if we should allow duplicate additions of mission. (optional)
----------------------------------------------------------------------------------------

-- Signature of all removal functions:
----------------------------------------------------------------------------------------
-- corpMissions.Rem_Missions_High(mission, corp, once)
----------------------------------------------------------------------------------------
-- removes a mission from a corporation.
-- if corp is nil, the mission will be removed from all default corps.
--
-- arg - type - description
-- ------ ----------- ------------------------------------------------------------
-- mission - string - mission we want to remove.
-- corp - string - corporation we want to remove the mission from.
-- once - number - if true, it will only attempt to remove the mission once. (optional)
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------


-- Examples:
----------------------------------------------------------------------------------------
-- corpMissions.Add_Missions_High("Mission_Survive", "Corp_Grass")
-- corpMissions.Add_Missions_Low("Mission_Survive", "Corp_Grass")
-- corpMissions.Add_Bosses("Mission_BotBoss", "Corp_Grass")
-- corpMissions.Add_UniqueBosses("Mission_BotBoss", "Corp_Grass")
-- corpMissions.Rem_Missions_High("Mission_Survive", "Corp_Grass")
-- corpMissions.Rem_Missions_Low("Mission_Survive", "Corp_Grass")
-- corpMissions.Rem_Bosses("Mission_BotBoss", "Corp_Grass")
-- corpMissions.Rem_UniqueBosses("Mission_BotBoss", "Corp_Grass")
--
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------

local this = {}

local corps = {
"Corp_Grass",
"Corp_Desert",
"Corp_Snow",
"Corp_Factory"
}

local corpsEasyEdit = {
"archive",
"rst",
"pinnacle",
"detritus",
}

-- set id for default corporations.
for i, v in ipairs(corps) do
_G[v].id = _G[v].id or v
end

_G["Corp_Default"].id = "Corp_Default"

local function Add(tbl)
this['Add_'.. tbl] = function(mission, corp, force)
-- Adjust our corp to match easyEdit if necessary
if easyEdit and easyEdit.world then
for i = 1, 4 do
if easyEdit.world[i].corporation == corp then
-- This is the island where easyEdit has our corp
corp = corps[i]
break
end
end
else
-- No easyEdit, so convert from easyEdit corp name to vanilla corp name
for i = 1, 4 do
if corp == corpsEasyEdit[i] or corp == corps[i] then
corp = corps[i]
break
end
end
end

for _, v in ipairs(corps) do
if corp == _G[v].id or (not corp and list_contains(corps, _G[v].id)) then
if force or not list_contains(_G[v][tbl], mission) then
table.insert(_G[v][tbl], mission)
end
end
end
end

this['Rem_'.. tbl] = function(mission, corp, once)
-- Adjust our corp to match easyEdit if necessary
if easyEdit and easyEdit.world then
for i = 1, 4 do
if easyEdit.world[i].corporation == corp then
-- This is the island where easyEdit has our corp
corp = corps[i]
end
end
else
-- No easyEdit, so convert from easyEdit corp name to vanilla corp name
for i = 1, 4 do
if corp == corpsEasyEdit[i] then
corp = corps[i]
end
end
end

for _, v in ipairs(corps) do
if not corp or corp == _G[v].id then
while list_contains(_G[v][tbl], mission) do
remove_element(mission, _G[v][tbl])
end
end
end
end
end

Add("Missions_High")
Add("Missions_Low")
Add("Bosses")
Add("UniqueBosses")

return this
11 changes: 10 additions & 1 deletion mods/other/mods/IslandMissions/scripts/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ local mod = {
version = "0.19",
modApiVersion = "2.8.0",
icon = "img/icons/mod_icon.png",
dependencies = { modApiExt = "1.2" },
requirements = { "easyEdit" },--Force to load first
dependencies = {
modApiExt = "1.2",
-- easyEdit = "2.0.4",
},
}

function mod:init()
Expand All @@ -16,6 +20,11 @@ function mod:init()
self.missions = require(scriptPath .."missions/init")
self.missions:init(self)

-- Add icons for easyEdit
modApi:appendAssets("img/strategy/mission/", "img/missions/", "")
modApi:appendAssets("img/strategy/mission/small/", "img/missions/small/", "")
--require(scriptPath .."missionList")

end

function mod:load(options, version)
Expand Down
6 changes: 4 additions & 2 deletions mods/other/mods/IslandMissions/scripts/missions/cannon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

local path = mod_loader.mods[modApi.currentMod].scriptPath
local this = {id = "Mission_tosx_Cannon"}
local corpMissions = require(path .."corpMissions")
--local corpMissions = require(path .."corpMissions")
local corpIslandMissions = require(path .."corpIslandMissions")

Mission_tosx_Cannon = Mission_Infinite:new{
Name = "Broken Cannon",
Expand Down Expand Up @@ -133,7 +134,8 @@ function this:init(mod)
end

function this:load(mod, options, version)
corpMissions.Add_Missions_High("Mission_tosx_Cannon", "Corp_Grass")
--corpMissions.Add_Missions_High("Mission_tosx_Cannon", "Corp_Grass")
corpIslandMissions.Add_Missions_High("Mission_tosx_Cannon", "archive")
end

return this
38 changes: 31 additions & 7 deletions mods/other/mods/IslandMissions/scripts/missions/disease.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

local path = mod_loader.mods[modApi.currentMod].scriptPath
local this = {id = "Mission_tosx_Disease"}
local corpMissions = require(path .."corpMissions")
--local corpMissions = require(path .."corpMissions")
local corpIslandMissions = require(path .."corpIslandMissions")


Mission_tosx_Disease = Mission_Infinite:new{
Expand Down Expand Up @@ -164,23 +165,46 @@ function this:init(mod)
end

function this:load(mod, options, version)
-- Add to all 4 default corps
corpMissions.Add_Missions_High("Mission_tosx_Disease")
-- Allowable corps:
local corps = {
"archive",
"rst",
"pinnacle",
"detritus",
"Watchtower",
}

-- Add to all 4 default corp slots
corpIslandMissions.Add_Missions_High("Mission_tosx_Disease")

-- Random number 0-3 (Corp_Grass, Corp_Desert, Corp_Snow, Corp_Factory)
modApi:addPostStartGameHook(function()
if GAME and not GAME.tosx_risle2 then
GAME.tosx_risle2 = math.random(4) - 1
--LOG("random island: "..GAME.tosx_risle2)
--LOG("random island2: "..GAME.tosx_risle2)
end
end)

-- Randomly remove the mission from 3 of the islands each run
-- Note that this code handles removing mission from modded corps, but not adding it
-- Randomly remove the mission from 3 of the slots each run
modApi:addPreIslandSelectionHook(function(corporation, island)
if GAME.tosx_risle2 and GAME.tosx_risle2 ~= island then
corpMissions.Rem_Missions_High("Mission_tosx_Disease", corporation)
corpIslandMissions.Rem_Missions_High("Mission_tosx_Disease", corporation)
elseif easyEdit and easyEdit.world then
-- Now also remove it from all but allowed corps
local disallow = true
for i = 1, #corps do
if easyEdit.world[island + 1].corporation == corps[i] then
-- This slot is set to something compatible
disallow = false
break
end
end
if disallow then
-- This slot doesn't contain anything compatible
corpIslandMissions.Rem_Missions_High("Mission_tosx_Disease", corporation)
end
end

end)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

local path = mod_loader.mods[modApi.currentMod].scriptPath
local this = {id = "Mission_tosx_Earthquake"}
local corpMissions = require(path .."corpMissions")
--local corpMissions = require(path .."corpMissions")
local corpIslandMissions = require(path .."corpIslandMissions")

Mission_tosx_Earthquake = Mission_Infinite:new{
Name = "Earthquake",
Expand Down Expand Up @@ -109,7 +110,8 @@ function this:init(mod)
end

function this:load(mod, options, version)
corpMissions.Add_Missions_High("Mission_tosx_Earthquake", "Corp_Desert")
--corpMissions.Add_Missions_High("Mission_tosx_Earthquake", "Corp_Desert")
corpIslandMissions.Add_Missions_High("Mission_tosx_Earthquake", "rst")
end

return this
6 changes: 4 additions & 2 deletions mods/other/mods/IslandMissions/scripts/missions/healrain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

local path = mod_loader.mods[modApi.currentMod].scriptPath
local this = {id = "Mission_tosx_Healrain"}
local corpMissions = require(path .."corpMissions")
--local corpMissions = require(path .."corpMissions")
local corpIslandMissions = require(path .."corpIslandMissions")

Mission_tosx_Healrain = Mission_Infinite:new{
Name = "Healing Rain",
Expand Down Expand Up @@ -98,7 +99,8 @@ function this:init(mod)
end

function this:load(mod, options, version)
corpMissions.Add_Missions_High("Mission_tosx_Healrain", "Corp_Factory")
-- corpMissions.Add_Missions_High("Mission_tosx_Healrain", "Corp_Factory")
corpIslandMissions.Add_Missions_High("Mission_tosx_Healrain", "detritus")
end

return this
16 changes: 14 additions & 2 deletions mods/other/mods/IslandMissions/scripts/missions/juggernaut.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

local path = mod_loader.mods[modApi.currentMod].scriptPath
local this = {id = "Mission_tosx_Juggernaut"}
local corpMissions = require(path .."corpMissions")
--local corpMissions = require(path .."corpMissions")
local corpIslandMissions = require(path .."corpIslandMissions")

-- returns number of pawns alive
-- in a list of pawn id's.
Expand Down Expand Up @@ -80,6 +81,16 @@ function Mission_tosx_Juggernaut:GetCompletedObjectives()
return ret
end

function Mission_tosx_Juggernaut:GetCompletedStatus()
if countAlive(self.Criticals) > 0 and countAlive(self.Criticals2) == 0 then
return "Success"
elseif countAlive(self.Criticals) == 0 and countAlive(self.Criticals2) > 0 then
return "Failure"
else
return "Partial"
end
end

tosx_mission_IceHulk = Pawn:new{
Name = "Frozen Hulk",
Health = 4,
Expand Down Expand Up @@ -243,7 +254,8 @@ function this:init(mod)
end

function this:load(mod, options, version)
corpMissions.Add_Missions_High("Mission_tosx_Juggernaut", "Corp_Snow")
-- corpMissions.Add_Missions_High("Mission_tosx_Juggernaut", "Corp_Snow")
corpIslandMissions.Add_Missions_High("Mission_tosx_Juggernaut", "pinnacle")
end

return this
6 changes: 4 additions & 2 deletions mods/other/mods/IslandMissions/scripts/missions/locusts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

local path = mod_loader.mods[modApi.currentMod].scriptPath
local this = {id = "Mission_tosx_Locusts"}
local corpMissions = require(path .."corpMissions")
--local corpMissions = require(path .."corpMissions")
local corpIslandMissions = require(path .."corpIslandMissions")

Mission_tosx_Locusts = Mission_Infinite:new{
Name = "Nanoswarm",
Expand Down Expand Up @@ -245,7 +246,8 @@ function this:init(mod)
end

function this:load(mod, options, version)
corpMissions.Add_Missions_High("Mission_tosx_Locusts", "Corp_Snow")
-- corpMissions.Add_Missions_High("Mission_tosx_Locusts", "Corp_Snow")
corpIslandMissions.Add_Missions_High("Mission_tosx_Locusts", "pinnacle")
end

return this
Loading

0 comments on commit 71c1430

Please sign in to comment.