From c38a288eee9775706decba2b0f69b43c4550d4c3 Mon Sep 17 00:00:00 2001 From: 20k Date: Mon, 27 Feb 2023 02:15:26 +0000 Subject: [PATCH] use insert_into_vector, tweak docs again --- docs/dev/Lua API.rst | 4 ++-- library/modules/Military.cpp | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 54ac4d48e..63803a66a 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -1594,9 +1594,9 @@ Military module * ``dfhack.military.makeSquad(assignment_id)`` - Creates a new squad associated with the assignment (ie df::entity_position_assignment, via `id``) and returns it. + Creates a new squad associated with the assignment (ie ``df::entity_position_assignment``, via ``id``) and returns it. Fails if a squad already exists that is associated with that assignment, or if the assignment is not a fort mode player controlled squad. - Note: This function does not name the squad: consider setting a nickname (under result.name.nickname), and/or filling out the language_name object at result.name. + Note: This function does not name the squad: consider setting a nickname (under ``squad.name.nickname``), and/or filling out the ``language_name`` object at ``squad.name``. The returned squad is otherwise complete and requires no more setup to work correctly. * ``dfhack.military.updateRoomAssignments(squad_id, assignment_id, squad_use_flags)`` diff --git a/library/modules/Military.cpp b/library/modules/Military.cpp index 3b7ce7bec..b402cc0fa 100644 --- a/library/modules/Military.cpp +++ b/library/modules/Military.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "MiscUtils.h" #include "modules/Military.h" #include "modules/Translation.h" #include "df/building.h" @@ -258,18 +259,16 @@ void Military::updateRoomAssignments(int32_t squad_id, int32_t civzone_id, df::s { room_from_squad = new df::squad::T_rooms(); room_from_squad->building_id = civzone_id; - squad->rooms.push_back(room_from_squad); - std::sort(squad->rooms.begin(), squad->rooms.end(), [](df::squad::T_rooms* a, df::squad::T_rooms* b){return a->building_id < b->building_id;}); + insert_into_vector(squad->rooms, &df::squad::T_rooms::building_id, room_from_squad); } if (room_from_building == nullptr) { room_from_building = new df::building_civzonest::T_squad_room_info(); room_from_building->squad_id = squad_id; - zone->squad_room_info.push_back(room_from_building); - std::sort(zone->squad_room_info.begin(), zone->squad_room_info.end(), [](df::building_civzonest::T_squad_room_info* a, df::building_civzonest::T_squad_room_info* b){return a->squad_id < b->squad_id;}); + insert_into_vector(zone->squad_room_info, &df::building_civzonest::T_squad_room_info::squad_id, room_from_building); } if (room_from_squad)