Skip to content
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
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Template for new versions:

## API
- ``Filesystem::getBaseDir`` and ``Filesystem::getInstallDir`` added (and made available in Lua)
- expand the partial implementations of ``Military::addToSquad`` and ``Military::removeFromSquad``

## Lua
- inserting values into STL containers containing nonprimitive types is now supported
Expand Down
25 changes: 25 additions & 0 deletions library/modules/Military.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "modules/Military.h"
#include "modules/Translation.h"
#include "modules/Units.h"
#include "df/activity_entry.h"
#include "df/activity_event.h"
#include "df/building.h"
#include "df/building_civzonest.h"
#include "df/building_squad_infost.h"
Expand All @@ -17,6 +19,7 @@
#include "df/history_event_remove_hf_entity_linkst.h"
#include "df/entity_position.h"
#include "df/entity_position_assignment.h"
#include "df/equipment_update.h"
#include "df/plotinfost.h"
#include "df/military_routinest.h"
#include "df/squad.h"
Expand Down Expand Up @@ -460,6 +463,15 @@ bool Military::addToSquad(int32_t unit_id, int32_t squad_id, int32_t squad_pos)
unit->military.squad_position = squad_pos;

add_soldier_entity_link(hf, squad, squad_pos);

#define F(flag) df::equipment_update::mask_##flag
auto constexpr update_flags = F(weapon) | F(armor) | F(shoes) | F(shield) | F(helm) | F(gloves)
| F(ammo) | F(pants) | F(backpack) | F(quiver) | F(flask);
#undef F

squad->ammo.update.whole |= update_flags;
df::global::plotinfo->equipment.update.whole |= update_flags;

return true;
}

Expand Down Expand Up @@ -489,6 +501,19 @@ bool Military::removeFromSquad(int32_t unit_id)
unit->military.squad_id = -1;
unit->military.squad_position = -1;

// abort individual training
if (unit->individual_drills.size()) {
unit->flags3.bits.verify_personal_training = true;
}

// remove unit from squad activities
auto activity_entry = binsearch_in_vector(df::global::world->activities.all,&df::activity_entry::id,squad->activity);
if (activity_entry) {
for (auto const activity_event : activity_entry->events) {
activity_event->removeParticipant(unit->hist_figure_id, unit->id, false);
}
}

if (squad_pos == 0) // is unit a commander?
remove_officer_entity_link(hf, squad);
else
Expand Down
Loading