aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstatin <[email protected]>2025-03-18 19:12:59 +0900
committerAstatin <[email protected]>2025-03-18 19:12:59 +0900
commit579e73311319868d8b186e3442098358d839b3b3 (patch)
treeb21d556c7c6a5e72b0c25a224711c2e553e46abb
parenta29c10798a8064542ac04a5160baaa9b406ef239 (diff)
Add generation events to be executed on floor generation
-rw-r--r--definitions.gbasm14
-rw-r--r--dialogues/demo_quest.gbasm13
-rw-r--r--dialogues/text.gbasm24
-rw-r--r--dialogues/text.gbtxt24
-rw-r--r--entity/bunny.gbasm1
-rw-r--r--entity/init.gbasm47
-rw-r--r--main.gbasm16
-rw-r--r--map/generationevents.gbasm111
-rw-r--r--rng.gbasm2
-rw-r--r--utils.gbasm2
10 files changed, 230 insertions, 24 deletions
diff --git a/definitions.gbasm b/definitions.gbasm
index 760751c..6a01759 100644
--- a/definitions.gbasm
+++ b/definitions.gbasm
@@ -170,6 +170,20 @@
; _padding: u32
; }
+.DEFINE mem_dungeon_generation_events $c9c0 ; Takes the memory from c9c0 to c9ff (16 events)
+; struct events {
+; floor_idx: u8,
+;
+; dungeon_gen_event_jump_table_index: u8
+; 00: Nothing
+; 01: Start dialogue at the beggining
+; 02: Spawn a special entity (should not be used twice on the same floor
+;
+; free_parameters: (u16)
+; 01: Dialogue script address
+; 02: Entity template index (u8 + padding8)
+; }
+
.DEFINE mem_oam_buffer $ca00 ; Until $ca9f
.DEFINE mem_oam_buffer_low ($c980)
diff --git a/dialogues/demo_quest.gbasm b/dialogues/demo_quest.gbasm
index ea9dd46..20e630d 100644
--- a/dialogues/demo_quest.gbasm
+++ b/dialogues/demo_quest.gbasm
@@ -3,3 +3,16 @@ Demo_quest_bunny:
.TEXT =Dialogue_1_2t =Dialogue_1_2b
.TEXT =Dialogue_1_3t =Empty
.END
+
+Demo_quest_init:
+.TEXTB =Bunny_Header_Text =Dialogue_2_1b
+.TEXT =Dialogue_2_2t =Empty
+.TEXT =Dialogue_2_3t =Dialogue_2_3b
+.TEXT =Dialogue_2_4t =Dialogue_2_4b
+.TEXT =Dialogue_2_5t =Empty
+.END
+
+Demo_quest_floor_reach:
+.TEXT =Dialogue_3_1t =Dialogue_3_1b
+.TEXT =Dialogue_3_2t =Dialogue_3_2b
+.TEXT =Dialogue_3_3t =Empty
diff --git a/dialogues/text.gbasm b/dialogues/text.gbasm
index c8895d7..c64f37b 100644
--- a/dialogues/text.gbasm
+++ b/dialogues/text.gbasm
@@ -10,3 +10,27 @@ Dialogue_1_2b:
.DB 0x8d, 0x9e, 0x97, 0x90, 0x8e, 0x98, 0x97, 0xa4, 0xff
Dialogue_1_3t:
.DB 0xa0, 0x98, 0x9e, 0x95, 0x8d, 0x0, 0xa2, 0x98, 0x9e, 0x0, 0x91, 0x8e, 0x95, 0x99, 0x0, 0x96, 0x8e, 0xa6, 0xff
+Dialogue_2_1b:
+.DB 0x91, 0x8e, 0x95, 0x99, 0x0, 0xa5, 0xff
+Dialogue_2_2t:
+.DB 0xa4, 0xa4, 0xa4, 0xff
+Dialogue_2_3t:
+.DB 0xa2, 0x98, 0x9e, 0x0, 0x91, 0x8e, 0x8a, 0x9b, 0x8d, 0x0, 0x9c, 0x98, 0x96, 0x8e, 0x98, 0x97, 0x8e, 0xff
+Dialogue_2_3b:
+.DB 0x9c, 0x91, 0x98, 0x9e, 0x9d, 0x92, 0x97, 0x90, 0xa4, 0xff
+Dialogue_2_4t:
+.DB 0x92, 0x9d, 0x0, 0x9c, 0x98, 0x9e, 0x97, 0x8d, 0x9c, 0x0, 0x95, 0x92, 0x94, 0x8e, 0x0, 0x92, 0x9d, 0xff
+Dialogue_2_4b:
+.DB 0x8c, 0x8a, 0x96, 0x8e, 0x0, 0x8f, 0x9b, 0x98, 0x96, 0x0, 0x9d, 0x91, 0x8e, 0xff
+Dialogue_2_5t:
+.DB 0x81, 0x80, 0x9d, 0x91, 0x0, 0x8f, 0x95, 0x98, 0x98, 0x9b, 0xa4, 0xff
+Dialogue_3_1t:
+.DB 0x92, 0x0, 0x8a, 0x9b, 0x9b, 0x92, 0x9f, 0x8e, 0x8d, 0x0, 0x8a, 0x9d, 0x0, 0x9d, 0x91, 0x8e, 0xff
+Dialogue_3_1b:
+.DB 0x81, 0x80, 0x9d, 0x91, 0x0, 0x8f, 0x95, 0x98, 0x98, 0x9b, 0xa4, 0xff
+Dialogue_3_2t:
+.DB 0x92, 0x0, 0x9c, 0x91, 0x98, 0x9e, 0x95, 0x8d, 0x0, 0x9d, 0x9b, 0xa2, 0x0, 0x9d, 0x98, 0xff
+Dialogue_3_2b:
+.DB 0x8f, 0x92, 0x97, 0x8d, 0x0, 0xa0, 0x91, 0x98, 0x0, 0x8c, 0x8a, 0x95, 0x95, 0x8e, 0x8d, 0xff
+Dialogue_3_3t:
+.DB 0x8f, 0x98, 0x9b, 0x0, 0x91, 0x8e, 0x95, 0x99, 0x0, 0x8e, 0x8a, 0x9b, 0x95, 0x92, 0x8e, 0x9b, 0xa4, 0xff
diff --git a/dialogues/text.gbtxt b/dialogues/text.gbtxt
index 64c16b2..cb8c619 100644
--- a/dialogues/text.gbtxt
+++ b/dialogues/text.gbtxt
@@ -1,8 +1,32 @@
Empty:
Bunny_Header_Text: Bunny:
+
+
Dialogue_1_1b: Hello !
Dialogue_1_2t: I am stuck in this
Dialogue_1_2b: dungeon.
Dialogue_1_3t: Would you help me?
+
+
+Dialogue_2_1b: Help !
+
+Dialogue_2_2t: ...
+
+Dialogue_2_3t: You heard someone
+Dialogue_2_3b: shouting.
+
+Dialogue_2_4t: It sounds like it
+Dialogue_2_4b: came from the
+
+Dialogue_2_5t: 10th floor.
+
+
+Dialogue_3_1t: I arrived at the
+Dialogue_3_1b: 10th floor.
+
+Dialogue_3_2t: I should try to
+Dialogue_3_2b: find who called
+
+Dialogue_3_3t: for help earlier.
diff --git a/entity/bunny.gbasm b/entity/bunny.gbasm
index 32cff97..29f66d9 100644
--- a/entity/bunny.gbasm
+++ b/entity/bunny.gbasm
@@ -147,7 +147,6 @@ Move_Bunny:
DEC A
DAA
LD (HL+), A
- DBG
SET 3, (HL)
LD A, $24
diff --git a/entity/init.gbasm b/entity/init.gbasm
index e9a3cbc..5d5676a 100644
--- a/entity/init.gbasm
+++ b/entity/init.gbasm
@@ -95,8 +95,6 @@ Initialize_Entities:
LD A, $ff
LD $mem_bunny_current_room_idx, A
- LD A, $07
- CALL =Initialize_Entity
CALL =Initialize_Enemy
CALL =Initialize_Enemy
CALL =Initialize_Enemy
@@ -136,7 +134,7 @@ Initialize_Enemy: ; HL => pointer to entity struct
AND $03
ADD $03
-Initialize_Entity: ; HL => pointer to entity struct, A => entity loaded index
+Initialize_Entity: ; HL => pointer to entity struct, A => entity loaded index, 1 in $tmp_var_3 if should retry if collsion (could potentially fail multiple time/infinite loop)
LD E, A
SLA A
SLA A
@@ -166,6 +164,8 @@ Initialize_Entity: ; HL => pointer to entity struct, A => entity loaded index
LD A, C
JR C, =Initialize_Enemy.Room_restriction.end
DEC A
+
+ LD A, E
JR =Initialize_Enemy.Room_restriction.end
Initialize_Enemy.All_rooms_allowed:
@@ -220,7 +220,13 @@ Initialize_Entity: ; HL => pointer to entity struct, A => entity loaded index
LD (HL), A
POP BC
- RET
+
+ LD A, $tmp_var_3
+ CP $01
+ RET Z
+
+ LD A, E
+ JP =Initialize_Entity
.no_collision:
CALL =Carve_Entity_Collision_Map
@@ -286,26 +292,14 @@ Initialize_Entity: ; HL => pointer to entity struct, A => entity loaded index
RET
-Respawn_Entities:
- LD A, $mem_moving_animation_step
- CP $04
- RET NZ
-
- LD A, $mem_enemies_alive_count
- CP $05
- RET NC
-
- CALL =RNG_Step
- AND $0f
- CP $00
- RET NZ
-
+FindFreeEntity:
LD HL, $mem_entities_list
FindFreeEntity.loop:
; This loop supposes that there is indeed enough space for a new entity
; to be spawn (thus the previous mem_enemies_alive_count).
; If entities are changed at some point to contain things that are not
; counted in mem_enemies_alive_count, this could result in an infinite loop.
+ ; (Technically the quest goals can spawn other entities. We assume that the enemies alive count and the quest goal entities spawned will never exceed 15 together)
LD A, L
AND $f0
ADD $10
@@ -314,6 +308,23 @@ Respawn_Entities:
LD A, $00
CP (HL)
JR NZ, =FindFreeEntity.loop
+ RET
+
+Respawn_Entities:
+ LD A, $mem_moving_animation_step
+ CP $04
+ RET NZ
+
+ LD A, $mem_enemies_alive_count
+ CP $05
+ RET NC
+
+ CALL =RNG_Step
+ AND $0f
+ CP $00
+ RET NZ
+
+ CALL =FindFreeEntity
CALL =Initialize_Enemy
RET
diff --git a/main.gbasm b/main.gbasm
index e22d5bb..699238c 100644
--- a/main.gbasm
+++ b/main.gbasm
@@ -100,6 +100,8 @@ Entrypoint:
LD $mem_bunny_mana, A
LD A, $01
LD $mem_floor_count, A
+ CALL =Init_DemoQuest_Event
+
New_Dungeon:
LD SP, $fffe
LD HL, $mem_loaded_enemies_indices
@@ -125,10 +127,6 @@ New_Dungeon:
CALL =Dungeon_Generation
CALL =Initialize_Entities
CALL =Initialize_Objects
- CALL =Load_Tile
- CALL =Load_Map
- CALL =Load_Objects
- CALL =Reload_Entities_Tile_Data
; Reset animations
LD HL, $mem_animation_list
@@ -171,6 +169,15 @@ New_Dungeon:
LD A, $f4
LD ($9d73), A
+ CALL =Generation_Event_Execution
+
+ CALL =Reload_Entities_Tile_Data
+ CALL =Reset_Entities_Collision_Map
+
+ CALL =Load_Tile
+ CALL =Load_Map
+ CALL =Load_Objects
+
.SET_WINDOW_LCDC_E
.ENABLE_TOP_BAR
.ENABLE_VBLANK_INTERRUPTS
@@ -309,6 +316,7 @@ STAT_Entrypoint:
.INCLUDE "map/loading.gbasm"
.INCLUDE "map/generation.gbasm"
.INCLUDE "map/objects.gbasm"
+.INCLUDE "map/generationevents.gbasm"
.INCLUDE "gui.gbasm"
.INCLUDE "dialogues/utils.gbasm"
.INCLUDE "entity/utils.gbasm"
diff --git a/map/generationevents.gbasm b/map/generationevents.gbasm
new file mode 100644
index 0000000..482c00e
--- /dev/null
+++ b/map/generationevents.gbasm
@@ -0,0 +1,111 @@
+Generation_Event_Execution:
+ LD A, $mem_floor_count
+ LD D, A
+ LD HL, $mem_dungeon_generation_events
+ .loop:
+ LD A, (HL+)
+ CP $00
+ JR Z, =.skip
+ CP D
+ JR NZ, =.skip
+
+ LD A, (HL+)
+ PUSH HL
+ PUSH DE
+ LD BC, =Generation_Event_Jump_Table
+
+ .JUMP_TABLE
+
+ POP DE
+ POP HL
+
+ .skip:
+ LD A, L
+ AND $fc
+ ADD $04
+ LD L, A
+ CP $00
+ JR NZ, =.loop
+ RET
+
+Generation_Event_Jump_Table:
+ ; 00
+ RET
+ NOP
+ NOP
+ NOP
+
+ ; 01
+ JP =.Dialogue_Script
+ NOP
+
+ ; 02
+ JP =.Entity
+ NOP
+
+ ; 03
+ JP =.Remove_Stairs
+
+ .Dialogue_Script:
+ LD A, $enum_dungeon_dialogue_mode
+ LD $mem_requested_mode, A
+
+ LD A, (HL+)
+ LD ($mem_dialogue_script_program_counter), A
+ LD A, (HL)
+ LD ($mem_dialogue_script_program_counter+1), A
+ JP =Dialogue_script_step
+
+ .Entity:
+ LD A, (HL)
+ LD $mem_loaded_special_entity_index, A
+
+ CALL =FindFreeEntity
+ LD A, $07
+ CALL =Initialize_Entity
+ RET
+
+ .Remove_Stairs:
+ LD HL, $mem_object_list
+ LD (HL), $00
+ RET
+
+Init_DemoQuest_Event:
+ LD HL, $mem_dungeon_generation_events
+
+ LD (HL), $01 ; floor
+ INC HL
+ LD (HL), $01 ; jump table dialogue script
+ INC HL
+ LD (HL), high(=Demo_quest_init)
+ INC HL
+ LD (HL), low(=Demo_quest_init)
+
+ INC HL
+
+ LD (HL), $10 ; floor
+ INC HL
+ LD (HL), $02 ; jump table entity
+ INC HL
+ LD (HL), $06 ; demo quest bunny idx
+ INC HL
+
+ INC HL
+
+ LD (HL), $10 ; floor
+ INC HL
+ LD (HL), $03 ; jump table remove stairs
+ INC HL
+ INC HL
+
+ INC HL
+
+ LD (HL), $10 ; floor
+ INC HL
+ LD (HL), $01 ; jump table dialogue script
+ INC HL
+ LD (HL), high(=Demo_quest_floor_reach)
+ INC HL
+ LD (HL), low(=Demo_quest_floor_reach)
+
+ RET
diff --git a/rng.gbasm b/rng.gbasm
index 2fe99ca..e2c30ae 100644
--- a/rng.gbasm
+++ b/rng.gbasm
@@ -66,7 +66,7 @@ RNG_Step:
LD A, E
LD $mem_rng_state_2, A
- ; XOR D
+ XOR D
POP DE
POP BC
diff --git a/utils.gbasm b/utils.gbasm
index a8696ed..fe03152 100644
--- a/utils.gbasm
+++ b/utils.gbasm
@@ -1,3 +1,5 @@
+; Baguette is tasty nomnom 🥖(๑ᵔ⤙ᵔ๑)
+
memcpy: ; src = DE, dest = HL, n = BC
.loop:
LD A, (DE)