MCPcopy Create free account
hub / github.com/DFHack/dfhack / makeSquad

Method makeSquad

library/modules/Military.cpp:54–236  ·  view source on GitHub ↗

only works for making squads for fort mode player controlled dwarf squads could be extended straightforwardly by passing in entity

Source from the content-addressed store, hash-verified

52//only works for making squads for fort mode player controlled dwarf squads
53//could be extended straightforwardly by passing in entity
54df::squad* Military::makeSquad(int32_t assignment_id)
55{
56 if (df::global::squad_next_id == nullptr || df::global::plotinfo == nullptr)
57 return nullptr;
58
59 df::language_name name;
60 name.type = df::language_name_type::Squad;
61
62 for (int i=0; i < 7; i++)
63 {
64 name.words[i] = -1;
65 name.parts_of_speech[i] = df::part_of_speech::Noun;
66 }
67
68 df::historical_entity* fort = df::historical_entity::find(df::global::plotinfo->group_id);
69
70 if (fort == nullptr)
71 return nullptr;
72
73 df::entity_position_assignment* found_assignment = nullptr;
74
75 for (auto* assignment : fort->positions.assignments)
76 {
77 if (assignment->id == assignment_id)
78 {
79 found_assignment = assignment;
80 break;
81 }
82 }
83
84 if (found_assignment == nullptr)
85 return nullptr;
86
87 //this function does not attempt to delete or replace squads for assignments
88 if (found_assignment->squad_id != -1)
89 return nullptr;
90
91 df::entity_position* corresponding_position = nullptr;
92
93 for (auto* position : fort->positions.own)
94 {
95 if (position->id == found_assignment->position_id)
96 {
97 corresponding_position = position;
98 break;
99 }
100 }
101
102 if (corresponding_position == nullptr)
103 return nullptr;
104
105 df::squad* result = new df::squad();
106 result->id = *df::global::squad_next_id;
107 result->uniform_priority = result->id + 1; //no idea why, but seems to hold
108 result->supplies.carry_food = 2;
109 result->supplies.carry_water = df::squad_water_level_type::Water;
110 result->entity_id = df::global::plotinfo->group_id;
111 result->leader_position = corresponding_position->id;

Callers

nothing calls this directly

Calls 2

findFunction · 0.50
resizeMethod · 0.45

Tested by

no test coverage detected