Vectorize MsgItems (#7687)

Convert MsgItems from an array to a vector, and remove the associated limit value and counter.

* vectorize msgitems

* appeasement

* leave me alone clang

* remove optional

* cleanup

* changes requested

* clang

* clang what is WRONG with you

* feedback

* remove flag in .h
This commit is contained in:
Kestrellius authored and GitHub committed 2026-08-16 02:04:50 +00:00
1 parent a4e33109a0
commit 1967daffd3
6 files changed
+98 -164

No files matched your search

+84 -143
View File
@@ -104,8 +104,8 @@ int Menu_pgdn_coords[GR_NUM_RESOLUTIONS][2] = {
// following defines/vars are used to build menus that are used in messaging mode
char Squad_msg_title[256] = "";
mmode_item MsgItems[MAX_MENU_ITEMS];
int Num_menu_items = -1; // number of items for a message menu
SCP_vector<mmode_item> MsgItems;
static bool Rebuild_MsgItems = true;
static int First_menu_item = -1; // index of first item in the menu. This tracks what element of comms options collection is displayed as first option, and displays the next 9 options. Changes only by +/- MAX_MENU_ITEMS (10)
static int Selected_menu_item = First_menu_item; //!< index of selected item in the menu. Possible index range: 0 - 9, assuming MAX_MENU_ITEMS == 10, and First_menu_item gets initialized
@@ -218,7 +218,8 @@ void hud_squadmsg_start()
Msg_key = -1;
Msg_key_set_from_scripting = false;
Num_menu_items = -1; // reset the menu items
Rebuild_MsgItems = true; // reset the menu items
MsgItems.clear();
First_menu_item = 0;
Selected_menu_item = First_menu_item; // make first menu item a selected object
Display_selector = false;
@@ -376,11 +377,7 @@ int hud_squadmsg_count_ships(int add_to_menu)
count++;
if (add_to_menu)
{
Assert ( Num_menu_items < MAX_MENU_ITEMS );
MsgItems[Num_menu_items].text = shipp->get_display_name();
MsgItems[Num_menu_items].instance = SHIP_INDEX(shipp);
MsgItems[Num_menu_items].active = 1;
Num_menu_items++;
MsgItems.push_back({SHIP_INDEX(shipp), 1, shipp->get_display_name()});
}
}
@@ -431,11 +428,7 @@ int hud_squadmsg_count_wings( int add_to_menu )
if ( hud_squadmsg_wing_valid(&Wings[wingnum]) ) {
count++;
if ( add_to_menu ) {
Assert ( Num_menu_items < MAX_MENU_ITEMS );
MsgItems[Num_menu_items].text = Wings[wingnum].get_display_name();
MsgItems[Num_menu_items].instance = wingnum;
MsgItems[Num_menu_items].active = 1;
Num_menu_items++;
MsgItems.push_back({wingnum, 1, Wings[wingnum].get_display_name()});
}
}
}
@@ -452,11 +445,7 @@ int hud_squadmsg_count_wings( int add_to_menu )
if ( hud_squadmsg_wing_valid(&Wings[i]) ) {
count++;
if ( add_to_menu ) {
Assert ( Num_menu_items < MAX_MENU_ITEMS );
MsgItems[Num_menu_items].text = Wings[i].get_display_name();
MsgItems[Num_menu_items].instance = i;
MsgItems[Num_menu_items].active = 1;
Num_menu_items++;
MsgItems.push_back({i, 1, Wings[i].get_display_name()});
}
}
}
@@ -469,15 +458,16 @@ int hud_squadmsg_count_wings( int add_to_menu )
void hud_squadmsg_do_mode( int mode )
{
Squad_msg_mode = mode;
Num_menu_items = -1;
MsgItems.clear();
Rebuild_MsgItems = true;
First_menu_item = 0;
}
void hud_squadmsg_page_down()
{
if ( (First_menu_item + MAX_MENU_DISPLAY) < Num_menu_items ) {
if ( (First_menu_item + MAX_MENU_DISPLAY) < sz2i(MsgItems.size()) ) {
First_menu_item += MAX_MENU_DISPLAY;
Assert ( First_menu_item < Num_menu_items );
Assert ( First_menu_item < sz2i(MsgItems.size()) );
}
}
@@ -490,77 +480,42 @@ void hud_squadmsg_page_up()
}
//Fuctions that allow selection of specific comms menu items with simple up/down/select buttons
void hud_squadmsg_selection_move_down() {
void hud_squadmsg_selection_move( bool up ) {
if (Rebuild_MsgItems || MsgItems.empty())
return;
//Check if comms menu is up
if (Player->flags & PLAYER_FLAGS_MSG_MODE)
{
//move down
++Selected_menu_item;
Display_selector = true;
//play scrolling sound and reset the comms window timeout timer, so the window doesn't disappear while we select our item
gamesnd_play_iface(InterfaceSounds::SCROLL);
Msg_mode_timestamp = _timestamp(DEFAULT_MSG_TIMEOUT);
//Move to next page if we went outside of current one
if (Selected_menu_item == MAX_MENU_DISPLAY
&& (First_menu_item + MAX_MENU_DISPLAY < Num_menu_items))
{
hud_squadmsg_page_down();
Selected_menu_item = 0;
}
//The selection moves +/-1 through the whole menu, wrapping around at either end.
//First_menu_item and Selected_menu_item are just the page and the offset within the page.
int num_items = sz2i(MsgItems.size());
int selected_index = First_menu_item + Selected_menu_item;
selected_index = (selected_index + (up ? -1 : 1) + num_items) % num_items;
//Select the first menu item if we went outside items range, so we can loop around
if (First_menu_item + Selected_menu_item >= Num_menu_items)
{
First_menu_item = 0;
Selected_menu_item = First_menu_item;
}
}
}
void hud_squadmsg_selection_move_up() {
//Check if comms menu is up
if (Player->flags & PLAYER_FLAGS_MSG_MODE)
{
//move up
--Selected_menu_item;
Display_selector = true;
//play scrolling sound and reset the comms window timeout timer, so the window doesn't disappear while we select our item
gamesnd_play_iface(InterfaceSounds::SCROLL);
Msg_mode_timestamp = _timestamp(DEFAULT_MSG_TIMEOUT);
//Move to previous page if it exists
if (Selected_menu_item < 0 && First_menu_item > 0)
{
hud_squadmsg_page_up();
Selected_menu_item = MAX_MENU_DISPLAY - 1; //if we're moving to previous page in the first place, we assume it was already populated to the max
}
//Select the last menu item if we went outside items range, so we can loop around
else if (Selected_menu_item < 0)
{
//Assuming MAX_MENU_DISPLAY = 10, set First_menu_item to the nearest lower multiple of 10
//So if we have 85 items in comms menu, looping back from 1st page to last would set First_menu_item to 80
//exactly like pageUp/pageDown does
First_menu_item = ((Num_menu_items - 1) / MAX_MENU_DISPLAY) * MAX_MENU_DISPLAY;
Selected_menu_item = Num_menu_items - 1 - First_menu_item;
}
Selected_menu_item = selected_index % MAX_MENU_DISPLAY;
First_menu_item = selected_index - Selected_menu_item;
}
}
//function that tricks hud_squadmsg_get_key() into thinking player selected a menu item with a num key press
//Yes, this is a pretty much a hack, but it's simple and works with every squadmsg type.
void hud_squadmsg_selection_select() {
if (Rebuild_MsgItems) {
return;
}
//Check if comms menu is up
if (Player->flags & PLAYER_FLAGS_MSG_MODE)
{
//Check if selected option is even active
if ((MsgItems[Selected_menu_item + First_menu_item].active > 0))
if ((sz2i(MsgItems.size()) > Selected_menu_item + First_menu_item) && (MsgItems[Selected_menu_item + First_menu_item].active > 0))
{
Msg_key_used = 1;
Msg_key = Selected_menu_item + 2; //+1 because menu items on actual menu start from 1, not 0
@@ -579,7 +534,7 @@ int hud_squadmsg_get_total_keys()
int num_keys_used;
num_keys_used = MAX_KEYS_NO_SCROLL;
if ( Num_menu_items > MAX_MENU_DISPLAY )
if ( sz2i(MsgItems.size()) > MAX_MENU_DISPLAY )
num_keys_used = MAX_KEYS_USED;
return num_keys_used;
@@ -669,15 +624,16 @@ int hud_squadmsg_get_key()
} else if ( k == KEY_ESC ) {
hud_squadmsg_toggle();
return -1;
} else if ( (i < Num_menu_items) && (Squad_msg_mode == SM_MODE_REINFORCEMENTS) ) // return any key if selecting reinforcement
} else if ( (i < sz2i(MsgItems.size())) && (Squad_msg_mode == SM_MODE_REINFORCEMENTS) ) { // return any key if selecting reinforcement
return i;
}
// play general fail sound if inactive item hit.
else if ((i + First_menu_item < Num_menu_items) && (MsgItems[i + First_menu_item].active == 0)) {
else if ((i + First_menu_item < sz2i(MsgItems.size())) && (MsgItems[i + First_menu_item].active == 0)) {
gamesnd_play_iface(InterfaceSounds::GENERAL_FAIL);
}
else if ((i + First_menu_item < Num_menu_items) && (MsgItems[i + First_menu_item].active > 0)) { // only return keys that are associated with menu items
else if ((i + First_menu_item < sz2i(MsgItems.size())) && (MsgItems[i + First_menu_item].active > 0)) { // only return keys that are associated with menu items
return i + First_menu_item;
}
@@ -1779,24 +1735,26 @@ void hud_squadmsg_type_select( )
num_order_types += (int)lua_cat_list.size();
MsgItems.clear();
Rebuild_MsgItems = false;
// Add the items
for (i = 0; i < num_order_types; i++)
{
if (i < NUM_COMM_ORDER_TYPES) {
MsgItems[i].text = Comm_order_types[i];
MsgItems.push_back({0, 1, Comm_order_types[i]}); // assume active
} else {
MsgItems[i].text = lua_cat_list[i - NUM_COMM_ORDER_TYPES];
MsgItems.push_back({0, 1, lua_cat_list[i - NUM_COMM_ORDER_TYPES]}); // assume active
}
MsgItems[i].active = 1; // assume active
}
Num_menu_items = num_order_types;
// check to see if the player is a traitor. If so, then he will not
// be able to do anything from this menu
if ((Player_ship != NULL) && (Player_ship->team == Iff_traitor)) {
for (i = 0; i < MAX_MENU_ITEMS; i++ )
MsgItems[i].active = 0;
for (auto &item : MsgItems)
item.active = 0;
goto do_main_menu;
}
@@ -1833,8 +1791,8 @@ void hud_squadmsg_type_select( )
//
// also, only allow support ship if this player is not allowed to messaage.
if ( (hud_communications_state(Player_ship) != COMM_OK) || ((Game_mode & GM_MULTIPLAYER) && !multi_can_message(Net_player)) ) {
for ( i = 0; i < MAX_MENU_ITEMS; i++ ){
MsgItems[i].active = 0;
for (auto &item : MsgItems){
item.active = 0;
}
MsgItems[TYPE_REPAIR_REARM_ITEM].active = Hide_main_rearm_items_in_comms_gauge ? -1 : 1;
@@ -1877,7 +1835,7 @@ do_main_menu:
strcpy_s(Squad_msg_title, XSTR( "Message What", 316));
k = hud_squadmsg_get_key();
if ( k != -1 ) { // when k != -1, we have a key that associates with menu item
Assert ( k < Num_menu_items );
Assert ( k < sz2i(MsgItems.size()) );
if ( k == TYPE_SHIP_ITEM ){
hud_squadmsg_do_mode( SM_MODE_SHIP_SELECT );
} else if ( k == TYPE_WING_ITEM ) {
@@ -1907,8 +1865,9 @@ void hud_squadmsg_ship_select()
{
int k;
if ( Num_menu_items == -1 ) {
Num_menu_items = 0;
if ( Rebuild_MsgItems ) {
MsgItems.clear();
Rebuild_MsgItems = false;
hud_squadmsg_count_ships( 1 );
}
@@ -1934,8 +1893,9 @@ void hud_squadmsg_wing_select()
{
int k;
if ( Num_menu_items == -1 ) {
Num_menu_items = 0;
if ( Rebuild_MsgItems ) {
MsgItems.clear();
Rebuild_MsgItems = false;
hud_squadmsg_count_wings( 1 );
}
@@ -2045,8 +2005,9 @@ void hud_squadmsg_call_reinforcement(reinforcements &reinforcement, int /*playe
// function to display a list of reinforcements available to the player
void hud_squadmsg_reinforcement_select()
{
if ( Num_menu_items == -1 ) {
Num_menu_items = 0;
if ( Rebuild_MsgItems ) {
MsgItems.clear();
Rebuild_MsgItems = false;
int i = -1;
for (const auto &reinforcement: Reinforcements) {
@@ -2092,16 +2053,7 @@ void hud_squadmsg_reinforcement_select()
r_name = p_objp->get_display_name(); // this will handle getting rid of the hash if necessary
}
Assert ( Num_menu_items < MAX_MENU_ITEMS );
MsgItems[Num_menu_items].text = r_name;
MsgItems[Num_menu_items].instance = i;
MsgItems[Num_menu_items].active = 0;
if ( reinforcement.flags & RF_IS_AVAILABLE ) {
MsgItems[Num_menu_items].active = 1;
}
Num_menu_items++;
MsgItems.push_back({i, (reinforcement.flags & RF_IS_AVAILABLE) ? 1 : 0, r_name}); // set the item to active if reinforcement is available
}
}
@@ -2158,25 +2110,23 @@ void hud_squadmsg_ship_command()
default_orders.insert(default_messages.cbegin(), default_messages.cend());
}
Num_menu_items = 0;
MsgItems.clear();
Rebuild_MsgItems = false;
for(size_t order_id : default_orders) {
Assert (Num_menu_items < MAX_MENU_ITEMS);
MsgItems[Num_menu_items].text = Player_orders[order_id].localized_name;
MsgItems[Num_menu_items].instance = (int)order_id;
MsgItems[Num_menu_items].active = 0;
MsgItems.push_back({(int)order_id, 0, Player_orders[order_id].localized_name});
// check the bit to see if the command is active
if (orders.find(order_id) != orders.end())
MsgItems[Num_menu_items].active = 1;
MsgItems.back().active = 1;
// if the order cannot be carried out by the ship, then item should be inactive
if ((Msg_instance != MESSAGE_ALL_FIGHTERS) && !hud_squadmsg_ship_order_valid(Msg_instance, (int)order_id))
MsgItems[Num_menu_items].active = 0;
MsgItems.back().active = 0;
// do some other checks to possibly gray out other items.
// if no target, remove any items which are associated with the players target
if (!hud_squadmsg_is_target_order_valid(order_id, nullptr))
MsgItems[Num_menu_items].active = 0;
MsgItems.back().active = 0;
// if messaging all fighters, see if we should gray out the order if no one will accept it,
// or modify the text if only some of the ships will accept it
@@ -2208,14 +2158,13 @@ void hud_squadmsg_ship_command()
if (!all_accept) {
// either modify the text if a partial accept, or grey it out if no one accepts
if (partial_accept) {
MsgItems[Num_menu_items].text += XSTR("(*)", 320);
MsgItems.back().text += XSTR("(*)", 320);
} else {
MsgItems[Num_menu_items].active = 0;
MsgItems.back().active = 0;
}
}
}
Num_menu_items++;
}
@@ -2225,7 +2174,7 @@ void hud_squadmsg_ship_command()
// when we get a valid goal, we must add the goal to the ai ship's goal list
if ( k != -1 ) {
Assert ( k < Num_menu_items );
Assert ( k < sz2i(MsgItems.size()) );
// when messaging all fighters or ignoring target, call the send_to_all_fighters routine
// Goober5000 - ignore no longer sends to all fighters
if (Msg_instance == MESSAGE_ALL_FIGHTERS)
@@ -2241,9 +2190,9 @@ void hud_squadmsg_msg_general()
{
int k;
Num_menu_items = 0;
MsgItems.clear();
Rebuild_MsgItems = false;
for (size_t order_id = 0; order_id < Player_orders.size(); order_id++) {
Assert(Num_menu_items < MAX_MENU_ITEMS);
if (Player_orders[order_id].lua_id <= 0) {
continue;
@@ -2263,17 +2212,12 @@ void hud_squadmsg_msg_general()
//Only add it if it is enabled for the mission
if (lua_porder->cur_enabled) {
MsgItems[Num_menu_items].text = Player_orders[order_id].localized_name;
MsgItems[Num_menu_items].instance = Player_orders[order_id].lua_id;
MsgItems[Num_menu_items].active = (int)lua_porder->cur_valid;
MsgItems.push_back({Player_orders[order_id].lua_id, (int)lua_porder->cur_valid, Player_orders[order_id].localized_name});
// do some other checks to possibly gray out other items.
// if no target, remove any items which are associated with the players target
if (!hud_squadmsg_is_target_order_valid(order_id, nullptr))
MsgItems[Num_menu_items].active = 0;
Num_menu_items++;
MsgItems.back().active = 0;
}
}
@@ -2283,7 +2227,7 @@ void hud_squadmsg_msg_general()
// when we get a valid goal, we must add the goal to the ai ship's goal list
if (k != -1) {
Assert(k < Num_menu_items);
Assert( k < sz2i(MsgItems.size()) );
ai_lua_start_general(MsgItems[k].instance, Player_ai->target_objnum);
@@ -2314,7 +2258,8 @@ void hud_squadmsg_wing_command()
default_orders.erase(CAPTURE_TARGET_ITEM); // we cannot capture any target with a wing.
Num_menu_items = 0;
MsgItems.clear();
Rebuild_MsgItems = false;
shipnum = wingp->ship_index[wingp->special_ship];
Assertion(shipnum >= 0, "Special ship (%d) for wing '%s' has a negative ship_index (%d). This should not happen; get a coder!\n", wingp->special_ship, wingp->name, shipnum);
orders = Ships[shipnum].orders_accepted; // get the orders that the wing leader will accept
@@ -2322,24 +2267,21 @@ void hud_squadmsg_wing_command()
for ( size_t order_id : default_orders ) {
// add the set of default orders to the comm menu. We will currently allow all messages
// to be available in the wing.
Assert ( Num_menu_items < MAX_MENU_ITEMS );
MsgItems[Num_menu_items].text = Player_orders[order_id].localized_name;
MsgItems[Num_menu_items].instance = (int)order_id;
MsgItems[Num_menu_items].active = 0;
MsgItems.push_back({(int)order_id, 0, Player_orders[order_id].localized_name});
// possibly grey out the menu item depending on whether or not the "wing" will accept this order
// the "wing" won't accept the order if the first ship in the wing doesn't accept it.
if ( orders.find(order_id) != orders.end() )
MsgItems[Num_menu_items].active = 1;
MsgItems.back().active = 1;
// do some other checks to possibly gray out other items.
// if no target, remove any items which are associated with the players target
if ( !hud_squadmsg_is_target_order_valid((int)order_id, 0, true) )
MsgItems[Num_menu_items].active = 0;
MsgItems.back().active = 0;
// if no ship in the wing can depart then gray out the departure order
if (order_id == DEPART_ITEM) {
if (MsgItems[Num_menu_items].active > 0) {
if (MsgItems.back().active > 0) {
int active = 0;
for (int i = 0; i < wingp->current_count; i++) {
if (hud_squadmsg_ship_order_valid(wingp->ship_index[i], (int)order_id)) {
@@ -2347,12 +2289,9 @@ void hud_squadmsg_wing_command()
break;
}
}
MsgItems[Num_menu_items].active = active;
MsgItems.back().active = active;
}
}
Num_menu_items++;
}
@@ -2904,15 +2843,17 @@ void HudGaugeSquadMessage::render(float /*frametime*/, bool config)
renderString(x + Header_offsets[0], y + fl2i(Header_offsets[1] * scale), title, scale, config);
}
int msg_items_size = sz2i(MsgItems.size());
int nitems;
if (!config) {
if (Num_menu_items < MAX_MENU_DISPLAY)
nitems = Num_menu_items;
if (msg_items_size < MAX_MENU_DISPLAY)
nitems = msg_items_size;
else {
if (First_menu_item == 0) // First_menu_item == 0 means first page of items
nitems = MAX_MENU_DISPLAY;
else if ((Num_menu_items - First_menu_item) <= MAX_MENU_DISPLAY) // check if remaining items fit on one page
nitems = Num_menu_items - First_menu_item;
else if (msg_items_size - First_menu_item <= MAX_MENU_DISPLAY) // check if remaining items fit on one page
nitems = msg_items_size - First_menu_item;
else {
nitems = MAX_MENU_DISPLAY;
}
@@ -2953,9 +2894,6 @@ void HudGaugeSquadMessage::render(float /*frametime*/, bool config)
XSTR("Abort Rearm", 298)
};
strcpy_s(text, temp_comm_order_types[i]);
if (Hide_main_rearm_items_in_comms_gauge && (i == TYPE_REPAIR_REARM_ITEM || i == TYPE_REPAIR_REARM_ABORT_ITEM)) {
MsgItems[First_menu_item + i].active = -1;
}
}
// blit the background
@@ -2976,7 +2914,10 @@ void HudGaugeSquadMessage::render(float /*frametime*/, bool config)
setGaugeColor(HUD_C_DIM, config);
}
if (MsgItems[First_menu_item + i].active >= 0) {
bool item_visible = config
? (!Hide_main_rearm_items_in_comms_gauge) || ((i != TYPE_REPAIR_REARM_ITEM) && (i != TYPE_REPAIR_REARM_ABORT_ITEM))
: (MsgItems[First_menu_item + i].active >= 0);
if (item_visible) {
// first print an icon to indicate selected item
item_num = (i + 1) % MAX_MENU_DISPLAY;
if (isSelectedItem && Display_selector) {
@@ -3001,7 +2942,7 @@ void HudGaugeSquadMessage::render(float /*frametime*/, bool config)
// maybe draw an extra line in to make room for [pgdn], or for the 'no active items'
// display
if (!config && (!messaging_allowed || none_valid || ((First_menu_item + nitems) < Num_menu_items) || (Msg_shortcut_command != -1))) {
if (!config && (!messaging_allowed || none_valid || ((First_menu_item + nitems) < msg_items_size) || (Msg_shortcut_command != -1))) {
// blit the background
setGaugeColor(HUD_C_NONE, config);
if ( Mbox_gauge[1].first_frame >= 0 ) {
@@ -3026,7 +2967,7 @@ void HudGaugeSquadMessage::render(float /*frametime*/, bool config)
renderPrintf(x + fl2i(Pgup_offsets[0] * scale), y + fl2i(Pgup_offsets[1] * scale), scale, config, "%s", XSTR( "[pgup]", 312) );
}
if ( (First_menu_item + nitems) < Num_menu_items ) {
if ( (First_menu_item + nitems) < msg_items_size ) {
renderPrintf(x + fl2i(Pgdn_offsets[0] * scale), y + fl2i(Pgdn_offsets[1] * scale), scale, config, "%s", XSTR( "[pgdn]", 313));
}
+2 -5
View File
@@ -62,7 +62,6 @@ struct reinforcements;
// used for Message box gauge
#define NUM_MBOX_FRAMES 3
#define MAX_MENU_ITEMS 50 // max number of items in the menu
#define MAX_MENU_DISPLAY 10 // max number that can be displayed
// following are defines and character strings that are used as part of messaging mode
@@ -83,8 +82,7 @@ typedef struct mmode_item {
} mmode_item;
extern char Squad_msg_title[256];
extern mmode_item MsgItems[MAX_MENU_ITEMS];
extern int Num_menu_items; // number of items for a message menu
extern SCP_vector<mmode_item> MsgItems;
typedef struct player_order {
private:
@@ -192,8 +190,7 @@ void hud_enemymsg_toggle(); // debug function to allow messaging of enemies
void hud_squadmsg_do_mode( int mode );
// functions for menu item selection with simple up/down/select buttons
void hud_squadmsg_selection_move_down();
void hud_squadmsg_selection_move_up();
void hud_squadmsg_selection_move( bool up );
void hud_squadmsg_selection_select();
// Added for checking message validity - Mjn
+2 -2
View File
@@ -2908,11 +2908,11 @@ int button_function(int n)
break;
case COMMS_MENU_MOVE_DOWN:
hud_squadmsg_selection_move_down();
hud_squadmsg_selection_move(false);
break;
case COMMS_MENU_MOVE_UP:
hud_squadmsg_selection_move_up();
hud_squadmsg_selection_move(true);
break;
case COMMS_MENU_SELECT:
-7
View File
@@ -154,13 +154,6 @@ void LuaAISEXP::parseTable() {
// Now get a list of all lua categories to add. Meow.
SCP_vector<SCP_string> lua_cat_list = ai_lua_get_general_order_categories();
// If we have too many categories then we have an oopsie!
if ((int)lua_cat_list.size() > (MAX_MENU_ITEMS - NUM_COMM_ORDER_TYPES)) {
Warning(LOCATION, "Too many defined Lua General Order Categories! Setting order to first available: %s", lua_cat_list[0].c_str());
order.category = lua_cat_list[0];
}
// General orders explicitely do not show up in FRED as sexps because they
// they are only meant for the comms board
_return_type = OPR_NONE;
+2 -2
View File
@@ -343,7 +343,7 @@ ADE_INDEXER(l_Mission_Comm_Items,
// convert from lua index
idx--;
if ((idx < 0) || idx >= MAX_MENU_ITEMS)
if (idx < 0)
return ade_set_args(L, "o", l_Comm_Item.Set(-1));
return ade_set_args(L, "o", l_Comm_Item.Set(idx));
@@ -356,7 +356,7 @@ ADE_FUNC(__len,
"number",
"Number of comm orders in the mission. 0 if comm menu is closed")
{
return ade_set_args(L, "i", Num_menu_items);
return ade_set_args(L, "i", sz2i(MsgItems.size()));
}
//****SUBLIBRARY: Mission/Debris
+8 -5
View File
@@ -17,8 +17,11 @@ ADE_VIRTVAR(Name, l_Comm_Item, nullptr, "The name of the comm item", "string", "
if (ADE_SETTING_VAR) {
LuaError(L, "This property is read only.");
}
return ade_set_args(L, "s", MsgItems[current].text.c_str());
SCP_string message = "Invalid comm item!";
if (MsgItems.in_bounds(current)) {
message = MsgItems[current].text;
}
return ade_set_args(L, "s", message.c_str());
}
ADE_VIRTVAR(Active, l_Comm_Item, nullptr, "Whether or not the item is active", "boolean", "The active status")
@@ -32,7 +35,7 @@ ADE_VIRTVAR(Active, l_Comm_Item, nullptr, "Whether or not the item is active", "
LuaError(L, "This property is read only.");
}
if (MsgItems[current].active > 0) {
if (MsgItems.in_bounds(current) && MsgItems[current].active > 0) {
return ADE_RETURN_TRUE;
}
@@ -60,7 +63,7 @@ ADE_FUNC(selectItem, l_Comm_Item, nullptr, "Selects the item and either proceeds
if (!ade_get_args(L, "o", l_Comm_Item.Get(&current)))
return ADE_RETURN_FALSE;
if (current < 0 || current >= Num_menu_items) {
if (!MsgItems.in_bounds(current)) {
LuaError(L, "Lua tried to select squad message that is not valid!");
return ADE_RETURN_FALSE;
}
@@ -77,7 +80,7 @@ ADE_FUNC(isValid, l_Comm_Item, nullptr, "Detect if the handle is valid", "boolea
if (!ade_get_args(L, "o", l_Comm_Item.Get(&current)))
return ADE_RETURN_FALSE;
return ade_set_args(L, "b", (current >= 0) && (current < Num_menu_items));
return ade_set_args(L, "b", MsgItems.in_bounds(current));
}
} // namespace scripting::api