Skip to content

Commit b74cdd1

Browse files
committed
Add support for constants in rpg_ headers
* Adds State::kDeath * Adds pan constants so that they don't need to be duplicated in Player
1 parent 037dfe6 commit b74cdd1

File tree

6 files changed

+32
-9
lines changed

6 files changed

+32
-9
lines changed

generator/csv/constants.csv

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#Structure,name,type,value,comment
2+
State,kDeathID,int,1,The ID of the special death state
3+
SavePartyLocation,kPanXDefault,int,2304,Equal to 9 tiles in 1/16th pixels
4+
SavePartyLocation,kPanYDefault,int,1792,Equal to 7 tiles in 1/16th pixels

generator/csv/fields.csv

+4-4
Original file line numberDiff line numberDiff line change
@@ -837,10 +837,10 @@ SavePartyLocation,unboarding,f,Boolean,0x68,False,0,0,
837837
SavePartyLocation,preboard_move_speed,f,Int32,0x69,4,0,0,Move speed before the party boarded the vehicle
838838
SavePartyLocation,menu_calling,f,Boolean,0x6C,False,0,0,Flag which briefly is true if the player presses ESC. At the right place in handling each frame's activities for the player; the code checks whether this flag is set and calls the menu; however there are several conditions which would cancel this flag and instead process another higher-priority action; such as when an encounter takes place during the same frame.
839839
SavePartyLocation,pan_state,f,Enum<SavePartyLoction_PanState>,0x6f,1,0,0,0: screen is fixed; 1: screen moves with player.
840-
SavePartyLocation,pan_current_x,f,Int32,0x70,2304,0,0,Number of 1/16 pixels to the left of player
841-
SavePartyLocation,pan_current_y,f,Int32,0x71,1792,0,0,Number of 1/16 pixels above the player
842-
SavePartyLocation,pan_finish_x,f,Int32,0x72,2304,0,0,Number of 1/16 pixels to the left of player when current scroll finishes
843-
SavePartyLocation,pan_finish_y,f,Int32,0x73,1792,0,0,Number of 1/16 pixels above the player when current scroll finishes.
840+
SavePartyLocation,pan_current_x,f,Int32,0x70,kPanXDefault,0,0,Number of 1/16 pixels to the left of player
841+
SavePartyLocation,pan_current_y,f,Int32,0x71,kPanYDefault,0,0,Number of 1/16 pixels above the player
842+
SavePartyLocation,pan_finish_x,f,Int32,0x72,kPanXDefault,0,0,Number of 1/16 pixels to the left of player when current scroll finishes
843+
SavePartyLocation,pan_finish_y,f,Int32,0x73,kPanYDefault,0,0,Number of 1/16 pixels above the player when current scroll finishes.
844844
SavePartyLocation,pan_speed,f,Int32,0x79,16,0,0,speed in the scrolls of the screen - shown in sixteenth pixels.
845845
SavePartyLocation,encounter_steps,f,Int32,0x7C,0,0,0,int: sum of terrain.encounter_rate for each step
846846
SavePartyLocation,encounter_calling,f,Boolean,0x7D,False,0,0,Similar to 0x6C - is used to signal a different piece of code that an encounter is to be triggered; which may be cancelled by other conditions such as the player starting to interact with an event during the same frame.

generator/generate.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ def get_flags(filename='flags.csv'):
273273
def get_setup(filename='setup.csv'):
274274
return process_file(filename, namedtuple("Setup", "method headers"))
275275

276+
def get_constants(filename='constants.csv'):
277+
return process_file(filename, namedtuple("Constant", "name type value comment"))
278+
276279
def get_headers():
277280
header_map = dict()
278281

@@ -379,14 +382,15 @@ def main(argv):
379382
if not os.path.exists(dest_dir):
380383
os.mkdir(dest_dir)
381384

382-
global structs, sfields, enums, flags, setup, headers
385+
global structs, sfields, enums, flags, setup, constants, headers
383386
global chunk_tmpl, lcf_struct_tmpl, rpg_header_tmpl, rpg_source_tmpl, flags_tmpl, enums_tmpl
384387

385388
structs = get_structs()
386389
sfields = get_fields()
387390
enums = get_enums()
388391
flags = get_flags()
389392
setup = get_setup()
393+
constants = get_constants()
390394
headers = get_headers()
391395

392396
# Setup Jinja
@@ -407,6 +411,7 @@ def main(argv):
407411
flags=flags,
408412
enums=enums,
409413
setup=setup,
414+
constants=constants,
410415
headers=headers
411416
)
412417

generator/templates/rpg_header.tmpl

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ namespace RPG {
2525
{%- if struct_name == "Map" %}
2626
std::string lmu_header;
2727
{%- endif %}
28+
{%- if struct_name in constants %}
29+
{%- for name, type, value, comment in constants[struct_name] %}
30+
// {{ comment }}
31+
static constexpr {{ type }} {{ name }} = {{ value }};
32+
{%- endfor %}
33+
{% endif %}
2834
{%- if struct_name in enums %}
2935
{%- for name, enum in enums[struct_name].items() %}
3036
{%- if name == "Code" %}

src/generated/rpg_savepartylocation.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
namespace RPG {
2424
class SavePartyLocation : public SaveMapEventBase {
2525
public:
26+
// Equal to 9 tiles in 1/16th pixels
27+
static constexpr int kPanXDefault = 2304;
28+
// Equal to 7 tiles in 1/16th pixels
29+
static constexpr int kPanYDefault = 1792;
30+
2631
enum VehicleType {
2732
VehicleType_none = 0,
2833
VehicleType_skiff = 1,
@@ -51,10 +56,10 @@ namespace RPG {
5156
int32_t preboard_move_speed = 4;
5257
bool menu_calling = false;
5358
int32_t pan_state = 1;
54-
int32_t pan_current_x = 2304;
55-
int32_t pan_current_y = 1792;
56-
int32_t pan_finish_x = 2304;
57-
int32_t pan_finish_y = 1792;
59+
int32_t pan_current_x = kPanXDefault;
60+
int32_t pan_current_y = kPanYDefault;
61+
int32_t pan_finish_x = kPanXDefault;
62+
int32_t pan_finish_y = kPanYDefault;
5863
int32_t pan_speed = 16;
5964
int32_t encounter_steps = 0;
6065
bool encounter_calling = false;

src/generated/rpg_state.h

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
namespace RPG {
2424
class State {
2525
public:
26+
// The ID of the special death state
27+
static constexpr int kDeathID = 1;
28+
2629
enum Persistence {
2730
Persistence_ends = 0,
2831
Persistence_persists = 1

0 commit comments

Comments
 (0)