Skip to content

Commit 4c785f3

Browse files
committed
MovableMan::ChangeActorTeam(actor, team)
1 parent 360352b commit 4c785f3

File tree

4 files changed

+110
-19
lines changed

4 files changed

+110
-19
lines changed

B33_ChangeLog.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,4 +636,8 @@
636636
Collection Presets // List of all presets in the data module. Contains Entity objects, so you'll have to up-cast to get most of the properties
637637
Prop FileName, r/o // Module file name, like Base.rte
638638
Prop FriendlyName, r/o // Module friendly name, like Dummy Tech
639-
639+
640+
30.06.2019
641+
Lua:
642+
MovableMan:
643+
Func ChangeActorTeam(actor, team) // Change actor team and update team rosters properly. Remember to switch actor manually if it's player controlled

Managers/LuaMan.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,8 @@ int LuaMan::Create()
21472147
.property("MaxDroppedItems", &MovableMan::GetMaxDroppedItems, &MovableMan::SetMaxDroppedItems)
21482148
.property("ScriptedEntity", &MovableMan::GetScriptedEntity, &MovableMan::SetScriptedEntity)
21492149
.def("SortTeamRoster", &MovableMan::SortTeamRoster)
2150-
.def("AddMO", &AddMO, adopt(_2))
2150+
.def("ChangeActorTeam", &MovableMan::ChangeActorTeam)
2151+
.def("AddMO", &AddMO, adopt(_2))
21512152
.def("AddActor", &AddActor, adopt(_2))
21522153
.def("AddItem", &AddItem, adopt(_2))
21532154
.def("AddParticle", &AddParticle, adopt(_2))

Managers/MovableMan.cpp

Lines changed: 73 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -869,16 +869,8 @@ void MovableMan::AddActor(Actor *pActorToAdd)
869869
pActorToAdd->SetAge(0);
870870
}
871871
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);
882874
}
883875
}
884876

@@ -991,9 +983,7 @@ bool MovableMan::RemoveActor(MovableObject *pActorToRem)
991983
}
992984
}
993985
}
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));
997987
}
998988
return removed;
999989
}
@@ -1039,6 +1029,68 @@ bool MovableMan::RemoveItem(MovableObject *pItemToRem)
10391029
}
10401030

10411031

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+
10421094
//////////////////////////////////////////////////////////////////////////////////////////
10431095
// Method: RemoveParticle
10441096
//////////////////////////////////////////////////////////////////////////////////////////
@@ -1813,8 +1865,9 @@ void MovableMan::Update()
18131865
else
18141866
{
18151867
// 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);
18181871
delete (*aIt);
18191872
}
18201873
}
@@ -1870,7 +1923,8 @@ void MovableMan::Update()
18701923
// Remove from the team roster
18711924

18721925
if ((*aIt)->GetTeam() >= 0)
1873-
m_ActorRoster[(*aIt)->GetTeam()].remove(*aIt);
1926+
//m_ActorRoster[(*aIt)->GetTeam()].remove(*aIt);
1927+
RemoveActorFromTeamRoster(*aIt);
18741928
aIt++;
18751929
}
18761930
// Try to set the existing iterator to a safer value, erase can crash in debug mode otherwise?
@@ -1917,7 +1971,9 @@ void MovableMan::Update()
19171971

19181972
// Remove from team rosters
19191973
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+
19211977
// Delete
19221978
delete *aIt;
19231979
aIt++;

Managers/MovableMan.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,36 @@ class MovableMan:
611611
bool RemoveParticle(MovableObject *pMOToRem);
612612

613613

614+
//////////////////////////////////////////////////////////////////////////////////////////
615+
// Method: ChangeActorTeam
616+
//////////////////////////////////////////////////////////////////////////////////////////
617+
// Description: Changes actor team and updates team rosters.
618+
// Arguments: Pointer to actor, new team value
619+
// Return value: None.
620+
621+
void ChangeActorTeam(Actor * pActor, int team);
622+
623+
624+
//////////////////////////////////////////////////////////////////////////////////////////
625+
// Method: AddActorToTeamRoster
626+
//////////////////////////////////////////////////////////////////////////////////////////
627+
// Description: Adds actor to internal team roster
628+
// Arguments: Pointer to actor
629+
// Return value: None.
630+
631+
void AddActorToTeamRoster(Actor * pActorToAdd);
632+
633+
634+
//////////////////////////////////////////////////////////////////////////////////////////
635+
// Method: RemoveActorToTeamRoster
636+
//////////////////////////////////////////////////////////////////////////////////////////
637+
// Description: Removes actor from internal team roster
638+
// Arguments: Pointer to actor
639+
// Return value: None.
640+
641+
void RemoveActorFromTeamRoster(Actor * pActorToRem);
642+
643+
614644
//////////////////////////////////////////////////////////////////////////////////////////
615645
// Method: ValidateMOIDs
616646
//////////////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)