コード例 #1
0
//=========================================================
// Selecciona una clase de NPC.
//=========================================================
const char *CDirectorSpawn::SelectRandom()
{
	int pRandom = random->RandomInt(0, ARRAYSIZE(iNpcs) - 1);

	if ( iNpcs[pRandom] == NULL_STRING )
		return SelectRandom();

	return STRING(iNpcs[pRandom]);
}
コード例 #2
0
ファイル: StateMachine.cpp プロジェクト: nurv/lirec
DMLString StateMachine::GetNextAnimation()
{
   DMLString animation = "";


   // first check whether a transition animation needs to be played
   // if so, play this animation before playing the next action animation
   animation = GetTransitionAnimation();
   if (animation != ""){
	   _currentAnimation=animation;
	   return animation;
   }
      
   // If no transition animation needs to be played then select the next
   // animation to be played in the current state
   if (_currentState == INTRO01){
      animation = "\\STANDARD\\Demo\\Intro01.raf";
	  GotoState (INTRO02, true);
   }

   else if (_currentState == INTRO02){
      animation = "\\STANDARD\\Demo\\Intro02.raf";
      GotoState (INTRO03, true);
   }
   else if (_currentState == INTRO03){
      animation = "\\STANDARD\\Demo\\Intro03.raf";
 	  GotoState (INTERACTIVE, true);
   }
   else if (_currentState == SLEEPING_BY_NODDING){
      animation = "\\STANDARD\\Modes\\Sleeping\\SleepNod.raf";      
      // the transition to an other sleeping animation is
      // done autonomously and by time
      _sleepingNods = _sleepingNods + 1;
      if (_sleepingNods >= 4)
         GotoState (SLEEPING_BY_FLASHING, false);
   }
   else if (_currentState == SLEEPING_BY_FLASHING){
	   animation = "\\STANDARD\\Modes\\Sleeping\\SleepFlash.raf";
   }
   else if (_currentState == IDLE_LOOK_FRONT){
      animation = SelectRandom (_idle_front_table);	  
      // the transition to looking left or right is done autonomously
      // and randomly
      if (ThrowDice(100)) 
         GotoState (IDLE_LOOK_LEFT, false);
      else if (ThrowDice(100))
         GotoState (IDLE_LOOK_RIGHT, false);
   }
   else if (_currentState == IDLE_LOOK_LEFT){
      animation = SelectRandom (_idle_left_table);
      // the transition to looking to the front is done autonomously
      if (ThrowDice(300)) 
         GotoState (IDLE_LOOK_FRONT, false);
   }	     
   else if (_currentState == IDLE_LOOK_RIGHT){ 
      animation = SelectRandom (_idle_right_table);
      // the transition to looking to the front is done autonomously
      if (ThrowDice(300)) 
         GotoState (IDLE_LOOK_FRONT, false);
   }     
   else if (_currentState == INTERACTIVE)
      animation = SelectRandom (_interactive_table);
  
   _currentAnimation=animation;
   return animation;
}
コード例 #3
0
//=========================================================
// Crea un Zombi.
//=========================================================
CAI_BaseNPC *CDirectorSpawn::MakeNPC(bool Horde, bool disclosePlayer, bool checkRadius)
{
	// Desactivado
	// Esta entidad no funciona en Multiplayer.
	if ( Disabled )
		return NULL;

	// Seleccionamos una clase de NPC para crear.
	const char *pClass	= SelectRandom();
	CAI_BaseNPC *pNPC	= VerifyClass(pClass);

	// Emm... ¿puso todas las clases en "no crear"? :genius:
	if ( !pNPC )
	{
		Warning("[DIRECTOR SPAWN] Ha ocurrido un problema al intentar crear un NPC. \r\n");
		return NULL;
	}

	Vector origin;

	// Verificamos si podemos crear un zombi en el radio.
	if ( checkRadius )
	{
		if ( !CanMakeNPC(pNPC, &origin) )
			return NULL;
	}

	// Lugar de creación.
	pNPC->SetAbsOrigin(origin);

	QAngle angles	= GetAbsAngles();
	angles.x		= 0.0;
	angles.z		= 0.0;

	pNPC->SetAbsAngles(angles);

	// Tiene que caer al suelo.
	pNPC->AddSpawnFlags(SF_NPC_FALL_TO_GROUND);
	// Su cuerpo tiene que desaparecer al morir.
	pNPC->AddSpawnFlags(SF_NPC_FADE_CORPSE);

	// Creamos al NPC, le decimos quien es su dios (creador) y lo activamos.
	DispatchSpawn(pNPC);
	pNPC->SetOwnerEntity(this);
	DispatchActivate(pNPC);

	// Al parecer se atoro en una pared.
	if ( !PostSpawn(pNPC) )
		return NULL;

	// Nombre del NPC.
	pNPC->SetName(MAKE_STRING(CHILD_NAME));

#ifdef APOCALYPSE
	// Skin al azar.
	if ( pNPC->GetClassname() == "npc_zombie" )	
		pNPC->m_nSkin = random->RandomInt(1, 4);
#endif

	// Es un NPC para la horda ¡woot!
	if ( Horde )
	{
		AddHealth(pNPC);

#ifdef APOCALYPSE
		// Más rápido.
		pNPC->SetAddAccel(40);

		// No colisiona con otros NPC's. (Zombis)
		if ( random->RandomInt(1, 4) == 2 )
			pNPC->SetCollisionGroup(COLLISION_GROUP_SPECIAL_NPC);
#endif
	}

	// Debe conocer la ubicación del jugador (Su enemigo)
	if ( disclosePlayer )
	{
		CIN_Player *pPlayer = UTIL_GetRandomInPlayer();

		if ( pPlayer )
			pNPC->UpdateEnemyMemory(pPlayer, pPlayer->GetAbsOrigin());
	}

	Childs++;
	ChildsAlive++;
	LastSpawn = gpGlobals->curtime;

	OnSpawnNPC.FireOutput(pNPC, this);
	return pNPC;
}