Prev: B3F6 Up: Map Next: B495
B417: Action: Wiresnips
This handles the hero using the snips to cut through a wire fence.
Check the hero's position against the four vertically-oriented fences.
action_wiresnips B417 LD HL,$B589 Point HL at the 12th entry of the walls array: the start of the vertically-oriented fences PLUS three bytes so it points at the maxy value.
B41A LD DE,$81B9 Point DE at hero_map_position.y
B41D LD B,$04 Set B for four iterations (four vertical fences)
Start loop
action_wiresnips_0 B41F PUSH HL Preserve the wall entry pointer during this iteration
Are we in range on the Y axis?
B420 LD A,(DE) Fetch hero_map_position.y
B421 CP (HL) Is it >= wall->maxy?
B422 JR NC,snips_next_vert Jump to the next iteration if so
B424 DEC HL Step HL back to wall->miny
B425 CP (HL) Is it < wall->miny?
B426 JR C,snips_next_vert Jump to the next iteration if so
Are we adjacent to the wall on the X axis?
B428 DEC DE Step DE back to hero_map_position.x
B429 LD A,(DE) Fetch hero_map_position.x
B42A DEC HL Step HL back to wall->maxx
B42B CP (HL) Is it == wall->maxx?
B42C JR Z,snips_crawl_tl Jump to snips_crawl_tl if so
B42E DEC A Try the opposite side
B42F CP (HL) Is it == wall->maxx?
B430 JR Z,snips_crawl_br Jump to snips_crawl_br if so
B432 INC DE Advance DE to hero_map_position.y
snips_next_vert B433 POP HL Restore wall array pointer
B434 LD A,L Advance HL to the next wall array element PLUS 3 bytes
B435 ADD A,$06
B437 LD L,A
B438 JR NC,action_wiresnips_1
B43A INC H
action_wiresnips_1 B43B DJNZ action_wiresnips_0 ...loop
Check the hero's position against the three horizontally-oriented fences.
B43D DEC DE Step DE back to hero_map_position.x
Point HL at the 16th entry of walls array (start of horizontal fences).
B43E DEC HL Step HL back to the 16th entry of the walls array PLUS 0 bytes (it's three ahead prior to this)
B43F DEC HL
B440 DEC HL
B441 LD B,$03 Set B for three iterations (three horizontal fences)
Start loop
action_wiresnips_2 B443 PUSH HL Preserve wall array pointer during this iteration
Are we in range on the X axis?
B444 LD A,(DE) Fetch hero_map_position.x
B445 CP (HL) Is it < wall->minx?
B446 JR C,snips_next_horz Jump to the next iteration if so
B448 INC HL Advance HL to wall->maxx
B449 CP (HL) Is x >= wall->maxx?
B44A JR NC,snips_next_horz Jump to the next iteration if so
Are we adjacent to the wall on the Y axis?
B44C INC DE Advance DE to hero_map_position.y
B44D LD A,(DE) Fetch hero_map_position.y
B44E INC HL Advance HL to wall->miny
B44F CP (HL) Is it == wall->miny?
B450 JR Z,snips_crawl_tr Jump to snips_crawl_tr if so
B452 DEC A Try the opposite side
B453 CP (HL) Is it == wall->maxy?
B454 JR Z,snips_crawl_bl Jump to snips_crawl_bl if so
B456 DEC DE Step DE back to hero_map_position.x
snips_next_horz B457 POP HL Restore wall array pointer
B458 LD A,L Advance HL to the next wall array element PLUS 3 bytes
B459 ADD A,$06
B45B LD L,A
B45C JR NC,action_wiresnips_3
B45E INC H
action_wiresnips_3 B45F DJNZ action_wiresnips_2 ...loop
B461 RET Return
snips_crawl_tl B462 LD A,$04 Set A to 4 (direction_TOP_LEFT + vischar_DIRECTION_CRAWL)
B464 JR snips_tail Jump forward
snips_crawl_tr B466 LD A,$05 Set A to 5 (direction_TOP_RIGHT + vischar_DIRECTION_CRAWL)
B468 JR snips_tail Jump forward
snips_crawl_br B46A LD A,$06 Set A to 6 (direction_BOTTOM_RIGHT + vischar_DIRECTION_CRAWL)
B46C JR snips_tail Jump forward
snips_crawl_bl B46E LD A,$07 Set A to 7 (direction_BOTTOM_LEFT + vischar_DIRECTION_CRAWL)
A is the direction + crawl flag. Proceed to making the hero cut the wire.
snips_tail B470 POP HL Restore wall array pointer
B471 LD HL,$800E Set hero's vischar.direction field (direction and walk/crawl flag) to the direction selected above
B474 LD (HL),A
B475 DEC L Set hero's vischar.input field to input_KICK
B476 LD (HL),$80
B478 LD HL,$8001 Set hero's vischar.flags to vischar_FLAGS_CUTTING_WIRE
B47B LD (HL),$02
B47D LD A,$0C Set hero's vischar.mi.pos.height to 12
B47F LD ($8013),A
B482 LD HL,$CE2E Set vischar.mi.sprite to the prisoner sprite set
B485 LD ($8015),HL
B488 LD A,($A12F) Lock out the player until the game counter is now + 96
B48B ADD A,$60
B48D LD ($A145),A
B490 LD B,$0B Queue the message "CUTTING THE WIRE" and exit via
B492 JP queue_message
Prev: B3F6 Up: Map Next: B495