void GuardSearch::Execute( BaseType::EntityType *entity )
    {
        CMonster *pSelf = dynamic_cast<CMonster*>( entity->GetOwner() );
        ShapeListType player_list;
        ShapeListType monster_list;
        CServerRegion *pRegion = static_cast<CServerRegion*>( pSelf->GetFather() );
        CMoveShape *pTarget = NULL;

        if( CanAttackCurrent( pSelf, entity ) )
        {
            return;
        }

        // find the around players
        pRegion->FindAroundObject( pSelf, TYPE_PLAYER, player_list );
        // find the around monsters including the guards.
        pRegion->FindAroundObject( pSelf, TYPE_MONSTER, monster_list );

        // filter the result
        Filter filter( static_cast<CMonster*>( pSelf ) );
        filter_shape( player_list, filter );
        filter_shape( monster_list, filter );


        // retrieve the ai reference
        DWORD ai_ref = pSelf->GetAIReferrence( 0 );
        if( ai_ref >= 0 )
        {
            pTarget = SearchByAIRef1( pSelf, player_list, ai_ref );
        }

        if( pTarget == NULL && ( ai_ref = pSelf->GetAIReferrence( 1 ) ) > 0 )
        {
            pTarget = SearchByAIRef2( pSelf, player_list, ai_ref );
        }	

        if( pTarget == NULL && ( ai_ref = pSelf->GetAIReferrence( 2 ) ) > 0 )
        {
            pTarget = SearchByAIRef3( pSelf, monster_list, ai_ref );
        }

        if( pTarget == NULL && ( ai_ref = pSelf->GetAIReferrence( 3 ) ) > 0 )
        {
            pTarget = SearchByAIRef4( pSelf, monster_list, ai_ref );
        }

        if( pTarget != NULL )
        {
            // search successfully
            entity->SetTarget( pTarget->GetExID(), pTarget->GetType() );
        }
        else if( entity->HasTarget() )
        {
            AI_EVENT_SENDER( entity ).ReturnPeace();
        }
    }
Esempio n. 2
0
/*******************************************************************************
 * Function Name  : tinkerAnalogWrite
 * Description    : Writes an analog value (PWM) to the specified pin
 * Input          : Pin and Value (0 to 255)
 * Output         : None.
 * Return         : 1 on success and a negative number on failure
 *******************************************************************************/
int tinkerAnalogWrite(String command)
{
   //convert ascii to integer
   int pinNumber = command.charAt(1) - '0';
   //Sanity check to see if the pin numbers are within limits
   if (pinNumber< 0 || pinNumber >7) return -1;

   int value = (command.substring(3)).toInt();

   if(command.startsWith("D"))
   {
      pinMode(pinNumber, OUTPUT);
      analogWrite(pinNumber, value);
      return 1;
   }
   else if(command.startsWith("A"))
   {
      /* run volume control if A0 was selected */
      if (pinNumber==0)
      {
         return volume_control(value);    
      }
      if (pinNumber==1)
      {
         return filter_shape(value);
      }
      return 1;
   }
   else return -2;
}
Esempio n. 3
0
BOOL Guard::SearchEnemy()
{
	if( !CanSearchEnemy() )
	{
		return FALSE;
	}

	if( CanAttackCurrent() )
	{
		return FALSE;
	}

	ShapeListType player_list;
	ShapeListType monster_list;
	CServerRegion *pRegion = static_cast<CServerRegion*>( m_pOwner->GetFather() );
	CMonster *pSelf = static_cast<CMonster*>( m_pOwner );
	CMoveShape *pTarget = NULL;

	// find the around players
	pRegion->FindAroundObject( m_pOwner, TYPE_PLAYER, player_list );
	// find the around monsters including the guards.
	pRegion->FindAroundObject( m_pOwner, TYPE_MONSTER, monster_list );

	// filter the result
	Filter filter( static_cast<CMonster*>( m_pOwner ) );
	filter_shape( player_list, filter );
	filter_shape( monster_list, filter );


	// retrieve the ai reference
	DWORD ai_ref = pSelf->GetAIReferrence( 0 );
	if( ai_ref >= 0 )
	{
		pTarget = SearchByAIRef1( player_list, ai_ref );
	}

	if( pTarget == NULL && ( ai_ref = pSelf->GetAIReferrence( 1 ) ) > 0 )
	{
		pTarget = SearchByAIRef2( player_list, ai_ref );
	}	

	if( pTarget == NULL && ( ai_ref = pSelf->GetAIReferrence( 2 ) ) > 0 )
	{
		pTarget = SearchByAIRef3( monster_list, ai_ref );
	}

	if( pTarget == NULL && ( ai_ref = pSelf->GetAIReferrence( 3 ) ) > 0 )
	{
		pTarget = SearchByAIRef4( monster_list, ai_ref );
	}

	if( pTarget != NULL )
	{
		// search successfully
		SetTarget( pTarget->GetType(), pTarget->GetExID() );
		return TRUE; 
	}
	else if( HasTarget() )
	{
		WhenLoseTarget();
	}

	return FALSE;	
}