Prev: 35449 Up: Map Next: 35560
35451: SwapHeldItems
Action on the back-item row (9): swap the actor's front and back hands — exchange HeldItemFront/HeldItemBack, flip the two markers in ItemLocations (29940) by +/-32, adjust the sprite position by the difference of the two courage bonuses, and redraw the front item's name.
35451 CALL 31820 refresh HeldItemFront/Back for this actor
35454 LD (IX+0),0
35458 LD DE,(31248) E = front item, D = back item
35462 LD HL,29984 ItemCourageBonus:
35465 PUSH HL
35466 LD C,E
35467 LD B,0
35469 ADD HL,BC
35470 LD E,(HL) E = bonus[front]
35471 LD C,D
35472 POP HL
35473 ADD HL,BC
35474 LD D,(HL) D = bonus[back]
35475 LD A,(IX+5) courage += bonus[back] - bonus[front]
35478 SUB E
35479 ADD A,D
35480 CP 127 (clamp underflow to 0)
35482 JR C,35485
35484 XOR A
35485 LD (IX+5),A
35488 LD A,(IX+6) morale likewise
35491 SUB E
35492 ADD A,D
35493 CP 127
35495 JR C,35498
35497 XOR A
35498 LD (IX+6),A
35501 LD BC,(31248) C = front item, B = back item
35505 LD L,B swap HeldItemFront <-> HeldItemBack
35506 LD H,C
35507 LD (31248),HL
35510 LD HL,29940 ItemLocations:
35513 PUSH HL
35514 LD E,C old front item's marker -32
35515 LD D,0 (160+slot -> 128+slot: now in the back hand)
35517 ADD HL,DE
35518 LD A,(HL)
35519 SUB 32
35521 LD (HL),A
35522 POP HL
35523 LD E,B old back item's marker +32
35524 ADD HL,DE (128+slot -> 160+slot: now in front)
35525 LD A,(HL)
35526 ADD A,32
35528 LD (HL),A
35529 LD HL,18486 redraw the " use:" rows:
35532 LD (31257),HL
35535 LD A,(31248)
35538 CALL 31857
35541 CALL 31634 draw the new front item's name
35544 LD A,(31249)
35547 CALL 31857 and the new back item's name
35550 CALL 31634
35553 CALL 32385
35556 CALL 36793
35559 RET
Prev: 35449 Up: Map Next: 35560