Exemple #1
0
bool ActorFactory::AddActorCreatorFromOneDesc( Json::Value& ActorsDesc, ActorCreatorMap_t& actorCreators )
{
    std::auto_ptr<ActorCreator> actorCreator( new ActorCreator() );
    std::string nameStr;
    if( !Json::GetStr( ActorsDesc["name"], nameStr ) )
    {
        return false;
    }
    actorCreator->SetId( AutoId( nameStr ) );
    Json::Value& components = ActorsDesc["components"];
    if ( !components.isArray() )
    {
        return false;
    }
    if ( components.empty() )
    {
        return true;
    }
    for( Json::Value::iterator i = components.begin(), e = components.end(); i != e; ++i )
    {
        Json::Value& component = *i;
        std::string compName;
        if ( !Json::GetStr( component["name"], compName ) )
        {
            return false;
        }
        Json::Value& setters = component["set"];
        actorCreator->AddComponent( AutoId( compName ), setters );
    }
    int32_t actorCreatorId = actorCreator->GetId();
    actorCreators.insert( actorCreatorId, actorCreator );
    return true;
}
Exemple #2
0
RoomProperty::RoomProperty()
{
    mIdToRoomPropertyMap.insert( IdToRoomPropertyMap_t::value_type( AutoId( "start" ), RoomProperty::Start ) );
    mIdToRoomPropertyMap.insert( IdToRoomPropertyMap_t::value_type( AutoId( "end" ), RoomProperty::End ) );
    mIdToRoomPropertyMap.insert( IdToRoomPropertyMap_t::value_type( AutoId( "key" ), RoomProperty::Key ) );
    mIdToRoomPropertyMap.insert( IdToRoomPropertyMap_t::value_type( AutoId( "chest" ), RoomProperty::Chest ) );
}
Exemple #3
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() );
    }
}
Exemple #4
0
EntranceType::EntranceType()
{
    mIdToEntranceTypeMap.insert(IdToEntranceTypeMap_t::value_type(AutoId("top"),EntranceType::Top));
    mIdToEntranceTypeMap.insert(IdToEntranceTypeMap_t::value_type(AutoId("right"),EntranceType::Right));
    mIdToEntranceTypeMap.insert(IdToEntranceTypeMap_t::value_type(AutoId("bottom"),EntranceType::Bottom));
    mIdToEntranceTypeMap.insert(IdToEntranceTypeMap_t::value_type(AutoId("left"),EntranceType::Left));
}
Exemple #5
0
GridRepo::GridRepo()
    : Repository<IGrid>( mDefault )
{
    int32_t id = AutoId( "absolute" );
    mElements.insert( id, new AbsoluteGrid( AutoId( "absolute" ) ) );
    id = AutoId( "matrix" );
    mElements.insert( id, new MatrixGrid( AutoId( "matrix" ) ) );
}
Exemple #6
0
ActorFactory::ActorFactory()
{
    Init();
    //every created actor is handled the same way.
    //actorCreators create actors from json data files.
    Bind( AutoId( "default_actor" ), boost::bind( &ActorFactory::CreateActor, this, _1 ) );
    SetDefault( AutoId( "default_actor" ) );
}
void LinkMapElement::Load( Json::Value& setters )
{
    MapElement::Load( setters );
    Json::Value const& targetOutput = setters["from"];
    if( !targetOutput.isObject() )
    {
        return;
    }
    Json::Value const& targetInput = setters["to"];
    if( !targetInput.isObject() )
    {
        return;
    }

    std::string targetOutputName;
    if ( !Json::GetStr( targetOutput["identifier"], targetOutputName ) )
    {
        return;
    }
    mTargetOutputUID = AutoId( targetOutputName );
    std::string targetOutputNodeName;
    if ( Json::GetStr( targetOutput["node"], targetOutputNodeName ) )
    {
        mTargetOutputNodeId = AutoId( targetOutputNodeName );
    }
    else if ( Json::GetInt( targetOutput["node"], mTargetOutputNodeOrdinal ) )
    {
        //ok it was a numeric
    }
    else
    {
        mTargetOutputNodeOrdinal = 0; //first node by default
    }




    std::string targetInputName;
    if ( !Json::GetStr( targetInput["identifier"], targetInputName ) )
    {
        return;
    }
    mTargetInputUID = AutoId( targetInputName );
    std::string targetInputNodeName;
    if ( Json::GetStr( targetInput["node"], targetInputNodeName ) )
    {
        mTargetInputNodeId = AutoId( targetInputNodeName );
    }
    else if ( Json::GetInt( targetInput["node"], mTargetInputNodeOrdinal ) )
    {
        //ok it was a numeric
    }
    else
    {
        mTargetInputNodeOrdinal = 0; //first node by default
    }
}
void SoldierSpawnTarget::PutTarget( glm::vec2 position )
{
    std::auto_ptr<MapElement> mapElement( MapElementFactory::Get()( AutoId( "soldier_spawn_point" ) ) );
    Opt<SoldierSpawnPointMapElement> soldierSpawn( static_cast<SoldierSpawnPointMapElement*>( mapElement.get() ) );
    soldierSpawn->SetX( position.x );
    soldierSpawn->SetY( position.y );
    int32_t nextIndex = MapSystem::GetNextUniqueSpawnIndex( "s" );
    soldierSpawn->SetIdentifier( AutoId( "s" + std::to_string( nextIndex ) ) );
    EditorSoldierSpawnSystem::Spawn( soldierSpawn );
    MapSystem::Get()->GetMapElementList().insert( Opt<MapElement>( mapElement.release() ) );
}
Exemple #9
0
void WallTarget::PutTarget( glm::vec2 position )
{
    std::auto_ptr<MapElement> mapElement( MapElementFactory::Get()( AutoId( "spawn_actor" ) ) );
    Opt<SpawnActorMapElement> spawnActor( static_cast<SpawnActorMapElement*>( mapElement.get() ) );
    spawnActor->GetInputNodeId( SpawnActorMapElement::SpawnNodeId() )( 1 );

    AddPositionLoader( position, spawnActor );

    spawnActor->SetActorID( EditorTargetSystem::Get()->GetTarget().GetActorId() );
    mapElement->SetUID( AutoId( "spawn_at_start" ) );
    MapSystem::Get()->GetMapElementList().insert( Opt<MapElement>( mapElement.release() ) );
}
CloakNormalItemSubSystem::CloakNormalItemSubSystem()
    : mScene( Scene::Get() )
    , mNormalItemSubSystem( NormalItemSubSystem::Get() )
    , mActorFactory( ActorFactory::Get() )
    , mProjectileId( AutoId( "CloakBuff" ) )
{
}
SoldierSpawnSystem::SoldierSpawnSystem()
    : mScene( Scene::Get() )
    , mProgramState( core::ProgramState::Get() )
    , mActorFactory( ActorFactory::Get() )
    , mPlayerAutoId( AutoId( "player" ) )
{
}
void InventoryComponentLoader::BindValues()
{
    std::string istr;
    auto const& addItem = (*mSetters)["add_item"];
    if (addItem.isArray())
    {
        for (auto&& item : addItem)
        {
            if (item.isString())
            {
                Bind<int32_t>( static_cast<Opt<Item> (InventoryComponent::*)(int32_t)>(&InventoryComponent::AddItem), AutoId( item.asString() ) );
            }
        }
    }
    else
    {
        if (Json::GetStr( (*mSetters)["add_item"], istr ))
        {
            Bind<int32_t>( static_cast<Opt<Item> (InventoryComponent::*)(int32_t)>(&InventoryComponent::AddItem), AutoId( istr ) );
        }
    }
    if (Json::GetStr( (*mSetters)["select_weapon"], istr ))
    {
        Bind<int32_t>( (
            std::bind( 
                std::bind(
                    &InventoryComponent::SetSelectedItem,std::placeholders::_1, std::placeholders::_2, std::placeholders::_3,true ), 
                std::placeholders::_1,ItemType::Weapon, std::placeholders::_2)), 
            AutoId( istr ));
    }
    Bind( "pickup_items", func_bool( &InventoryComponent::SetPickupItems ) );
    Bind( "collect_dark_matter", func_bool( &InventoryComponent::SetCollectDarkMatter ) );
}
void EmitterComponentLoader::BindValues()
{
    EmitterComponent::EmitDescs descs;
    Json::Value const& json = ( *mSetters )["emit_descs"];
    if( !json.isArray() )
    {
        return;
    }
    for( Json::Value::iterator i = json.begin(), e = json.end(); i != e; ++i )
    {
        Json::Value& part = *i;
        EmitterComponent::EmitDesc d;
        Json::GetDouble( part["delay"], d.mDelay );
        Json::GetDouble( part["delay_variance"], d.mDelayVariance );
        Json::GetDouble( part["probability"], d.mProbability );
        std::string str;
        Json::GetStr( part["emit_type"], str );
        d.mEmitType = AutoId( str );
        Json::GetInt( part["iteration"], d.mIteration );
        Json::GetInt( part["iteration_variance"], d.mIterationVariance );
        descs.push_back( d );
    }
    Bind<EmitterComponent::EmitDescs>( &EmitterComponent::InitEmitDescs, descs );
    //Add( boost::lambda::_1 ->* &EmitterComponent::mEmitDescs = descs );
}
Exemple #14
0
void TextureRepo::Init()
{
    PathVect_t Paths;
    mFilesys.GetFileNames( Paths, "textures" );
    for( PathVect_t::const_iterator i = Paths.begin(), e = Paths.end(); i != e; ++i )
    {
        boost::filesystem::path const& Path = *i;
        if( Path.extension().string() != ".png" )
        {
            continue;
        }
        AutoFile TexFile = mFilesys.Open( Path );
        if( !TexFile.get() )
        {
            continue;
        }
        PngTexture Png( *TexFile );
        if( !Png.IsValid() )
        {
            continue;
        }
        Texture* Tex = new Texture( Png.GetWidth(), Png.GetHeight(), Png.GetChannels(), Png.GetData() );
        int32_t Id = AutoId( Path.generic_string() );
        mElements.insert( Id, Tex );
    }
}
void CtfSoldierSpawnPointMapElement::Load( Json::Value& setters )
{
    MapElement::Load( setters );
    Json::Value const& position = setters["position"];
    if( !position.isObject() )
    {
        return;
    }
    int32_t x;
    if ( !Json::GetInt( position["x"], x ) )
    {
        return;
    }
    SetX( x );
    int32_t y;
    if ( !Json::GetInt( position["y"], y ) )
    {
        return;
    }
    SetY( y );
    std::string teamStr;
    if ( !Json::GetStr( setters["team"], teamStr ) )
    {
        return;
    }
    SetTeam( Team::Get()( AutoId( teamStr ) ) );

}
Exemple #16
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() );
}
Exemple #17
0
void MapElement::Load( Json::Value& setters )
{
    std::string identifier;
    if ( Json::GetStr( setters["identifier"], identifier ) )
    {
        mIdentifier = AutoId( identifier );
    }
}
Exemple #18
0
void IRoom::PlaceSoldierSpawnPoint( RoomDesc &roomDesc, glm::vec2 pos )
{
    std::auto_ptr<MapElement> mapElement( MapElementFactory::Get()(AutoId( "soldier_spawn_point" )) );
    Opt<SoldierSpawnPointMapElement> ctfSoldierSpawn( static_cast<SoldierSpawnPointMapElement*>(mapElement.get()) );
    ctfSoldierSpawn->SetX( pos.x );
    ctfSoldierSpawn->SetY( pos.y );
    MapSystem::Get()->GetMapElementList().insert( Opt<MapElement>( mapElement.release() ) );
}
PickupProfilesRepo::PickupProfilesRepo()
    : Repository<PickupProfile>( mDefault )
    , mDefault( -1, Json::Value() )
{
    fs_utils::for_each( "misc/pickup_profiles", ".json", [&]( Json::Value const& desc )
    {
        int32_t Idx = AutoId( desc["name"].asString() );
        mElements.insert( Idx, new PickupProfile( Idx, desc ) );
    } );
}
void IdleActionRenderer::FillRenderableSprites( const Actor& actor, IRenderableComponent const& renderableC, RenderableSprites_t& renderableSprites )
{
    if( nullptr != mSpr )
    {
        SpritePhase const& Phase = (*mSpr)( ( int32_t )GetState() );
        glm::vec4 col = GetCloakColor( actor ) * GetColor( actor );
        static int32_t aid = AutoId( "body_idle" );
        renderableSprites.push_back( RenderableSprite( &actor, &renderableC, aid, mSpr, &Phase, col ) );
    }
}
Exemple #21
0
void WallTarget::AddPositionLoader( glm::vec2& position, Opt<SpawnActorMapElement> spawnActor )
{
    int32_t componentId = AutoId( "position_component" );
    ComponentLoaderFactory& componentLoaderFactory = ComponentLoaderFactory::Get();
    std::auto_ptr<PropertyLoaderBase<Component> > compLoader = componentLoaderFactory( componentId );
    Opt<PositionComponentLoader> positionCompLoader( static_cast<PositionComponentLoader*>( compLoader.get() ) );
    positionCompLoader->Bind<double>( &PositionComponent::SetX, position.x );
    positionCompLoader->Bind<double>( &PositionComponent::SetY, position.y );
    spawnActor->AddComponentLoader( componentId, compLoader );
}
Exemple #22
0
void WeaponLoader::BindValues()
{
    L2( "Bind Weapon values \n" );
    Bind( "shoot_cooldown", func_double( &Weapon::SetShootCooldown ) );
    Bind( "shoot_alt_cooldown", func_double( &Weapon::SetShootAltCooldown ) );
    Bind( "bullets", func_double( &Weapon::SetBullets ) );
    Bind( "bullets", func_double( &Weapon::SetBulletsMax ) );
    Bind( "shot_cost", func_int32_t( &Weapon::SetShotCost ) );
    Bind( "shot_cost_alt", func_int32_t( &Weapon::SetShotCostAlt ) );
    Bind( "reload_time", func_double( &Weapon::SetReloadTimeMax ) );
    Bind( "static_reload", func_double( &Weapon::SetStaticReload ) );
    Bind( "position_x", func_double(&Weapon::SetPositionX));
    Bind( "position_y", func_double(&Weapon::SetPositionY));
    std::string istr;
    if (Json::GetStr((*mSetters)["muzzle"], istr))
    {
        Bind<int32_t>(&Weapon::SetMuzzleId, AutoId(istr));
    }
    if (Json::GetStr((*mSetters)["muzzle_alt"], istr))
    {
        Bind<int32_t>(&Weapon::SetMuzzleAltId, AutoId(istr));
    }

    Scatter scatter;
    Json::GetDouble( ( *mSetters )["scatter_increase"], scatter.mIncrease );
    Json::GetDouble( ( *mSetters )["scatter_alt_increase"], scatter.mAltIncrease );
    Json::GetDouble( ( *mSetters )["scatter_chill"], scatter.mChill );
    Json::GetDouble( ( *mSetters )["scatter_magic_number"], scatter.mMagicNumber );
    L2( "Scatter in: %f %f %f %f", scatter.mIncrease, scatter.mAltIncrease, scatter.mChill, scatter.mMagicNumber );
    Bind<Scatter>( &Weapon::SetScatter, scatter );
    if (Json::GetStr( (*mSetters)["shot"], istr ))
    {
        Bind<int32_t>( &Weapon::SetShotId, AutoId( istr ) );
    }
    if (Json::GetStr( (*mSetters)["shot_alt"], istr ))
    {
        Bind<int32_t>( &Weapon::SetShotAltId, AutoId( istr ) );
    }
    Limited<double> sumBullets;
    sumBullets.Load( (*mSetters)["sum_bullets"] );
    Bind<Limited<double>>(&Weapon::InitSumBullets, sumBullets);
}
bool SoldierSpawnTarget::Load( const Json::Value& setters )
{
    std::string cursor_id;
    if( !Json::GetStr(setters["cursor_id"], cursor_id))
    {
        L1("Error retrieving 'cursor_id' \n" );
        return false;
    }
    mCursorId = AutoId( cursor_id );
    return true;
}
Exemple #24
0
bool MapSystem::AddMapElementFromOneTextureDesc( Json::Value& mapElementDesc )
{
    std::string name;
    if ( !Json::GetStr( mapElementDesc["name"], name ) )
    {
        return false;
    }
    std::auto_ptr<MapElement> mapElement( mMapElementFactory( AutoId( name ) ) );
    mapElement->Load( mapElementDesc );
    mMapElementHolder.mAllMapElements.insert( Opt<MapElement>( mapElement.release() ) );
    return true;
}
Exemple #25
0
void WallTarget::AddBorderLoader( IBorderComponent::Borders_t& borders, IBorderComponent::Borders_t& outerBorders, Opt<SpawnActorMapElement> spawnActor )
{
    {
        int32_t componentId = AutoId( "border_component" );
        ComponentLoaderFactory& componentLoaderFactory = ComponentLoaderFactory::Get();
        std::auto_ptr<PropertyLoaderBase<Component> > compLoader = componentLoaderFactory( componentId );
        Opt<BorderComponentLoader> borderCompLoader( static_cast<BorderComponentLoader*>( compLoader.get() ) );
        borderCompLoader->Bind<IBorderComponent::Borders_t>( &BorderComponent::SetBorders, borders );
        borderCompLoader->Bind<IBorderComponent::Borders_t>( &BorderComponent::SetOuterBorders, outerBorders );
        spawnActor->AddComponentLoader( componentId, compLoader );
    }
}
void LevelGeneratorMapElement::Load( Json::Value const& setters )
{
    MapElement::Load( setters );
    std::string identifier;
    if (Json::GetStr( setters["generator_name"], identifier ))
    {
        mGeneratorId = AutoId( identifier );
    }
    static LevelGeneratorFactory& levelGeneratorFactory = LevelGeneratorFactory::Get();
    auto generator = levelGeneratorFactory( mGeneratorId );
    generator->Load( setters["properties"] );
    mLevelGenerator.reset( generator.release() );
    AddInputNodeId( GeneratorNodeId() );
}
void ExplodeOnHitComponentLoader::BindValues()
{
    std::string istr;
    if( Json::GetStr( ( *mSetters )["explosion_projectile"], istr ) )
    {
        Bind<int32_t>( &ExplodeOnHitComponent::SetExplosionProjectile, AutoId( istr ) );
    }
    Bind( "count", func_int32_t( &ExplodeOnHitComponent::SetCount ) );
    Bind( "scatter", func_double( &ExplodeOnHitComponent::SetExplosionScatter ) );

    if( Json::GetStr( ( *mSetters )["detonator_material"], istr ) )
    {
        Bind<int32_t>( &ExplodeOnHitComponent::SetDetonatorMaterial, AutoId( istr ) );
    }
    if( Json::GetStr( ( *mSetters )["distribution"], istr ) )
    {
        Bind<ExplodeDistributionType::Type>( &ExplodeOnHitComponent::SetDistribution, mExplodeDistributionType( AutoId( istr ) ) );
    }
    Bind( "secs_to_end_variance", func_double( &ExplodeOnHitComponent::SetSecsToEndVariance ) );
    Bind( "position_variance", func_int32_t( &ExplodeOnHitComponent::SetPositionVariance ) );
    Bind( "speed_variance", func_double( &ExplodeOnHitComponent::SetSpeedVariance ) );
    Bind( "add_actor_radius", func_bool( &ExplodeOnHitComponent::SetAddActorRadius ) );
}
void IdleActionRenderer::Init( const Actor& actor )
{
    int32_t actorId = actor.GetId();
    auto renderableC( actor.Get<IRenderableComponent>() );
    actorId = GetSpriteId( renderableC->GetSpriteIndex(), actorId );
    
    SpriteCollection const& Sprites = mRenderableRepo( actorId );
    static int32_t aid = AutoId( "body_idle" );
    Sprite const& Spr = Sprites( aid );
    if( Spr.IsValid() )
    {
        mSpr = &Spr;
        mSecsToEnd = Spr.GetSecsToEnd();
    }
}
void RespawnActorMapElement::Load( Json::Value& setters )
{
    MapElement::Load( setters );

    std::string actorStr;
    if ( !Json::GetStr( setters["actor"], actorStr ) )
    {
        return;
    }
    SetActorID( AutoId( actorStr ) );

    SpawnActorMapElement::LoadComponentLoaders( setters, mComponentLoaders );

    Json::GetDouble( setters["secs_to_respawn"], mSecsToRespawn );
    mSecsToRespawnOriginal = mSecsToRespawn;
}
void GroupMapElement::Load( Json::Value& setters )
{
    MapElement::Load( setters );
    mTargets.clear();
    auto const& targets = setters["targets"];
    if (targets.isArray())
    {
        for (auto& target : targets)
        {
            if (target.isString())
            {
                mTargets.insert( AutoId( target.asString() ) );
            }
        }
    }
}