本文整理汇总了C++中Ship::GetRegion方法的典型用法代码示例。如果您正苦于以下问题:C++ Ship::GetRegion方法的具体用法?C++ Ship::GetRegion怎么用?C++ Ship::GetRegion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ship
的用法示例。
在下文中一共展示了Ship::GetRegion方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
FltDlg::UpdateObjective()
{
if (!objective_list || mission_type < 0 || !ship) return;
Sim* sim = Sim::GetSim();
char txt[32];
for (int item = 0; item < objective_list->NumItems(); item++) {
const char* obj_name = objective_list->GetItemText(item);
Element* elem = sim->FindElement(obj_name);
// if element has expired, remove it from the objective list
if (!elem || !elem->IsActive() || elem->IsFinished()) {
objective_list->RemoveItem(item);
item--;
}
// otherwise, the element is still active, so update range/region
else {
Ship* s = elem->GetShip(1);
double r = 0;
bool con = false;
if (s) {
Point s_loc = s->Location() + s->GetRegion()->Location();
Point h_loc = ship->Location() + ship->GetRegion()->Location();
r = (s_loc - h_loc).length();
con = ship->FindContact(s) != 0;
if (con) {
FormatNumber(txt, r);
}
else {
strcpy_s(txt, Game::GetText("FltDlg.Unknown").data());
r = 2e9;
}
}
objective_list->SetItemText(item, 1, s->GetRegion()->Name());
objective_list->SetItemText(item, 2, txt);
objective_list->SetItemData(item, 2, (DWORD) r);
}
}
}
示例2: while
void
CameraDirector::SetViewObjectGroup(ListIter<Ship> group, bool quick)
{
if (!ship) return;
Starshatter* stars = Starshatter::GetInstance();
if (!stars->InCutscene()) {
// only view solid contacts:
while (++group) {
Ship* s = group.value();
if (s->GetIFF() != ship->GetIFF()) {
Contact* c = ship->FindContact(s);
if (!c || !c->ActLock())
return;
}
if (s->Life() == 0 || s->IsDying() || s->IsDead())
return;
}
}
group.reset();
if (external_group.size() > 1 &&
external_group.size() == group.size()) {
bool same = true;
for (int i = 0; same && i < external_group.size(); i++) {
if (external_group[i] != group.container()[i])
same = false;
}
if (same) {
SetMode(MODE_ZOOM);
return;
}
}
ClearGroup();
if (quick) {
mode = MODE_ORBIT;
transition = 0;
}
else {
SetMode(MODE_TRANSLATE);
}
external_group.append(group.container());
ListIter<Ship> iter = external_group;
while (++iter) {
Ship* s = iter.value();
region = s->GetRegion();
Observe(s);
}
}
示例3: if
void
NetGameClient::DoObjDamage(NetMsg* msg)
{
if (!msg) return;
NetObjDamage obj_damage;
obj_damage.Unpack(msg->Data());
Ship* ship = FindShipByObjID(obj_damage.GetObjID());
if (ship) {
Sim* sim = Sim::GetSim();
Shot* shot = FindShotByObjID(obj_damage.GetShotID());
const Ship* owner = 0;
const char* owner_name = "[NET]";
ship->InflictNetDamage(obj_damage.GetDamage(), shot);
if (shot && sim) {
if (shot->Owner()) {
owner = shot->Owner();
owner_name = owner->Name();
}
if (shot->IsMissile()) {
SimRegion* region = ship->GetRegion();
float scale = ship->Design()->explosion_scale;
if (scale <= 0)
scale = ship->Design()->scale;
if (owner) {
const ShipDesign* owner_design = owner->Design();
if (owner_design && owner_design->scale < scale)
scale = (float) owner_design->scale;
}
sim->CreateExplosion(shot->Location(), Point(), Explosion::SHOT_BLAST, 20.0f * scale, scale, region);
}
if (!shot->IsBeam()) {
if (owner) {
ShipStats* stats = ShipStats::Find(owner_name);
if (stats) {
if (shot->IsPrimary())
stats->AddGunHit();
else if (shot->Damage() > 0)
stats->AddMissileHit();
}
}
shot->Destroy();
}
}
}
}
示例4: if
//.........这里部分代码省略.........
ClearRadioOrders();
}
break;
case RadioMessage::ESCORT:
case RadioMessage::COVER_ME:
{
SimObject* tgt = orders->GetTarget();
if (tgt && tgt->Type() == SimObject::SIM_SHIP) {
roe = DEFENSIVE;
ship_ai->SetWard((Ship*) tgt);
ship_ai->SetNavPoint(0);
}
else {
ClearRadioOrders();
}
}
break;
case RadioMessage::WEP_FREE:
roe = AGRESSIVE;
ship_ai->DropTarget(0.1);
break;
case RadioMessage::WEP_HOLD:
case RadioMessage::FORM_UP:
roe = NONE;
ship_ai->DropTarget(5);
break;
case RadioMessage::MOVE_PATROL:
roe = SELF_DEFENSIVE;
ship_ai->SetPatrol(orders->Location());
ship_ai->SetNavPoint(0);
ship_ai->DropTarget(Random(5, 10));
break;
case RadioMessage::RTB:
case RadioMessage::DOCK_WITH:
roe = NONE;
ship_ai->DropTarget(10);
if (!ship->GetInbound()) {
RadioMessage* msg = 0;
Ship* controller = ship->GetController();
if (orders->Action() == RadioMessage::DOCK_WITH && orders->GetTarget()) {
controller = (Ship*) orders->GetTarget();
}
if (!controller) {
Element* elem = ship->GetElement();
if (elem && elem->GetCommander()) {
Element* cmdr = elem->GetCommander();
controller = cmdr->GetShip(1);
}
}
if (controller && controller->GetHangar() &&
controller->GetHangar()->CanStow(ship)) {
SimRegion* self_rgn = ship->GetRegion();
SimRegion* rtb_rgn = controller->GetRegion();
if (self_rgn == rtb_rgn) {
double range = Point(controller->Location() - ship->Location()).length();
if (range < 50e3) {
msg = new(__FILE__,__LINE__) RadioMessage(controller, ship, RadioMessage::CALL_INBOUND);
RadioTraffic::Transmit(msg);
}
}
}
else {
ship->ClearRadioOrders();
}
ship_ai->SetNavPoint(0);
}
break;
case RadioMessage::QUANTUM_TO:
case RadioMessage::FARCAST_TO:
roe = NONE;
ship_ai->DropTarget(10);
break;
}
action = orders->Action();
return true;
}
// if we had an action before, this must be a "cancel orders"
else if (action) {
ClearRadioOrders();
}
return false;
}
示例5: if
//.........这里部分代码省略.........
}
}
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;
case HOLD:
if (elem)
elem->SetHoldTime(event_param[0]);
break;
case SKIP: {
for (int i = 0; i < event_nparams; i++) {
int skip_id = event_param[i];
ListIter<MissionEvent> iter = sim->GetEvents();
while (++iter) {
MissionEvent* e = iter.value();
示例6: 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;
}
示例7: 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);
//.........这里部分代码省略.........