Exemplo n.º 1
0
Arquivo: board.c Projeto: pegue/naev
/**
 * @brief Attempt to steal the boarded ship's cargo.
 *
 *    @param wdw Window triggering the function.
 *    @param str Unused.
 */
static void board_stealCargo( unsigned int wdw, char* str )
{
   (void)str;
   int q;
   Pilot* p;

   p = pilot_get(player->target);

   if (p->ncommodities==0) { /* no cargo */
      player_message("The ship has no cargo.");
      return;
   }
   else if (pilot_cargoFree(player) <= 0) {
      player_message("You have no room for cargo.");
      return;
   }

   if (board_fail(wdw)) return;

   /** steal as much as possible until full - @todo let player choose */
   q = 1;
   while ((p->ncommodities > 0) && (q!=0)) {
      q = pilot_addCargo( player, p->commodities[0].commodity,
            p->commodities[0].quantity );
      pilot_rmCargo( p, p->commodities[0].commodity, q );
   }

   board_update( wdw );
   player_message("You manage to steal the ship's cargo.");
}
Exemplo n.º 2
0
Arquivo: board.c Projeto: pegue/naev
/**
 * @brief Attempt to steal the boarded ship's fuel.
 *
 *    @param wdw Window triggering the function.
 *    @param str Unused.
 */
static void board_stealFuel( unsigned int wdw, char* str )
{
   (void)str;
   Pilot* p;

   p = pilot_get(player->target);

   if (p->fuel <= 0.) { /* no fuel. */
      player_message("The ship has no fuel.");
      return;
   }
   else if (player->fuel == player->fuel_max) {
      player_message("Your ship is at maximum fuel capacity.");
      return;
   }

   if (board_fail(wdw)) return;

   /* Steal fuel. */
   player->fuel += p->fuel;
   p->fuel = 0.;

   /* Make sure doesn't overflow. */
   if (player->fuel > player->fuel_max) {
      p->fuel = player->fuel_max - player->fuel;
      player->fuel = player->fuel_max;
   }

   board_update( wdw );
   player_message("You manage to steal the ship's fuel.");
}
Exemplo n.º 3
0
Arquivo: board.c Projeto: pegue/naev
/**
 * @brief Attempt to steal the boarded ship's credits.
 *
 *    @param wdw Window triggering the function.
 *    @param str Unused.
 */
static void board_stealCreds( unsigned int wdw, char* str )
{
   (void)str;
   Pilot* p;

   p = pilot_get(player->target);

   if (p->credits==0) { /* you can't steal from the poor */
      player_message("The ship has no credits.");
      return;
   }

   if (board_fail(wdw)) return;

   player->credits += p->credits;
   p->credits = 0;
   board_update( wdw ); /* update the lack of credits */
   player_message("You manage to steal the ship's credits.");
}
Exemplo n.º 4
0
// Initialise board
void board_init (void) {

	#ifndef SIMULATE
    io_init(); // Init GPIOs
    uart_init(BAUD_RATE);
    stderr = &uartio;
    printf(str_boot_uart,BAUD_RATE);
    printf(str_boot_start);
	#else
	printf("Skipping UART initialization...\n");
	#endif
	#ifndef SIMULATE
    digital_init();
	#endif
    encoder_init();
	#ifndef SIMULATE
    spi_init();
    motor_init();
    servo_init();
#ifdef LCD_DEBUG
    lcd_init(); //consider wrapping this in an #ifdef LCD_DEBUG tag?
    stdout = &lcdout;
#else
    stdout = &uartio;
    stdin = &uartio;
#endif
    adc_init();
    isr_init();
    memory_init();
	#endif

    // load config, or fail if invalid
    if (!board_load_config())
        board_fail("Bad Config");
    printf(str_boot_conf);
    printf(str_boot_board,
            board_config.version>>8,
            board_config.version&0xFF);
    printf(str_boot_id, board_config.id);

    // print boot text to screen
    printf(str_boot_message, board_config.version>>8, board_config.version&0xFF);

    // check battery, fail if <7.5V
    printf(str_boot_batt,read_battery());
#ifdef CHECK_BATTERY
    if (!(read_battery()>=7200)) {
        // NOTE: in the current 2-battery version of the HappyBoard, the 
        // battery voltage is the motor battery (P+).  Holding GO overrides
        // the check so you can run the HappyBoard without a motor battery.
        if (go_press())
            printf("WARNING: LOW BATTERY\n");
        else 
            board_fail("Low battery");
    } else {
        printf("Battery OK\n");
    }
#endif

	#ifndef SIMULATE
    // initialise FPGA
    if (!fpga_init(FPGA_CONFIG_ADDRESS, board_config.fpga_len))
        board_fail("FPGA failure");
    printf(str_boot_fpga, fpga_get_version_major(), fpga_get_version_minor());
	#else
	printf("Skipping FPGA initialization...\n");
	#endif

    // all ok
#ifndef SIMULATE
#ifdef LCD_DEBUG
    lcd_set_pos(31);
    lcd_print_char('\1', NULL);
#else
	printf("Board init complete.\n");
#endif
#else
    printf("Board init complete.\n");
#endif

#ifndef SIMULATE
    LED_COMM(0);
#endif

}