本文整理汇总了C++中Sim::FindShip方法的典型用法代码示例。如果您正苦于以下问题:C++ Sim::FindShip方法的具体用法?C++ Sim::FindShip怎么用?C++ Sim::FindShip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sim
的用法示例。
在下文中一共展示了Sim::FindShip方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Observe
SimObject*
Instruction::GetTarget()
{
if (!target && tgt_name.length() > 0) {
Sim* sim = Sim::GetSim();
if (sim) {
Ship* s = sim->FindShip(tgt_name, rgn_name);
if (s) {
target = s;
Observe(target);
}
}
}
return target;
}
示例2: if
bool
MissionEvent::CheckTrigger()
{
Sim* sim = Sim::GetSim();
if (time > 0 && time > sim->MissionClock())
return false;
switch (trigger) {
case TRIGGER_TIME: {
if (time <= sim->MissionClock())
Activate();
}
break;
case TRIGGER_DAMAGE: {
Ship* ship = sim->FindShip(trigger_ship);
if (ship) {
double damage = 100.0 * (ship->Design()->integrity - ship->Integrity()) /
(ship->Design()->integrity);
if (damage >= trigger_param[0])
Activate();
}
}
break;
case TRIGGER_DETECT: {
Ship* ship = sim->FindShip(trigger_ship);
Ship* tgt = sim->FindShip(trigger_target);
if (ship && tgt) {
if (ship->FindContact(tgt))
Activate();
}
else {
Skip();
}
}
break;
case TRIGGER_RANGE: {
Ship* ship = sim->FindShip(trigger_ship);
Ship* tgt = sim->FindShip(trigger_target);
if (ship && tgt) {
double range = (ship->Location() - tgt->Location()).length();
double min_range = 0;
double max_range = 1e12;
if (trigger_param[0] > 0)
min_range = trigger_param[0];
else
max_range = -trigger_param[0];
if (range < min_range || range > max_range)
Activate();
}
else {
Skip();
}
}
break;
case TRIGGER_SHIPS_LEFT: {
int alive = 0;
int count = 0;
int iff = -1;
int nparams = NumTriggerParams();
if (nparams > 0) count = TriggerParam(0);
if (nparams > 1) iff = TriggerParam(1);
ListIter<SimRegion> iter = sim->GetRegions();
while (++iter) {
SimRegion* rgn = iter.value();
ListIter<Ship> s_iter = rgn->Ships();
while (++s_iter) {
Ship* ship = s_iter.value();
if (ship->Type() >= Ship::STATION)
continue;
if (ship->Life() == 0 && ship->RespawnCount() < 1)
continue;
if (iff < 0 || ship->GetIFF() == iff)
alive++;
}
}
if (alive <= count)
Activate();
}
break;
case TRIGGER_EVENT_ALL: {
bool all = true;
int nparams = NumTriggerParams();
//.........这里部分代码省略.........
示例3: new
void
NetGameClient::DoElemCreate(NetMsg* msg)
{
if (!msg) return;
NetElemCreate elem_create;
elem_create.Unpack(msg->Data());
const char* elem_name = elem_create.GetName().data();
::Print("NetGameClient::DoElemCreate name: %s iff: %d type %s\n",
elem_name,
elem_create.GetIFF(),
Mission::RoleName(elem_create.GetType()));
Sim* sim = Sim::GetSim();
Element* elem = sim->FindElement(elem_name);
if (elem) {
::Print(" element '%' already exists - ignored\n", elem_name);
return;
}
elem = sim->CreateElement(elem_name,
elem_create.GetIFF(),
elem_create.GetType());
int* load = elem_create.GetLoadout();
int* slots = elem_create.GetSlots();
int squadron = elem_create.GetSquadron();
int code = elem_create.GetObjCode();
Text target = elem_create.GetObjective();
bool alert = elem_create.GetAlert();
bool active = elem_create.GetInFlight();
elem->SetIntelLevel(elem_create.GetIntel());
elem->SetLoadout(load);
if (code > Instruction::RTB || target.length() > 0) {
Instruction* obj = new(__FILE__,__LINE__) Instruction(code, target);
elem->AddObjective(obj);
}
Ship* carrier = sim->FindShip(elem_create.GetCarrier());
if (carrier) {
elem->SetCarrier(carrier);
Hangar* hangar = carrier->GetHangar();
if (hangar) {
Text squadron_name = hangar->SquadronName(squadron);
elem->SetSquadron(squadron_name);
if (active) {
for (int i = 0; i < 4; i++) {
int slot = slots[i];
if (slot > -1) {
hangar->GotoActiveFlight(squadron, slot, elem, load);
}
}
}
else {
FlightDeck* deck = 0;
int queue = 1000;
for (int i = 0; i < carrier->NumFlightDecks(); i++) {
FlightDeck* d = carrier->GetFlightDeck(i);
if (d && d->IsLaunchDeck()) {
int dq = hangar->PreflightQueue(d);
if (dq < queue) {
queue = dq;
deck = d;
}
}
}
for (int i = 0; i < 4; i++) {
int slot = slots[i];
if (slot > -1) {
hangar->GotoAlert(squadron, slot, deck, elem, load, !alert);
}
}
}
}
}
}