Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create framework for custom environments #215

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Lemonymous
Copy link
Contributor

@Lemonymous Lemonymous commented Jul 2, 2023

Changes

  • 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))

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

### Changes
- 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)
Lemonymous added a commit to Lemonymous/ITB-MinimalisticExampleMods that referenced this pull request Jul 2, 2023
This mod now requires mod loader PR 215. itb-community/ITB-ModLoader#215

There were some bugs that, in order to fix them, would require overriding the mod loader's altered Mission.ApplyEnvironmentEffect. This library would then need to include the mod loader's event dispatch code to not ruin it. At that point, it seems to make more sense to add the custom environment features directly to the mod loader, instead of adding layers upon layers of hacks. (Mod loader upon vanilla game, and this library upon the mod loader)
@Lemonymous Lemonymous added the enhancement New feature or request label Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant