void launch_rocket(int x, int y) { int i, r, xx, yy, xxx, yyy; rockets_launched++; MP_TYPE(x, y) = CST_ROCKET_FLOWN; update_main_screen(0); /* The first five failures gives 49.419 % chances of 5 success * TODO: some stress could be added by 3,2,1,0 and animation of rocket with sound... */ r = rand() % MAX_TECH_LEVEL; if (r > tech_level || rand() % 100 > (rockets_launched * 15 + 25)) { /* the launch failed */ display_rocket_result_dialog(ROCKET_LAUNCH_BAD); rockets_launched_success = 0; xx = ((rand() % 40) - 20) + x; yy = ((rand() % 40) - 20) + y; for (i = 0; i < 20; i++) { xxx = ((rand() % 20) - 10) + xx; yyy = ((rand() % 20) - 10) + yy; if (xxx > 0 && xxx < (WORLD_SIDE_LEN - 4) && yyy > 0 && yyy < (WORLD_SIDE_LEN - 4)) { /* don't crash on it's own area */ if (xxx >= x && xxx < (x + 4) && yyy >= y && yyy < (y + 4)) continue; fire_area(xxx, yyy); /* make a sound perhaps */ } } } else { rockets_launched_success++; /* TODO: Maybe should generate some pollution ? */ if (rockets_launched_success > 5) { remove_people(1000); if (people_pool || housed_population) display_rocket_result_dialog(ROCKET_LAUNCH_EVAC); } else { display_rocket_result_dialog(ROCKET_LAUNCH_GOOD); } } }
// called when the window is brought to the foreground (appears) static void handle_window_update(Window* window){ update_main_screen(); }
// creates all layers in this window and allocates heap memory static void initialise_ui(void) { s_window = window_create(); s_res_image_action_icon_reset = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_RESET); s_res_image_action_icon_play_pause = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_PLAY_PAUSE); s_res_image_action_icon_play = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_PLAY); s_res_image_action_icon_pause = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_PAUSE); s_res_image_action_icon_increment = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_INCREMENT); s_res_image_action_icon_finish = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_FINISH); s_res_distFont = fonts_get_system_font(FONT_KEY_LECO_26_BOLD_NUMBERS_AM_PM ); s_res_timerFont_large = fonts_get_system_font(FONT_KEY_LECO_36_BOLD_NUMBERS); s_res_timerFont_small = fonts_get_system_font(FONT_KEY_LECO_28_LIGHT_NUMBERS); s_res_timeFont = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD); s_res_statFont = fonts_get_system_font(FONT_KEY_LECO_20_BOLD_NUMBERS ); // s_actionbarlayer_1 s_actionbarlayer_1 = action_bar_layer_create(); action_bar_layer_add_to_window(s_actionbarlayer_1, s_window); action_bar_layer_set_icon(s_actionbarlayer_1, BUTTON_ID_SELECT, s_res_image_action_icon_play_pause); action_bar_layer_set_click_config_provider(s_actionbarlayer_1, click_config_provider); layer_add_child(window_get_root_layer(s_window), (Layer *)s_actionbarlayer_1); // s_bitmaplayer_bar_1_bar bar 1 s_bitmaplayer_bar_1 = bitmap_layer_create(GRect(s_barPos_x, s_barPos_y, s_barWidth, s_barHeight)); layer_add_child(window_get_root_layer(s_window), (Layer *)s_bitmaplayer_bar_1); // s_bitmaplayer_titlebox_1 s_bitmaplayer_titlebox_1 = bitmap_layer_create(GRect(s_boxPos_x1, s_boxPos_y, s_boxWidth_lap, s_titleHeight)); layer_add_child(window_get_root_layer(s_window), (Layer *)s_bitmaplayer_titlebox_1); // s_bitmaplayer_titlebox_2 s_bitmaplayer_titlebox_2 = bitmap_layer_create(GRect(s_boxPos_x2, s_boxPos_y, s_boxWidth_dist, s_titleHeight)); layer_add_child(window_get_root_layer(s_window), (Layer *)s_bitmaplayer_titlebox_2); // s_bitmaplayer_unitbox_1 s_bitmaplayer_unitbox_1 = bitmap_layer_create(GRect(s_boxPos_x1, s_unitPos_y, s_boxWidth_lap, s_unitboxHeight)); layer_add_child(window_get_root_layer(s_window), (Layer *)s_bitmaplayer_unitbox_1); // s_bitmaplayer_unitbox_2 s_bitmaplayer_unitbox_2 = bitmap_layer_create(GRect(s_boxPos_x2, s_unitPos_y, s_boxWidth_dist, s_unitboxHeight)); layer_add_child(window_get_root_layer(s_window), (Layer *)s_bitmaplayer_unitbox_2); // s_textlayer_laps_num s_textlayer_laps_num = text_layer_create(GRect(s_digitPos_x1, s_digitPos_y, s_boxWidth_lap, s_digitHeight)); text_layer_set_background_color(s_textlayer_laps_num, GColorClear); text_layer_set_text_alignment(s_textlayer_laps_num, GTextAlignmentCenter); text_layer_set_font(s_textlayer_laps_num, s_res_distFont); layer_add_child(window_get_root_layer(s_window), (Layer *)s_textlayer_laps_num); // s_textlayer_laps_title s_textlayer_laps_title = text_layer_create(GRect(s_boxPos_x1, s_boxPos_y, s_boxWidth_lap, s_titleHeight)); text_layer_set_background_color(s_textlayer_laps_title, GColorClear); text_layer_set_text(s_textlayer_laps_title, "Laps"); text_layer_set_text_alignment(s_textlayer_laps_title, GTextAlignmentCenter); layer_add_child(window_get_root_layer(s_window), (Layer *)s_textlayer_laps_title); // s_textlayer_dist_unit s_textlayer_dist_unit = text_layer_create(GRect(s_boxPos_x2, s_unitPos_y-2, s_boxWidth_dist, s_unitboxHeight)); text_layer_set_background_color(s_textlayer_dist_unit, GColorClear); text_layer_set_text_alignment(s_textlayer_dist_unit, GTextAlignmentCenter); layer_add_child(window_get_root_layer(s_window), (Layer *)s_textlayer_dist_unit); // s_textlayer_dist_num s_textlayer_dist_num = text_layer_create(GRect(s_digitPos_x2, s_digitPos_y, s_boxWidth_dist+4, s_digitHeight)); text_layer_set_background_color(s_textlayer_dist_num, GColorClear); text_layer_set_text_alignment(s_textlayer_dist_num, GTextAlignmentCenter); text_layer_set_font(s_textlayer_dist_num, s_res_distFont); layer_add_child(window_get_root_layer(s_window), (Layer *)s_textlayer_dist_num); // s_textlayer_dist_title s_textlayer_dist_title = text_layer_create(GRect(s_boxPos_x2, s_boxPos_y, s_boxWidth_dist+2, s_titleHeight)); text_layer_set_background_color(s_textlayer_dist_title, GColorClear); text_layer_set_text(s_textlayer_dist_title, "Distance"); text_layer_set_text_alignment(s_textlayer_dist_title, GTextAlignmentCenter); layer_add_child(window_get_root_layer(s_window), (Layer *)s_textlayer_dist_title); // s_textlayer_time s_textlayer_time = text_layer_create(GRect(0, -8, 114, 50)); text_layer_set_background_color(s_textlayer_time, GColorClear); text_layer_set_text_alignment(s_textlayer_time, GTextAlignmentCenter); text_layer_set_font(s_textlayer_time, s_res_timeFont); layer_add_child(window_get_root_layer(s_window), (Layer *)s_textlayer_time); // s_textlayer_timer s_textlayer_timer = text_layer_create(GRect(0, 8, 114, 50)); text_layer_set_background_color(s_textlayer_timer, GColorClear); text_layer_set_text_alignment(s_textlayer_timer, GTextAlignmentCenter); text_layer_set_font(s_textlayer_timer, s_res_timerFont_large); layer_add_child(window_get_root_layer(s_window), (Layer *)s_textlayer_timer); // s_textlayer_stats s_textlayer_stats = text_layer_create(GRect(s_statsPos_x, s_statsPos_y, s_statsWidth, s_statsHeight)); text_layer_set_background_color(s_textlayer_stats, GColorClear); text_layer_set_text_alignment(s_textlayer_stats, GTextAlignmentCenter); text_layer_set_font(s_textlayer_stats, s_res_statFont); layer_add_child(window_get_root_layer(s_window), (Layer *)s_textlayer_stats); // update screen text and color scheme update_main_screen(); }
/* The "guts" of main loop is here. */ int execute_timestep (void) { static int next_time_step = 0; int engine_updated = 0; int real_quit_flag = 0; if (market_cb_flag == 0 && help_flag == 0 && port_cb_flag == 0 && prefs_flag == 0) { if ((real_time < next_time_step || pause_flag || mt_flag) && save_flag == 0 && load_flag == 0) { if ((let_one_through == 0) || mt_flag) { lc_usleep (1); return 0; } else let_one_through = 0; } if (slow_flag) next_time_step = real_time + (SLOW_TIME_FOR_YEAR * 1000 / NUMOF_DAYS_IN_YEAR); else if (fast_flag) next_time_step = real_time + (FAST_TIME_FOR_YEAR * 1000 / NUMOF_DAYS_IN_YEAR); else if (med_flag) next_time_step = real_time + (MED_TIME_FOR_YEAR * 1000 / NUMOF_DAYS_IN_YEAR); do_time_step (); #ifdef CS_PROFILE if (--prof_countdown <= 0) real_quit_flag = 1; #endif update_main_screen (0); /* XXX: Shouldn't the rest be handled in update_main_screen()? */ /* GCS: No, I don't think so. These remaining items are outside of the main screen */ print_stats (); if (market_cb_flag) draw_market_cb (); else if (port_cb_flag) /* else- can't have both */ draw_port_cb (); } else /* if game is "stalled" */ { if (market_cb_flag != 0 && market_cb_drawn_flag == 0) draw_market_cb (); if (port_cb_flag != 0 && port_cb_drawn_flag == 0) draw_port_cb (); #if defined (SVGALIB) mouse_update (); #endif } #if defined (NETWORK_ENABLE) if (network_flag != 0) { do_network_screen (); network_flag = 0; let_one_through = 1; /* if we are paused we need */ } /* this to redraw the screen */ #endif if (prefs_flag != 0 && prefs_drawn_flag == 0) { do_prefs_screen (); let_one_through = 1; /* if we are paused we need */ } /* this to redraw the screen */ if (load_flag != 0) { #if defined (WIN32) DisableWindowsMenuItems (); #endif if (help_flag == 0) /* block loading when in help */ do_load_city (); load_flag = 0; let_one_through = 1; /* if we are paused we need */ } /* this to redraw the screen */ else if (save_flag != 0) { #if defined (WIN32) DisableWindowsMenuItems (); #endif if (help_flag == 0) do_save_city (); save_flag = 0; let_one_through = 1; } else if (quit_flag != 0) { #if defined (WIN32) DisableWindowsMenuItems (); #endif if (yn_dial_box (_("Quit The Game?") ,_("Do you really want to quit?") ,_("If you want to save the game select NO.") ,"" /* GCS: This can't be translated!. */ ) != 0) real_quit_flag = 1; else quit_flag = 0; } if (help_flag != 0) lc_usleep (1); if (make_dir_ok_flag) make_savedir (); /* sorry a bit crude :( */ return real_quit_flag; }
void do_rocket_pad(int x, int y) { /* // You need ROCKET_PAD_JOBS, ROCKET_PAD_GOODS and ROCKET_PAD_STEEL // to add 1 to % of ready to fire. // int_1 is the stored jobs // int_2 is the stored goods // int_3 is the stored steel // int_4 is the count which gets to ROCKET_PAD_LAUNCH to fire. // int_5 unused // MP_ANIM is the time of the next animation frame, when waiting for launch. since 1.91 */ if (MP_TYPE(x, y) == CST_ROCKET_FLOWN) return; /* The rocket has been launched. */ /* get some jobs */ if (MP_INFO(x, y).int_1 < ROCKET_PAD_JOBS_STORE) { if (get_jobs(x, y, ROCKET_PAD_JOBS + 10) != 0) MP_INFO(x, y).int_1 += ROCKET_PAD_JOBS; } /* get goods */ if (MP_INFO(x, y).int_2 < ROCKET_PAD_GOODS_STORE) { if (get_goods(x, y, ROCKET_PAD_GOODS + 10) != 0) MP_INFO(x, y).int_2 += ROCKET_PAD_GOODS; else if (get_goods(x, y, ROCKET_PAD_GOODS / 10) != 0) MP_INFO(x, y).int_2 += ROCKET_PAD_GOODS / 5; else if (get_goods(x, y, ROCKET_PAD_GOODS / 50) != 0) MP_INFO(x, y).int_2 += ROCKET_PAD_GOODS / 20; } /* get steel */ if (MP_INFO(x, y).int_3 < ROCKET_PAD_STEEL_STORE) { if (get_steel(x, y, ROCKET_PAD_STEEL + 10) != 0) MP_INFO(x, y).int_3 += ROCKET_PAD_STEEL + 10; else if (get_steel(x, y, ROCKET_PAD_STEEL / 5) != 0) MP_INFO(x, y).int_3 += ROCKET_PAD_STEEL / 5; else if (get_steel(x, y, ROCKET_PAD_STEEL / 20) != 0) MP_INFO(x, y).int_3 += ROCKET_PAD_STEEL / 20; } #ifdef DEBUG_ROCKETS MP_INFO(x, y).int_4++; #else /* now build the rocket. Unlike uni's need a full store to make +1% */ if (MP_TYPE(x, y) < CST_ROCKET_5 && MP_INFO(x, y).int_1 >= ROCKET_PAD_JOBS_STORE && MP_INFO(x, y).int_2 >= ROCKET_PAD_GOODS_STORE && MP_INFO(x, y).int_3 >= ROCKET_PAD_STEEL_STORE) { MP_INFO(x, y).int_1 -= ROCKET_PAD_JOBS_STORE; MP_INFO(x, y).int_2 -= ROCKET_PAD_GOODS_STORE; MP_INFO(x, y).int_3 -= ROCKET_PAD_STEEL_STORE; MP_INFO(x, y).int_4++; goods_used += ROCKET_PAD_GOODS_STORE; } #endif rocket_pad_cost += ROCKET_PAD_RUNNING_COST; /* animate and return if already said no to launch */ if (MP_TYPE(x, y) >= CST_ROCKET_5 && MP_INFO(x, y).int_4 >= (100 * ROCKET_PAD_LAUNCH) / 100) { if (real_time >= MP_ANIM(x, y)) { MP_ANIM(x, y) = real_time + ROCKET_ANIMATION_SPEED; switch (MP_TYPE(x, y)) { case (CST_ROCKET_5): MP_TYPE(x, y) = CST_ROCKET_6; break; case (CST_ROCKET_6): MP_TYPE(x, y) = CST_ROCKET_7; break; case (CST_ROCKET_7): MP_TYPE(x, y) = CST_ROCKET_5; break; } } return; } /* now choose a graphic */ if (MP_INFO(x, y).int_4 < (25 * ROCKET_PAD_LAUNCH) / 100) MP_TYPE(x, y) = CST_ROCKET_1; else if (MP_INFO(x, y).int_4 < (60 * ROCKET_PAD_LAUNCH) / 100) MP_TYPE(x, y) = CST_ROCKET_2; else if (MP_INFO(x, y).int_4 < (90 * ROCKET_PAD_LAUNCH) / 100) MP_TYPE(x, y) = CST_ROCKET_3; else if (MP_INFO(x, y).int_4 < (100 * ROCKET_PAD_LAUNCH) / 100) MP_TYPE(x, y) = CST_ROCKET_4; else if (MP_INFO(x, y).int_4 >= (100 * ROCKET_PAD_LAUNCH) / 100) { MP_TYPE(x, y) = CST_ROCKET_5; update_main_screen(0); if (ask_launch_rocket_now(x, y)) { /* ? FIXME ? AL1: in NG 1.1 it seems we are never here ? * ? ask_launch_rocket_now manages everything and call launch_rocket ? */ launch_rocket(x, y); } } }