PyResult Command_spawnbelt( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if( !who->IsInSpace() ) throw PyException( MakeCustomError( "You must be in space to spawn things." ) ); const double beltradius = 100000.0; const double beltdistance = 25000.0; const double roidradius = MakeRandomFloat( 100.0, 1000.0 ); const double beltangle = M_PI * 2.0 / 3.0; const uint32 pcs = 20 + MakeRandomInt( -10, 10 ); // reduced from 160 + MakeRandomInt( -10, 10 ) const GPoint position( who->GetPosition() ); const double R = sqrt( position.x * position.x + position.z * position.z ); const GPoint r = position * ( R + beltdistance - beltradius ) / R; double phi = atan( position.x / position.z ); if( position.z < 0 ) phi += M_PI; SystemManager* sys = who->System(); std::map<double, uint32> roidDist; if( !db->GetRoidDist( sys->GetSystemSecurity(), roidDist ) ) { sLog.Error( "Command", "Couldn't get roid list for system security %s", sys->GetSystemSecurity() ); throw PyException( MakeCustomError( "Couldn't get roid list for system security %s", sys->GetSystemSecurity() ) ); } //double distanceToMe; double alpha; GPoint mposition; for( uint32 i = 0; i < pcs; ++i ) { alpha = beltangle * MakeRandomFloat( -0.5, 0.5 ); mposition.x = beltradius * sin( phi + alpha ) + roidradius * MakeRandomFloat( 0, 15 ); mposition.z = beltradius * cos( phi + alpha ) + roidradius * MakeRandomFloat( 0, 15 ); mposition.y = position.y - r.y + roidradius * MakeRandomFloat( 0, 15 ); //distanceToMe = (r + mposition - position).length(); SpawnAsteroid( who->System(), GetAsteroidType( MakeRandomFloat(), roidDist ), roidradius, r + mposition ); } return new PyString( "Spawn successsfull." ); }
void GameController::gameLoop() { wParams.mFullscreen = false; wParams.mHeight = screenHeight; wParams.mWidth = screenWidth; wParams.mTitle = "Project"; wParams.mPosX = 0; wParams.mPosY = 0; if (common.init(wParams)) { //Load all textures common.registerSoundResource("soundExplosion", "sound/explosion.ogg"); common.registerSoundResource("soundShoot", "sound/fire.ogg"); common.registerTextureResource("shoot", "image/spark.png"); common.registerTextureResource("plane", "image/plane.png"); common.registerTextureResource("explosion", "image/explosion.png"); common.registerTextureResource("asteroid1", "image/asteroid1.png"); common.registerTextureResource("asteroid2", "image/asteroid2.png"); common.registerTextureResource("asteroid3", "image/asteroid3.png"); common.registerTextureResource("asteroid4", "image/asteroid4.png"); common.registerTextureResource("asteroid5", "image/asteroid5.png"); common.registerTextureResource("asteroid6", "image/asteroid6.png"); common.registerTextureResource("background_menu", "image/space_background_menu.png"); common.registerTextureResource("background_after_game", "image/space_background_after_game.png"); common.registerTextureResource("health_package", "image/health_package.png"); common.registerFontResource("sans16", 16, "fonts/ARIAL.ttf"); common.registerFontResource("sans20", 20, "fonts/OpenSans-Regular.ttf"); common.registerFontResource("lobsterBold", 30, "fonts/LobsterTWo-Bold.otf"); EventManager em; common.setEventProcessor(&em); Graphics *g = common.getGraphics(); g->setViewport(0, 0, screenWidth, screenHeight); HiResTimer timer; timer.restart(); SetAsteroidType(currentLvl); Model::MenuModel menuModel; View::MenuView menuView(&common, &menuModel); menuModel.AddView(&menuView); int height, width; common.getGraphics()->getContextSize(&width, &height); menuModel.Init(Vec2(width, height)); Model::ManagerModel *managerModel = DBG_NEW Model::ManagerModel; View::ManagerView *managerView = DBG_NEW View::ManagerView(&common, managerModel); managerModel->AddView(managerView); common.getGraphics()->getContextSize(&width, &height); managerModel->Init(Vec2(width, height), GetAsteroidType().typ1, GetAsteroidType().type2, maxScore, currentLvl); currentState = GAMESTATE_INMENU; while (gRunning) { timer.tick(); // Process OS events. common.frame(); if (timerEsc <= 0) { timerEsc = 0; } else { timerEsc -= timer.getDeltaSeconds(); } InputState input; common.getInputState(&input); if (input.isDown(Button::BUTTON_ESCAPE)) { if (timerEsc <= 0) { if (currentState == GAMESTATE_INGAME) { currentState = GAMESTATE_INMENU; } else { currentState = GAMESTATE_INGAME; } timerEsc = coolDownEsc; } } if (managerModel->WonRound() || managerModel->LostRound()) { if (timerResultScreen <= 0) { timerResultScreen = 0; } else { timerResultScreen -= timer.getDeltaSeconds(); } if (managerModel->LostRound()) { menuModel.ShowLostRound(); currentState = GAMESTATE_AFTER_GAME; timerDelayScreenForExplosion = timeElapsedForExplosion; } else { if (currentLvl >= 2) { menuModel.ShowWonGame(); currentState = GAMESTATE_AFTER_GAME; } else { menuModel.ShowWonRound(); currentState = GAMESTATE_AFTER_GAME; } } if (timerResultScreen == 0) { timerResultScreen = timeElapseResultScreen; if (currentLvl >= 2) { currentState = GAMESTATE_INMENU; } else { currentState = GAMESTATE_INGAME; //Start new game. } if (managerModel->WonRound()) { ++currentLvl; SetAsteroidType(currentLvl); } delete managerModel; delete managerView; managerModel = NULL; managerView = NULL; managerModel = DBG_NEW Model::ManagerModel; managerView = DBG_NEW View::ManagerView(&common, managerModel); managerModel->AddView(managerView); common.getGraphics()->getContextSize(&width, &height); managerModel->Init(Vec2(width, height), GetAsteroidType().typ1, GetAsteroidType().type2, maxScore, currentLvl); } } if (currentState == GAMESTATE_INMENU) { //ShowCursor(TRUE); menuModel.OnUpdate(timer.getDeltaSeconds(), isGameStarted); menuView.OnUpdate(timer.getDeltaSeconds()); if (menuModel.IsPaused() && isGameStarted) { currentState = GAMESTATE_INGAME; } else if (menuModel.IsNewGame()) { currentState = GAMESTATE_INGAME; currentLvl = 0; SetAsteroidType(currentLvl); delete managerModel; delete managerView; managerModel = NULL; managerView = NULL; managerModel = DBG_NEW Model::ManagerModel; managerView = DBG_NEW View::ManagerView(&common, managerModel); managerModel->AddView(managerView); common.getGraphics()->getContextSize(&width, &height); managerModel->Init(Vec2(width, height), GetAsteroidType().typ1, GetAsteroidType().type2, maxScore, currentLvl); } g->clear(Color::Black, true); menuView.OnRenderMenu(); } else if (currentState == GAMESTATE_INGAME) { isGameStarted = true; //ShowCursor(FALSE); managerModel->OnUpdate(timer.getDeltaSeconds()); managerView->OnUpdate(timer.getDeltaSeconds()); g->clear(Color::Black, true); managerView->OnRender(); } else if (currentState == GAMESTATE_AFTER_GAME) { timerDelayScreenForExplosion -= timer.getDeltaSeconds(); if (timerDelayScreenForExplosion <= 0) { menuModel.OnUpdate(timer.getDeltaSeconds(), isGameStarted); menuView.OnUpdate(timer.getDeltaSeconds()); g->clear(Color::Black, true); menuView.OnRenderAfterGame(); } else if (timerResultScreen > 0) { menuModel.OnUpdate(timer.getDeltaSeconds(), isGameStarted); menuView.OnUpdate(timer.getDeltaSeconds()); g->clear(Color::Black, true); menuView.OnRenderAfterGame(); } else { managerModel->OnUpdate(timer.getDeltaSeconds()); managerView->OnUpdate(timer.getDeltaSeconds()); g->clear(Color::Black, true); managerView->OnRender(); } } g->present(); } } }
PyResult Command_spawnbelt( Client* who, CommandDB* db, PyServiceMgr* services, const Seperator& args ) { if( !who->IsInSpace() ) throw PyException( MakeCustomError( "You must be in space to spawn things." ) ); bool makeIceBelt = false; bool makeRareIce = false; uint32 customCount = 0; if( args.argCount() >= 2 ) { if( !args.isNumber( 1 ) ) { if( args.arg( 1 ) == "ice" ) makeIceBelt = true; } else { if( atoi(args.arg( 1 ).c_str()) > 15 ) customCount = atoi(args.arg( 1 ).c_str()); else PyException( MakeCustomError( "Argument 1 should be at least 15!" ) ); } } if( args.argCount() >= 3 ) { if( args.isNumber( 2 ) ) { if( atoi(args.arg( 2 ).c_str()) > 15 ) customCount = atoi(args.arg(2).c_str()); else PyException( MakeCustomError( "Argument 2 should be at least 15!" ) ); } else if( args.arg( 2 ) == "ice" ) makeIceBelt = true; if( args.arg( 2 ) == "rareice" ) { makeIceBelt = true; makeRareIce = true; } } const double beltradius = 100000.0; const double beltdistance = 25000.0; double roidradius; const double beltangle = M_PI * 2.0 / 3.0; uint32 pcs = 0; if( customCount > 15 ) pcs = customCount + static_cast<uint32>(MakeRandomInt( -10, 10 )); else pcs = 30 + static_cast<uint32>(MakeRandomInt( -10, 10 )); const GPoint position( who->GetPosition() ); const double R = sqrt( position.x * position.x + position.z * position.z ); const GPoint r = position * ( R + beltdistance - beltradius ) / R; double phi = atan( position.x / position.z ); if( position.z < 0 ) phi += M_PI; SystemManager* sys = who->System(); std::map<double, uint32> roidDist; if( makeIceBelt ) { std::string securityStatus = sys->GetSystemSecurity(); if( !makeRareIce ) { roidDist.insert(std::pair<double,uint32>(0.60,16264)); // Blue Ice roidDist.insert(std::pair<double,uint32>(0.45,17975)); // Thick Blue Ice roidDist.insert(std::pair<double,uint32>(0.30,28627)); // Azure Ice roidDist.insert(std::pair<double,uint32>(0.20,16262)); // Clear Icicle roidDist.insert(std::pair<double,uint32>(0.10,16267)); // Dark Glitter } if( makeRareIce ) { roidDist.insert(std::pair<double,uint32>(0.90,16263)); // Glacial Mass roidDist.insert(std::pair<double,uint32>(0.80,16265)); // White Glaze roidDist.insert(std::pair<double,uint32>(0.70,16266)); // Glare Crust roidDist.insert(std::pair<double,uint32>(0.60,16268)); // Gelidus roidDist.insert(std::pair<double,uint32>(0.50,16269)); // Krystallos roidDist.insert(std::pair<double,uint32>(0.40,17976)); // Pristine White Glaze roidDist.insert(std::pair<double,uint32>(0.30,17977)); // Smooth Glacial Mass roidDist.insert(std::pair<double,uint32>(0.20,17978)); // Enriched Clear Icicle roidDist.insert(std::pair<double,uint32>(0.10,28628)); // Crystalline Icicle } } else { if( !db->GetRoidDist( sys->GetSystemSecurity(), roidDist ) ) { sLog.Error( "Command", "Couldn't get roid list for system security %s", sys->GetSystemSecurity() ); throw PyException( MakeCustomError( "Couldn't get roid list for system security %s", sys->GetSystemSecurity() ) ); } } double distanceToMe; double alpha; GPoint mposition; if( makeIceBelt ) pcs *= 2; for( uint32 i = 0; i < pcs; ++i ) { alpha = beltangle * MakeRandomFloat( -0.5, 0.5 ); if( makeIceBelt ) roidradius = MakeRandomFloat( 1000.0, 10000.0 ); else roidradius = MakeRandomFloat( 100.0, 1000.0 ); mposition.x = beltradius * sin( phi + alpha ) + roidradius * MakeRandomFloat( 0, 15 ); mposition.z = beltradius * cos( phi + alpha ) + roidradius * MakeRandomFloat( 0, 15 ); mposition.y = position.y - r.y + roidradius * MakeRandomFloat( 0, 15 ); distanceToMe = (r + mposition - position).length(); SpawnAsteroid( who->System(), GetAsteroidType( MakeRandomFloat(), roidDist ), roidradius, r + mposition ); } return new PyString( "Spawn successsfull." ); }
/* * SQL to remove all asteroids from space in ALL systems. * Important, run in this order or the attributes will not be deleted! * DELETE FROM srvEntity_default_attributes WHERE attributeID > 0 and itemID in (SELECT itemID from srvEntity where ownerID=1 AND typeID in (SELECT typeID from invTypes where groupID in (select groupID FROM invGroups where categoryID=25) or groupID=711)); DELETE FROM srvEntity_attributes WHERE attributeID > 0 and itemID in (SELECT itemID from srvEntity where ownerID=1 AND typeID in (SELECT typeID from invTypes where groupID in (select groupID FROM invGroups where categoryID=25) or groupID=711)); DELETE FROM srvEntity WHERE itemID>=140000000 AND ownerID=1 AND typeID in (SELECT typeID from invTypes where groupID in (select groupID FROM invGroups where categoryID=25) or groupID=711); * */ PyResult Command_spawnbelt( Client* who, const Seperator& args ) { if (!who->IsInSpace()) { throw PyException(MakeCustomError("You must be in space to spawn things.")); } bool makeIceBelt = false; bool makeRareIce = false; uint32 customCount = 0; if( args.argCount() >= 2 ) { if( !args.isNumber( 1 ) ) { if( args.arg( 1 ) == "ice" ) makeIceBelt = true; } else { if( atoi(args.arg( 1 ).c_str()) > 15 ) customCount = atoi(args.arg( 1 ).c_str()); else PyException( MakeCustomError( "Argument 1 should be at least 15!" ) ); } } if( args.argCount() >= 3 ) { if( args.isNumber( 2 ) ) { if( atoi(args.arg( 2 ).c_str()) > 15 ) customCount = atoi(args.arg(2).c_str()); else PyException( MakeCustomError( "Argument 2 should be at least 15!" ) ); } else if( args.arg( 2 ) == "ice" ) makeIceBelt = true; if( args.arg( 2 ) == "rareice" ) { makeIceBelt = true; makeRareIce = true; } } double beltradius = 25000.0; // 25 KM if(makeIceBelt) { beltradius = 100000.0; // 100 KM } uint32 pcs = 0; if (customCount > 15) { pcs = customCount + static_cast<uint32> (MakeRandomInt(-10, 10)); } else { pcs = 200 + static_cast<uint32> (MakeRandomInt(-10, 10)); } SystemManager* sys = who->System(); std::map<double, uint32> roidDist; if (makeIceBelt) { pcs /= 8; std::string securityStatus = sys->GetSystemSecurity(); if (!makeRareIce) { roidDist.insert(std::pair<double, uint32>(0.60, 16264)); // Blue Ice roidDist.insert(std::pair<double, uint32>(0.45, 17975)); // Thick Blue Ice roidDist.insert(std::pair<double, uint32>(0.30, 28627)); // Azure Ice roidDist.insert(std::pair<double, uint32>(0.20, 16262)); // Clear Icicle roidDist.insert(std::pair<double, uint32>(0.10, 16267)); // Dark Glitter } if (makeRareIce) { roidDist.insert(std::pair<double, uint32>(0.90, 16263)); // Glacial Mass roidDist.insert(std::pair<double, uint32>(0.80, 16265)); // White Glaze roidDist.insert(std::pair<double, uint32>(0.70, 16266)); // Glare Crust roidDist.insert(std::pair<double, uint32>(0.60, 16268)); // Gelidus roidDist.insert(std::pair<double, uint32>(0.50, 16269)); // Krystallos roidDist.insert(std::pair<double, uint32>(0.40, 17976)); // Pristine White Glaze roidDist.insert(std::pair<double, uint32>(0.30, 17977)); // Smooth Glacial Mass roidDist.insert(std::pair<double, uint32>(0.20, 17978)); // Enriched Clear Icicle roidDist.insert(std::pair<double, uint32>(0.10, 28628)); // Crystalline Icicle } } else { if (!CommandDB::GetRoidDist(sys->GetSystemSecurity(), roidDist)) { SysLog::Error("Command", "Couldn't get roid list for system security %s", sys->GetSystemSecurity()); throw PyException(MakeCustomError("Couldn't get roid list for system security %s", sys->GetSystemSecurity())); } } const GPoint position(who->GetPosition()); double phi = atan(position.x / position.z); if (position.z == 0) { phi = M_PI / 2; } if (position.z < 0) { phi += M_PI; } GPoint beltOffset; if (makeIceBelt) { beltOffset.x = (beltradius * 0.75) * sin(phi); beltOffset.z = (beltradius * 0.75) * cos(phi); } double alpha; GPoint mposition; double beltThickness = 3000; double height; double roidradius; const double beltangle = M_PI * 2.0 / 3.0; int triesLeft = pcs * 25; int pcsLeft = pcs; std::vector<std::pair<GPoint, double>> spawned; while (triesLeft-- && pcsLeft) { uint32 typeID = GetAsteroidType(MakeRandomFloat(), roidDist); // Generate asteroid parameters. if( makeIceBelt) { height = MakeRandomFloat(-0.2, 1.8); alpha = beltangle * ((M_PI / 8) * height); roidradius = MakeRandomFloat(4000.0, 10000.0); height *= 8; } else { alpha = beltangle * MakeRandomFloat(-M_PI / 4, M_PI / 4); roidradius = MakeRandomFloat( 100.0, 1000.0 ); height = MakeRandomFloat(-1, 1); const ItemType *type = ItemFactory::GetType(typeID); if (type->groupID() == EVEDB::invGroups::Veldspar) { roidradius *= 2; } } // Calculate new position. mposition.y = beltThickness * height; mposition.x = beltradius * sin(phi + alpha) + beltThickness * MakeRandomFloat(-1, 1); mposition.z = beltradius * cos(phi + alpha) + beltThickness * MakeRandomFloat(-1, 1); // Check for collision. bool collision = false; for (auto pair : spawned) { GPoint point = pair.first; double dist = (mposition - point).length(); double radii = (roidradius + pair.second); if ((dist - radii) < 0) { collision = true; continue; } } if (collision) { // There was a collision, try again. continue; } // Were good, add the asteroid. pcsLeft--; SpawnAsteroid(who->System(), typeID, roidradius, mposition + position - beltOffset); // Save the location for collision checks. spawned.push_back(std::pair<GPoint, double>(mposition, roidradius)); } return new PyString( "Spawn successsfull." ); }