Prev: 9252 Up: Map Next: 9308
9257: STRIKE (break something)
Breaking things - STRIKE, BREAK and SMASH, and THROW at something that is not alive. Things that pour cannot be broken, and nor can anything with a defence of 0. If there is an instrument, it must have some strength and must itself have a STRIKE handler (so you can smash a door with the sword but not with the lunch).
The force is the instrument's strength plus the actor's strength plus a random number from -21 to +21 (9BFD), capped at 255. If that is at least the target's defence, the target breaks: it is marked broken, its adjective becomes BROKEN (A0BC), its strength is halved, and if it is a container its contents fall out. 'the door is broken.'
Then the instrument may break too, whether or not the target did: its defence plus a random number from -21 to +21 is compared with the target's defence, and if it is at least as large the instrument breaks. As written, this makes a tougher instrument more likely to break. Worse, the addition has the same carry-flag mistake as the fight code (917D): a negative random number sets the carry, which is taken as an overflow, and the value becomes 255 - so the instrument breaks whenever the random number is negative. In 40 test runs in the emulator of BREAK DOOR WITH SWORD against the heavy rock door, the sword broke 9 times; with the bow, whose defence of 16 could never reach the door's 144 honestly, the bow still broke 5 times.
9257 LD IX,($B5F8) IX = the target's record
925B BIT 1,(IX+$07) Is the object "evaporates" (bit 1 of its flags)?
925F JP NZ,$9EBF If the bit is set, go to Report failure (9EBF)
9262 BIT 3,(IX+$07) Is the object dead/broken (bit 3 of its flags)?
9266 JP NZ,$9303 If the bit is set, go to 9303
9269 SUB A A = 0
926A CP (IX+$06) Compare with the byte at (IX+$06)
926D JP Z,$9EBF If yes, go to Report failure (9EBF)
9270 LD B,A B = A
9271 LD A,($B5DA) A = the instrument
9274 INC A (sets Z if A was $FF: none)
9275 JR Z,$9296 If it is zero, go to 9296
9277 LD IY,($B5FA) IY = the instrument's record
927B LD A,(IY+$05) A = the object's strength
927E AND A Is A zero?
927F JP Z,$9EBF If it is zero, go to Report failure (9EBF)
9282 PUSH IX Save IX
9284 LD IX,($B5FA) IX = the instrument's record
9288 LD A,$0B A = 11
928A CALL $9ADC Call: Find an object's handler for an action (9ADC)
928D POP IX Restore IX
928F INC A Increment A
9290 JP Z,$9EBF If the routine returned with Z set, go to Report failure (9EBF)
9293 LD B,(IY+$05) B = the object's strength
9296 CALL $9C99 Dry run? Then just record that this would work, and return from the caller
9299 LD A,$15 A = 21
929B CALL $9BFD Call: Random number in a range (9BFD)
929E ADD A,B Add A,B
929F LD IY,($B5FC) IY = the actor's record
92A3 ADD A,(IY+$05) Add the object's strength
92A6 JR NC,$92AA If the routine returned with carry reset, go to 92AA
92A8 LD A,$FF A = 255
92AA SUB (IX+$06) Subtract the object's defence
92AD JR C,$92CA If carry is set, go to 92CA
92AF SET 3,(IX+$07) Set the object's "dead/broken" flag (bit 3)
92B3 LD A,($B5D9) A = the target
92B6 CALL $A0BC Call: Mark an object as dead or broken (A0BC)
92B9 SRA (IX+$05) Shift/rotate (IX+$05)
92BD LD A,(IX+$04) How are the target's contents described?
92C0 CP $02 In (0) or on (1)?
92C2 CALL C,$9CA5 Then they fall out of the broken container
92C5 LD A,$83 A = 131
92C7 CALL $A09C Call: "The X is Y" (A09C)
92CA LD A,($B5DA) A = the instrument
92CD CP $FF Is it nobody ($FF)?
92CF RET Z Return if yes
92D0 LD IY,($B5FA) IY = the instrument's record
92D4 BIT 3,(IY+$07) Is the object dead/broken (bit 3 of its flags)?
92D8 RET NZ Return if the bit is set
92D9 LD B,(IY+$06) B = the object's defence
92DC LD A,$15 A = 21
92DE CALL $9BFD Call: Random number in a range (9BFD)
92E1 ADD A,B Add A,B
92E2 JR NC,$92E6 If the routine returned with carry reset, go to 92E6
92E4 LD A,$FF A = 255
92E6 SUB (IX+$06) Subtract the object's defence
92E9 RET C Return if carry is set
92EA SET 3,(IY+$07) Set the object's "dead/broken" flag (bit 3)
92EE LD A,($B5DA) A = the instrument
92F1 CALL $A0BC Call: Mark an object as dead or broken (A0BC)
92F4 LD A,(IY+$05) A = the object's strength
92F7 SRA A Shift/rotate A
92F9 LD (IY+$05),A Set the object's strength to A
92FC CALL $9CA5 Call: Drop everything the target holds (9CA5)
92FF PUSH IY Save IY
9301 POP IX Restore IX
9303 LD A,$83 A = 131
9305 JP $A09C Finish by jumping to "The X is Y" (A09C)
Prev: 9252 Up: Map Next: 9308