Skip to content
Snippets Groups Projects
Commit 6c415120 authored by DarkGod's avatar DarkGod
Browse files

Generic triggers mechanisms added to let statci maps do funky stuff

parent fa9eaaf8
No related branches found
No related tags found
No related merge requests found
......@@ -430,7 +430,7 @@ function _M:makeEntityByName(level, type, name, force_unique)
if _G.type(type) == "table" then e = type[name] type = type.__real_type or type
elseif type == "actor" then e = self.npc_list[name]
elseif type == "object" then e = self.object_list[name]
elseif type == "grid" or type == "terrain" then e = self.grid_list[name]
elseif type == "grid" or type == "terrain" or type == "trigger" then e = self.grid_list[name]
elseif type == "trap" then e = self.trap_list[name]
end
if not e then return nil end
......@@ -716,6 +716,8 @@ function _M:addEntity(level, e, typ, x, y, no_added)
if not no_added then e:added() end
elseif typ == "terrain" or typ == "grid" then
if x and y then level.map(x, y, Map.TERRAIN, e) end
elseif typ == "trigger" then
if x and y then level.map(x, y, Map.TRIGGER, e) end
end
e:check("addedToLevel", level, x, y)
e:check("on_added", level, x, y)
......
......@@ -491,16 +491,28 @@ function _M:generate(lev, old_lev)
actor = self.tiles[c] and self.tiles[c].actor
trap = self.tiles[c] and self.tiles[c].trap
object = self.tiles[c] and self.tiles[c].object
trigger = self.tiles[c] and self.tiles[c].trigger
status = self.tiles[c] and self.tiles[c].status
define_spot = self.tiles[c] and self.tiles[c].define_spot
else
actor = c.actor and self.tiles[c.actor]
trap = c.trap and self.tiles[c.trap]
object = c.object and self.tiles[c.object]
trigger = c.trigger and self.tiles[c.trigger]
status = c.status and self.tiles[c.status]
define_spot = c.define_spot and self.tiles[c.define_spot]
end
if trigger then
local t, mod
if type(trigger) == "string" then t = self.zone:makeEntityByName(self.level, "trigger", trigger)
elseif type(trigger) == "table" and trigger.random_filter then mod = trigger.entity_mod t = self.zone:makeEntity(self.level, "terrain", trigger.random_filter, nil, true)
else t = self.zone:finishEntity(self.level, "terrain", trigger)
end
if t then if mod then t = mod(t) end self:roomMapAddEntity(i-1, j-1, "trigger", t) end
end
if object then
local o, mod
if type(object) == "string" then o = self.zone:makeEntityByName(self.level, "object", object)
......
......@@ -423,3 +423,45 @@ function _M:mergeSubEntities(...)
end end
return tbl
end
--- Push a lever
function _M:leverActivated(x, y, who)
if self.lever_dead then return end
self.lever = not self.lever
local spot = game.level.map.attrs(x, y, "lever_spot") or nil
local block = game.level.map.attrs(x, y, "lever_block") or nil
local radius = game.level.map.attrs(x, y, "lever_radius") or 10
local val = game.level.map.attrs(x, y, "lever")
local kind = game.level.map.attrs(x, y, "lever_kind")
if game.level.map.attrs(x, y, "lever_only_once") then self.lever_dead = true end
if type(kind) == "string" then kind = {[kind]=true} end
game.log("#VIOLET#You hear a mechanism clicking.")
local apply = function(i, j)
local akind = game.level.map.attrs(i, j, "lever_action_kind")
if not akind then return end
if type(akind) == "string" then akind = {[akind]=true} end
for k, _ in pairs(kind) do if akind[k] then
local old = game.level.map.attrs(i, j, "lever_action_value") or 0
local newval = old + (self.lever and val or -val)
game.level.map.attrs(i, j, "lever_action_value", newval)
if game.level.map:checkEntity(i, j, engine.Map.TERRAIN, "on_lever_change", e, newval, old) then
if game.level.map.attrs(i, j, "lever_action_only_once") then game.level.map.attrs(i, j, "lever_action_kind", false) end
end
local fct = game.level.map.attrs(i, j, "lever_action_custom")
if fct and fct(i, j, e, newval, old) then
if game.level.map.attrs(i, j, "lever_action_only_once") then game.level.map.attrs(i, j, "lever_action_kind", false) end
end
end end
end
if spot then
local spot = game.level:pickSpot(spot)
if spot then apply(spot.x, spot.y) end
else
core.fov.calc_circle(x, y, game.level.map.w, game.level.map.h, radius, function(_, i, j)
if block and game.level.map.attrs(i, j, block) then return true end
end, function(_, i, j) apply(i, j) end, nil)
end
end
\ No newline at end of file
......@@ -380,7 +380,7 @@ newEntity{
end
end,
}
newEntity{ base = "GENERIC_LEVER_DOOR", define_as = "GENERIC_LEVER_DOOR_HORIZ", image = "terrain/granite_door1.png", add_displays = {class.new{image="terrain/granite_wall3.png", z=18, display_y=-1, add_mos={{image="terrain/padlock2.png", display_y=0.1}}}}, door_opened = "GENERIC_LEVER_GENERIC_LEVER_DOOR_HORIZ_OPEN"}
newEntity{ base = "GENERIC_LEVER_DOOR", define_as = "GENERIC_LEVER_DOOR_HORIZ", image = "terrain/granite_door1.png", add_displays = {class.new{image="terrain/granite_wall3.png", z=18, display_y=-1, add_mos={{image="terrain/padlock2.png", display_y=0.1}}}}, door_opened = "GENERIC_LEVER_DOOR_HORIZ_OPEN"}
newEntity{ base = "GENERIC_LEVER_DOOR", define_as = "GENERIC_LEVER_DOOR_VERT", image = "terrain/marble_floor.png", add_displays = {class.new{image="terrain/granite_door1_vert.png", z=17, add_mos={{image="terrain/padlock2.png", display_x=0.2, display_y=-0.4}}}, class.new{image="terrain/granite_door1_vert_north.png", z=18, display_y=-1}}, door_opened = "GENERIC_LEVER_DOOR_OPEN_VERT"}
newEntity{
......@@ -417,12 +417,6 @@ newEntity{
force_clone = true,
block_move = function(self, x, y, e, act)
if act and e.player then
local spot = game.level.map.attrs(x, y, "lever_spot") or nil
local block = game.level.map.attrs(x, y, "lever_block") or nil
local radius = game.level.map.attrs(x, y, "lever_radius") or 10
local val = game.level.map.attrs(x, y, "lever")
local kind = game.level.map.attrs(x, y, "lever_kind")
if type(kind) == "string" then kind = {[kind]=true} end
if self.lever then
self.color_r = colors.UMBER.r self.color_g = colors.UMBER.g self.color_b = colors.UMBER.b
self.add_mos[1].image = "terrain/lever1_state1.png"
......@@ -432,36 +426,18 @@ newEntity{
end
self:removeAllMOs()
game.level.map:updateMap(x, y)
self.lever = not self.lever
game.log("#VIOLET#You hear a mechanism clicking.")
local apply = function(i, j)
local akind = game.level.map.attrs(i, j, "lever_action_kind")
if not akind then return end
if type(akind) == "string" then akind = {[akind]=true} end
for k, _ in pairs(kind) do if akind[k] then
local old = game.level.map.attrs(i, j, "lever_action_value") or 0
local newval = old + (self.lever and val or -val)
game.level.map.attrs(i, j, "lever_action_value", newval)
if game.level.map:checkEntity(i, j, engine.Map.TERRAIN, "on_lever_change", e, newval, old) then
if game.level.map.attrs(i, j, "lever_action_only_once") then game.level.map.attrs(i, j, "lever_action_kind", false) end
end
local fct = game.level.map.attrs(i, j, "lever_action_custom")
if fct and fct(i, j, e, newval, old) then
if game.level.map.attrs(i, j, "lever_action_only_once") then game.level.map.attrs(i, j, "lever_action_kind", false) end
end
end end
end
if spot then
local spot = game.level:pickSpot(spot)
if spot then apply(spot.x, spot.y) end
else
core.fov.calc_circle(x, y, game.level.map.w, game.level.map.h, radius, function(_, i, j)
if block and game.level.map.attrs(i, j, block) then return true end
end, function(_, i, j) apply(i, j) end, nil)
end
self:leverActivated(x, y, e)
end
return true
end,
}
-- This is for the Map.TRIGGER layer
newEntity{
define_as = "GENERIC_TRIGGER_BOOL",
type = "trigger", subtype = "bool",
lever = false,
on_move = function(self, x, y, e)
if e.player then self:leverActivated(x, y, e) end
end,
}
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="20" height="20" tilewidth="64" tileheight="64" nextobjectid="6">
<properties>
<property name="rotate" value="&quot;default&quot;"/>
<property name="status_all" value="{no_teleport=true}"/>
</properties>
<tileset firstgid="1" name="Basic Terrains" tilewidth="64" tileheight="64" tilecount="100">
<image source="../../../../../../tiled-maps/gfx/vaults.png" width="640" height="640"/>
<tile id="0">
<properties>
<property name="id" value="HARDWALL"/>
</properties>
</tile>
<tile id="1">
<properties>
<property name="id" value="WALL"/>
</properties>
</tile>
<tile id="2">
<properties>
<property name="id" value="GLASSWALL"/>
</properties>
</tile>
<tile id="3">
<properties>
<property name="id" value="LAVA_WALL"/>
</properties>
</tile>
<tile id="4">
<properties>
<property name="id" value="LAVA"/>
</properties>
</tile>
<tile id="10">
<properties>
<property name="id" value="FLOOR"/>
</properties>
</tile>
<tile id="11">
<properties>
<property name="id" value="OLD_FLOOR"/>
</properties>
</tile>
<tile id="12">
<properties>
<property name="id" value="LAVA_FLOOR"/>
</properties>
</tile>
<tile id="20">
<properties>
<property name="id" value="DOOR_VAULT"/>
<property name="start" value=""/>
</properties>
</tile>
<tile id="21">
<properties>
<property name="id" value="DOOR"/>
</properties>
</tile>
<tile id="22">
<properties>
<property name="id" value="GLASSDOOR"/>
</properties>
</tile>
<tile id="30">
<properties>
<property name="id" value="WATER_FLOOR"/>
</properties>
</tile>
<tile id="31">
<properties>
<property name="id" value="WATER_FLOOR_BUBBLE"/>
</properties>
</tile>
<tile id="32">
<properties>
<property name="id" value="WATER_WALL"/>
</properties>
</tile>
<tile id="33">
<properties>
<property name="id" value="WATER_DOOR"/>
</properties>
</tile>
<tile id="34">
<properties>
<property name="id" value="DEEP_WATER"/>
</properties>
</tile>
<tile id="35">
<properties>
<property name="id" value="POISON_DEEP_WATER"/>
</properties>
</tile>
<tile id="50">
<properties>
<property name="id" value="GENERIC_LEVER_DOOR"/>
</properties>
</tile>
<tile id="51">
<properties>
<property name="id" value="GENERIC_LEVER"/>
</properties>
</tile>
</tileset>
<tileset firstgid="101" name="Trees" tilewidth="64" tileheight="64" tilecount="100">
<properties>
<property name="load_terrains" value="{&quot;/data/general/grids/forest.lua&quot;, &quot;/data/general/grids/autumn_forest.lua&quot;, &quot;/data/general/grids/snowy_forest.lua&quot;}"/>
</properties>
<image source="../../../../../../tiled-maps/gfx/vault_trees.png" width="640" height="640"/>
<tile id="0">
<properties>
<property name="id" value="GRASS"/>
</properties>
</tile>
<tile id="1">
<properties>
<property name="id" value="AUTUMN_GRASS"/>
</properties>
</tile>
<tile id="2">
<properties>
<property name="id" value="SNOWY_GRASS"/>
</properties>
</tile>
<tile id="10">
<properties>
<property name="id" value="TREE"/>
</properties>
</tile>
<tile id="11">
<properties>
<property name="id" value="AUTUMN_TREE"/>
</properties>
</tile>
<tile id="12">
<properties>
<property name="id" value="SNOWY_TREE"/>
</properties>
</tile>
<tile id="20">
<properties>
<property name="id" value="HARDTREE"/>
</properties>
</tile>
<tile id="21">
<properties>
<property name="id" value="HARDAUTUMN_TREE"/>
</properties>
</tile>
<tile id="22">
<properties>
<property name="id" value="HARDSNOWY_TREE"/>
</properties>
</tile>
<tile id="30">
<properties>
<property name="id" value="ROCK_VAULT"/>
</properties>
</tile>
</tileset>
<tileset firstgid="201" name="Loot" tilewidth="64" tileheight="64" tilecount="100">
<image source="../../../../../../tiled-maps/gfx/vault_loot.png" width="640" height="640"/>
<tile id="0">
<properties>
<property name="custom" value="{random_filter={add_levels=25, type=&quot;money&quot;}}"/>
</properties>
</tile>
<tile id="1">
<properties>
<property name="custom" value="{random_filter={add_levels=10, type=&quot;money&quot;}}"/>
</properties>
</tile>
<tile id="10">
<properties>
<property name="custom" value="{random_filter={tome_mod=&quot;vault&quot;}}"/>
</properties>
</tile>
<tile id="11">
<properties>
<property name="custom" value="{random_filter={tome_mod=&quot;gvault&quot;}}"/>
</properties>
</tile>
<tile id="12">
<properties>
<property name="custom" value="{random_filter={add_levels=10, tome_mod=&quot;vault&quot;}}"/>
</properties>
</tile>
<tile id="13">
<properties>
<property name="custom" value="{random_filter={add_levels=10, tome_mod=&quot;gvault&quot;}}"/>
</properties>
</tile>
<tile id="14">
<properties>
<property name="custom" value="{random_filter={add_levels=25, tome_mod=&quot;vault&quot;}}"/>
</properties>
</tile>
<tile id="15">
<properties>
<property name="custom" value="{random_filter={add_levels=25, tome_mod=&quot;gvault&quot;}}"/>
</properties>
</tile>
<tile id="16">
<properties>
<property name="custom" value="{random_filter={tome_mod=&quot;uvault&quot;}}"/>
</properties>
</tile>
<tile id="17">
<properties>
<property name="custom" value="{random_filter={add_levels=10, tome_mod=&quot;uvault&quot;}}"/>
</properties>
</tile>
<tile id="18">
<properties>
<property name="custom" value="{random_filter={add_levels=25, tome_mod=&quot;uvault&quot;}}"/>
</properties>
</tile>
</tileset>
<tileset firstgid="301" name="Trigger" tilewidth="64" tileheight="64" tilecount="100">
<image source="../../../../../../tiled-maps/gfx/vault_trigger.png" width="640" height="640"/>
<tile id="0">
<properties>
<property name="id" value="GENERIC_TRIGGER_BOOL"/>
</properties>
</tile>
</tileset>
<tileset firstgid="401" name="Traps" tilewidth="64" tileheight="64" tilecount="100">
<image source="../../../../../../tiled-maps/gfx/vault_traps.png" width="640" height="640"/>
<tile id="0">
<properties>
<property name="custom" value="{random_filter={}}"/>
</properties>
</tile>
</tileset>
<tileset firstgid="501" name="Arbitrary" tilewidth="64" tileheight="64" tilecount="36">
<image source="../../../../../../tiled-maps/gfx/vault_numbers.png" width="384" height="384"/>
</tileset>
<layer name="Terrain" width="20" height="20">
<data encoding="base64" compression="zlib">
eJyt1L0KwjAUhuEEzVQdxdFGewf1lqqrjtrRGzeBBD4+zsmPOLwUS3g4TYLWGGP/1Bo6hIZKce0S2lVa09oezwmVvA2keVuoxRsK3h5q9Y6d87mCJzVX9q/Xk87Xmd/O96p4pfuCzcK77EndoeydqJF+xzUvoU8yMKsY+C6umSic75liz4fO6cnzSRab6HlwPJm2YOEesoczefpe7TwW2tOSh/PdoFYvzyR97yXFJp853hdP1ih4j5R0f9jTQq9mtv6Xv5XY+wLFbUGB
</data>
</layer>
<layer name="Object" width="20" height="20">
<data encoding="base64" compression="zlib">
eJxjYKA9OIWGqQWuAPFlMvXexCJ2DYivkmnebSzsG0B8nQj19AAnB6lZowA7uMmAPY1SYt5wAzeQ8EgHAxUGALvuExE=
</data>
</layer>
<layer name="Trap" width="20" height="20">
<data encoding="base64" compression="zlib">
eJxjYBgFIxlMZBxoF6ACYt0DUgfD1LKXmuaNglEwEgAADNgEkQ==
</data>
</layer>
<layer name="Actor" width="20" height="20">
<data encoding="base64" compression="zlib">
eJxjYBgFo2AUjIJRMApIBwAGQAAB
</data>
</layer>
<layer name="Trigger" width="20" height="20">
<data encoding="base64" compression="zlib">
eJxjYBgF1Aa6jAPtglEwCkbBKKA9AADopwAv
</data>
</layer>
<objectgroup name="attrs">
<object id="1" x="529" y="528" width="39" height="36">
<properties>
<property name="lever" value="1"/>
<property name="lever_kind" value="&quot;foobar&quot;"/>
</properties>
</object>
<object id="2" x="582" y="393" width="49" height="46">
<properties>
<property name="lever_action_kind" value="&quot;foobar&quot;"/>
<property name="lever_toggle" value="true"/>
</properties>
</object>
<object id="4" x="335" y="271" width="39" height="36">
<properties>
<property name="lever" value="1"/>
<property name="lever_kind" value="&quot;lolz&quot;"/>
<property name="lever_only_once" value="true"/>
</properties>
</object>
<object id="5" x="264" y="586" width="49" height="46">
<properties>
<property name="lever_action_kind" value="&quot;lolz&quot;"/>
<property name="lever_toggle" value="true"/>
</properties>
</object>
</objectgroup>
</map>
tiled-maps/gfx/vault_loot.png

31.5 KiB

tiled-maps/gfx/vault_numbers.png

27.4 KiB

tiled-maps/gfx/vault_traps.png

10.1 KiB

tiled-maps/gfx/vault_trees.png

90.6 KiB

tiled-maps/gfx/vault_trigger.png

4.18 KiB

tiled-maps/gfx/vaults.png

130 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment