Prev: 42450 Up: Map Next: 42575
42453: Update Prices
Used by the routine at CreateTownObjects.
Called every frame, but only does anything when the low byte of the frame counter is 189 so once every 256 frames. It picks one of the three amounts on the telegram at random: the fine, the price of a horse or the price of a bullet. If the telegram has finished typing it chooses a new price from a table and retypes that line. The higher the level, the more prices the table offers, so prices tend to rise as the game goes on.
UpdatePrices 42453 LD HL,(41494) Fetch the frame counter.
42456 LD A,L Copy its low byte into A.
42457 ADD A,67 Add 67 which gives zero only when the low byte is 189.
42459 RET NZ Return unless it is.
42460 LD A,(41496) Fetch a random number.
42463 AND %00000011 Keep bits 0 and 1.
42465 JR Z,UpdatePrices_Fine Jump to UpdatePrices_Fine to change the fine if the number is zero.
42467 DEC A Jump to UpdatePrices_HorsePrice to change the price of a horse if the number is one.
42468 JR Z,UpdatePrices_HorsePrice
Change the price of a bullet.
42470 CALL CheckTelegramComplete Check whether the telegram has finished typing.
42473 RET NZ Return if it has not.
42474 XOR A Write 0 to TelegramLines to start typing the bullet line again.
42475 LD (43056),A
42478 LD HL,41567 Point HL at BulletPrice_HighByte.
42481 LD DE,43069 Point DE at TelegramLines_BulletDigits.
42484 EXX Keep both in the alternate registers.
42485 LD HL,42591 Point HL at BulletPrices.
Choose a new price from the table at HL, using more of the table as the level goes up.
UpdatePrices_ChooseNewPrice 42488 LD A,(41568) Fetch the level.
42491 CP 6 Jump to UpdatePrices_TestLevelThirteen if the level is six or more.
42493 JR NC,UpdatePrices_TestLevelThirteen
42495 LD A,2 Allow the first two prices.
42497 JR UpdatePrices_StoreAllowed Jump to UpdatePrices_StoreAllowed.
UpdatePrices_TestLevelThirteen 42499 CP 13 Jump to UpdatePrices_AllowEight if the level is thirteen or more.
42501 JR NC,UpdatePrices_AllowEight
42503 LD A,4 Allow the first four prices.
42505 JR UpdatePrices_StoreAllowed Jump to UpdatePrices_StoreAllowed.
UpdatePrices_AllowEight 42507 LD A,8 Allow all eight prices.
UpdatePrices_StoreAllowed 42509 LD C,A Copy the number of prices that are allowed into C.
42510 LD A,(41497) Fetch a random number.
42513 AND %00001111 Keep a number between 0 and 15.
UpdatePrices_ChooseNewPriceLoop 42515 CP C Jump to UpdatePrices_ReadPrice once the number is less than the number of prices allowed.
42516 JR C,UpdatePrices_ReadPrice
42518 SUB C Otherwise subtract the number of prices allowed.
42519 JR UpdatePrices_ChooseNewPriceLoop Loop back to UpdatePrices_ChooseNewPriceLoop.
UpdatePrices_ReadPrice 42521 ADD A,A Double the number to get an offset into the table of words.
42522 LD E,A Copy the offset into E.
42523 LD D,0 Clear D.
42525 ADD HL,DE Point HL at the chosen price.
42526 LD C,(HL) Fetch the low byte of the price.
42527 INC HL Move on to the high byte.
42528 LD B,(HL) Fetch the high byte of the price.
42529 PUSH BC Stash the price on the stack.
42530 EXX Bring back the address of the price and the digits.
42531 POP BC Fetch the new price into BC.
42532 JP ResetBulletPrice_SetPrice Store the new price, convert it to text and start typing the line again.
Change the fine.
UpdatePrices_Fine 42535 CALL CheckTelegramComplete Check whether the telegram has finished typing.
42538 RET NZ Return if it has not.
42539 XOR A Write 0 to 43092 to start typing the fine line again.
42540 LD (43092),A
42543 LD HL,41563 Point HL at Fine_HighByte.
42546 LD DE,43105 Point DE at TelegramLines_FineDigits.
42549 EXX Keep both in the alternate registers.
42550 LD HL,42623 Point HL at FineAmounts.
42553 JR UpdatePrices_ChooseNewPrice Jump to UpdatePrices_ChooseNewPrice.
Change the price of a horse.
UpdatePrices_HorsePrice 42555 CALL CheckTelegramComplete Check whether the telegram has finished typing.
42558 RET NZ Return if it has not.
42559 XOR A Write 0 to 43074 to start typing the horse line again.
42560 LD (43074),A
42563 LD HL,41565 Point HL at HorsePrice_HighByte.
42566 LD DE,43087 Point DE at TelegramLines_HorseDigits.
42569 EXX Keep both in the alternate registers.
42570 LD HL,42607 Point HL at HorsePrices.
42573 JR UpdatePrices_ChooseNewPrice Jump to UpdatePrices_ChooseNewPrice.
Prev: 42450 Up: Map Next: 42575