Skip to content

Commit

Permalink
Randomize & check entry codes properly. Minor size-optimization of sc…
Browse files Browse the repository at this point in the history
…ript code.
  • Loading branch information
cadaver committed Jan 10, 2016
1 parent e9158fa commit 87c895a
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 35 deletions.
4 changes: 2 additions & 2 deletions enemy.s
Original file line number Diff line number Diff line change
Expand Up @@ -1277,9 +1277,9 @@ MovePersistentNPC:
lda menuMode
bne MPNPC_InDialogue
ldy actT,x
ldx actScript-ACT_FIRSTPERSISTENTNPC,y
ldx actScriptF-ACT_FIRSTPERSISTENTNPC,y
beq MPNPC_NoScript
lda actEP-ACT_FIRSTPERSISTENTNPC,y
lda actScriptEP-ACT_FIRSTPERSISTENTNPC,y
jsr ExecScript
MPNPC_NoScript: ldx actIndex
MPNPC_InDialogue:
Expand Down
4 changes: 2 additions & 2 deletions level.s
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ UpdateLevelObjects:
inc attackTime
ULO_NoGlobalAttack:
ldx scriptF ;Check for continuous script execution
bmi ULO_NoScript
beq ULO_NoScript ;Can't be from scriptfile 0 (title)
lda scriptEP
jsr ExecScript
ULO_NoScript: ldy autoDeactObjNum ;Check object auto-deactivation
Expand Down Expand Up @@ -1197,7 +1197,7 @@ ULO_SkipDestDoorActivation:
jsr MH_SetGrounded
jsr MH_ResetFall
lda #$40
sta actYL,x
sta actYL+ACTI_PLAYER
ULO_FinePositionLoop: ;Fineposition player to ground at floor
lda #8*8
jsr MoveActorY
Expand Down
7 changes: 4 additions & 3 deletions leveldata.s
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ score: ds.b 3,0
battery: ds.b 2,0
oxygen: dc.b 0
plotBits: ds.b MAX_PLOTBITS/8,0
actScript: ds.b MAX_PERSISTENTNPCS,0
actEP: ds.b MAX_PERSISTENTNPCS,0
actScriptF: ds.b MAX_PERSISTENTNPCS,0
actScriptEP: ds.b MAX_PERSISTENTNPCS,0
codes: ds.b MAX_CODES*3,0
playerStateZeroEnd:
invMag: ds.b ITEM_LAST_MAG-ITEM_FIRST_MAG+1,0
invCount: ds.b ITEM_LAST-ITEM_FIRST+1,0
Expand All @@ -38,7 +39,7 @@ playerStateEnd:
endif

; Not saved variables
; Note: must be at least 4
; Note: must be at least 4, due to code that skips saving of time

scriptVariable: dc.b 0
codeEntry: ds.b 3,0
Expand Down
3 changes: 2 additions & 1 deletion memory.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ MAX_LVLACT = 96 ;Allow extra 16 global or tempor
MAX_GLOBALACT = MAX_LVLACT-MAX_LVLDATAACT
MAX_SAVEACT = 24 ;Amount of persistent actors saved in save optimize mode
MAX_LVLOBJ = 96
MAX_PLOTBITS = 64
MAX_PLOTBITS = 16
MAX_SAVES = 5
MAX_PERSISTENTNPCS = 3
MAX_CODES = 8

ACTI_PLAYER = 0
ACTI_FIRSTNPC = 1
Expand Down
2 changes: 1 addition & 1 deletion script.s
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ ES_ScriptJump: jmp $1000
; Returns: -
; Modifies: -

StopScript: ldx #$ff
StopScript: ldx #$00
SetScript: stx scriptF
sta scriptEP
ES_LoadOnly: rts
Expand Down
15 changes: 7 additions & 8 deletions script00.s
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,25 @@ START_Y = $1700
TitleScreen: jsr BlankScreen
lda #REDRAW_ITEM+REDRAW_AMMO+REDRAW_SCORE ;Redraw all
sta panelUpdateFlags
lda #$00 ;Armor message no longer necessary,
sta armorMsgTime ;as game is over
jsr ClearPanelText
jsr InitScroll ;Make sure no scrolling

; Load logo chars & clear screen

jsr StopScript
stx Irq1_Bg1+1 ;X=0 on return
stx Irq1_Bg2+1
stx Irq1_Bg3+1
stx menuMode ;Reset in-game menu mode
stx armorMsgTime ;Reset armor message if any
dex
stx ECS_LoadedCharSet+1 ;Mark game charset destroyed (X=$ff)
lda #F_LOGO
jsr MakeFileName_Direct
lda #<logoStart
ldx #>logoStart
jsr LoadFileRetry
lda #$00 ;Fade out colors initially
sta Irq1_Bg1+1
sta Irq1_Bg2+1
sta Irq1_Bg3+1
sta menuMode ;Reset in-game menu mode

lda #$03
sta screen ;Set split screen mode
lda #$0f
Expand Down Expand Up @@ -491,7 +491,6 @@ IP_InitInventory:
ldx #50
jsr AddItem
endif
jsr StopScript ;Stop any continuous script
lda #START_LEVEL
sta levelNum
lda #$00
Expand Down
32 changes: 29 additions & 3 deletions script01.s
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,31 @@ ECL_Next: jsr ECL_Sound
stx numberIndex
cpx #3
bcc ECL_Done
jsr OO_RequirementOK ;Open the door. TODO: actually verify code
ldx #MAX_CODES-1
ECL_Verify: lda levelNum
cmp codeLevel,x
bne ECL_VerifyNext
lda lvlObjNum
cmp codeObject,x
beq ECL_VerifyFound
ECL_VerifyNext: dex
bpl ECL_Verify
ECL_VerifyFound:txa
sta temp1
asl
adc temp1
tay
ldx #$00
ECL_VerifyLoop: lda codeEntry,x
cmp codes,y
bne ECL_Finish
iny
inx
cpx #$03
bcc ECL_VerifyLoop
jsr OO_RequirementOK ;Open the door if code right
ECL_Finish: jsr StopScript
ldx #MENU_NONE
jmp SetMenuMode
jmp SetMenuMode ;X=0 on return

; Recycling station script routine
;
Expand Down Expand Up @@ -606,6 +627,11 @@ elevatorPlotBit:
elevatorSpeed: dc.b 48,-48,-64,64
elevatorAcc: dc.b 2,-2,-2,2

; Code entry tables

codeLevel: dc.b $05,$06,$06,$08,$08,$08,$0c,$08
codeObject: dc.b $12,$29,$27,$16,$27,$22,$08,$31

; Recycler tables

recyclerCountTbl:
Expand Down
26 changes: 19 additions & 7 deletions script02.s
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
dc.w Scientist2
dc.w RadioUpperLabsEntrance

; Finalize game start. Create persistent NPCs to the leveldata
; Finalize game start. Create persistent NPCs to the leveldata and randomize entry codes
;
; Parameters: -
; Returns: -
Expand All @@ -33,17 +33,28 @@ GS_Loop: jsr GetLevelActorIndex
dex
bpl GS_Loop
lda #<EP_SCIENTIST2 ;Initial NPC scripts to drive the plot forward
sta actEP
sta actScriptEP
lda #>EP_SCIENTIST2
sta actScript
sta actScriptF
lda #<EP_HACKER
sta actEP+2
sta actScriptEP+2
lda #>EP_HACKER
sta actScript+2
sta actScriptF+2
ldx #(MAX_CODES)*3-1
GS_CodeLoop: jsr Random
and #$0f
cmp #$0a
bcs GS_CodeLoop
sta codes,x
dex
bpl GS_CodeLoop
lda codes+MAX_CODES*3-1 ;Make the last (nether tunnels) code initially
ora #$80 ;impossible to enter, even by guessing
sta codes+MAX_CODES*3-1
jsr FindPlayerZone ;Need to get starting level's charset so that save is named properly
jsr SaveCheckpoint ;Save first in-memory checkpoint immediately
jmp CenterPlayer

; Scientist 1 (intro) move routine
;
; Parameters: X actor number
Expand Down Expand Up @@ -229,7 +240,7 @@ S2_Dialogue4: lda #ITEM_COMMGEAR
lda #SFX_PICKUP
jsr PlaySfx
lda #$00
sta actScript ;No more script exec here
sta actScriptF ;No more script exec here
ldy #ACT_SCIENTIST2
lda #<txtHideoutDialogue4
ldx #>txtHideoutDialogue4
Expand Down Expand Up @@ -271,6 +282,7 @@ txtDyingDialogue:
dc.b 34,"ARGH, I'M NO GOOD TO GO ON. SEARCH THE UPSTAIRS - YOU'LL NEED A PASSCARD WE USED TO LOCK UP THIS PLACE. "
dc.b "WATCH OUT FOR MORE OF THOSE BASTARDS.. AND ONE FINAL THING - THE NANOBOTS RUNNING YOUR BODY DEPEND ON BATTERY POWER. "
dc.b "DON'T RUN OUT.",34,0

txtHideoutDialogue1:
dc.b 34,"I SEE VIKTOR DIDN'T MAKE IT. BUT YOU DID, THAT'S WHAT COUNTS. AMOS, NANOSURGEON. SHE'S LINDA, CYBER-PSYCHOLOGIST. "
dc.b "YOU'VE SEEN HOW OUR CREATIONS HAVE TURNED ON US. THERE'S A TOTAL COMMS BLACKOUT. WE'RE STUCK AND HELP IS UNLIKELY. "
Expand Down
4 changes: 2 additions & 2 deletions script03.s
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ H_Random: jsr Random
adc #$36 ;Randomize between 75%, 85%, 95%
sta txtPercent
lda #<EP_HACKER2
sta actEP+2 ;Set 2nd script
sta actScriptEP+2 ;Set 2nd script
ldy #ACT_HACKER
lda #<txtHacker
ldx #>txtHacker
Expand All @@ -413,7 +413,7 @@ Hacker2: ldy #ITEM_AMPLIFIER
cmp #FR_DUCK
bcs H_NoItem
lda #$00 ;No more scripts for now
sta actScript+2
sta actScriptF+2
ldy #ACT_HACKER
lda #<txtHacker2
ldx #>txtHacker2
Expand Down
3 changes: 1 addition & 2 deletions script04.s
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,7 @@ IE_NoSound: lda installColor
rts
IE_Restore: jmp SetZoneColors
IE_End: jsr StopScript
ldx #MENU_NONE
jsr SetMenuMode
jsr SetMenuMode ;X=0 on return
lda #<1000
ldy #>1000
jsr AddScore
Expand Down
3 changes: 1 addition & 2 deletions script05.s
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ RL_Explode: ldy #$0f
lda #SFX_EXPLOSION
jmp PlaySfx
RL_Finish: jsr StopScript
ldx #MENU_NONE
jsr SetMenuMode
jsr SetMenuMode ;X=0 on return
jmp CenterPlayer

; Generator (screen shake) move routine
Expand Down
3 changes: 1 addition & 2 deletions script08.s
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ TMR_MoveRight: tya
TMR_Decision: lda tmChoice
bne TMR_Drive
TMR_Finish: jsr StopScript
ldx #MENU_NONE
jmp SetMenuMode
jmp SetMenuMode ;X=0 on return
TMR_Drive: jsr AddQuestScore
jsr TMR_Finish
lda #$00
Expand Down

0 comments on commit 87c895a

Please sign in to comment.