Compare commits

...

6 Commits

Author SHA1 Message Date
Milan 304f55fe83 Merge branch 'master' into 'master'
Fix robot being able to take pipeworks virtual item.

See merge request Illuna-Minetest/basic_robot!1
2020-04-13 16:19:14 +02:00
Jacob Piela 51fccf0491 fix robot being able to take pipeworks virtual item. 2020-04-12 18:21:14 +02:00
Milan fd136303c5 merge upstream 2019-01-31 15:59:39 +01:00
rnd ac1817dc9e book write: bugfix
item drops: randomize number of returned items
too long code used fix
2019-01-27 18:40:29 +01:00
rnd 5706500ad8 renaming 2019-01-13 21:37:58 +01:00
Milan* bb71554cc6 unlist buttons from crafting guide 2017-12-19 11:16:49 +01:00
5 changed files with 227 additions and 157 deletions

View File

@ -222,7 +222,12 @@ basic_robot.commands.take_item = function(name,item, inventory,dir)
local pos = basic_robot.data[name].spawnpos; -- position of spawner block local pos = basic_robot.data[name].spawnpos; -- position of spawner block
if basic_robot.bad_inventory_blocks[ minetest.get_node(tpos).name ] then return false end -- dont allow take from for i, bad_inventory in pairs(basic_robot.bad_inventory_blocks) do -- dont allow take from
if minetest.get_node(tpos).name:find("^" .. bad_inventory) ~= nil then
return false
end
end
local meta = minetest.get_meta(pos); local meta = minetest.get_meta(pos);
local tmeta = minetest.get_meta(tpos); local tmeta = minetest.get_meta(tpos);
@ -457,10 +462,11 @@ basic_robot.commands.write_book = function(name,title,text) -- returns itemstack
local data = {} local data = {}
if title == "" or not title then title = "program book "..minetest.get_gametime() end if title == "" or not title then title = "program book "..minetest.get_gametime() end
data.title = title data.title = title or ""
data.text = text or "" data.text = text or ""
data.text_len = #data.text data.text_len = #data.text
data.page = 1 data.page = 1
data.description = title or ""
data.page_max = math.ceil((#data.text:gsub("[^\n]", "") + 1) / lpp) data.page_max = math.ceil((#data.text:gsub("[^\n]", "") + 1) / lpp)
data.owner = name data.owner = name
--local data_str = minetest.serialize(data) -- pre 0.4.16 --local data_str = minetest.serialize(data) -- pre 0.4.16
@ -484,15 +490,16 @@ basic_robot.give_drops = function(nodename, inv) -- gives apropriate drops when
if max_items==0 then -- just drop all the items (taking the rarity into consideration) if max_items==0 then -- just drop all the items (taking the rarity into consideration)
max_items = #table.drop.items or 0; max_items = #table.drop.items or 0;
end end
max_items = math.random(max_items) -- return random number of items
local drop = table.drop; local drop = table.drop;
local i = 0; local i = 0;
for k,v in pairs(drop.items) do for k,v in pairs(drop.items) do
if i > max_items then break end; i=i+1; if i > max_items then break end;
i=i+1;
local rare = v.rarity or 1; local rare = v.rarity or 1;
if rare>0 and math.random(1, rare)==1 then if rare>0 and math.random(1, rare)==1 then
dropname = v.items[math.random(1,#v.items)]; -- pick item randomly from list dropname = v.items[math.random(1,#v.items)]; -- pick item randomly from list
inv:add_item("main",dropname); inv:add_item("main",dropname);
break
end end
end end
else else
@ -589,7 +596,7 @@ local register_robot_button = function(R,G,B,type)
wield_image = "robot_button.png^[colorize:#"..R..G..B..":180", wield_image = "robot_button.png^[colorize:#"..R..G..B..":180",
is_ground_content = false, is_ground_content = false,
groups = {cracky=3}, groups = {cracky=3,not_in_craft_guide=1},
on_punch = function(pos, node, player) on_punch = function(pos, node, player)
local name = player:get_player_name(); if name==nil then return end local name = player:get_player_name(); if name==nil then return end
local round = math.floor; local round = math.floor;
@ -613,7 +620,7 @@ minetest.register_node("basic_robot:button"..number,
wield_image = "robot_button".. number .. ".png", wield_image = "robot_button".. number .. ".png",
is_ground_content = false, is_ground_content = false,
groups = {cracky=3}, groups = {cracky=3,not_in_craft_guide=1},
on_punch = function(pos, node, player) on_punch = function(pos, node, player)
local name = player:get_player_name(); if name==nil then return end local name = player:get_player_name(); if name==nil then return end
local round = math.floor; local round = math.floor;
@ -636,7 +643,7 @@ minetest.register_node("basic_robot:button_"..number,
inventory_image = string.format("%03d",number).. ".png", inventory_image = string.format("%03d",number).. ".png",
wield_image = string.format("%03d",number).. ".png", wield_image = string.format("%03d",number).. ".png",
is_ground_content = false, is_ground_content = false,
groups = {cracky=3}, groups = {cracky=3,not_in_craft_guide=1},
on_punch = function(pos, node, player) on_punch = function(pos, node, player)
local name = player:get_player_name(); if name==nil then return end local name = player:get_player_name(); if name==nil then return end
local round = math.floor; local round = math.floor;
@ -658,7 +665,7 @@ minetest.register_node("basic_robot:button_"..number,
inventory_image = texture .. ".png", inventory_image = texture .. ".png",
wield_image = texture .. ".png", wield_image = texture .. ".png",
is_ground_content = false, is_ground_content = false,
groups = {cracky=3}, groups = {cracky=3,not_in_craft_guide=1},
on_punch = function(pos, node, player) on_punch = function(pos, node, player)
local name = player:get_player_name(); if name==nil then return end local name = player:get_player_name(); if name==nil then return end
local round = math.floor; local round = math.floor;
@ -1489,13 +1496,3 @@ end
-- code for act borrowed from: https://github.com/minetest-mods/pipeworks/blob/fa4817136c8d1e62dafd6ab694821cba255b5206/wielder.lua, line 372 -- code for act borrowed from: https://github.com/minetest-mods/pipeworks/blob/fa4817136c8d1e62dafd6ab694821cba255b5206/wielder.lua, line 372

View File

@ -15,11 +15,15 @@ basic_robot.maxoperations = 10; -- how many operations (dig, place,move,...,gene
basic_robot.dig_require_energy = true; -- does robot require energy to dig stone? basic_robot.dig_require_energy = true; -- does robot require energy to dig stone?
basic_robot.bad_inventory_blocks = { -- disallow taking from these nodes inventories to prevent player abuses basic_robot.bad_inventory_blocks = { -- disallow taking from these nodes inventories to prevent player abuses
["craft_guide:sign_wall"] = true, "craft_guide:sign_wall",
["basic_machines:battery_0"] = true, "basic_machines:battery_0",
["basic_machines:battery_1"] = true, "basic_machines:battery_1",
["basic_machines:battery_2"] = true, "basic_machines:battery_2",
["basic_machines:generator"] = true, "basic_machines:generator",
"pipeworks:autocrafter",
"pipeworks:mese_filter",
"pipeworks:filter",
"pipeworks:mese_tube_", -- matched to first part of node name
} }
----- END OF SETTINGS ------ ----- END OF SETTINGS ------
@ -209,7 +213,7 @@ function getSandboxEnv (name)
label = function(text) label = function(text)
local obj = basic_robot.data[name].obj; local obj = basic_robot.data[name].obj;
obj:set_properties({nametag = text}); -- "[" .. name .. "] " .. obj:set_properties({nametag = text or ""}); -- "[" .. name .. "] " ..
end, end,
display_text = function(text,linesize,size) display_text = function(text,linesize,size)
@ -576,7 +580,7 @@ end
check_code = function(code) check_code = function(code)
--"while ", "for ", "do ","goto ", --"while ", "for ", "do ","goto ",
local bad_code = {"repeat", "until", "_ccounter", "_G", "while%(", "while{", "pcall","%.%."} --,"\\\"", "%[=*%[","--[["} local bad_code = {"repeat", "until", "_c_", "_G", "while%(", "while{", "pcall","%.%."} --,"\\\"", "%[=*%[","--[["}
for _, v in pairs(bad_code) do for _, v in pairs(bad_code) do
if string.find(code, v) then if string.find(code, v) then
return v .. " is not allowed!"; return v .. " is not allowed!";
@ -1578,6 +1582,7 @@ minetest.register_on_player_receive_fields(
if not data then data = {} end if not data then data = {} end
local text = fields.book or ""; local text = fields.book or "";
if string.len(text) > 64000 then if string.len(text) > 64000 then
local sender = player:get_player_name();
minetest.chat_send_all("#ROBOT: " .. sender .. " is spamming with long text.") return minetest.chat_send_all("#ROBOT: " .. sender .. " is spamming with long text.") return
end end
data.text = text or "" data.text = text or ""
@ -1903,4 +1908,4 @@ minetest.register_craft({
minetest.register_privilege("robot", "increased number of allowed active robots") minetest.register_privilege("robot", "increased number of allowed active robots")
minetest.register_privilege("puzzle", "allow player to use puzzle. namespace in robots") minetest.register_privilege("puzzle", "allow player to use puzzle. namespace in robots")
print('[MOD]'.. " basic_robot " .. basic_robot.version .. " loaded.") print('[MOD]'.. " basic_robot " .. basic_robot.version .. " loaded.")

View File

@ -11,6 +11,22 @@ if not paste then
end end
end end
data = {}; data = {};
display_marker = function(pos,label)
minetest.add_particle(
{
pos = pos,
expirationtime = 10,
velocity = {x=0, y=0,z=0},
size = 18,
texture = label..".png",
acceleration = {x=0,y=0,z=0},
collisiondetection = true,
collision_removal = true,
})
end
self.listen(1) self.listen(1)
self.label("COPY-PASTE MASTER v1.2 gold edition. commands: c1 c2 r c p") self.label("COPY-PASTE MASTER v1.2 gold edition. commands: c1 c2 r c p")
end end
@ -21,12 +37,16 @@ speaker, msg = self.listen_msg()
if speaker == "rnd" then if speaker == "rnd" then
local player = _G.minetest.get_player_by_name(speaker); local player = _G.minetest.get_player_by_name(speaker);
local p = player:getpos(); p.x = round(p.x); p.y=round(p.y); p.z = round(p.z); local p = player:getpos(); p.x = round(p.x); p.y=round(p.y); p.z = round(p.z);
if p.y<0 then p.y = p.y +1 end -- needed cause of minetest bug
if msg == "c1" then if msg == "c1" then
paste.src1 = {x=p.x,y=p.y,z=p.z};say("marker 1 set at " .. p.x .. " " .. p.y .. " " .. p.z) paste.src1 = {x=p.x,y=p.y,z=p.z};say("marker 1 set at " .. p.x .. " " .. p.y .. " " .. p.z)
display_marker(p,"099") -- c
elseif msg == "c2" then elseif msg == "c2" then
paste.src2 = {x=p.x,y=p.y,z=p.z};say("marker 2 set at " .. p.x .. " " .. p.y .. " " .. p.z) paste.src2 = {x=p.x,y=p.y,z=p.z};say("marker 2 set at " .. p.x .. " " .. p.y .. " " .. p.z)
display_marker(p,"099") -- c
elseif msg == "r" then elseif msg == "r" then
paste.ref = {x=p.x,y=p.y,z=p.z};say("reference set at " .. p.x .. " " .. p.y .. " " .. p.z) paste.ref = {x=p.x,y=p.y,z=p.z};say("reference set at " .. p.x .. " " .. p.y .. " " .. p.z)
display_marker(p,"114") -- r
elseif msg == "c" then -- copy elseif msg == "c" then -- copy
local x1 = math.min(paste.src1.x,paste.src2.x);local y1 = math.min(paste.src1.y,paste.src2.y);local z1 = math.min(paste.src1.z,paste.src2.z); local x1 = math.min(paste.src1.x,paste.src2.x);local y1 = math.min(paste.src1.y,paste.src2.y);local z1 = math.min(paste.src1.z,paste.src2.z);
local x2 = math.max(paste.src1.x,paste.src2.x);local y2 = math.max(paste.src1.y,paste.src2.y);local z2 = math.max(paste.src1.z,paste.src2.z); local x2 = math.max(paste.src1.x,paste.src2.x);local y2 = math.max(paste.src1.y,paste.src2.y);local z2 = math.max(paste.src1.z,paste.src2.z);

View File

@ -1,137 +1,146 @@
-- simple ctf robot, rnd -- simple ctf robot, rnd
--instructions: build game arena and place blue/red buttons as flags. edit flag positions below --instructions: build game arena and place blue/red buttons as flags. edit flag positions below
--you must register 'keyboard' events by placing robot with same 'id' as robot running this code at 'event register' positions - default (32*i,64*j+1, 32*k) --you must register 'keyboard' events by placing robot with same 'id' as robot running this code at 'event register' positions - default (32*i,64*j+1, 32*k)
if not ctf then if not ctf then
_G.minetest.forceload_block(self.pos(),true) _G.minetest.forceload_block(self.pos(),true)
ctf = { ctf = {
[1] = {state = 1, flagnode = "basic_robot:button8080FF", pos = {x=-18,y=501,z=17}, name = "blue", owner = "", score = 0}, -- team[1] [1] = {state = 1, flagnode = "basic_robot:button8080FF", pos = {x=-18,y=502,z=110}, name = "blue", owner = "", score = 0}, -- team[1]
[2] = {state = 1, flagnode = "basic_robot:buttonFF8080", pos = {x=-79,y=501,z=46}, name = "red", owner = "", score = 0}, -- team[2] [2] = {state = 1, flagnode = "basic_robot:buttonFF8080", pos = {x=-18,y=502,z=80}, name = "red", owner = "", score = 0}, -- team[2]
} }
teams = {} -- example : {["rnd"] = {1,0, player, health points at start}}; -- team, ownership of flag teams = {} -- example : {["rnd"] = {1,0, player, health points at start}}; -- team, ownership of flag
maxscore = 3; maxscore = 3;
t = 0 t = 0
teamid = 1; -- team selector when joining teamid = 1; -- team selector when joining
gamestate = 0; gamestate = 0;
self.listen(1) self.listen(1)
self.spam(1) self.spam(1)
get_id = function(pos) get_id = function(pos)
local range = 1000; local range = 1000;
return pos.x + range*pos.y+range^2*pos.z return pos.x + range*pos.y+range^2*pos.z
end
flag_id = {}; for i = 1,#ctf do flag_id[get_id(ctf[i].pos)] = i end
render_flags = function()
for i = 1,#ctf do minetest.set_node(ctf[i].pos, {name = ctf[i].flagnode}) end
end
end
if gamestate == 0 then -- welcome
say(colorize("red","#CAPTURE THE FLAG GAME. say '\\join' to join game. to start game one of joined players says '\\start'"))
gamestate = 1
elseif gamestate == 1 then
speaker,msg = self.listen_msg()
if msg == "join" then
local pl = minetest.get_player_by_name(speaker);
teams[speaker] = {teamid, 0, pl,20};pl:set_hp(20)
local msg1 = ""; local msg2 = ""
for k,v in pairs(teams) do
if v[1] == 1 then msg1 = msg1 .. k .. " " elseif v[1] == 2 then msg2 = msg2 .. k .. " " end
end end
say(colorize("yellow","#CTF : " .. speaker .. " joined team " .. ctf[teamid].name .. ". TEAM " .. ctf[1].name .. ": " .. msg1 .. ", TEAM " .. ctf[2].name .. ": " .. msg2)) flag_id = {}; for i = 1,#ctf do flag_id[get_id(ctf[i].pos)] = i end
teamid = 3-teamid; -- 1,2
elseif msg == "start" then -- game start render_flags = function()
if teams[speaker] then for i = 1,#ctf do minetest.set_node(ctf[i].pos, {name = ctf[i].flagnode}) end
gamestate = 2
keyboard.get() -- clear keyboard buffer
say(colorize("red","#CTF GAME STARTED. GET ENEMY FLAG AND BRING IT BACK TO YOUR FLAG. DONT LET YOUR HEALTH GO BELOW 5 HEARTS OR YOU ARE OUT."))
for k,_ in pairs(teams) do -- teleport players
local data = teams[k];data[3]:setpos( ctf[data[1]].pos )
end
render_flags()
end end
end end
elseif gamestate == 2 then if gamestate == 0 then -- welcome
-- check player health say(colorize("red","#CAPTURE THE FLAG GAME. say '\\join' to join game. to start game one of joined players says '\\start'"))
for k,v in pairs(teams) do gamestate = 1
local hp = teams[k][3]:get_hp(); elseif gamestate == 1 then
if not hp or hp<10 then -- teams[k][4] speaker,msg = self.listen_msg()
if msg == "join" then
local cflag = teams[k][2]; local pl = minetest.get_player_by_name(speaker);
if cflag>0 then -- drop flag teams[speaker] = {teamid, 0, pl,20};pl:set_hp(20)
ctf[cflag].state = 1 local msg1 = ""; local msg2 = ""
ctf[cflag].owner = "" for k,v in pairs(teams) do
minetest.set_node(ctf[cflag].pos, {name = ctf[cflag].flagnode}) if v[1] == 1 then msg1 = msg1 .. k .. " " elseif v[1] == 2 then msg2 = msg2 .. k .. " " end
say(colorize("red", "#CTF " .. k .. " dropped " .. ctf[cflag].name .. " flag!"))
end end
if not hp then -- player left
say(colorize("yellow", "#CTF " .. k .. " left the game!"))
teams[k] = nil
else -- reset player
say(colorize("yellow", "#CTF " .. k .. " resetted!"))
v[2] = 0 -- player has no flag
v[3]:set_hp(20)
v[3]:setpos( ctf[v[1]].pos )
end
say(colorize("yellow","#CTF : " .. speaker .. " joined team " .. ctf[teamid].name .. ". TEAM " .. ctf[1].name .. ": " .. msg1 .. ", TEAM " .. ctf[2].name .. ": " .. msg2))
teamid = 3-teamid; -- 1,2
elseif msg == "start" then -- game start
if teams[speaker] then
gamestate = 2
keyboard.get() -- clear keyboard buffer
say(colorize("red","#CTF GAME STARTED. GET ENEMY FLAG AND BRING IT BACK TO YOUR FLAG. DONT LET YOUR HEALTH GO BELOW 3 HEARTS OR YOU ARE OUT."))
for k,_ in pairs(teams) do -- teleport players
local data = teams[k];data[3]:setpos( ctf[data[1]].pos )
end
render_flags()
end
end end
end
elseif gamestate == 2 then
speaker,msg = self.listen_msg()
event = keyboard.get() if msg == "score" then
if event and teams[event.puncher] then local msg1 = ""; local msg2 = ""
--say(serialize(event)) for k,v in pairs(teams) do
local punch_id = get_id({x=event.x,y=event.y,z=event.z}); if v[1] == 1 then msg1 = msg1 .. k .. " " elseif v[1] == 2 then msg2 = msg2 .. k .. " " end
local flag = flag_id[punch_id]; end
if flag then say(colorize("yellow","SCORE " .. ctf[1].score .. "/" .. ctf[2].score) .."\n" .. colorize("yellow","TEAM " .. ctf[1].name .. ": " .. msg1 .. ", TEAM " .. ctf[2].name .. ": " .. msg2))
local state = ctf[flag].state end
local puncher = event.puncher;
if state == 1 then -- flag is here, ready to be taken or capture of enemy flag -- check player health
if teams[puncher][1] ~= flag then -- take for k,v in pairs(teams) do
say(colorize("red","#CTF " .. puncher .. " has taken " .. ctf[flag].name .. " flag !")) local hp = teams[k][3]:get_hp();
ctf[flag].state = 2; if not hp or hp<6 then -- teams[k][4]
ctf[flag].owner = puncher;
teams[puncher][2] = flag; local cflag = teams[k][2];
minetest.set_node(ctf[flag].pos, {name = "basic_robot:buttonFFFF80"}) if cflag>0 then -- drop flag
else -- capture? ctf[cflag].state = 1
if teams[puncher][2] > 0 then ctf[cflag].owner = ""
local cflag = teams[puncher][2] -- puncher has this flag minetest.set_node(ctf[cflag].pos, {name = ctf[cflag].flagnode})
local data = ctf[cflag]; say(colorize("red", "#CTF " .. k .. " dropped " .. ctf[cflag].name .. " flag!"))
end
local team = teams[puncher][1]; if not hp then -- player left
ctf[team].score = ctf[team].score + 1 say(colorize("yellow", "#CTF " .. k .. " left the game!"))
ctf[team].owner = "" teams[k] = nil
ctf[cflag].state = 1; -- reset captured flag state else -- reset player
minetest.set_node(ctf[cflag].pos, {name = ctf[cflag].flagnode}) say(colorize("yellow", "#CTF " .. k .. " resetted!"))
teams[puncher][2] = 0 v[2] = 0 -- player has no flag
say(colorize("orange","#CTF " .. puncher .. " has captured " .. data.name .. " flag! Team " .. ctf[team].name .. " has score " .. ctf[team].score )) v[3]:set_hp(20)
if ctf[team].score == maxscore then v[3]:setpos( ctf[v[1]].pos )
say(colorize("yellow","#CTF: TEAM " .. ctf[team].name .. " WINS! "))
gamestate = 3;t=5; -- intermission, duration 5
--reset
teams = {}
for i=1,#ctf do ctf[i].state = 1 ctf[i].score = 0 ctf[i].owner = "" end
end
end
end end
end end
end end
--say(serialize(event))
end
elseif gamestate == 3 then -- intermission event = keyboard.get()
if t>0 then t=t-1 else gamestate = 0 end if event and teams[event.puncher] then
end --say(serialize(event))
local punch_id = get_id({x=event.x,y=event.y,z=event.z});
local flag = flag_id[punch_id];
if flag then
local state = ctf[flag].state
local puncher = event.puncher;
if state == 1 then -- flag is here, ready to be taken or capture of enemy flag
if teams[puncher][1] ~= flag then -- take
say(colorize("red","#CTF " .. puncher .. " has taken " .. ctf[flag].name .. " flag !"))
ctf[flag].state = 2;
ctf[flag].owner = puncher;
teams[puncher][2] = flag;
minetest.set_node(ctf[flag].pos, {name = "basic_robot:buttonFFFF80"})
else -- capture?
if teams[puncher][2] > 0 then
local cflag = teams[puncher][2] -- puncher has this flag
local data = ctf[cflag];
local team = teams[puncher][1];
ctf[team].score = ctf[team].score + 1
ctf[team].owner = ""
ctf[cflag].state = 1; -- reset captured flag state
minetest.set_node(ctf[cflag].pos, {name = ctf[cflag].flagnode})
teams[puncher][2] = 0
say(colorize("orange","#CTF " .. puncher .. " has captured " .. data.name .. " flag! Team " .. ctf[team].name .. " has score " .. ctf[team].score ))
if ctf[team].score == maxscore then
say(colorize("yellow","#CTF: TEAM " .. ctf[team].name .. " WINS! "))
gamestate = 3;t=5; -- intermission, duration 5
--reset
teams = {}
for i=1,#ctf do ctf[i].state = 1 ctf[i].score = 0 ctf[i].owner = "" end
end
end
end
end
end
--say(serialize(event))
end
elseif gamestate == 3 then -- intermission
if t>0 then t=t-1 else gamestate = 0 end
end

View File

@ -4,6 +4,10 @@ if not data then
paused = true paused = true
turn = 2; turn = 2;
turntimeout = 5
shorttimeout = 1
shortround = false
turnmessage = ""
t = 0; t = 0;
SIGNUP = 0; GAME = 1; INTERMISSION = 2 SIGNUP = 0; GAME = 1; INTERMISSION = 2
state = SIGNUP state = SIGNUP
@ -12,6 +16,8 @@ if not data then
data = {}; data = {};
init_game = function() init_game = function()
abilitypoints = {0,0}; -- points to use ability, step outside ring to use them in following round
shortround = false
data = {}; minescount = 32 data = {}; minescount = 32
for i = 1, minescount do local i = math.random(m); local j = math.random(n); if not data[i] then data[i] = {} end; data[i][j] = 1; end for i = 1, minescount do local i = math.random(m); local j = math.random(n); if not data[i] then data[i] = {} end; data[i][j] = 1; end
if not data[1] then data[1] = {} end if not data[2] then data[2] = {} end -- create 2x2 safe area if not data[1] then data[1] = {} end if not data[2] then data[2] = {} end -- create 2x2 safe area
@ -44,8 +50,17 @@ if not data then
return count return count
end end
near_chat = function(msg)
end
greeting = function() greeting = function()
_G.minetest.chat_send_all(colorize("red","#BATTLE MINESWEEPER : two player battle in minesweeper. say join to play.\nRules: 1. each player has 5 second turn to make a move 2. if you dont make move you lose\n3. if you make move in other player turn you lose. 4. if you hit bomb or mark bomb falsely you lose")) _G.minetest.chat_send_all(colorize("red",
"#BATTLE MINESWEEPER : two player battle in minesweeper. say join to play.\nRules: "..
"1. each player has 5 second turn to make a move 2. if you dont make move you lose\n"..
"3. if you make move in other player turn you lose. 4. if you hit bomb or mark bomb falsely you lose\n"..
"5. by playing fast you get ability charge. when you collect 10 you can step out of ring when your round ends and opponent will only have 2s to play his turn."
))
end end
player_lost = function () player_lost = function ()
@ -53,22 +68,38 @@ if not data then
local player = _G.minetest.get_player_by_name(players[i]); local player = _G.minetest.get_player_by_name(players[i]);
if player then player:setpos({x=spawnpos.x,y=spawnpos.y+10,z=spawnpos.z}) end if player then player:setpos({x=spawnpos.x,y=spawnpos.y+10,z=spawnpos.z}) end
end end
_G.minetest.sound_play("electric_zap",{pos=spawnpos, max_hear_distance = 100})
state = INTERMISSION; t = 0 state = INTERMISSION; t = 0
end end
function change_turn() function change_turn()
shortround = false -- reset ability if activated
if turn == 1 then if turn == 1 then
_G.minetest.sound_play("default_break_glass",{pos=spawnpos, max_hear_distance = 100}) _G.minetest.sound_play("default_break_glass",{pos=spawnpos, max_hear_distance = 100})
else else
_G.minetest.sound_play("note_a",{pos=spawnpos, max_hear_distance = 100}) _G.minetest.sound_play("default_cool_lava",{pos=spawnpos, max_hear_distance = 100})
end end
if paused == false then if paused == false then
say(players[turn] .. " lost : didn't make a move"); say(players[turn] .. " lost : didn't make a move fast enough ");
player_lost() player_lost()
else else
local player = minetest.get_player_by_name(players[turn])
local ppos = player:getpos()
local x = ppos.x - spawnpos.x;local y = ppos.y - spawnpos.y;local z = ppos.z - spawnpos.z;
local points = abilitypoints[turn]
if x<1 or x>m or z<1 or z>n then -- outside area
local points = abilitypoints[turn]
if points>=10 then -- do we have enough points?
shortround = true -- next round will be shorter, 2s
_G.minetest.sound_play("grinder",{pos=spawnpos, max_hear_distance = 100})
abilitypoints[turn] = abilitypoints[turn]-10
end
end
if turn == 1 then turn = 2 else turn = 1 end if turn == 1 then turn = 2 else turn = 1 end
self.label("turn " .. turn .. " " .. players[turn]) turnmessage = "turn " .. turn .. " " .. players[turn] .. ",charge " .. abilitypoints[turn] .. "\n"
self.label(turnmessage)
t=0 t=0
paused = false paused = false
end end
@ -96,6 +127,7 @@ if state == SIGNUP then
if player then player:setpos({x=spawnpos.x,y=spawnpos.y+1,z=spawnpos.z}) end if player then player:setpos({x=spawnpos.x,y=spawnpos.y+1,z=spawnpos.z}) end
end end
_G.minetest.chat_send_all(colorize("red","BATTLE MINESWEEPER " .. m .. "x" ..n .. " with " .. minescount .. " mines.\n" .. players[turn] .. " its your move!")) _G.minetest.chat_send_all(colorize("red","BATTLE MINESWEEPER " .. m .. "x" ..n .. " with " .. minescount .. " mines.\n" .. players[turn] .. " its your move!"))
init_game()
end end
end end
@ -104,17 +136,24 @@ if state == SIGNUP then
elseif state == GAME then elseif state == GAME then
t = t + 1; t = t + 1;
if t>5 then -- change of turn if (t>turntimeout) or (shortround and t>shorttimeout) then -- change of turn
change_turn() change_turn()
else
self.label(turnmessage .. " " .. (turntimeout-t+1))
end end
event = keyboard.get(); event = keyboard.get();
if event and event.type == 2 and not paused then if event and event.type == 2 and not paused then
if event.puncher == players[turn] then if event.puncher == players[turn] then
local x = event.x - spawnpos.x;local y = event.y - spawnpos.y;local z = event.z - spawnpos.z; local x = event.x - spawnpos.x;local y = event.y - spawnpos.y;local z = event.z - spawnpos.z;
if x<1 or x>m or z<1 or z>n then local points = abilitypoints[turn]
if x<1 or x>m or z<1 or z>n then -- outside area
else else
local ppos = player.getpos(event.puncher) local ppos = player.getpos(event.puncher)
points = points + math.max(turntimeout-t-2,0); if points>40 then points = 40 end
abilitypoints[turn] = points
if ppos and math.abs(ppos.x-event.x)<0.5 and math.abs(ppos.z-event.z)<0.5 then -- just mark mine if ppos and math.abs(ppos.x-event.x)<0.5 and math.abs(ppos.z-event.z)<0.5 then -- just mark mine
if data[x] and data[x][z] == 1 then if data[x] and data[x][z] == 1 then
if keyboard.read({x=event.x,y=event.y,z=event.z})~="basic_robot:button808080" then if keyboard.read({x=event.x,y=event.y,z=event.z})~="basic_robot:button808080" then
@ -146,5 +185,5 @@ elseif state == GAME then
end end
elseif state == INTERMISSION then elseif state == INTERMISSION then
t=t+1; if t> 15 then state = SIGNUP;players = {}; paused = true; init_game(); greeting() end t=t+1; if t> 15 then state = SIGNUP;players = {}; paused = true; greeting() end
end end