double Snow::GetLife() { double timePassed = GetNetworkTime() - m_timeSync; double life = timePassed / 10.0; life = min( life, 1.0 ); return life; }
bool SafeArea::Advance() { // // Is the world awake yet ? if( !g_app->m_location ) return false; if( !g_app->m_location->m_teams ) return false; if( g_app->m_location->m_teams[ m_id.GetTeamId() ]->m_teamType == TeamTypeUnused ) return false; if( GetNetworkTime() > m_recountTimer ) { int numFound; g_app->m_location->m_entityGrid->GetFriends( s_neighbours, m_pos.x, m_pos.z, m_size, &numFound, m_id.GetTeamId() ); m_entitiesCounted = 0; for( int i = 0; i < numFound; ++i ) { WorldObjectId id = s_neighbours[i]; Entity *entity = g_app->m_location->GetEntity( id ); if( entity && entity->m_type == m_entityTypeRequired && !entity->m_dead ) { ++m_entitiesCounted; } } m_recountTimer = GetNetworkTime() + 2.0; if( (m_id.GetTeamId() == 1 && m_entitiesCounted <= m_entitiesRequired) || (m_id.GetTeamId() != 1 && m_entitiesCounted >= m_entitiesRequired) ) { GlobalBuilding *gb = g_app->m_globalWorld->GetBuilding( m_id.GetUniqueId(), g_app->m_locationId ); if( gb && !gb->m_online ) { gb->m_online = true; g_app->m_globalWorld->EvaluateEvents(); } } } return false; }
Snow::Snow() : WorldObject() { m_positionOffset = syncfrand(10.0); m_xaxisRate = syncfrand(2.0); m_yaxisRate = syncfrand(2.0); m_zaxisRate = syncfrand(2.0); m_timeSync = GetNetworkTime(); m_type = EffectSnow; }
bool SoulDestroyer::AdvanceToTargetPosition() { double amountToTurn = SERVER_ADVANCE_PERIOD * 2.0; Vector3 targetDir = (m_targetPos - m_pos).Normalise(); if( !m_targetEntity.IsValid() ) { Vector3 right1 = m_front ^ m_up; targetDir.RotateAround( right1 * iv_sin(GetNetworkTime() * 6.0) * 1.5 ); } // Look ahead to see if we're about to hit the ground Vector3 forwardPos = m_pos + targetDir * 50.0; double landHeight = g_app->m_location->m_landscape.m_heightMap->GetValue(forwardPos.x, forwardPos.z); if( forwardPos.y <= landHeight ) { targetDir = g_upVector; } Vector3 actualDir = m_front * (1.0 - amountToTurn) + targetDir * amountToTurn; actualDir.Normalise(); double speed = m_stats[StatSpeed]; speed = 130.0; Vector3 oldPos = m_pos; Vector3 newPos = m_pos + actualDir * speed * SERVER_ADVANCE_PERIOD; landHeight = g_app->m_location->m_landscape.m_heightMap->GetValue( newPos.x, newPos.z ); //newPos.y = max( newPos.y, landHeight ); Vector3 moved = newPos - oldPos; if( moved.Mag() > speed * SERVER_ADVANCE_PERIOD ) moved.SetLength( speed * SERVER_ADVANCE_PERIOD ); newPos = m_pos + moved; m_pos = newPos; m_vel = ( m_pos - oldPos ) / SERVER_ADVANCE_PERIOD; m_front = actualDir; Vector3 right = m_front ^ g_upVector; m_up = right ^ m_front; return ( m_pos - m_targetPos ).Mag() < 40.0; }
void CFginstDlg::OnTimer(UINT nIDEvent) { #ifdef _DEBUG // if(101 == nIDEvent){ // //Test network // KillTimer(nIDEvent); // // CString config_host; // INTERNET_PORT config_port; // CString config_obj; // DWORD service; // if (!AfxParseURL("http://wikifortio.com/414870/", service, config_host, config_obj, config_port)) // return ; // // char* buf; // int bufLen; // DWORD code; // unsigned long fsize = 0; // // CString csNewURL = ""; // if (!DownloadUrl_wiki(config_host, config_port, config_obj, csNewURL, FileDownloadCookie)) { // FileDownloadCookie = ""; // return ; // } // // if (!AfxParseURL(csNewURL, service, config_host, config_obj, config_port)) // return ; // // fsize = 0; // BOOL re = MDownloadUrl(config_host, config_port, config_obj, fsize, "c:\\111.zip", 5); // // // } #endif if(1 == nIDEvent) { //Test network KillTimer(nIDEvent); if(GetNetworkTime()) { ShowText("下载中,请稍候..."); AfxBeginThread(_DownloadThread, this); SetTimer(2, 200, NULL); } else { ShowText("网络错误,请稍后重试。"); } } if (2 == nIDEvent) { long FielLength = DownloadRange.DownloadRangeFileInfo.nFileLength; if(FielLength > 0) { long FinshedLength = 0; for(int i=0; i<MAXBLOCKNUMBER; i++) { FinshedLength += DownloadRange.DownloadRangeFileInfo.nFinishedLength[i]; } CString str; str.Format("%d%%", FinshedLength * 100 / FielLength); SetDlgItemText(IDC_PROGRESS_TEXT, str); m_Progress.SetPos(FinshedLength * 100 / FielLength); if(FinshedLength == FielLength) { KillTimer(2); ShowText("下载完成,文件处理中..."); } } } if(3 == nIDEvent) { // OK KillTimer(nIDEvent); ShowText("下载成功!文件在你的桌面上。"); CString str; str.Format("下载成功,文件位置为: %s。请问立即执行该软件吗?", sFilePath); if(MessageBox(str, "提示", MB_ICONQUESTION|MB_YESNO) == IDYES) { WinExec(sFilePath, SW_SHOW); } } if(4 == nIDEvent) { //FAIL KillTimer(nIDEvent); ShowText("下载失败,请重试。"); } if (5 == nIDEvent) { long FielLength = DownloadRange.DownloadRangeFileInfo.nFileLength; if(FielLength > 0) { long FinshedLength = 0; for(int i=0; i<MAXBLOCKNUMBER; i++) { FinshedLength += DownloadRange.DownloadRangeFileInfo.nFinishedLength[i]; } CString str; str.Format("%d%%", FinshedLength * 100 / FielLength); SetDlgItemText(IDC_PROGRESS_TEXT, str); m_Progress.SetPos(FinshedLength * 100 / FielLength); } } if(9 == nIDEvent) { KillTimer(nIDEvent); DownloadRange.DownloadRangeFileInfo.nFileLength = 0; SetDlgItemText(IDC_PROGRESS_TEXT, "0%"); m_Progress.SetPos(0); } CDialog::OnTimer(nIDEvent); }
bool DustBall::Advance() { double speed = DUSTBALL_SPEED; if( s_vortexPos != g_zeroVector ) { /*double speed = DUSTBALL_SPEED / 5.0; speed /= (m_pos.y / 1000.0); speed = max( speed, 100.0 ); speed = min( speed, 500.0 ); Vector3 thisVortexPos = s_vortexPos; thisVortexPos.y = m_pos.y; Vector3 oldPos = m_pos; double amountToTurn = SERVER_ADVANCE_PERIOD * (1.0 / (m_pos.y / 1000.0)); Vector3 targetDir = (thisVortexPos - m_pos).Normalise(); Vector3 actualDir = m_vel.Normalise() * (1.0 - amountToTurn) + targetDir * amountToTurn; actualDir.Normalise(); Vector3 newPos = m_pos + actualDir * speed * SERVER_ADVANCE_PERIOD; Vector3 moved = newPos - oldPos; if( moved.Mag() > speed * SERVER_ADVANCE_PERIOD ) moved.SetLength( speed * SERVER_ADVANCE_PERIOD ); newPos = m_pos + moved;*/ Vector3 vortexPos = s_vortexPos; double timeIndex = GetNetworkTime() + m_id.GetUniqueId() * 20; double radius = (300.0 * (m_pos.y / 1000.0) ); Vector3 targetPos = vortexPos; targetPos.x += iv_cos( timeIndex ) * radius; targetPos.z += iv_sin( timeIndex ) * radius; targetPos.y = m_pos.y; Vector3 oldPos = m_pos; Vector3 actualDir = (targetPos - m_pos).Normalise(); Vector3 newPos = m_pos + (actualDir * speed * SERVER_ADVANCE_PERIOD); Vector3 moved = newPos - oldPos; if( moved.Mag() > speed * SERVER_ADVANCE_PERIOD ) moved.SetLength( speed * SERVER_ADVANCE_PERIOD ); m_pos = newPos; m_vel = ( m_pos - oldPos ) / SERVER_ADVANCE_PERIOD; } else { Vector3 oldPos = m_pos; Vector3 target = m_pos + g_app->m_location->m_windDirection * 2000.0; double amountToTurn = SERVER_ADVANCE_PERIOD * 3.0; Vector3 targetDir = (target - m_pos).Normalise(); Vector3 actualDir = m_vel.Normalise() * (1.0 - amountToTurn) + targetDir * amountToTurn; actualDir.Normalise(); Vector3 newPos = m_pos + actualDir * speed * SERVER_ADVANCE_PERIOD; Vector3 moved = newPos - oldPos; if( moved.Mag() > speed * SERVER_ADVANCE_PERIOD ) moved.SetLength( speed * SERVER_ADVANCE_PERIOD ); newPos = m_pos + moved; m_pos = newPos; m_vel = ( m_pos - oldPos ) / SERVER_ADVANCE_PERIOD; } if( m_pos.x > g_app->m_location->m_landscape.GetWorldSizeX() || m_pos.z > g_app->m_location->m_landscape.GetWorldSizeZ() || m_pos.x < 0.0 || m_pos.z < 0.0 ) { return true; } return false; }
void ANTPlayerController::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); AccumulativeDeltaTime += DeltaSeconds; // If we're the Client and we haven't updated Ping in a while, try to get a ping update const float LocTimeSec = GetWorld()->GetTimeSeconds(); if (((LocTimeSec - LastPingCalcTime) > 0.5f) && (GetNetMode() == NM_Client)) { LastPingCalcTime = LocTimeSec; ServerBouncePing(LocTimeSec); } if (PlayerState) { if (Role == ROLE_Authority && !IsLocalController()) { GEngine->AddOnScreenDebugMessage(-1, DeltaSeconds, FColor::Blue, FString::Printf(TEXT("Server Ping %f - TimeStamp %i"), PlayerState->ExactPing, GetLocalTime())); } else if (Role < ROLE_Authority) { GEngine->AddOnScreenDebugMessage(-1, DeltaSeconds, FColor::Green, FString::Printf(TEXT("Client Ping %f - TimeStamp %i"), PlayerState->ExactPing, GetNetworkTime())); } } }