const itype *turret_data::ammo_data() const { if( !veh || !part ) { return 0; } if( part->info().has_flag( "USE_TANKS" ) ) { return ammo_current() != "null" ? item::find_type( ammo_current() ) : nullptr; } return part->base.ammo_data(); }
int turret_data::fire( player &p, const tripoint &target ) { if( !veh || !part ) { return 0; } int shots = 0; p.add_effect( effect_on_roof, 1 ); p.recoil = abs( veh->velocity ) / 100 / 4; auto mode = base()->gun_current_mode(); auto ammo = ammo_current(); long qty = mode->ammo_required(); if( part->info().has_flag( "USE_TANKS" ) ) { mode->ammo_set( ammo, std::min( qty * mode.qty, long( veh->fuel_left( ammo ) ) ) ); } shots = p.fire_gun( target, mode.qty, *mode ); if( part->info().has_flag( "USE_TANKS" ) ) { veh->drain( ammo, qty * shots ); mode->ammo_unset(); } veh->drain( fuel_type_battery, mode->get_gun_ups_drain() * shots ); p.remove_effect( effect_on_roof ); return shots; }
long turret_data::ammo_remaining() const { if( !veh || !part ) { return 0; } if( part->info().has_flag( "USE_TANKS" ) ) { return veh->fuel_left( ammo_current() ); } return part->base.ammo_remaining(); }
long vehicle_part::ammo_capacity() const { if( is_tank() ) { return item::find_type( ammo_current() )->charges_per_volume( base.get_container_capacity() ); } if( is_fuel_store( false ) || is_turret() ) { return base.ammo_capacity(); } return 0; }
bool vehicle_part::can_reload( const item &obj ) const { // first check part is not destroyed and can contain ammo if( !is_fuel_store() ) { return false; } if( !obj.is_null() ) { const itype_id obj_type = obj.typeId(); if( is_reactor() ) { return base.is_reloadable_with( obj_type ); } // forbid filling tanks with solids or non-material things if( is_tank() && ( obj.made_of( SOLID ) || obj.made_of( PNULL ) ) ) { return false; } // forbid putting liquids, gasses, and plasma in things that aren't tanks else if( !obj.made_of( SOLID ) && !is_tank() ) { return false; } // prevent mixing of different ammo if( ammo_current() != "null" && ammo_current() != obj_type ) { return false; } // For storage with set type, prevent filling with different types if( info().fuel_type != fuel_type_none && info().fuel_type != obj_type ) { return false; } // don't fill magazines with inappropriate fuel if( !is_tank() && !base.is_reloadable_with( obj_type ) ) { return false; } } return ammo_remaining() < ammo_capacity(); }
turret_data::status turret_data::query() const { if( !veh || !part ) { return status::invalid; } if( part->info().has_flag( "USE_TANKS" ) ) { if( veh->fuel_left( ammo_current() ) < part->base.ammo_required() ) { return status::no_ammo; } } else { if( !part->base.ammo_sufficient() ) { return status::no_ammo; } } auto ups = part->base.get_gun_ups_drain() * part->base.gun_current_mode().qty; if( ups > veh->fuel_left( fuel_type_battery ) ) { return status::no_power; } return status::ready; }