;VXej[`
@system_menu
gosub @system_menu_0
for %i=1 to 4
	if pageid<>"log" and %i==5 then exit
	if pageid=="title" and %i==1 then continue
	if pageid=="title" then sys_y=232
	if pageid=="log" and %i<=2 then continue
	if pageid=="log" then sys_y=95
	if pageid=="stage" then sys_y=207
	sp "command:sys"+str(%i),{name={"img\panel\system_"+str(%i)+".png","img\panel\system_"+str(%i)+"_on.png"},a=255,x=1860,y=sys_y+%i*112,z=100}
	if pageid<>"log" then
		print #c
		wait 50
	endif
next
if pageid=="title" and _clear==1 then sp "command:sys9",{name={"img\panel\system_9.png","img\panel\system_9_on.png"},a=255,x=1860,y=904,z=100}
return

;XN[[h{^
@system_menu_0
sp "command:sys0",{name={"img\panel\system_0_"+str(getscreen())+".png","img\panel\system_0_"+str(getscreen())+"_on.png"},a=255,x=1877,y=5,z=100}
return

;{^`
@system_btndef
for %i=1 to 9
	btn "command:sys"+str(%i)
next
btn "command:sys0"
return

;VXe
@system
param %mode,%sys
if %mode==0 or %mode==3 then
	se1 "004"
elseif %mode==1 then
	wait 500
	se1 "001"
endif
if %sys==0 then goto @system_0
if %sys==5 then goto @system_5
if %mode<>3 then spset "system",810
sp "system:bg",{name="*#000000",a=230,x=0,y=0,z=3}
if %sys>=1 and %sys<=4 then %y=sys_y+%sys*112
if %sys==9 then %y=904
if %mode==0 then sp "system:x",{name={"img\panel\system_"+str(%sys)+".png","img\panel\system_"+str(%sys)+"_on.png"},a=255,x=1860,y=%y,z=0}
if pageid=="stage" then %backlogpage=backlogpage
manualpagemax=0
for %i=1 to 99
	%s=str(%i)
	zeropad 2,%s
	if filechk("img\panel\system_2_"+%s+"_0.png")==1 then manualpagemax=manualpagemax+1
next

;[h
@system_reload
if %sys==1 then
	backlog_reload "system",%backlogpage,backlogpage
endif
if %sys==2 then
	spdeletes "system:manual_pict_"
	gosub "@system_2_"+str(_manualpage)
	sp "system:table",{name="img\panel\system_1_table.png",a=255,x=960,y=303,z=2}
	sp "system:manual_head",{name="?y"+manual_head+"z,manual_head",a=255,x=960,y=340,z=0}
	sp "system:manual_text_1",{name="*2000,1000,#00000000",a=255,x=960,y=0,z=1}
	sp "system:manual_text_0",{name="*2000,1000,#00000000",a=255,x=960,y=320,z=0}
	spformat "system:manual_text_1",0,manual_text_1+"{@/@}",{font="manual_text_1",x=2,y=52,w=80,h=11},{font="manual_ruby_1"}
	spformat "system:manual_text_0",0,manual_text_0+"{@/@}",{font="manual_text_0",x=2,y=52,w=80,h=11},{font="manual_ruby_0"}
	if %mode==0 then
		%len=zlen(zenkaku(str(_manualpage))+"^"+zenkaku(str(manualpagemax)))
		sp "system:manual_page",{name="?i"+zenkaku(str(_manualpage))+"^"+zenkaku(str(manualpagemax))+"j,manual_head",a=255,x=1299+(5-%len)*15,y=267,z=0}
		sp "system:btn1",{name={"img\panel\system_1_btn_1.png","img\panel\system_1_btn_1_on.png"},a=255,x=1190,y=259,z=0}
		sp "system:btn2",{name={"img\panel\system_1_btn_2.png","img\panel\system_1_btn_2_on.png"},a=255,x=1534,y=259,z=0}
		btn "system:btn1"
		btn "system:btn2"
	endif
	if %mode>0 and _manualpopup==1 then
		sp "system:manual_cancel",{name="?񂩂\Ȃ,caption",a=255,x=1630,y=789,z=0}
		sp "system:btn0",{name={"img\panel\system_2_btn_0.png","img\panel\system_2_btn_0_on.png"},a=255,x=1566,y=773,z=0}
		btn "system:btn0"
	elseif %mode>0 and _manualpopup==0 then
		spdelete "system:manual_cancel"
		spdelete "system:btn0"
		_manualpage=%manualpage
	endif
	if %mode==1 then print #u,500,"img\rule_00.png"
	if %mode==2 then print #c
endif
if %sys==3 then
	sp "system:table",{name="img\panel\system_3_table.png",a=255,x=870,y=sys_y+336,z=1}
	for %i=0 to 3
		sp "system:btn"+str(%i)+"0",{name={"img\panel\system_3_btn_0_"+str(_volume[%i][0])+".png","img\panel\system_3_btn_0_"+str(_volume[%i][0])+"_on.png"},a=255,x=935+230*%i,y=sys_y+412,z=0}
		sp "system:btn"+str(%i)+"1",{name={"img\panel\system_3_btn_1.png","img\panel\system_3_btn_1_on.png"},a=255,x=1005+230*%i,y=sys_y+412,z=0}
		sp "system:btn"+str(%i)+"2",{name={"img\panel\system_3_btn_2.png","img\panel\system_3_btn_2_on.png"},a=255,x=1075+230*%i,y=sys_y+412,z=0}
		if _volume[%i][1]>0 then sp "system:bar"+str(%i),{name=">l200,6,"+str(_volume[%i][1])+",11,#00ff00,#282828",a=255,x=930+230*%i,y=sys_y+387,z=0}
		if _volume[%i][1]==0 then spdelete "system:bar"+str(%i)
	next
	for %i1=0 to 3
		for %i2=0 to 2
			btn "system:btn"+str(%i1)+str(%i2)
		next
	next
endif
if %sys==4 then
	sp "system:table",{name="img\panel\system_4_table.png",a=255,x=870,y=sys_y+448,z=1}
	if pageid=="title" then
		sp "system:btn1",{name="img\panel\system_4_btn_1_lock.png",a=255,x=906,y=sys_y+477,z=0}
		sp "system:btn2",{name="img\panel\system_4_btn_2_lock.png",a=255,x=1222,y=sys_y+477,z=0}
	endif
	if pageid=="log" then
		sp "system:btn1",{name="img\panel\system_4_btn_1_lock.png",a=255,x=906,y=sys_y+477,z=0}
		sp "system:btn2",{name={"img\panel\system_4_btn_2.png","img\panel\system_4_btn_2_on.png"},a=255,x=1222,y=sys_y+477,z=0}
		btn "system:btn2"
	endif
	if pageid=="stage" then
		sp "system:btn1",{name={"img\panel\system_4_btn_1.png","img\panel\system_4_btn_1_on.png"},a=255,x=906,y=sys_y+477,z=0}
		btn "system:btn1"
		sp "system:btn2",{name={"img\panel\system_4_btn_2.png","img\panel\system_4_btn_2_on.png"},a=255,x=1222,y=sys_y+477,z=0}
		btn "system:btn2"
	endif
	sp "system:btn3",{name={"img\panel\system_4_btn_3.png","img\panel\system_4_btn_3_on.png"},a=255,x=1538,y=sys_y+477,z=0}
	btn "system:btn3"
endif
if %sys==41 then
	sp "system:table",{name="img\panel\system_41_table.png",a=255,x=870,y=sys_y+448,z=1}
	for %i=1 to 10
		%s=str(%i)
		zeropad 2,%s
		if filechk("savedata\"+str(stage*100+%i)+".sav")==1 then
			sp "system:btn"+%s,{name={"img\panel\log_btn1_"+%s+".png","img\panel\log_btn1_"+%s+"_on.png"},a=255,x=910+85*%i,y=sys_y+477,z=0}
			btn "system:btn"+%s
		else
			sp "system:btn"+%s,{name="img\panel\log_btn1_"+%s+"_lock.png",a=255,x=910+85*%i,y=sys_y+477,z=0}
		endif
	next
endif
if %sys==9 then
	sp "system:table",{name="img\panel\system_4_table.png",a=255,x=870,y=904,z=1}
	sp "system:btn1",{name={"img\panel\system_9_btn_1.png","img\panel\system_9_btn_1_on.png"},a=255,x=919,y=933,z=0}
	sp "system:btn2",{name={"img\panel\system_9_btn_2.png","img\panel\system_9_btn_2_on.png"},a=255,x=1385,y=933,z=0}
	btn "system:btn1"
	btn "system:btn2"
endif
if %mode==0 then btn "system:x"

@system_btnexec
btnid="system"
if %sys==1 then
	btnexec btn_system,"system",{func=1,wheel=1}
elseif %mode==0 and %sys==2 then
	btnexec btn_system,"system",{func=1,wheel=1}
else
	btnexec btn_system,"system",{func=1}
endif
if mid(btn_system,0,2)=="#F" then goto "@func_"+mid(btn_system,2,2)
if %mode==3 and %sys==4 then
	if btn_system=="" or btn_system==#r then goto @system_btnexec
endif
if %mode==3 and %sys==41 then
	if btn_system=="" then goto @system_btnexec
endif
btnclear "system"

;}jA|bvAbvAO
if btn_system=="btn0" then
	_manualpopup=0
	%manualpage=_manualpage
	%page=0:goto @system_2_continue
endif

;}jA|bvAbvAQ
if %mode==1 and _manualpage==1 then %page=2:goto @system_2_continue

;}jA|bvAbvAS
if %mode==1 and _manualpage==3 then %page=4:goto @system_2_continue

;}jA|bvAbvAW
if %mode==1 and _manualpage==7 then %page=8:goto @system_2_continue

;}jA|bvAbvAPP
if %mode==1 and _manualpage==10 then %page=11:goto @system_2_continue

;gCLZ
if %sys==41 and btn_system==#r then
	%sys=4
	spdeletes "system:btn"
	goto @system_reload
endif

;߂
if btn_system=="" or btn_system==#r or btn_system=="x" then
	if btn_system=="x" then se1 "004"
	spsetdelete "system"
	return
endif

goto "@system_"+str(%sys)

;XN[
@system_0
if getscreen()==0 then
	setscreen 1
else
	setscreen 0
endif
gosub @system_menu_0
return

;obNO
@system_1
se1 "007"
if btn_system==#wu then btn_system="btn1"
if btn_system==#wd then btn_system="btn2"
if %backlogpage>1 and btn_system=="btn1" then %backlogpage=%backlogpage-1
if %backlogpage==backlogpage and btn_system=="btn2" then
	spsetdelete "system"
	return
endif
if %backlogpage<backlogpage and btn_system=="btn2" then %backlogpage=%backlogpage+1
goto @system_reload

;}jA
@system_2
se1 "007"
if %mode==0 then
	if btn_system==#wu then btn_system="btn1"
	if btn_system==#wd then btn_system="btn2"
	if btn_system=="btn1" then _manualpage=_manualpage-1
	if btn_system=="btn2" then _manualpage=_manualpage+1
	if _manualpage<1 then _manualpage=manualpagemax
	if _manualpage>manualpagemax then _manualpage=1
endif
goto @system_reload

;}jA|bvAbv
@system_2_popup
param %page
_manualpopup[%page]=1
_manualpage=%page
system 1,2
return

;}jA|bvAbvA
@system_2_continue
_manualpopup[%page]=1
_manualpage=%page
%mode=2
btn_system=""
goto @system_2

@system_2_0
manual_head="Check the Manual"
manual_text_1="You can open the manual from the '?' button in the side\nmenu."
manual_text_0="'?'"
return

@system_2_1
manual_head="Basic Rules"
manual_text_1="Select and flip the panels representing the agent's mental\nbarriers by clicking on them. Avoid the firewalls hidden in\nthe panels and flip all of them to complete, progressing the\nmental intrusion depth 'DEPTH'. Reach and complete DEPTH 10\nto clear the stage."
manual_text_0="Flip all panels while avoiding hidden firewalls\n'DEPTH'"
sp "system:manual_pict_0",{name="img\panel\system_2_01_0.png",a=255,x=960,y=535,z=0}
sp "system:manual_pict_1",{name="img\panel\system_2_01_1.png",a=255,x=1160,y=535,z=0}
return

@system_2_2
manual_head="Firewall"
manual_text_1="The panels have a set number of 'firewalls' displayed in the\nupper right corner. Stepping on them will damage your HP. If\nyour HP reaches 0, it's game over. (You won't step on a\nfirewall on your first move)"
manual_text_0="Stepping on them damages your HP. If HP reaches 0,\nit's game over"
sp "system:manual_pict_0",{name="img\panel\system_2_02_0.png",a=255,x=960,y=535,z=0}
sp "system:manual_pict_1",{name="img\panel\system_2_02_1.png",a=255,x=1160,y=535,z=0}
return

@system_2_3
manual_head="Number Hex"
manual_text_1="The numbers displayed on empty spaces indicate the level of\nfirewalls in adjacent panels. For example, a '1' means there\nis one level 1 firewall in an adjacent panel. You can mark\nidentified firewall panels with a right-click."
manual_text_0="Level of firewalls in adjacent panels Mark with a right-\nclick"
sp "system:manual_pict_0",{name="img\panel\system_2_03_0.png",a=255,x=960,y=515,z=0}
sp "system:manual_pict_1",{name="img\panel\system_2_03_1.png",a=255,x=1215,y=550,z=0}
return

@system_2_4
manual_head="HACK"
manual_text_1="Each time you flip a panel, the gauge fills up, earning you\nHACK points needed to activate hacking."
manual_text_0="Needed to activate hacking"
sp "system:manual_pict_0",{name="img\panel\system_2_04_0.png",a=255,x=960,y=480,z=0}
return

@system_2_5
manual_head="Hacking"
manual_text_1="Left-clicking on a marked panel consumes HACK points and\nactivates a skill that removes the panel along with the\nfirewall. Successfully destroying a firewall through hacking\nallows you to select an H attack 'Attack' against the agent."
manual_text_0="Remove panel along with firewall\nH attack 'Attack' against the agent"
sp "system:manual_pict_0",{name="img\panel\system_2_05_0.png",a=255,x=960,y=535,z=0}
sp "system:manual_pict_1",{name="img\log\operation_101_1.png",a=255,cx=1550,cy=638,xs=0.19,ys=0.19,rot=0,z=0}
return

@system_2_6
manual_head="Attack"
manual_text_1="The selectable attack corresponds to the firewall's level.\nTo select a level 2 attack, you need to destroy a firewall\nof that level or higher. Additionally, selecting Charge\nallows you to carry over the level to the next turn."
manual_text_0="Corresponds to firewall's level Selecting Charge allows\nlevel carryover"
sp "system:manual_pict_0",{name="img\panel\system_2_06_0.png",a=255,x=960,y=535,z=0}
sp "system:manual_pict_1",{name="img\panel\system_2_06_1.png",a=255,x=1250,y=563,z=0}
return

@system_2_7
manual_head="ORGASM"
manual_text_1="Executing an attack increases the agent's ORGASM gauge. When\nthe gauge is full, an orgasm occurs, granting you a shield.\nThe gauge increase rate changes based on game progress.\nRepeated orgasms also increase the rate."
manual_text_0="ORGASM gauge increases. Gain shield\nRepeated orgasms increase rate"
sp "system:manual_pict_0",{name="img\panel\system_2_07_0.png",a=255,x=960,y=575,z=0}
sp "system:manual_pict_1",{name="img\panel\system_2_07_1.png",a=255,x=1400,y=575,z=0}
return

@system_2_8
manual_head="Shield"
manual_text_1="The shield blocks damage from a firewall once. It completely\nnullifies damage regardless of the firewall's level."
manual_text_0="Blocks damage from a firewall once."
sp "system:manual_pict_0",{name="img\panel\system_2_08_0.png",a=255,x=960,y=485,z=0}
sp "system:manual_pict_1",{name="img\panel\system_2_07_1.png",a=255,x=1200,y=485,z=0}
return

@system_2_9
manual_head="Recovery"
manual_text_1="During DEPTH progression, you gain 1 HACK and 1 HP. This is\nthe only way to recover HP."
manual_text_0="Gain 1 HACK and 1 HP during DEPTH progression"
sp "system:manual_pict_0",{name="img\panel\system_2_01_1.png",a=255,x=960,y=485,z=0}
sp "system:manual_pict_1",{name="img\panel\system_2_09_0.png",a=255,x=1075,y=560,z=0}
sp "system:manual_pict_2",{name="img\panel\system_2_09_1.png",a=255,x=1375,y=560,z=0}
return

@system_2_10
manual_head="Firewall Level"
manual_text_1="Firewalls have levels from 1 to 5, each corresponding to\ntheir damage. The number hex indicates the total level of\nadjacent firewalls, not their count, so be careful when\nidentifying them. You can change the marking level by\nrepeatedly right-clicking."
manual_text_0="Levels from 1 to 5\nTotal level Change marking level by repeatedly right-\nclicking"
sp "system:manual_pict_0",{name="img\panel\system_2_10_0.png",a=255,x=960,y=535,z=0}
sp "system:manual_pict_1",{name="img\panel\system_2_10_1.png",a=255,x=1280,y=570,z=0}
return

@system_2_11
manual_head="Hacking Level"
manual_text_1="Hacking also has levels from 1 to 5, corresponding to\nmarking. Activating hacking requires HACK points equal to\nits level. Destroying a firewall requires hacking of the\nsame or higher level; if lower, you take damage equal to the\ndifference in HP."
manual_text_0="Levels from 1 to 5. Corresponds to marking Same or higher\nlevel hacking"
sp "system:manual_pict_0",{name="img\panel\system_2_11_0.png",a=255,x=960,y=535,z=0}
return

@system_2_12
manual_head="Security Hole"
manual_text_1="A pink number hex indicates the presence of a 'Security\nHole'. This is a firewall with a weakness; successful\nhacking triggers an area attack that destroys adjacent\nhexes. If firewalls are involved, you gain their levels as\ncharge."
manual_text_0="Triggers area attack destroying adjacent hexes. Gain\nlevels as charge if firewalls are involved"
sp "system:manual_pict_0",{name="img\panel\system_2_12_0.png",a=255,x=960,y=535,z=0}
sp "system:manual_pict_1",{name="img\panel\system_2_12_1.png",a=255,x=1180,y=535,z=0}
return

;
@system_3
%n1=num(mid(btn_system,3,1))
%n2=num(mid(btn_system,4,1))
if %n2==0 then
	if _volume[%n1][0]==0 then _volume[%n1][0]=1 else _volume[%n1][0]=0
endif
if %n2==1 and _volume[%n1][1]>0 then _volume[%n1][1]=_volume[%n1][1]-1
if %n2==2 and _volume[%n1][1]<10 then _volume[%n1][1]=_volume[%n1][1]+1
se1 "004"
volume_load
goto @system_reload

;I
@system_4
if btn_system=="btn1" then
	se1 "004"
	spdelete "system:btn1"
	spdelete "system:btn2"
	spdelete "system:btn3"
	%sys=41
	goto @system_reload
endif
se1 "001"
spsetdelete "system"
print #c
sp "effect:mask",{name="*#000000",a=255,x=0,y=0,z=0}
print #f,1500
bgmfade 1000
selpstopall
if btn_system=="btn2" then
	resettimer
	stage_spsetdelete
	waittimer 1500
	return @title
elseif btn_system=="btn3" then
	wait 1000
	quit
endif

;gC
@system_41
se1 "001"
spdelete "system:table"
spdeletes "system:btn"
print #c
spset "sign",100
sp "sign:bg",{name="img\title.png",a=255,x=0,y=0,z=1}
sp "sign:load",{name="img\sign_load.png",a=255,x=760,y=510,z=0}
print #f,500
for %i=1 to 40
	sp "sign:bar",{name=">l400,7,"+str(%i)+",40,#ff91ed,#505050",a=255,x=760,y=578,z=0}
	print #c
	wait 1
next
_retry=1
load num(st+right(btn_system,2))

;AbN
@system_9
se1 "126"
if btn_system=="btn1" then unlock 1
if btn_system=="btn2" then unlock 0
sp "effect:flash",{name="*#ffffff",a=255,x=0,y=0,z=0}
print #f,1000
bgmfade 1000
wait 1000
spdelete "effect:flash"
spsetdelete "system"
return @title
