Skip to content

Commit 662259a

Browse files
author
Mikel
committed
Add mutli-agent-combat environment
1 parent ed1d7d3 commit 662259a

File tree

15 files changed

+205
-0
lines changed

15 files changed

+205
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
channel_name = "craftium_channel"
2+
mod_channel = nil
3+
4+
minetest.register_globalstep(function(dtime)
5+
-- If soft-reset is requested by craftium, thoen send a message to
6+
-- the server to reset the environment
7+
if get_soft_reset() == 1 then
8+
mod_channel:send_all(
9+
minetest.serialize({
10+
agent = "server",
11+
reset = true,
12+
})
13+
)
14+
reset_termination()
15+
end
16+
end)
17+
18+
-- Function to check if the client has fully loaded
19+
wait_for_client_ready = function()
20+
if minetest.localplayer then
21+
-- Client has joined the server and is fully loaded
22+
callback()
23+
else
24+
-- Retry after a short delay if not yet fully initialized
25+
minetest.after(0.01, function() wait_for_client_ready() end)
26+
end
27+
end
28+
29+
-- Callback executed once the client is fully initialized
30+
callback = function()
31+
-- Join the mod channel and set up listeners here
32+
mod_channel = minetest.mod_channel_join(channel_name)
33+
34+
minetest.register_on_modchannel_message(function(channel, sender, str_message)
35+
if channel ~= channel_name then
36+
return
37+
end
38+
39+
local msg = minetest.deserialize(str_message)
40+
41+
if msg.agent ~= minetest.localplayer:get_name() then
42+
return
43+
end
44+
45+
if msg.reward ~= nil then
46+
set_reward_once(msg.reward, 0.0)
47+
end
48+
49+
if msg.termination == true then
50+
set_termination()
51+
end
52+
end)
53+
end
54+
55+
wait_for_client_ready()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = craftium_mod
2+
description = Craftium environment
3+
# depends = default
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
load_mod_craftium_mod = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../minetest_game
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
local channel = minetest.mod_channel_join("craftium_channel")
2+
3+
num_players = 0
4+
5+
reset_player = function(player)
6+
-- Set the name tag color to transparent
7+
player:set_nametag_attributes({color = {a = 0, r = 0, g = 0, b = 0}})
8+
9+
player:set_hp(20, {type = "set_hp", from = "mod" })
10+
11+
-- Set the player's initial position and yaw
12+
if player:get_player_name() == "agent0" then
13+
player:set_pos({x = -2.5, y = 4.5, z = -1.7})
14+
player:set_look_horizontal(3.1416)
15+
else
16+
player:set_pos({x = -2.5, y = 4.5, z = -8.5})
17+
player:set_look_horizontal(0)
18+
end
19+
20+
-- Disable HUD elements
21+
player:hud_set_flags({
22+
hotbar = false,
23+
crosshair = false,
24+
healthbar = false,
25+
chat = false,
26+
})
27+
end
28+
29+
minetest.register_on_joinplayer(function(player, _last_login)
30+
num_players = num_players + 1
31+
reset_player(player)
32+
end)
33+
34+
minetest.register_globalstep(function(dtime)
35+
-- Set timeofday to midday
36+
minetest.set_timeofday(0.5)
37+
end)
38+
39+
minetest.register_on_modchannel_message(function(channel, sender, str_message)
40+
if channel ~= "craftium_channel" then
41+
return
42+
end
43+
44+
local msg = minetest.deserialize(str_message)
45+
46+
if msg.agent ~= "server" then
47+
return
48+
end
49+
50+
if msg.reset == true then
51+
for _, player in pairs(minetest.get_connected_players()) do
52+
reset_player(player)
53+
end
54+
end
55+
end)
56+
57+
minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
58+
-- Get the names of both players involved
59+
local player_name = player:get_player_name()
60+
-- local hitter_name = hitter:get_player_name()
61+
62+
-- NOTE The player's health is updated after this callback, so the real hp will be get_hp()-1
63+
channel:send_all(
64+
minetest.serialize({
65+
agent = hitter:get_player_name(),
66+
reward = 1.0,
67+
termination = (player:get_hp() - 1) <= 5
68+
})
69+
)
70+
end)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name = craftium_env
2+
description = Craftium environment
3+
depends = default
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../common_mods/superflat
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
day_count = 12480
2+
lbm_introduction_times = :farming:start_nodetimer_cotton~0;default:convert_saplings_to_node_timer~0;:doors:replace_doors_door_glass~0;:doors:replace_doors_door_obsidian_glass~0;default:upgrade_chest_v2~0;xpanes:gen2~0;default:3dtorch~0;:farming:start_nodetimer_wheat~0;:doors:replace_doors_door_wood~0;:doors:replace_doors_door_steel~0;default:upgrade_chest_locked_v2~0;:doors:replace_xpanes_door_steel_bar~0;
3+
lbm_introduction_times_version = 1
4+
last_clear_objects_time = 0
5+
time_of_day = 12000
6+
game_time = 1330
7+
EnvArgsEnd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
return {}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
mg_biome_np_humidity_blend = {
2+
flags = defaults
3+
lacunarity = 2
4+
persistence = 1
5+
seed = 90003
6+
spread = (8,8,8)
7+
scale = 1.5
8+
octaves = 2
9+
offset = 0
10+
}
11+
mg_biome_np_heat_blend = {
12+
flags = defaults
13+
lacunarity = 2
14+
persistence = 1
15+
seed = 13
16+
spread = (8,8,8)
17+
scale = 1.5
18+
octaves = 2
19+
offset = 0
20+
}
21+
mg_flags = caves, dungeons, light, decorations, biomes, ores
22+
chunksize = 5
23+
mapgen_limit = 31007
24+
mg_biome_np_heat = {
25+
flags = defaults
26+
lacunarity = 2
27+
persistence = 0.5
28+
seed = 5349
29+
spread = (1000,1000,1000)
30+
scale = 50
31+
octaves = 3
32+
offset = 50
33+
}
34+
water_level = 1
35+
mg_biome_np_humidity = {
36+
flags = defaults
37+
lacunarity = 2
38+
persistence = 0.5
39+
seed = 842
40+
spread = (1000,1000,1000)
41+
scale = 50
42+
octaves = 3
43+
offset = 50
44+
}
45+
seed = 13264707149538330578
46+
mg_name = singlenode
47+
[end_of_params]
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sflat.Y_ORIGIN = 1
2+
sflat.BLOCKS = "superflat:bedrock,default:steelblock"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
enable_damage = false
2+
creative_mode = true
3+
mod_storage_backend = sqlite3
4+
auth_backend = sqlite3
5+
player_backend = sqlite3
6+
backend = sqlite3
7+
gameid = minetest
8+
world_name = world
9+
server_announce = false
10+
load_mod_superflat = mods/superflat
11+
load_mod_craftium_env = mods/craftium_env
12+
load_mod_mobs_monster = mods/mobs_monster
13+
load_mod_mobs = mods/mobs
14+
load_mod_mobs_animal = false

0 commit comments

Comments
 (0)