Ejemplo n.º 1
0
void AUModCharacter::DamagePlayer(int32 force)
{
    if (Role != ROLE_Authority) {
        return;
    }

    uint32 a = (uint32)force;

    if (playerHealth > a) {
        playerHealth -= a;
    } else if (playerHealth == a) {
        KillPlayer();
    } else if (playerHealth < a) {
        KillPlayer();
    }
}
Ejemplo n.º 2
0
void game_sv_TeamDeathmatch::OnPlayerChangeTeam(ClientID id_who, s16 team)
{
    game_PlayerState*	ps_who	=	get_id	(id_who);
    if (!ps_who) return;
    if (!team)
    {
        if (!ps_who->team)
            team = AutoTeam();
        else if (TeamSizeEqual())
        {
            team = ps_who->team;
        }
        else
        {
            team = AutoTeam();
        }
    };
    //-----------------------------------------------------
    NET_Packet Px;
    GenerateGameMessage(Px);
    Px.w_u32(GAME_EVENT_PLAYER_GAME_MENU_RESPOND);
    Px.w_u8(PLAYER_CHANGE_TEAM);
    Px.w_s16(team);
    m_server->SendTo(id_who,Px,net_flags(TRUE,TRUE));
    //-----------------------------------------------------
    if (ps_who->team == team) return;
    //-----------------------------------------------------
    KillPlayer(id_who, ps_who->GameID);
    //-----------------------------------------------------
    ps_who->setFlag(GAME_PLAYER_FLAG_SPECTATOR);
    //-----------------------------------------------------
    s16 OldTeam = ps_who->team;
    ps_who->team = u8(team & 0x00ff);
    TeamStruct* pTS = GetTeamData(team);
    if (pTS)
    {
        if ((ps_who->money_for_round < pTS->m_iM_Start) || (OldTeam == 0))
            Money_SetStart(id_who);
    }

/////////////////////////////////////////////////////////
    //Send Switch team message
    NET_Packet			P;
//	P.w_begin			(M_GAMEMESSAGE);
    GenerateGameMessage (P);
    P.w_u32				(PLAYER_CHANGE_TEAM);
    P.w_u16				(ps_who->GameID);
    P.w_u16				(ps_who->team);
    P.w_u16				(team);
    u_EventSend(P);
/////////////////////////////////////////////////////////



    SetPlayersDefItems(ps_who);

}
void game_sv_CaptureTheArtefact::OnEvent(NET_Packet & tNetPacket, u16 type, u32 time, ClientID sender )
{
	switch	(type)
	{
	case GAME_EVENT_PLAYER_KILL:
		{
			u16				ID = tNetPacket.r_u16();
			xrClientData*	l_pC = (xrClientData*)get_client(ID);
			if (!l_pC)
				break;

			KillPlayer		(l_pC->ID, l_pC->ps->GameID);
		}break;
	case GAME_EVENT_PLAYER_BUY_FINISHED:
		{
			xrClientData* l_pC = m_server->ID_to_client(sender);
			OnPlayerBuyFinished(l_pC->ID, tNetPacket);
		}break;
	case GAME_EVENT_PLAYER_ENTER_TEAM_BASE:
		{
			u16 pl_id = tNetPacket.r_u16();
			//warning, in editor green team zone has 1 id, blue team zone has id 2
			u8 z_t_id = tNetPacket.r_u8();
			z_t_id--; // :( !!!
			OnObjectEnterTeamBase(pl_id, z_t_id);
		}break;

	case GAME_EVENT_PLAYER_LEAVE_TEAM_BASE:
		{
 			u16 pl_id = tNetPacket.r_u16();
			u8 z_t_id = tNetPacket.r_u8();
			z_t_id--;						// :( !!!
			OnObjectLeaveTeamBase(pl_id, z_t_id);
		}break;
	default:
		inherited::OnEvent(tNetPacket, type, time, sender);
	};//switch
}
Ejemplo n.º 4
0
static s32 CalcCrow( struct TaskData* pTask , u32 Flag ) {
	int dx = pTask->x - g_PlayerX;
	int dy = pTask->y - g_PlayerY -g_OffsetY + 275;



	if(dx*dx>512*512) return 0;	//遠すぎる場合はすぐ終了

	pTask->Data.crow.count += 1;
	if(pTask->Data.crow.count>=60){
        // 弾発射
          struct TaskData* pBTask;
          pBTask = AllocTask();
          if (pBTask != NULL) {
			  InitTaskEBullet( pBTask , pTask->x, pTask->y, AG_RP_OBJ_EBULLET,0, 5, 0,0 );
            AddlLink( pBTask , DISP_LEVEL_EBULLET );
        };
		pTask->Data.crow.count = 0;
		ageSndMgrPlayOneshot( AS_SND_CROW , 0 , 0x80 , AGE_SNDMGR_PANMODE_LR12 , 0x80 , 0 );

	};
	if(pTask->Data.crow.count % 20 == 0){
		pTask->Data.crow.mode += 1;
		pTask->Data.crow.mode %= 3;
	};
	//移動
	{
		int ax = (int)(-dx*0.01 - pTask->Data.crow.vx*0.04);
		int ay = (int)(-dy*0.01 - pTask->Data.crow.vy*0.04);
		if(ax==0){
			if(dx>0)ax = -1;
			else if(dx<0)ax = 1;
		}
		pTask->Data.crow.vx += ax;
		pTask->Data.crow.vy += ay;
	
	if(pTask->Data.crow.vx==0){
		if(dx>0)pTask->Data.crow.vx = -1;
		else if(dx<0)pTask->Data.crow.vx = 1;
	}
	pTask->x += pTask->Data.crow.vx;
	pTask->y += pTask->Data.crow.vy;
	}

  // 自機の弾の判定
  {
    struct TaskData* pBTask;
    pBTask = GetDispLink( DISP_LEVEL_PBULLET );
    while ( pBTask != NULL ) {
      if (pBTask->type == TASK_PBULLET) {
        if ( (pTask->x - pBTask->x) * (pTask->x - pBTask->x) + (pTask->y - pBTask->y) * (pTask->y - pBTask->y) < 50*50) {
          struct TaskData* pATask;

          pATask = AllocTask();
          InitTaskAttack( pATask , pTask->x , pTask->y );
          AddlLink( pATask , DISP_LEVEL_ATTACK );

          pTask->visible = 0;
          pTask->flag = TASK_FLAG_DESTROY;

          AddScore( pTask->Data.crow.score );

          pBTask->visible = 0;
          pBTask->flag = TASK_FLAG_DESTROY;
          break;
        }
      }

      pBTask = pBTask->Next;
    }
  }

  // 自機との判定
  if ( (pTask->x - g_PlayerX) * (pTask->x - g_PlayerX) + (pTask->y - 28 - g_PlayerY ) * (pTask->y - 28 - g_PlayerY ) < 60*60) {
  //if ( g_pPlayerRect != NULL && HitCrow(pTask, g_pPlayerRect) ) {
    KillPlayer( g_pPlayerTask );
  }

	return( 0 );
}
Ejemplo n.º 5
0
void ATotemCharacter::ReduceHealth(float damage, ATotemPlayerController* player, AbilityType type, FName abilityName)
{
	if (PlayerHealth > 0 && HasAuthority() && !bInvincible)
	{
		PlayerHealth -= damage * DamageScale;


		ATotemCharacter* character = nullptr;

		if (type != AbilityType::NONE && type != AbilityType::End && player)
		{
			character = Cast<ATotemCharacter>(player->AcknowledgedPawn);
			PreviousHit.controller = player;
			PreviousHit.name = abilityName;
			PreviousHit.type = type;
			TimeSinceHit = InstigKillTimer;
		}
		else if (PlayerHealth <= 0)
		{
#if WRITE_METRICS
			ATotemPlayerController* control = Cast<ATotemPlayerController>(Controller);
			if (control)
			{
				ATotemPlayerState* state = Cast<ATotemPlayerState>(control->PlayerState);
				std::string team;
				switch (state->Team)
				{
				case ETeam::RED_TEAM:
					team = "Red";
					break;
				case ETeam::BLUE_TEAM:
					team = "Blue";
					break;
				default:
					team = "None";
					break;
				}
				Metrics::WriteToFile(std::string(TCHAR_TO_UTF8(*(state->MyName))), team, std::string("Died in lava"), std::string(), std::string(), std::string("Probably"));
				state->NumOfDie += 1;
			}
#endif
		}

		if (PlayerHealth <= 0)
		{
			PlayerHealth = 0;
			if (character)
			{
#if WRITE_METRICS
				if (type != AbilityType::NONE && type != AbilityType::End)
				{
					ATotemPlayerController* control = Cast<ATotemPlayerController>(Controller);
					if (control)
					{
						ATotemPlayerState* state = Cast<ATotemPlayerState>(control->PlayerState);
						ATotemPlayerState* attackerState = Cast<ATotemPlayerState>(player->PlayerState);
						if (state && attackerState)
						{
							std::string team;
							std::string attackerTeam;
							switch (state->Team)
							{
							case ETeam::RED_TEAM:
								team = "Red";
								break;
							case ETeam::BLUE_TEAM:
								team = "Blue";
								break;
							default:
								team = "None";
								break;
							}
							switch (attackerState->Team)
							{
							case ETeam::RED_TEAM:
								attackerTeam = "Red";
								break;
							case ETeam::BLUE_TEAM:
								attackerTeam = "Blue";
								break;
							default:
								attackerTeam = "None";
								break;
							}
							Metrics::WriteToFile(std::string(TCHAR_TO_UTF8(*(attackerState->MyName))), attackerTeam, std::string("Killed"), std::string(TCHAR_TO_UTF8(*(state->MyName))), team, std::string("Using: " + std::string(TCHAR_TO_UTF8(*(abilityName.ToString())))));
							// Player statistics part
							state->NumOfDie += 1;
							// Prevent count friendly kill
							if (team != attackerTeam)
							{
								attackerState->NumOfKill += 1;
							}							
						}
					}
				}
#endif
				ATotemPlayerController* controller = Cast<ATotemPlayerController>(GetController());
				if (controller && controller != player)
				{
					character->DealtDamageTo(nullptr, controller, player, true);
				}
			}
			else if (PreviousHit.controller)
			{
				////Tell controller to count the kill
				//ATotemCharacter* character = Cast<ATotemCharacter>(PreviousHit.controller->GetPawn());
				//if (character)
				//{
				//	ATotemPlayerController* controller = Cast<ATotemPlayerController>(GetController());
				//	if (controller)
				//	{
				//		character->DealtDamageTo(nullptr, controller, PreviousHit.controller, true);
				//	}
				//}
				//else
				//{
				//	//TODO: update score on the controller if previous hit player died in the meantime
				//}
				DeathToLava(PreviousHit.controller, PreviousHit.type);
				// Add kill and dead statistics, hopefully it will work
				ATotemPlayerState* AttackerState = Cast<ATotemPlayerState>(PreviousHit.controller->PlayerState);				
				if (Controller)
				{
					ATotemPlayerController* VictimController = Cast<ATotemPlayerController>(Controller);
					if (VictimController)
					{
						ATotemPlayerState* VictimState = Cast<ATotemPlayerState>(Controller->PlayerState);
						if (VictimState)
						{
							VictimState->NumOfDie += 1;
							if (AttackerState)
							{
								if (AttackerState->Team != VictimState->Team)
								{
									AttackerState += 1;
								}
							}
						}
					}
				}
				
#if WRITE_METRICS
				ATotemPlayerController* control = Cast<ATotemPlayerController>(Controller);
				if (control)
				{
					ATotemPlayerState* state = Cast<ATotemPlayerState>(control->PlayerState);
					ATotemPlayerState* attackerState = Cast<ATotemPlayerState>(PreviousHit.controller->PlayerState);
					if (state && attackerState)
					{
						std::string team;
						std::string attackerTeam;
						switch (state->Team)
						{
						case ETeam::RED_TEAM:
							team = "Red";
							break;
						case ETeam::BLUE_TEAM:
							team = "Blue";
							break;
						default:
							team = "None";
							break;
						}
						switch (attackerState->Team)
						{
						case ETeam::RED_TEAM:
							attackerTeam = "Red";
							break;
						case ETeam::BLUE_TEAM:
							attackerTeam = "Blue";
							break;
						default:
							attackerTeam = "None";
							break;
						}
						Metrics::WriteToFile(std::string(TCHAR_TO_UTF8(*(attackerState->MyName))), attackerTeam, std::string("Killed"), std::string(TCHAR_TO_UTF8(*(state->MyName))), team, std::string("Using: " + std::string(TCHAR_TO_UTF8(*(abilityName.ToString())))));
					}
				}
#endif
			}
			KillPlayer();
		}
		else if (character)
		{
			ATotemPlayerController* controller = Cast<ATotemPlayerController>(GetController());
			if (controller)
			{
				character->DealtDamageTo(nullptr, controller, player, false);
			}
		}
	}

	if (!bInvincible )
	{
		OnDamageTaken(player);

		DamageTakenBy(type, abilityName);
	}
}
Ejemplo n.º 6
0
static void PlayGame()
{
    Uint8 *keystate;
    int quit = 0;
    int turn;
    int prev_ticks = 0, cur_ticks = 0; /* for keeping track of timing */
    int awaiting_respawn = 0;

    /* framerate counter variables */
    int start_time, end_time;
    int frames_drawn = 0;

    /* respawn timer */
    int respawn_timer = -1;
	
    prev_ticks = SDL_GetTicks();
	
    start_time = time(NULL);

    /* Reset the score counters. */
    player.score = 0;
    opponent.score = 0;

    /* Start sound playback. */
    StartAudio();
    StartMusic();

    /* Start the music update thread. */
    music_update_thread = SDL_CreateThread(UpdateMusicThread, NULL);
    if (music_update_thread == NULL) {
	printf("Unable to start music update thread.\n");
    }

    /* Start the game! */
    while ((quit == 0) && network_ok) {

	/* Determine how many milliseconds have passed since
	   the last frame, and update our motion scaling. */
	prev_ticks = cur_ticks;
	cur_ticks = SDL_GetTicks();
	time_scale = (double)(cur_ticks-prev_ticks)/30.0;
				
	/* Update SDL's internal input state information. */
	SDL_PumpEvents();
		
	/* Grab a snapshot of the keyboard. */
	keystate = SDL_GetKeyState(NULL);

	/* Lock the mutex so we can access the player's data. */
	SDL_LockMutex(player_mutex);
		
	/* If this is a network game, take note of variables
	   set by the network thread. These are handled differently
	   for a scripted opponent. */
	if (opponent_type == OPP_NETWORK) {

	    /* Has the opponent respawned? */
	    if (network_opponent_respawn) {
		printf("Remote player has respawned.\n");
		opponent.shields = 100;
		network_opponent_respawn = 0;
		awaiting_respawn = 0;
	    }
		
	    /* Has the local player been hit? */
	    if (local_player_hit) {
		local_player_hit--;
		player.shields -= PHASER_DAMAGE;
		ShowPhaserHit(&player);
				/* No need to check for death, the
				   other computer will tell us. */
	    }
		}

	/* Update phasers. */
	player.firing -= time_scale;
	if (player.firing < 0) player.firing = 0;
	opponent.firing -= time_scale;
	if (opponent.firing < 0) opponent.firing = 0;
	ChargePhasers(&player);

	/* If the local player is destroyed, the respawn timer will
	   start counting. During this time the controls are disabled
	   and explosion sequence occurs. */
	if (respawn_timer >= 0) {
	    respawn_timer++;

	    if (respawn_timer >= ((double)RESPAWN_TIME / time_scale)) {
		respawn_timer = -1;
		InitPlayer(&player);

				/* Set the local_player_respawn flag so the
				   network thread will notify the opponent
				   of the respawn. */
		local_player_respawn = 1;

		SetStatusMessage("GOOD LUCK, WARRIOR!");
	    }
	}

	/* Respond to input and network events, but not if we're in a respawn. */
	if (respawn_timer == -1) {
	    if (keystate[SDLK_q] || keystate[SDLK_ESCAPE]) quit = 1;
			
	    /* Left and right arrow keys control turning. */
	    turn = 0;
	    if (keystate[SDLK_LEFT]) turn += 10;
	    if (keystate[SDLK_RIGHT]) turn -= 10;
			
	    /* Forward and back arrow keys activate thrusters. */
	    player.accel = 0;
	    if (keystate[SDLK_UP]) player.accel = PLAYER_FORWARD_THRUST;
	    if (keystate[SDLK_DOWN]) player.accel = PLAYER_REVERSE_THRUST;
			
	    /* Spacebar fires phasers. */
	    if (keystate[SDLK_SPACE]) {

		if (CanPlayerFire(&player)) {

		    FirePhasers(&player);

		    /* If it's a hit, either notify the opponent
		       or exact the damage. Create a satisfying particle
		       burst. */
		    if (!awaiting_respawn &&
			CheckPhaserHit(&player,&opponent)) {

			ShowPhaserHit(&opponent);
			DamageOpponent();

			/* If that killed the opponent, set the
			   "awaiting respawn" state, to prevent multiple
			   kills. */
			if (opponent.shields <= 0 &&
			    opponent_type == OPP_NETWORK)
			    awaiting_respawn = 1;
       		    }
		}
	    }
			
	    /* Turn. */
	    player.angle += turn * time_scale;
	    if (player.angle < 0) player.angle += 360;
	    if (player.angle >= 360) player.angle -= 360;

	    /* If this is a network game, the remote player will
	       tell us if we've died. Otherwise we have to check
	       for failed shields. */
	    if (((opponent_type == OPP_NETWORK) && local_player_dead) ||
		(player.shields <= 0))
	    {
		printf("Local player has been destroyed.\n");
		local_player_dead = 0;
				
		/* Kaboom! */
		KillPlayer();
				
		/* Respawn. */
		respawn_timer = 0;
	    }
	}

	/* If this is a player vs. computer game, give the computer a chance. */
	if (opponent_type == OPP_COMPUTER) {
	    if (RunGameScript() != 0) {
		fprintf(stderr, "Ending game due to script error.\n");
		quit = 1;
	    }
			
	    /* Check for phaser hits against the player. */
	    if (opponent.firing) {
		if (CheckPhaserHit(&opponent,&player)) {
					
		    ShowPhaserHit(&player);
		    player.shields -= PHASER_DAMAGE;

		    /* Did that destroy the player? */
		    if (respawn_timer < 0 && player.shields <= 0) {
			KillPlayer();
			respawn_timer = 0;
		    }
		}
	    }

	    ChargePhasers(&opponent);
	    UpdatePlayer(&opponent);
	}

	/* Update the player's position. */
	UpdatePlayer(&player);

	/* Update the status information. */
	SetPlayerStatusInfo(player.score, player.shields, player.charge);
	SetOpponentStatusInfo(opponent.score, opponent.shields);

	/* Make the camera follow the player (but impose limits). */
	camera_x = player.world_x - SCREEN_WIDTH/2;
	camera_y = player.world_y - SCREEN_HEIGHT/2;
		
	if (camera_x < 0) camera_x = 0;
	if (camera_x >= WORLD_WIDTH-SCREEN_WIDTH)
	    camera_x = WORLD_WIDTH-SCREEN_WIDTH-1;
	if (camera_y < 0) camera_y = 0;
	if (camera_y >= WORLD_HEIGHT-SCREEN_HEIGHT)
	    camera_y = WORLD_HEIGHT-SCREEN_HEIGHT-1;

	/* Update the particle system. */
	UpdateParticles();

	/* Keep OpenAL happy. */
	UpdateAudio(&player, &opponent);
				
	/* Redraw everything. */
	DrawBackground(screen, camera_x, camera_y);
	DrawParallax(screen, camera_x, camera_y);
	DrawParticles(screen, camera_x, camera_y);
	if (opponent.firing)
	    DrawPhaserBeam(&opponent, screen, camera_x, camera_y);
	if (player.firing)
	    DrawPhaserBeam(&player, screen, camera_x, camera_y);

	if (respawn_timer < 0)
	    DrawPlayer(&player);
	if (!awaiting_respawn)
	    DrawPlayer(&opponent);
	UpdateStatusDisplay(screen);
		
	/* Release the mutex so the networking system can get it.
	   It doesn't stay unlocked for very long, but the networking
	   system should still have plenty of time. */
	SDL_UnlockMutex(player_mutex);
	
	/* Flip the page. */
	SDL_Flip(screen);

	frames_drawn++;
    }

    end_time = time(NULL);
    if (start_time == end_time) end_time++;

    /* Display the average framerate. */
    printf("Drew %i frames in %i seconds, for a framerate of %.2f fps.\n",
	   frames_drawn,
	   end_time-start_time,
	   (float)frames_drawn/(float)(end_time-start_time));


    /* Terminate the music update thread. */
    if (music_update_thread != NULL) {
	SDL_KillThread(music_update_thread);
	music_update_thread = NULL;
    }
	
    /* Stop audio playback. */
    StopAudio();
    StopMusic();
}
void EntityManager::handleCollisions()
{
    // Evade from other enemies.
    for(std::list<Enemy*>::iterator i = m_enemies.begin(); i != m_enemies.end(); i++)
    {
        for(std::list<Enemy*>::iterator j = m_enemies.begin(); j != m_enemies.end(); j++)
        {
            if(isColliding(*i, *j))
            {
                (*i)->handleCollision(*j);
                (*j)->handleCollision(*i);
            }
        }
    }

    // Determine shot enemies.
    for(std::list<Enemy*>::iterator i = m_enemies.begin(); i != m_enemies.end(); i++)
    {
        for(std::list<Bullet*>::iterator j = m_bullets.begin(); j != m_bullets.end(); j++)
        {
            if(isColliding(*i, *j))
            {
                (*i)->wasShot();
                (*i)->setExpired();
            }
        }
    }

    // Determine enemy crashing into player.
    for(std::list<Enemy*>::iterator i = m_enemies.begin(); i != m_enemies.end(); i++)
    {
        if(isColliding(*i, PlayerShip::getInstance()) && (*i)->getIsActive())
        {
            PlayerShip::getInstance()->kill();

            for(std::list<Enemy*>::iterator j = m_enemies.begin(); j != m_enemies.end(); j++)
            {
                (*j)->wasShot();
            }

            EnemySpawner::getInstance()->reset();
            break;
        }
    }

    // Determine enemy crashing into player.
    for(std::list<BlackHole *>::iterator i = m_blackHoles.begin(); i != m_blackHoles.end(); i++)
    {
        // Kill enemies in the way.
        for(std::list<Enemy*>::iterator j = m_enemies.begin();
            j != m_enemies.end();
            j++)
        {
            if((*j)->getIsActive() && isColliding(*i, *j))
            {
                (*j)->wasShot();
            }
        }

        // Kill bullets in the way.
        for(std::list<Bullet*>::iterator j = m_bullets.begin();
            j != m_bullets.end();
            j++)
        {
            if(isColliding(*i, *j))
            {
                (*j)->setExpired();
                (*i)->wasShot();
            }
        }

        // Kill player if collide.
        if(isColliding(PlayerShip::getInstance(), *i))
        {
            KillPlayer();
        }
    }
}