mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2024-12-26 18:50:21 +01:00
tidy code
This commit is contained in:
parent
b4a8ce71c6
commit
431d3844a6
93
api.lua
93
api.lua
@ -8,11 +8,10 @@ else
|
|||||||
if minetest.get_modpath("intllib") then
|
if minetest.get_modpath("intllib") then
|
||||||
dofile(minetest.get_modpath("intllib") .. "/init.lua")
|
dofile(minetest.get_modpath("intllib") .. "/init.lua")
|
||||||
if intllib.make_gettext_pair then
|
if intllib.make_gettext_pair then
|
||||||
gettext, ngettext = intllib.make_gettext_pair() -- new gettext method
|
S = intllib.make_gettext_pair() -- new gettext method
|
||||||
else
|
else
|
||||||
gettext = intllib.Getter() -- old text file method
|
S = intllib.Getter() -- old text file method
|
||||||
end
|
end
|
||||||
S = gettext
|
|
||||||
else -- boilerplate function
|
else -- boilerplate function
|
||||||
S = function(str, ...)
|
S = function(str, ...)
|
||||||
local args = {...}
|
local args = {...}
|
||||||
@ -28,7 +27,7 @@ local use_cmi = minetest.global_exists("cmi")
|
|||||||
|
|
||||||
mobs = {
|
mobs = {
|
||||||
mod = "redo",
|
mod = "redo",
|
||||||
version = "20220922",
|
version = "20220929",
|
||||||
intllib = S,
|
intllib = S,
|
||||||
invis = minetest.global_exists("invisibility") and invisibility or {}
|
invis = minetest.global_exists("invisibility") and invisibility or {}
|
||||||
}
|
}
|
||||||
@ -111,6 +110,7 @@ local stuck_path_timeout = 5 -- how long will mob follow path before giving up
|
|||||||
local node_ice = "default:ice"
|
local node_ice = "default:ice"
|
||||||
local node_snowblock = "default:snowblock"
|
local node_snowblock = "default:snowblock"
|
||||||
local node_snow = "default:snow"
|
local node_snow = "default:snow"
|
||||||
|
|
||||||
mobs.fallback_node = minetest.registered_aliases["mapgen_dirt"] or "default:dirt"
|
mobs.fallback_node = minetest.registered_aliases["mapgen_dirt"] or "default:dirt"
|
||||||
|
|
||||||
local mob_class = {
|
local mob_class = {
|
||||||
@ -190,15 +190,14 @@ local mob_class_meta = {__index = mob_class}
|
|||||||
-- play sound
|
-- play sound
|
||||||
function mob_class:mob_sound(sound)
|
function mob_class:mob_sound(sound)
|
||||||
|
|
||||||
local pitch = 1.0
|
if sound then
|
||||||
|
|
||||||
-- higher pitch for a child
|
-- higher pitch for a child
|
||||||
if self.child then pitch = pitch * 1.5 end
|
local pitch = self.child and 1.5 or 1.0
|
||||||
|
|
||||||
-- a little random pitch to be different
|
-- a little random pitch to be different
|
||||||
pitch = pitch + random(-10, 10) * 0.005
|
pitch = pitch + random(-10, 10) * 0.005
|
||||||
|
|
||||||
if sound then
|
|
||||||
minetest.sound_play(sound, {
|
minetest.sound_play(sound, {
|
||||||
object = self.object,
|
object = self.object,
|
||||||
gain = 1.0,
|
gain = 1.0,
|
||||||
@ -219,7 +218,7 @@ function mob_class:do_attack(player)
|
|||||||
self.attack = player
|
self.attack = player
|
||||||
self.state = "attack"
|
self.state = "attack"
|
||||||
|
|
||||||
if random(0, 100) < 90 then
|
if random(100) < 90 then
|
||||||
self:mob_sound(self.sounds.war_cry)
|
self:mob_sound(self.sounds.war_cry)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -462,7 +461,7 @@ local line_of_sight = function(self, pos1, pos2, stepsize)
|
|||||||
-- It continues to advance in the line of sight in search of a real
|
-- It continues to advance in the line of sight in search of a real
|
||||||
-- obstruction which counts as 'walkable' nodebox.
|
-- obstruction which counts as 'walkable' nodebox.
|
||||||
while minetest.registered_nodes[nn]
|
while minetest.registered_nodes[nn]
|
||||||
and (minetest.registered_nodes[nn].walkable == false) do
|
and minetest.registered_nodes[nn].walkable == false do
|
||||||
|
|
||||||
-- Check if you can still move forward
|
-- Check if you can still move forward
|
||||||
if td < ad + stepsize then
|
if td < ad + stepsize then
|
||||||
@ -499,53 +498,6 @@ local line_of_sight = function(self, pos1, pos2, stepsize)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- check line of sight (by BrunoMine, tweaked by Astrobe)
|
|
||||||
local new_line_of_sight = function(self, pos1, pos2, stepsize)
|
|
||||||
|
|
||||||
if not pos1 or not pos2 then return end
|
|
||||||
|
|
||||||
stepsize = stepsize or 1
|
|
||||||
|
|
||||||
local stepv = vmultiply(vdirection(pos1, pos2), stepsize)
|
|
||||||
|
|
||||||
local s, pos = minetest.line_of_sight(pos1, pos2, stepsize)
|
|
||||||
|
|
||||||
-- normal walking and flying mobs can see you through air
|
|
||||||
if s == true then return true end
|
|
||||||
|
|
||||||
-- New pos1 to be analyzed
|
|
||||||
local npos1 = {x = pos1.x, y = pos1.y, z = pos1.z}
|
|
||||||
|
|
||||||
local r, pos = minetest.line_of_sight(npos1, pos2, stepsize)
|
|
||||||
|
|
||||||
-- Checks the return
|
|
||||||
if r == true then return true end
|
|
||||||
|
|
||||||
-- Nodename found
|
|
||||||
local nn = minetest.get_node(pos).name
|
|
||||||
|
|
||||||
-- It continues to advance in the line of sight in search of a real
|
|
||||||
-- obstruction which counts as 'walkable' nodebox.
|
|
||||||
while minetest.registered_nodes[nn]
|
|
||||||
and (minetest.registered_nodes[nn].walkable == false) do
|
|
||||||
|
|
||||||
npos1 = vadd(npos1, stepv)
|
|
||||||
|
|
||||||
if get_distance(npos1, pos2) < stepsize then return true end
|
|
||||||
|
|
||||||
-- scan again
|
|
||||||
r, pos = minetest.line_of_sight(npos1, pos2, stepsize)
|
|
||||||
|
|
||||||
if r == true then return true end
|
|
||||||
|
|
||||||
-- New Nodename found
|
|
||||||
nn = minetest.get_node(pos).name
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
-- check line of sight using raycasting (thanks Astrobe)
|
-- check line of sight using raycasting (thanks Astrobe)
|
||||||
local ray_line_of_sight = function(self, pos1, pos2)
|
local ray_line_of_sight = function(self, pos1, pos2)
|
||||||
|
|
||||||
@ -611,8 +563,7 @@ function mob_class:attempt_flight_correction(override)
|
|||||||
local escape_target = flyable_nodes[random(#flyable_nodes)]
|
local escape_target = flyable_nodes[random(#flyable_nodes)]
|
||||||
local escape_direction = vdirection(pos, escape_target)
|
local escape_direction = vdirection(pos, escape_target)
|
||||||
|
|
||||||
self.object:set_velocity(
|
self.object:set_velocity(vmultiply(escape_direction, 1))
|
||||||
vmultiply(escape_direction, 1))
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -1088,11 +1039,6 @@ end
|
|||||||
-- environmental damage (water, lava, fire, light etc.)
|
-- environmental damage (water, lava, fire, light etc.)
|
||||||
function mob_class:do_env_damage()
|
function mob_class:do_env_damage()
|
||||||
|
|
||||||
-- feed/tame text timer (so mob 'full' messages dont spam chat)
|
|
||||||
if self.htimer > 0 then
|
|
||||||
self.htimer = self.htimer - 1
|
|
||||||
end
|
|
||||||
|
|
||||||
self:update_tag()
|
self:update_tag()
|
||||||
|
|
||||||
local pos = self.object:get_pos() ; if not pos then return end
|
local pos = self.object:get_pos() ; if not pos then return end
|
||||||
@ -1739,7 +1685,7 @@ function mob_class:smart_mobs(s, p, dist, dtime)
|
|||||||
end -- can see target!
|
end -- can see target!
|
||||||
end
|
end
|
||||||
|
|
||||||
if (self.path.stuck_timer > stuck_timeout and not self.path.following) then
|
if self.path.stuck_timer > stuck_timeout and not self.path.following then
|
||||||
|
|
||||||
use_pathfind = true
|
use_pathfind = true
|
||||||
self.path.stuck_timer = 0
|
self.path.stuck_timer = 0
|
||||||
@ -1755,7 +1701,7 @@ function mob_class:smart_mobs(s, p, dist, dtime)
|
|||||||
end, self)
|
end, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
if (self.path.stuck_timer > stuck_path_timeout and self.path.following) then
|
if self.path.stuck_timer > stuck_path_timeout and self.path.following then
|
||||||
|
|
||||||
use_pathfind = true
|
use_pathfind = true
|
||||||
self.path.stuck_timer = 0
|
self.path.stuck_timer = 0
|
||||||
@ -1771,7 +1717,7 @@ function mob_class:smart_mobs(s, p, dist, dtime)
|
|||||||
end, self)
|
end, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
if abs(vsubtract(s,target_pos).y) > self.stepheight then
|
if abs(vsubtract(s, target_pos).y) > self.stepheight then
|
||||||
|
|
||||||
if height_switcher then
|
if height_switcher then
|
||||||
use_pathfind = true
|
use_pathfind = true
|
||||||
@ -1833,6 +1779,7 @@ function mob_class:smart_mobs(s, p, dist, dtime)
|
|||||||
print("-- path length:" .. tonumber(#self.path.way))
|
print("-- path length:" .. tonumber(#self.path.way))
|
||||||
|
|
||||||
for _,pos in pairs(self.path.way) do
|
for _,pos in pairs(self.path.way) do
|
||||||
|
|
||||||
minetest.add_particle({
|
minetest.add_particle({
|
||||||
pos = pos,
|
pos = pos,
|
||||||
velocity = {x=0, y=0, z=0},
|
velocity = {x=0, y=0, z=0},
|
||||||
@ -2513,8 +2460,7 @@ function mob_class:do_states(dtime)
|
|||||||
self.object:set_texture_mod(self.texture_mods)
|
self.object:set_texture_mod(self.texture_mods)
|
||||||
else
|
else
|
||||||
|
|
||||||
self.object:set_texture_mod(self.texture_mods
|
self.object:set_texture_mod(self.texture_mods .. "^[brighten")
|
||||||
.. "^[brighten")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.blinkstatus = not self.blinkstatus
|
self.blinkstatus = not self.blinkstatus
|
||||||
@ -3319,8 +3265,7 @@ function mob_class:mob_activate(staticdata, def, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if use_cmi then
|
if use_cmi then
|
||||||
self._cmi_components = cmi.activate_components(
|
self._cmi_components = cmi.activate_components(self.serialized_cmi_components)
|
||||||
self.serialized_cmi_components)
|
|
||||||
cmi.notify_activate(self.object, dtime)
|
cmi.notify_activate(self.object, dtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -3440,8 +3385,8 @@ function mob_class:on_step(dtime, moveresult)
|
|||||||
if yaw > self.target_yaw then
|
if yaw > self.target_yaw then
|
||||||
|
|
||||||
if dif > pi then
|
if dif > pi then
|
||||||
dif = 2 * pi - dif -- need to add
|
dif = 2 * pi - dif
|
||||||
yaw = yaw + dif / self.delay
|
yaw = yaw + dif / self.delay -- need to add
|
||||||
else
|
else
|
||||||
yaw = yaw - dif / self.delay -- need to subtract
|
yaw = yaw - dif / self.delay -- need to subtract
|
||||||
end
|
end
|
||||||
@ -4382,7 +4327,7 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@ -4444,7 +4389,7 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -492,6 +492,7 @@ function mobs.fly(entity, _, speed, shoots, arrow, moving_anim, stand_anim)
|
|||||||
|
|
||||||
ent.switch = 1 -- for mob specific arrows
|
ent.switch = 1 -- for mob specific arrows
|
||||||
ent.owner_id = tostring(entity.object) -- so arrows dont hurt entity you are riding
|
ent.owner_id = tostring(entity.object) -- so arrows dont hurt entity you are riding
|
||||||
|
|
||||||
local vec = {x = dir.x * 6, y = dir.y * 6, z = dir.z * 6}
|
local vec = {x = dir.x * 6, y = dir.y * 6, z = dir.z * 6}
|
||||||
|
|
||||||
yaw = entity.driver:get_look_horizontal()
|
yaw = entity.driver:get_look_horizontal()
|
||||||
|
Loading…
Reference in New Issue
Block a user