Beispiel #1
0
void FreeForAllGameModeSystem::OnStartGameMode( core::StartGameModeEvent const& Evt )
{
    if ( Evt.mMode != "ffa" )
    {
        return;
    }
    ::engine::Engine::Get().SetEnabled< ::engine::SoldierSpawnSystem>( true );
    ::engine::Engine::Get().SetEnabled< ::engine::ctf::CtfSoldierSpawnSystem>( false );
    ::engine::Engine::Get().SetEnabled< ::map::EditorSoldierSpawnSystem>( false );
    ::engine::Engine::Get().SetEnabled< ::map::RoomEditorSystem>( false );
    ::engine::Engine::Get().SetEnabled< ::map::EditorSystem>( false );
    ::engine::Engine::Get().SetEnabled< ::map::EditorTargetSystem>( false );
    ::engine::Engine::Get().SetEnabled< ::map::EditorGridSystem>( false );
    ::engine::Engine::Get().SetEnabled< ::map::EditorBrushSystem>( false );
    ::engine::Engine::Get().SetEnabled< ::core::FreeForAllGameModeSystem>( true );
    ::engine::Engine::Get().SetEnabled< ::core::CaptureTheFlagGameModeSystem>( false );
    ::engine::Engine::Get().SetEnabled< ::core::RogueGameModeSystem>( false );

    auto levelSelectionSystem = engine::Engine::Get().GetSystem<LevelSelectionSystem>();
    if ( levelSelectionSystem.IsValid() )
    {
        mScene.Load( levelSelectionSystem->GetSelectedLevel() );
    }
    else
    {
        L1("failed to retrieve LevelSelectionSystem\n");
        return;
    }
    //    glfwSetInputMode(engine::Engine::Get().GetSystem<engine::WindowSystem>()->GetWindow(),GLFW_CURSOR,GLFW_CURSOR_HIDDEN);
    Ui::Get().Load( "hud" );
    if ( ProgramState::Get().mMode == ProgramState::Client )
    {
        return;
    }

    if ( ProgramState::Get().mMode != ProgramState::Local )
    {
        return;
    }

    std::auto_ptr<Actor> Pl;
    for( int i = 0; i < 11; ++i )
    {
        Pl = ActorFactory::Get()( AutoId( "player" ) );

        Opt<IPositionComponent> positionC = Pl->Get<IPositionComponent>();
        positionC->SetX( -240 + i * 60 );
        positionC->SetY( 0.0 );
        Pl->Get<IInventoryComponent>();
        Opt<IInventoryComponent> inventoryC = Pl->Get<IInventoryComponent>();
        inventoryC->AddItem( AutoId( "plasma_gun" ) );
        inventoryC->SetSelectedWeapon( AutoId( "plasma_gun" ) );
        Opt<PlayerControllerComponent> pcc( Pl->Get<IControllerComponent>() );
        pcc->SetEnabled( false );
        pcc->mActive = false;
        pcc->mControllerId = i;
        Pl->Get<IMoveComponent>()->SetMoving( false );
        mScene.AddActor( Pl.release() );
    }
}
Beispiel #2
0
void IRoom::PlaceLevelEndPoint( RoomDesc &roomDesc, glm::vec2 pos )
{
    auto endPoint = ActorFactory::Get()( AutoId( "platform" ) );
    Opt<IPositionComponent> positionC = endPoint->Get<IPositionComponent>();
    positionC->SetX( pos.x );
    positionC->SetY( pos.y );
    mScene.AddActor( endPoint.release() );
}
std::auto_ptr<Actor> SoldierSpawnSystem::Spawn( core::ClientData& clientData, map::SpawnPoint spawnPoint, std::auto_ptr<Actor> player )
{
    Opt<Actor> clientActor( mScene.GetActor( clientData.mClientActorGUID ) );
    if( clientActor.IsValid() )
    {
        Opt<IHealthComponent> healthC = clientActor->Get<IHealthComponent>();
        if ( healthC.IsValid() && healthC->IsAlive() )
        {
            L1( "Cannot spawn soldier for clientData (%s) current soldier still alive!\n", clientData.mClientName.c_str() );
            return std::auto_ptr<Actor>();
        }
    }
    else
    {
        L2( "No actor for clientData(%s). (it might be an error on revive)\n", clientData.mClientName.c_str() );
    }
    L2( "player is valid %d", player.get() );
    Opt<IPositionComponent> positionC = player->Get<IPositionComponent>();
    L2( "positionC is valid %d", positionC.IsValid() );
    positionC->SetX( spawnPoint.mX );
    positionC->SetY( spawnPoint.mY );

    //TODO: temporary till normal inventory sync
//     Opt<IInventoryComponent> inventoryC = player->Get<IInventoryComponent>();
//     if ( inventoryC.IsValid() )
//     {
//         inventoryC->SetSelectedWeapon( AutoId( "pistol" ) );
//     }

    Opt<PlayerControllerComponent> playerControllerC( player->Get<IControllerComponent>() );
    if ( playerControllerC.IsValid() )
    {
        playerControllerC->mControllerId = clientData.mClientId;
        if ( mProgramState.mControlledActorGUID == clientData.mClientActorGUID
             && mProgramState.mMode != core::ProgramState::Server )
        {
            playerControllerC->SetEnabled( true );
            playerControllerC->mActive = true;
            mProgramState.mControlledActorGUID = player->GetGUID();
        }
    }
    clientData.mClientActorGUID = player->GetGUID(); //TODO: might seek for a better place
    L2( "player created clientId:%d clientName:%s actorId:%d\n", clientData.mClientId, clientData.mClientName.c_str(), clientData.mClientActorGUID );

    if ( mProgramState.mMode != core::ProgramState::Server &&
         mProgramState.mClientDatas.begin()->mClientActorGUID == player->GetGUID() )
    {
        Scene::Get().SetPlayerModels( Opt<Actor>( player.get() ) );
    }
    EventServer<SoldierCreatedEvent>::Get().SendEvent( SoldierCreatedEvent( clientData, Opt<Actor>( player.get() ) ) );
    return player;
}
Beispiel #4
0
void FlashMessageHandlerSubSystem::Execute( Message const& message )
{
    FlashMessage const& msg = static_cast<FlashMessage const&>( message );
    Opt<Actor> actor = mScene.GetActor( msg.mActorGUID );
    if ( !actor.IsValid() )
    {
        L1( "cannot find actor with GUID: (%s) %d \n", __FUNCTION__, msg.mActorGUID );
        return;
    }
    Opt<IPositionComponent> positionC = actor->Get<IPositionComponent>();
    if ( !positionC.IsValid() )
    {
        return;
    }
    positionC->SetX( msg.mX / PRECISION );
    positionC->SetY( msg.mY / PRECISION );
}
void WeaponItemSubSystem::SetProjectilePosition(Actor& projectile, Actor& actor)
{
    Opt<IPositionComponent> projPositionC = projectile.Get<IPositionComponent>();
    Opt<IPositionComponent> actorPositionC = actor.Get<IPositionComponent>();
    glm::vec2 rvec(0.0, 0.0);
    Opt<IInventoryComponent> inventoryC = actor.Get<IInventoryComponent>();
    if (inventoryC.IsValid())
    {
        Opt<Weapon> weapon = inventoryC->GetSelectedWeapon();
        if (weapon.IsValid())
        {
            rvec.x += weapon->GetPositionX();
            rvec.y -= weapon->GetPositionY();
        }
    }
    rvec=glm::rotate(rvec, float(actorPositionC->GetOrientation()));
    projPositionC->SetX( projPositionC->GetX() + actorPositionC->GetX() + rvec.x );
    projPositionC->SetY( projPositionC->GetY() + actorPositionC->GetY() + rvec.y );
}