Exemplo n.º 1
0
bool Career::getLicensedFlag(void)
{
    GameData* gameData = getGameData( "LCF" );
    if( !gameData )
    {
        gameData = new GameData( sizeof(bool) );
        *reinterpret_cast<bool*>(gameData->getData()) = false;
        addGameData( "LCF", gameData );
    }
    return *reinterpret_cast<bool*>(gameData->getData());
}
Exemplo n.º 2
0
bool Career::getHomePlacementFlag(void)
{
    GameData* gameData = getGameData( "HPF" );
    if( !gameData )
    {
        gameData = new GameData( sizeof(bool) );
        *reinterpret_cast<bool*>(gameData->getData()) = false;
        addGameData( "HPF", gameData );
    }
    return *reinterpret_cast<bool*>(gameData->getData());
}
Exemplo n.º 3
0
bool Career::getAcrobaticsSkill(Acrobatics skill)
{
    GameData* gameData = getGameData( actobaticsGameData );
    if( !gameData )
    {
        // create gamedata for acrobatics and reset its contents
        gameData = new GameData( sizeof(unsigned int) );
        memset( gameData->getData(), 0, gameData->getSize() );
        addGameData( actobaticsGameData, gameData );
    }
    unsigned int bitset = *reinterpret_cast<unsigned int*>( gameData->getData() );
    return ( bitset & skill ) != 0;
}
Exemplo n.º 4
0
void Career::setAcrobaticsSkill(Acrobatics skill, bool isLearned)
{
    GameData* gameData = getGameData( actobaticsGameData );
    if( !gameData )
    {
        // create gamedata for acrobatics and reset its contents
        gameData = new GameData( sizeof(unsigned int) );
        memset( gameData->getData(), 0, gameData->getSize() );
        addGameData( actobaticsGameData, gameData );
    }

    // modify flag
    unsigned int bitset = *reinterpret_cast<unsigned int*>( gameData->getData() );
    if( isLearned ) bitset = bitset | skill; else bitset = bitset & ~skill;
    memcpy( gameData->getData(), &bitset, sizeof(unsigned int) );
}
Exemplo n.º 5
0
float Altimeter::getAAAltitude(Career* career)
{
    // retrieve altimeter state
    AltimeterState* state = NULL;
    GameData* gameData = career->getGameData( "ALTST" );    
    if( gameData == NULL )
    {
        gameData = new GameData( sizeof( AltimeterState ) );
        state = reinterpret_cast<AltimeterState*>( gameData->getData() );
        state->mode = false;
        state->altitude = 0.0f;
        career->addGameData( "ALTST", gameData );
    }
    else
    {
        state = reinterpret_cast<AltimeterState*>( gameData->getData() );
    }

    return state->altitude;
}
Exemplo n.º 6
0
void Altimeter::setAudibleAltimeter(Career* career, bool mode, float altitude)
{
    // retrieve altimeter state
    AltimeterState* state = NULL;
    GameData* gameData = career->getGameData( "ALTST" );    
    if( gameData == NULL )
    {
        gameData = new GameData( sizeof( AltimeterState ) );
        state = reinterpret_cast<AltimeterState*>( gameData->getData() );
        career->addGameData( "ALTST", gameData );
    }
    else
    {
        state = reinterpret_cast<AltimeterState*>( gameData->getData() );
    }

    // setup altimeter
    state->mode = mode;
    state->altitude = altitude;
}
Exemplo n.º 7
0
void Career::setMissionWalkthroughFlag(unsigned int tournamentId, unsigned int missionId, bool flag)
{
    // this feature is not available for demo tournament
    if( tournamentId == database::TournamentInfo::getDemoTournament() ) return;

    // retrieve tournament record
    database::TournamentInfo* tournamentInfo = database::TournamentInfo::getRecord( tournamentId );

    // check mission index is valid
    assert( missionId < tournamentInfo->getNumMissions() );

    // retrieve correspoding gamedata
    GameData* gameData = getGameData( tournamentInfo->gameData ); assert( gameData );
    Bitfield32* bitfield = reinterpret_cast<Bitfield32*>( gameData->getData() );

    // save result
    bitfield->setBit( missionId, flag );
}
Exemplo n.º 8
0
void Career::initializeWalkthroughMeter(void)
{
    // for all tournaments...
    for( unsigned int i=0; i<database::TournamentInfo::getNumRecords(); i++ )
    {
        // except for demo tournament
        if( i == database::TournamentInfo::getDemoTournament() ) continue;

        // retrieve tournament record
        database::TournamentInfo* tournamentInfo = database::TournamentInfo::getRecord( i );
        assert( tournamentInfo->gameData );

        // check there is gamedata record for "tournament walkthrough"
        GameData* gameData = getGameData( tournamentInfo->gameData );
        if( !gameData )
        {
            // create gamedata for tournament & reset its content
            gameData = new GameData( sizeof( Bitfield32 ) );
            memset( gameData->getData(), 0, gameData->getSize() );
            addGameData( tournamentInfo->gameData, gameData );
        }
    }
}
Exemplo n.º 9
0
Location::Location(Geoscape* geoscape, unsigned int databaseId)
{
    // initialize location
    _geoscape   = geoscape;
    _databaseId = databaseId;

    // make demo game data
    _demoGameData = new GameData( sizeof(LocationData) );
    LocationData* demoLocationData = reinterpret_cast<LocationData*>( _demoGameData->getData() );
    demoLocationData->player = true;
    // random weather
    unsigned int dice = unsigned int( getCore()->getRandToolkit()->getUniform( 0, 3 ) );
    switch( dice )
    {
    case 0:
        demoLocationData->weather = wtSunny; break;
    case 1:
        demoLocationData->weather = wtVariable; break;
    case 2:
        demoLocationData->weather = wtCloudy; break;    
    default:
        demoLocationData->weather = wtSunny;
    }
    demoLocationData->wind.set(
        getCore()->getRandToolkit()->getUniform( -1.0f, 1.0f ), 
        0.0f,
        getCore()->getRandToolkit()->getUniform( -1.0f, 1.0f )
    );
    demoLocationData->wind.normalize();
    demoLocationData->windAmbient = getCore()->getRandToolkit()->getUniform( 0.0f, 6.0f );
    demoLocationData->windBlast = getCore()->getRandToolkit()->getUniform( 0.0f, 6.0f );

    // location info
    database::LocationInfo* locationInfo = database::LocationInfo::getRecord( _databaseId );

    // create location window
    _window = Gameplay::iGui->createWindow("CareerLocation");
    _window->getPanel()->find( "Action" )->setRect(gui::Rect(0, 0, 20, 20));

    // setup caption
    gui::IGuiPanel* caption       = _window->getPanel()->find( "Caption" );
    gui::IGuiPanel* captionShadow = _window->getPanel()->find( "CaptionShadow" );
    assert( caption && caption->getStaticText() );
    assert( captionShadow && captionShadow->getStaticText() );
    caption->getStaticText()->setText( Gameplay::iLanguage->getUnicodeString( locationInfo->nameId ) );
    captionShadow->getStaticText()->setText( Gameplay::iLanguage->getUnicodeString( locationInfo->nameId ) );

    // place location
    if( _geoscape )
    {
        gui::Rect oldRect = _window->getPanel()->getRect();
        gui::Rect newRect;
        if( _databaseId == 0 )
        {
            newRect.left = _geoscape->getCareer()->getHomeX() - oldRect.getWidth() / 2;
            newRect.top  = _geoscape->getCareer()->getHomeY() - oldRect.getHeight() / 2;
        }
        else
        {
            newRect.left   = locationInfo->worldX - oldRect.getWidth() / 2;
            newRect.top    = locationInfo->worldY - oldRect.getHeight() / 2;
        }
        newRect.right  = newRect.left + oldRect.getWidth();
        newRect.bottom = newRect.top + oldRect.getHeight();
        _window->getPanel()->setRect( newRect );
        _geoscape->getWindow()->getPanel()->insertPanel( _window->getPanel() );
    }

    // location serializable data
    GameData* gameData = NULL;
    if( geoscape )
    {
        gameData = geoscape->getCareer()->getGameData( locationInfo->gameData.c_str() );
    }
    else
    {
        gameData = _demoGameData;
    }
    if( !gameData )
    {
        gameData = new GameData( sizeof( LocationData ) );
        _gameData = reinterpret_cast<LocationData*>( gameData->getData() );
        geoscape->getCareer()->addGameData( locationInfo->gameData.c_str(), gameData );        
        setPlayer( false );
        // random weather
        unsigned int dice = unsigned int( getCore()->getRandToolkit()->getUniform( 0, 6 ) );
        switch( dice )
        {
        case 0:
            setWeather( wtSunny );
            break;
        case 1:
            setWeather( wtVariable );
            break;
        case 2:
            setWeather( wtCloudy );
            break;
        case 3:
            setWeather( wtLightRain );
            break;
        case 4:
            setWeather( wtHardRain );
            break;
        case 5:
            setWeather( wtThunder );
            break;
        default:
            setWeather( wtSunny );
            break;
        }
    }
Exemplo n.º 10
0
void Career::setHomePlacementFlag(bool flag)
{
    getHomePlacementFlag();
    GameData* gameData = getGameData( "HPF" );
    *reinterpret_cast<bool*>(gameData->getData()) = flag;
}
Exemplo n.º 11
0
Career::Career(TiXmlElement* node)
{
    assert( strcmp( node->Value(), "career" ) == 0 );

    _name = node->Attribute( "name" );

    _isHomeDefined = false;
    _homeX = _homeY = 0;
    _eventCallback = NULL;
    _eventCallbackData = NULL;

    TiXmlNode* child = node->FirstChild(); assert( child );
    if( child != NULL ) do 
    {
        if( child->Type() == TiXmlNode::ELEMENT && strcmp( child->Value(), "virtues" ) == 0 )
        {
            int cs;
            static_cast<TiXmlElement*>( child )->Attribute( "checksum", &cs );
            std::string data = static_cast<TiXmlElement*>( child )->Attribute( "data" );
			if (!decrypt( &_virtues, sizeof(Virtues), data, _name.c_str() )) {

				VirtuesLegacy virtuesL;
				decrypt( &virtuesL, sizeof(VirtuesLegacy), data, _name.c_str() );
				
				_virtues.loadLegacy(virtuesL);
				//Virtues *a = NULL;a->appearance.face = 1;
			}
            if( cs != checksum( &_virtues, sizeof(Virtues) ) )
            {
                throw ccor::Exception( "User database entry corrupted: \"%s\"! Cheating not allowed!", _name.c_str() );
            }
        }
        else if( child->Type() == TiXmlNode::ELEMENT && strcmp( child->Value(), "gears" ) == 0 )
        {
            TiXmlNode* gearNode = child->FirstChild();
            if( gearNode ) do
            {
                assert( gearNode->Type() == TiXmlNode::ELEMENT && strcmp( gearNode->Value(), "gear" ) == 0 );
                int cs;
                static_cast<TiXmlElement*>( gearNode )->Attribute( "checksum", &cs );
                std::string data = static_cast<TiXmlElement*>( gearNode )->Attribute( "data" );
                Gear gear;
                decrypt( &gear, sizeof(Gear), data, _name.c_str() );
                if( cs != checksum( &gear, sizeof(Gear) ) )
                {
                    throw ccor::Exception( "User database entry corrupted: \"%s\"! Cheating not allowed!", _name.c_str() );
                }
                addGear( gear );
                gearNode = gearNode->NextSibling();
            }
            while( gearNode != NULL );
        }
        else if( child->Type() == TiXmlNode::ELEMENT && strcmp( child->Value(), "home" ) == 0 )
        {
            _isHomeDefined = true;
            static_cast<TiXmlElement*>( child )->Attribute( "x", &_homeX );
            static_cast<TiXmlElement*>( child )->Attribute( "y", &_homeY );
        }
        else if( child->Type() == TiXmlNode::ELEMENT && strcmp( child->Value(), "events" ) == 0 )
        {
            TiXmlNode* eventNode = child->FirstChild();
            if( eventNode ) do
            {
                if( eventNode->Type() == TiXmlNode::ELEMENT && strcmp( eventNode->Value(), "event" ) == 0 )
                {
                    Event* event = Event::createFromXml( this, static_cast<TiXmlElement*>( eventNode ) );
                    assert( event );
                    _events.push_back( event );
                }
                eventNode = eventNode->NextSibling();
            }
            while( eventNode != NULL );
        }        
        else if( child->Type() == TiXmlNode::ELEMENT && strcmp( child->Value(), "gamedata" ) == 0 )
        {
            TiXmlNode* entryNode = child->FirstChild();
            if( entryNode ) do
            {
                if( entryNode->Type() == TiXmlNode::ELEMENT && strcmp( entryNode->Value(), "entry" ) == 0 )
                {
                    std::string name = static_cast<TiXmlElement*>( entryNode )->Attribute( "name" );
                    std::string data = static_cast<TiXmlElement*>( entryNode )->Attribute( "data" );
                    int cs;
                    static_cast<TiXmlElement*>( entryNode )->Attribute( "checksum", &cs );
                    GameData* gameData = new GameData( data.length() / 2 );
                    ::decrypt( gameData->getData(), gameData->getSize(), data, _name.c_str() );
                    if( ::checksum( gameData->getData(), gameData->getSize() ) != cs )
                    {
                        throw ccor::Exception( "User database entry corrupted: \"%s\"! Cheating not allowed!", _name.c_str() );
                    }
                    _gameDataM.insert( GameDataT( name, gameData ) );
                }
                entryNode = entryNode->NextSibling();
            }
            while( entryNode != NULL );
        }
        child = child->NextSibling();
    }
    while( child != NULL );

    // TEST_MODE( enable acrobatics )
    
    //setAcrobaticsSkill( acroJumpFromRun, true );
    //setAcrobaticsSkill( acroFreeflyFlip, true );
    //setAcrobaticsSkill( acroFreeflySitfly, true );
    //setAcrobaticsSkill( acroFrontFlip, true );
    //setAcrobaticsSkill( acroFrontBackFlip, true );
    //setAcrobaticsSkill( acroBackFlip, true );
    //setAcrobaticsSkill( acroBackFrontFlip, true );
    

    // initialize game walk-through meter
    initializeWalkthroughMeter();
}
Exemplo n.º 12
0
void Career::setLicensedFlag(bool flag)
{
    getLicensedFlag();
    GameData* gameData = getGameData( "LCF" );
    *reinterpret_cast<bool*>(gameData->getData()) = flag;
}