| 424 | } |
| 425 | |
| 426 | bool Military::addToSquad(int32_t unit_id, int32_t squad_id, int32_t squad_pos) |
| 427 | { |
| 428 | df::unit* unit = df::unit::find(unit_id); |
| 429 | if (unit == nullptr || unit->military.squad_id != -1) return false; |
| 430 | |
| 431 | df::historical_figure* hf = df::historical_figure::find(unit->hist_figure_id); |
| 432 | if (hf == nullptr) |
| 433 | return false; |
| 434 | |
| 435 | df::squad* squad = df::squad::find(squad_id); |
| 436 | if (squad == nullptr) return false; |
| 437 | |
| 438 | if (squad_pos == -1) |
| 439 | { |
| 440 | for (int p = 0; p < 10; p++) |
| 441 | { |
| 442 | auto pp = vector_get(squad->positions, p); |
| 443 | if (pp == nullptr || pp->occupant == -1) |
| 444 | { |
| 445 | squad_pos = p; |
| 446 | break; |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | if (squad_pos == -1) return false; |
| 451 | |
| 452 | // this function cannot (currently) change the squad commander |
| 453 | if (squad_pos == 0) return false; |
| 454 | |
| 455 | df::squad_position* pos = vector_get(squad->positions, squad_pos); |
| 456 | if (pos == nullptr) |
| 457 | pos = squad->positions[squad_pos] = df::allocate<df::squad_position>(); |
| 458 | |
| 459 | pos->occupant = hf->id; |
| 460 | // does anything else need to be set here? |
| 461 | |
| 462 | unit->military.squad_id = squad->id; |
| 463 | unit->military.squad_position = squad_pos; |
| 464 | |
| 465 | add_soldier_entity_link(hf, squad, squad_pos); |
| 466 | |
| 467 | #define F(flag) df::equipment_update::mask_##flag |
| 468 | auto constexpr update_flags = F(weapon) | F(armor) | F(shoes) | F(shield) | F(helm) | F(gloves) |
| 469 | | F(ammo) | F(pants) | F(backpack) | F(quiver) | F(flask); |
| 470 | #undef F |
| 471 | |
| 472 | squad->ammo.update.whole |= update_flags; |
| 473 | df::global::plotinfo->equipment.update.whole |= update_flags; |
| 474 | |
| 475 | return true; |
| 476 | } |
| 477 | |
| 478 | bool Military::removeFromSquad(int32_t unit_id) |
| 479 | { |
nothing calls this directly
no test coverage detected