当前位置: 首页>>代码示例>>C++>>正文


C++ Ship::Name方法代码示例

本文整理汇总了C++中Ship::Name方法的典型用法代码示例。如果您正苦于以下问题:C++ Ship::Name方法的具体用法?C++ Ship::Name怎么用?C++ Ship::Name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ship的用法示例。


在下文中一共展示了Ship::Name方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DrawShip

void ShopPanel::DrawShip(const Ship &ship, const Point &center, bool isSelected) const
{
	const Sprite *sprite = ship.GetSprite().GetSprite();
	const Sprite *back = SpriteSet::Get(
		isSelected ? "ui/shipyard selected" : "ui/shipyard unselected");
	SpriteShader::Draw(back, center);
	// Make sure the ship sprite leaves 10 pixels padding all around.
	float zoomSize = SHIP_SIZE - 60.f;
	
	// Draw the ship name.
	const string &name = ship.Name().empty() ? ship.ModelName() : ship.Name();
	const Font &font = FontSet::Get(14);
	Point offset(-.5f * font.Width(name), -.5f * SHIP_SIZE + 10.f);
	font.Draw(name, center + offset, *GameData::Colors().Get("bright"));
	
	float zoom = min(1.f, zoomSize / max(sprite->Width(), sprite->Height()));
	int swizzle = GameData::PlayerGovernment()->GetSwizzle();
	
	SpriteShader::Draw(sprite, center, zoom, swizzle);
}
开发者ID:AMDmi3,项目名称:endless-sky,代码行数:20,代码来源:ShopPanel.cpp

示例2: UpdateAttributes

void ShipInfoDisplay::UpdateAttributes(const Ship &ship)
{
	bool isGeneric = ship.Name().empty() || ship.GetPlanet();
	
	attributeLabels.clear();
	attributeValues.clear();
	attributesHeight = 20;
	
	const Outfit &attributes = ship.Attributes();
	
	attributeLabels.push_back("cost:");
	attributeValues.push_back(Format::Number(ship.Cost()));
	attributesHeight += 20;
	
	attributeLabels.push_back(string());
	attributeValues.push_back(string());
	attributesHeight += 10;
	if(attributes.Get("shield generation"))
	{
		attributeLabels.push_back("shields charge / max:");
		attributeValues.push_back(Format::Number(60. * attributes.Get("shield generation"))
			+ " / " + Format::Number(attributes.Get("shields")));
	}
	else
	{
		attributeLabels.push_back("shields:");
		attributeValues.push_back(Format::Number(attributes.Get("shields")));
	}
	attributesHeight += 20;
	if(attributes.Get("hull repair rate"))
	{
		attributeLabels.push_back("hull repair / max:");
		attributeValues.push_back(Format::Number(60. * attributes.Get("hull repair rate"))
			+ " / " + Format::Number(attributes.Get("hull")));
	}
	else
	{
		attributeLabels.push_back("hull:");
		attributeValues.push_back(Format::Number(attributes.Get("hull")));
	}
	attributesHeight += 20;
	double emptyMass = ship.Mass();
	attributeLabels.push_back(isGeneric ? "mass with no cargo:" : "mass:");
	attributeValues.push_back(Format::Number(emptyMass));
	attributesHeight += 20;
	attributeLabels.push_back(isGeneric ? "cargo space:" : "cargo:");
	if(isGeneric)
		attributeValues.push_back(Format::Number(attributes.Get("cargo space")));
	else
		attributeValues.push_back(Format::Number(ship.Cargo().Used())
			+ " / " + Format::Number(attributes.Get("cargo space")));
	attributesHeight += 20;
	attributeLabels.push_back("required crew / bunks:");
	attributeValues.push_back(Format::Number(ship.RequiredCrew())
		+ " / " + Format::Number(attributes.Get("bunks")));
	attributesHeight += 20;
	attributeLabels.push_back(isGeneric ? "fuel capacity:" : "fuel:");
	double fuelCapacity = attributes.Get("fuel capacity");
	if(isGeneric)
		attributeValues.push_back(Format::Number(fuelCapacity));
	else
		attributeValues.push_back(Format::Number(ship.Fuel() * fuelCapacity)
			+ " / " + Format::Number(fuelCapacity));
	attributesHeight += 20;
	
	double fullMass = emptyMass + (isGeneric ? attributes.Get("cargo space") : ship.Cargo().Used());
	isGeneric &= (fullMass != emptyMass);
	attributeLabels.push_back(string());
	attributeValues.push_back(string());
	attributesHeight += 10;
	attributeLabels.push_back(isGeneric ? "movement, full / no cargo:" : "movement:");
	attributeValues.push_back(string());
	attributesHeight += 20;
	attributeLabels.push_back("max speed:");
	attributeValues.push_back(Format::Number(60. * attributes.Get("thrust") / attributes.Get("drag")));
	attributesHeight += 20;
	
	attributeLabels.push_back("acceleration:");
	if(!isGeneric)
		attributeValues.push_back(Format::Number(3600. * attributes.Get("thrust") / fullMass));
	else
		attributeValues.push_back(Format::Number(3600. * attributes.Get("thrust") / fullMass)
			+ " / " + Format::Number(3600. * attributes.Get("thrust") / emptyMass));
	attributesHeight += 20;
	
	attributeLabels.push_back("turning:");
	if(!isGeneric)
		attributeValues.push_back(Format::Number(60. * attributes.Get("turn") / fullMass));
	else
		attributeValues.push_back(Format::Number(60. * attributes.Get("turn") / fullMass)
			+ " / " + Format::Number(60. * attributes.Get("turn") / emptyMass));
	attributesHeight += 20;
	
	// Find out how much outfit, engine, and weapon space the chassis has.
	map<string, double> chassis;
	static const string names[] = {
		"outfit space free:", "outfit space",
		"    weapon capacity:", "weapon capacity",
		"    engine capacity:", "engine capacity",
		"gun ports free:", "gun ports",
//.........这里部分代码省略.........
开发者ID:Faileas,项目名称:endless-sky,代码行数:101,代码来源:ShipInfoDisplay.cpp

示例3: if

void
NetGameClient::DoObjKill(NetMsg* msg)
{
	if (!msg) return;

	NetObjKill obj_kill;
	obj_kill.Unpack(msg->Data());

	Ship* ship = FindShipByObjID(obj_kill.GetObjID());
	if (ship) {
		Ship* killer = FindShipByObjID(obj_kill.GetKillerID());
		Text  killer_name = Game::GetText("NetGameClient.unknown");

		if (killer)
		killer_name = killer->Name();

		// log the kill:
		switch (obj_kill.GetKillType()) {
		default:
		case NetObjKill::KILL_MISC:
			Print("Ship '%s' destroyed (misc) (%s)\n", ship->Name(), FormatGameTime());
			break;

		case NetObjKill::KILL_PRIMARY:
		case NetObjKill::KILL_SECONDARY:
			Print("Ship '%s' killed by '%s' (%s)\n", ship->Name(), killer_name.data(), FormatGameTime());
			break;

		case NetObjKill::KILL_COLLISION:
			Print("Ship '%s' killed in collision with '%s' (%s)\n", ship->Name(), killer_name.data(), FormatGameTime());
			break;

		case NetObjKill::KILL_CRASH:
			Print("Ship '%s' destroyed (crash) (%s)\n", ship->Name(), FormatGameTime());

		case NetObjKill::KILL_DOCK:
			Print("Ship '%s' docked (%s)\n", ship->Name(), FormatGameTime());
		}

		// record the kill in the stats:
		if (killer && obj_kill.GetKillType() != NetObjKill::KILL_DOCK) {
			ShipStats* kstats = ShipStats::Find(killer->Name());
			if (kstats) {
				if (obj_kill.GetKillType() == NetObjKill::KILL_PRIMARY)
				kstats->AddEvent(SimEvent::GUNS_KILL, ship->Name());
				
				else if (obj_kill.GetKillType() == NetObjKill::KILL_SECONDARY)
				kstats->AddEvent(SimEvent::MISSILE_KILL, ship->Name());
			}

			if (killer && killer->GetIFF() != ship->GetIFF()) {
				if (ship->GetIFF() > 0 || killer->GetIFF() > 1)
				kstats->AddPoints(ship->Value());
			}
		}

		ShipStats* killee = ShipStats::Find(ship->Name());
		if (killee) {
			if (obj_kill.GetKillType() == NetObjKill::KILL_DOCK)
			killee->AddEvent(SimEvent::DOCK, killer_name);
			else 
			killee->AddEvent(SimEvent::DESTROYED, killer_name);
		}

		if (obj_kill.GetKillType() == NetObjKill::KILL_DOCK) {
			FlightDeck* deck = killer->GetFlightDeck(obj_kill.GetFlightDeck());
			sim->NetDockShip(ship, killer, deck);
		}
		else {
			ship->InflictNetDamage(ship->Integrity());
			ship->DeathSpiral();

			if (!obj_kill.GetRespawn())
			ship->SetRespawnCount(0);
			else
			ship->SetRespawnLoc(obj_kill.GetRespawnLoc());
		}
	}

	// this shouldn't happen in practice, 
	// but if it does, this is what should be done:
	else {
		Shot* shot = FindShotByObjID(obj_kill.GetObjID());

		if (shot) {
			::Print("NetGameClient::DoObjKill destroying shot '%s'\n", shot->Name());
			shot->Destroy();
		}
	}
}
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:90,代码来源:NetGameClient.cpp

示例4: if


//.........这里部分代码省略.........
	case INSTRUCTION:
		if (elem) {
			if (event_param[0])
			elem->ClearInstructions();

			elem->AddInstruction(event_message);

			if (elem->Contains(player) && event_message.length() > 0) {
				HUDView* hud = HUDView::GetInstance();

				if (hud)
				hud->ShowHUDInst();
			}
		}
		break;

	case IFF:
		if (elem) {
			elem->SetIFF(event_param[0]);
		}

		else if (ship) {
			ship->SetIFF(event_param[0]);
		}
		break;

	case DAMAGE:
		if (ship) {
			ship->InflictDamage(event_param[0]);

			if (ship->Integrity() < 1) {
				NetUtil::SendObjKill(ship, 0, NetObjKill::KILL_MISC);
				ship->DeathSpiral();
				Print("    %s Killed By Scripted Event %d (%s)\n", (const char*) ship->Name(), id, FormatGameTime());
			}
		}
		else {
			Print("   EVENT %d: Could not apply damage to ship '%s' (not found).\n", id, (const char*) event_ship);
		}
		break;

	case JUMP:
		if (ship) {
			SimRegion* rgn = sim->FindRegion(event_target);

			if (rgn && ship->GetRegion() != rgn) {
				if (rgn->IsOrbital()) {
					QuantumDrive* quantum_drive = ship->GetQuantumDrive();
					if (quantum_drive) {
						quantum_drive->SetDestination(rgn, Point(0,0,0));
						quantum_drive->Engage(true); // request immediate jump
					}

					else if (ship->IsAirborne()) {
						ship->MakeOrbit();
					}
				}

				else {
					ship->DropOrbit();
				}
			}

		}
		break;
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:66,代码来源:MissionEvent.cpp

示例5: FindPlayerByObjID

bool
NetGameClient::DoJoinBacklog(NetJoinAnnounce* join_ann)
{
	bool finished = false;

	if (!join_ann)
	return finished;

	Sim* sim = Sim::GetSim();
	if (!sim)
	return finished;

	DWORD nid       = join_ann->GetNetID();
	DWORD oid       = join_ann->GetObjID();
	Text  name      = join_ann->GetName();
	Text  elem_name = join_ann->GetElement();
	Text  region    = join_ann->GetRegion();
	Point loc       = join_ann->GetLocation();
	Point velocity  = join_ann->GetVelocity();
	int   index     = join_ann->GetIndex();
	int   shld_lvl  = join_ann->GetShield();
	Ship* ship      = 0;
	char  ship_name[128];

	strcpy_s(ship_name, Game::GetText("NetGameClient.no-ship").data());

	if (nid && oid) {
		NetPlayer* remote_player = FindPlayerByObjID(oid);
		if (remote_player) {
			remote_player->SetName(name);
			remote_player->SetObjID(oid);

			if (index > 0)
			sprintf_s(ship_name, "%s %d", elem_name.data(), index);
			else
			sprintf_s(ship_name, "%s", elem_name.data());
		}
		else {
			Element* element = sim->FindElement(elem_name);

			if (element) {
				ship = element->GetShip(index);
			}

			if (ship) {
				strcpy_s(ship_name, ship->Name());

				SimRegion* rgn = ship->GetRegion();
				if (rgn && region != rgn->Name()) {
					SimRegion* dst = sim->FindRegion(region);
					if (dst) dst->InsertObject(ship);
				}

				ship->MoveTo(loc);
				ship->SetVelocity(velocity);

				Shield* shield = ship->GetShield();
				if (shield)
				shield->SetNetShieldLevel(shld_lvl);

				NetPlayer* remote_player = new(__FILE__,__LINE__) NetPlayer(nid);
				remote_player->SetName(name);
				remote_player->SetObjID(oid);
				remote_player->SetShip(ship);

				players.append(remote_player);
				finished = true;

				if (name == "Server A.I. Ship") {
					Print("NetGameClient::DoJoinBacklog() Remote Player '%s' has joined as '%s' with ID %d\n", name.data(), ship_name, oid);
				}
				else {
					HUDView::Message(Game::GetText("NetGameClient.remote-join").data(), name.data(), ship_name);
				}
			}
		}
	}

	return finished;
}
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:80,代码来源:NetGameClient.cpp

示例6: new

void
NetGameClient::DoJoinAnnounce(NetMsg* msg)
{
	if (!msg) return;

	Sim* sim = Sim::GetSim();
	if (!sim) return;

	NetJoinAnnounce*  join_ann = new(__FILE__,__LINE__) NetJoinAnnounce;
	bool              saved    = false;

	if (join_ann->Unpack(msg->Data())) {
		DWORD nid       = msg->NetID();
		DWORD oid       = join_ann->GetObjID();
		Text  name      = join_ann->GetName();
		Text  elem_name = join_ann->GetElement();
		Text  region    = join_ann->GetRegion();
		Point loc       = join_ann->GetLocation();
		Point velocity  = join_ann->GetVelocity();
		int   index     = join_ann->GetIndex();
		int   shld_lvl  = join_ann->GetShield();
		join_ann->SetNetID(nid);
		Ship* ship      = 0;
		char  ship_name[128];

		strcpy_s(ship_name, Game::GetText("NetGameClient.no-ship").data());

		if (local_player && player_name == name) {
			HUDView::Message(Game::GetText("NetGameClient.local-accept"), name.data(), local_player->Name());

			objid = oid;
			netid = nid;
			local_player->SetObjID(oid);
			local_player->SetNetObserver(false);
			Observe(local_player);

			SimRegion* rgn = local_player->GetRegion();
			if (rgn && region != rgn->Name()) {
				SimRegion* dst = sim->FindRegion(region);
				if (dst) dst->InsertObject(local_player);
			}

			local_player->MoveTo(loc);
			local_player->SetVelocity(velocity);

			Shield* shield = local_player->GetShield();
			if (shield)
			shield->SetNetShieldLevel(shld_lvl);
		}
		else {
			NetPlayer* remote_player = FindPlayerByObjID(oid);
			if (remote_player) {
				remote_player->SetName(name);
				remote_player->SetObjID(oid);

				if (index > 0)
				sprintf_s(ship_name, "%s %d", elem_name.data(), index);
				else
				sprintf_s(ship_name, "%s", elem_name.data());
			}
			else {
				Element* element = sim->FindElement(elem_name);

				if (element) {
					ship = element->GetShip(index);
				}
				else {
					Print("NetGameClient::DoJoinAnnounce() could not find elem %s for player '%s' objid %d\n",
					elem_name.data(), name.data(), oid);

					NetUtil::SendElemRequest(elem_name.data());
				}

				if (!ship) {
					// save it for later:
					join_backlog.append(join_ann);
					saved = true;
				}
				else {
					strcpy_s(ship_name, ship->Name());

					SimRegion* rgn = ship->GetRegion();
					if (rgn && region != rgn->Name()) {
						SimRegion* dst = sim->FindRegion(region);
						if (dst) dst->InsertObject(ship);
					}

					ship->MoveTo(loc);
					ship->SetVelocity(velocity);

					Shield* shield = ship->GetShield();
					if (shield)
					shield->SetNetShieldLevel(shld_lvl);

					NetPlayer* remote_player = new(__FILE__,__LINE__) NetPlayer(nid);
					remote_player->SetName(name);
					remote_player->SetObjID(oid);
					remote_player->SetShip(ship);

					players.append(remote_player);
//.........这里部分代码省略.........
开发者ID:The-E,项目名称:Starshatter-Experimental,代码行数:101,代码来源:NetGameClient.cpp

示例7: CalculateStep


//.........这里部分代码省略.........
	Point newCenter = center;
	Point newCenterVelocity;
	if(flagship)
	{
		newCenter = flagship->Position();
		newCenterVelocity = flagship->Velocity();
	}
	else
		doClick = false;
	draw[calcTickTock].SetCenter(newCenter, newCenterVelocity);
	radar[calcTickTock].SetCenter(newCenter);
	
	for(const StellarObject &object : player.GetSystem()->Objects())
		if(object.HasSprite())
		{
			// Don't apply motion blur to very large planets and stars.
			if(object.Width() >= 280.)
				draw[calcTickTock].AddUnblurred(object);
			else
				draw[calcTickTock].Add(object);
			
			double r = max(2., object.Radius() * .03 + .5);
			radar[calcTickTock].Add(RadarType(object), object.Position(), r, r - 1.);
			
			if(object.GetPlanet())
				object.GetPlanet()->DeployDefense(ships);
			
			Point position = object.Position() - newCenter;
			if(doClick && object.GetPlanet() && (clickPoint - position).Length() < object.Radius())
			{
				if(&object == player.Flagship()->GetTargetPlanet())
				{
					if(!object.GetPlanet()->CanLand())
						Messages::Add("The authorities on " + object.GetPlanet()->Name() +
							" refuse to let you land.");
					else
					{
						clickCommands |= Command::LAND;
						Messages::Add("Landing on " + object.GetPlanet()->Name() + ".");
					}
				}
				else
					player.Flagship()->SetTargetPlanet(&object);
			}
		}
	
	// Add all neighboring systems to the radar.
	const System *targetSystem = flagship ? flagship->GetTargetSystem() : nullptr;
	const vector<const System *> &links = (flagship && flagship->Attributes().Get("jump drive")) ?
		player.GetSystem()->Neighbors() : player.GetSystem()->Links();
	for(const System *system : links)
		radar[calcTickTock].AddPointer(
			(system == targetSystem) ? Radar::SPECIAL : Radar::INACTIVE,
			system->Position() - player.GetSystem()->Position());
	
	// Now that the planets have been drawn, we can draw the asteroids on top
	// of them. This could be done later, as long as it is done before the
	// collision detection.
	asteroids.Step();
	asteroids.Draw(draw[calcTickTock], newCenter);
	
	// Move existing projectiles. Do this before ships fire, which will create
	// new projectiles, since those should just stay where they are created for
	// this turn. This is also where projectiles get deleted, which may also
	// result in a "die" effect or a sub-munition being created. We could not
	// move the projectiles before this because some of them are homing and need
开发者ID:EndlessBureaucracy,项目名称:endless-bureaucracy,代码行数:67,代码来源:Engine.cpp

示例8: if

void
FltDlg::OnFilter(AWEvent* event)
{
	if (!filter_list || !hangar_list) return;

	int seln = filter_list->GetSelectedIndex();

	hangar_list->ClearItems();

	if (!ship) return;

	Hangar* hangar = ship->GetHangar();

	// selected squadron:
	if (seln < hangar->NumSquadrons()) {
		int         nslots   = hangar->SquadronSize(seln);

		for (int i = 0; i < nslots; i++) {
			char txt[32];
			sprintf_s(txt, " %2d    ", i+1);

			const HangarSlot* s = hangar->GetSlot(seln, i);
			hangar_list->AddItemWithData(txt, i);

			hangar_list->SetItemText(i, 1, "--");
			hangar_list->SetItemText(i, 2, hangar->StatusName(s));

			FormatTime(txt, hangar->TimeRemaining(s));
			hangar_list->SetItemText(i, 4, txt);
		}
	}

	// selected pending filter:
	else if (seln == hangar->NumSquadrons()) {
		int item = 0;

		for (int f = 0; f < ship->NumFlightDecks(); f++) {
			FlightDeck* deck = ship->GetFlightDeck(f);

			if (deck->IsLaunchDeck()) {
				for (int i = 0; i < deck->NumSlots(); i++) {
					int      state    = deck->State(i);
					int      seq      = deck->Sequence(i);
					double   time     = deck->TimeRemaining(i);
					Ship*    deckship = deck->GetShip(i);

					int      squadron = -1;
					int      slot     = -1;

					char txt[32];
					sprintf_s(txt, "%d-%d    ", f+1, i+1);

					hangar_list->AddItemWithData(txt, item); // use data for sort

					if (deckship) {
						hangar_list->SetItemText(item, 1, deckship->Name());

						const HangarSlot* s = 0;

						for (int a = 0; !s && a < hangar->NumSquadrons(); a++) {
							for (int b = 0; !s && b < hangar->SquadronSize(a); b++) {
								const HangarSlot* test = hangar->GetSlot(a, b);
								if (hangar->GetShip(test) == deckship) {
									s          = test;
									squadron   = a;
									slot       = b;
								}
							}
						}

						if (s) {
							hangar_list->SetItemText(item, 2, hangar->StatusName(s));
							if (hangar->GetPackageElement(s))
							hangar_list->SetItemText(item, 3, Mission::RoleName(hangar->GetPackageElement(s)->Type()));
						}
					}
					else {
						hangar_list->SetItemText(item, 1, "--");
						hangar_list->SetItemText(item, 2, Game::GetText("FltDlg.Open"));
					}


					FormatTime(txt, time);
					hangar_list->SetItemText(item, 4, txt);

					hangar_list->SetItemData(item, 1, f);
					hangar_list->SetItemData(item, 2, i);
					hangar_list->SetItemData(item, 3, squadron);
					hangar_list->SetItemData(item, 4, slot);

					item++;
				}
			}
		}
	}

	// selected active filter:
	else if (seln == hangar->NumSquadrons()+1) {
		int item = 0;

//.........这里部分代码省略.........
开发者ID:lightgemini78,项目名称:Starshatter-Rearmed,代码行数:101,代码来源:FltDlg.cpp


注:本文中的Ship::Name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。