REM A visiting Father Christmas fish waits for a gap between title banners.
DEF PROCfestiveinit
fishsantadone%=FALSE:fishsantavisible%=FALSE:fishsantastart=-1000:fishpresents%=0
chimeenabled%=TRUE:chimeremaining%=0:chimenext%=0:chimelast$="":chimeflash%=0:chimetext$=""
ENDPROC
:
DEF PROCfishsantastate
LOCAL t,u
IF fishsantadone%=FALSE AND scenetime>=600 AND FNbanneractive=FALSE AND bannerpending%=FALSE AND catvisiting%=FALSE THEN
  fishsantastart=scenetime:fishsantadone%=TRUE
ENDIF
t=scenetime-fishsantastart:fishsantavisible%=t>=0 AND t<20
IF fishsantadone% THEN
  IF t>=7 THEN fishpresents%=1
  IF t>=10 THEN fishpresents%=2
  IF t>=13 THEN fishpresents%=3
ENDIF
IF fishsantavisible%=FALSE THEN ENDPROC
fishsantax=485:fishsantay=241+SIN(t*1.5):fishsantaface%=0
IF t<5 THEN
  u=t/5:u=u*u*(3-2*u):fishsantax=600-115*u:fishsantay=224+17*u
ENDIF
IF t>=15 THEN
  u=(t-15)/5:u=u*u*(3-2*u):fishsantax=485+115*u:fishsantay=241-17*u:fishsantaface%=1
ENDIF
fishsantaid%=fishsantabase%+fishsantaface%*4+(INT(t*8) MOD 4)
ENDPROC
:
DEF PROCdrawfishgifts
LOCAL i%
IF fishpresents%=0 THEN ENDPROC
FOR i%=0 TO fishpresents%-1:PROCsprite(fishgiftbase%+i%,457+i%*7,253-i% MOD 2*3):NEXT
ENDPROC
:
DEF PROCdrawfishsanta
LOCAL t,p,px,py,which%
IF fishsantavisible%=FALSE THEN ENDPROC
VDU 24,ox%+910;oy%-530;ox%+1150;oy%-400;
PROCsprite(fishsantaid%,fishsantax-19,fishsantay-20)
t=scenetime-fishsantastart
FOR which%=0 TO 2
  p=(t-(6+which%*3))
  IF p>=0 AND p<1 THEN
    px=fishsantax-8+(457+which%*7-(fishsantax-8))*p
    py=fishsantay+1+(253-which% MOD 2*3-(fishsantay+1))*p
    PROCsprite(fishgiftbase%+which%,px,py)
  ENDIF
NEXT
VDU 24,clipx0%;clipy0%;clipx1%;clipy1%;
ENDPROC
:
REM Chimes follow the real local clock, independently of the scene clock.
DEF FNclockclick(x,y,shift%,buttons%)
IF x<540+shift% OR x>=595+shift% OR y<51 OR y>=119 THEN =FALSE
IF (buttons% AND 4)<>0 THEN PROCclockannounce:=TRUE
IF (buttons% AND 1)<>0 THEN PROCchimetoggle:=TRUE
=FALSE
:
DEF PROCclockannounce
REM Force a fresh local-time read, even with animation/clock repaint stopped.
wallfirst%=TRUE:PROCwallclockpoll
IF LEN(wallstamp$)<>14 THEN ENDPROC
chimetext$=LEFT$(walltime$,5):chimeflash%=now%+400:bufferdirty%=TRUE
PROCfxsaytime(wallhour%,wallminute%)
ENDPROC
:
DEF PROCchimehour(old$)
LOCAL key$
IF LEN(wallstamp$)<>14 THEN ENDPROC
key$=LEFT$(wallstamp$,10)
IF LEN(old$)<>14 THEN chimelast$=key$:ENDPROC
IF LEFT$(old$,10)=key$ OR key$=chimelast$ THEN ENDPROC
chimelast$=key$
IF chimeenabled%=FALSE OR wallminute%<>0 OR wallsecond%>5 THEN ENDPROC
chimeremaining%=wallhour% MOD 12:IF chimeremaining%=0 THEN chimeremaining%=12
chimenext%=now%
ENDPROC
:
DEF PROCchimetick
LOCAL dummy%
IF chimeflash%<>0 AND now%-chimeflash%>=0 THEN
  chimeflash%=0:bufferdirty%=TRUE
  IF openmain% AND karaokemode%=FALSE AND gameactive%=FALSE THEN SYS "Wimp_ForceRedraw",main%,0,-viewh%,vieww%,0
ENDIF
IF chimeenabled%=FALSE OR chimeremaining%=0 OR now%-chimenext%<0 THEN ENDPROC
PROCfxinit
IF fxready%=FALSE THEN chimeremaining%=0:ENDPROC
IF fxid%(2)<>0 THEN ENDPROC
PROCfxplay(2,fxbank%+fxbank%!(16+35*8),fxbank%!(20+35*8))
chimeremaining%-=1:chimenext%=now%+140
ENDPROC
:
DEF PROCchimetoggle
LOCAL word%,dummy%
chimeenabled%=NOT chimeenabled%:chimeremaining%=0
IF fxcode%<>0 THEN dummy%=FNfxstop(2)
chimetext$="Chimes off":word%=34
IF chimeenabled% THEN chimetext$="Chimes on":word%=33
chimeflash%=now%+400:bufferdirty%=TRUE
PROCfxinit
IF fxready%=FALSE THEN ENDPROC
IF FNfxstop(1)=FALSE THEN ENDPROC
fxused%=0:PROCfxword(word%):PROCfxplay(1,fxspeech%,fxused%)
ENDPROC
:
DEF PROCdrawchimenotice
IF chimeflash%=0 THEN ENDPROC
PROCcolour(25,40,49):RECTANGLE FILL ox%+1064,oy%-274,132,24
PROCgametext(chimetext$,534,126)
ENDPROC
