Skip to content

Commit f386204

Browse files
author
Mikel
committed
procgen-dungeons: Add ceiling by default
This change prevents monsters to escape the labyrinth
1 parent ef9a7bf commit f386204

File tree

5 files changed

+6988
-4927
lines changed

5 files changed

+6988
-4927
lines changed

craftium-envs/procgen-dungeons/mods/craftium_mod/init.lua

+139-130
Original file line numberDiff line numberDiff line change
@@ -8,144 +8,153 @@ spawned_mobs = {}
88

99
-- Spawn a monster of the given name in a position, disabling the infotext of the monster
1010
spawn_monster = function(pos, name)
11-
local obj = minetest.add_entity(pos, name)
12-
13-
-- Get the registered monster object
14-
local mob_def = minetest.registered_entities[name]
15-
if mob_def then
16-
-- Remove the update_tag function, this prevents showing the infotext
17-
mob_def.update_tag = function(self)
18-
end
19-
-- Provide some reward when the monster dies
20-
mob_def.on_die = function(self)
21-
set_reward_once(rwd_kill_monster)
22-
end
23-
end
24-
25-
table.insert(spawned_mobs, obj)
11+
local obj = minetest.add_entity(pos, name)
12+
13+
-- Get the registered monster object
14+
local mob_def = minetest.registered_entities[name]
15+
if mob_def then
16+
-- Remove the update_tag function, this prevents showing the infotext
17+
mob_def.update_tag = function(self) end
18+
-- Provide some reward when the monster dies
19+
mob_def.on_die = function(self)
20+
set_reward_once(rwd_kill_monster)
21+
end
22+
end
23+
24+
table.insert(spawned_mobs, obj)
2625
end
2726

2827
respawn_objective = function()
29-
item = minetest.add_item(objective_pos, minetest.settings:get("objective_item"))
30-
31-
-- Scale the item by some factor
32-
local scale_factor = 2
33-
local props = item:get_properties()
34-
35-
item:set_properties({
36-
visual_size = {
37-
x = props.visual_size.x * scale_factor, y = props.visual_size.y * scale_factor, z = props.visual_size.z * scale_factor
38-
},
39-
collisionbox = {
40-
props.collisionbox[1] * scale_factor, props.collisionbox[2] * scale_factor, props.collisionbox[3] * scale_factor,
41-
props.collisionbox[4] * scale_factor, props.collisionbox[5] * scale_factor, props.collisionbox[6] * scale_factor
42-
},
43-
selectionbox = {
44-
props.selectionbox[1] * scale_factor, props.selectionbox[2] * scale_factor, props.selectionbox[3] * scale_factor,
45-
props.selectionbox[4] * scale_factor, props.selectionbox[5] * scale_factor, props.selectionbox[6] * scale_factor
46-
}
47-
})
48-
49-
-- Override the 'on_punch' callback for this item to provide some reward when collected
50-
item:get_luaentity().on_punch = function(self, _puncher)
51-
set_reward_once(rwd_objective, 0.0)
52-
set_termination()
53-
end
28+
item = minetest.add_item(objective_pos, minetest.settings:get("objective_item"))
29+
30+
-- Scale the item by some factor
31+
local scale_factor = 2
32+
local props = item:get_properties()
33+
34+
item:set_properties({
35+
visual_size = {
36+
x = props.visual_size.x * scale_factor,
37+
y = props.visual_size.y * scale_factor,
38+
z = props.visual_size.z * scale_factor,
39+
},
40+
collisionbox = {
41+
props.collisionbox[1] * scale_factor,
42+
props.collisionbox[2] * scale_factor,
43+
props.collisionbox[3] * scale_factor,
44+
props.collisionbox[4] * scale_factor,
45+
props.collisionbox[5] * scale_factor,
46+
props.collisionbox[6] * scale_factor,
47+
},
48+
selectionbox = {
49+
props.selectionbox[1] * scale_factor,
50+
props.selectionbox[2] * scale_factor,
51+
props.selectionbox[3] * scale_factor,
52+
props.selectionbox[4] * scale_factor,
53+
props.selectionbox[5] * scale_factor,
54+
props.selectionbox[6] * scale_factor,
55+
},
56+
})
57+
58+
-- Override the 'on_punch' callback for this item to provide some reward when collected
59+
item:get_luaentity().on_punch = function(self, _puncher)
60+
set_reward_once(rwd_objective, 0.0)
61+
set_termination()
62+
end
5463
end
5564

5665
minetest.register_on_joinplayer(function(player, _last_login)
57-
-- Disable HUD elements
58-
player:hud_set_flags({
59-
crosshair = false,
60-
basic_debug = false,
61-
healthbar = false,
62-
hotbar = false,
63-
})
64-
65-
-- Generate map and locate the player and monsters
66-
local map, _ = minetest.settings:get("ascii_map"):gsub("\\n", "\n")
67-
local material_wall = minetest.settings:get("wall_material")
68-
local y = 4.5 -- The height of the terrain
69-
local z = 0
70-
for row in string.gmatch(map, "[^\n]+") do
71-
local x = 0
72-
for c in string.gmatch(row, ".") do
73-
if c == "#" then
74-
minetest.set_node({x = x, y = y, z = z}, { name = material_wall })
75-
elseif c == "O" then
76-
objective_pos = {x = x, y = y+1, z = z}
77-
respawn_objective()
78-
elseif c == "-" then
79-
y = y + 1
80-
z = -1
81-
x = -1
82-
elseif c == "@" then
83-
player_pos = {x = x, y = y, z = z}
84-
player:set_pos(player_pos)
85-
elseif c == "a" then
86-
local pos = {x = x, y = y, z = z}
87-
local name = minetest.settings:get("monster_type_a")
88-
spawn_monster(pos, name)
89-
table.insert(mobs_info, { pos = pos, name = name })
90-
elseif c == "b" then
91-
local pos = {x = x, y = y, z = z}
92-
local name = minetest.settings:get("monster_type_b")
93-
spawn_monster(pos, name)
94-
table.insert(mobs_info, { pos = pos, name = name })
95-
elseif c == "c" then
96-
local pos = {x = x, y = y, z = z}
97-
local name = minetest.settings:get("monster_type_c")
98-
spawn_monster(pos, name)
99-
table.insert(mobs_info, { pos = pos, name = name })
100-
elseif c == "d" then
101-
local pos = {x = x, y = y, z = z}
102-
local name = minetest.settings:get("monster_type_d")
103-
spawn_monster(pos, name)
104-
table.insert(mobs_info, { pos = pos, name = name })
105-
end
106-
x = x + 1
107-
end
108-
z = z + 1
109-
end
66+
-- Disable HUD elements
67+
player:hud_set_flags({
68+
crosshair = false,
69+
basic_debug = false,
70+
healthbar = false,
71+
hotbar = false,
72+
})
73+
74+
-- Generate map and locate the player and monsters
75+
local map, _ = minetest.settings:get("ascii_map"):gsub("\\n", "\n")
76+
local material_wall = minetest.settings:get("wall_material")
77+
local y = 4.5 -- The height of the terrain
78+
local z = 0
79+
for row in string.gmatch(map, "[^\n]+") do
80+
local x = 0
81+
for c in string.gmatch(row, ".") do
82+
if c == "#" then
83+
minetest.set_node({ x = x, y = y, z = z }, { name = material_wall })
84+
elseif c == "%" then
85+
minetest.set_node({ x = x, y = y, z = z }, { name = "default:glass" })
86+
elseif c == "O" then
87+
objective_pos = { x = x, y = y + 1, z = z }
88+
respawn_objective()
89+
elseif c == "-" then
90+
y = y + 1
91+
z = -1
92+
x = -1
93+
elseif c == "@" then
94+
player_pos = { x = x, y = y, z = z }
95+
player:set_pos(player_pos)
96+
elseif c == "a" then
97+
local pos = { x = x, y = y, z = z }
98+
local name = minetest.settings:get("monster_type_a")
99+
spawn_monster(pos, name)
100+
table.insert(mobs_info, { pos = pos, name = name })
101+
elseif c == "b" then
102+
local pos = { x = x, y = y, z = z }
103+
local name = minetest.settings:get("monster_type_b")
104+
spawn_monster(pos, name)
105+
table.insert(mobs_info, { pos = pos, name = name })
106+
elseif c == "c" then
107+
local pos = { x = x, y = y, z = z }
108+
local name = minetest.settings:get("monster_type_c")
109+
spawn_monster(pos, name)
110+
table.insert(mobs_info, { pos = pos, name = name })
111+
elseif c == "d" then
112+
local pos = { x = x, y = y, z = z }
113+
local name = minetest.settings:get("monster_type_d")
114+
spawn_monster(pos, name)
115+
table.insert(mobs_info, { pos = pos, name = name })
116+
end
117+
x = x + 1
118+
end
119+
z = z + 1
120+
end
110121
end)
111122

112-
minetest.register_on_player_hpchange(
113-
function(player, hp_change, reason)
114-
if player:get_hp() + hp_change <= 0 then -- Check if the player will die
115-
set_termination()
116-
return 0 -- Avoid the death of the player that shows the death screen
117-
end
118-
return hp_change
119-
end,
120-
true)
123+
minetest.register_on_player_hpchange(function(player, hp_change, reason)
124+
if player:get_hp() + hp_change <= 0 then -- Check if the player will die
125+
set_termination()
126+
return 0 -- Avoid the death of the player that shows the death screen
127+
end
128+
return hp_change
129+
end, true)
121130

122131
minetest.register_globalstep(function(dtime)
123-
-- Set timeofday to midday
124-
minetest.set_timeofday(0.5)
125-
126-
-- Reset the environment if requested by the python interface
127-
if get_soft_reset() == 1 then
128-
-- Remove the objective item if it's already spawned
129-
item:remove()
130-
-- Respawn the objective
131-
respawn_objective()
132-
133-
-- Remove all monsters
134-
for _, mob in ipairs(spawned_mobs) do
135-
mob:remove()
136-
end
137-
spawned_mobs = {}
138-
139-
-- Respawn all monsters
140-
for _, info in ipairs(mobs_info) do
141-
spawn_monster(info.pos, info.name)
142-
end
143-
144-
-- Reset player's health and position
145-
local player = minetest.get_connected_players()[1]
146-
player:set_hp(20, {type = "set_hp", from = "mod" })
147-
player:set_pos(player_pos)
148-
149-
reset_termination()
150-
end
132+
-- Set timeofday to midday
133+
minetest.set_timeofday(0.5)
134+
135+
-- Reset the environment if requested by the python interface
136+
if get_soft_reset() == 1 then
137+
-- Remove the objective item if it's already spawned
138+
item:remove()
139+
-- Respawn the objective
140+
respawn_objective()
141+
142+
-- Remove all monsters
143+
for _, mob in ipairs(spawned_mobs) do
144+
mob:remove()
145+
end
146+
spawned_mobs = {}
147+
148+
-- Respawn all monsters
149+
for _, info in ipairs(mobs_info) do
150+
spawn_monster(info.pos, info.name)
151+
end
152+
153+
-- Reset player's health and position
154+
local player = minetest.get_connected_players()[1]
155+
player:set_hp(20, { type = "set_hp", from = "mod" })
156+
player:set_pos(player_pos)
157+
158+
reset_termination()
159+
end
151160
end)

craftium/__init__.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from .minetest import is_minetest_build_dir
2+
import os
13
from .craftium_env import CraftiumEnv
24
from .multiagent_env import MarlCraftiumEnv
35
from .wrappers import BinaryActionWrapper, DiscreteActionWrapper
@@ -16,8 +18,8 @@
1618
monster_type_d="mobs_monster:mese_monster",
1719
wall_material="default:steelblock",
1820
objective_item="default:diamond",
19-
rwd_objective=100.0,
20-
rwd_kill_monster=1.0,
21+
rwd_objective=10.0,
22+
rwd_kill_monster=0.5,
2123
soft_reset=True,
2224
)
2325

@@ -64,9 +66,6 @@ def make_dungeon_env(
6466
# Environment registrations:
6567
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
6668

67-
import os
68-
from .minetest import is_minetest_build_dir
69-
7069

7170
# get the craftium's root directory, where the craftium-envs directory
7271
# containing all the environments is located
@@ -132,7 +131,8 @@ def make_dungeon_env(
132131
name="DiscreteActionWrapper",
133132
entry_point="craftium.wrappers:DiscreteActionWrapper",
134133
kwargs=dict(
135-
actions=["forward", "jump", "dig", "mouse x+", "mouse x-", "mouse y+", "mouse y-"],
134+
actions=["forward", "jump", "dig", "mouse x+",
135+
"mouse x-", "mouse y+", "mouse y-"],
136136
mouse_mov=0.5,
137137
),
138138
)
@@ -227,12 +227,12 @@ def make_dungeon_env(
227227
init_frames=200,
228228
game_id="mineclone2",
229229
minetest_conf=dict(
230-
max_block_generate_distance=3, # 16x3 blocks
230+
max_block_generate_distance=3, # 16x3 blocks
231231
mcl_logging_mobs_spawn=True,
232232
hud_scaling=0.5,
233233
fov=90,
234234
console_alpha=0,
235-
### Graphics Effects
235+
# Graphics Effects
236236
smooth_lighting=False,
237237
performance_tradeoffs=True,
238238
enable_particles=False,

0 commit comments

Comments
 (0)