/** * @brief Shows the player what outfits he has. * * @param str Unused. */ static void info_openShip( unsigned int wid ) { int w, h; /* Get the dimensions. */ window_dimWindow( wid, &w, &h ); /* Buttons */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "closeOutfits", _("Close"), info_close ); /* Text. */ window_addText( wid, 40, -60, 100, h-60, 0, "txtSDesc", &gl_smallFont, &cDConsole, _("Name:\n" "Model:\n" "Class:\n" "Crew:\n" "\n" "Total CPU:\n" "Mass:\n" "Jump Time:\n" "Thrust:\n" "Speed:\n" "Turn:\n" "\n" "Absorption:\n" "Shield:\n" "Armour:\n" "Energy:\n" "Cargo Space:\n" "Fuel:\n" "\n" "Stats:\n") ); window_addText( wid, 140, -60, w-300., h-60, 0, "txtDDesc", &gl_smallFont, &cBlack, NULL ); /* Custom widget. */ equipment_slotWidget( wid, -20, -40, 180, h-60, &info_eq ); info_eq.selected = player.p; info_eq.canmodify = 0; /* Update ship. */ ship_update( wid ); }
int main(void) { asteroids.lives = START_LIVES; asteroids.display = NULL; asteroids.timer = NULL; asteroids.event_queue = NULL; SHIP *ship; bool redraw = true; bool quit = false; bool key[7] = { false }; seed_rand(); atexit(shutdown); if(!init()) exit(EXIT_FAILURE); if((asteroids.high_score = get_config_value("high_score")) == NULL) asteroids.high_score = "0"; asteroids.level = level_create(0, 0); if(!(ship = ship_create())) exit(EXIT_FAILURE); al_flip_display(); al_start_timer(asteroids.timer); while(!quit) { ALLEGRO_EVENT ev; al_wait_for_event(asteroids.event_queue, &ev); if(ev.type == ALLEGRO_EVENT_TIMER) { /* start game */ if(asteroids.level->number == 0 && key[KEY_S]) { start(); continue; } /* are we out of asteroids to destroy? */ if(list_length(asteroids.level->asteroids) == 0) asteroids.level = level_next(asteroids.level); /* update objects */ ship = ship_update(ship, key, asteroids.timer); explosions_update(); asteroids.level = level_update(asteroids.level, ship, key, asteroids.timer); /* ship->asteroid collisions. */ check_ship_asteroid_collisions(ship, asteroids.level->asteroids); /* ship[missile] -> asteroid collisions. */ check_ship_missile_asteroid_collisions(asteroids.level, ship); /* ship[missile] -> saucer collisions. */ check_ship_missile_saucer_collisions(asteroids.level, ship); /* saucer[missile] -> ship collisions. */ check_saucer_missile_ship_collisions(asteroids.level, ship); /* saucer[missile] -> asteroid collisions. */ check_saucer_missile_asteroids_collisions(asteroids.level); /* saucer->asteroid collisions. */ check_saucer_asteroid_collisions(asteroids.level); redraw = true; } else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { keydown(ev, key); quit = key[KEY_ESCAPE]; } else if(ev.type == ALLEGRO_EVENT_KEY_UP) { keyup(ev, key); ship->fire_debounce = key[KEY_SPACE]; ship->hyper_debounce = key[KEY_LCONTROL]; } if(redraw && al_is_event_queue_empty(asteroids.event_queue)) { redraw = false; al_clear_to_color(al_map_rgb(BLACK)); level_draw(asteroids.level); draw_lives(); draw_high_score(); animation_draw_list(asteroids.explosions); if(asteroids.level->number == 0) { draw_home(); al_flip_display(); continue; } if(asteroids.lives > 0) { ship_draw(ship, key[KEY_UP]); missile_draw_list(ship->missiles); } else { if(ship->explosion) ship_draw(ship, false); draw_gameover(); } al_flip_display(); } }; /* FIXME: cleanup */ if(asteroids.timer != NULL) al_destroy_timer(asteroids.timer); if(asteroids.event_queue != NULL) al_destroy_event_queue(asteroids.event_queue); if(asteroids.display != NULL) al_destroy_display(asteroids.display); LIST *head = list_first(asteroids.level->asteroids); while(head != NULL) { ASTEROID *rock = (ASTEROID *) head->data; asteroid_free(rock); head = head->next; } ship_free(ship); al_destroy_bitmap(asteroids.lives_sprite); ship_shutdown(); missile_shutdown(); asteroid_shutdown(); explosion_shutdown(); al_uninstall_keyboard(); exit(EXIT_SUCCESS); }
/** * @brief Makes the player jettison the currently selected cargo. * @param str Unused. */ static void cargo_jettison( unsigned int wid, char* str ) { (void)str; int i, j, f, pos, ret; Mission *misn; if (player.p->ncommodities==0) return; /* No cargo, redundant check */ pos = toolkit_getListPos( wid, "lstCargo" ); /* Special case mission cargo. */ if (player.p->commodities[pos].id != 0) { if (!dialogue_YesNo( "Abort Mission", "Are you sure you want to abort this mission?" )) return; /* Get the mission. */ f = 0; for (i=0; i<MISSION_MAX; i++) { for (j=0; j<player_missions[i].ncargo; j++) { if (player_missions[i].cargo[j] == player.p->commodities[pos].id) { f = 1; break; } } if (f==1) break; } if (!f) { WARN("Cargo '%d' does not belong to any active mission.", player.p->commodities[pos].id); return; } misn = &player_missions[i]; /* We run the "abort" function if it's found. */ ret = misn_tryRun( misn, "abort" ); /* Now clean up mission. */ if (ret != 2) { mission_cleanup( misn ); memmove( misn, &player_missions[i+1], sizeof(Mission) * (MISSION_MAX-i-1) ); memset( &player_missions[MISSION_MAX-1], 0, sizeof(Mission) ); } /* Reset markers. */ mission_sysMark(); /* Reset claims. */ claim_activateAll(); /* Regenerate list. */ mission_menu_genList( info_windows[ INFO_WIN_MISN ] ,0); } else { /* Remove the cargo */ commodity_Jettison( player.p->id, player.p->commodities[pos].commodity, player.p->commodities[pos].quantity ); pilot_cargoRm( player.p, player.p->commodities[pos].commodity, player.p->commodities[pos].quantity ); } /* We reopen the menu to recreate the list now. */ ship_update( info_windows[ INFO_WIN_SHIP ] ); cargo_genList( wid ); }