本文整理汇总了C++中Planet::GetWorldPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Planet::GetWorldPosition方法的具体用法?C++ Planet::GetWorldPosition怎么用?C++ Planet::GetWorldPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Planet
的用法示例。
在下文中一共展示了Planet::GetWorldPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Load
/**\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 planet moved or lastPlanet changed.
// This happens with --random-universe. TODO: Does this matter? random-universe was removed.
Planet* p = Menu::GetCurrentScenario()->GetPlanets()->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;
}
示例2: FromXMLNode
/**\brief Parse one player out of an xml node
*/
bool Player::FromXMLNode( xmlDocPtr doc, xmlNodePtr node ) {
xmlNodePtr attr;
string value;
Coordinate pos;
if( (attr = FirstChildNamed(node,"name")) ){
SetName(NodeToString(doc,attr));
}
if( (attr = FirstChildNamed(node, "planet"))){
string temp;
xmlNodePtr name = FirstChildNamed(attr,"name");
lastPlanet = NodeToString(doc,name);
Planet* p = Planets::Instance()->GetPlanet( lastPlanet );
if( p != NULL ) {
SetWorldPosition( p->GetWorldPosition() );
}
}else return false;
if( (attr = FirstChildNamed(node,"model")) ){
value = NodeToString(doc,attr);
Model* model = Models::Instance()->GetModel( value );
if( NULL!=model) {
SetModel( model );
} else {
LogMsg(ERR,"No such model as '%s'", value.c_str());
return false;
}
} else return false;
if( (attr = FirstChildNamed(node,"engine")) ){
value = NodeToString(doc,attr);
Engine* engine = Engines::Instance()->GetEngine( value );
if( NULL!=engine) {
SetEngine( engine );
} else {
LogMsg(ERR,"No such engine as '%s'", value.c_str());
return false;
}
} else return false;
if( (attr = FirstChildNamed(node,"credits")) ){
value = NodeToString(doc,attr);
SetCredits( atoi(value.c_str()) );
} else return false;
for( attr = FirstChildNamed(node,"weapon"); attr!=NULL; attr = NextSiblingNamed(attr,"weapon") ){
AddShipWeapon( NodeToString(doc,attr) );
}
for( attr = FirstChildNamed(node,"outfit"); attr!=NULL; attr = NextSiblingNamed(attr,"outfit") ){
AddOutfit( NodeToString(doc,attr) );
}
for( attr = FirstChildNamed(node,"cargo"); attr!=NULL; attr = NextSiblingNamed(attr,"cargo") ){
xmlNodePtr type = FirstChildNamed(attr,"type");
xmlNodePtr ammt = FirstChildNamed(attr,"amount");
if(!type || !ammt)
return false;
if( NodeToInt(doc,ammt) > 0 )
{
StoreCommodities( NodeToString(doc,type), NodeToInt(doc,ammt) );
}
}
for( attr = FirstChildNamed(node,"ammo"); attr!=NULL; attr = NextSiblingNamed(attr,"ammo") ){
xmlNodePtr type = FirstChildNamed(attr,"type");
xmlNodePtr ammt = FirstChildNamed(attr,"amount");
if(!type || !ammt)
return false;
AmmoType ammoType = Weapon::AmmoNameToType( NodeToString(doc,type) );
int ammoCount = NodeToInt(doc,ammt);
if( ammoType < max_ammo ) {
AddAmmo( ammoType, ammoCount );
} else return false;
}
for( attr = FirstChildNamed(node,"Mission"); attr!=NULL; attr = NextSiblingNamed(attr,"Mission") ){
Mission *mission = Mission::FromXMLNode(doc,attr);
if( mission != NULL ) {
LogMsg(INFO, "Successfully loaded the %s mission of player '%s'", mission->GetName().c_str(), this->GetName().c_str() );
missions.push_back( mission );
} else {
LogMsg(INFO, "Aborted loading mission of player '%s'", this->GetName().c_str() );
}
}
for( attr = FirstChildNamed(node,"favor"); attr!=NULL; attr = NextSiblingNamed(attr,"favor") ){
xmlNodePtr alliance = FirstChildNamed(attr,"alliance");
xmlNodePtr value = FirstChildNamed(attr,"value");
if(!alliance || !value)
return false;
if( NodeToInt(doc,value) > 0 )
{
UpdateFavor( NodeToString(doc,alliance), NodeToInt(doc,value) );
}
}
//.........这里部分代码省略.........