aircraft_fire_result aircraft_fire_weapon (entity *en, unsigned int check_flags) { entity *target; aircraft *raw; vec3d *target_pos, en_pos; ASSERT (en); raw = get_local_entity_data (en); // // Fire suppressed // if (check_flags & AIRCRAFT_FIRE_SUPPRESSED) { if (get_local_entity_int_value (get_session_entity (), INT_TYPE_SUPPRESS_AI_FIRE)) { return AIRCRAFT_FIRE_SUPPRESSED; } } // // check weapon // if (check_flags & AIRCRAFT_FIRE_NO_WEAPON) { if (get_local_entity_int_value (en, INT_TYPE_SELECTED_WEAPON) == ENTITY_SUB_TYPE_WEAPON_NO_WEAPON) { debug_log ("AC_WPN: Fire Weapon Error - NO WEAPON"); return AIRCRAFT_FIRE_NO_WEAPON; } } // // weapon system_ready // if (check_flags & AIRCRAFT_FIRE_WEAPON_SYSTEM_NOT_READY) { if (!get_local_entity_int_value (en, INT_TYPE_SELECTED_WEAPON_SYSTEM_READY)) { debug_log ("AC_WPN: Fire Weapon Error - WEAPON SYSTEM NOT READY"); return AIRCRAFT_FIRE_WEAPON_SYSTEM_NOT_READY; } } // // find target // if (check_flags & AIRCRAFT_FIRE_NO_TARGET) { target = get_local_entity_parent (en, LIST_TYPE_TARGET); if (!target) { debug_log ("AC_WPN: Fire Weapon Error - NO TARGET"); return AIRCRAFT_FIRE_NO_TARGET; } } // // line of sight checks // if (check_flags & AIRCRAFT_FIRE_NO_LOS) { int criteria; if (get_local_entity_int_value (target, INT_TYPE_PLAYER) != ENTITY_PLAYER_AI) { criteria = MOBILE_LOS_CHECK_ALL; } else { criteria = MOBILE_LOS_CHECK_COURSE_TERRAIN; } get_local_entity_vec3d (en, VEC3D_TYPE_POSITION, &en_pos); target_pos = get_local_entity_vec3d_ptr (target, VEC3D_TYPE_POSITION); en_pos.y -= (get_local_entity_float_value (en, FLOAT_TYPE_CENTRE_OF_GRAVITY_TO_GROUND_DISTANCE) + 2.0); if (!check_position_line_of_sight (en, target, &en_pos, target_pos, criteria)) { debug_log ("AC_WPN: Fire Weapon Error - NO LOS (Aircraft %s (%d), Target %s (%d))", get_local_entity_string (en, STRING_TYPE_FULL_NAME), get_local_entity_index (en), get_local_entity_string (target, STRING_TYPE_FULL_NAME), get_local_entity_index (target)); return AIRCRAFT_FIRE_NO_LOS; } } // // Play Speech // play_aircraft_weapon_launched_speech (en, raw->selected_weapon); // // Fire weapon // launch_client_server_weapon (en, raw->selected_weapon); return AIRCRAFT_FIRE_OK; }
aircraft_fire_result aircraft_fire_weapon (entity *en, unsigned int check_flags) { entity *target; aircraft *raw; vec3d *target_pos, en_pos; int loal_mode = FALSE; ASSERT (en); raw = (aircraft *) get_local_entity_data (en); // // Fire suppressed // if (check_flags & AIRCRAFT_FIRE_SUPPRESSED) { if (get_local_entity_int_value (get_session_entity (), INT_TYPE_SUPPRESS_AI_FIRE)) { return AIRCRAFT_FIRE_SUPPRESSED; } } // // check weapon // if (check_flags & AIRCRAFT_FIRE_NO_WEAPON) { if (get_local_entity_int_value (en, INT_TYPE_SELECTED_WEAPON) == ENTITY_SUB_TYPE_WEAPON_NO_WEAPON) { debug_log ("AC_WPN: Fire Weapon Error - NO WEAPON"); return AIRCRAFT_FIRE_NO_WEAPON; } } // // weapon system_ready // if (check_flags & AIRCRAFT_FIRE_WEAPON_SYSTEM_NOT_READY) { if (!get_local_entity_int_value (en, INT_TYPE_SELECTED_WEAPON_SYSTEM_READY)) { debug_log ("AC_WPN: Fire Weapon Error - WEAPON SYSTEM NOT READY"); return AIRCRAFT_FIRE_WEAPON_SYSTEM_NOT_READY; } } // debug_log("%s: %d", get_sub_type_name(en), get_local_entity_int_value (en, INT_TYPE_SELECTED_WEAPON)); // // find target // if (check_flags & AIRCRAFT_FIRE_NO_TARGET) { target = get_local_entity_parent (en, LIST_TYPE_TARGET); if (!target) { debug_log ("AC_WPN: Fire Weapon Error - NO TARGET"); return AIRCRAFT_FIRE_NO_TARGET; } } // // line of sight checks // if (check_flags & AIRCRAFT_FIRE_NO_LOS) { int criteria; if (get_local_entity_int_value (target, INT_TYPE_PLAYER) != ENTITY_PLAYER_AI) { criteria = MOBILE_LOS_CHECK_ALL; } else { criteria = MOBILE_LOS_CHECK_COURSE_TERRAIN; } get_local_entity_vec3d (en, VEC3D_TYPE_POSITION, &en_pos); target_pos = get_local_entity_vec3d_ptr (target, VEC3D_TYPE_POSITION); en_pos.y -= (get_local_entity_float_value (en, FLOAT_TYPE_CENTRE_OF_GRAVITY_TO_GROUND_DISTANCE) + 2.0); if (!check_position_line_of_sight (en, target, &en_pos, target_pos, (mobile_los_check_criteria) criteria)) { if (get_local_entity_int_value (en, INT_TYPE_SELECTED_WEAPON) == ENTITY_SUB_TYPE_WEAPON_AGM114L_LONGBOW_HELLFIRE && get_2d_range(&en_pos, target_pos) > weapon_database[ENTITY_SUB_TYPE_WEAPON_AGM114L_LONGBOW_HELLFIRE].min_range_loal) { debug_log("AC_WPN: Switching to LOAL mode to fire at target without LOS ((Aircraft %s (%d), Target %s (%d))", get_local_entity_string (en, STRING_TYPE_FULL_NAME), get_local_entity_index (en), get_local_entity_string (target, STRING_TYPE_FULL_NAME), get_local_entity_index (target)); loal_mode = TRUE; } else { debug_log ("AC_WPN: Fire Weapon Error - NO LOS (Aircraft %s (%d), Target %s (%d))", get_local_entity_string (en, STRING_TYPE_FULL_NAME), get_local_entity_index (en), get_local_entity_string (target, STRING_TYPE_FULL_NAME), get_local_entity_index (target)); return AIRCRAFT_FIRE_NO_LOS; } } } // // Play Speech // play_aircraft_weapon_launched_speech (en, raw->selected_weapon); // // Fire weapon // set_local_entity_int_value(en, INT_TYPE_LOCK_ON_AFTER_LAUNCH, loal_mode); launch_client_server_weapon (en, raw->selected_weapon); return AIRCRAFT_FIRE_OK; }