Skip to content

Commit cabfaa3

Browse files
committed
Add the retail Magic window and spell bar
1 parent e97697a commit cabfaa3

48 files changed

Lines changed: 1657 additions & 52 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎roadmap.md‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,18 @@ single-item swaps, partial Gold merges, hover information, and condition
6666
markers use the ordinary shared rules. Its fourth retail save container is
6767
decoded into a separate fixed owner and its required definitions stay in the
6868
active resource request.
69-
The shared Status/Magic window now has its first complete tab. `S` and the HUD
70-
button open the live Status page on the left, where the authored frame is
71-
combined with the saved identity, current pools, table-backed base values,
72-
valid equipment bonuses, affinities, and elemental marker. A small game-side
73-
profile owns those derived values, while the panel and its layout stay in
74-
`ui/`. Status coexists with right-side Inventory, replaces Special Item on the
75-
left, and uses the same camera and input offset. The shared owner has an
76-
explicit Magic tab ready for the spell-page slice instead of treating these as
77-
two unrelated windows.
69+
The shared Status/Magic window now has both retail tabs. `S` and the HUD button
70+
open Status with the saved identity, current pools, table-backed base values,
71+
valid equipment bonuses, affinities, and elemental marker. `M` or the top tab
72+
opens Magic's four six-spell pages, including availability states, saved
73+
levels and experience, table-backed MP/effect values, help text, arrows, and
74+
the authored large icons. Learned spells drag into eight persistent save-owned
75+
slots, while the small gameplay bar keeps retail's dynamic position beside
76+
left and right panels. Every gameplay load starts on normal attack as retail
77+
does. UI state only emits actions; persistent spell ownership remains in
78+
`game/`, table scanning in `data/`, and samples 57/58 reach TAL through a small
79+
general world event queue. Both tabs coexist with right-side Inventory,
80+
replace Special Item on the left, and share the same camera and input offset.
7881

7982
Selecting a retail save now
8083
streams and verifies its `ShadowFlare0005` envelope without allocating a
@@ -87,8 +90,8 @@ values now reach the interpreter before its first periodic pass, so one-time
8790
handoffs such as Ostare's starter items stay complete. Mine count, walk/run
8891
pace, scenario, and authored entry reach the world owner as well. The three
8992
Remote Town saves also pass the complete asset-and-owner restore path. The
90-
remaining save work belongs to the systems which are not in the small runtime
91-
yet: magic, companions, warehouse pages, automatic-item pages, and writing saves.
93+
remaining save work belongs to systems which are not in the small runtime yet:
94+
companions, warehouse pages, automatic-item pages, and writing saves.
9295
A slice is only done after the C99/TWL/TAL tests, a release build, a practical
9396
check when visible behavior changed, and a fresh measured budget when assets
9497
changed.

‎shadowflare/CMakeLists.txt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ add_library(
3939
assets/ground_item_requests.c
4040
assets/inventory_item_assets.c
4141
assets/gameplay_assets.c
42+
assets/gameplay_sound_assets.c
4243
assets/load_game_assets.c
4344
assets/menu_assets.c
4445
assets/player_assets.c
@@ -73,6 +74,7 @@ add_library(
7374
data/save_player.c
7475
data/save_player_items.c
7576
data/scs.c
77+
data/spell_parameters.c
7678
data/table.c
7779
data/voc.c
7880
game/character_create.c
@@ -86,6 +88,7 @@ add_library(
8688
game/load_game.c
8789
game/movement.c
8890
game/player.c
91+
game/player_magic.c
8992
game/player_elements.c
9093
game/player_item.c
9194
game/player_loadout.c
@@ -94,11 +97,13 @@ add_library(
9497
game/route.c
9598
game/route_tables.c
9699
game/scenario_actor.c
100+
game/sound_event.c
97101
game/special_items.c
98102
game/title.c
99103
game/world.c
100104
game/world_conversation.c
101105
game/world_inventory.c
106+
game/world_magic.c
102107
game/world_save.c
103108
game/world_script.c
104109
interpreter/scenario_actor_script.c
@@ -128,6 +133,9 @@ add_library(
128133
ui/gameplay_hud_input.c
129134
ui/gameplay_inventory.c
130135
ui/gameplay_inventory_input.c
136+
ui/gameplay_magic_input.c
137+
ui/gameplay_magic_layout.c
138+
ui/gameplay_magic.c
131139
ui/gameplay_panels_input.c
132140
ui/gameplay_item_information.c
133141
ui/gameplay_item_icon.c

‎shadowflare/README.md‎

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,28 @@ left and right panels can remain open together; opening only one shifts the
121121
live world and its input anchor to the exposed half of the screen. Items move
122122
directly between either owner without a second transfer path, and the fourth
123123
retail save container restores exact Special Item cells on load.
124-
`S` and the authored STATUS button open the first tab of the shared
124+
`S` and the authored STATUS button open the Status tab of the shared
125125
Status/Magic window. The live Status page uses retail pattern 5 for its frame
126126
and labels, then overlays the character identity, current pools, base and
127127
equipment-adjusted physical and magical values, eight elemental affinities,
128128
and the saved elemental marker. Its game-side profile ignores broken gear and
129129
suppressed off-hand items; the UI only formats and draws the result. Status can
130130
remain open beside Inventory, replaces Special Item on the left, shifts the
131131
world and input by the same integer offset, and is closed together with other
132-
open panels by Escape. The shared panel owner already has a separate Magic tab
133-
state so that the next slice can add Magic without creating another window.
132+
open panels by Escape.
133+
134+
`M` and the authored top tab open the other half of that same owner. Magic uses
135+
retail pattern 6, four six-spell pages, authored icon wells, saved availability,
136+
level and experience arrays, and streamed Tables 16, 17, 27, and 600 through
137+
621. Learned icons can be dragged into eight saved slots and moved without
138+
duplicates. The always-visible bar above the HUD uses its original compact and
139+
selected icons, expands around the selected spell, and follows the retail
140+
full/left/right-panel positions. Clicking its final icon selects normal attack;
141+
every new or loaded gameplay entry starts there. UI code owns the page, hit
142+
rectangles, tooltip, and held icon, while `game/player_magic.c` owns spell data
143+
and applies the emitted selection or assignment. Samples 57 and 58 use a small
144+
general world-event queue and dedicated gameplay-interface assets before TAL
145+
plays them at the runtime edge.
134146

135147
Choosing a retail save now restores more than its load-screen summary. The
136148
`ShadowFlare0005` envelope is decoded and checksummed as a stream, so even a
@@ -228,8 +240,8 @@ it is invalid.
228240

229241
## Current screen budgets
230242

231-
The complete title currently uses 1,452,293 bytes of the 7 MiB main arena,
232-
leaving 5,887,739 bytes free. Its screen-scoped artwork accounts for 1,101,182
243+
The complete title currently uses 1,454,573 bytes of the 7 MiB main arena,
244+
leaving 5,885,459 bytes free. Its screen-scoped artwork accounts for 1,101,182
233245
bytes. The rest includes TWL/TAL state, game and screen metadata, persistent
234246
8-bit menu music and effects, and one reusable 60,000-byte decode buffer. The
235247
video pool contains only the 614,400-byte RGB555 framebuffer, leaving 3,579,904
@@ -242,22 +254,22 @@ nonblank case, all ten smoke streams together decode at most 57,864 bytes into
242254
the same reusable buffer during one rendered frame.
243255

244256
Character creation releases all title-only artwork before loading its own
245-
assets. It uses 765,216 bytes of the main arena, leaving 6,574,816 bytes free;
257+
assets. It uses 767,496 bytes of the main arena, leaving 6,572,536 bytes free;
246258
414,105 bytes of that total are character-screen artwork and font data. Shared
247259
NJP parts are decoded only once even when several patterns reference them, and
248260
a static character screen is not filled again until a visible state changes.
249261

250-
The load-game screen uses 725,432 bytes of the main arena, leaving 6,614,600
262+
The load-game screen uses 727,712 bytes of the main arena, leaving 6,612,320
251263
bytes free. Its screen-scoped artwork, font, and selected save preview account
252264
for 374,321 bytes. Save headers stay in a fixed six-entry catalog, while only
253265
the selected 391x114 thumbnail occupies memory. Changing selection decodes the
254266
new preview into the same 89,148-byte RGB555 buffer; idle frames perform no
255267
file access and do not refill the framebuffer.
256268

257-
The complete Remote Town gameplay screen uses 5,199,068 bytes of the main
258-
arena, leaving 2,140,964 bytes free. Its screen-owned scenario, script, map,
269+
The complete Remote Town gameplay screen uses 5,423,692 bytes of the main
270+
arena, leaving 1,916,340 bytes free. Its screen-owned scenario, script, map,
259271
player, PEOPLE, ground-item, inventory-panel, equipment, and UI data and
260-
artwork account for 4,847,957
272+
artwork account for 5,070,301
261273
bytes. GND rendering data is decoded directly from its compressed three-plane
262274
stream into two bytes
263275
per tile, so the 300x300 town grid occupies 180,000 bytes instead of retaining
@@ -346,7 +358,7 @@ grid placement, single-item swaps, invalid-placement rollback, and partial
346358
Gold merges all stay in `game/inventory.c`.
347359

348360
The inventory and character panels follow the same lifetime. `Status.njp` is
349-
streamed twice to retain only 33 required patterns, without constructing
361+
streamed to retain only 37 required patterns, without constructing
350362
metadata for its other 115 patterns. Item definitions provide the inventory
351363
group, pattern, and optional palette directly; only groups and cells referenced
352364
by the active map's retained definitions are decoded.
@@ -364,6 +376,15 @@ fixed 9x10 owner but shares this pointer transfer and item presentation path.
364376
Both panels can be open at once; their opposing integer camera offsets cancel,
365377
while either panel alone leaves the other half as the live world.
366378

379+
Magic follows the same prepared-resource rule. Only the 23 required
380+
`MagicIcon.njp` patterns and 24 required `MagicBarIcon.njp` patterns are
381+
decoded when gameplay loads. The table scanner copies the 22 fixed MP/effect
382+
rows, experience thresholds, and bounded help lines into gameplay-owned
383+
storage, then discards the table stream. Panel rendering performs no file
384+
access, allocation, decompression, or format conversion. Its only normal-frame
385+
cost is composing the nine small gameplay-bar entries when that region is
386+
redrawn; the four-page panel is drawn only while open or visibly changing.
387+
367388
The same held-item path now owns all nine visible equipment regions. Their
368389
retail rectangles live in one small UI layout file, while category, subtype,
369390
level requirement, swapping, equipped weight, and off-hand suppression remain

‎shadowflare/assets/gameplay_assets.c‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,19 @@ bool sf_gameplay_assets_load(
226226
0u, 3u, 7u, 8u, 10u, 11u, 14u, 15u,
227227
19u, 20u, 21u, 22u, 23u, 24u, 25u, 26u, 27u, 28u
228228
};
229-
static const uint8_t inventory_patterns[33] = {
230-
0u, 1u, 2u, 3u, 5u, 14u, 15u, 16u,
229+
static const uint8_t inventory_patterns[37] = {
230+
0u, 1u, 2u, 3u, 5u, 6u, 14u, 15u, 16u, 32u,
231231
36u, 37u, 38u, 39u, 40u, 41u, 42u, 43u, 44u, 45u, 46u,
232232
47u, 48u, 49u, 50u, 51u, 52u, 53u, 54u, 55u, 56u, 57u,
233-
67u, 116u, 117u
233+
67u, 69u, 70u, 116u, 117u
234+
};
235+
static const uint8_t magic_icon_patterns[23] = {
236+
0u, 2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u, 11u, 12u,
237+
13u, 14u, 15u, 16u, 17u, 18u, 19u, 20u, 21u, 22u, 23u
238+
};
239+
static const uint8_t magic_bar_patterns[24] = {
240+
2u, 3u, 4u, 5u, 6u, 7u, 8u, 9u, 10u, 11u, 12u, 13u,
241+
14u, 15u, 16u, 17u, 18u, 19u, 20u, 21u, 22u, 23u, 24u, 25u
234242
};
235243
size_t mark;
236244
bool success = false;
@@ -240,7 +248,9 @@ bool sf_gameplay_assets_load(
240248
memset(&selection, 0, sizeof(selection));
241249
assets->script = (SfScsScript *) sf_arena_push_zero(
242250
arena, sizeof(*assets->script), sizeof(int32_t));
243-
if (!assets->script) goto done;
251+
assets->spell_parameters = (SfSpellParameters *) sf_arena_push_zero(
252+
arena, sizeof(*assets->spell_parameters), sizeof(int32_t));
253+
if (!assets->script || !assets->spell_parameters) goto done;
244254
if (!sf_gameplay_path(
245255
path, sizeof(path), data_root,
246256
sf_retail_world_paths.scenario_format, NULL, scenario_id) ||
@@ -286,12 +296,24 @@ bool sf_gameplay_assets_load(
286296
!sf_retail_path_join(
287297
path, sizeof(path), data_root, sf_retail_game_paths.status) ||
288298
!sf_njp_stream_decoded_patterns(
289-
path, inventory_patterns, 33u, arena, &assets->inventory_panel) ||
299+
path, inventory_patterns, 37u, arena, &assets->inventory_panel) ||
300+
!sf_retail_path_join(
301+
path, sizeof(path), data_root, sf_retail_game_paths.magic_icons) ||
302+
!sf_njp_stream_decoded_patterns(
303+
path, magic_icon_patterns, 23u, arena, &assets->magic_icons) ||
304+
!sf_retail_path_join(
305+
path, sizeof(path), data_root,
306+
sf_retail_game_paths.magic_bar_icons) ||
307+
!sf_njp_stream_decoded_patterns(
308+
path, magic_bar_patterns, 24u, arena, &assets->magic_bar_icons) ||
290309
!sf_retail_path_join(
291310
path, sizeof(path), data_root,
292311
sf_retail_game_paths.parameter_tables) ||
293312
!sf_player_initial_parameters_load(
294313
path, player_gender, player_level, &assets->player_parameters) ||
314+
!sf_spell_parameters_load(path, assets->spell_parameters) ||
315+
!sf_gameplay_sound_assets_load(
316+
&assets->sounds, data_root, arena) ||
295317
!sf_ground_item_assets_load(
296318
&assets->ground_items, data_root, assets->script,
297319
retained_items, retained_item_count, arena) ||

‎shadowflare/assets/gameplay_assets.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "assets/player_assets.h"
2424
#include "assets/ground_item_assets.h"
25+
#include "assets/gameplay_sound_assets.h"
2526
#include "assets/inventory_item_assets.h"
2627
#include "assets/scenario_actor_assets.h"
2728
#include "core/arena.h"
@@ -31,6 +32,7 @@
3132
#include "data/obl.h"
3233
#include "data/player_parameters.h"
3334
#include "data/scs.h"
35+
#include "data/spell_parameters.h"
3436

3537
#include <stdbool.h>
3638
#include <stddef.h>
@@ -53,10 +55,14 @@ typedef struct SfGameplayAssets {
5355
SfNjpSelected speech_frame;
5456
SfNjpDecodedResource hud;
5557
SfNjpDecodedResource inventory_panel;
58+
SfNjpDecodedResource magic_icons;
59+
SfNjpDecodedResource magic_bar_icons;
5660
SfPlayerInitialParameters player_parameters;
61+
SfSpellParameters *spell_parameters;
5762
SfPlayerAssets player;
5863
SfScenarioActorAssets actors;
5964
SfGroundItemAssets ground_items;
65+
SfGameplaySoundAssets sounds;
6066
SfInventoryItemAssets inventory_items;
6167
SfGameplayPatternSet *pattern_sets;
6268
size_t memory_bytes;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (C) 2026 Michael Binder and contributors
3+
*
4+
* This file is part of OpenShadowFlare.
5+
*
6+
* OpenShadowFlare is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License as published by the Free
8+
* Software Foundation, either version 3 of the License, or (at your option)
9+
* any later version.
10+
*
11+
* OpenShadowFlare is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14+
* details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with OpenShadowFlare. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include "assets/gameplay_sound_assets.h"
21+
22+
#include "assets/retail_paths.h"
23+
24+
#include <string.h>
25+
26+
static const uint16_t sf_gameplay_interface_samples[
27+
SF_GAMEPLAY_INTERFACE_SOUND_COUNT] = {57u, 58u};
28+
29+
bool sf_gameplay_sound_assets_load(
30+
SfGameplaySoundAssets *assets, const char *data_root, SfArena *arena) {
31+
char path[SF_RETAIL_PATH_CAPACITY];
32+
if (!assets || !data_root || !arena) return false;
33+
memset(assets, 0, sizeof(*assets));
34+
return sf_retail_path_join(
35+
path, sizeof(path), data_root, sf_retail_game_paths.common_sounds) &&
36+
sf_voc_load_u8_mono_samples(
37+
path, sf_gameplay_interface_samples,
38+
SF_GAMEPLAY_INTERFACE_SOUND_COUNT, arena, assets->interface_sounds);
39+
}
40+
41+
const SfPcmU8 *sf_gameplay_interface_sound(
42+
const SfGameplaySoundAssets *assets, uint16_t sample) {
43+
uint8_t index;
44+
if (!assets) return NULL;
45+
for (index = 0u; index < SF_GAMEPLAY_INTERFACE_SOUND_COUNT; ++index)
46+
if (sf_gameplay_interface_samples[index] == sample)
47+
return &assets->interface_sounds[index];
48+
return NULL;
49+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (C) 2026 Michael Binder and contributors
3+
*
4+
* This file is part of OpenShadowFlare.
5+
*
6+
* OpenShadowFlare is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License as published by the Free
8+
* Software Foundation, either version 3 of the License, or (at your option)
9+
* any later version.
10+
*
11+
* OpenShadowFlare is distributed in the hope that it will be useful, but
12+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14+
* details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with OpenShadowFlare. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef SHADOWFLARE_ASSETS_GAMEPLAY_SOUND_ASSETS_H
21+
#define SHADOWFLARE_ASSETS_GAMEPLAY_SOUND_ASSETS_H
22+
23+
#include "core/arena.h"
24+
#include "data/voc.h"
25+
26+
#include <stdbool.h>
27+
#include <stdint.h>
28+
29+
#define SF_GAMEPLAY_INTERFACE_SOUND_COUNT 2u
30+
31+
typedef struct SfGameplaySoundAssets {
32+
SfPcmU8 interface_sounds[SF_GAMEPLAY_INTERFACE_SOUND_COUNT];
33+
} SfGameplaySoundAssets;
34+
35+
bool sf_gameplay_sound_assets_load(
36+
SfGameplaySoundAssets *assets, const char *data_root, SfArena *arena);
37+
const SfPcmU8 *sf_gameplay_interface_sound(
38+
const SfGameplaySoundAssets *assets, uint16_t sample);
39+
40+
#endif

‎shadowflare/assets/retail_paths.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ const SfRetailGamePaths sf_retail_game_paths = {
7878
"System/Game/Pattern/Hukidasi.njp",
7979
"System/Game/Pattern/Bar.njp",
8080
"System/Game/Pattern/Status.njp",
81+
"System/Game/Pattern/MagicIcon.njp",
82+
"System/Game/Pattern/MagicBarIcon.njp",
8183
"System/Game/Pattern/Item%04u.njp"
8284
};
8385

‎shadowflare/assets/retail_paths.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ typedef struct SfRetailGamePaths {
8181
const char *speech_frame;
8282
const char *hud;
8383
const char *status;
84+
const char *magic_icons;
85+
const char *magic_bar_icons;
8486
const char *inventory_item_format;
8587
} SfRetailGamePaths;
8688

‎shadowflare/data/njp_stream.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <stdio.h>
2727
#include <string.h>
2828

29-
#define SF_NJP_STREAM_PALETTE_LIMIT 16u
29+
#define SF_NJP_STREAM_PALETTE_LIMIT 32u
3030

3131
static int sf_stream_request(
3232
const uint8_t *requests, uint8_t request_count, int32_t source) {

0 commit comments

Comments
 (0)