master
Lean Rada 2015-01-26 02:06:09 +08:00
parent 4cf28830d6
commit cfb7ea288c
7 changed files with 59 additions and 48 deletions

View File

@ -25,7 +25,7 @@ director.spawn_list = {
group_max = 24,
probability = 0.8,
day_start = 1,
spawn_time = 40.0,
spawn_time = 41.0,
spawn_location = "ground",
},
{
@ -49,7 +49,7 @@ director.spawn_list = {
group_max = 1,
probability = 0.2,
day_start = 3,
spawn_time = 19.0,
spawn_time = 90.0,
spawn_location = "ground",
},
{
@ -58,15 +58,15 @@ director.spawn_list = {
intensity_min = 0,
intensity_max = 0.1,
group_min = 1,
--
probability = 0.1,
group_max = 1,
probability = 0.1,
day_start = 1,
spawn_time = 21.0,
spawn_time = 90.0,
spawn_location = "air",
},
}
-- State tracking stuff
director.intensity = 0.5
director.cooldown_timer = 3
@ -74,18 +74,15 @@ local spawn_timers = {}
local last_average_health = 1.0
local last_mob_count = 0
for i,m in ipairs(director.spawn_list) do
for _,m in ipairs(director.spawn_list) do
spawn_timers[m.description] = m.spawn_time/2
end
function director:on_interval()
self:update_intensity()
if defense.debug then
minetest.chat_send_all("Intensity: " .. self.intensity)
end
if self.cooldown_timer <= 0 then
if defense:is_dark() and #minetest.luaentities < self.max_entities then
if defense:is_dark() and #minetest.luaentities < self.max_entities and not defense.debug then
self:spawn_monsters()
end

View File

@ -17,6 +17,16 @@ minetest.register_chatcommand("debug", {
end,
})
function minetest.wallmounted_to_dir(wallmounted)
return ({[0]={x=0, y=1, z=0},
{x=0, y=-1, z=0},
{x=1, y=0, z=0},
{x=-1, y=0, z=0},
{x=0, y=0, z=1},
{x=0, y=0, z=-1}})
[wallmounted]
end
local modpath = minetest.get_modpath("defense")
local function dofile2(file)
dofile(modpath .. "/" .. file)
@ -24,7 +34,7 @@ end
function defense:is_dark()
local tod = minetest.get_timeofday()
return tod < 0.22 or tod > 0.8 or defense.debug
return tod < 0.21 or tod > 0.8 or defense.debug
end
dofile2("mob.lua")

View File

@ -149,9 +149,10 @@ function mobs.default_prototype:jump(direction)
direction = vector.normalize(direction)
local v = self.object:getvelocity()
v.y = math.sqrt(2 * -mobs.gravity * (self.jump_height + 0.2))
v.x = direction.x * v.y
v.z = direction.z * v.y
self.object:setvelocity(v)
v.x = direction.x * self.jump_height
v.z = direction.z * self.jump_height
self.object:setvelocity(vector.add(self.object:getvelocity(), v))
self.object:setyaw(math.atan2(direction.z, direction.x))
self:set_animation("jump")
end
end
@ -248,7 +249,7 @@ function mobs.move_method:air(dtime, destination)
if vector.length(v) < self.move_speed * 1.5 then
t = math.pow(0.1, dtime)
else
t = math.pow(0.9, dtime)
t = math.pow(0.8, dtime)
speed = speed * 0.9
end
self.object:setvelocity(vector.add(
@ -265,7 +266,7 @@ function mobs.move_method:air(dtime, destination)
yaw_delta = yaw_delta - math.pi * 2
end
self.object:setyaw(yaw + yaw_delta * (1-t))
self:set_animation("move", {"move_attack"})
self:set_animation("move", {"attack", "move_attack"})
else
self:set_animation("idle", {"attack", "move_attack"})
end
@ -286,10 +287,10 @@ function mobs.move_method:ground(dtime, destination)
local speed = self.move_speed * math.max(0, math.min(1, 0.8 * dist))
local t
local v = self.object:getvelocity()
if self:is_standing() and vector.length(v) < self.move_speed * 3 then
if self:is_standing() and vector.length(v) < self.move_speed * 4 then
t = math.pow(0.001, dtime)
else
t = math.pow(0.9, dtime)
t = math.pow(0.7, dtime)
speed = speed * 0.9
end
local dir = vector.normalize(delta)
@ -309,6 +310,7 @@ function mobs.move_method:ground(dtime, destination)
local sz = self.collisionbox[6] - self.collisionbox[3]
local r = math.sqrt(sx*sx + sz*sz)/2 + 0.5
local fronts = {
{x = dir.x * self.jump_height, y = 0, z = dir.z * self.jump_height},
{x = dir.x * r, y = 0, z = dir.z * r},
{x = dir.x + dir.z * r, y = 0, z = dir.z + dir.x * r},
{x = dir.x - dir.z * r, y = 0, z = dir.z - dir.x * r},
@ -323,7 +325,7 @@ function mobs.move_method:ground(dtime, destination)
end
if jump then
self:jump(dir)
self:jump(vector.direction(self.object:getpos(), destination))
elseif self:is_standing() then
if speed > self.move_speed * 0.06 then
local yaw = self.object:getyaw()

View File

@ -34,9 +34,9 @@ local function place_goo(pos, life)
end
end
if dir then
local facedir = minetest.dir_to_facedir(dir, true)
local wallmounted = minetest.dir_to_wallmounted(dir)
if minetest.registered_nodes[node.name].buildable_to then
minetest.set_node(pos, {name="defense:goo", param2=facedir})
minetest.set_node(pos, {name="defense:goo", param2=wallmounted})
minetest.get_meta(pos):set_int("life", life)
return true
end
@ -94,7 +94,7 @@ local function spread_goo(pos)
local dir = nil
if node.name == "defense:goo" then
dir = minetest.facedir_to_dir(node.param2)
dir = minetest.wallmounted_to_dir(node.param2)
else
dir = dirs[4]
end
@ -130,9 +130,9 @@ defense.mobs.register_mob("defense:botete", {
animation = {
idle = {a=0, b=39, rate=20},
attack = {a=40, b=79, rate=50},
attack = {a=80, b=99, rate=25},
move = {a=40, b=79, rate=25},
move_attack = {a=40, b=79, rate=25},
move_attack = {a=80, b=99, rate=25},
},
mass = 1,
@ -216,7 +216,7 @@ minetest.register_entity("defense:gooball", {
space = vector.add(space, back)
bnode = minetest.get_node_or_nil(space)
until not bnode or bnode.name == "air"
place_goo(space, 12)
place_goo(space, 6)
self.object:remove()
end
end,
@ -233,10 +233,10 @@ minetest.register_node("defense:goo", {
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, 0.5-2/16, 0.5, 0.5, 0.5},
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5+2/16, 0.5},
},
paramtype = "light",
paramtype2 = "facedir",
paramtype2 = "wallmounted",
liquid_viscosity = 4,
liquidtype = "source",
liquid_alternative_flowing = "defense:goo",

View File

@ -6,7 +6,7 @@ defense.mobs.register_mob("defense:sarangay", {
textures = {"defense_sarangay.png"},
makes_footstep_sound = true,
animation = nil,
animation = {},
normal_animation = {
idle = {a=0, b=19, rate=10},
@ -28,7 +28,7 @@ defense.mobs.register_mob("defense:sarangay", {
},
mass = 12,
move_speed = 4,
move_speed = 6,
jump_height = 1,
armor = 0,
attack_damage = 4,
@ -46,20 +46,22 @@ defense.mobs.register_mob("defense:sarangay", {
on_step = function(self, dtime)
defense.mobs.default_prototype.on_step(self, dtime)
if self.charging then
minetest.chat_send_all(self.charge_power)
if self.charge_power > 0.5 then
self:hunt()
end
-- Break obstacles
local pos = self.object:getpos()
pos.y = pos.y + 2.5
pos.y = pos.y + 1.5
local v = self.object:getvelocity()
v.y = 0
pos = vector.add(pos, vector.multiply(vector.normalize(v), 1.5))
self.charge_power = self:crash_blocks(pos, 4, self.charge_power/2) * 2
self.charge_power = self:crash_entities(pos, 3, self.charge_power/3) * 3
self.charge_power = self:crash_blocks(pos, 3, self.charge_power)
self.charge_power = self:crash_entities(pos, 3, self.charge_power * 4) / 4
if self.charge_power < 0 or (self.charge_power > 1 and vector.length(self.object:getvelocity()) < self.move_speed/4) then
if self.charge_power <= 0 or (self.charge_power > 1 and vector.length(self.object:getvelocity()) < self.move_speed/4) then
self:set_charging_state(false)
self.destination = nil
else
@ -68,16 +70,15 @@ defense.mobs.register_mob("defense:sarangay", {
else
local nearest = self:find_nearest_player()
if nearest then
if math.abs(self.object:getpos().y - nearest.player:getpos().y) < 4 then
if math.random() < 0.1 then
if math.abs(self.object:getpos().y - nearest.position.y) < 4 then
if nearest.distance > 4 and math.random() < 0.1 then
self:set_charging_state(true)
self.destination = nil
elseif nearest.distance < 4 then
self:hunt()
elseif not self.destination then
local nearest_pos = nearest.player:getpos()
local dir = vector.direction(nearest_pos, self.object:getpos())
self.destination = vector.add(nearest_pos, vector.multiply(dir, math.random() * 16))
else
local dir = vector.direction(nearest.position, self.object:getpos())
self.destination = vector.add(nearest.position, vector.multiply(dir, 12))
end
else
self:hunt()
@ -87,14 +88,15 @@ defense.mobs.register_mob("defense:sarangay", {
end,
set_charging_state = function(self, state)
minetest.chat_send_all(dump(state))
self.charging = state
if state then
self.charge_power = 0
self.move_speed = 8
self.charge_power = 0.1
self.move_speed = 9
self.animation = self.charging_animation
self:set_animation("charge")
else
self.move_speed = 4
self.move_speed = 6
self.animation = self.normal_animation
self:set_animation("attack")
end
@ -138,7 +140,7 @@ defense.mobs.register_mob("defense:sarangay", {
local e = o:get_luaentity()
if e then
local m = e.mass or 1
local m = e.mass or 10
local v = vector.add(o:getvelocity(), vector.multiply(myv, 1/m))
if v then
local dir = vector.direction(self.object:getpos(), o:getpos())
@ -160,11 +162,11 @@ defense.mobs.register_mob("defense:sarangay", {
get_node_wear = function(self, pos)
local node = minetest.get_node_or_nil(pos)
local groupwear = {
crumbly = {[1]=0.5, [2]=0.1, [3]=0.1},
fleshy = {[1]=1, [2]=0.5, [3]=0.1},
snappy = {[1]=1.5, [2]=1, [3]=0.5},
choppy = {[1]=2, [2]=1, [3]=0.5},
cracky = {[1]=4, [2]=2, [3]=1},
crumbly = {[1]=2, [2]=1, [3]=1},
fleshy = {[1]=3, [2]=2, [3]=1},
snappy = {[1]=4, [2]=3.5, [3]=3},
choppy = {[1]=5, [2]=4.5, [3]=4},
cracky = {[1]=6, [2]=5, [3]=4},
}
if node then
local wear = 0