| 343 | } |
| 344 | |
| 345 | static void remove_officer_entity_link(df::historical_figure* hf, df::squad* squad) |
| 346 | { |
| 347 | std::vector<Units::NoblePosition> nps; |
| 348 | if (!Units::getNoblePositions(&nps, hf)) |
| 349 | return; |
| 350 | |
| 351 | int32_t assignment_id = -1; |
| 352 | int32_t pos_id = -1; |
| 353 | for (auto& np : nps) |
| 354 | { |
| 355 | if (np.entity->id != squad->entity_id || np.assignment->squad_id != squad->id) |
| 356 | continue; |
| 357 | |
| 358 | np.assignment->histfig = -1; |
| 359 | np.assignment->histfig2 = -1; |
| 360 | |
| 361 | assignment_id = np.assignment->id; |
| 362 | pos_id = np.position->id; |
| 363 | break; |
| 364 | } |
| 365 | |
| 366 | if (assignment_id == -1) |
| 367 | return; |
| 368 | |
| 369 | int32_t start_year = -1; |
| 370 | for (size_t i = 0; i < hf->entity_links.size(); i++) |
| 371 | { |
| 372 | df::histfig_entity_link* link = hf->entity_links[i]; |
| 373 | if (link->getType() != df::enums::histfig_entity_link_type::POSITION) |
| 374 | continue; |
| 375 | |
| 376 | auto pos_link = strict_virtual_cast<df::histfig_entity_link_positionst>(link); |
| 377 | if (pos_link == nullptr) |
| 378 | continue; |
| 379 | if (pos_link->assignment_id != assignment_id && pos_link->entity_id != squad->entity_id) |
| 380 | continue; |
| 381 | |
| 382 | hf->entity_links.erase(hf->entity_links.begin() + i); |
| 383 | start_year = pos_link->start_year; |
| 384 | |
| 385 | delete pos_link; |
| 386 | break; |
| 387 | } |
| 388 | |
| 389 | if (start_year == -1) |
| 390 | return; |
| 391 | |
| 392 | auto former_pos = df::allocate<df::histfig_entity_link_former_positionst>(); |
| 393 | former_pos->assignment_id = assignment_id; |
| 394 | former_pos->entity_id = squad->entity_id; |
| 395 | former_pos->start_year = start_year; |
| 396 | former_pos->end_year = *df::global::cur_year; |
| 397 | former_pos->link_strength = 100; |
| 398 | |
| 399 | hf->entity_links.push_back(former_pos); |
| 400 | |
| 401 | int32_t event_id = (*df::global::hist_event_next_id)++; |
| 402 | auto former_pos_event = df::allocate<df::history_event_remove_hf_entity_linkst>(); |
no test coverage detected