//--------------------------------------------------------- //--------------------------------------------------------- void CNPC_Combine_Cannon::StartTask( const Task_t *pTask ) { switch( pTask->iTask ) { case TASK_CANNON_ATTACK_CURSOR: break; case TASK_RANGE_ATTACK1: // Setup the information for this barrage m_flBarrageDuration = gpGlobals->curtime + random->RandomFloat( 0.25f, 0.5f ); m_hBarrageTarget = GetEnemy(); break; case TASK_CANNON_PAINT_ENEMY: { if ( GetEnemy()->IsPlayer() ) { float delay = random->RandomFloat( 0.0f, 0.3f ); if ( ( gpGlobals->curtime - m_flTimeLastAttackedPlayer ) < 1.0f ) { SetWait( CANNON_SUBSEQUENT_PAINT_TIME ); m_flPaintTime = CANNON_SUBSEQUENT_PAINT_TIME; } else { SetWait( CANNON_PAINT_ENEMY_TIME + delay ); m_flPaintTime = CANNON_PAINT_ENEMY_TIME + delay; } } else { // Use a random time m_flPaintTime = CANNON_PAINT_ENEMY_TIME + random->RandomFloat( 0, CANNON_PAINT_NPC_TIME_NOISE ); SetWait( m_flPaintTime ); } // Try to start the laser where the player can't miss seeing it! Vector vecCursor; AngleVectors( GetEnemy()->GetLocalAngles(), &vecCursor ); vecCursor *= 300; vecCursor += GetEnemy()->EyePosition(); LaserOn( vecCursor, Vector( 16, 16, 16 ) ); } break; default: BaseClass::StartTask( pTask ); break; } }
bool CDeleteEntityAction::ActionPerformed(CEntity* pEntity) { CString command; CString results; bool bRes = false; if(CImpactAction::ActionPerformed(pEntity)==true) { CString kind = pEntity->GetKind(); kind.MakeLower(); CString id = PrepareQuery(pEntity->GetEtag()); SetWait(true); if ( kind == "package" ) { if(MessageBox(NULL,"Running impact queries on packages may take a long time.\nWould you like to proceed?", "QA Warning", MB_ICONQUESTION|MB_OKCANCEL)!=IDOK) { SetExecuted(false); bRes = false; return false; } command = "Impact:DeleteEntity " + id; } else if ( kind == "var" ) { command = "oo_member " + id; results = m_pCtrl->ExecCommand(command); if (results == "1") { command = "Impact:DeleteVariableFromClass " + id; } else { command = "Impact:DeleteVariable " + id + " [ where defined " + id + " ] "; } } else { command = "Impact:DeleteEntity " + id; } results = m_pCtrl->ExecPrint(command); ParseResult(results); bRes = true; SetWait(false); } SetExecuted(bRes); return bRes; }
int CRealControlSocket::Connect(const CServer &server) { SetWait(true); if (server.GetEncodingType() == ENCODING_CUSTOM) m_pCSConv = new wxCSConv(server.GetCustomEncoding()); if (m_pCurrentServer) delete m_pCurrentServer; m_pCurrentServer = new CServer(server); // International domain names m_pCurrentServer->SetHost(ConvertDomainName(server.GetHost()), server.GetPort()); return ContinueConnect(); }
int CRealControlSocket::Connect(const CServer &server) { SetWait(true); if (server.GetEncodingType() == ENCODING_CUSTOM) { LogMessage(MessageType::Debug_Info, _T("Using custom encoding: %s"), server.GetCustomEncoding()); m_pCSConv = new wxCSConv(server.GetCustomEncoding()); } delete m_pCurrentServer; m_pCurrentServer = new CServer(server); // International domain names m_pCurrentServer->SetHost(ConvertDomainName(server.GetHost()), server.GetPort()); return ContinueConnect(); }
bool CRealControlSocket::Send(const char *buffer, int len) { SetWait(true); if (m_pSendBuffer) { char *tmp = m_pSendBuffer; m_pSendBuffer = new char[m_nSendBufferLen + len]; memcpy(m_pSendBuffer, tmp, m_nSendBufferLen); memcpy(m_pSendBuffer + m_nSendBufferLen, buffer, len); m_nSendBufferLen += len; delete [] tmp; } else { int error; int written = m_pBackend->Write(buffer, len, error); if (written < 0) { if (error != EAGAIN) { LogMessage(MessageType::Error, _("Could not write to socket: %s"), CSocket::GetErrorDescription(error)); LogMessage(MessageType::Error, _("Disconnected from server")); DoClose(); return false; } written = 0; } if (written) m_pEngine->SetActive(CFileZillaEngine::send); if (written < len) { char *tmp = m_pSendBuffer; m_pSendBuffer = new char[m_nSendBufferLen + len - written]; memcpy(m_pSendBuffer, tmp, m_nSendBufferLen); memcpy(m_pSendBuffer + m_nSendBufferLen, buffer, len - written); m_nSendBufferLen += len - written; delete [] tmp; } } return true; }
bool CRealControlSocket::Send(const char *buffer, int len) { SetWait(true); if (m_pSendBuffer) { char *tmp = m_pSendBuffer; m_pSendBuffer = new char[m_nSendBufferLen + len]; memcpy(m_pSendBuffer, tmp, m_nSendBufferLen); memcpy(m_pSendBuffer + m_nSendBufferLen, buffer, len); m_nSendBufferLen += len; delete [] tmp; } else { m_pBackend->Write(buffer, len); int numsent = 0; if (m_pBackend->Error()) { if (m_pBackend->LastError() != wxSOCKET_WOULDBLOCK) { DoClose(); return false; } } else numsent = m_pBackend->LastCount(); if (numsent) m_pEngine->SetActive(false); if (numsent < len) { char *tmp = m_pSendBuffer; m_pSendBuffer = new char[m_nSendBufferLen + len - numsent]; memcpy(m_pSendBuffer, tmp, m_nSendBufferLen); memcpy(m_pSendBuffer + m_nSendBufferLen, buffer, len - numsent); m_nSendBufferLen += len - numsent; delete [] tmp; } } return true; }
int CRealControlSocket::Connect(const CServer &server) { SetWait(true); if (server.GetEncodingType() == ENCODING_CUSTOM) m_pCSConv = new wxCSConv(server.GetCustomEncoding()); if (m_pCurrentServer) delete m_pCurrentServer; m_pCurrentServer = new CServer(server); CConnectOpData* pData; if (!m_pCurOpData || m_pCurOpData->opId != cmd_connect) pData = 0; else pData = static_cast<CConnectOpData *>(m_pCurOpData); const wxString& host = pData ? pData->host : server.GetHost(); if (!IsIpAddress(host)) { LogMessage(Status, _("Resolving IP-Address for %s"), host.c_str()); CAsyncHostResolver *resolver = new CAsyncHostResolver(m_pEngine, ConvertDomainName(host)); m_pEngine->AddNewAsyncHostResolver(resolver); resolver->Create(); resolver->Run(); } else { wxIPV4address addr; addr.Hostname(host); return ContinueConnect(&addr); } return FZ_REPLY_WOULDBLOCK; }
int CControlSocket::ResetOperation(int nErrorCode) { LogMessage(MessageType::Debug_Verbose, _T("CControlSocket::ResetOperation(%d)"), nErrorCode); if (nErrorCode & FZ_REPLY_WOULDBLOCK) { LogMessage(MessageType::Debug_Warning, _T("ResetOperation with FZ_REPLY_WOULDBLOCK in nErrorCode (%d)"), nErrorCode); } if (m_pCurOpData && m_pCurOpData->holdsLock) UnlockCache(); if (m_pCurOpData && m_pCurOpData->pNextOpData) { COpData *pNext = m_pCurOpData->pNextOpData; m_pCurOpData->pNextOpData = 0; delete m_pCurOpData; m_pCurOpData = pNext; if (nErrorCode == FZ_REPLY_OK || nErrorCode == FZ_REPLY_ERROR || nErrorCode == FZ_REPLY_CRITICALERROR) { return ParseSubcommandResult(nErrorCode); } else return ResetOperation(nErrorCode); } wxString prefix; if ((nErrorCode & FZ_REPLY_CRITICALERROR) == FZ_REPLY_CRITICALERROR && (!m_pCurOpData || m_pCurOpData->opId != Command::transfer)) { prefix = _("Critical error:") + _T(" "); } if (m_pCurOpData) { const Command commandId = m_pCurOpData->opId; switch (commandId) { case Command::none: if( !prefix.empty() ) { LogMessage(MessageType::Error, _("Critical error")); } break; case Command::connect: if ((nErrorCode & FZ_REPLY_CANCELED) == FZ_REPLY_CANCELED) LogMessage(MessageType::Error, prefix + _("Connection attempt interrupted by user")); else if (nErrorCode != FZ_REPLY_OK) LogMessage(MessageType::Error, prefix + _("Could not connect to server")); break; case Command::list: if ((nErrorCode & FZ_REPLY_CANCELED) == FZ_REPLY_CANCELED) LogMessage(MessageType::Error, prefix + _("Directory listing aborted by user")); else if (nErrorCode != FZ_REPLY_OK) LogMessage(MessageType::Error, prefix + _("Failed to retrieve directory listing")); else { if (m_CurrentPath.empty()) { LogMessage(MessageType::Status, _("Directory listing successful")); } else { LogMessage(MessageType::Status, _("Directory listing of \"%s\" successful"), m_CurrentPath.GetPath()); } } break; case Command::transfer: { CFileTransferOpData *pData = static_cast<CFileTransferOpData *>(m_pCurOpData); if (!pData->download && pData->transferInitiated) { if (!m_pCurrentServer) LogMessage(__TFILE__, __LINE__, this, MessageType::Debug_Warning, _T("m_pCurrentServer is 0")); else { bool updated = engine_.GetDirectoryCache().UpdateFile(*m_pCurrentServer, pData->remotePath, pData->remoteFile, true, CDirectoryCache::file, (nErrorCode == FZ_REPLY_OK) ? pData->localFileSize : -1); if (updated) engine_.SendDirectoryListingNotification(pData->remotePath, false, true, false); } } LogTransferResultMessage(nErrorCode, pData); } break; default: if ((nErrorCode & FZ_REPLY_CANCELED) == FZ_REPLY_CANCELED) LogMessage(MessageType::Error, prefix + _("Interrupted by user")); break; } delete m_pCurOpData; m_pCurOpData = 0; } engine_.transfer_status_.Reset(); SetWait(false); if (m_invalidateCurrentPath) { m_CurrentPath.clear(); m_invalidateCurrentPath = false; } return engine_.ResetOperation(nErrorCode); }
int CControlSocket::ResetOperation(int nErrorCode) { LogMessage(Debug_Verbose, _T("CControlSocket::ResetOperation(%d)"), nErrorCode); if (nErrorCode & FZ_REPLY_WOULDBLOCK) { LogMessage(::Debug_Warning, _T("ResetOperation with FZ_REPLY_WOULDBLOCK in nErrorCode (%d)"), nErrorCode); } if (m_pCurOpData && m_pCurOpData->opId != cmd_rawtransfer) { UnlockCache(); } if (m_pCurOpData && m_pCurOpData->pNextOpData) { COpData *pNext = m_pCurOpData->pNextOpData; m_pCurOpData->pNextOpData = 0; delete m_pCurOpData; m_pCurOpData = pNext; if (nErrorCode == FZ_REPLY_OK || nErrorCode == FZ_REPLY_ERROR || nErrorCode == FZ_REPLY_CRITICALERROR) { return ParseSubcommandResult(nErrorCode); } else return ResetOperation(nErrorCode); } if ((nErrorCode & FZ_REPLY_CRITICALERROR) == FZ_REPLY_CRITICALERROR) LogMessage(::Error, _("Critical error")); if (m_pCurOpData) { const enum Command commandId = m_pCurOpData->opId; switch (commandId) { case cmd_none: break; case cmd_connect: if ((nErrorCode & FZ_REPLY_CANCELED) == FZ_REPLY_CANCELED) LogMessage(::Error, _("Connection attempt interrupted by user")); else if (nErrorCode != FZ_REPLY_OK) LogMessage(::Error, _("Could not connect to server")); break; case cmd_list: if ((nErrorCode & FZ_REPLY_CANCELED) == FZ_REPLY_CANCELED) LogMessage(::Error, _("Directory listing aborted by user")); else if (nErrorCode != FZ_REPLY_OK) LogMessage(::Error, _("Failed to retrieve directory listing")); else LogMessage(Status, _("Directory listing successful")); break; case cmd_transfer: { CFileTransferOpData *pData = static_cast<CFileTransferOpData *>(m_pCurOpData); if (!pData->download && pData->transferInitiated) { if (!m_pCurrentServer) LogMessage(__TFILE__, __LINE__, this, Debug_Warning, _T("m_pCurrentServer is 0")); else { CDirectoryCache cache; bool updated = cache.UpdateFile(*m_pCurrentServer, pData->remotePath, pData->remoteFile, true, CDirectoryCache::file, (nErrorCode == FZ_REPLY_OK) ? pData->localFileSize : -1); if (updated) m_pEngine->SendDirectoryListingNotification(pData->remotePath, false, true, false); } } if ((nErrorCode & FZ_REPLY_CANCELED) == FZ_REPLY_CANCELED) LogMessage(::Error, _("Transfer aborted by user")); else if (nErrorCode == FZ_REPLY_OK) LogMessage(Status, _("File transfer successful")); } break; default: if ((nErrorCode & FZ_REPLY_CANCELED) == FZ_REPLY_CANCELED) LogMessage(::Error, _("Interrupted by user")); break; } delete m_pCurOpData; m_pCurOpData = 0; } ResetTransferStatus(); SetWait(false); if (m_invalidateCurrentPath) { m_CurrentPath.Clear(); m_invalidateCurrentPath = false; } return m_pEngine->ResetOperation(nErrorCode); }
//========================================================= // start task //========================================================= void CNPC_Stalker::StartTask( const Task_t *pTask ) { switch ( pTask->iTask ) { case TASK_STALKER_SCREAM: { if( gpGlobals->curtime > m_flNextScreamTime ) { EmitSound( "NPC_Stalker.Scream" ); m_flNextScreamTime = gpGlobals->curtime + random->RandomFloat( 10.0, 15.0 ); } TaskComplete(); } case TASK_ANNOUNCE_ATTACK: { // If enemy isn't facing me and I haven't attacked in a while // annouce my attack before I start wailing away CBaseCombatCharacter *pBCC = GetEnemyCombatCharacterPointer(); if (pBCC && (!pBCC->FInViewCone ( this )) && (gpGlobals->curtime - m_flLastAttackTime > 1.0) ) { m_flLastAttackTime = gpGlobals->curtime; // Always play this sound EmitSound( "NPC_Stalker.Scream" ); m_flNextScrambleSoundTime = gpGlobals->curtime + 2; m_flNextBreatheSoundTime = gpGlobals->curtime + 2; // Wait two seconds SetWait( 2.0 ); SetActivity(ACT_IDLE); } break; } case TASK_STALKER_ZIGZAG: break; case TASK_RANGE_ATTACK1: { CBaseEntity *pEnemy = GetEnemy(); if (pEnemy) { m_vLaserTargetPos = GetEnemyLKP() + pEnemy->GetViewOffset(); // Never hit target on first try Vector missPos = m_vLaserTargetPos; if( pEnemy->Classify() == CLASS_BULLSEYE && hl2_episodic.GetBool() ) { missPos.x += 60 + 120*random->RandomInt(-1,1); missPos.y += 60 + 120*random->RandomInt(-1,1); } else { missPos.x += 80*random->RandomInt(-1,1); missPos.y += 80*random->RandomInt(-1,1); } // ---------------------------------------------------------------------- // If target is facing me and not running towards me shoot below his feet // so he can see the laser coming // ---------------------------------------------------------------------- CBaseCombatCharacter *pBCC = ToBaseCombatCharacter(pEnemy); if (pBCC) { Vector targetToMe = (pBCC->GetAbsOrigin() - GetAbsOrigin()); Vector vBCCFacing = pBCC->BodyDirection2D( ); if ((DotProduct(vBCCFacing,targetToMe) < 0) && (pBCC->GetSmoothedVelocity().Length() < 50)) { missPos.z -= 150; } // -------------------------------------------------------- // If facing away or running towards laser, // shoot above target's head // -------------------------------------------------------- else { missPos.z += 60; } } m_vLaserDir = missPos - LaserStartPosition(GetAbsOrigin()); VectorNormalize(m_vLaserDir); } else { TaskFail(FAIL_NO_ENEMY); return; } StartAttackBeam(); SetActivity(ACT_RANGE_ATTACK1); break; } case TASK_GET_PATH_TO_ENEMY_LOS: { if ( GetEnemy() != NULL ) { BaseClass:: StartTask( pTask ); return; } Vector posLos; if (GetTacticalServices()->FindLos(m_vLaserCurPos, m_vLaserCurPos, MIN_STALKER_FIRE_RANGE, MAX_STALKER_FIRE_RANGE, 1.0, &posLos)) { AI_NavGoal_t goal( posLos, ACT_RUN, AIN_HULL_TOLERANCE ); GetNavigator()->SetGoal( goal ); } else { TaskFail(FAIL_NO_SHOOT); } break; } case TASK_FACE_ENEMY: { if ( GetEnemy() != NULL ) { BaseClass:: StartTask( pTask ); return; } GetMotor()->SetIdealYawToTarget( m_vLaserCurPos ); break; } default: BaseClass:: StartTask( pTask ); break; } }
bool CAddBaseInterfaceAction::ActionPerformed(CEntity* pEntity) { CString command; CString results; bool bRes = false; if(CImpactAction::ActionPerformed(pEntity)==true) { SetWait(true); // lets get the implemented interfaces first command = "printformat \"%s\t%s\" etag kind;source_dis closure.dis;set IMPLEMENTED_INTERFACES [query_closure 50 \"get_super_classes\" " + PrepareQuery(pEntity->GetEtag()) + "]"; results=m_pCtrl->ExecCommand(command); results=m_pCtrl->ExecPrint(CString("print $IMPLEMENTED_INTERFACES")); CAttributesQueryResult* pImplemented = new CAttributesQueryResult(); pImplemented->parse(results); TActionDataList* pList = NULL; if(m_pHash==NULL || !m_pHash->Lookup(pEntity->GetEtag(),pList)) pList = NULL; // now get all available interfaces command = "printformat \"%s\t%s\" name etag;set DEFINED_INTERFACES [sort name [defines -interfaces /]]"; results=m_pCtrl->ExecCommand(command); results=m_pCtrl->ExecPrint(CString("print $DEFINED_INTERFACES")); CAttributesQueryResult* pAvailable = new CAttributesQueryResult(); pAvailable->parse(results); if(pAvailable->getRecordsCount()>0) { POSITION iter = pAvailable->getStartPos(); CAttributesQueryResult DeletedRecords; while(iter!=NULL) { TRecord* pRecord = pAvailable->getNext(iter); TField* field = (*pRecord)[1]; bool bImplemented = false; if(pList && pList->FindTag(*(*pRecord)[1])) bImplemented = true; if(pImplemented->contains(*field,0) || bImplemented) DeletedRecords.add(pRecord); } iter = DeletedRecords.getStartPos(); while(iter!=NULL) { TRecord* pRecord = DeletedRecords.getNext(iter); pAvailable->remove(pRecord); } } else { m_pCtrl->MessageBox("Nothing to implement.","Warning",MB_OK|MB_ICONWARNING); SetExecuted(false); bRes = false; return bRes; } delete pImplemented; SetWait(false); CSelectorDlg dlg(CString("Add Base Interface"),CString("Base Interface:"),m_pCtrl); dlg.SetQueryResults(pAvailable); int nRes = dlg.DoModal(); if(nRes == IDOK) { CString szInterfaceName = dlg.GetSelection(); CString szTag = dlg.GetSelectionTag(); CString description = GetName(); description += " " + szInterfaceName; SetDescription(description); command = "Impact:AddBaseInterface " + PrepareQuery(pEntity->GetEtag()) + " " + PrepareQuery(szTag); results = m_pCtrl->ExecPrint(command); ParseResult(results); if(m_pHash!=NULL) { if(pList == NULL) { pList = new TActionDataList(); (*m_pHash)[pEntity->GetEtag()] = pList; } CActionData* pData = new CActionData(new CString(pEntity->GetEtag()),new CString(szTag)); pList->AddTail(pData); SetData(pData); bRes = true; } else bRes = false; } delete pAvailable; } SetExecuted(bRes); return bRes; }
void CNPCSimpleTalker::StartTask( const Task_t *pTask ) { switch ( pTask->iTask ) { case TASK_TALKER_WAIT_FOR_SEMAPHORE: if ( GetExpresser()->SemaphoreIsAvailable( this ) ) TaskComplete(); break; case TASK_TALKER_SPEAK: // ask question or make statement FIdleSpeak(); TaskComplete(); break; case TASK_TALKER_RESPOND: // respond to question IdleRespond(); TaskComplete(); break; case TASK_TALKER_HELLO: // greet player FIdleHello(); TaskComplete(); break; case TASK_TALKER_STARE: // let the player know I know he's staring at me. FIdleStare(); TaskComplete(); break; case TASK_TALKER_LOOK_AT_CLIENT: case TASK_TALKER_CLIENT_STARE: // track head to the client for a while. SetWait( pTask->flTaskData ); break; case TASK_TALKER_EYECONTACT: break; case TASK_TALKER_IDEALYAW: if (GetSpeechTarget() != NULL) { GetMotor()->SetIdealYawToTarget( GetSpeechTarget()->GetAbsOrigin() ); } TaskComplete(); break; case TASK_TALKER_HEADRESET: // reset head position after looking at something SetSpeechTarget( NULL ); TaskComplete(); break; case TASK_TALKER_BETRAYED: Speak( TLK_BETRAYED ); TaskComplete(); break; case TASK_TALKER_STOPSHOOTING: // tell player to stop shooting Speak( TLK_NOSHOOT ); TaskComplete(); break; default: BaseClass::StartTask( pTask ); } }