Skip to content

Commit

Permalink
Factorio: add Atomic Cliff Remover Trap
Browse files Browse the repository at this point in the history
  • Loading branch information
Berserker66 committed Nov 29, 2024
1 parent ce210cd commit d8310de
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
7 changes: 7 additions & 0 deletions worlds/factorio/Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ class AtomicRocketTrapCount(TrapCount):
display_name = "Atomic Rocket Traps"


class AtomicCliffRemoverTrapCount(TrapCount):
"""Trap items that when received trigger an atomic rocket explosion on a random cliff.
Warning: there is no warning. The launch is instantaneous."""
display_name = "Atomic Cliff Remover Traps"


class EvolutionTrapCount(TrapCount):
"""Trap items that when received increase the enemy evolution."""
display_name = "Evolution Traps"
Expand Down Expand Up @@ -467,6 +473,7 @@ class FactorioOptions(PerGameCommonOptions):
cluster_grenade_traps: ClusterGrenadeTrapCount
artillery_traps: ArtilleryTrapCount
atomic_rocket_traps: AtomicRocketTrapCount
atomic_cliff_remover_traps: AtomicCliffRemoverTrapCount
attack_traps: AttackTrapCount
evolution_traps: EvolutionTrapCount
evolution_trap_increase: EvolutionTrapIncrease
Expand Down
5 changes: 4 additions & 1 deletion worlds/factorio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class FactorioItem(Item):
all_items["Cluster Grenade Trap"] = factorio_base_id - 5
all_items["Artillery Trap"] = factorio_base_id - 6
all_items["Atomic Rocket Trap"] = factorio_base_id - 7
all_items["Atomic Cliff Remover Trap"] = factorio_base_id - 8


class Factorio(World):
Expand Down Expand Up @@ -140,6 +141,7 @@ def create_regions(self):
self.options.grenade_traps + \
self.options.cluster_grenade_traps + \
self.options.atomic_rocket_traps + \
self.options.atomic_cliff_remover_traps + \
self.options.artillery_traps

location_pool = []
Expand Down Expand Up @@ -192,7 +194,8 @@ def sorter(loc: FactorioScienceLocation):
def create_items(self) -> None:
self.custom_technologies = self.set_custom_technologies()
self.set_custom_recipes()
traps = ("Evolution", "Attack", "Teleport", "Grenade", "Cluster Grenade", "Artillery", "Atomic Rocket")
traps = ("Evolution", "Attack", "Teleport", "Grenade", "Cluster Grenade", "Artillery", "Atomic Rocket",
"Atomic Cliff Remover")
for trap_name in traps:
self.multiworld.itempool.extend(self.create_item(f"{trap_name} Trap") for _ in
range(getattr(self.options,
Expand Down
21 changes: 16 additions & 5 deletions worlds/factorio/data/mod/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@ function random_offset_position(position, offset)
end

function fire_entity_at_players(entity_name, speed)
local entities = {}
for _, player in ipairs(game.forces["player"].players) do
current_character = player.character
if current_character ~= nil then
current_character.surface.create_entity{name=entity_name,
position=random_offset_position(current_character.position, 128),
target=current_character, speed=speed}
if player.character ~= nil then
table.insert(entities, player.character)
end
end
return fire_entity_at_entities(entity_name, entities, speed)
end

function fire_entity_at_entities(entity_name, entities, speed)
for _, current_entity in ipairs(entities) do
local target = current_entity
if target.health == nil then
target = target.position
end
current_entity.surface.create_entity{name=entity_name,
position=random_offset_position(current_entity.position, 128),
target=target, speed=speed}
end
end
7 changes: 7 additions & 0 deletions worlds/factorio/data/mod_template/control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,13 @@ end,
["Atomic Rocket Trap"] = function ()
fire_entity_at_players("atomic-rocket", 0.1)
end,
["Atomic Cliff Remover Trap"] = function ()
local cliffs = game.surfaces["nauvis"].find_entities_filtered{type = "cliff"}

if #cliffs > 0 then
fire_entity_at_entities("atomic-rocket", {cliffs[math.random(#cliffs)]}, 0.1)
end
end,
}

commands.add_command("ap-get-technology", "Grant a technology, used by the Archipelago Client.", function(call)
Expand Down

0 comments on commit d8310de

Please sign in to comment.