2019-05-22 22:57:34 -05:00
|
|
|
local Piece = require 'tetris.components.piece'
|
2020-12-04 19:36:11 -06:00
|
|
|
local Ruleset = require 'tetris.rulesets.arika_srs'
|
2019-05-22 22:57:34 -05:00
|
|
|
|
|
|
|
local SRS = Ruleset:extend()
|
|
|
|
|
2020-12-02 23:26:36 -06:00
|
|
|
SRS.name = "SRS-X"
|
|
|
|
SRS.hash = "StandardEXP"
|
|
|
|
SRS.world = true
|
|
|
|
SRS.colourscheme = {
|
|
|
|
I = "C",
|
|
|
|
L = "O",
|
|
|
|
J = "B",
|
|
|
|
S = "G",
|
|
|
|
Z = "R",
|
|
|
|
O = "Y",
|
|
|
|
T = "M",
|
|
|
|
}
|
2021-01-28 20:05:36 -06:00
|
|
|
SRS.softdrop_lock = true
|
|
|
|
SRS.harddrop_lock = false
|
2019-05-22 22:57:34 -05:00
|
|
|
|
|
|
|
SRS.enable_IRS_wallkicks = true
|
|
|
|
|
2020-12-02 23:26:36 -06:00
|
|
|
SRS.MANIPULATIONS_MAX = 24
|
|
|
|
SRS.ROTATIONS_MAX = 12
|
2020-12-27 21:41:26 -06:00
|
|
|
|
2021-01-08 15:46:19 -06:00
|
|
|
function SRS:checkNewLow(piece)
|
2020-11-06 19:49:44 -06:00
|
|
|
for _, block in pairs(piece:getBlockOffsets()) do
|
|
|
|
local y = piece.position.y + block.y
|
|
|
|
if y > piece.lowest_y then
|
2021-01-30 15:49:52 -06:00
|
|
|
--piece.manipulations = 0
|
|
|
|
--piece.rotations = 0
|
2020-11-06 19:49:44 -06:00
|
|
|
piece.lowest_y = y
|
|
|
|
end
|
|
|
|
end
|
2020-10-20 23:30:28 -05:00
|
|
|
end
|
|
|
|
|
2020-12-05 16:15:28 -06:00
|
|
|
-- Component functions.
|
|
|
|
|
|
|
|
function SRS:attemptWallkicks(piece, new_piece, rot_dir, grid)
|
|
|
|
|
|
|
|
local kicks
|
|
|
|
if piece.shape == "O" then
|
|
|
|
return
|
|
|
|
elseif piece.shape == "I" then
|
|
|
|
kicks = SRS.wallkicks_line[piece.rotation][new_piece.rotation]
|
|
|
|
else
|
|
|
|
kicks = SRS.wallkicks_3x3[piece.rotation][new_piece.rotation]
|
|
|
|
end
|
|
|
|
|
|
|
|
assert(piece.rotation ~= new_piece.rotation)
|
|
|
|
|
|
|
|
for idx, offset in pairs(kicks) do
|
|
|
|
kicked_piece = new_piece:withOffset(offset)
|
|
|
|
if grid:canPlacePiece(kicked_piece) then
|
|
|
|
piece:setRelativeRotation(rot_dir)
|
|
|
|
piece:setOffset(offset)
|
|
|
|
self:onPieceRotate(piece, grid)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
function SRS:onPieceCreate(piece, grid)
|
2020-10-20 23:30:28 -05:00
|
|
|
piece.manipulations = 0
|
2020-12-02 23:26:36 -06:00
|
|
|
piece.rotations = 0
|
2020-11-06 19:49:44 -06:00
|
|
|
piece.lowest_y = -math.huge
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function SRS:onPieceDrop(piece, grid)
|
2021-01-08 15:46:19 -06:00
|
|
|
self:checkNewLow(piece)
|
2020-12-27 21:41:26 -06:00
|
|
|
if piece.manipulations >= self.MANIPULATIONS_MAX and piece:isDropBlocked(grid) then
|
2020-11-06 19:49:44 -06:00
|
|
|
piece.locked = true
|
|
|
|
else
|
|
|
|
piece.lock_delay = 0 -- step reset
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function SRS:onPieceMove(piece, grid)
|
|
|
|
piece.lock_delay = 0 -- move reset
|
|
|
|
if piece:isDropBlocked(grid) then
|
2020-10-20 23:30:28 -05:00
|
|
|
piece.manipulations = piece.manipulations + 1
|
2021-01-28 20:05:36 -06:00
|
|
|
if piece.manipulations >= SRS.MANIPULATIONS_MAX then
|
2019-05-22 22:57:34 -05:00
|
|
|
piece.locked = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SRS:onPieceRotate(piece, grid)
|
|
|
|
piece.lock_delay = 0 -- rotate reset
|
2021-01-08 15:46:19 -06:00
|
|
|
self:checkNewLow(piece)
|
2020-12-02 23:26:36 -06:00
|
|
|
if piece.rotations >= self.ROTATIONS_MAX then
|
2021-01-30 15:54:09 -06:00
|
|
|
piece.rotations = piece.rotations + 1
|
|
|
|
piece:moveInGrid({ x = 0, y = 1 }, 1, grid)
|
2020-12-27 21:41:26 -06:00
|
|
|
if piece:isDropBlocked(grid) then
|
|
|
|
piece.locked = true
|
|
|
|
end
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
2020-12-04 20:36:25 -06:00
|
|
|
function SRS:get180RotationValue() return 2 end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
return SRS
|