Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit d2bb568

Browse files
committed
2 parents 25ebbed + 328a400 commit d2bb568

File tree

4 files changed

+42
-30
lines changed

4 files changed

+42
-30
lines changed

Entities/Turret.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ namespace RTE {
3030
return 0;
3131
}
3232

33+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
34+
35+
void Turret::Destroy(bool notInherited) {
36+
if (!notInherited) { Attachable::Destroy(); }
37+
for (const HeldDevice *mountedDevice : m_MountedDevices) { m_HardcodedAttachableUniqueIDsAndRemovers.erase(mountedDevice->GetUniqueID()); }
38+
Clear();
39+
}
40+
3341
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3442

3543
int Turret::ReadProperty(const std::string_view &propName, Reader &reader) {
@@ -121,6 +129,15 @@ namespace RTE {
121129
}
122130
}
123131

132+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
133+
134+
void Turret::SetParent(MOSRotating *newParent) {
135+
Attachable::SetParent(newParent);
136+
for (HeldDevice *mountedDevice : m_MountedDevices) {
137+
mountedDevice->Deactivate(); //mountedDevice->Reloading = false; m_ReloadTmr.Reset();
138+
}
139+
}
140+
124141
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
125142

126143
void Turret::RemoveMountedDevice(const HeldDevice *mountedDeviceToRemove) {

Entities/Turret.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace RTE {
4242
/// Destroys and resets (through Clear()) the Turret object.
4343
/// </summary>
4444
/// <param name="notInherited">Whether to only destroy the members defined in this derived class, or to destroy all inherited members also.</param>
45-
void Destroy(bool notInherited = false) override { if (!notInherited) { Attachable::Destroy(); } Clear(); }
45+
void Destroy(bool notInherited = false) override;
4646

4747
/// <summary>
4848
/// Resets the entire Turret, including its inherited members, to their default settings or values.
@@ -114,12 +114,19 @@ namespace RTE {
114114

115115
protected:
116116

117+
/// <summary>
118+
/// Sets this Attachable's parent MOSRotating, and also sets its Team based on its parent and, if the Attachable is set to collide, adds/removes Atoms to its new/old parent.
119+
/// Additionally, deactivates all MountedDevices.
120+
/// </summary>
121+
/// <param name="newParent">A pointer to the MOSRotating to set as the new parent. Ownership is NOT transferred!</param>
122+
void SetParent(MOSRotating *newParent) override;
123+
117124
static Entity::ClassInfo m_sClass; //!< ClassInfo for this class.
118125

119126
private:
120127

121128
//TODO I think things would be cleaner if this (and all hardcoded attachable pointers) used weak_ptrs. It would solve some weird ownership stuff, particularly with this. However, for that to be possible, m_Attachables has to be shared_ptrs though.
122-
std::vector<HeldDevice *> m_MountedDevices; //!< Vector of unique_ptrs to the mounted HeldDevices of this Turret, if any. Owned here.
129+
std::vector<HeldDevice *> m_MountedDevices; //!< Vector of pointers to the mounted HeldDevices of this Turret, if any. Owned here.
123130
float m_MountedDeviceRotationOffset; //!< The relative offset angle (in radians) of the mounted HeldDevice from this Turret's rotation.
124131

125132
/// <summary>

Menus/MetagameGUI.cpp

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,36 +1096,25 @@ bool MetagameGUI::StartNewGame()
10961096
g_MetaMan.m_TeamCount++;
10971097
}
10981098

1099-
// Get the tech selection and apply it to the metaplayer
1100-
GUIListPanel::Item *pTechItem = m_apPlayerTechSelect[player]->GetSelectedItem();
1101-
if (pTechItem)
1102-
{
1103-
// If the "random" selection, choose one from the list of loaded techs
1104-
if (m_apPlayerTechSelect[player]->GetSelectedIndex() <= 0)//pTechItem->m_ExtraIndex < 0)
1105-
{
1106-
int selection = RandomNum<int>(1, m_apPlayerTechSelect[player]->GetListPanel()->GetItemList()->size() - 1);
1107-
1108-
// Don't let the game to chose the same faction twice
1099+
if (const GUIListPanel::Item *selectedTech = m_apPlayerTechSelect[player]->GetSelectedItem()) {
1100+
// If the "random" selection, choose one from the list of loaded techs.
1101+
if (m_apPlayerTechSelect[player]->GetSelectedIndex() <= 0) {
1102+
int randomSelection = 0;
1103+
1104+
// Don't let the game to chose the same faction twice.
11091105
bool ok = false;
1110-
while (!ok)
1111-
{
1106+
while (!ok) {
1107+
randomSelection = RandomNum<int>(1, m_apPlayerTechSelect[player]->GetListPanel()->GetItemList()->size() - 1);
11121108
ok = true;
1113-
selection = RandomNum<int>(1, m_apPlayerTechSelect[player]->GetListPanel()->GetItemList()->size() - 1);
1114-
1115-
for (int p = 0; p < player; p++)
1116-
if (selection == m_apPlayerTechSelect[p]->GetSelectedIndex())
1117-
ok = false;
1109+
for (int p = 0; p < player; p++) {
1110+
if (randomSelection == m_apPlayerTechSelect[p]->GetSelectedIndex()) { ok = false; }
1111+
}
11181112
}
1113+
selectedTech = m_apPlayerTechSelect[player]->GetItem(randomSelection);
1114+
}
1115+
if (selectedTech) { newPlayer.m_NativeTechModule = selectedTech->m_ExtraIndex; }
1116+
}
11191117

1120-
m_apPlayerTechSelect[player]->SetSelectedIndex(selection);
1121-
pTechItem = m_apPlayerTechSelect[player]->GetSelectedItem();
1122-
}
1123-
1124-
// Now set the selected tech's module index as what the metaplayer is going to use
1125-
if (pTechItem)
1126-
newPlayer.m_NativeTechModule = pTechItem->m_ExtraIndex;
1127-
}
1128-
11291118
// Set the starting brains for this player
11301119
// Start with the baseline setting
11311120
newPlayer.m_BrainPool = m_pLengthSlider->GetValue();

Menus/ScenarioActivityConfigGUI.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ namespace RTE {
212212
if (techItem->m_ExtraIndex == -2) {
213213
gameActivity->SetTeamTech(team, "-All-");
214214
} else if (techItem->m_ExtraIndex == -1) {
215-
m_TeamTechComboBoxes.at(team)->SetSelectedIndex(RandomNum<int>(2, m_TeamTechComboBoxes.at(team)->GetListPanel()->GetItemList()->size() - 1));
216-
gameActivity->SetTeamTech(team, g_PresetMan.GetDataModuleName(m_TeamTechComboBoxes.at(team)->GetSelectedItem()->m_ExtraIndex));
215+
gameActivity->SetTeamTech(team, g_PresetMan.GetDataModuleName(m_TeamTechComboBoxes.at(team)->GetItem(RandomNum<int>(2, m_TeamTechComboBoxes.at(team)->GetListPanel()->GetItemList()->size() - 1))->m_ExtraIndex));
217216
} else {
218217
gameActivity->SetTeamTech(team, g_PresetMan.GetDataModuleName(techItem->m_ExtraIndex));
219218
}

0 commit comments

Comments
 (0)