mirror of
https://github.com/ElCeejo/creatura.git
synced 2025-03-15 04:11:24 +00:00
Add Utility Cooldown, Boid improvement
This commit is contained in:
parent
6cd34a727d
commit
de5ddbd4c1
2 changed files with 31 additions and 5 deletions
|
@ -110,8 +110,9 @@ function creatura.get_boid_dir(self)
|
||||||
local closest_pos
|
local closest_pos
|
||||||
for _, object in ipairs(boids) do
|
for _, object in ipairs(boids) do
|
||||||
if object then
|
if object then
|
||||||
boid_pos, vel = object:get_pos(), vector.normalize(object:get_velocity())
|
boid_pos, vel = object:get_pos(), object:get_velocity()
|
||||||
if boid_pos then
|
if boid_pos then
|
||||||
|
vel = vec_normal(vel)
|
||||||
local obj_yaw = object:get_yaw()
|
local obj_yaw = object:get_yaw()
|
||||||
pos_no, pos_sum = pos_no + 1, vec_add(pos_sum, boid_pos)
|
pos_no, pos_sum = pos_no + 1, vec_add(pos_sum, boid_pos)
|
||||||
sum_sin, sum_cos = sum_sin + sin(obj_yaw), sum_cos + cos(obj_yaw)
|
sum_sin, sum_cos = sum_sin + sin(obj_yaw), sum_cos + cos(obj_yaw)
|
||||||
|
|
33
mob_meta.lua
33
mob_meta.lua
|
@ -492,7 +492,8 @@ end
|
||||||
|
|
||||||
function mob:set_mesh(id)
|
function mob:set_mesh(id)
|
||||||
local mesh = self.mesh
|
local mesh = self.mesh
|
||||||
if mesh then
|
if mesh
|
||||||
|
and not self.meshes then
|
||||||
self.object:set_properties({
|
self.object:set_properties({
|
||||||
mesh = mesh
|
mesh = mesh
|
||||||
})
|
})
|
||||||
|
@ -504,6 +505,13 @@ function mob:set_mesh(id)
|
||||||
self.object:set_properties({
|
self.object:set_properties({
|
||||||
mesh = meshes[mesh_no]
|
mesh = meshes[mesh_no]
|
||||||
})
|
})
|
||||||
|
self:memorize("mesh_no", self.mesh_no)
|
||||||
|
if self.mesh_textures then
|
||||||
|
self.textures = self.mesh_textures[mesh_no]
|
||||||
|
self.texture_no = random(#self.textures)
|
||||||
|
self:set_texture(self.texture_no, self.textures)
|
||||||
|
self:memorize("texture_no", self.texture_no)
|
||||||
|
end
|
||||||
return meshes[mesh_no]
|
return meshes[mesh_no]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1116,6 +1124,7 @@ function mob:_execute_utilities()
|
||||||
step_delay = nil,
|
step_delay = nil,
|
||||||
score = 0
|
score = 0
|
||||||
}
|
}
|
||||||
|
self._util_cooldown = {}
|
||||||
end
|
end
|
||||||
local loop_data = {
|
local loop_data = {
|
||||||
utility = nil,
|
utility = nil,
|
||||||
|
@ -1130,13 +1139,20 @@ function mob:_execute_utilities()
|
||||||
local util_stack = self.utility_stack
|
local util_stack = self.utility_stack
|
||||||
local utility
|
local utility
|
||||||
local get_score
|
local get_score
|
||||||
|
local cooldown
|
||||||
local step_delay
|
local step_delay
|
||||||
local score, args
|
local score, args
|
||||||
for i = 1, #util_stack do
|
for i = 1, #util_stack do
|
||||||
utility = util_stack[i].utility
|
utility = util_stack[i].utility
|
||||||
get_score = util_stack[i].get_score
|
get_score = util_stack[i].get_score
|
||||||
|
cooldown = self._util_cooldown[i] or 0
|
||||||
step_delay = util_stack[i].step_delay
|
step_delay = util_stack[i].step_delay
|
||||||
score, args = get_score(self)
|
score, args = get_score(self)
|
||||||
|
|
||||||
|
if cooldown > 0 then
|
||||||
|
cooldown = cooldown - (self.util_timer or 1)
|
||||||
|
end
|
||||||
|
|
||||||
if util_data.utility
|
if util_data.utility
|
||||||
and utility == util_data.utility
|
and utility == util_data.utility
|
||||||
and util_data.score > 0
|
and util_data.score > 0
|
||||||
|
@ -1149,16 +1165,21 @@ function mob:_execute_utilities()
|
||||||
}
|
}
|
||||||
util_data = self._utility_data
|
util_data = self._utility_data
|
||||||
end
|
end
|
||||||
|
|
||||||
if score > 0
|
if score > 0
|
||||||
and score >= util_data.score
|
and score >= util_data.score
|
||||||
and score >= loop_data.score then
|
and score >= loop_data.score
|
||||||
|
and cooldown <= 0 then
|
||||||
loop_data = {
|
loop_data = {
|
||||||
utility = utility,
|
utility = utility,
|
||||||
score = score,
|
score = score,
|
||||||
|
util_no = i,
|
||||||
step_delay = step_delay,
|
step_delay = step_delay,
|
||||||
args = args
|
args = args
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self._util_cooldown[i] = cooldown
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if loop_data.utility
|
if loop_data.utility
|
||||||
|
@ -1209,7 +1230,11 @@ function mob:_execute_utilities()
|
||||||
and self.vert_vel ~= 0 then
|
and self.vert_vel ~= 0 then
|
||||||
self:set_vertical_velocity(nil)
|
self:set_vertical_velocity(nil)
|
||||||
end
|
end
|
||||||
if func(self) then
|
local func_complete, func_cooldown = func(self)
|
||||||
|
if func_complete then
|
||||||
|
if util_data.util_no then
|
||||||
|
self._util_cooldown[util_data.util_no] = func_cooldown
|
||||||
|
end
|
||||||
self._utility_data = {
|
self._utility_data = {
|
||||||
utility = nil,
|
utility = nil,
|
||||||
func = nil,
|
func = nil,
|
||||||
|
@ -1249,8 +1274,8 @@ function mob:_vitals()
|
||||||
else
|
else
|
||||||
local resist = self.fall_resistance or 0
|
local resist = self.fall_resistance or 0
|
||||||
damage = damage - damage * resist
|
damage = damage - damage * resist
|
||||||
fall_start = nil
|
|
||||||
end
|
end
|
||||||
|
fall_start = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self._fall_start = fall_start
|
self._fall_start = fall_start
|
||||||
|
|
Loading…
Add table
Reference in a new issue