int init_game_level(int level_no) { game_o.current_level = level_no; game_o.level_end_rumble = true; game_o.bomb_delay_count = 0; game_o.immune = true; game_o.immunity_state = 0; game_o.immunity_delay_count = 0; game_o.immune = true; game_o.level_end_time = false; game_o.level_end_count = 0; game_o.level_end_phase = 0; game_o.level_end_display_active = false; game_o.powerups_spawened = false; game_o.level_kills = 0; game_o.level_spawened = 0; game_o.level_score = 0; game_o.active_npc_count = 0; game_o.player.x_pos =-0.9f+thruster_offset(); game_o.player.y_pos = 0.0f; game_o.player.x_dir = 0.0f; game_o.player.y_dir = 0.0f; game_o.player.x_vel = 0.0f; game_o.player.y_vel = 0.0f; game_o.player.health = game_o.player.max_health; game_o.player.shield = game_o.player.max_shield; game_o.rumble.stop(); init_in_game_message_class(); kill_active_npcs(); init_npcs(0); init_active_npcs(); kill_powerups(); kill_coins(); kill_wexps(); kill_player_bullet(); pos_supportships(game_o.player.x_pos,game_o.player.y_pos); kill_supportship_bullets(); game_o.level[game_o.current_level].wave[0].active = true; set_level_background(1,game_o.level[game_o.current_level].background_00); set_level_background(2,game_o.level[game_o.current_level].background_00); set_level_background(3,game_o.level[game_o.current_level].background_01); set_level_background(4,game_o.level[game_o.current_level].background_01); game.background.set_movement_type(SCROLL); game.music_track = game_o.level[game_o.current_level].music_track; game_o.speed = game_o.level[game_o.current_level].speed; game_o.npc_spawn_rate = game_o.level[game_o.current_level].NPC_spawn_rate; game_o.npc_spawn_rate_count = game_o.level[game_o.current_level].NPC_spawn_rate_count; game_o.npc_projectile_spawn_rate = game_o.level[game_o.current_level].NPC_projectile_spawn_rate; game_o.victory_kills = game_o.level[game_o.current_level].victory_kills; game_o.victory_score = game_o.level[game_o.current_level].victory_score; game_o.victory_spawened = game_o.level[game_o.current_level].victory_spawened; init_npcs(game_o.level[game_o.current_level].NPC_type); return(0); }
void init_server(void) { printf("Initializing Data. \n"); check_dir(LOG_PATH); printf("Loading Items. \n"); init_items(); printf("Loading Maps. \n"); init_maps(); printf("Loading Npcs. \n"); init_npcs(); printf("Loading Shops. \n"); init_shops(); printf("Loading Spells. \n"); init_spells(); printf("Initializing Player Data. \n"); init_players(); printf("Initializing Temp Player Data. \n"); init_temp_player_index(); printf("Data Initialized. \n"); }
/** * init_client(void) * * @brief Initializes client * @param void * @return void */ void init_client(void) { printf("Initializing Data. \n"); check_dir(LOG_PATH); check_tiles(); check_sprites(); check_items(); check_spells(); init_items(); _sleep(100); init_maps(); init_npcs(); init_shops(); init_spells(); init_players(); printf("Data Initialized. \n"); }
//----------------------------------- Main ------------------------------------- int main(int argc, char *argv[]) { std::string cheat_string = "cheat"; //std::locale::global( std::locale( "" ) ); events_init(); game.log.File_Set("Star.P.G..log"); game.log.File_Clear(); if (argc > 1) { for (int count = 0; count < (argc+1); count++) { //game.log.File_Write(argv[count]); if (cheat_string.compare(argv[count]) == 0) game_o.cheats_enabled = true; } } //game_o.cheats_enabled = true; /// test!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! game.log.File_Write("------------------"); game.log.File_Write("| Star.P.G V1.01 |"); game.log.File_Write("------------------\n"); game.log.File_Write("Starting up!"); game.log.File_Write(""); game.log.File_Write("------------------\n"); //if (game_o.cheats_enabled) game.log.File_Write("Cheating enabled!\n"); game.config.File_Set("Star.P.G..cfg"); game.config.Set_Defaults(); game.log.File_Write("Loading config..."); game.config.File_Set("Star.P.G..cfg"); game.config.File_Read(); game.log.File_Write("Loading language file -> data/configuration/languages/"+game.config.language+".txt"); game_o.language.load("data/configuration/languages/"+game.config.language+".txt"); //----------------------------------- Start the PhysicsFS ---------------------- //game.log.File_Write("Starting PhysicsFS..."); //PHYSFS_init(argv[0]); //PHYSFS_addToSearchPath("Star.P.G..spg", 1); //----------------------------------- SDL Video -------------------------------- game.log.File_Write("Starting SDL..."); char SDL_VID_WIN_POS[] = "SDL_VIDEO_WINDOW_POS"; char SDL_VID_CENTERD[] = "SDL_VIDEO_CENTERED=1"; putenv(SDL_VID_WIN_POS); putenv(SDL_VID_CENTERD); getenv("SDL_VIDEO_WINDOW_POS"); getenv("SDL_VIDEO_CENTERED"); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD); game.log.File_Write("Starting OpenGL..."); if (game.config.Display_Fullscreen) SDL_SetVideoMode(game.config.Display_X_Resolution,game.config.Display_Y_Resolution,game.config.Display_BPS,SDL_OPENGL | SDL_FULLSCREEN); else SDL_SetVideoMode(game.config.Display_X_Resolution,game.config.Display_Y_Resolution,game.config.Display_BPS,SDL_OPENGL/* | SDL_NOFRAME */); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); App_Icon_Surface = SDL_LoadBMP(App_Icon); colorkey = SDL_MapRGB(App_Icon_Surface->format, 255, 0, 255); SDL_SetColorKey(App_Icon_Surface, SDL_SRCCOLORKEY, colorkey); SDL_WM_SetIcon(App_Icon_Surface,NULL); SDL_WM_SetCaption(App_Name, 0); //SDL_ShowCursor(SDL_DISABLE); //----------------------------------- SDL Audio -------------------------------- game.log.File_Write("Starting sound system..."); SDL_Init(SDL_INIT_AUDIO); Mix_AllocateChannels(game.config.Audio_Channels); Mix_OpenAudio(game.config.Audio_Rate, AUDIO_S16, 2, game.config.Audio_Buffers); Mix_Volume(-1,game.config.Audio_Sound_Volume); Mix_VolumeMusic(game.config.Audio_Music_Volume); game.log.File_Write("Initializing joystick / gamepad..."); SDL_Init(SDL_INIT_JOYSTICK); game.log.File_Write("Initializing game system..."); init_game(false); game.log.File_Write("Initializing projectiles..."); init_player_bullets(); game.log.File_Write("Initializing explosions..."); init_explosions(); game.log.File_Write("Initializing NPCs...\n"); init_active_npcs(); init_npc_bullets(); init_npcs(0); game_o.current_level = 0; game.log.File_Write("Initializing OpenGL..."); game.graphics.init_gl(game.config.Display_X_Resolution,game.config.Display_Y_Resolution); seed_rand(); TTF_Init(); game.log.File_Write("Loading resources..."); loading_screen_display("data/textures/misc/loading_screen.png"); load_resources(); game.log.File_Write("Initializing menu system..."); init_menu(); init_in_game_message_class(); init_projectiles(false); init_powerups(); init_shields(false); init_game(false); game.log.File_Write("Starting game..."); game.log.File_Write("---------------\n"); //----------------------------------- Main loop -------------------------------- game.timer.start(); game.LastTicks = game.timer.getticks(); for(int quit = 0; !quit;) { game.config.process(false); if (game.config.mouse_autohide) SDL_ShowCursor(SDL_DISABLE); else SDL_ShowCursor(SDL_ENABLE); proc_textures(); events_process(); if (game.status_quit_active) quit = 1; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //****************************************** MENU ***************************************** if (game.menu_active) { SDL_ShowCursor(SDL_ENABLE); if (game.music_next_track) { music.menu_00.play(); game.music_next_track = false; } diplay_menu (); if (game.process_ready) game.background.process(); if (game.process_ready) process_menu(); } //****************************************** GAME ***************************************** if (game.game_active) { if (game.music_next_track) { game.music_next_track = false; if (game.music_track == 0) music.level_00.play(); if (game.music_track == 1) music.level_01.play(); if (game.music_track == 2) music.level_02.play(); if (game.music_track == 3) music.level_03.play(); if (game.music_track == 4) music.level_04.play(); if (game.music_track == 5) music.level_05.play(); if (game.music_track == 6) music.level_06.play(); if (game.music_track == 7) music.level_07.play(); if (game.music_track == 8) music.level_08.play(); if (game.music_track == 9) music.level_09.play(); if (game.music_track == 10) music.level_10.play(); if (game.music_track == 11) music.level_11.play(); if (game.music_track == 12) music.level_12.play(); if (game.music_track == 13) music.level_13.play(); if (game.music_track == 14) music.level_14.play(); if (game.music_track == 15) music.level_15.play(); if (game.music_track == 16) music.level_16.play(); if (game.music_track == 17) music.level_17.play(); if (game.music_track == 18) music.level_18.play(); if (game.music_track == 19) music.level_19.play(); if (game.music_track == 20) music.level_20.play(); if (game.music_track == 21) music.level_21.play(); if (game.music_track == 22) music.level_22.play(); if (game.music_track == 23) music.level_23.play(); if (game.music_track == 24) music.level_24.play(); if (game.music_track == 25) music.level_25.play(); } game.game_resume = true; if (game.process_ready) process_game(); display_game(); if ((game.config.Display_Touchscreen) && (game.process_ready)) { if(game.physics.point_in_quadrangle(-0.875f,0.2f,-0.550f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.left = true; if(game.physics.point_in_quadrangle(-0.475f,0.2f,-0.550f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.right = true; if(game.physics.point_in_quadrangle(-0.675f,0.2f,-0.350f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.up = true; if(game.physics.point_in_quadrangle(-0.675f,0.2f,-0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.down = true; if(game.physics.point_in_quadrangle( 0.875f,0.2f,-0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.shoot = true; if(game.physics.point_in_quadrangle( 0.575f,0.2f,-0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.key_b = true; if(game.physics.point_in_quadrangle( 0.875f,0.2f, 0.750f,0.2f,game.io.mouse_x,game.io.mouse_y)) game.io.escape = true; } if (game_o.player.health < 0) { sound.menu_select_00.play(); game.game_active = false; game.game_resume = false; game.pdie_active = true; game.menu_level = 8; game.config.menu_delay_count = 0; music.level_pd.play(); game.background.set_data ( 2, 1, 1, 0.0f, 0.0f, 0.0050f, 0.0050f, texture.background_019.ref_number); game.background.set_data ( 1, 1, 1, 0.0f, 0.0f, 0.0020f, 0.0020f, texture.background_008.ref_number); game.background.set_active( 3, false); game.background.set_active( 4, false); game.background.set_movement_type(BOUNCE); SDL_WarpMouse(game.graphics.gl_to_res(game_over_menu.get_button_x_pos(1),game.config.mouse_resolution_x),game.config.mouse_resolution_y-game.graphics.gl_to_res(game_over_menu.get_button_y_pos(1),game.config.mouse_resolution_y)); game.log.File_Write("User terminated due to insufficient health...better luck next time buddy!"); } if ((game.io.escape) && (game.process_ready)) { sound.menu_select_01.play(); game.music_next_track = true; game.game_active = false; game.menu_level = 1; game.menu_active = true; game.io.escape = false; game.io.keyboard_delay_count = 0; game.config.menu_delay_count = 0; while (game.config.menu_delay_count < (game.config.menu_delay/2)) { game.config.menu_delay_count++; } } if (game_o.bomb_delay_count < game_o.bomb_delay)//bomb delay counter { game_o.bomb_delay_count++; if (game_o.bomb_delay_count > game_o.bomb_delay) game_o.bomb_delay_count = game_o.bomb_delay; } if ((game.io.key_b) && (game.process_ready))//user pressed "b" for bomb { if ((game_o.number_bombs > 0) && (game_o.bomb_delay_count >= game_o.bomb_delay)) { game_o.number_bombs--; use_bomb_powerup(); game_o.bomb_delay_count = 0; if (!game_o.rumble.active) sound.explosion_001.play(); if (!game_o.rumble.active) game_o.rumble.start(0.025f,45); // shake the screen about. } } if (game.io.pause) { if (!game.game_paused) { game_o.paused.spawn(); game.game_paused = true; game.game_active = false; game.io.pause = false; game.menu_level = 11; SDL_WarpMouse(game.graphics.gl_to_res(pause_menu.get_button_x_pos(1),game.config.mouse_resolution_x),game.config.mouse_resolution_y-game.graphics.gl_to_res(pause_menu.get_button_y_pos(1),game.config.mouse_resolution_y)); game.config.menu_delay_count = 0; while (game.config.menu_delay_count < (game.config.menu_delay*16)) { game.config.menu_delay_count++; } } else { game.menu_active = false; game.game_paused = false; game.game_active = true; } }; if (game_o.cheats_enabled == true) { if (game.io.key_0) game_o.victory_kills = game_o.level_kills; //complete level if (game.io.key_1) spawn_powerup(1.0f,random_GLcoord(), 1);//spawn health power-up if (game.io.key_2) spawn_powerup(1.0f,random_GLcoord(), 2);//spawn shield level power-up if (game.io.key_3) spawn_powerup(1.0f,random_GLcoord(), 3);//spawn shield new power-up if (game.io.key_4) spawn_powerup(1.0f,random_GLcoord(), 4);//spawn thruster level power-up if (game.io.key_5) spawn_powerup(1.0f,random_GLcoord(), 5);//spawn thruster new power-up if (game.io.key_6) spawn_powerup(1.0f,random_GLcoord(), 6);//spawn weapon level power-up if (game.io.key_7) spawn_powerup(1.0f,random_GLcoord(), 7);//spawn weapon new power-up if (game.io.key_8) unlock_levels(); //unlock all levels if (game.io.key_9) spawn_powerup(1.0f,random_GLcoord(), 8);//spawn bomb power-up if (game.io.key_a) game_o.anc_enabled = !game_o.anc_enabled; //toggle active NPC count display if (game.io.key_f) game_o.fps_enabled = !game_o.fps_enabled; //toggle active NPC count display if (game.io.key_q) spawn_powerup(1.0f,random_GLcoord(), 9);//spawn support ship 0 power-up if (game.io.key_w) spawn_powerup(1.0f,random_GLcoord(),10);//spawn support ship 1 power-up if (game.io.key_e) spawn_powerup(1.0f,random_GLcoord(),11);//spawn support ship 2 power-up if (game.io.key_r) spawn_powerup(1.0f,random_GLcoord(),12);//spawn support ship 3 power-up if (game.io.key_s) { if (!game_o.rumble.active) sound.explosion_001.play(); if (!game_o.rumble.active) game_o.rumble.start(); // shake the screen about. } } if (game.io.shoot) { process_supportships(true); if(game_o.fw_rof_count >= game_o.projectile[game_o.player.front_weapon].rate_of_fire) { spawn_player_bullet(0); game_o.fw_rof_count = 0; } if(game_o.sw_rof_count >= game_o.projectile[game_o.player.side_weapon].rate_of_fire) { spawn_player_bullet(1); game_o.sw_rof_count = 0; } } else { process_supportships(false); } if (game.process_ready) { if (game.io.up) process_player(1); if (game.io.down) process_player(2); if (game.io.right) process_player(3); if (game.io.left) process_player(4); } if ((game.io.key_1) && (game_o.projectile[ 0].active)) { game_o.player.front_weapon = 0; } if ((game.io.key_2) && (game_o.projectile[ 1].active)) { game_o.player.front_weapon = 1; } if ((game.io.key_3) && (game_o.projectile[ 2].active)) { game_o.player.front_weapon = 2; } if ((game.io.key_4) && (game_o.projectile[ 3].active)) { game_o.player.front_weapon = 3; } if ((game.io.key_5) && (game_o.projectile[ 4].active)) { game_o.player.front_weapon = 4; } if ((game.io.key_6) && (game_o.projectile[ 5].active)) { game_o.player.front_weapon = 5; } } //*********************************** Game paused ***************************************** if (game.game_paused) { if ((game.io.pause) && (game.process_ready)) { game.menu_active = false; game.game_paused = false; game.game_active = true; } if (game.music_next_track) { game.music_next_track = false; music.level_pd.play(); } game.menu_level = 11; if (game.process_ready) game.background.process(); if (game.process_ready) process_menu(); display_game(); diplay_menu (); } //*********************************** PLAYER DEATH SCREEN ***************************************** if (game.pdie_active) { if (game.music_next_track) { game.music_next_track = false; music.level_pd.play(); } diplay_menu (); if (game.process_ready) game.background.process(); if (game.process_ready) process_menu(); if (!game.pdie_active) init_game(true); } //******************************* PLAYER NEXT LEVEL SCREEN ************************************* if (game.nlvl_active) { if (game.music_next_track) { game.music_next_track = false; music.level_nl.play(); } game.menu_level = 9; if (game.process_ready) game.background.process(); if (game.process_ready) process_menu(); diplay_menu (); } //******************************* OUTRO SCREEN ************************************************* if (game.outr_active) { if (game.music_next_track) { game.music_next_track = false; music.outro_00.play(); } game.menu_level = 10; if (game.process_ready) game.background.process(); if (game.process_ready) process_menu(); diplay_menu (); } //---------------------------- code for end of main loop ----------------------- game.FPS = (game.timer.getticks() - game.LastTicks); if ((game.timer.getticks() - game.LastTicks) >= 2) { game.LastTicks = game.timer.getticks(); game.process_ready = true; } else game.process_ready = false; SDL_GL_SwapBuffers(); } //----------------------------------- Exit ------------------------------------- game.log.File_Write("Saving configuration..."); game.config.File_Set("Star.P.G..cfg"); game.config.File_Clear(); game.config.File_Write(); game.log.File_Write("\n"); game.log.File_Write("Shutting down..."); game.log.File_Write("---------------\n"); // game.log.File_Write("PhysicsFS deinit..."); // PHYSFS_deinit(); game.log.File_Write("SDL deinit..."); SDL_Quit(); return(0); }
int init_service(int isparent) { if (!isparent) { DEBUG_LOG("INIT_SERVICE"); const char *ip= get_ip_ex(0x01); if ( strncmp( ip,"10.",3 )==0 ) { g_is_test_env=true; DEBUG_LOG("=============TEST ENV TRUE ============="); }else{ g_is_test_env=false; DEBUG_LOG("=============TEST ENV FALSE ============="); } g_log_send_buf_hex_flag=g_is_test_env?1:0; if (sizeof(sprite_t) >= SPRITE_STRUCT_LEN - 800 || sizeof(grp_loop_t) != VIP_BUFF_LEN) { ERROR_RETURN(("sprite struct not big enough\t[%lu %u]", sizeof(sprite_t), SPRITE_STRUCT_LEN), -1); } srand(time(0) * get_server_id()); setup_timer(); INIT_LIST_HEAD(&(g_events.timer_list)); INIT_LIST_HEAD(&active_box_list); if ( config_get_strval("_use_lua_config") ==NULL ){ config_init("./conf/common.conf"); } statistic_logfile = config_get_strval("statistic_file"); if (!statistic_logfile) return -1; if ((init_cli_proto_handles(0) == -1) || (init_db_proto_handles(0) == -1) || (init_home_handle_funs() == -1) || (init_switch_handle_funs() == -1) || (init_all_timer_type() == -1) || (init_magic_code_proto_handles(0) == -1) || (init_spacetime_code_proto_handles(0) == -1) || (init_mall_proto_handles(0) == -1) ) { return -1; } init_sprites(); init_exp_lv(); init_home_maps(); init_all_items(); init_beast_grp(); init_rand_infos(); init_npcs(); init_all_skills(); init_all_clothes(); init_sys_info(); init_all_tasks(); init_mail(); init_shops(); init_vip_items(); init_products(); idc_type = config_get_intval("idc_type" ,1); KDEBUG_LOG(0, "ONLINE START\t[%lu %d]", sizeof(sprite_t), idc_type); if ( //11 (load_xmlconf("./conf/items.xml", load_items) == -1) || (load_xmlconf("./conf/clothes.xml", load_clothes) == -1) || (load_xmlconf("./conf/beasts.xml", load_beasts) == -1) // || (load_xmlconf("./conf/pet_exchange.xml", load_pet_exchange) == -1)//3M || (load_xmlconf("./conf/pet_exchange_egg.xml", load_pet_exchange_egg) == -1) //62 || (load_xmlconf("./conf/gplan.xml", load_rare_beasts) == -1) || (load_xmlconf("./conf/titles.xml", load_honor_titles) == -1) || (load_xmlconf("./conf/picsrv.xml", load_picsrv_config) == -1) ) { return -1; } if ( load_xmlconf("./conf/beastgrp.xml", load_beast_grp) == -1 || (load_xmlconf("./conf/handbook.xml", load_handbook) == -1) || (load_xmlconf("./conf/suits.xml", load_suit) == -1) || ( load_xmlconf("./conf/maps.xml", load_maps) == -1) || (load_xmlconf("./conf/rand_item.xml", load_rand_item) == -1) || (load_xmlconf("./conf/vip_item.xml", load_vip_item) == -1) || (load_xmlconf("./conf/commodity.xml", load_products) == -1) || (load_xmlconf("./conf/skills_price.xml", load_all_skills) == -1) || (load_xmlconf("./conf/tasks_new.xml", load_tasks) == -1)//task:12M || (load_xmlconf("./conf/tasks_new.xml", load_task_loops) == -1) || (load_xmlconf("./conf/holiday.xml", load_holiday_factor) == -1) || (load_xmlconf("./conf/box.xml", load_box) == -1) || (load_xmlconf("./conf/exchanges.xml", load_exchange_info) == -1) || (load_xmlconf("./conf/npc.xml", load_npc) == -1) || (load_xmlconf("./conf/npcSkills.xml", load_shop_skill) == -1) || (load_xmlconf("./conf/npcShop.xml", load_shop_item) == -1) || (load_xmlconf("./conf/mail.xml", load_sys_mail) == -1) || (load_xmlconf("./conf/sysinfo.xml", load_sys_info) == -1) || (load_xmlconf("./conf/fishGame.xml", load_fish_info) == -1) || (load_xmlconf("./conf/professtion.xml", load_init_prof_info) == -1) || (load_xmlconf("./conf/maze.xml", load_maze_xml) == -1) || (load_xmlconf("./conf/mapcopy.xml", load_map_copy) == -1) ) return -1; // sleep(1000); activate_boxes(); start_maze_timer(); /* if(tm_load_dirty("./data/tm_dirty.dat") < 0){ KERROR_LOG(0, "Failed to load drity word file!"); return -1; } */ init_batter_teams(); init_batter_infos(); connect_to_switch_timely(0, 0); regist_timers(); udp_report_fd = create_udp_socket(&udp_report_addr, config_get_strval("report_svr_ip"), config_get_intval("report_svr_port", 0)); udp_post_fd = create_udp_socket(&udp_post_addr, config_get_strval("post_svr_ip"), config_get_intval("post_svr_port", 0)); switch (idc_type) { case idc_type_dx: chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("dx_chat_svr_ip"), config_get_intval("chat_svr_port", 0)); break; case idc_type_wt: chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("wt_chat_svr_ip"), config_get_intval("chat_svr_port", 0)); break; case idc_type_internal: case idc_type_internal + 1: chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("in_chat_svr_ip"), config_get_intval("chat_svr_port", 0)); break; default: return -1; } } return 0; }