Skip to content

Commit 2909e8f

Browse files
committed
address feedback
1 parent a47658b commit 2909e8f

File tree

8 files changed

+32
-11
lines changed

8 files changed

+32
-11
lines changed

code/parse/sexp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3951,7 +3951,7 @@ int check_sexp_syntax(int node, int return_type, int recursive, int *bad_node, i
39513951

39523952
default:
39533953
if (Dynamic_enums.size() > 0) {
3954-
if ((type - First_available_list_id) < (int)Dynamic_enums.size()) {
3954+
if ((type - First_available_opf_id) < (int)Dynamic_enums.size()) {
39553955
if (type2 != SEXP_ATOM_STRING)
39563956
return SEXP_CHECK_TYPE_MISMATCH;
39573957
} else {

code/parse/sexp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct ship_obj;
2828

2929
// Operator argument formats (data types of an argument)
3030
enum : int {
31+
UNUSED, // argument types need to start at 1 instead of 0
3132
OPF_NONE, // argument cannot exist at this position if it's this
3233
OPF_NULL, // no value. Can still be used for type matching, however
3334
OPF_BOOL,
@@ -133,7 +134,7 @@ enum : int {
133134
OPF_WING_FORMATION, // Goober5000 - as defined in ships.tbl
134135

135136
//Must always be at the end of the list
136-
First_available_list_id
137+
First_available_opf_id
137138
};
138139

139140
struct dynamic_sexp_enum_list {

code/parse/sexp/LuaSEXP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static SCP_unordered_map<SCP_string, int> parameter_type_mapping{{ "boolean",
4646
{ "ship+wing+ship_on_team+waypoint", OPF_SHIP_WING_SHIPONTEAM_POINT },
4747
{ "ship+wing+waypoint", OPF_SHIP_WING_POINT },
4848
{ "ship+wing+waypoint+none", OPF_SHIP_WING_POINT_OR_NONE },
49-
{ "enum", First_available_list_id } };
49+
{ "enum", First_available_opf_id } };
5050

5151
std::pair<SCP_string, int> LuaSEXP::get_parameter_type(const SCP_string& name)
5252
{
@@ -526,7 +526,7 @@ void LuaSEXP::parseTable() {
526526
}
527527

528528
if ((strcmp(type.first.c_str(), "enum")) == 0) {
529-
type.second = increment_list_id();
529+
type.second = increment_enum_list_id();
530530
required_string("+Enum Name:");
531531

532532
SCP_string enum_name;

code/parse/sexp/sexp_lookup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct global_state {
2828
int next_free_operator_id = First_available_operator_id;
2929
int next_free_category_id = First_available_category_id;
3030
int next_free_subcategory_id = First_available_subcategory_id;
31-
int next_free_enum_list_id = First_available_list_id;
31+
int next_free_enum_list_id = First_available_opf_id;
3232
};
3333

3434
// Static initialization to avoid initialization order issues
@@ -199,7 +199,7 @@ DynamicSEXP* get_dynamic_sexp(int operator_const)
199199

200200
return iter->second.get();
201201
}
202-
int increment_list_id()
202+
int increment_enum_list_id()
203203
{
204204
auto& global = globals();
205205
return global.next_free_enum_list_id++;

code/parse/sexp/sexp_lookup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int get_category_of_subcategory(int subcategory_id);
4444
*/
4545
int add_category(const SCP_string& name);
4646

47-
int increment_list_id();
47+
int increment_enum_list_id();
4848

4949
/**
5050
* @brief Dynamically add a new subcategory to the SEXP system

fred2/sexp_tree.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3500,7 +3500,7 @@ int sexp_tree::query_default_argument_available(int op, int i)
35003500

35013501
default:
35023502
if (!Dynamic_enums.empty()) {
3503-
if ((type - First_available_list_id) < (int)Dynamic_enums.size()) {
3503+
if ((type - First_available_opf_id) < (int)Dynamic_enums.size()) {
35043504
return 1;
35053505
} else {
35063506
UNREACHABLE("Unhandled SEXP argument type!");
@@ -7360,7 +7360,7 @@ sexp_list_item* sexp_tree::check_for_dynamic_sexp_enum(int opf)
73607360
{
73617361
sexp_list_item head;
73627362

7363-
int item = opf - First_available_list_id;
7363+
int item = opf - First_available_opf_id;
73647364

73657365
if (item < (int)Dynamic_enums.size()) {
73667366

qtfred/src/ui/widgets/sexp_tree.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3321,8 +3321,8 @@ sexp_list_item* sexp_tree::get_listing_opf(int opf, int parent_node, int arg_ind
33213321
break;
33223322

33233323
default:
3324-
Int3(); // unknown OPF code
3325-
list = NULL;
3324+
// We're at the end of the list so check for any dynamic enums
3325+
list = check_for_dynamic_sexp_enum(opf);
33263326
break;
33273327
}
33283328

@@ -5128,6 +5128,25 @@ sexp_list_item *sexp_tree::get_container_multidim_modifiers(int con_data_node) c
51285128
return head.next;
51295129
}
51305130

5131+
sexp_list_item* sexp_tree::check_for_dynamic_sexp_enum(int opf)
5132+
{
5133+
sexp_list_item head;
5134+
5135+
int item = opf - First_available_list_id;
5136+
5137+
if (item < (int)Dynamic_enums.size()) {
5138+
5139+
for (const SCP_string& enum_item : Dynamic_enums[item].list) {
5140+
head.add_data(enum_item.c_str());
5141+
}
5142+
return head.next;
5143+
} else {
5144+
// else if opf is invalid do this
5145+
UNREACHABLE("Unhandled SEXP argument type!"); // unknown OPF code
5146+
return nullptr;
5147+
}
5148+
}
5149+
51315150
// given a node's parent, check if node is eligible for being used with the special argument
51325151
bool sexp_tree::is_node_eligible_for_special_argument(int parent_node) const
51335152
{

qtfred/src/ui/widgets/sexp_tree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ class sexp_tree: public QTreeWidget {
350350
sexp_list_item *get_listing_opf_animation_name(int parent_node);
351351
static sexp_list_item *get_listing_opf_sexp_containers(ContainerType con_type);
352352
sexp_list_item *get_listing_opf_wing_formation();
353+
sexp_list_item* check_for_dynamic_sexp_enum(int opf);
353354

354355
// container modifier options for container data nodes
355356
sexp_list_item *get_container_modifiers(int con_data_node) const;

0 commit comments

Comments
 (0)