KAZIK/src_graphics/bowling_simulation.inc

391 lines
9 KiB
PHP

BowlingScore3D PROC uses ebx esi edi owner:DWORD
local frame:DWORD,roll:DWORD,total:DWORD,available:DWORD
mov ebx,owner
mov eax,bwRollCount3D[ebx*4]
mov available,eax
imul ebx,96
lea esi,bwRolls3D[ebx]
mov frame,0
mov roll,0
mov total,0
bw_score_frame:
mov edi,roll
cmp edi,available
jae bw_score_done
mov eax,[esi+edi*4]
add total,eax
cmp eax,10
je bw_score_strike
inc edi
cmp edi,available
jae bw_score_done
add eax,[esi+edi*4]
mov edx,[esi+edi*4]
add total,edx
inc edi
cmp eax,10
jne bw_score_advance_two
cmp edi,available
jae bw_score_advance_two
mov eax,[esi+edi*4]
add total,eax
bw_score_advance_two:
add roll,2
jmp bw_score_advance_frame
bw_score_strike:
inc edi
cmp edi,available
jae bw_score_advance_one
mov eax,[esi+edi*4]
add total,eax
inc edi
cmp edi,available
jae bw_score_advance_one
mov eax,[esi+edi*4]
add total,eax
bw_score_advance_one:
inc roll
bw_score_advance_frame:
inc frame
cmp frame,10
jb bw_score_frame
bw_score_done:
mov ebx,owner
mov eax,total
mov bwScores3D[ebx*4],eax
ret
BowlingScore3D ENDP
BowlingRegisterRoll3D PROC uses ebx esi edi lane:DWORD,hit:DWORD
mov esi,lane
lea ebx,[esi*2]
add ebx,bwTurn3D[esi*4]
mov edi,bwRollCount3D[ebx*4]
cmp edi,21
jae bw_register_done
imul eax,ebx,96
lea edi,[eax+edi*4]
mov eax,hit
mov bwRolls3D[edi],eax
inc bwRollCount3D[ebx*4]
invoke BowlingScore3D,ebx
mov bwNewRack3D[esi*4],0
mov bwFrameDone3D[esi*4],0
cmp bwBall3D[esi*4],0
jne bw_register_after_first
mov eax,hit
mov bwFirstHit3D[esi*4],eax
cmp eax,10
jne bw_register_next_ball
cmp bwFrames3D[ebx*4],9
jb bw_register_complete
mov bwNewRack3D[esi*4],1
jmp bw_register_next_ball
bw_register_after_first:
cmp bwFrames3D[ebx*4],9
jb bw_register_complete
cmp bwBall3D[esi*4],2
jae bw_register_complete
mov eax,bwFirstHit3D[esi*4]
add eax,hit
cmp eax,10
jb bw_register_complete
cmp bwFirstHit3D[esi*4],10
jne bw_register_bonus_rack
cmp hit,10
jne bw_register_next_ball
bw_register_bonus_rack:
mov bwNewRack3D[esi*4],1
bw_register_next_ball:
inc bwBall3D[esi*4]
ret
bw_register_complete:
inc bwFrames3D[ebx*4]
mov bwNewRack3D[esi*4],1
mov bwFrameDone3D[esi*4],1
mov bwBall3D[esi*4],0
bw_register_done:
ret
BowlingRegisterRoll3D ENDP
BowlingImpact3D PROC uses ebx esi edi lane:DWORD
local pinMask:DWORD,count:DWORD
mov esi,lane
mov pinMask,0
mov count,0
mov eax,bwAim3D[esi*4]
test eax,eax
jns @F
neg eax
@@:
cmp eax,FP_1*68/100
ja bw_impact_finish
xor edi,edi
bw_impact_pin:
mov ecx,edi
mov ebx,1
shl ebx,cl
test bwRack3D[esi*4],ebx
jz bw_impact_next
mov eax,bwPinX3D[edi*4]
sub eax,bwAim3D[esi*4]
test eax,eax
jns @F
neg eax
@@:
cmp eax,FP_1*44/100
ja bw_impact_next
or pinMask,ebx
inc count
bw_impact_next:
inc edi
cmp edi,10
jb bw_impact_pin
mov eax,bwAim3D[esi*4]
add eax,FP_1*18/100
cmp eax,FP_1*36/100
ja bw_impact_finish
; A central pocket can propagate through the complete rack.
test bwRng3D,3
jz bw_impact_finish
mov eax,bwRack3D[esi*4]
mov pinMask,eax
mov count,0
@@:
test eax,eax
jz bw_impact_finish
lea edx,[eax-1]
and eax,edx
inc count
jmp @B
bw_impact_finish:
mov eax,pinMask
mov bwHit3D[esi*4],eax
invoke BowlingRegisterRoll3D,esi,count
ret
BowlingImpact3D ENDP
UpdateBowling3D PROC uses ebx esi edi
cmp hallLevel3D,HALL_BOWLING
je bw_update_active
cmp hallLevel3D,0
jne bw_update_done
cmp playerY,10*FP_1
ja bw_update_done
cmp playerX,10*FP_1
ja bw_update_done
bw_update_active:
mov eax,animationClock3D
cmp eax,bwClock3D
je bw_update_done
mov bwClock3D,eax
cmp bwSeat3D,0
je bw_update_lanes
cmp keys3D[57h],0
jne bw_update_stand
cmp keys3D[53h],0
je bw_update_lanes
bw_update_stand:
mov interactTargetId,INTERACT_BOWL_SEAT
call TryBowlingInteraction3D
bw_update_lanes:
xor esi,esi
bw_update_lane:
cmp bwBusy3D[esi*4],0
je bw_update_next
mov eax,deltaTime3D
add bwTime3D[esi*4],eax
mov eax,bwState3D[esi*4]
cmp eax,0
je bw_update_rest
cmp eax,1
je bw_update_pick
cmp eax,2
je bw_update_throw
cmp eax,3
je bw_update_roll
cmp eax,4
je bw_update_sweep
cmp eax,5
je bw_update_return
cmp bwTime3D[esi*4],4000
jb bw_update_next
cmp bwFrameDone3D[esi*4],0
je bw_update_new_approach
xor bwTurn3D[esi*4],1
lea ebx,[esi*2]
add ebx,bwTurn3D[esi*4]
cmp bwFrames3D[ebx*4],10
jb bw_update_new_approach
xor bwTurn3D[esi*4],1
lea ebx,[esi*2]
add ebx,bwTurn3D[esi*4]
cmp bwFrames3D[ebx*4],10
jb bw_update_new_approach
; Both games finished: start a new pair without affecting the casino bankroll.
lea ebx,[esi*8]
mov bwFrames3D[ebx],0
mov bwFrames3D[ebx+4],0
mov bwRollCount3D[ebx],0
mov bwRollCount3D[ebx+4],0
mov bwScores3D[ebx],0
mov bwScores3D[ebx+4],0
bw_update_new_approach:
mov bwState3D[esi*4],0
jmp bw_update_reset_timer
bw_update_rest:
cmp bwTime3D[esi*4],2300
jb bw_update_next
mov bwState3D[esi*4],1
jmp bw_update_reset_timer
bw_update_pick:
cmp bwTime3D[esi*4],2700
jb bw_update_next
mov bwState3D[esi*4],2
mov eax,bwRng3D
imul eax,1664525
add eax,1013904223
mov bwRng3D,eax
shr eax,16
xor edx,edx
mov ecx,171
div ecx
sub edx,85
imul eax,edx,FP_1
cdq
mov ecx,100
idiv ecx
mov bwAim3D[esi*4],eax
jmp bw_update_reset_timer
bw_update_throw:
cmp bwTime3D[esi*4],2400
jb bw_update_next
mov bwState3D[esi*4],3
jmp bw_update_reset_timer
bw_update_roll:
cmp bwTime3D[esi*4],2400
jb bw_update_next
invoke BowlingImpact3D,esi
mov bwState3D[esi*4],4
jmp bw_update_reset_timer
bw_update_sweep:
cmp bwTime3D[esi*4],1800
jb bw_update_next
mov eax,bwHit3D[esi*4]
not eax
and bwRack3D[esi*4],eax
mov bwHit3D[esi*4],0
mov bwState3D[esi*4],5
jmp bw_update_reset_timer
bw_update_return:
cmp bwTime3D[esi*4],3600
jb bw_update_next
cmp bwNewRack3D[esi*4],0
je @F
mov bwRack3D[esi*4],1023
@@:
mov bwState3D[esi*4],6
bw_update_reset_timer:
mov bwTime3D[esi*4],0
bw_update_next:
inc esi
cmp esi,BW_LANES
jb bw_update_lane
bw_update_done:
ret
UpdateBowling3D ENDP
BowlingMonitorText3D PROC uses ebx esi edi target:DWORD,x:DWORD,y:DWORD,value:DWORD,color:DWORD
local row:DWORD,bits:DWORD,atX:DWORD
mov esi,value
mov eax,x
mov atX,eax
bw_monitor_char:
movzx eax,BYTE PTR [esi]
test eax,eax
jz bw_monitor_text_done
cmp atX,120
ja bw_monitor_text_done
lea ebx,font8x8[eax*8]
mov row,0
bw_monitor_row:
mov ecx,row
movzx eax,BYTE PTR [ebx+ecx]
mov bits,eax
mov eax,row
add eax,y
shl eax,7
add eax,atX
lea edi,[eax*4]
add edi,target
mov ecx,8
bw_monitor_pixel:
test bits,80h
jz @F
mov eax,color
stosd
jmp bw_monitor_pixel_next
@@:
add edi,4
bw_monitor_pixel_next:
shl bits,1
dec ecx
jnz bw_monitor_pixel
inc row
cmp row,8
jb bw_monitor_row
inc esi
add atX,8
jmp bw_monitor_char
bw_monitor_text_done:
ret
BowlingMonitorText3D ENDP
RefreshBowlingMonitors3D PROC uses ebx esi edi
local target:DWORD,number[16]:BYTE
mov eax,animationClock3D
shr eax,8
cmp eax,bwMonitorClock3D
je bw_monitors_done
mov bwMonitorClock3D,eax
lea edi,bwSignPixels3D
mov eax,0FF10282Fh
mov ecx,128*64
rep stosd
invoke BowlingMonitorText3D,OFFSET bwSignPixels3D,36,4,OFFSET bwSignText3D,0FF55D9CFh
xor esi,esi
bw_monitor_lane:
mov eax,esi
shl eax,15
add eax,OFFSET bwMonitors3D
mov target,eax
mov edi,eax
mov eax,0FF101F27h
mov ecx,128*64
rep stosd
invoke BowlingMonitorText3D,target,8,5,OFFSET bwLaneWord3D,0FF55D9CFh
lea ebx,[esi+1]
invoke FormatNumber,ebx,ADDR number
invoke BowlingMonitorText3D,target,52,5,ADDR number,0FFFFFFFFh
cmp bwBusy3D[esi*4],0
jne bw_monitor_scores
invoke BowlingMonitorText3D,target,36,30,OFFSET bwFreeText3D,0FF55D9CFh
jmp bw_monitor_advance
bw_monitor_scores:
invoke BowlingMonitorText3D,target,8,21,OFFSET bwPlayerA3D,0FFFF9F89h
invoke BowlingMonitorText3D,target,70,21,OFFSET bwPlayerB3D,0FF55D9CFh
lea ebx,[esi*8]
invoke FormatNumber,bwScores3D[ebx],ADDR number
invoke BowlingMonitorText3D,target,8,33,ADDR number,0FFFFFFFFh
invoke FormatNumber,bwScores3D[ebx+4],ADDR number
invoke BowlingMonitorText3D,target,70,33,ADDR number,0FFFFFFFFh
mov eax,bwState3D[esi*4]
mov eax,bwPhaseTexts3D[eax*4]
invoke BowlingMonitorText3D,target,8,51,eax,0FFFFBF70h
bw_monitor_advance:
inc esi
cmp esi,BW_LANES
jb bw_monitor_lane
bw_monitors_done:
ret
RefreshBowlingMonitors3D ENDP