-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathinit.lua
More file actions
504 lines (459 loc) · 13.5 KB
/
Copy pathinit.lua
File metadata and controls
504 lines (459 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
local Player=require"parts.player.player"
local getSeqGen=require"parts.player.seqGenerators"
local gameEnv0=require"parts.player.gameEnv0"
local rnd,max=math.random,math.max
local ins=table.insert
local ply_draw=require"parts.player.draw"
local PLY={draw=ply_draw}
--------------------------<Libs>--------------------------
local modeDataMeta do
local rawset=rawset
modeDataMeta={
__index=function(self,k) rawset(self,k,0) return 0 end,
__newindex=function(self,k,v) rawset(self,k,v) end,
}
end
local function _getNewStatTable()
local T={
time=0,frame=0,score=0,
key=0,rotate=0,hold=0,
extraPiece=0,finesseRate=0,
piece=0,row=0,dig=0,
atk=0,digatk=0,
send=0,recv=0,pend=0,off=0,
clear={},clears={},spin={},spins={},
pc=0,hpc=0,b2b=0,b3b=0,
maxCombo=0,maxFinesseCombo=0,
}
for i=1,29 do
T.clear[i]={0,0,0,0,0,0}
T.spin[i]={0,0,0,0,0,0,0}
T.clears[i]=0
T.spins[i]=0
end
-- Big pieces - Undecacrashes are possible, so need more entries
for i=30,58 do
T.clear[i]={0,0,0,0,0,0,0,0,0,0,0}
T.spin[i]={0,0,0,0,0,0,0,0,0,0,0,0}
T.clears[i]=0
T.spins[i]=0
end
return T
end
local function _newEmptyPlayer(id,mini)
local P={id=id}
PLAYERS[id]=P
PLY_ALIVE[id]=P
-- Inherit functions of Player class
for k,v in next,Player do P[k]=v end
-- Field position
P.swingOffset={-- Shake FX
x=0,y=0,
vx=0,vy=0,
a=0,va=0,
}
P.shakeTimer=0
P.x,P.y,P.size=0,0,1
P.frameColor=COLOR.Z
-- Set these at Player:setPosition()
-- P.fieldX,P.fieldY=...
-- P.centerX,P.centerY=...
-- P.absFieldX,P.absFieldY=...
-- Minimode
P.miniMode=mini
if mini then
P.canvas=love.graphics.newCanvas(60,120)
P.frameWait=rnd(26,62)
P.draw=ply_draw.small
else
P.draw=ply_draw.norm
end
-- States
P.type='none'
P.sound=false
P.alive=true
P.control=false
P.timing=false
P.trigFrame=0
P.result=false-- String: 'finish'|'win'|'lose'
P.stat=_getNewStatTable()
P.modeData=setmetatable({},modeDataMeta)-- Data use by mode
P.keyPressing={} for i=1,12 do P.keyPressing[i]=false end
P.clearingRow,P.clearedRow={},{}-- Clearing animation height,cleared row mark
P.dropFX,P.moveFX,P.lockFX,P.clearFX={},{},{},{}
-- P.destFX={}-- Normally created by bot
P.tasks={}
P.bonus={}-- Texts
-- Times
P.frameRun=GAME.frameStart-- Frame run, mainly for replay
P.endCounter=0-- Used after gameover
P.dropTime={} for i=1,10 do P.dropTime[i]=-1e99 end P.dropSpeed=0
P.stream={}
P.streamProgress=false-- 1 to start play recording
-- Randomizers
P.seqRND=love.math.newRandomGenerator(GAME.seed)
P.atkRND=love.math.newRandomGenerator(GAME.seed)
P.holeRND=love.math.newRandomGenerator(GAME.seed)
P.aiRND=love.math.newRandomGenerator(GAME.seed+P.id)
-- Field-related
P.field,P.visTime={},{}
P.keepVisible=true
P.showTime=false
P.garbageBeneath=0
P.fieldBeneath=0
P.fieldUp=0
-- Attack-related
P.atkBuffer={}
P.atkBufferSum,P.atkBufferSum1=0,0
P.spike,P.spikeTime=0,0
P.spikeText=love.graphics.newText(getFont(100))
-- Attacker-related
P.badge,P.strength=0,0
P.atkMode,P.swappingAtkMode=1,20
P.atker,P.atking,P.lastRecv={}
-- User-related
P.uid=false
P.sid=false
-- Block states
--[[
P.curX,P.curY,P.ghoY,P.minY=0,0,0,0-- x,y,ghostY
P.cur={
id=shapeID,
bk=matrix[2],
sc=table[2],
dir=direction,
name=nameID
color=colorID,
}
P.newNext=false-- Warped coroutine to get new next, loaded in applyGameEnv()
]]
P.movDir,P.moving,P.downing=0,0,-1-- Last move key,DAS charging,downDAS charging
P.dropDelay,P.lockDelay=0,0
P.waiting,P.falling=0,0
P.freshTime=0
P.spinLast=false
P.ctrlCount=0-- Key press time, for finesse check
-- Game states
P.combo=0
P.b2b,P.b2b1=0,0-- B2B point & Displayed B2B point
P.score1=0-- Displayed score
P.pieceCount=0-- Count pieces from next, for drawing bagline
P.finesseCombo,P.finesseComboTime=0,0
P.nextQueue={}
P.holdQueue={}
P.holdTime=0
P.holdIXSFromNext=nil
P.lastPiece={
id=0,name=0,-- block id/name
curX=0,curY=0,-- block position
centX=0,centY=0,-- center position
dir=0,-- direction
frame=-1e99,-- lock time
autoLock=true,-- if lock with gravity
finePts=0,-- finesse Points
row=0,dig=0,-- lines/garbage cleared
score=0,-- score gained
atk=0,exblock=0,-- lines attack/defend
off=0,send=0,-- lines offset/sent
spin=false,mini=false,-- if spin/mini
pc=false,hpc=false,-- if pc/hpc
special=false,-- if special clear (spin, >=4, pc)
}
return P
end
local function _loadGameEnv(P)-- Load gameEnv
P.gameEnv={}-- Current game setting environment
local ENV=P.gameEnv
local GAME,SETTING=GAME,SETTING
-- Load game settings
for k,v in next,gameEnv0 do
if GAME.modeEnv[k]~=nil then
v=GAME.modeEnv[k] -- Mode setting
-- print("mode-"..k..":"..tostring(v))
elseif GAME.setting[k]~=nil then
v=GAME.setting[k] -- Game setting
-- print("game-"..k..":"..tostring(v))
elseif SETTING[k]~=nil then
v=SETTING[k] -- Global setting
-- print("global-"..k..":"..tostring(v))
-- else
-- print("default-"..k..":"..tostring(v))
end
if type(v)~='table' then -- Default setting
ENV[k]=v
else
ENV[k]=TABLE.copy(v)
end
end
if ENV.allowMod then
for i=1,#GAME.mod do
if GAME.mod[i]>0 then
local M=MODOPT[i]
M.func(P,M.list and M.list[GAME.mod[i]])
end
end
end
end
local function _loadRemoteEnv(P,confStr)-- Load gameEnv
confStr=JSON.decode(confStr)
if not confStr then
confStr={}
MES.new('warn',"Bad conf from "..USERS.getUsername(P.uid).."#"..P.uid)
end
for i=1,#(confStr.skin or {}) do if confStr.skin[i]>16 then confStr.skin[i]=17 end end-- Filter invalid skin (bomb)
P.gameEnv={}-- Current game setting environment
local ENV=P.gameEnv
local GAME,SETTING=GAME,SETTING
-- Load game settings
for k,v in next,gameEnv0 do
if GAME.modeEnv[k]~=nil then
v=GAME.modeEnv[k] -- Mode setting
elseif confStr[k]~=nil then
v=confStr[k] -- Game setting
elseif SETTING[k]~=nil then
v=SETTING[k] -- Global setting
end
if type(v)~='table' then -- Default setting
ENV[k]=v
else
ENV[k]=TABLE.copy(v)
end
end
end
local function _mergeFuncTable(f,L)
if type(f)=='function' then
ins(L,f)
elseif type(f)=='table' then
for i=1,#f do
ins(L,f[i])
end
end
return L
end
local hooks = {
'mesDisp',
'hook_left',
'hook_left_manual',
'hook_left_auto',
'hook_right',
'hook_right_manual',
'hook_right_auto',
'hook_rotate',
'hook_drop',
'hook_spawn',
'hook_hold',
'hook_die',
'task'
}
local function _applyGameEnv(P)-- Finish gameEnv processing
local ENV=P.gameEnv
-- Apply events
for i=1,#hooks do
ENV[hooks[i]]=_mergeFuncTable(ENV[hooks[i]],{})
end
-- Apply eventSet
if ENV.eventSet and ENV.eventSet~="X" then
if type(ENV.eventSet)=='string' then
local eventSet=require('parts.eventsets.'..ENV.eventSet)
if eventSet then
for k,v in next,eventSet do
if TABLE.find(hooks,k) then
_mergeFuncTable(v,ENV[k])
elseif type(v)=='table' then
ENV[k]=TABLE.copy(v)
else
ENV[k]=v
end
end
else
MES.new('warn',"No event set called: "..ENV.eventSet)
end
else
MES.new('warn',"Wrong event set type: "..type(ENV.eventSet))
end
end
P._20G=ENV.drop==0
P.dropDelay=ENV.drop
P.lockDelay=ENV.lock
P.freshTime=ENV.freshLimit
P.life=ENV.life
P.keyAvailable=TABLE.new(true,20)
if ENV.noTele then
for i=11,20 do
if i~=14 then
P.keyAvailable[i]=false
end
end
end
if not ENV.fkey1 then P.keyAvailable[9]=false end
if not ENV.fkey2 then P.keyAvailable[10]=false end
for _,v in next,ENV.keyCancel do
P.keyAvailable[v]=false
end
P.skinLib=SKIN.lib[ENV.skinSet]
P:setInvisible(
ENV.visible=='show' and -1 or
ENV.visible=='easy' and 300 or
ENV.visible=='slow' and 100 or
ENV.visible=='medium' and 60 or
ENV.visible=='fast' and 20 or
ENV.visible=='none' and 0
)
P:set20G(P._20G)
P:setHold(ENV.holdCount)
P:setNext(ENV.nextCount)
P:setRS(ENV.RS)
if type(ENV.mission)=='table' then
P.curMission=1
end
ENV.das=max(ENV.das,ENV.mindas)
ENV.arr=max(ENV.arr,ENV.minarr)
ENV.sdarr=max(ENV.sdarr,ENV.minsdarr)
if ENV.nextCount==0 then
ENV.nextPos=false
end
local seqGen=coroutine.create(getSeqGen(ENV.sequence))
local seqCalled=false
local initSZOcount=0
local bagLineCounter=0
function P:newNext()
local status,piece
if seqCalled then
status,piece=coroutine.resume(seqGen,P.field,P.stat)
else
status,piece=coroutine.resume(seqGen,P.seqRND,P.gameEnv.seqData)
seqCalled=true
end
if not status then
assert(piece=='cannot resume dead coroutine')
elseif piece then
if ENV.noInitSZO and initSZOcount<5 then
initSZOcount=initSZOcount+1
if piece==1 or piece==2 or piece==6 then
return self:newNext()
else
initSZOcount=5
end
end
P:getNext(piece,bagLineCounter)
bagLineCounter=0
else
if ENV.bagLine then
bagLineCounter=bagLineCounter+1
end
P:newNext()
end
end
for _=1,ENV.trueNextCount do
P:newNext()
end
if P.miniMode then
ENV.lockFX=false
ENV.dropFX=false
ENV.moveFX=false
ENV.clearFX=false
ENV.splashFX=false
ENV.shakeFX=false
ENV.text=false
end
if ENV.lockFX==0 then ENV.lockFX=false end
if ENV.dropFX==0 then ENV.dropFX=false end
if ENV.moveFX==0 then ENV.moveFX=false end
if ENV.clearFX==0 then ENV.clearFX=false end
if ENV.splashFX==0 then ENV.splashFX=false end
if ENV.shakeFX==0 then ENV.shakeFX=false end
if ENV.atkFX==0 then ENV.atkFX=false end
if ENV.ghost==0 then ENV.ghost=false end
if ENV.grid==0 then ENV.grid=false end
if ENV.center==0 then ENV.center=false end
if ENV.lineNum==0 then ENV.lineNum=false end
-- Load tasks
for i=1,#ENV.task do P:newTask(ENV.task[i]) end
end
--------------------------</Libs>--------------------------
--------------------------<Public>--------------------------
local DemoEnv={
face={0,0,0,0,0,0,0},
das=10,arr=2,sddas=2,sdarr=2,
drop=60,lock=60,
wait=10,fall=20,
highCam=false,
life=1e99,
allowMod=false,
fine=false,
}
function PLY.newDemoPlayer(id)
local P=_newEmptyPlayer(id)
P.type='bot'
P.sound=false
P.demo=true
P.frameRun=180
P.draw=ply_draw.demo
P.control=true
GAME.modeEnv=DemoEnv
_loadGameEnv(P)
_applyGameEnv(P)
P:loadAI{
type='CC',
next=5,
hold=true,
delay=6,
node=100000,
}
P:spawn()
end
function PLY.newRemotePlayer(id,mini,p)
local P=_newEmptyPlayer(id,mini)
P.type='remote'
P.draw=ply_draw.norm
P:startStreaming()
P.uid=p.uid
P.sid=NET.uid_sid[p.uid] or p.uid
P.group=p.group
P.netAtk=0-- Sum of lines sent in stream, will be compared with P.stat.send for checking stream legal or not
P.loseTimer=false-- Will be set to 26 when receive player_finish signal
if not (P.group%1==0 and P.group>=1 and P.group<=6) then P.group=0 end
_loadRemoteEnv(P,p.config)
_applyGameEnv(P)
end
function PLY.newAIPlayer(id,AIdata,mini,p)
local P=_newEmptyPlayer(id,mini)
P.type='bot'
local pData={
uid=id,
group=0,
} if p then TABLE.coverR(p,pData) end
P.username="BOT"..pData.uid
P.sid=NET.uid_sid[pData.uid] or pData.uid
P.group=pData.group
if not (P.group%1==0 and P.group>=1 and P.group<=6) then P.group=0 end
_loadGameEnv(P)
P.gameEnv.face={0,0,0,0,0,0,0}
P.gameEnv.skin={1,7,11,3,14,4,9}
_applyGameEnv(P)
AIdata._20G=P._20G
P:loadAI(AIdata)
end
function PLY.newPlayer(id,mini,p)
local P=_newEmptyPlayer(id,mini)
P.type='human'
P.sound=true
local pData={
uid=USER.uid,
group=0,
} if p then
TABLE.coverR(p,pData)
else
-- Default pid=1, and empty username
pData.uid=1
P.username=""
end
P.uid=pData.uid
P.sid=NET.uid_sid[pData.uid] or pData.uid
P.group=pData.group
if not (P.group%1==0 and P.group>=1 and P.group<=6) then P.group=0 end
_loadGameEnv(P)
_applyGameEnv(P)
end
--------------------------</Public>--------------------------
return PLY