diff --git a/.gitignore b/.gitignore index a2fb451..9e132e1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,3 @@ tags *.vim debug.txt - -## Files related to minetest development cycle -*.patch diff --git a/.luacheckrc b/.luacheckrc index b301ed9..151f963 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -15,7 +15,8 @@ globals = { "crafting", "vector", "table", "minetest", "worldedit", "ctf", "ctf_flag", "ctf_colors", "hudkit", "default", "treasurer", "ChatCmdBuilder", "ctf_map", "ctf_match", "ctf_stats", "ctf_treasure", "ctf_playertag", "chatplus", "irc", - "armor", "vote", "give_initial_stuff", "hud_score", "physics", "tsm_chests" + "armor", "vote", "give_initial_stuff", "hud_score", "physics", "tsm_chests", + "armor", "shooter" } read_globals = { diff --git a/docs/accurate_statbar.patch b/docs/accurate_statbar.patch new file mode 100644 index 0000000..8acf78b --- /dev/null +++ b/docs/accurate_statbar.patch @@ -0,0 +1,18 @@ +diff --git a/builtin/game/statbars.lua b/builtin/game/statbars.lua +index 46c947b6..f4372843 100644 +--- builtin/game/statbars.lua ++++ builtin/game/statbars.lua +@@ -24,12 +24,14 @@ local breath_bar_definition = { + local hud_ids = {} + + local function scaleToDefault(player, field) ++ return player["get_" .. field](player) +- -- Scale "hp" or "breath" to the default dimensions +- local current = player["get_" .. field](player) +- local nominal = core["PLAYER_MAX_".. field:upper() .. "_DEFAULT"] +- local max_display = math.max(nominal, +- math.max(player:get_properties()[field .. "_max"], current)) +- return current / max_display * nominal + end + + local function update_builtin_statbars(player) diff --git a/minetest.conf b/minetest.conf index 0eb278f..01019e1 100644 --- a/minetest.conf +++ b/minetest.conf @@ -3,8 +3,8 @@ enable_pvp = true mg_name = singlenode vote.kick_vote = false barrier = 106 -regen_interval = 6 -regen_amount = 1 +hpregen.interval = 6 +hpregen.amount = 1 random_messages_interval = 60 sprint_stamina = 10 enable_lavacooling = false diff --git a/mods/ctf/ctf_classes/api.lua b/mods/ctf/ctf_classes/api.lua index 7da3d71..88728e8 100644 --- a/mods/ctf/ctf_classes/api.lua +++ b/mods/ctf/ctf_classes/api.lua @@ -4,10 +4,15 @@ function ctf_classes.register(cname, def) ctf_classes.__classes[cname] = def table.insert(ctf_classes.__classes_ordered, def) - def.max_hp = def.max_hp or 20 - def.speed = def.speed or 1 def.pros = def.pros or {} def.cons = def.cons or {} + + def.properties = def.properties or {} + if def.properties.can_capture == nil then + def.properties.can_capture = true + end + def.properties.speed = def.properties.speed or 1 + def.properties.max_hp = def.properties.max_hp or 20 end function ctf_classes.set_skin(player, color, class) @@ -44,12 +49,17 @@ end local function set_max_hp(player, max_hp) local cur_hp = player:get_hp() - local new_hp = cur_hp + max_hp - player:get_properties().hp_max + local old_max = player:get_properties().hp_max + local new_hp = cur_hp + max_hp - old_max player:set_properties({ hp_max = max_hp }) - assert(new_hp <= max_hp) + if new_hp > max_hp then + minetest.log("error", string.format("New hp %d is larger than new max %d, old max is %d", new_hp, max_hp, old_max)) + new_hp = max_hp + end + if cur_hp > max_hp then player:set_hp(max_hp) elseif new_hp > cur_hp then @@ -59,12 +69,12 @@ end function ctf_classes.update(player) local class = ctf_classes.get(player) - local color, _ = ctf_colors.get_color(ctf.player(player:get_player_name())) + local color = ctf_colors.get_color(ctf.player(player:get_player_name())).text - set_max_hp(player, class.max_hp) + set_max_hp(player, class.properties.max_hp) ctf_classes.set_skin(player, color, class) physics.set(player:get_player_name(), "ctf_classes:speed", { - speed = class.speed, + speed = class.properties.speed, }) end diff --git a/mods/ctf/ctf_classes/gui.lua b/mods/ctf/ctf_classes/gui.lua index 93c9d8b..6eb3bcf 100644 --- a/mods/ctf/ctf_classes/gui.lua +++ b/mods/ctf/ctf_classes/gui.lua @@ -66,9 +66,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) "Move closer to the flag to change classes!") end - for _, class in pairs(ctf_classes.__classes_ordered) do - if fields["select_" .. class.name] then - ctf_classes.set(player, class.name) + for name in pairs(ctf_classes.__classes) do + if fields["select_" .. name] then + ctf_classes.set(player, name) return true end end diff --git a/mods/ctf/ctf_classes/init.lua b/mods/ctf/ctf_classes/init.lua index 14d1455..fdab6f2 100644 --- a/mods/ctf/ctf_classes/init.lua +++ b/mods/ctf/ctf_classes/init.lua @@ -10,29 +10,43 @@ dofile(minetest.get_modpath("ctf_classes") .. "/ranged.lua") ctf_classes.register("knight", { description = "Knight", - pros = { "+10 HP", "+10% melee skill" }, + pros = { "+50% Health Points" }, cons = { "-10% speed" }, - max_hp = 30, color = "#ccc", + properties = { + max_hp = 30, + speed = 0.90, + }, }) ctf_classes.register("shooter", { description = "Shooter", - pros = { "+10% ranged skill", "Can use sniper rifles", "Can use grapling hooks" }, - cons = {}, - speed = 1.1, + pros = { "+10% ranged skill", "Rifles and grappling hooks" }, + cons = { "Can't capture the flag" }, color = "#c60", + properties = { + can_capture = false, + }, }) ctf_classes.register("medic", { description = "Medic", - speed = 1.1, - pros = { "x2 regen for nearby friendlies", "Free bandages" }, - cons = { "Can't capture the flag"}, + pros = { "x2 regen for nearby friendlies" }, + cons = { "-50% Health Points" }, color = "#0af", + properties = { + max_hp = 10, + }, }) -minetest.register_on_joinplayer(ctf_classes.update) + +minetest.register_on_joinplayer(function(player) + ctf_classes.update(player) + + if minetest.check_player_privs(player, { interact = true }) then + ctf_classes.show_gui(player:get_player_name()) + end +end) minetest.register_chatcommand("class", { func = function(name, params) @@ -72,12 +86,20 @@ local flags = { for _, flagname in pairs(flags) do local old_func = minetest.registered_nodes[flagname].on_punch local function on_punch(pos, node, player, ...) - if ctf_classes.get(player).name == "medic" then - local flag = ctf_flag.get(pos) - local team = ctf.player(player:get_player_name()).team - if not flag or not flag.team or not team or team ~= flag.team then - minetest.chat_send_player(player:get_player_name(), - "Medics can't capture the flag!") + local fpos = pos + if node.name:sub(1, 18) == "ctf_flag:flag_top_" then + fpos = vector.new(pos) + fpos.y = fpos.y - 1 + end + + local class = ctf_classes.get(player) + if not class.properties.can_capture then + local pname = player:get_player_name() + local flag = ctf_flag.get(fpos) + local team = ctf.player(pname).team + if flag and flag.team and team and team ~= flag.team then + minetest.chat_send_player(pname, + "You need to change classes to capture the flag!") return end end diff --git a/mods/ctf/ctf_classes/mod.conf b/mods/ctf/ctf_classes/mod.conf index ef91fb4..c0e72d5 100644 --- a/mods/ctf/ctf_classes/mod.conf +++ b/mods/ctf/ctf_classes/mod.conf @@ -1,2 +1,3 @@ name = ctf_classes -depends = ctf, ctf_flag, ctf_colors, physics, shooter +depends = ctf, ctf_flag, ctf_colors, physics, shooter, hpregen +description = Adds classes, including knight, shooter, and medic diff --git a/mods/ctf/ctf_classes/ranged.lua b/mods/ctf/ctf_classes/ranged.lua index 73857f3..4f65452 100644 --- a/mods/ctf/ctf_classes/ranged.lua +++ b/mods/ctf/ctf_classes/ranged.lua @@ -40,7 +40,7 @@ local function check_grapple(itemname) local def = minetest.registered_items[itemname] local old_func = def.on_use minetest.override_item(itemname, { - description = def.description .. "\nCan only be used by Shooters", + description = def.description .. "\n\nCan only be used by Shooters", on_use = function(itemstack, user, ...) if ctf_classes.get(user).name ~= "shooter" then minetest.chat_send_player(user:get_player_name(), @@ -56,3 +56,7 @@ end check_grapple("shooter:grapple_gun_loaded") check_grapple("shooter:grapple_gun") + +minetest.override_item("shooter:rifle", { + description = "Rifle\n\nCan only be used by Shooters", +}) diff --git a/mods/ctf/ctf_classes/regen.lua b/mods/ctf/ctf_classes/regen.lua index bde42a2..6a0a958 100644 --- a/mods/ctf/ctf_classes/regen.lua +++ b/mods/ctf/ctf_classes/regen.lua @@ -1,13 +1,3 @@ -local regen_interval = tonumber(minetest.settings:get("regen_interval")) -if regen_interval <= 0 then - regen_interval = 6 -end - -local regen_amount = tonumber(minetest.settings:get("regen_amount")) -if regen_amount <= 0 then - regen_amount = 1 -end - local function regen_update() local get = ctf_classes.get local players = minetest.get_connected_players() @@ -54,7 +44,7 @@ local function regen_update() local medics = medic_by_team[tname] for j=1, #medics do if sqdist(pos, medics[j]) < 100 then - hp = hp + regen_amount + hp = hp + hpregen.amount player:set_hp(hp) break end @@ -63,13 +53,13 @@ local function regen_update() end end -local update = regen_interval / 2 +local update = hpregen.interval / 2 minetest.register_globalstep(function(delta) update = update + delta - if update < regen_interval then + if update < hpregen.interval then return end - update = update - regen_interval + update = update - hpregen.interval regen_update() end) diff --git a/mods/ctf/ctf_classes/textures/ctf_classes_skin_medic_blue.png b/mods/ctf/ctf_classes/textures/ctf_classes_skin_medic_blue.png index 68ddb3b..15491c5 100644 Binary files a/mods/ctf/ctf_classes/textures/ctf_classes_skin_medic_blue.png and b/mods/ctf/ctf_classes/textures/ctf_classes_skin_medic_blue.png differ diff --git a/mods/ctf/ctf_classes/textures/ctf_classes_skin_medic_red.png b/mods/ctf/ctf_classes/textures/ctf_classes_skin_medic_red.png index 9b72df7..b6294d6 100644 Binary files a/mods/ctf/ctf_classes/textures/ctf_classes_skin_medic_red.png and b/mods/ctf/ctf_classes/textures/ctf_classes_skin_medic_red.png differ diff --git a/mods/other/random_messages/init.lua b/mods/other/random_messages/init.lua index ac4a5c4..83345a6 100644 --- a/mods/other/random_messages/init.lua +++ b/mods/other/random_messages/init.lua @@ -73,7 +73,9 @@ function random_messages.read_messages() "Use bandages on team-mates to heal them by 3-4 HP if their health is below 15 HP.", "Use /m to add a team marker at pointed location, that's visible only to team-mates.", "Use /summary to check scores of the current match and the previous match.", - "Use /maps to view the maps catalog. It also contains license info and attribution details." + "Use /maps to view the maps catalog. It also contains license info and attribution details.", + "Change your class in your base by right clicking the home flag or typing /class.", + "Medics cause nearby troops to regenerate health faster.", } end diff --git a/mods/pvp/hpregen/init.lua b/mods/pvp/hpregen/init.lua index 15222fb..3b83e7e 100644 --- a/mods/pvp/hpregen/init.lua +++ b/mods/pvp/hpregen/init.lua @@ -1,17 +1,19 @@ -local regen_interval = tonumber(minetest.settings:get("regen_interval")) -if regen_interval <= 0 then - regen_interval = 6 +hpregen = {} + +hpregen.interval = tonumber(minetest.settings:get("hpregen.interval")) +if hpregen.interval <= 0 then + hpregen.interval = 6 end -local regen_amount = tonumber(minetest.settings:get("regen_amount")) -if regen_amount <= 0 then - regen_amount = 1 +hpregen.amount = tonumber(minetest.settings:get("hpregen.amount")) +if hpregen.amount <= 0 then + hpregen.amount = 1 end local function regen_all() for _, player in pairs(minetest.get_connected_players()) do local oldhp = player:get_hp() if oldhp > 0 then - local newhp = oldhp + regen_amount + local newhp = oldhp + hpregen.amount if newhp > player:get_properties().hp_max then newhp = player:get_properties().hp_max end @@ -26,10 +28,10 @@ end local update = 0 minetest.register_globalstep(function(delta) update = update + delta - if update < regen_interval then + if update < hpregen.interval then return end - update = update - regen_interval + update = update - hpregen.interval regen_all() end) diff --git a/mods/pvp/medkits/init.lua b/mods/pvp/medkits/init.lua index 9450b29..791ae33 100644 --- a/mods/pvp/medkits/init.lua +++ b/mods/pvp/medkits/init.lua @@ -8,7 +8,7 @@ local players = {} local regen_max = 20 -- Max HP provided by one medkit local regen_interval = 0.5 -- Time in seconds between each iteration -local regen_timer = 0 -- Timer to keep track of regen_interval +local regen_timer = 0 -- Timer to keep track of hpregen.interval local regen_step = 1 -- Number of HP added every iteration -- Boolean function for use by other mods to check if a player is healing @@ -54,7 +54,7 @@ local function stop_healing(player, interrupted) players[name] = nil if interrupted then minetest.chat_send_player(name, minetest.colorize("#FF4444", - "Your healing was interrupted!")) + "Your healing was interrupted!")) player:set_hp(info.hp) player:get_inventory():add_item("main", ItemStack("medkits:medkit 1")) end diff --git a/mods/pvp/shooter/grapple.lua b/mods/pvp/shooter/grapple.lua index a6f2599..4e902fa 100644 --- a/mods/pvp/shooter/grapple.lua +++ b/mods/pvp/shooter/grapple.lua @@ -112,7 +112,7 @@ minetest.register_tool("shooter:grapple_gun_loaded", { end minetest.sound_play("shooter_pistol", {object=user}) itemstack = ItemStack("shooter:grapple_hook 1 "..itemstack:get_wear()) - itemstack:add_wear(65536 / 6) + itemstack:add_wear(65536 / 8) throw_hook(itemstack, user, 20) return "shooter:grapple_gun" end,