@@ -869,16 +869,8 @@ void MovableMan::AddActor(Actor *pActorToAdd)
869
869
pActorToAdd->SetAge (0 );
870
870
}
871
871
m_AddedActors.push_back (pActorToAdd);
872
- // Add to the team roster and then sort it too
873
- int team = pActorToAdd->GetTeam ();
874
- // Also re-set the TEam so that the Team Icons get set up properly
875
- pActorToAdd->SetTeam (team);
876
- // Only add to a roster if it's on a team AND is controllable (eg doors are not)
877
- if (team >= Activity::TEAM_1 && team < Activity::MAXTEAMCOUNT && pActorToAdd->IsControllable ())
878
- {
879
- m_ActorRoster[pActorToAdd->GetTeam ()].push_back (pActorToAdd);
880
- m_ActorRoster[pActorToAdd->GetTeam ()].sort (MOXPosComparison ());
881
- }
872
+
873
+ AddActorToTeamRoster (pActorToAdd);
882
874
}
883
875
}
884
876
@@ -991,9 +983,7 @@ bool MovableMan::RemoveActor(MovableObject *pActorToRem)
991
983
}
992
984
}
993
985
}
994
- // Remove from roster as well
995
- if (pActorToRem->GetTeam () >= 0 )
996
- m_ActorRoster[pActorToRem->GetTeam ()].remove (dynamic_cast <Actor *>(pActorToRem));
986
+ RemoveActorFromTeamRoster (dynamic_cast <Actor *>(pActorToRem));
997
987
}
998
988
return removed;
999
989
}
@@ -1039,6 +1029,68 @@ bool MovableMan::RemoveItem(MovableObject *pItemToRem)
1039
1029
}
1040
1030
1041
1031
1032
+
1033
+
1034
+ // ////////////////////////////////////////////////////////////////////////////////////////
1035
+ // Method: AddActorToTeamRoster
1036
+ // ////////////////////////////////////////////////////////////////////////////////////////
1037
+ // Description: Adds actor to internal team roster
1038
+ // Arguments: Pointer to actor
1039
+ // Return value: None.
1040
+
1041
+ void MovableMan::AddActorToTeamRoster (Actor * pActorToAdd)
1042
+ {
1043
+ if (!pActorToAdd)
1044
+ return ;
1045
+
1046
+ // Add to the team roster and then sort it too
1047
+ int team = pActorToAdd->GetTeam ();
1048
+ // Also re-set the TEam so that the Team Icons get set up properly
1049
+ pActorToAdd->SetTeam (team);
1050
+ // Only add to a roster if it's on a team AND is controllable (eg doors are not)
1051
+ if (team >= Activity::TEAM_1 && team < Activity::MAXTEAMCOUNT && pActorToAdd->IsControllable ())
1052
+ {
1053
+ m_ActorRoster[pActorToAdd->GetTeam ()].push_back (pActorToAdd);
1054
+ m_ActorRoster[pActorToAdd->GetTeam ()].sort (MOXPosComparison ());
1055
+ }
1056
+ }
1057
+
1058
+
1059
+ // ////////////////////////////////////////////////////////////////////////////////////////
1060
+ // Method: RemoveActorToTeamRoster
1061
+ // ////////////////////////////////////////////////////////////////////////////////////////
1062
+ // Description: Removes actor from internal team roster
1063
+ // Arguments: Pointer to actor
1064
+ // Return value: None.
1065
+
1066
+ void MovableMan::RemoveActorFromTeamRoster (Actor * pActorToRem)
1067
+ {
1068
+ if (!pActorToRem)
1069
+ return ;
1070
+
1071
+ int team = pActorToRem->GetTeam ();
1072
+
1073
+ // Remove from roster as well
1074
+ if (team >= Activity::TEAM_1 && team < Activity::MAXTEAMCOUNT)
1075
+ m_ActorRoster[team].remove (pActorToRem);
1076
+ }
1077
+
1078
+ // ////////////////////////////////////////////////////////////////////////////////////////
1079
+ // Method: ChangeActorTeam
1080
+ // ////////////////////////////////////////////////////////////////////////////////////////
1081
+ // Description: Changes actor team and updates team rosters.
1082
+
1083
+ void MovableMan::ChangeActorTeam (Actor * pActor, int team)
1084
+ {
1085
+ if (!pActor)
1086
+ return ;
1087
+
1088
+ RemoveActorFromTeamRoster (pActor);
1089
+ pActor->SetTeam (team);
1090
+ AddActorToTeamRoster (pActor);
1091
+ }
1092
+
1093
+
1042
1094
// ////////////////////////////////////////////////////////////////////////////////////////
1043
1095
// Method: RemoveParticle
1044
1096
// ////////////////////////////////////////////////////////////////////////////////////////
@@ -1813,8 +1865,9 @@ void MovableMan::Update()
1813
1865
else
1814
1866
{
1815
1867
// Also remove actor from the roster
1816
- if ((*aIt)->GetTeam () >= 0 )
1817
- m_ActorRoster[(*aIt)->GetTeam ()].remove (*aIt);
1868
+ if ((*aIt)->GetTeam () >= 0 )
1869
+ // m_ActorRoster[(*aIt)->GetTeam()].remove(*aIt);
1870
+ RemoveActorFromTeamRoster (*aIt);
1818
1871
delete (*aIt);
1819
1872
}
1820
1873
}
@@ -1870,7 +1923,8 @@ void MovableMan::Update()
1870
1923
// Remove from the team roster
1871
1924
1872
1925
if ((*aIt)->GetTeam () >= 0 )
1873
- m_ActorRoster[(*aIt)->GetTeam ()].remove (*aIt);
1926
+ // m_ActorRoster[(*aIt)->GetTeam()].remove(*aIt);
1927
+ RemoveActorFromTeamRoster (*aIt);
1874
1928
aIt++;
1875
1929
}
1876
1930
// Try to set the existing iterator to a safer value, erase can crash in debug mode otherwise?
@@ -1917,7 +1971,9 @@ void MovableMan::Update()
1917
1971
1918
1972
// Remove from team rosters
1919
1973
if ((*aIt)->GetTeam () >= Activity::TEAM_1 && (*aIt)->GetTeam () < Activity::MAXTEAMCOUNT)
1920
- m_ActorRoster[(*aIt)->GetTeam ()].remove (*aIt);
1974
+ // m_ActorRoster[(*aIt)->GetTeam()].remove(*aIt);
1975
+ RemoveActorFromTeamRoster (*aIt);
1976
+
1921
1977
// Delete
1922
1978
delete *aIt;
1923
1979
aIt++;
0 commit comments