Example #1
0
/**\brief Create a new Player
 * This is used instead of a normal class constructor
 */
Player* Players::CreateNew(
    string simulation,
    string playerName,
    Model *model,
    Engine *engine,
    int credits,
    Coordinate location)
{
    Player* newPlayer = new Player;

    LogMsg(INFO, "Creating New Player '%s' with Model='%s' Engine='%s' Credits = %d at (%.0f,%.0f).",
           playerName.c_str(),
           model->GetName().c_str(),
           engine->GetName().c_str(),
           credits,
           location.GetX(), location.GetY()
          );

    newPlayer->name = playerName;

    newPlayer->SetModel( model );
    newPlayer->SetEngine( engine );
    newPlayer->SetCredits( credits );
    newPlayer->SetWorldPosition( location );
    newPlayer->RemoveLuaControlFunc();

    newPlayer->lastLoadTime = time(NULL);

    Add( (Component*)(new PlayerInfo( newPlayer, simulation )) );

    return newPlayer;
}
Example #2
0
/**\brief Load a player from a file.
 * \param[in] filename of a player's xml saved game.
 * \returns pointer to new Player instance.
 */
Player* Player::Load( string filename ) {
    xmlDocPtr doc;
    xmlNodePtr cur;
    Player* newPlayer = new Player();

    File xmlfile = File (filename);
    long filelen = xmlfile.GetLength();
    char *buffer = xmlfile.Read();
    doc = xmlParseMemory( buffer, static_cast<int>(filelen) );
    cur = xmlDocGetRootElement( doc );

    newPlayer->FromXMLNode( doc, cur );

    // We check the planet location at loadtime in case the planet has moved or the lastPlanet has changed.
    // This happens with the --random-universe option.
    Planet* p = Planets::Instance()->GetPlanet( newPlayer->lastPlanet );
    if( p != NULL ) {
        newPlayer->SetWorldPosition( p->GetWorldPosition() );
    } else {
        LogMsg(INFO, "There is no planet named: '%s'.", newPlayer->lastPlanet.c_str() );
    }

    newPlayer->RemoveLuaControlFunc();

    // We can't start the game with bad player Information
    assert( newPlayer->GetModelName() != "" );
    assert( newPlayer->GetEngineName() != "" );

    // Tell Lua to initialize these escorts.
    for(list<Player::HiredEscort*>::iterator iter_escort = newPlayer->hiredEscorts.begin(); iter_escort != newPlayer->hiredEscorts.end(); iter_escort++) {
        (*iter_escort)->Lua_Initialize( newPlayer->GetID(), newPlayer->GetWorldPosition() );
    }

    // Remember this Player
    newPlayer->lastLoadTime = time(NULL);

    LogMsg(INFO, "Successfully loaded the player: '%s'.",newPlayer->GetName().c_str() );
    LogMsg(INFO, "Loaded Player '%s' with Model='%s' Engine='%s' Credits = %d at (%.0f,%.0f).",
           newPlayer->GetName().c_str(),
           newPlayer->GetModel()->GetName().c_str(),
           newPlayer->GetEngine()->GetName().c_str(),
           newPlayer->GetCredits(),
           newPlayer->GetWorldPosition().GetX(), newPlayer->GetWorldPosition().GetY()
          );

    return newPlayer;
}