2020-12-21 10:55:56 +02:00
-- Здесь мы настраиваем парсер.
2020-12-21 13:32:40 +02:00
local mrd = require " morph/mrd "
2020-12-23 19:33:56 +02:00
local msg = dprint or print
2020-12-21 10:55:56 +02:00
2020-12-21 12:08:22 +02:00
mp.msg . SCENE = " {#Me} {#plural/находишься,находитесь} {#if_has/#here,supporter,на,в} {#here/пр,2}. " ;
2020-12-23 18:38:34 +02:00
mp.msg . Exam.DEFAULT = " {#Me} не {#g/видишь,видите} {#vo/{#first/пр}} ничего необычного. " ;
2020-12-22 17:28:55 +02:00
mp.msg . LookUnder.NOTHING = " {#Me} не {#g/находишь,находите} под {#first/тв} ничего интересного. "
mp.msg . Enter.INV = " Нельзя зайти в то, что {#me} {#g/держишь,держите} в руках. "
mp.msg . Open.OPEN = " {#Me} {#g/открываешь,открываете} {#first/вн}. "
mp.msg . Open.CLOSE = " {#Me} {#g/закрываешь,закрываете} {#first/вн}. "
mp.msg . Take.HAVE = " У {#you/вн} и так {#firstit} уже есть."
mp.msg . Take.SELF = " {#Me} есть у {#you/рд}. "
mp.msg . Drop.SELF = " У {#you/рд} не хватит ловкости."
mp.msg . Insert.INSERT = " {#Me} {#g/кладёшь,кладёте} {#first/вн} в {#second/вн}. "
mp.msg . PutOn.PUTON = " {#Me} {#g/кладёшь,кладёте} {#first/вн} на {#second/вн}. "
mp.msg . SwitchOn.SWITCHON = " {#Me} {#g/включаешь,включаете} {#first/вн}. "
mp.msg . SwitchOff.SWITCHOFF = " {#Me} {#g/выключаешь,выключаете} {#first/вн}. "
mp.msg . Sing.SING = " Это лучше оставить оперным певцам. "
mp.msg . Smell.SMELL = " Запах очень забытых вещей. "
mp.msg . Smell.SMELL2 = " Н е {#g/волнуйся,волнуйтесь}, у {#you/рд} не пропало чувство запаха. Просто это ничем особенным не пахнет."
mp.msg . Sleep.SLEEP = " Н е спится."
mp.msg . Jump.JUMP = " Прыг-скок. Н е помогает. "
mp.msg . Consult.CONSULT = " {#Me} не {#g/находишь,находите} ничего подходящего. "
2020-12-21 12:08:22 +02:00
function split ( s , sep )
if sep == nil then
sep = " , "
end
local t = { }
for str in string.gmatch ( s , " ([^ " .. sep .. " ]+) " ) do
table.insert ( t , str )
end
return t
end
local function istable ( t ) return type ( t ) == ' table ' end
-- "Ты/вы" в разных падежах: им, род, дат, вин, твор, пред.
function mp . shortcut . you ( case )
2020-12-21 12:20:39 +02:00
if case == nil or case == ' ' then
2020-12-21 12:08:22 +02:00
case = ' им '
end
if case == ' им ' then
if pl.plural then
return ' вы '
end
return ' ты '
end
2020-12-21 12:20:39 +02:00
if case == ' род ' or case == ' рд ' then
2020-12-21 12:08:22 +02:00
if pl.plural then
return ' вас '
end
return ' тебя '
end
2020-12-21 12:20:39 +02:00
if case == ' дат ' or case == ' дт ' then
2020-12-21 12:08:22 +02:00
if pl.plural then
return ' вам '
end
return ' тебе '
end
2020-12-21 12:20:39 +02:00
if case == ' вин ' or case == ' вн ' then
2020-12-21 12:08:22 +02:00
if pl.plural then
return ' вас '
end
return ' тебя '
end
2020-12-21 12:20:39 +02:00
if case == ' твор ' or case == ' тв ' then
2020-12-21 12:08:22 +02:00
if pl.plural then
return ' вами '
end
return ' тобой '
end
2020-12-21 12:20:39 +02:00
if case == ' пред ' or case == ' пр ' then
2020-12-21 12:08:22 +02:00
if pl.plural then
return ' вас '
end
return ' тебе '
end
2020-12-21 12:11:53 +02:00
return ' ты '
2020-12-21 12:08:22 +02:00
end
function mp . shortcut . plural ( options )
if not istable ( options ) then
options = split ( options )
end
if pl.plural then
return options [ 2 ]
end
return options [ 1 ]
end
-- {#g/singlefem,singlemasc,singleother,plural}
function mp . shortcut . g ( options )
if not istable ( options ) then
options = split ( options )
end
if # options == 2 then
return mp.shortcut . plural ( options )
end
if pl.plural then
return options [ 4 ]
end
if pl.pronouns == ' fem ' then
return options [ 1 ]
end
if pl.pronouns == ' masc ' then
return options [ 2 ]
end
if pl.pronouns == ' other ' then
return options [ 3 ]
end
return options [ 1 ]
end
2020-12-21 13:02:03 +02:00
function HasChar ( str , skipc )
if type ( str ) ~= ' string ' then
return false
end
return ( string.find ( str , skipc ) ~= nil )
end
function StrCut ( str , skipc )
if type ( str ) ~= ' string ' then
return str
end
return str : gsub ( skipc , ' ' )
end
2020-12-24 16:56:47 +02:00
Verb {
" #Shoot " ,
' вырез/ать ' ,
' ~ * из {noun}/рд,scene : SetShoot ' ,
}
2020-12-21 13:02:03 +02:00
2020-12-24 16:56:47 +02:00
function mp : SetShoot ( what , letter )
2020-12-21 13:02:03 +02:00
if not pl : have ( ' letterremover ' ) then
return ' Нечем. ' ;
end
2020-12-23 19:33:56 +02:00
if ( what : has ' animate ' ) then
2020-12-21 13:02:03 +02:00
return ' Вырезатель не работает на живых. ' ;
end
2020-12-23 19:33:56 +02:00
if ( what : has ' essential ' ) then
2020-12-21 15:00:29 +02:00
return ' Это слишком полезная вещь, чтобы её вырезать. ' ;
end
2020-12-23 19:33:56 +02:00
if type ( letter ) ~= ' string ' then
2020-12-24 16:56:47 +02:00
return ' Вырезатель можно установить только на букву. ' ;
end
-- string.len считает байты, а надо символы; utf8.len в инстеде не работает
if # ( letter ) : gsub ( ' [ \128 - \191 ] ' , ' ' ) == 0 then
2020-12-23 19:33:56 +02:00
return ' Вырезатель можно установить только на букву русского алфавита. ' ;
end
2020-12-24 16:56:47 +02:00
if # ( letter ) : gsub ( ' [ \128 - \191 ] ' , ' ' ) > 1 then
2020-12-23 19:33:56 +02:00
return ' Вырезатель можно установить только на одну букву. ' ;
end
2020-12-21 13:32:40 +02:00
local lcaseletter = mrd.lang . lower ( letter ) ;
2020-12-23 19:33:56 +02:00
if what.canonical == nil or what.canonical == ' ' then
what.canonical = what.word
2020-12-21 15:00:29 +02:00
end
2020-12-23 19:33:56 +02:00
if not HasChar ( what.canonical , lcaseletter ) then
return ' Вырезатель настроен на букву ' .. letter .. ' , которой нет в слове « ' .. what.canonical .. ' ». ' ;
2020-12-21 13:02:03 +02:00
end
2020-12-23 19:33:56 +02:00
local newCanonical = StrCut ( what.canonical , lcaseletter ) ;
2020-12-21 13:28:54 +02:00
local newTarget = lookup ( newCanonical ) ;
2020-12-21 15:00:29 +02:00
if not newTarget then
-- продолжаем поиск полным перебором
std.for_each_obj ( function ( v )
if v.canonical == newCanonical then
newTarget = v
return ;
end
end )
end
2020-12-21 13:28:54 +02:00
if newTarget then
2020-12-23 19:33:56 +02:00
what : remove ( ) ;
2020-12-21 13:28:54 +02:00
put ( newTarget , here ( ) ) ;
2020-12-24 16:58:36 +02:00
pn ( ' Вы стреляете в ' .. what : noun ' вн ' .. ' ,и ' .. what : it ( ' им ' ) .. ' вырезается в ' .. newCanonical .. ' . ' ) ;
2020-12-22 11:56:46 +02:00
if newTarget.oncreate ~= nil then
newTarget.oncreate ( )
end
return ;
2020-12-21 13:28:54 +02:00
end
2020-12-23 19:33:56 +02:00
return ' Вы стреляете в ' .. what : noun ' вн ' .. ' и ' .. what : it ( ' им ' ) .. ' мигает в слабом тумане букв « ' .. newCanonical .. ' », но затем возвращается в прежнее состояние. ' ;
2020-12-21 13:28:54 +02:00
2020-12-21 13:02:03 +02:00
end