Preserve original function Mission.ApplyEnvironmentEffect as Mission.ApplyEnvironmentEffectVanilla
Preserve original function Mission.IsEnvironmentEffect as Mission.IsEnvironmentEffectVanilla
Add comments to describe why the mod loader overrides the environment functions
Add Mission.CustomEnv - a mission table that custom environments can be added to
Add logic to mark the board for all custom environments
Add logic to apply environment effects for all custom environments
(Custom environments will not automatically "plan" next tiles like LiveEnvironment does. This must be handled by the user)
Usage
Creating an instance of an environment:
The base environment table is called Environment.
The base attack-environment table is called Env_Attack and is derived from Environment: Env_Attack = Environment:new{}
RST's lightning environment is called Env_Lightning and is derived from Env_Attack: Env_Lightning = Env_Attack:new{}
To instance an environment: local env = Env_Lightning:new()
And add it to a mission: mission.CustomEnv["unique_env_id"] = env
Missions have a LiveEnvironment, which it handles automatically, by Starting it and Planning their tiles.
Custom environments will have to be manually started and planned.
A simple example of adding and starting a custom environment:
local mission = GetCurrentMission()
local env = Env_Lightning:new()
-- We must manually start custom environments, since we can dynamically add/remove them.
-- In general 'Start' just sets up necessary tables that is required by the environment.
env:Start()
-- Add the environment to the mission using a unique identifier, so we can find our environment later,
-- and avoid collisions with other environments added by other mods.
mission.CustomEnv["unique_env_id"] = env
-- Insert a point to 'Locations'. Many (but not all) environments use this to determine marked tiles that
-- should be affected when the environment effect is being processed.
table.insert(env.Locations, Point(0,0))
Changes
Usage
Creating an instance of an environment:
Environment
.Env_Attack
and is derived fromEnvironment
:Env_Attack = Environment:new{}
Env_Lightning
and is derived fromEnv_Attack
:Env_Lightning = Env_Attack:new{}
local env = Env_Lightning:new()
mission.CustomEnv["unique_env_id"] = env
LiveEnvironment
, which it handles automatically, byStart
ing it andPlan
ning their tiles.A simple example of adding and starting a custom environment:
Minimalistic example mod
Link to a minimalistic modded weapon that can add environment lightning tiles, using the code added by this PR: https://github.com/Lemonymous/ITB-MinimalisticExampleMods/blob/master/mods/custom_environment_weapon/scripts/env_weapon.lua