static void wid_intro_settings_add_default_screen_modes (void) { int w; int h; #if SDL_MAJOR_VERSION == 2 /* { */ SDL_DisplayMode mode; SDL_GetCurrentDisplayMode(0, &mode); w = mode.w; h = mode.h; #else const SDL_VideoInfo *info = SDL_GetVideoInfo(); w = info->current_w; h = info->current_h; #endif char *tmp = dynprintf("%dx%d", w, h); int j; for (j = 0; j < WID_INTRO_MAX_VAL - 1; j++) { if (!wid_intro_button_value_string [WID_INTRO_SETTINGS_ROW_WINDOW][j]) { wid_intro_button_value_string [WID_INTRO_SETTINGS_ROW_WINDOW][j] = tmp; break; } } /* } */ }
uint8_t config_save (void) { char *file = dynprintf("%s", config_dir_and_file); marshal_p ctx; LOG("Saving config to: %s", file); ctx = marshal(file); if (!ctx) { WARN("Failed to save: %s", file); myfree(file); return (false); } marshal_config(ctx, &global_config); if (marshal_fini(ctx) < 0) { WARN("Failed to finalize: %s", file); myfree(file); return (false); } myfree(file); return (true); }
static void server_rx_client_leave (gsocketp s) { aplayerp p = socket_get_player(s); if (!p) { WARN("Received leave %s, but no player on socket", socket_get_remote_logname(s)); return; } LOG("Server: \"%s\" (ID %u) left from %s", p->stats_from_client.pname, p->key, socket_get_remote_logname(s)); char *tmp = dynprintf("%s left the game", p->stats_from_client.pname); MSG_SERVER_SHOUT_AT_ALL_PLAYERS(INFO, 0, 0, "%s", tmp); myfree(tmp); server_rx_client_leave_implicit(s); }
uint8_t config_load (void) { char *file = dynprintf("%s", config_dir_and_file); demarshal_p ctx; /* * Default settings. */ global_config.video_pix_width = 0; global_config.video_pix_height = 0; global_config.sound_volume = 10; global_config.music_volume = 5; global_config.display_sync = 0; global_config.full_screen = 0; global_config.intro_screen = 1; global_config.fps_counter = 0; global_config.deathmatch = 0; global_config.deathmatch_monsters = 0; if (!global_config.server_name[0]) { strncpy(global_config.server_name, "unnamed-server", sizeof(global_config.server_name) - 1); } global_config.server_max_players = 4; global_config.server_port = SERVER_DEFAULT_PORT; if (!(ctx = demarshal(file))) { myfree(file); return (true); } if (!demarshal_config(ctx, &global_config)) { MSG_BOX("Failed to parse: %s", file); } myfree(file); demarshal_fini(ctx); return (true); }
static void server_rx_client_close (gsocketp s) { aplayerp p = socket_get_player(s); if (!p) { /* * Not an error. Just not in our game. */ return; } LOG("Server: \"%s\" (ID %u) suddenly left from %s", p->stats_from_client.pname, p->key, socket_get_remote_logname(s)); char *tmp = dynprintf("%s suddenly left the game", p->stats_from_client.pname); MSG_SERVER_SHOUT_AT_ALL_PLAYERS(CRITICAL, 0, 0, "%s", tmp); myfree(tmp); server_rx_client_leave_implicit(s); }
static void server_rx_client_join (gsocketp s) { aplayerp p = socket_get_player(s); if (!p) { WARN("Received join %s, but no player on socket", socket_get_remote_logname(s)); return; } global_config.server_current_players++; LOG("Server: Player \"%s\" (ID %u) joined from %s", p->stats_from_client.pname, p->key, socket_get_remote_logname(s)); thing_stats_dump(&p->stats_from_client); char *tmp = dynprintf("%s joined", p->stats_from_client.pname); MSG_SERVER_SHOUT_AT_ALL_PLAYERS(INFO, 0, 0, "%s", tmp); myfree(tmp); LOG("Server: Total players now %u", global_config.server_current_players); /* * Tick the player things so we work out their torch light so they do not * start the level in darkness. */ thing_tick_server_player_slow_all(true /* force */); socket_server_tx_map_update(s, server_boring_things, "rx client join boring things"); socket_server_tx_map_update(s, server_active_things, "rx client join active things"); wid_game_map_server_visible(); }
void wid_game_map_client_score_update (levelp level, uint8_t redo) { /* * Huge hack - we don't send ping/pong in single player mode, so * we don't get the level name. */ if (single_player_mode) { level = server_level; } if (!player) { return; } if (player->stats.pclass[0]) { wid_player_action_hide(true /* fast */, false /* player quit */); wid_player_action_visible(&player->stats, true /* fast */); } if (redo) { if (wid_scoreline_container_top) { wid_destroy(&wid_scoreline_container_top); } } uint8_t update; if (wid_scoreline_container_top) { update = true; } else { update = false; } /* * Create the area for the scores at the top. */ if (!update) { fpoint tl; fpoint br; tl.x = 0.7; tl.y = 0.0; br.x = 1.0; br.y = 1.0; wid_scoreline_container_top = wid_new_container(wid_game_map_client_window, "scoreline top"); wid_set_no_shape(wid_scoreline_container_top); wid_set_tl_br_pct(wid_scoreline_container_top, tl, br); wid_set_color(wid_scoreline_container_top, WID_COLOR_TL, BLACK); wid_set_color(wid_scoreline_container_top, WID_COLOR_BG, BLACK); wid_set_color(wid_scoreline_container_top, WID_COLOR_BR, BLACK); } double score_x = 0.78; double cash_x = 0.88; double player_y_offset = 0.17; // player start y double next_player_y_delta = 0.1; double score_and_cash_title_offset = 0.025; double score_and_cash_value_offset = 0.055; /* * Print the score. */ for (;;) { msg_player_state *p = client_get_player(); /* * Experience */ char tmp[20]; snprintf(tmp, sizeof(tmp), "%05u", p->stats.xp); static widp wid_score_container; if (!update) { wid_set_no_shape( wid_textbox(wid_scoreline_container_top, &wid_score, tmp, score_x, player_y_offset, med_font)); wid_score_container = wid_score; } else { wid_set_text(wid_score_container, tmp); wid_set_text_outline(wid_score_container, true); } /* * cash */ snprintf(tmp, sizeof(tmp), "%05u", p->stats.cash); static widp wid_cash_container; if (!update) { wid_set_no_shape( wid_textbox(wid_scoreline_container_top, &wid_cash, tmp, cash_x, player_y_offset, med_font)); wid_cash_container = wid_cash; } else { wid_set_text(wid_cash_container, tmp); wid_set_text_outline(wid_cash_container, true); } if (update) { break; } /* * Score title */ widp wid_score_title_container; wid_score_title_container = wid_textbox( wid_scoreline_container_top, &wid_score_title, "XP", score_x, player_y_offset - score_and_cash_title_offset, med_font); wid_set_no_shape(wid_score_title_container); /* * cash title */ widp wid_cash_title_container; wid_cash_title_container = wid_textbox( wid_scoreline_container_top, &wid_cash_title, "$$$", cash_x, player_y_offset - score_and_cash_title_offset, med_font); wid_set_no_shape(wid_cash_title_container); /* * Score title */ widp wid_name_title_container; char *name_title; /* * Just print the name, don't need the class as well. */ if (p->stats.pname[0]) { name_title = dynprintf("%%%%fg=cyan$%s", p->stats.pname); } else { name_title = 0; } wid_name_title_container = wid_textbox( wid_scoreline_container_top, &wid_name_title, name_title ? name_title : "No player", (score_x + cash_x) / 2, player_y_offset - score_and_cash_value_offset, med_font); if (name_title) { myfree(name_title); } wid_set_no_shape(wid_name_title_container); wid_set_color(wid_score, WID_COLOR_TEXT, RED); wid_set_color(wid_cash, WID_COLOR_TEXT, GOLD); wid_set_color(wid_score_title, WID_COLOR_TEXT, RED); wid_set_color(wid_cash_title, WID_COLOR_TEXT, GOLD); player_y_offset += next_player_y_delta; break; } if (update) { if (global_config.server_current_players > 1) { wid_raise(wid_chat_window); wid_visible(wid_chat_window, 0); } return; } /* * Print the level title. */ if (level_get_title(level) && strcasecmp(level_get_title(level), "(null)")) { widp wid_level_container; wid_level_container = wid_textbox(wid_scoreline_container_top, &wid_level, level_get_title(level), (score_x + cash_x) / 2.0, 0.02, med_font); wid_set_no_shape(wid_level_container); wid_set_color(wid_level, WID_COLOR_TEXT, WHITE); } /* * Print the level. */ if (client_level) { level_pos_t level_pos = level_get_level_pos(client_level); char *tmp = dynprintf("%%%%fg=green$Depth %d.%d", level_pos.y, level_pos.x); widp wid_level_container; wid_level_container = wid_textbox(wid_scoreline_container_top, &wid_level, tmp, (score_x + cash_x) / 2.0, 0.05, med_font); myfree(tmp); wid_set_no_shape(wid_level_container); wid_set_color(wid_level, WID_COLOR_TEXT, WHITE); } if (client_level) { uint32_t seed = level_get_seed(client_level); if (seed) { char *tmp = dynprintf("%%%%fg=green$Level %u", seed); widp wid_level_container; wid_level_container = wid_textbox(wid_scoreline_container_top, &wid_level, tmp, (score_x + cash_x) / 2.0, 0.08, med_font); myfree(tmp); wid_set_no_shape(wid_level_container); wid_set_color(wid_level, WID_COLOR_TEXT, WHITE); } } wid_raise(wid_scoreline_container_top); wid_update(wid_scoreline_container_top); wid_update_mouse(); wid_set_focus(wid_game_map_client_grid_container); if (global_config.server_current_players > 1) { wid_raise(wid_chat_window); wid_visible(wid_chat_window, 0); } }
static void wid_intro_settings_create (void) { wid_intro_settings_restart_needed = false; if (wid_intro_settings) { return; } widp w = wid_intro_settings = wid_new_rounded_window("wid settings"); fpoint tl = {0.0, 0.0}; fpoint br = {1.0, 1.0}; wid_set_tl_br_pct(w, tl, br); wid_set_no_shape(w); char *keys[WID_INTRO_MAX_SETTINGS]; char *values[WID_INTRO_MAX_SETTINGS]; int i; for (i = WID_INTRO_SETTINGS_ROW_WINDOW; i < WID_INTRO_MAX_SETTINGS; i++) { keys[i] = dynprintf("%s", wid_intro_button_name[i]); values[i] = dynprintf("%s", wid_intro_button_value_string[i][wid_intro_button_val[i]]); } i = WID_INTRO_SETTINGS_ROW_WINDOW; wid_intro_menu = wid_menu(wid_intro_settings, vvlarge_font, large_font, 0, // on_update 0.5, /* x */ 0.6, /* y */ 2, /* columns */ saved_focus, /* focus */ WID_INTRO_MAX_SETTINGS + 1, /* items */ /* * Column widths */ (double) 0.3, (double) 0.2, (int) '1', keys[i], values[i], wid_intro_settings_mouse_event, (int) '2', keys[i + 1], values[i + 1], wid_intro_settings_mouse_event, (int) '3', keys[i + 2], values[i + 2], wid_intro_settings_mouse_event, (int) '4', keys[i + 3], values[i + 3], wid_intro_settings_mouse_event, (int) '5', keys[i + 4], values[i + 4], wid_intro_settings_mouse_event, (int) 'b', "Back", (char*) 0, wid_intro_settings_back_mouse_event); for (i = WID_INTRO_SETTINGS_ROW_WINDOW; i < WID_INTRO_MAX_SETTINGS; i++) { myfree(keys[i]); myfree(values[i]); } wid_raise(wid_intro_settings); wid_update(wid_intro_settings); }
static void wid_intro_settings_read (void) { memcpy(&old_game, &game, sizeof(old_game)); const char *cmp_str; char *val_str; int32_t val; /* * window. */ val_str = dynprintf("%dx%d", game.video_pix_width, game.video_pix_height); for (val = 0; val < WID_INTRO_MAX_VAL; val++) { cmp_str = wid_intro_button_value_string [WID_INTRO_SETTINGS_ROW_WINDOW][val]; if (!cmp_str) { continue; } if (!strcasecmp(val_str, cmp_str)) { break; } } if (val == WID_INTRO_MAX_VAL) { MSG_BOX("Window size %s was not found in known list", val_str); val = 0; } wid_intro_button_val[WID_INTRO_SETTINGS_ROW_WINDOW] = val; myfree(val_str); /* * sound_volume. */ val = wid_intro_button_val[WID_INTRO_SETTINGS_ROW_SOUND] = game.sound_volume; if ((val >= WID_INTRO_MAX_VAL) || (val < 0) || !wid_intro_button_value_string[WID_INTRO_SETTINGS_ROW_SOUND][val]) { wid_intro_button_val[WID_INTRO_SETTINGS_ROW_SOUND] = 0; MSG_BOX("Sound volume size %d was not found in known list", val); } /* * music_volume. */ val = wid_intro_button_val[WID_INTRO_SETTINGS_ROW_MUSIC] = game.music_volume; if ((val >= WID_INTRO_MAX_VAL) || (val < 0) || !wid_intro_button_value_string[WID_INTRO_SETTINGS_ROW_MUSIC][val]) { wid_intro_button_val[WID_INTRO_SETTINGS_ROW_MUSIC] = 0; MSG_BOX("Music volume %d was not found in known list", val); } /* * display_sync. */ #if 0 val = wid_intro_button_val[WID_INTRO_SETTINGS_ROW_DISPLAY_SYNC] = game.display_sync; #endif /* * full_screen. */ val = wid_intro_button_val[WID_INTRO_SETTINGS_ROW_FULL_SCREEN] = game.full_screen; /* * fps_counter. */ val = wid_intro_button_val[WID_INTRO_SETTINGS_ROW_FPS_COUNTER] = game.fps_counter; }
static void wid_intro_settings_add_screen_modes (void) { int i; #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2 /* { */ SDL_Rect **modes; /* Get available fullscreen/hardware modes */ modes = SDL_ListModes(0, 0); /* Check if there are any modes available */ if (modes == (SDL_Rect**)0) { return; } /* Check if our resolution is restricted */ if (modes == (SDL_Rect**)-1) { return; } for (i=0; modes[i]; ++i) { char *tmp = dynprintf("%dx%d", modes[i]->w, modes[i]->h); #else /* } { */ for (i = 0; i < SDL_GetNumDisplayModes(0); ++i) { SDL_DisplayMode mode; SDL_GetDisplayMode(0, i, &mode); char *tmp = dynprintf("%dx%d", mode.w, mode.h); #endif /* } */ int j; for (j = 0; j < WID_INTRO_MAX_VAL - 1; j++) { if (!wid_intro_button_value_string [WID_INTRO_SETTINGS_ROW_WINDOW][j]) { wid_intro_button_value_string [WID_INTRO_SETTINGS_ROW_WINDOW][j] = tmp; break; } } } /* } */ } void wid_intro_settings_visible (void) { static int first = true; if (first) { first = false; wid_intro_settings_add_default_screen_modes(); wid_intro_settings_add_screen_modes(); } wid_intro_settings_read(); wid_intro_settings_create(); } static uint8_t wid_intro_settings_back_mouse_event (widp w, int32_t x, int32_t y, uint32_t button) { wid_intro_settings_save(); wid_intro_settings_hide(); wid_intro_restart_selected(); return (true); }