Exemplo n.º 1
0
bool
DeviceDescriptor::Declare(const struct Declaration &declaration,
                          const Waypoint *home,
                          OperationEnvironment &env)
{
  if (port == NULL)
    return false;

  SetBusy(true);

  StaticString<60> text;
  text.Format(_T("%s: %s."), _("Sending declaration"), driver->display_name);
  env.SetText(text);

  port->StopRxThread();

  bool result = device != NULL && device->Declare(declaration, home, env);

  if (device_blackboard->IsFLARM(index) && !IsDriver(_T("FLARM"))) {
    text.Format(_T("%s: FLARM."), _("Sending declaration"));
    env.SetText(text);
    FlarmDevice flarm(*port);
    result = flarm.Declare(declaration, home, env) || result;
  }

  port->StartRxThread();

  SetBusy(false);
  return result;
}
Exemplo n.º 2
0
BOOL CMeterReader::OnActiveThread()
{
    if (IsBusyCoreService()) return TRUE;

	SetBusy(TRUE);
	MeterReaderWorker();
	SetBusy(FALSE);
	
	return TRUE;
}
Exemplo n.º 3
0
//------------------------------------------------------------------------
void CItemScheduler::Reset(bool keepPersistent)
{
	for (TTimerActionVector::iterator it = m_timers.begin(); it != m_timers.end();)
	{
		if (!it->persist || !keepPersistent)
		{
			it->action->destroy();
			it = m_timers.erase(it);
		}
		else
			it++;
	}

	for (TScheduledActionVector::iterator it = m_schedule.begin(); it != m_schedule.end();)
	{
		if (!it->persist || !keepPersistent)
		{
			it->action->destroy();
			it = m_schedule.erase(it);
		}
		else
			it++;
	}

	if (m_timers.empty() && m_schedule.empty())
		m_pItem->EnableUpdate(false, eIUS_Scheduler);

  SetBusy(false);
}
Exemplo n.º 4
0
//
/// Stops the MCI device and closes it.
//
uint32
TMci::Close()
{
  SetBusy(false);
  Stop(MCI_WAIT);
  return SendCommand(MCI_CLOSE, MCI_WAIT, 0);
}
Exemplo n.º 5
0
CCompressionProcessor::EStatus CZipDecompressor::Init(void)
{
    // Initialize members
    Reset();
    SetBusy();
    m_NeedCheckHeader = true;
    m_IsGZ = false;
    m_SkipInput = 0;
    m_Cache.erase();
    m_Cache.reserve(kMaxHeaderSize);

    // Initialize the compressor stream structure
    memset(STREAM, 0, sizeof(z_stream));
    // Create a compressor stream
    int errcode = inflateInit2_(STREAM, m_WindowBits,
                                ZLIB_VERSION, (int)sizeof(z_stream));

    SetError(errcode, zError(errcode));

    if ( errcode == Z_OK ) {
        return eStatus_Success;
    }
    ERR_COMPRESS(68, FormatErrorMessage("CZipDecompressor::Init", GetProcessedSize()));
    return eStatus_Error;
}
Exemplo n.º 6
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CAI_FuncTankBehavior::Dismount( void )
{
	SetBusy( gpGlobals->curtime + AI_FUNCTANK_BEHAVIOR_BUSYTIME );

	Assert( m_hFuncTank );

	if ( m_hFuncTank )
	{
		GetOuter()->SpeakSentence( FUNCTANK_SENTENCE_DISMOUNTING );

		Assert( m_hFuncTank->IsMarkedForDeletion() || m_hFuncTank->GetController() == GetOuter() );
		
		m_hFuncTank->NPC_SetInRoute( false );
		if ( m_hFuncTank->GetController() == GetOuter() )
			m_hFuncTank->StopControl();
		SetFuncTank( NULL );
	}

	GetOuter()->SetDesiredWeaponState( DESIREDWEAPONSTATE_UNHOLSTERED );

	m_bMounted = false;

	// Set this condition to force breakout of any func_tank behavior schedules
	SetCondition( COND_FUNCTANK_DISMOUNT );
}
Exemplo n.º 7
0
CCompressionProcessor::EStatus CZipCompressor::Init(void)
{
    if ( IsBusy() ) {
        // Abnormal previous session termination
        End();
    }
    // Initialize members
    Reset();
    SetBusy();

    m_CRC32 = 0;
    m_NeedWriteHeader = true;
    m_Cache.erase();

    // Initialize the compressor stream structure
    memset(STREAM, 0, sizeof(z_stream));
    // Create a compressor stream
    int errcode = deflateInit2_(STREAM, GetLevel(), Z_DEFLATED,
                                F_ISSET(fWriteGZipFormat) ? -m_WindowBits :
                                m_WindowBits,
                                m_MemLevel, m_Strategy,
                                ZLIB_VERSION, (int)sizeof(z_stream));
    SetError(errcode, zError(errcode));
    if ( errcode == Z_OK ) {
        return eStatus_Success;
    }
    ERR_COMPRESS(60, FormatErrorMessage("CZipCompressor::Init", GetProcessedSize()));
    return eStatus_Error;
}
Exemplo n.º 8
0
status_t
Interface::_SetUp()
{
	status_t status = up_device_interface(fDeviceInterface);
	if (status != B_OK)
		return status;

	RecursiveLocker interfacesLocker(sLock);
	SetBusy(true);
	interfacesLocker.Unlock();

	// Propagate flag to all datalink protocols
	DatalinkTable::Iterator iterator = fDatalinkTable.GetIterator();
	while (domain_datalink* datalink = iterator.Next()) {
		status = datalink->first_info->interface_up(datalink->first_protocol);
		if (status != B_OK) {
			// Revert "up" status
			DatalinkTable::Iterator secondIterator
				= fDatalinkTable.GetIterator();
			while (secondIterator.HasNext()) {
				domain_datalink* secondDatalink = secondIterator.Next();
				if (secondDatalink == NULL || secondDatalink == datalink)
					break;

				secondDatalink->first_info->interface_down(
					secondDatalink->first_protocol);
			}

			down_device_interface(fDeviceInterface);
			SetBusy(false);
			return status;
		}
	}

	// Add default routes for the existing addresses

	AddressList::Iterator addressIterator = fAddresses.GetIterator();
	while (InterfaceAddress* address = addressIterator.Next()) {
		address->AddDefaultRoutes(SIOCSIFADDR);
	}

	flags |= IFF_UP;
	SetBusy(false);

	return B_OK;
}
void AsyncExeCmd::Execute(const wxString &cmdLine)
{
	m_cmdLine = cmdLine;
	SetBusy(true);
	SendStartMsg();

	m_proc = new clProcess(wxNewId(), m_cmdLine);
	if(m_proc){
		if(m_proc->Start(false) == 0){
			delete m_proc;
			m_proc = NULL;
			SetBusy(false);
		}else{
			Connect(wxEVT_TIMER, wxTimerEventHandler(AsyncExeCmd::OnTimer), NULL, this);
			m_timer->Start(10);
		}
	}
}
void QBtServiceDiscovererPrivate::Construct()
{
	InitBthSdk();

	connect(p_ptr, SIGNAL(discoveryStarted()), 
			this, SLOT(SetBusy()));
	connect(p_ptr, SIGNAL(discoveryStopped()),
			this, SLOT(SetNotBusy()));
}
Exemplo n.º 11
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CAI_FuncTankBehavior::SetFuncTank( CHandle<CFuncTank> hFuncTank )			
{ 
	if ( m_hFuncTank && !hFuncTank )
	{
		SetBusy( gpGlobals->curtime + AI_FUNCTANK_BEHAVIOR_BUSYTIME );
		SetCondition( COND_FUNCTANK_DISMOUNT );
	}

	m_hFuncTank = hFuncTank; 
	GetOuter()->ClearSchedule();
}
Exemplo n.º 12
0
CCompressionProcessor::EStatus CZipDecompressor::End(int abandon)
{
    int errcode = inflateEnd(STREAM);
    SetBusy(false);
    if ( abandon ||
            m_DecompressMode == eMode_TransparentRead   ||
            errcode == Z_OK ) {
        return eStatus_Success;
    }
    ERR_COMPRESS(71, FormatErrorMessage("CZipDecompressor::End", GetProcessedSize()));
    return eStatus_Error;
}
Exemplo n.º 13
0
//
/// Resumes playing of the MCI device.
//
uint32
TMci::Resume(uint32 flags)
{
  SetBusy(false);
  MCI_GENERIC_PARMS parms;

  if (flags & MCI_NOTIFY)
    parms.dwCallback = GetCallback();

  uint32 retVal = SendCommand(MCI_RESUME, flags, (uint32)(void *)&parms);
  SetBusyIfNeeded(flags);
  return retVal;
}
Exemplo n.º 14
0
void
Interface::SetDown()
{
	if ((flags & IFF_UP) == 0)
		return;

	RecursiveLocker interfacesLocker(sLock);

	if (IsBusy())
		return;

	SetBusy(true);
	interfacesLocker.Unlock();

	DatalinkTable::Iterator iterator = fDatalinkTable.GetIterator();
	while (domain_datalink* datalink = iterator.Next()) {
		datalink->first_info->interface_down(datalink->first_protocol);
	}

	flags &= ~IFF_UP;

	SetBusy(false);
}
Exemplo n.º 15
0
CCompressionProcessor::EStatus CZipCompressor::End(int abandon)
{
    int errcode = deflateEnd(STREAM);
    SetBusy(false);
    if (abandon) {
        // Ignore result of deflateEnd(), because it can return an error code for empty data
        return eStatus_Success;
    }
    SetError(errcode, zError(errcode));
    if ( errcode == Z_OK ) {
        return eStatus_Success;
    }
    ERR_COMPRESS(67, FormatErrorMessage("CZipCompressor::End", GetProcessedSize()));
    return eStatus_Error;
}
Exemplo n.º 16
0
void CIA6526::NewDelayOrFeed() {
  if (IsIdle()) {
    if (TimerIdle.IsCounting()) {
      int iClocks = TimerIdle.ReadCounter();
      if ((dwDelay & CountA3) != 0) {
        iCounterA += iClocks;
      }
      if ((dwDelay & CountB3) != 0) {
        iCounterB += iClocks;
      }
      TimerIdle.StopCounter();
    }
    SetBusy();
  }
}
Exemplo n.º 17
0
Error CAutoResearch::StartAction(int param)
{
    if ( m_phase != ALP_WAIT )
    {
        return ERR_UNKNOWN;
    }

    m_research = static_cast<ResearchType>(param);

    if ( m_main->IsResearchDone(m_research, m_object->GetTeam()) )
    {
        return ERR_RESEARCH_ALREADY;
    }

    if (m_object->GetPower() == nullptr || !m_object->GetPower()->Implements(ObjectInterfaceType::PowerContainer))
    {
        return ERR_RESEARCH_POWER;
    }
    CPowerContainerObject* power = dynamic_cast<CPowerContainerObject*>(m_object->GetPower());
    if ( power->GetCapacity() > 1.0f )
    {
        return ERR_RESEARCH_TYPE;
    }
    if ( power->GetEnergy() < 1.0f )
    {
        return ERR_RESEARCH_ENERGY;
    }

    float time = SEARCH_TIME;
    if ( m_research == RESEARCH_TANK   )  time *= 0.3f;
    if ( m_research == RESEARCH_FLY    )  time *= 0.3f;
    if ( m_research == RESEARCH_ATOMIC )  time *= 2.0f;

    SetBusy(true);
    InitProgressTotal(time);
    UpdateInterface();

    m_channelSound = m_sound->Play(SOUND_RESEARCH, m_object->GetPosition(), 0.0f, 1.0f, true);
    m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f,      2.0f, SOPER_CONTINUE);
    m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, time-4.0f, SOPER_CONTINUE);
    m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f,      2.0f, SOPER_STOP);

    m_phase    = ALP_SEARCH;
    m_progress = 0.0f;
    m_speed    = 1.0f/time;
    return ERR_OK;
}
Exemplo n.º 18
0
void CIA6526::DoInit() {

  // initialize base class
  Chip::DoInit();

  // set function to call at each clock
  SetOnClock((pfn)OnClock);
  SetBusy();

  // initialize components
  Reset.Init("Reset", this);
  Reset.SetOnHigh((pfn)OnReset);
  Reset.SetOnLow((pfn)OnReset);
  InitPorts();
  InitTimers();
  InitTOD();
  InitSDR();
  InitControl();

  // reset components
  OnReset();
};
Exemplo n.º 19
0
Error CAutoFactory::StartAction(int param)
{
    CObject*   cargo;
    ObjectType type = static_cast<ObjectType>(param);

    if ( type != OBJECT_NULL )
    {
        if ( m_phase != AFP_WAIT )
        {
            return ERR_OK;
        }

        m_type = type;

        cargo = SearchCargo();  // transform metal?
        if ( cargo == nullptr )
        {
            return ERR_FACTORY_NULL;
        }
        if ( NearestVehicle() )
        {
            return ERR_FACTORY_NEAR;
        }

        m_program = "";
        SetBusy(true);
        InitProgressTotal(3.0f+2.0f+15.0f+2.0f+3.0f);
        UpdateInterface();

        cargo->SetLock(true);  // usable metal
        SoundManip(3.0f, 1.0f, 0.5f);

        m_phase    = AFP_CLOSE_S;
        m_progress = 0.0f;
        m_speed    = 1.0f/3.0f;
        return ERR_OK;
    }
    return ERR_UNKNOWN;
}
Exemplo n.º 20
0
bool CAutoConvert::Abort()
{
    if ( m_soundChannel != -1 )
    {
        m_sound->FlushEnvelope(m_soundChannel);
        m_sound->AddEnvelope(m_soundChannel, 0.0f, 1.0f, 1.0f, SOPER_STOP);
        m_soundChannel = -1;
    }

    m_object->SetPartRotationY(1, 0.0f);
    m_object->SetPartRotationY(2, 0.0f);
    m_object->SetPartRotationY(3, Math::PI);
    m_object->SetPartRotationX(2, -Math::PI*0.35f);
    m_object->SetPartRotationX(3, -Math::PI*0.35f);

    m_phase    = ACP_WAIT;
    m_progress = 0.0f;
    m_speed    = 1.0f/2.0f;

    SetBusy(false);
    UpdateInterface();

    return true;
}
void CNoWeapon::Select(bool select)
{
	BaseClass::Select(select);

	SetBusy(!select);
}
Exemplo n.º 22
0
bool CAutoResearch::EventProcess(const Event &event)
{
    CPowerContainerObject*    power;
    Math::Vector    pos, speed;
    Error       message;
    Math::Point     dim;
    float       angle;

    CAuto::EventProcess(event);

    if ( m_engine->GetPause() )  return true;

    if ( event.type == EVENT_UPDINTERFACE )
    {
        if ( m_object->GetSelect() )  CreateInterface(true);
    }

    if ( m_object->GetSelect() )  // center selected?
    {
        Error err = ERR_UNKNOWN;
        if ( event.type == EVENT_OBJECT_RTANK   ) err = StartAction(RESEARCH_TANK);
        if ( event.type == EVENT_OBJECT_RFLY    ) err = StartAction(RESEARCH_FLY);
        if ( event.type == EVENT_OBJECT_RTHUMP  ) err = StartAction(RESEARCH_THUMP);
        if ( event.type == EVENT_OBJECT_RCANON  ) err = StartAction(RESEARCH_CANON);
        if ( event.type == EVENT_OBJECT_RTOWER  ) err = StartAction(RESEARCH_TOWER);
        if ( event.type == EVENT_OBJECT_RPHAZER ) err = StartAction(RESEARCH_PHAZER);
        if ( event.type == EVENT_OBJECT_RSHIELD ) err = StartAction(RESEARCH_SHIELD);
        if ( event.type == EVENT_OBJECT_RATOMIC ) err = StartAction(RESEARCH_ATOMIC);

        if( err != ERR_OK && err != ERR_UNKNOWN )
            m_main->DisplayError(err, m_object);

        if( err != ERR_UNKNOWN )
            return false;
    }

    if ( event.type != EVENT_FRAME )  return true;

    m_progress += event.rTime*m_speed;
    m_timeVirus -= event.rTime;

    if ( m_object->GetVirusMode() )  // contaminated by a virus?
    {
        if ( m_timeVirus <= 0.0f )
        {
            m_timeVirus = 0.1f+Math::Rand()*0.3f;
        }
        return true;
    }

    UpdateInterface(event.rTime);
    EventProgress(event.rTime);

    angle = m_time*0.1f;
    m_object->SetPartRotationY(1, angle);  // rotates the antenna

    angle = (30.0f+sinf(m_time*0.3f)*20.0f)*Math::PI/180.0f;
    m_object->SetPartRotationZ(2, angle);  // directs the antenna

    if ( m_phase == ALP_WAIT )
    {
        FireStopUpdate(m_progress, false);  // extinguished
        return true;
    }

    if ( m_phase == ALP_SEARCH )
    {
        FireStopUpdate(m_progress, true);  // flashes
        if ( m_progress < 1.0f )
        {
            if ( m_object->GetPower() == nullptr || !m_object->GetPower()->Implements(ObjectInterfaceType::PowerContainer) )  // more battery?
            {
                SetBusy(false);
                UpdateInterface();

                m_phase    = ALP_WAIT;
                m_progress = 0.0f;
                m_speed    = 1.0f/1.0f;
                return true;
            }
            power = dynamic_cast<CPowerContainerObject*>(m_object->GetPower());
            power->SetEnergyLevel(1.0f-m_progress);

            if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
            {
                m_lastParticle = m_time;

                pos = m_object->GetPosition();
                pos.x += (Math::Rand()-0.5f)*6.0f;
                pos.z += (Math::Rand()-0.5f)*6.0f;
                pos.y += 11.0f;
                speed.x = (Math::Rand()-0.5f)*2.0f;
                speed.z = (Math::Rand()-0.5f)*2.0f;
                speed.y = Math::Rand()*20.0f;
                dim.x = Math::Rand()*1.0f+1.0f;
                dim.y = dim.x;
                m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIVAPOR);
            }
        }
        else
        {
            m_main->MarkResearchDone(m_research, m_object->GetTeam());  // research done

            m_eventQueue->AddEvent(Event(EVENT_UPDINTERFACE));
            UpdateInterface();

            m_main->DisplayError(INFO_RESEARCH, m_object);

            message = ERR_OK;
            if ( m_research == RESEARCH_TANK   )  message = INFO_RESEARCHTANK;
            if ( m_research == RESEARCH_FLY    )  message = INFO_RESEARCHFLY;
            if ( m_research == RESEARCH_THUMP  )  message = INFO_RESEARCHTHUMP;
            if ( m_research == RESEARCH_CANON  )  message = INFO_RESEARCHCANON;
            if ( m_research == RESEARCH_TOWER  )  message = INFO_RESEARCHTOWER;
            if ( m_research == RESEARCH_PHAZER )  message = INFO_RESEARCHPHAZER;
            if ( m_research == RESEARCH_SHIELD )  message = INFO_RESEARCHSHIELD;
            if ( m_research == RESEARCH_ATOMIC )  message = INFO_RESEARCHATOMIC;
            if ( message != ERR_OK )
            {
                m_main->DisplayError(message, m_object);
            }

            SetBusy(false);
            UpdateInterface();

            m_phase    = ALP_WAIT;
            m_progress = 0.0f;
            m_speed    = 1.0f/1.0f;
        }
    }

    return true;
}
Exemplo n.º 23
0
void CItem::AttachAccessory(const ItemString &name, bool attach, bool noanim, bool force, bool initialSetup)
{
	if(!force && IsBusy())
		return;

	bool anim = !noanim && m_stats.fp;
	SAccessoryParams *params = GetAccessoryParams(name);

	if(!params)
		return;

	if(attach)
	{
		if(!IsAccessoryHelperFree(params->attach_helper))
			return;

		if(CItem *pAccessory = AddAccessory(name))
		{
			pAccessory->Physicalize(false, false);
			pAccessory->SetViewMode(m_stats.viewmode);

			if(!initialSetup)
				pAccessory->m_bonusAccessoryAmmo.clear();

			SetCharacterAttachment(eIGS_FirstPerson, params->attach_helper, pAccessory->GetEntity(), eIGS_FirstPerson, 0);
			SetBusy(true);

			AttachAction action(pAccessory, params);

			if(anim)
			{
				PlayAction(params->attach_action, 0, false, eIPAF_Default|eIPAF_NoBlend);
				m_scheduler.TimerAction(GetCurrentAnimationTime(eIGS_FirstPerson), CSchedulerAction<AttachAction>::Create(action), false);
			}
			else
				action.execute(this);

		}
	}
	else
	{
		if(CItem *pAccessory = GetAccessory(name))
		{
			DetachAction action(pAccessory, params);

			if(anim)
			{
				StopLayer(params->attach_layer, eIPAF_Default|eIPAF_NoBlend);
				PlayAction(params->detach_action, 0, false, eIPAF_Default|eIPAF_NoBlend);
				m_scheduler.TimerAction(GetCurrentAnimationTime(eIGS_FirstPerson), CSchedulerAction<DetachAction>::Create(action), false);
				SetBusy(true);
			}
			else
			{
				SetBusy(true);
				action.execute(this);
			}
		}
	}

	//Skip all this for the offhand
	if(GetEntity()->GetClass()!=CItem::sOffHandClass)
		FixAccessories(params, attach);

	//Attach silencer to 2nd SOCOM
	/////////////////////////////////////////////////////////////
	bool isDualWield = IsDualWieldMaster();
	CItem *dualWield = 0;

	if(isDualWield)
	{
		IItem *slave = GetDualWieldSlave();

		if(slave && slave->GetIWeapon())
			dualWield = static_cast<CItem *>(slave);
		else
			isDualWield = false;
	}

	if(isDualWield)
		dualWield->AttachAccessory(name,attach,noanim);

	//////////////////////////////////////////////////////////////

	//Luciano - send game event
	g_pGame->GetIGameFramework()->GetIGameplayRecorder()->Event(GetOwner(), GameplayEvent(eGE_AttachedAccessory, name, (float)attach, (void *)GetEntityId()));

}
Exemplo n.º 24
0
bool CAutoFactory::EventProcess(const Event &event)
{
    ObjectType  type;
    CObject*    fret;
    CObject*    vehicle;
    Math::Matrix*   mat;
    CPhysics*   physics;
    Math::Vector    pos, speed;
    Math::Point     dim;
    float       zoom, angle, prog;
    int         i;

    CAuto::EventProcess(event);

    if ( m_engine->GetPause() )  return true;

    if ( m_object->GetSelect() )  // factory selected?
    {
        if ( event.type == EVENT_UPDINTERFACE )
        {
            CreateInterface(true);
        }

        type = OBJECT_NULL;
        if ( event.type == EVENT_OBJECT_FACTORYwa )  type = OBJECT_MOBILEwa;
        if ( event.type == EVENT_OBJECT_FACTORYta )  type = OBJECT_MOBILEta;
        if ( event.type == EVENT_OBJECT_FACTORYfa )  type = OBJECT_MOBILEfa;
        if ( event.type == EVENT_OBJECT_FACTORYia )  type = OBJECT_MOBILEia;
        if ( event.type == EVENT_OBJECT_FACTORYws )  type = OBJECT_MOBILEws;
        if ( event.type == EVENT_OBJECT_FACTORYts )  type = OBJECT_MOBILEts;
        if ( event.type == EVENT_OBJECT_FACTORYfs )  type = OBJECT_MOBILEfs;
        if ( event.type == EVENT_OBJECT_FACTORYis )  type = OBJECT_MOBILEis;
        if ( event.type == EVENT_OBJECT_FACTORYwc )  type = OBJECT_MOBILEwc;
        if ( event.type == EVENT_OBJECT_FACTORYtc )  type = OBJECT_MOBILEtc;
        if ( event.type == EVENT_OBJECT_FACTORYfc )  type = OBJECT_MOBILEfc;
        if ( event.type == EVENT_OBJECT_FACTORYic )  type = OBJECT_MOBILEic;
        if ( event.type == EVENT_OBJECT_FACTORYwi )  type = OBJECT_MOBILEwi;
        if ( event.type == EVENT_OBJECT_FACTORYti )  type = OBJECT_MOBILEti;
        if ( event.type == EVENT_OBJECT_FACTORYfi )  type = OBJECT_MOBILEfi;
        if ( event.type == EVENT_OBJECT_FACTORYii )  type = OBJECT_MOBILEii;
        if ( event.type == EVENT_OBJECT_FACTORYrt )  type = OBJECT_MOBILErt;
        if ( event.type == EVENT_OBJECT_FACTORYrc )  type = OBJECT_MOBILErc;
        if ( event.type == EVENT_OBJECT_FACTORYrr )  type = OBJECT_MOBILErr;
        if ( event.type == EVENT_OBJECT_FACTORYrs )  type = OBJECT_MOBILErs;
        if ( event.type == EVENT_OBJECT_FACTORYsa )  type = OBJECT_MOBILEsa;

        Error err = StartAction(type);
        if( err != ERR_OK && err != ERR_GENERIC )
            m_displayText->DisplayError(err, m_object);

        if( err != ERR_GENERIC )
            return false;
    }

    if ( event.type != EVENT_FRAME )  return true;

    m_progress += event.rTime*m_speed;
    EventProgress(event.rTime);

    if ( m_phase == AFP_WAIT )
    {
        if ( m_progress >= 1.0f )
        {
            m_phase    = AFP_WAIT;  // still waiting ...
            m_progress = 0.0f;
            m_speed    = 1.0f/2.0f;
        }
    }

    if ( m_phase == AFP_CLOSE_S )
    {
        if ( m_progress < 1.0f )
        {
            for ( i=0 ; i<9 ; i++ )
            {
                zoom = 0.30f+(m_progress-0.5f+i/16.0f)*2.0f*0.70f;
                if ( zoom < 0.30f )  zoom = 0.30f;
                if ( zoom > 1.00f )  zoom = 1.00f;
                m_object->SetZoomZ( 1+i, zoom);
                m_object->SetZoomZ(10+i, zoom);
            }
        }
        else
        {
            for ( i=0 ; i<9 ; i++ )
            {
                m_object->SetZoomZ( 1+i, 1.0f);
                m_object->SetZoomZ(10+i, 1.0f);
            }

            SoundManip(2.0f, 1.0f, 1.2f);

            m_phase    = AFP_CLOSE_T;
            m_progress = 0.0f;
            m_speed    = 1.0f/2.0f;
        }
    }

    if ( m_phase == AFP_CLOSE_T )
    {
        if ( m_progress < 1.0f )
        {
            for ( i=0 ; i<9 ; i++ )
            {
                angle = -m_progress*(Math::PI/2.0f)+Math::PI/2.0f;
                m_object->SetAngleZ( 1+i,  angle);
                m_object->SetAngleZ(10+i, -angle);
            }
        }
        else
        {
            for ( i=0 ; i<9 ; i++ )
            {
                m_object->SetAngleZ( 1+i, 0.0f);
                m_object->SetAngleZ(10+i, 0.0f);
            }

            m_channelSound = m_sound->Play(SOUND_FACTORY, m_object->GetPosition(0), 0.0f, 1.0f, true);
            m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f,  2.0f, SOPER_CONTINUE);
            m_sound->AddEnvelope(m_channelSound, 1.0f, 1.0f, 11.0f, SOPER_CONTINUE);
            m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f,  2.0f, SOPER_STOP);

            m_phase    = AFP_BUILD;
            m_progress = 0.0f;
            m_speed    = 1.0f/15.0f;
        }
    }

    if ( m_phase == AFP_BUILD )
    {
        if ( m_progress == 0.0f )
        {
            if ( !CreateVehicle() )
            {
                fret = SearchFret();  // transform metal?
                if ( fret != 0 )
                {
                    fret->SetLock(false);  // metal usable again
                }

                if ( m_channelSound != -1 )
                {
                    m_sound->FlushEnvelope(m_channelSound);
                    m_sound->AddEnvelope(m_channelSound, 0.0f, 1.0f, 1.0f, SOPER_STOP);
                    m_channelSound = -1;
                }

                m_phase    = AFP_OPEN_T;
                m_progress = 0.0f;
                m_speed    = 1.0f/2.0f;
                return true;
            }
        }

        if ( m_progress < 1.0f )
        {
            if ( m_type == OBJECT_MOBILErt ||
                 m_type == OBJECT_MOBILErc ||
                 m_type == OBJECT_MOBILErr ||
                 m_type == OBJECT_MOBILErs )
            {
                prog = 1.0f-m_progress*1.5f;
                if ( prog < 0.0f )  prog = 0.0f;
            }
            else
            {
                prog = 1.0f-m_progress;
            }
            angle = powf(prog*10.0f, 2.0f)+m_object->GetAngleY(0);

            vehicle = SearchVehicle();
            if ( vehicle != 0 )
            {
                vehicle->SetAngleY(0, angle+Math::PI);
                vehicle->SetZoom(0, m_progress);
            }

            fret = SearchFret();  // transform metal?
            if ( fret != 0 )
            {
                fret->SetZoom(0, 1.0f-m_progress);
            }

            if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
            {
                m_lastParticle = m_time;

#if 0
                pos = m_fretPos;
                pos.x += (Math::Rand()-0.5f)*20.0f;
                pos.z += (Math::Rand()-0.5f)*20.0f;
                pos.y += 1.0f;
                speed.x = (Math::Rand()-0.5f)*12.0f;
                speed.z = (Math::Rand()-0.5f)*12.0f;
                speed.y = Math::Rand()*12.0f;
                dim.x = Math::Rand()*12.0f+10.0f;
                dim.y = dim.x;
                m_particle->CreateParticle(pos, speed, dim, PARTIBLUE, 1.0f, 0.0f, 0.0f);
#else
                mat = m_object->GetWorldMatrix(0);
                pos = Math::Vector(-12.0f, 20.0f, -4.0f);  // position of chimney
                pos = Math::Transform(*mat, pos);
                pos.y += 2.0f;
                pos.x += (Math::Rand()-0.5f)*2.0f;
                pos.z += (Math::Rand()-0.5f)*2.0f;
                speed.x = 0.0f;
                speed.z = 0.0f;
                speed.y = 6.0f+Math::Rand()*6.0f;
                dim.x = Math::Rand()*1.5f+1.0f;
                dim.y = dim.x;
                m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISMOKE3, 4.0f);
#endif
            }
        }
        else
        {
            m_displayText->DisplayError(INFO_FACTORY, m_object);
            SoundManip(2.0f, 1.0f, 1.2f);

            fret = SearchFret();  // transform metal?
            if ( fret != 0 )
            {
                fret->DeleteObject();  // removes the metal
                delete fret;
            }

            m_vehicle = vehicle = SearchVehicle();
            if ( vehicle != 0 )
            {
                physics = vehicle->GetPhysics();
                if ( physics != 0 )
                {
                    physics->SetFreeze(false);  // can move
                }

                vehicle->SetLock(false);  // vehicle useable
//?             vehicle->GetPhysics()->GetBrain()->StartTaskAdvance(16.0f);
                vehicle->SetAngleY(0, m_object->GetAngleY(0)+Math::PI);
                vehicle->SetZoom(0, 1.0f);
            }

            m_main->CreateShortcuts();

            m_phase    = AFP_OPEN_T;
            m_progress = 0.0f;
            m_speed    = 1.0f/2.0f;
        }
    }

    if ( m_phase == AFP_OPEN_T )
    {
        if ( m_progress < 1.0f )
        {
            for ( i=0 ; i<9 ; i++ )
            {
                angle = -(1.0f-m_progress)*(Math::PI/2.0f)+Math::PI/2.0f;
                m_object->SetAngleZ( 1+i,  angle);
                m_object->SetAngleZ(10+i, -angle);
            }

            if ( m_lastParticle+m_engine->ParticleAdapt(0.1f) <= m_time )
            {
                m_lastParticle = m_time;

                pos = m_fretPos;
                pos.x += (Math::Rand()-0.5f)*10.0f;
                pos.z += (Math::Rand()-0.5f)*10.0f;
                pos.y += Math::Rand()*10.0f;
                speed = Math::Vector(0.0f, 0.0f, 0.0f);
                dim.x = 2.0f;
                dim.y = dim.x;
                m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGLINT, 2.0f, 0.0f, 0.0f);
            }
        }
        else
        {
            for ( i=0 ; i<9 ; i++ )
            {
                m_object->SetAngleZ( 1+i,  Math::PI/2.0f);
                m_object->SetAngleZ(10+i, -Math::PI/2.0f);
            }

            SoundManip(3.0f, 1.0f, 0.5f);

            m_phase    = AFP_OPEN_S;
            m_progress = 0.0f;
            m_speed    = 1.0f/3.0f;
        }
    }

    if ( m_phase == AFP_OPEN_S )
    {
        if ( m_progress < 1.0f )
        {
            for ( i=0 ; i<9 ; i++ )
            {
                zoom = 0.30f+((1.0f-m_progress)-0.5f+i/16.0f)*2.0f*0.70f;
                if ( zoom < 0.30f )  zoom = 0.30f;
                if ( zoom > 1.00f )  zoom = 1.00f;
                m_object->SetZoomZ( 1+i, zoom);
                m_object->SetZoomZ(10+i, zoom);
            }

            if ( m_lastParticle+m_engine->ParticleAdapt(0.1f) <= m_time )
            {
                m_lastParticle = m_time;

                pos = m_fretPos;
                pos.x += (Math::Rand()-0.5f)*10.0f;
                pos.z += (Math::Rand()-0.5f)*10.0f;
                pos.y += Math::Rand()*10.0f;
                speed = Math::Vector(0.0f, 0.0f, 0.0f);
                dim.x = 2.0f;
                dim.y = dim.x;
                m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGLINT, 2.0f, 0.0f, 0.0f);
            }
        }
        else
        {
            for ( i=0 ; i<9 ; i++ )
            {
                m_object->SetZoomZ( 1+i, 0.30f);
                m_object->SetZoomZ(10+i, 0.30f);
            }

            if ( m_program != nullptr )
            {
                CBrain* brain = m_vehicle->GetBrain();
                if ( brain != nullptr )
                {
                    brain->SendProgram(0, const_cast<const char*>(m_program));
                    brain->SetScriptRun(0);
                    brain->RunProgram(0);
                }
            }

            SetBusy(false);
            UpdateInterface();

            m_phase    = AFP_WAIT;
            m_progress = 0.0f;
            m_speed    = 1.0f/2.0f;
        }
    }

    return true;
}
Exemplo n.º 25
0
/** The state machine of the rotor control engine ...
 *
 * This is the transition diagram after the command kRotateCW has been issued:
 *
 * kRotateCW -> kIdle
 *                |
 *                | ==> PowerOn()
 *               \/
 *              kReleaseBrake
 *                |
 *       kStop -> | -------- >>> -------+
 *                | ==> ReleaseBrake()  |
 *                |                     |
 *               \/                     |
 *              kRotorRampup            |
 *                |                     |
 *       kStop -> | -------- >>> -------|--+
 *                | ==> RotateCW()      |  |
 *                |                     |  |
 *               \/                     |  |
 *              kTurningCW              |  |
 *                |                     |  |
 *                * <-------------------+  |
 *       kStop -> |                        |
 *                | ==> RotorOff()         |
 *                |                        |
 *               \/                        |
 *              kLockBrake                 |
 *                |                        |
 *                * <----------------------+
 *                |
 *                | ==> LockBrake()
 *                |
 *               \/
 *              kRotorRampdown
 *                |
 *                | ==> PowerOff()
 *                |
 *               \/
 *              kIdle
 *
 * It will be handled in a similar way for the command kRotateCCW.
 *
 * As the trasitions will take some time, it is not unlikely, that the kStop 
 * event is issued before the state kTurningCW is reached. In that case the 
 * rotor relays etc. must be switched off in a proper order.
 */
void RotatorExec(void) {

  switch ( gRotatorCommand ) {
  
    case kStop:
         
	 SetBusy(1);
	 
	 switch ( gRotatorState ) {
	 
	   case kReleaseBrake: // ???
	   case kTurningCW:
	   case kTurningCCW:
	        RotatorOff();
		gRotatorBusyCounter = 5;
		gRotatorState = kLockBrake;
	        break;

	   case kRotorRampup: // ???
	   case kLockBrake:
	        BrakeLock();
		gRotatorBusyCounter = 5;
		gRotatorState = kRotorRampdown;
	        break;

	   case kRotorRampdown:
		PowerOff();
	        gRotatorState = kIdle;
		gRotatorBusyCounter = 10;
	        break;

	   case kIdle:
		gRotatorCommand = kNone;
		SetBusy(0);
	        break;
	 }

         break;

    case kTurnCW:
         
	 SetBusy(1);
	 
	 switch ( gRotatorState ) {
	 
	   case kIdle: 
	        PowerOn();
		gRotatorState = kReleaseBrake;
		gRotatorBusyCounter = 10;
		break;
	 
	   case kReleaseBrake:
	        BrakeRelease();
		gRotatorState = kRotorRampup;
		gRotatorBusyCounter = 5;
		break;
	 
	   case kRotorRampup: 
		gRotatorState = kTurningCW;
         	RotatorCW();
		gRotatorBusyCounter = 5;
		break;
	   
	   case kTurningCW:
		gRotatorState = kTurningCW;
	        gRotatorCommand = kNone;
		break;
	 }
	
         break;

    case kTurnCCW:
         
	 SetBusy(1);
	 
	 switch ( gRotatorState ) {
	 
	   case kIdle: 
	        PowerOn();
		gRotatorState = kReleaseBrake;
		gRotatorBusyCounter = 10;
		break;
	 
	   case kReleaseBrake:
	        BrakeRelease();
		gRotatorState = kRotorRampup;
		gRotatorBusyCounter = 5;
		break;
	 
	   case kRotorRampup: 
		gRotatorState = kTurningCCW;
         	RotatorCCW();
		gRotatorBusyCounter = 5;
		break;
	   
	   case kTurningCCW:
		gRotatorState = kTurningCCW;
	        gRotatorCommand = kNone;
		break;
	 }

         break;

    case kFastStop:
         RotatorOff();
         BrakeLock();
	 PowerOff();
	 
	 // reset state machine and command variable
	 gRotatorState = kIdle;
	 gRotatorCommand = kNone;
         
         // both PRESET LEDs off
         LED_PORT &= ~(LED_LEFT | LED_RIGHT);
	 
	 SetBusy(0);
      
         // clear preset data
         gPresetHeading = gCurrentHeading;
	 gPresetCounter = 0;
	 gPresetCommand = kPresetNone;
         break;

    default:
         break;
  }
}
Exemplo n.º 26
0
//
// Set the busy flag if the command included MCI_NOTIFY.
//
void
TMci::SetBusyIfNeeded(uint32 command)
{
  if (command & MCI_NOTIFY)
    SetBusy(true);
}
Exemplo n.º 27
0
void __cdecl SetPointer (logical wait_opt )
{

  SetBusy(wait_opt);

}
Exemplo n.º 28
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CAI_FuncTankBehavior::StartTask( const Task_t *pTask )
{
	switch ( pTask->iTask )
	{
	case TASK_FUNCTANK_ANNOUNCE_SCAN:
		{
			if ( random->RandomInt( 0, 3 ) == 0 )
			{
				GetOuter()->SpeakSentence( FUNCTANK_SENTENCE_SCAN_FOR_ENEMIES );
			}
			TaskComplete();
		}
		break;

	case TASK_GET_PATH_TO_FUNCTANK:
		{
			if ( !m_hFuncTank )
			{
				TaskFail( FAIL_NO_TARGET  );
				return;
			}

			Vector vecManPos;
			m_hFuncTank->NPC_FindManPoint( vecManPos );
			AI_NavGoal_t goal( vecManPos );
			goal.pTarget = m_hFuncTank;
			if ( GetNavigator()->SetGoal( goal ) )
			{
				GetNavigator()->SetArrivalDirection( m_hFuncTank->GetAbsAngles() );
				TaskComplete();
			}
			else
			{
				TaskFail("NO PATH");

				// Don't try and use me again for a while
				SetBusy( gpGlobals->curtime + AI_FUNCTANK_BEHAVIOR_BUSYTIME );
			}
			break;
		}		
	case TASK_FACE_FUNCTANK:
		{
			if ( !m_hFuncTank )
			{
				TaskFail( FAIL_NO_TARGET );
				return;
			}
			
			// Ensure we've reached the func_tank
			Vector vecManPos;
			m_hFuncTank->NPC_FindManPoint( vecManPos );

			// More leniency in Z.
			Vector vecDelta = (vecManPos - GetAbsOrigin());
			if ( fabs(vecDelta.x) > 16 || fabs(vecDelta.y) > 16 || fabs(vecDelta.z) > 48 )
			{
				TaskFail( "Not correctly on func_tank man point" );
				m_hFuncTank->NPC_InterruptRoute();
				return;
			}

			GetMotor()->SetIdealYawToTarget( m_hFuncTank->GetAbsOrigin() );
			GetOuter()->SetTurnActivity(); 
			break;
		}

	case TASK_HOLSTER_WEAPON:
		{
			if ( !m_hFuncTank )
			{
				TaskFail( FAIL_NO_TARGET );
				return;
			}

			if ( GetOuter()->IsWeaponHolstered() || !GetOuter()->CanHolsterWeapon() )
			{
				GetOuter()->SpeakSentence( FUNCTANK_SENTENCE_JUST_MOUNTED );

				// We are at the correct position and facing for the func_tank, mount it.
				m_hFuncTank->StartControl( GetOuter() );
				GetOuter()->ClearEnemyMemory();
				m_bMounted = true;
				TaskComplete();

				GetOuter()->SetIdealActivity( ACT_IDLE_MANNEDGUN );
			}
			else
			{
				GetOuter()->SetDesiredWeaponState( DESIREDWEAPONSTATE_HOLSTERED );
			}
			break;
		}

	case TASK_FIRE_FUNCTANK:
		{
			if ( !m_hFuncTank )
			{
				TaskFail( FAIL_NO_TARGET );
				return;
			}
			GetOuter()->m_flWaitFinished = gpGlobals->curtime + FUNCTANK_FIRE_TIME;
			break;
		}
	case TASK_SCAN_LEFT_FUNCTANK:
		{
			if ( !m_hFuncTank )
			{
				TaskFail( FAIL_NO_TARGET );
				return;
			}

			GetMotor()->SetIdealYawToTarget( m_hFuncTank->GetAbsOrigin() );

			float flCenterYaw = m_hFuncTank->YawCenterWorld();
			float flYawRange = m_hFuncTank->YawRange();
			float flScanAmount = random->RandomFloat( 0, flYawRange );
			QAngle vecTargetAngles( 0, UTIL_AngleMod( flCenterYaw + flScanAmount ), 0 );

			/*
			float flCenterPitch = m_hFuncTank->YawCenterWorld();
			float flPitchRange = m_hFuncTank->PitchRange();
			float flPitch = random->RandomFloat( -flPitchRange, flPitchRange );
			QAngle vecTargetAngles( flCenterPitch + flPitch, UTIL_AngleMod( flCenterYaw + flScanAmount ), 0 );
			*/

			Vector vecTargetForward;
			AngleVectors( vecTargetAngles, &vecTargetForward );
			Vector vecTarget = GetOuter()->EyePosition() + (vecTargetForward * 256);
			GetOuter()->AddLookTarget( vecTarget, 1.0, 2.0, 0.2 );

			m_hFuncTank->NPC_SetIdleAngle( vecTarget );

			break;
		}
	case TASK_SCAN_RIGHT_FUNCTANK:
		{
			if ( !m_hFuncTank )
			{
				TaskFail( FAIL_NO_TARGET );
				return;
			}

			GetMotor()->SetIdealYawToTarget( m_hFuncTank->GetAbsOrigin() );

			float flCenterYaw = m_hFuncTank->YawCenterWorld();
			float flYawRange = m_hFuncTank->YawRange();
			float flScanAmount = random->RandomFloat( 0, flYawRange );
			QAngle vecTargetAngles( 0, UTIL_AngleMod( flCenterYaw - flScanAmount ), 0 );

			/*
			float flCenterPitch = m_hFuncTank->YawCenterWorld();
			float flPitchRange = m_hFuncTank->PitchRange();
			float flPitch = random->RandomFloat( -flPitchRange, flPitchRange );
			QAngle vecTargetAngles( flCenterPitch + flPitch, UTIL_AngleMod( flCenterYaw - flScanAmount ), 0 );
			*/

			Vector vecTargetForward;
			AngleVectors( vecTargetAngles, &vecTargetForward );
			Vector vecTarget = GetOuter()->EyePosition() + (vecTargetForward * 256);
			GetOuter()->AddLookTarget( vecTarget, 1.0, 2.0, 0.2 );

			m_hFuncTank->NPC_SetIdleAngle( vecTarget );

			break;
		}
	case TASK_FORGET_ABOUT_FUNCTANK:
		{
			if ( !m_hFuncTank )
			{
				TaskFail( FAIL_NO_TARGET );
				return;
			}
			break;
		}
	default:
		{
			BaseClass::StartTask( pTask );
			break;
		}
	}
}
Exemplo n.º 29
0
bool CAutoConvert::EventProcess(const Event &event)
{
    CObject*    cargo;
    Math::Vector    pos, speed;
    Math::Point     dim, c, p;
    float       angle;

    CAuto::EventProcess(event);

    if ( m_engine->GetPause() )  return true;
    if ( event.type != EVENT_FRAME )  return true;

    m_progress += event.rTime*m_speed;
    m_timeVirus -= event.rTime;

    if ( m_object->GetVirusMode() )  // contaminated by a virus?
    {
        if ( m_timeVirus <= 0.0f )
        {
            m_timeVirus = 0.1f+Math::Rand()*0.3f;

            angle = (Math::Rand()-0.5f)*0.3f;
            m_object->SetPartRotationY(1, angle);
            m_object->SetPartRotationY(2, angle);
            m_object->SetPartRotationY(3, angle+Math::PI);

            m_object->SetPartRotationX(2, -Math::PI*0.35f*(0.8f+Math::Rand()*0.2f));
            m_object->SetPartRotationX(3, -Math::PI*0.35f*(0.8f+Math::Rand()*0.2f));
        }
        return true;
    }

    EventProgress(event.rTime);

    if ( m_phase == ACP_STOP )  return true;

    if ( m_phase == ACP_WAIT )
    {
        if ( m_progress >= 1.0f )
        {
            cargo = SearchStone(OBJECT_STONE);  // Has stone transformed?
            if ( cargo == nullptr || SearchVehicle() )
            {
                m_phase    = ACP_WAIT;  // still waiting ...
                m_progress = 0.0f;
                m_speed    = 1.0f/2.0f;
            }
            else
            {
                cargo->SetLock(true);  // stone usable

                SetBusy(true);
                InitProgressTotal(3.0f+10.0f+1.5f);
                UpdateInterface();

                m_sound->Play(SOUND_OPEN, m_object->GetPosition(), 1.0f, 1.0f);
                m_bSoundClose = false;

                m_phase    = ACP_CLOSE;
                m_progress = 0.0f;
                m_speed    = 1.0f/3.0f;
            }
        }
    }

    if ( m_phase == ACP_CLOSE )
    {
        if ( m_progress < 1.0f )
        {
            if ( m_progress >= 0.8f && !m_bSoundClose )
            {
                m_bSoundClose = true;
                m_sound->Play(SOUND_CLOSE, m_object->GetPosition(), 1.0f, 0.8f);
            }
            angle = -Math::PI*0.35f*(1.0f-Math::Bounce(m_progress, 0.85f, 0.05f));
            m_object->SetPartRotationX(2, angle);
            m_object->SetPartRotationX(3, angle);
        }
        else
        {
            m_object->SetPartRotationX(2, 0.0f);
            m_object->SetPartRotationX(3, 0.0f);

            m_soundChannel = m_sound->Play(SOUND_CONVERT, m_object->GetPosition(), 0.0f, 0.25f, true);
            m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.25f, 0.5f, SOPER_CONTINUE);
            m_sound->AddEnvelope(m_soundChannel, 1.0f, 1.00f, 4.5f, SOPER_CONTINUE);
            m_sound->AddEnvelope(m_soundChannel, 1.0f, 0.25f, 4.5f, SOPER_CONTINUE);
            m_sound->AddEnvelope(m_soundChannel, 0.0f, 0.25f, 0.5f, SOPER_STOP);

            m_phase    = ACP_ROTATE;
            m_progress = 0.0f;
            m_speed    = 1.0f/10.0f;
        }
    }

    if ( m_phase == ACP_ROTATE )
    {
        if ( m_progress < 1.0f )
        {
            if ( m_progress < 0.5f )
            {
                angle = powf((m_progress*2.0f)*5.0f, 2.0f);  // accelerates
            }
            else
            {
                angle = -powf((2.0f-m_progress*2.0f)*5.0f, 2.0f);  // slows
            }
            m_object->SetPartRotationY(1, angle);
            m_object->SetPartRotationY(2, angle);
            m_object->SetPartRotationY(3, angle+Math::PI);

            if ( m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
            {
                m_lastParticle = m_time;

                pos = m_object->GetPosition();
                c.x = pos.x;
                c.y = pos.z;
                p.x = c.x;
                p.y = c.y+6.0f;
                p = Math::RotatePoint(c, Math::Rand()*Math::PI*2.0f, p);
                pos.x = p.x;
                pos.z = p.y;
                pos.y += 1.0f;
                speed = Math::Vector(0.0f, 0.0f, 0.0f);
                dim.x = Math::Rand()*2.0f+1.0f;
                dim.y = dim.x;
                m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 1.0f, 0.0f, 0.0f);
            }
        }
        else
        {
            m_object->SetPartRotationY(1, 0.0f);
            m_object->SetPartRotationY(2, 0.0f);
            m_object->SetPartRotationY(3, Math::PI);

            cargo = SearchStone(OBJECT_STONE);
            if ( cargo != nullptr )
            {
                CObjectManager::GetInstancePointer()->DeleteObject(cargo);
            }

            CreateMetal();  // Create the metal
            m_sound->Play(SOUND_OPEN, m_object->GetPosition(), 1.0f, 1.5f);

            m_phase    = ACP_OPEN;
            m_progress = 0.0f;
            m_speed    = 1.0f/1.5f;
        }
    }

    if ( m_phase == ACP_OPEN )
    {
        if ( m_progress < 1.0f )
        {
            angle = -Math::PI*0.35f*Math::Bounce(m_progress, 0.7f, 0.2f);
            m_object->SetPartRotationX(2, angle);
            m_object->SetPartRotationX(3, angle);

            if ( m_progress < 0.9f &&
                 m_lastParticle+m_engine->ParticleAdapt(0.05f) <= m_time )
            {
                m_lastParticle = m_time;

                pos = m_object->GetPosition();
                pos.x += (Math::Rand()-0.5f)*6.0f;
                pos.z += (Math::Rand()-0.5f)*6.0f;
                pos.y += Math::Rand()*4.0f;
                speed = Math::Vector(0.0f, 0.0f, 0.0f);
                dim.x = Math::Rand()*4.0f+3.0f;
                dim.y = dim.x;
                m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLUE, 1.0f, 0.0f, 0.0f);
            }
        }
        else
        {
            m_soundChannel = -1;
            m_object->SetPartRotationX(2, -Math::PI*0.35f);
            m_object->SetPartRotationX(3, -Math::PI*0.35f);

            SetBusy(false);
            UpdateInterface();

            m_phase    = ACP_WAIT;
            m_progress = 0.0f;
            m_speed    = 1.0f/2.0f;
        }
    }

    return true;
}
Exemplo n.º 30
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CAI_FuncTankBehavior::RunTask( const Task_t *pTask )
{
	switch ( pTask->iTask )
	{
	case TASK_FACE_FUNCTANK:
		{
			Assert( m_hFuncTank );

			GetMotor()->UpdateYaw();

			if ( GetOuter()->FacingIdeal() )
			{
				TaskComplete();
			}
			break;
		}
	case TASK_HOLSTER_WEAPON:
		{
			Assert( m_hFuncTank );

			if ( GetOuter()->IsWeaponHolstered() )
			{
				GetOuter()->SpeakSentence( FUNCTANK_SENTENCE_JUST_MOUNTED );

				// We are at the correct position and facing for the func_tank, mount it.
				m_hFuncTank->StartControl( GetOuter() );
				GetOuter()->ClearEnemyMemory();
				m_bMounted = true;
				TaskComplete();

				GetOuter()->SetIdealActivity( ACT_IDLE_MANNEDGUN );
			}

			break;
		}
	case TASK_FIRE_FUNCTANK:
		{
			Assert( m_hFuncTank );

			if( GetOuter()->m_flWaitFinished < gpGlobals->curtime )
			{
				TaskComplete();
			}

			if ( m_hFuncTank->NPC_HasEnemy() )
			{
				GetOuter()->SetLastAttackTime( gpGlobals->curtime );
				m_hFuncTank->NPC_Fire();

				// The NPC may have decided to stop using the func_tank, because it's out of ammo.
				if ( !m_hFuncTank )
				{
					TaskComplete();
					break;
				}
			}
			else
			{
				TaskComplete();
			}
			
			Assert( m_hFuncTank );

			if ( m_hFuncTank->GetAmmoCount() == 0 )
			{
				TaskComplete();
			}
			break;
		}
	case TASK_SCAN_LEFT_FUNCTANK:
	case TASK_SCAN_RIGHT_FUNCTANK:
		{
			GetMotor()->UpdateYaw();
			if ( GetOuter()->FacingIdeal() )
			{
				TaskComplete();
			}
			break;
		}
	case TASK_FORGET_ABOUT_FUNCTANK:
		{
			m_hFuncTank->NPC_InterruptRoute();
			SetBusy( gpGlobals->curtime + AI_FUNCTANK_BEHAVIOR_BUSYTIME );
			TaskComplete();
			break;
		}
	default:
		{
			BaseClass::RunTask( pTask );
			break;
		}
	}
}