Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lua minigame for micrometeorites point defense #1886

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions scripts/locale/utils_micrometeorites.de.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2023-11-20 11:57+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: de_DE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.1.1\n"
"X-Poedit-Basepath: .\n"

#: scripts/utils_micrometeorites.lua:26 scripts/utils_micrometeorites.lua:91
#: scripts/utils_micrometeorites.lua:118
msgid "MicroMeteorite Defense"
msgstr "Mikrometeoriten-Abwehr"

#: scripts/utils_micrometeorites.lua:27 scripts/utils_micrometeorites.lua:92
#: scripts/utils_micrometeorites.lua:119
msgid "Left"
msgstr "Links"

#: scripts/utils_micrometeorites.lua:28 scripts/utils_micrometeorites.lua:93
#: scripts/utils_micrometeorites.lua:120
msgid "Right"
msgstr "Rechts"

#: scripts/utils_micrometeorites.lua:54
msgid "!!! IMPACT IMMINENT !!!"
msgstr "!!! EINSCHLAG STEHT BEVOR !!!"

#: scripts/utils_micrometeorites.lua:68
msgid "Left in"
msgstr "Links in"

#: scripts/utils_micrometeorites.lua:70
msgid "Right in"
msgstr "Rechts in"
140 changes: 140 additions & 0 deletions scripts/utils_micrometeorites.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
-- Utils for micrometeorite point defense
-----------
-- Usage --
-----------
-- Place this line somewhere in the update function:
-- MicroMeteorites:updateAll(delta)

-- To add MicroMeteorites to a ship
-- MicroMeteorites:init([playership])

-- To remove MicroMeteorites from a ship:
-- MicroMeteorites:remove([playership])

require('utils.lua')

MicroMeteorites ={}

function MicroMeteorites:init(player_ship)
player_ship.micrometeorite_impact_time=5 -- time to react after warning
player_ship.micrometeorite_delay_min=20 -- minimal...
player_ship.micrometeorite_delay_max=30 -- ...and maximal delay between two impact warnings

player_ship.micrometeorite_impact_countdown=player_ship.micrometeorite_impact_time
player_ship.micrometeorite_time=math.random(player_ship.micrometeorite_delay_min,player_ship.micrometeorite_delay_max)
player_ship.micrometeorite_phase = 1

player_ship:addCustomInfo("Weapons","point_defense_info",_("MicroMeteorite Defense"),10)
player_ship:addCustomButton("Weapons","point_defense_btn_left","« ".._("Left"),function () MicroMeteorites:fired(1,player_ship) end,11)
player_ship:addCustomButton("Weapons","point_defense_btn_right","» ".._("Right"),function () MicroMeteorites:fired(2,player_ship) end,12)
end

function MicroMeteorites:remove(player_ship)
player_ship:removeCustom("point_defense_info")
player_ship:removeCustom("point_defense_btn_left")
player_ship:removeCustom("point_defense_btn_right")
player_ship.micrometeorite_phase = 0
end


function MicroMeteorites:update(delta,player_ship)
if player_ship.micrometeorite_phase == 1 then
MicroMeteorites:timer(delta,player_ship)
end
if player_ship.micrometeorite_phase == 2 then
MicroMeteorites:incoming(delta,player_ship)
end
end

function MicroMeteorites:updateAll(delta)
for _, p in ipairs(getActivePlayerShips()) do
if p ~= nil then
MicroMeteorites:update(delta,p)
end
end
end

function MicroMeteorites:timer(delta,player_ship)
if (not player_ship:getShieldsActive()) and player_ship:hasPlayerAtPosition("Weapons") then -- do not bother the player when shields are up or no weapons officer is around (tactical and single pilot are busy enough)
player_ship.micrometeorite_time = player_ship.micrometeorite_time - delta
if player_ship.micrometeorite_time <= 0 then
player_ship.micrometeorite_direction = math.random(1,2)
player_ship.micrometeorite_phase = 2
player_ship:addCustomInfo("Weapons","point_defense_info",_("!!! IMPACT IMMINENT !!!"),10)
end
end

end

function MicroMeteorites:incoming(delta,player_ship)

player_ship.micrometeorite_impact_time=player_ship.micrometeorite_impact_time-delta

if player_ship.micrometeorite_impact_time < player_ship.micrometeorite_impact_countdown-1 then
player_ship.micrometeorite_impact_countdown=player_ship.micrometeorite_impact_countdown-1
if player_ship.micrometeorite_direction==1 then
player_ship:addCustomButton("Weapons","point_defense_btn_left","« ".._("Left in").." "..(player_ship.micrometeorite_impact_countdown),function () MicroMeteorites:fired(1,player_ship) end,11)
else
player_ship:addCustomButton("Weapons","point_defense_btn_right","« ".._("Right in").." "..(player_ship.micrometeorite_impact_countdown),function () MicroMeteorites:fired(2,player_ship) end,12)
end
end

if player_ship.micrometeorite_impact_time <= 0 then
player_ship.micrometeorite_impact_time=5
x, y = player_ship:getPosition()
if player_ship.micrometeorite_direction==1 then
explosion_angle=math.random(315,350)+player_ship:getRotation()
else if player_ship.micrometeorite_direction==2 then
explosion_angle=math.random(10,45)+player_ship:getRotation()
end
end
xx, yy = vectorFromAngle(explosion_angle, 150)
ExplosionEffect():setPosition(x+xx,y+yy):setSize(10)
player_ship:takeDamage(5,"kinetic",x+xx,y+yy)

player_ship.micrometeorite_impact_countdown=5
player_ship.micrometeorite_time=math.random(player_ship.micrometeorite_delay_min,player_ship.micrometeorite_delay_max)

--reset info and buttons
player_ship:addCustomInfo("Weapons","point_defense_info",_("MicroMeteorite Defense"),10)
player_ship:addCustomButton("Weapons","point_defense_btn_left","« ".._("Left"),function () MicroMeteorites:fired(1,player_ship) end,11)
player_ship:addCustomButton("Weapons","point_defense_btn_right","» ".._("Right"),function () MicroMeteorites:fired(2,player_ship) end,12)

player_ship.micrometeorite_phase=1
end

end

function MicroMeteorites:fired(button_direction,player_ship)
if player_ship:getSystemHeat("beamweapons")<0.99 and player_ship:getSystemHealth("beamweapons")>0.0 and player_ship:getSystemPower("beamweapons")>0.1 then
x, y = player_ship:getPosition()
if button_direction==1 then
beam_angle=math.random(315,350)+player_ship:getRotation()
else if button_direction==2 then
beam_angle=math.random(10,45)+player_ship:getRotation()
end
end
xx, yy = vectorFromAngle(beam_angle, 200*player_ship.micrometeorite_impact_time+100)
debris=Artifact():setPosition(x+xx, y+yy):setRadarTraceColor(255,200,100);
if player_ship.micrometeorite_direction==button_direction then
player_ship.micrometeorite_impact_time=5
player_ship.micrometeorite_impact_countdown=5
player_ship.micrometeorite_time=math.random(player_ship.micrometeorite_delay_min,player_ship.micrometeorite_delay_max)

--reset info and buttons
player_ship:addCustomInfo("Weapons","point_defense_info",_("MicroMeteorite Defense"),10)
player_ship:addCustomButton("Weapons","point_defense_btn_left","« ".._("Left"),function () MicroMeteorites:fired(1,player_ship) end,11)
player_ship:addCustomButton("Weapons","point_defense_btn_right","» ".._("Right"),function () MicroMeteorites:fired(2,player_ship) end,12)

player_ship.micrometeorite_phase=1
BeamEffect():setSource(player_ship, 0, 0, 0):setTarget(debris, 0, 0):setDuration(0.5):setRing(false):setTexture("texture/beam_blue.png"):setBeamFireSoundPower(0.1)
ExplosionEffect():setPosition(x+xx,y+yy):setSize(5)
player_ship.micrometeorite_direction=0
else
BeamEffect():setSource(player_ship, 0, 0, 0):setTarget(debris, 0, 0):setDuration(0.5):setRing(false):setTexture("texture/beam_blue.png"):setBeamFireSoundPower(0.1)
player_ship:setSystemHeat("beamweapons", player_ship:getSystemHeat("beamweapons")+0.1) -- some heat to prevent button spamming
end
debris:destroy()
end
end

Loading