2 Commits

Author SHA1 Message Date
e5b8a30cb6 cooldown reduction prototype
I decided to keep cooldown in the same unit as the frame counter,
because the extra math when calculating an upgrade is going to happen
much less frequently than actual cooldown checks and calculations, so
leaving the upgrade logic as the less efficient path seems like the
more appropriate choice.
2025-05-03 16:28:54 -07:00
7ed305d2d9 Ammo quantity upgrade prototype
Not yet tested. Will crash until I also get rate_upgrade_opt up.
2025-05-03 16:06:16 -07:00

View File

@ -676,7 +676,13 @@ bullet_base = mknew{ }
gun_base = mknew{ gun_base = mknew{
shoot_ready = -32768, shoot_ready = -32768,
icon = 20 icon = 20,
ammobonus = 1,
-- fractional frames of
-- cooldown reduction from
-- upgrades, not yet applied
cd_remainder = 0,
} }
-- gun_base subtypes are -- gun_base subtypes are
@ -707,6 +713,68 @@ function gun_base:actually_shoot(x, y)
self.munition.new{}:spawn_at(x, y) self.munition.new{}:spawn_at(x, y)
end end
-- upgrade
function gun_base:small_upgrade_opts()
local ret = {
self:ammo_upgrade_opt(),
self:rate_upgrade_opt(),
}
local s = self.special_upgrade_opt
if (s) add(ret, s(self))
return ret
end
function gun_base:ammo_upgrade_opt()
local a=self.maxammo
local x=a\10+self.ammobonus
return {
icon=self.icon,
hdr=self.hdr,
body=[[----------AMMO
more shots
before you
run out.
is: ]]..tostr(a)..[[
add: ]]..tostr(x)..[[
----------
total: ]]..tostr(a+x),
action=function()
self.maxammo+=x
self.ammo+=x
end,
}
end
function gun_base:rate_upgrade_opt()
local c=self.cooldown<<16
local rawnewc=0.85*(c-self.cd_remainder)
local newc=ceil(rawnewc)
return {
icon=self.icon,
hdr=self.hdr,
body=[[----------RATE
reduce delay
between shots
in frames.
fractions
add up across
upgrades.
is: ]]..tostr(c)..[[
minus: ]]..tostr(c-newc)..[[
----------
total: ]]..tostr(newc),
action=function()
self.cooldown=newc>>16
self.cd_remainder=newc-rawnewc
end,
}
end
function bullet_base:hitship(_) function bullet_base:hitship(_)
self:die() self:die()
return true return true