Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thecl: better support for th185 diffs #102

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions thecl/ecsparse.y
Original file line number Diff line number Diff line change
Expand Up @@ -2132,7 +2132,7 @@ parse_rank(
const parser_state_t* state,
const char* value)
{
int rank = state->has_overdrive_difficulty ? 0xC0 : 0xF0;
int rank = get_default_none_rank(state->version);

if (check_rank_flag(state, value, '*')) {
if (strlen(value) != 1) {
Expand All @@ -2150,6 +2150,16 @@ parse_rank(
state->current_sub->name);
}
return rank;
} else if (state->has_numeric_difficulties) {
if (check_rank_flag(state, value, '0')) rank |= RANK_ID_0;
if (check_rank_flag(state, value, '1')) rank |= RANK_ID_1;
if (check_rank_flag(state, value, '2')) rank |= RANK_ID_2;
if (check_rank_flag(state, value, '3')) rank |= RANK_ID_3;
if (check_rank_flag(state, value, '4')) rank |= RANK_ID_4;
if (check_rank_flag(state, value, '5')) rank |= RANK_ID_5;
if (check_rank_flag(state, value, '6')) rank |= RANK_ID_6;
if (check_rank_flag(state, value, '7')) rank |= RANK_ID_7;
return rank;
} else {
if (check_rank_flag(state, value, 'E')) rank |= RANK_EASY;
if (check_rank_flag(state, value, 'N')) rank |= RANK_NORMAL;
Expand Down Expand Up @@ -2492,8 +2502,7 @@ expression_output(
instr_add(state->current_sub, instr_new(state, expr->id, ""));
} else if (expr->type == EXPRESSION_RANK_SWITCH) {

const int diff_amt = state->has_overdrive_difficulty ? 5 : 4;
const char* diffs[5] = {"E", "N", "H", "L", "O"};
const int diff_amt = state->has_numeric_difficulties ? 8 : (state->has_overdrive_difficulty ? 5 : 4);

int diff = 0;
int rank_none = parse_rank(state, "-");
Expand All @@ -2503,11 +2512,12 @@ expression_output(
expression_t* last_expr = NULL;
list_for_each(&expr->children, iter_expr) {
if (last_expr != NULL) {
state->instr_rank = rank_org & parse_rank(state, diffs[diff++]);
state->instr_rank = rank_org & (1 << diff);
++diff;
if (state->instr_rank != rank_none) expression_output(state, last_expr, 1);
}

if (diff > 4) {
if (diff > diff_amt) {
yyerror(state, "too many parameters for difficulty switch");
exit(2);
}
Expand All @@ -2516,13 +2526,13 @@ expression_output(
}

/* Set last expr to all remaining difficulties. */
char diff_str[5] = "";
int last_diff = 0;
while(diff < diff_amt) {
const char* next_diff = diffs[diff++];
strcat(diff_str, next_diff);
last_diff = last_diff | (1 << diff);
++diff;
}

state->instr_rank = rank_org & parse_rank(state, diff_str);
state->instr_rank = rank_org & last_diff;
if (state->instr_rank != rank_none) expression_output(state, last_expr, 1);

state->instr_rank = rank_org;
Expand Down
2 changes: 1 addition & 1 deletion thecl/ecsscan.l
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ ins_[0-9]+ {
return INTEGER;
}

![-*ENHLWXYZO4567]+ {
![-*ENHLWXYZO01234567]+ {
yylval.string = strdup(yytext + 1);
return RANK;
}
Expand Down
11 changes: 11 additions & 0 deletions thecl/thecl.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,17 @@ is_post_th13(unsigned int version) {
}
}

int32_t
get_default_none_rank(unsigned int version) {
if (!is_post_th13(version)) {
return 0xF0;
} else if (version == 185) {
return 0x00;
} else {
return 0xC0;
}
}

static void
print_usage(void)
{
Expand Down
12 changes: 11 additions & 1 deletion thecl/thecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ typedef enum {
#define RANK_EXTRA (1 << 4)
#define RANK_OVERDRIVE (1 << 5)

/* Used to describe unused ranks */
/* Used to describe unused ranks in some games and ranks in general in th185 */
#define RANK_ID_0 (1 << 0)
#define RANK_ID_1 (1 << 1)
#define RANK_ID_2 (1 << 2)
#define RANK_ID_3 (1 << 3)
#define RANK_ID_4 (1 << 4)
#define RANK_ID_5 (1 << 5)
#define RANK_ID_6 (1 << 6)
Expand Down Expand Up @@ -104,6 +108,11 @@ bool is_post_th10(
bool is_post_th13(
unsigned int version);

/* Returns the rank value for the '!-' label. */
int32_t
get_default_none_rank(
unsigned int version);

typedef struct thecl_instr_t {
thecl_instr_type type;
char* string;
Expand Down Expand Up @@ -238,6 +247,7 @@ typedef struct {
unsigned int version;
bool uses_numbered_subs;
bool has_overdrive_difficulty;
bool has_numeric_difficulties;
bool uses_stack_offsets;
bool is_timeline_sub; /* Variable for escparse.y */
list_t expressions;
Expand Down
2 changes: 1 addition & 1 deletion thecl/thecl06.c
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ th06_dump(
break;
case THECL_INSTR_RANK:
if(instr->rank == 0xFF) fprintf(out, "!*");
else if(instr->rank == 0xF0) fprintf(out, "!-");
else if(instr->rank == get_default_none_rank(ecl->version)) fprintf(out, "!-");
else {
fprintf(out, "!%s%s%s%s%s%s%s%s",
(instr->rank) & RANK_EASY ? "E" : "",
Expand Down
14 changes: 13 additions & 1 deletion thecl/thecl10.c
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,18 @@ th10_dump(
case THECL_INSTR_RANK:
if(instr->rank == 0xFF)
instr->string = strdup("!*");
else if(instr->rank == (is_post_th13(ecl->version) ? 0xC0 : 0xF0))
else if (ecl->version == 185) {
sprintf(temp, "!%s%s%s%s%s%s%s%s",
(instr->rank) & RANK_ID_0 ? "0" : "",
(instr->rank) & RANK_ID_1 ? "1" : "",
(instr->rank) & RANK_ID_2 ? "2" : "",
(instr->rank) & RANK_ID_3 ? "3" : "",
(instr->rank) & RANK_ID_4 ? "4" : "",
(instr->rank) & RANK_ID_5 ? "5" : "",
(instr->rank) & RANK_ID_6 ? "6" : "",
(instr->rank) & RANK_ID_7 ? "7" : "");
instr->string = strdup(temp);
} else if(instr->rank == get_default_none_rank(ecl->version))
instr->string = strdup("!-");
else {
if (is_post_th13(ecl->version)) {
Expand Down Expand Up @@ -1970,6 +1981,7 @@ th10_parse(
state.version = version;
state.uses_numbered_subs = false;
state.has_overdrive_difficulty = is_post_th13(version);
state.has_numeric_difficulties = version == 185;
state.uses_stack_offsets = is_post_th13(version);
list_init(&state.expressions);
list_init(&state.block_stack);
Expand Down