bool Unit::interact(Unit *target) { // Verify that the Unit hasn't interacted already. if(interacted) { return false; } // Verify second is within range of first. if(!is_within_range(target)) { return false; } // If this Unit is a healer, calculate heals. First verify target is friendly. if(type == HEALER) { if(player_id != target->get_player_id()) { return false; } target->apply_heal(); interacted = true; moved = true; return true; } // If we're not healing, verify the unit we're attacking isn't friendly. if(player_id == target->get_player_id()) { return false; } // Note that this Unit can no longer move or interact. interacted = true; moved = true; // Let's see if it hits. There's a 25% chance of missing. if(rand() % 4 == 0) { // Even though we aren't applying damage, this was still a valid outcome. return true; } // Time to attack the target! target->apply_damage(this, false); // There's also a chance that the defender can counterattack. if(target->is_within_range(this) && target->get_type() != HEALER) { apply_damage(this, true); } // If we've gotten here, everything was successful! return true; }
static int _rfic_fpga_set_frequency(struct bladerf *dev, bladerf_channel ch, bladerf_frequency frequency) { struct bladerf_range const *range = NULL; CHECK_STATUS(dev->board->get_frequency_range(dev, ch, &range)); if (!is_within_range(range, frequency)) { return BLADERF_ERR_RANGE; } return _rfic_cmd_write(dev, ch, BLADERF_RFIC_COMMAND_FREQUENCY, frequency); }
static int _rfic_fpga_set_bandwidth(struct bladerf *dev, bladerf_channel ch, bladerf_bandwidth bandwidth, bladerf_bandwidth *actual) { struct bladerf2_board_data *board_data = dev->board_data; struct controller_fns const *rfic = board_data->rfic; struct bladerf_range const *range = NULL; CHECK_STATUS(dev->board->get_bandwidth_range(dev, ch, &range)); if (!is_within_range(range, bandwidth)) { return BLADERF_ERR_RANGE; } CHECK_STATUS( _rfic_cmd_write(dev, ch, BLADERF_RFIC_COMMAND_BANDWIDTH, bandwidth)); if (actual != NULL) { return rfic->get_bandwidth(dev, ch, actual); } return 0; }