void CPlayer::StartControllingUnit() { CUnit* curControlleeUnit = fpsController.GetControllee(); CUnit* newControlleeUnit = NULL; if (curControlleeUnit != NULL) { // player released control StopControllingUnit(); } else { // player took control const std::vector<int>& ourSelectedUnits = selectedUnitsHandler.netSelected[this->playerNum]; if (ourSelectedUnits.empty()) { return; } // pick the first unit we have selected newControlleeUnit = unitHandler->GetUnit(ourSelectedUnits[0]); if (newControlleeUnit == NULL || newControlleeUnit->weapons.empty()) { return; } if (newControlleeUnit->fpsControlPlayer != NULL) { if (this->playerNum == gu->myPlayerNum) { LOG_L(L_WARNING, "player %d (%s) is already controlling unit %d", newControlleeUnit->fpsControlPlayer->playerNum, newControlleeUnit->fpsControlPlayer->name.c_str(), newControlleeUnit->id); } return; } if (eventHandler.AllowDirectUnitControl(this->playerNum, newControlleeUnit)) { newControlleeUnit->fpsControlPlayer = this; fpsController.SetControlleeUnit(newControlleeUnit); selectedUnitsHandler.ClearNetSelect(this->playerNum); if (this->playerNum == gu->myPlayerNum) { // update the unsynced state selectedUnitsHandler.ClearSelected(); gu->fpsMode = true; mouse->wasLocked = mouse->locked; if (!mouse->locked) { mouse->locked = true; mouse->HideMouse(); } camHandler->PushMode(); camHandler->SetCameraMode(0); } } } }
void CPlayer::StartSpectating() { if (spectator) { return; } spectator = true; if (gu->myPlayerNum == this->playerNum) { // HACK: unsynced code should just listen for the PlayerChanged event gu->spectating = true; gu->spectatingFullView = true; gu->spectatingFullSelect = true; CLuaUI::UpdateTeams(); selectedUnits.ClearSelected(); unitTracker.Disable(); } StopControllingUnit(); eventHandler.PlayerChanged(playerNum); }