Skip to content

Commit

Permalink
removes obsolete code, adds comments for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
bobtista committed May 28, 2023
1 parent 5529abc commit a1f5d61
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/game/logic/ai/aigroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1641,19 +1641,25 @@ void Get_Helicopter_Offset(Coord3D &pos, int count)
}
}

/**
Group_Tighten_To_Position - Performs tightening of the group members towards a target position.
This method iterates over the group members, calculates their distances to the target position,
and sorts them in ascending order based on the squared distance. It then applies tightening
behavior to each member based on the specified conditions.
@param target_pos The target position to tighten towards.
@param append A flag indicating whether to append to existing waypoints or not.
@param cmd_source The source of the command.
*/
void AIGroup::Group_Tighten_To_Position(const Coord3D *target_pos, bool append, CommandSourceType cmd_source)
{
if (cmd_source == COMMANDSOURCE_PLAYER && g_theWriteableGlobalData->m_groupMoveClickToGatherAreaFactor > 0.0f) {
Coord2D min;
Coord2D max;
Coord3D center;
Get_Min_Max_And_Center(&min, &max, &center);
}

// Create a SimpleObjectIterator to hold and iterate over the group members
MemoryPoolObjectHolder holder(nullptr);
SimpleObjectIterator *iter = new SimpleObjectIterator();
holder.Hold(iter);

// Iterate over the group members and insert them into the iterator based on distance to target
for (auto it = m_memberList.begin(); it != m_memberList.end(); it++) {
Coord3D member_pos = *(*it)->Get_Position();

Expand All @@ -1668,9 +1674,11 @@ void AIGroup::Group_Tighten_To_Position(const Coord3D *target_pos, bool append,
}
}

// Sort the iterator in ascending order based on the distance to target
iter->Sort(ITER_SORTED_NEAR_TO_FAR);
int heli_count = 0;

// Iterate over the sorted members and apply tightening behavior
for (Object *iter_obj = iter->First(); iter_obj != nullptr; iter_obj = iter->Next()) {
AIUpdateInterface *update = iter_obj->Get_AI_Update_Interface();

Expand All @@ -1686,6 +1694,7 @@ void AIGroup::Group_Tighten_To_Position(const Coord3D *target_pos, bool append,
}
}

// Update the positions of the members in the Pathfinder
for (Object *iter_obj = iter->First(); iter_obj != nullptr; iter_obj = iter->Next()) {
Coord3D iter_pos = *iter_obj->Get_Position();
g_theAI->Get_Pathfinder()->Update_Pos(iter_obj, &iter_pos);
Expand Down

0 comments on commit a1f5d61

Please sign in to comment.