Skip to content

Commit 4a5c766

Browse files
authored
Merge pull request #5269 from ong-yinggao98/fix/remove-from-squad
`Military::removeFromSquad`: Add missing history event when unassigning officer
2 parents 52a6b89 + 4aa4fe9 commit 4a5c766

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

docs/about/Authors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ NotRexButCaesar NotRexButCaesar
158158
Nuno Fernandes UnknowableCoder
159159
nuvu vallode
160160
Omniclasm
161+
Ong Ying Gao ong-yinggao98
161162
oorzkws oorzkws
162163
OwnageIsMagic OwnageIsMagic
163164
palenerd dlmarquis

docs/dev/Lua API.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,8 +1991,9 @@ Military module
19911991
Removes a unit from its squad. Unsets the unit's
19921992
military information (i.e., ``unit.military.squad_id`` and
19931993
``unit.military.squad_pos``), the squad's position information (i.e.,
1994-
``squad.positions[squad_pos].occupant``), and modifies the unit's entity links
1995-
to indicate former squad membership or command.
1994+
``squad.positions[squad_pos].occupant``), modifies the unit's entity links
1995+
to indicate former squad membership or command, and creates a corresponding
1996+
world history event.
19961997

19971998
Items module
19981999
------------

library/modules/Military.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "df/histfig_entity_link_squadst.h"
1515
#include "df/historical_figure.h"
1616
#include "df/historical_entity.h"
17+
#include "df/history_event_remove_hf_entity_linkst.h"
1718
#include "df/entity_position.h"
1819
#include "df/entity_position_assignment.h"
1920
#include "df/plotinfost.h"
@@ -334,6 +335,8 @@ static void remove_soldier_entity_link(df::historical_figure* hf, df::squad* squ
334335
former_squad->link_strength = 100;
335336

336337
hf->entity_links.push_back(former_squad);
338+
339+
// Unassigning a normal soldier does not seem to generate an event record.
337340
}
338341

339342
static void remove_officer_entity_link(df::historical_figure* hf, df::squad* squad)
@@ -343,6 +346,7 @@ static void remove_officer_entity_link(df::historical_figure* hf, df::squad* squ
343346
return;
344347

345348
int32_t assignment_id = -1;
349+
int32_t pos_id = -1;
346350
for (auto& np : nps)
347351
{
348352
if (np.entity->id != squad->entity_id || np.assignment->squad_id != squad->id)
@@ -352,6 +356,7 @@ static void remove_officer_entity_link(df::historical_figure* hf, df::squad* squ
352356
np.assignment->histfig2 = -1;
353357

354358
assignment_id = np.assignment->id;
359+
pos_id = np.position->id;
355360
break;
356361
}
357362

@@ -389,6 +394,18 @@ static void remove_officer_entity_link(df::historical_figure* hf, df::squad* squ
389394
former_pos->link_strength = 100;
390395

391396
hf->entity_links.push_back(former_pos);
397+
398+
int32_t event_id = (*df::global::hist_event_next_id)++;
399+
auto former_pos_event = df::allocate<df::history_event_remove_hf_entity_linkst>();
400+
former_pos_event->year = *df::global::cur_year;
401+
former_pos_event->seconds = *df::global::cur_year_tick;
402+
former_pos_event->id = event_id;
403+
former_pos_event->civ = squad->entity_id;
404+
former_pos_event->histfig = hf->id;
405+
former_pos_event->position_id = pos_id;
406+
former_pos_event->link_type = df::histfig_entity_link_type::POSITION;
407+
408+
df::global::world->history.events.push_back(former_pos_event);
392409
}
393410

394411
bool Military::removeFromSquad(int32_t unit_id)

0 commit comments

Comments
 (0)