Skip to content

Commit

Permalink
Add support for constants in rpg_ headers
Browse files Browse the repository at this point in the history
* Adds State::kDeath
* Adds pan constants so that they don't need to be duplicated in Player
  • Loading branch information
mateofio committed Dec 6, 2018
1 parent 037dfe6 commit bbde6be
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
4 changes: 4 additions & 0 deletions generator/csv/constants.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Structure,name,type,value,comment
State,kDeathID,int,1,The ID of the special death state
SavePartyLocation,kPanXDefault,int,9 * 256,Equal to 9 tiles in 1/16th pixels
SavePartyLocation,kPanYDefault,int,7 * 256,Equal to 7 tiles in 1/16th pixels
8 changes: 4 additions & 4 deletions generator/csv/fields.csv
Original file line number Diff line number Diff line change
Expand Up @@ -837,10 +837,10 @@ SavePartyLocation,unboarding,f,Boolean,0x68,False,0,0,
SavePartyLocation,preboard_move_speed,f,Int32,0x69,4,0,0,Move speed before the party boarded the vehicle
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.
SavePartyLocation,pan_state,f,Enum<SavePartyLoction_PanState>,0x6f,1,0,0,0: screen is fixed; 1: screen moves with player.
SavePartyLocation,pan_current_x,f,Int32,0x70,2304,0,0,Number of 1/16 pixels to the left of player
SavePartyLocation,pan_current_y,f,Int32,0x71,1792,0,0,Number of 1/16 pixels above the player
SavePartyLocation,pan_finish_x,f,Int32,0x72,2304,0,0,Number of 1/16 pixels to the left of player when current scroll finishes
SavePartyLocation,pan_finish_y,f,Int32,0x73,1792,0,0,Number of 1/16 pixels above the player when current scroll finishes.
SavePartyLocation,pan_current_x,f,Int32,0x70,kPanXDefault,0,0,Number of 1/16 pixels to the left of player
SavePartyLocation,pan_current_y,f,Int32,0x71,kPanYDefault,0,0,Number of 1/16 pixels above the player
SavePartyLocation,pan_finish_x,f,Int32,0x72,kPanXDefault,0,0,Number of 1/16 pixels to the left of player when current scroll finishes
SavePartyLocation,pan_finish_y,f,Int32,0x73,kPanYDefault,0,0,Number of 1/16 pixels above the player when current scroll finishes.
SavePartyLocation,pan_speed,f,Int32,0x79,16,0,0,speed in the scrolls of the screen - shown in sixteenth pixels.
SavePartyLocation,encounter_steps,f,Int32,0x7C,0,0,0,int: sum of terrain.encounter_rate for each step
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.
Expand Down
7 changes: 6 additions & 1 deletion generator/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ def get_flags(filename='flags.csv'):
def get_setup(filename='setup.csv'):
return process_file(filename, namedtuple("Setup", "method headers"))

def get_constants(filename='constants.csv'):
return process_file(filename, namedtuple("Constant", "name type value comment"))

def get_headers():
header_map = dict()

Expand Down Expand Up @@ -379,14 +382,15 @@ def main(argv):
if not os.path.exists(dest_dir):
os.mkdir(dest_dir)

global structs, sfields, enums, flags, setup, headers
global structs, sfields, enums, flags, setup, constants, headers
global chunk_tmpl, lcf_struct_tmpl, rpg_header_tmpl, rpg_source_tmpl, flags_tmpl, enums_tmpl

structs = get_structs()
sfields = get_fields()
enums = get_enums()
flags = get_flags()
setup = get_setup()
constants = get_constants()
headers = get_headers()

# Setup Jinja
Expand All @@ -407,6 +411,7 @@ def main(argv):
flags=flags,
enums=enums,
setup=setup,
constants=constants,
headers=headers
)

Expand Down
6 changes: 6 additions & 0 deletions generator/templates/rpg_header.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ namespace RPG {
{%- if struct_name == "Map" %}
std::string lmu_header;
{%- endif %}
{%- if struct_name in constants %}
{%- for name, type, value, comment in constants[struct_name] %}
// {{ comment }}
static constexpr {{ type }} {{ name }} = {{ value }};
{%- endfor %}
{% endif %}
{%- if struct_name in enums %}
{%- for name, enum in enums[struct_name].items() %}
{%- if name == "Code" %}
Expand Down
13 changes: 9 additions & 4 deletions src/generated/rpg_savepartylocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
namespace RPG {
class SavePartyLocation : public SaveMapEventBase {
public:
// Equal to 9 tiles in 1/16th pixels
static constexpr int kPanXDefault = 9 * 256;
// Equal to 7 tiles in 1/16th pixels
static constexpr int kPanYDefault = 7 * 256;

enum VehicleType {
VehicleType_none = 0,
VehicleType_skiff = 1,
Expand Down Expand Up @@ -51,10 +56,10 @@ namespace RPG {
int32_t preboard_move_speed = 4;
bool menu_calling = false;
int32_t pan_state = 1;
int32_t pan_current_x = 2304;
int32_t pan_current_y = 1792;
int32_t pan_finish_x = 2304;
int32_t pan_finish_y = 1792;
int32_t pan_current_x = kPanXDefault;
int32_t pan_current_y = kPanYDefault;
int32_t pan_finish_x = kPanXDefault;
int32_t pan_finish_y = kPanYDefault;
int32_t pan_speed = 16;
int32_t encounter_steps = 0;
bool encounter_calling = false;
Expand Down
3 changes: 3 additions & 0 deletions src/generated/rpg_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
namespace RPG {
class State {
public:
// The ID of the special death state
static constexpr int kDeathID = 1;

enum Persistence {
Persistence_ends = 0,
Persistence_persists = 1
Expand Down

0 comments on commit bbde6be

Please sign in to comment.