本文整理汇总了C++中Ship::AIFlyTo方法的典型用法代码示例。如果您正苦于以下问题:C++ Ship::AIFlyTo方法的具体用法?C++ Ship::AIFlyTo怎么用?C++ Ship::AIFlyTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ship
的用法示例。
在下文中一共展示了Ship::AIFlyTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: l_ship_ai_fly_to
/*
* Method: AIFlyTo
*
* Fly to the vicinity of a given physics body
*
* > ship:AIFlyTo(target)
*
* Parameters:
*
* target - the <Body> to fly to
*
* Availability:
*
* alpha 10
*
* Status:
*
* experimental
*/
static int l_ship_ai_fly_to(lua_State *l)
{
Ship *s = LuaObject<Ship>::CheckFromLua(1);
if (s->GetFlightState() == Ship::HYPERSPACE)
return luaL_error(l, "Ship:AIFlyTo() cannot be called on a ship in hyperspace");
Body *target = LuaObject<Body>::CheckFromLua(2);
s->AIFlyTo(target);
return 0;
}
示例2: HandleEvents
//.........这里部分代码省略.........
vector3d dir = -Pi::player->GetOrient().VectorZ();
/* add test object */
if (KeyState(SDLK_RSHIFT)) {
Missile *missile =
new Missile(ShipType::MISSILE_GUIDED, Pi::player);
missile->SetOrient(Pi::player->GetOrient());
missile->SetFrame(Pi::player->GetFrame());
missile->SetPosition(Pi::player->GetPosition()+50.0*dir);
missile->SetVelocity(Pi::player->GetVelocity());
game->GetSpace()->AddBody(missile);
missile->AIKamikaze(Pi::player->GetCombatTarget());
} else if (KeyState(SDLK_LSHIFT)) {
SpaceStation *s = static_cast<SpaceStation*>(Pi::player->GetNavTarget());
if (s) {
Ship *ship = new Ship(ShipType::POLICE);
int port = s->GetFreeDockingPort(ship);
if (port != -1) {
Output("Putting ship into station\n");
// Make police ship intent on killing the player
ship->AIKill(Pi::player);
ship->SetFrame(Pi::player->GetFrame());
ship->SetDockedWith(s, port);
game->GetSpace()->AddBody(ship);
} else {
delete ship;
Output("No docking ports free dude\n");
}
} else {
Output("Select a space station...\n");
}
} else {
Ship *ship = new Ship(ShipType::POLICE);
if( KeyState(SDLK_LCTRL) )
ship->AIFlyTo(Pi::player); // a less lethal option
else
ship->AIKill(Pi::player); // a really lethal option!
lua_State *l = Lua::manager->GetLuaState();
pi_lua_import(l, "Equipment");
LuaTable equip(l, -1);
LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("laser").Sub("pulsecannon_dual_1mw"));
LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("misc").Sub("laser_cooling_booster"));
LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("misc").Sub("atmospheric_shielding"));
lua_pop(l, 5);
ship->SetFrame(Pi::player->GetFrame());
ship->SetPosition(Pi::player->GetPosition()+100.0*dir);
ship->SetVelocity(Pi::player->GetVelocity());
ship->UpdateEquipStats();
game->GetSpace()->AddBody(ship);
}
}
break;
}
#endif /* DEVKEYS */
#if WITH_OBJECTVIEWER
case SDLK_F10:
Pi::SetView(Pi::game->GetObjectViewerView());
break;
#endif
case SDLK_F11:
// XXX only works on X11
//SDL_WM_ToggleFullScreen(Pi::scrSurface);
#if WITH_DEVKEYS
renderer->ReloadShaders();
#endif
break;
case SDLK_F9: // Quicksave
示例3: HandleKeyDown
//.........这里部分代码省略.........
Output("slow frame profiling %s\n", Pi::doProfileSlow ? "enabled" : "disabled");
}
break;
#endif
case SDLK_F12: {
if (Pi::game) {
vector3d dir = -Pi::player->GetOrient().VectorZ();
/* add test object */
if (input.KeyState(SDLK_RSHIFT)) {
Missile *missile =
new Missile(ShipType::MISSILE_GUIDED, Pi::player);
missile->SetOrient(Pi::player->GetOrient());
missile->SetFrame(Pi::player->GetFrame());
missile->SetPosition(Pi::player->GetPosition() + 50.0 * dir);
missile->SetVelocity(Pi::player->GetVelocity());
game->GetSpace()->AddBody(missile);
missile->AIKamikaze(Pi::player->GetCombatTarget());
} else if (input.KeyState(SDLK_LSHIFT)) {
SpaceStation *s = static_cast<SpaceStation *>(Pi::player->GetNavTarget());
if (s) {
Ship *ship = new Ship(ShipType::POLICE);
int port = s->GetFreeDockingPort(ship);
if (port != -1) {
Output("Putting ship into station\n");
// Make police ship intent on killing the player
ship->AIKill(Pi::player);
ship->SetFrame(Pi::player->GetFrame());
ship->SetDockedWith(s, port);
game->GetSpace()->AddBody(ship);
} else {
delete ship;
Output("No docking ports free dude\n");
}
} else {
Output("Select a space station...\n");
}
} else {
Ship *ship = new Ship(ShipType::POLICE);
if (!input.KeyState(SDLK_LALT)) { //Left ALT = no AI
if (!input.KeyState(SDLK_LCTRL))
ship->AIFlyTo(Pi::player); // a less lethal option
else
ship->AIKill(Pi::player); // a really lethal option!
}
lua_State *l = Lua::manager->GetLuaState();
pi_lua_import(l, "Equipment");
LuaTable equip(l, -1);
LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("laser").Sub("pulsecannon_dual_1mw"));
LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("misc").Sub("laser_cooling_booster"));
LuaObject<Ship>::CallMethod<>(ship, "AddEquip", equip.Sub("misc").Sub("atmospheric_shielding"));
lua_pop(l, 5);
ship->SetFrame(Pi::player->GetFrame());
ship->SetPosition(Pi::player->GetPosition() + 100.0 * dir);
ship->SetVelocity(Pi::player->GetVelocity());
ship->UpdateEquipStats();
game->GetSpace()->AddBody(ship);
}
}
break;
}
#endif /* DEVKEYS */
#if WITH_OBJECTVIEWER
case SDLK_F10:
Pi::SetView(Pi::game->GetObjectViewerView());
break;
#endif
case SDLK_F11:
// XXX only works on X11
//SDL_WM_ToggleFullScreen(Pi::scrSurface);
#if WITH_DEVKEYS
renderer->ReloadShaders();
#endif
break;
case SDLK_F9: // Quicksave
{
if (Pi::game) {
if (Pi::game->IsHyperspace())
Pi::game->log->Add(Lang::CANT_SAVE_IN_HYPERSPACE);
else {
const std::string name = "_quicksave";
const std::string path = FileSystem::JoinPath(GetSaveDir(), name);
try {
Game::SaveGame(name, Pi::game);
Pi::game->log->Add(Lang::GAME_SAVED_TO + path);
} catch (CouldNotOpenFileException) {
Pi::game->log->Add(stringf(Lang::COULD_NOT_OPEN_FILENAME, formatarg("path", path)));
} catch (CouldNotWriteToFileException) {
Pi::game->log->Add(Lang::GAME_SAVE_CANNOT_WRITE);
}
}
}
break;
}
default:
break; // This does nothing but it stops the compiler warnings
}
}
}