void Transport::UpdatePosition(float x, float y, float z, float o) { bool newActive = GetMap()->IsGridLoaded(x, y); Cell oldCell(GetPositionX(), GetPositionY()); Relocate(x, y, z, o); m_stationaryPosition.SetOrientation(o); UpdateModelPosition(); UpdatePassengerPositions(_passengers); /* There are four possible scenarios that trigger loading/unloading passengers: 1. transport moves from inactive to active grid 2. the grid that transport is currently in becomes active 3. transport moves from active to inactive grid 4. the grid that transport is currently in unloads */ if (_staticPassengers.empty() && newActive) // 1. LoadStaticPassengers(); else if (!_staticPassengers.empty() && !newActive && oldCell.DiffGrid(Cell(GetPositionX(), GetPositionY()))) // 3. UnloadStaticPassengers(); else UpdatePassengerPositions(_staticPassengers); // 4. is handed by grid unload }
void Transport::UpdatePosition(MovementInfo* mi) { float transport_o = mi->pos.GetOrientation() - mi->transport.pos.GetOrientation(); float transport_x = mi->pos.m_positionX - (mi->transport.pos.m_positionX * std::cos(transport_o) - mi->transport.pos.m_positionY * std::sin(transport_o)); float transport_y = mi->pos.m_positionY - (mi->transport.pos.m_positionY * std::cos(transport_o) + mi->transport.pos.m_positionX * std::sin(transport_o)); float transport_z = mi->pos.m_positionZ - mi->transport.pos.m_positionZ; Relocate(transport_x, transport_y, transport_z, transport_o); UpdatePassengerPositions(); }
void Transport::Update(uint32 p_diff) { if (!AI()) { if (!AIM_Initialize()) TC_LOG_ERROR(LOG_FILTER_TRANSPORTS, "Could not initialize GameObjectAI for Transport"); } else AI()->UpdateAI(p_diff); if (m_WayPoints.size() <= 1) return; m_timer = getMSTime() % m_period; while (((m_timer - m_curr->first) % m_pathTime) > ((m_next->first - m_curr->first) % m_pathTime)) { DoEventIfAny(*m_curr, true); m_curr = GetNextWayPoint(); m_next = GetNextWayPoint(); DoEventIfAny(*m_curr, false); // first check help in case client-server transport coordinates de-synchronization if (m_curr->second.mapid != GetMapId() || m_curr->second.teleport) { TeleportTransport(m_curr->second.mapid, m_curr->second.x, m_curr->second.y, m_curr->second.z); } else { Relocate(m_curr->second.x, m_curr->second.y, m_curr->second.z, GetAngle(m_next->second.x, m_next->second.y) + float(M_PI)); UpdatePassengerPositions(); // COME BACK MARKER // This forces the server to update positions in transportation for players -- gunship UpdatePlayerPositions(); } sScriptMgr->OnRelocate(this, m_curr->first, m_curr->second.mapid, m_curr->second.x, m_curr->second.y, m_curr->second.z); m_nextNodeTime = m_curr->first; if (m_curr == m_WayPoints.begin()) TC_LOG_DEBUG(LOG_FILTER_TRANSPORTS, " ************ BEGIN ************** %s", m_name.c_str()); TC_LOG_DEBUG(LOG_FILTER_TRANSPORTS, "%s moved to %d %f %f %f %d", m_name.c_str(), m_curr->second.id, m_curr->second.x, m_curr->second.y, m_curr->second.z, m_curr->second.mapid); } sScriptMgr->OnTransportUpdate(this, p_diff); }
void Transport::Update(uint32 diff) { if (!AI()) { if (!AIM_Initialize()) sLog->outError("Could not initialize GameObjectAI for Transport"); } else AI()->UpdateAI(diff); if (_isStopped) return; if (GetKeyFrames().size() <= 1) return; //_moveTimer = getMSTime() % _transportInfo->pathTime; _moveTimer += diff; _moveTimer %= _transportInfo->pathTime; // need restart path from beginning /* if (m_timer < m_curr->pathTime) { m_curr = keyFrames.begin(); m_next = m_curr + 1; } */ while (_moveTimer > _nextFrame->pathTime || _moveTimer < _currentFrame->departureTime) { // arrived at next stop point if (_transportInfo->pathTime > _nextFrame->pathTime && _moveTimer < _nextFrame->departureTime) { if (IsMoving()) { SetMoving(false); DoEventIfAny(*_currentFrame, false); } break; } MoveToNextWayPoint(); SetMoving(true); DoEventIfAny(*_currentFrame, true); // first check help in case client-server transport coordinates de-synchronization if (_currentFrame->IsTeleportFrame()) TeleportTransport(_nextFrame->node->mapid, _nextFrame->node->x, _nextFrame->node->y, _nextFrame->node->z); ASSERT(_nextFrame != GetKeyFrames().begin()); sScriptMgr->OnRelocate(this, _currentFrame->node->index, _currentFrame->node->mapid, _currentFrame->node->x, _currentFrame->node->y, _currentFrame->node->z); sLog->outDebug(LOG_FILTER_TRANSPORTS, "%s moved to %f %f %f %d", GetName(), GetPositionX(), GetPositionY(), GetPositionZ(), _currentFrame->node->mapid); } if (IsMoving()) { if (_moveTimer < _currentFrame->departureTime || _moveTimer > _nextFrame->pathTime) sLog->outError("strange times, c.dep:%u, n.pt:%u (%s, %u)", _currentFrame->departureTime, _nextFrame->pathTime, GetName(), m_goInfo->moTransport.mapID); float t = CalculateSegmentPos((float)_moveTimer/(float)IN_MILLISECONDS); //if (t < -0.01f || t > 1.01f) // sLog.outError("strange t=%f (%s, %u)", t, GetName(), m_goInfo->moTransport.mapID); //G3D::Vector3 pos; //m_spline->Evaluate(m_curr->node->index - 1, t, pos); //G3D::Vector3 dir; //m_spline->EvaluateDerivative(m_curr->node->index - 1, t, dir); //dir.z = 0.0f; //dir = -dir.direction(); //Relocate(pos.x, pos.y, pos.z); float x = _currentFrame->node->x * (1.0f - t) + _nextFrame->node->x * t; float y = _currentFrame->node->y * (1.0f - t) + _nextFrame->node->y * t; float z = _currentFrame->node->z * (1.0f - t) + _nextFrame->node->z * t; float o = GetAngle(_nextFrame->node->x, _nextFrame->node->y) + float(M_PI); Relocate(x, y, z, o); UpdatePassengerPositions(); } sScriptMgr->OnTransportUpdate(this, diff); }