void get_formation_position (formation_types form, int index, vec3d *vec) { formation_type *formation_data; formation_data = get_formation (form); vec->x = formation_data->sites [index].x; vec->y = formation_data->sites [index].y; vec->z = formation_data->sites [index].z; }
const char *get_formation_name (formation_types formation) { formation_type *this_formation; ASSERT (formation_database); this_formation = get_formation (formation); if (this_formation) { return this_formation->name; } return NULL; }
short int get_number_in_formation (formation_types formation) { formation_type *this_formation; ASSERT (formation_database); this_formation = get_formation (formation); if (this_formation) { return this_formation->number_in_formation; } return 0; }
float get_formation_member_radius (formation_types form, int member_count) { formation_type *formation_data; int loop, biggest_radius_index; float radius, sqr_radius, biggest_sqr_radius; formation_data = get_formation (form); biggest_sqr_radius = 0.0; biggest_radius_index = 0; for (loop = 0; loop < member_count; loop ++) { sqr_radius = (formation_data->sites [loop].x * formation_data->sites [loop].x) + (formation_data->sites [loop].z * formation_data->sites [loop].z); if (sqr_radius > biggest_sqr_radius) { biggest_sqr_radius = sqr_radius; biggest_radius_index = loop; } } radius = get_3d_vector_magnitude (&formation_data->sites [biggest_radius_index]); return radius; }
void initialise_formation_component_database (void) { formation_type *formation_data; session_list_data_type *current_session; formation_vehicle_components *new_formation_component; FILE *file_ptr; file_tags tag; int loop, type, count, result; char temp_filename [1024]; ASSERT (!formation_component_database); current_session = get_current_game_session (); file_ptr = NULL; // check if this campaign has its own formation component database if (current_game_session->data_path && current_game_session->campaign_directory) { sprintf (temp_filename, "%s\\%s\\%s", current_game_session->data_path, current_game_session->campaign_directory, FORMATION_COMPONENT_FILENAME); if (file_exist(temp_filename)) file_ptr = safe_fopen (temp_filename, "r"); if (file_ptr) { debug_log("formcomp file: %s", temp_filename); } } // check if this map has its own formation component database if (!file_ptr && current_game_session->data_path) { sprintf (temp_filename, "%s\\%s", current_game_session->data_path, FORMATION_COMPONENT_FILENAME); if (file_exist(temp_filename)) file_ptr = safe_fopen (temp_filename, "r"); if (file_ptr) { debug_log("formcomp file: %s", temp_filename); } } // use default if there is no specific one if (!file_ptr) { sprintf (temp_filename, "%s", FORMATION_COMPONENT_DEFAULT_FULLPATH); file_ptr = safe_fopen (temp_filename, "r"); } while (TRUE) { tag = (file_tags) get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG); switch (tag) { case FILE_TAG_START: { continue; } case FILE_TAG_FORMATION_COMPONENT: { new_formation_component = (formation_vehicle_components *) malloc_heap_mem (sizeof (formation_vehicle_components)); memset (new_formation_component, 0, sizeof (formation_vehicle_components)); result = get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG); ASSERT (result == FILE_TAG_TYPE); type = get_next_file_enum (file_ptr, formation_component_names, NUM_FORMATION_COMPONENT_TYPES); new_formation_component->formation_component = (formation_component_types) type; result = get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG); ASSERT (result == FILE_TAG_TYPE); type = get_next_file_enum (file_ptr, formation_names, NUM_FORMATION_TYPES); new_formation_component->formation = (formation_types) type; result = get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG); ASSERT (result == FILE_TAG_COUNT); count = get_next_file_int (file_ptr); formation_data = get_formation (new_formation_component->formation); new_formation_component->group_type = get_next_file_enum (file_ptr, entity_sub_type_group_names, NUM_ENTITY_SUB_TYPE_GROUPS); ASSERT (count <= formation_data->number_in_formation); new_formation_component->count = count; if (count > 0) { new_formation_component->components = (entity_sub_types *) malloc_heap_mem (sizeof (entity_sub_types) * (count * 2)); loop = 0; #if DEBUG_MODULE debug_log ("EN_FORMS: loading formation components %s, formation %s", formation_component_names [new_formation_component->formation_component], formation_names [new_formation_component->formation]); #endif while (loop < count * 2) { switch (group_database [new_formation_component->group_type].default_landing_type) { case ENTITY_SUB_TYPE_LANDING_GROUND: case ENTITY_SUB_TYPE_LANDING_PEOPLE: case ENTITY_SUB_TYPE_LANDING_SEA: { type = get_next_file_enum (file_ptr, entity_sub_type_vehicle_names, NUM_ENTITY_SUB_TYPE_VEHICLES); #if DEBUG_MODULE debug_log (" adding component %d %s", loop, entity_sub_type_vehicle_names [type]); #endif break; } case ENTITY_SUB_TYPE_LANDING_HELICOPTER: case ENTITY_SUB_TYPE_LANDING_FIXED_WING: case ENTITY_SUB_TYPE_LANDING_FIXED_WING_TRANSPORT: { type = get_next_file_enum (file_ptr, entity_sub_type_aircraft_names, NUM_ENTITY_SUB_TYPE_AIRCRAFT); #if DEBUG_MODULE debug_log (" adding component %d %s", loop, entity_sub_type_aircraft_names [type]); #endif break; } } new_formation_component->components [loop] = type; loop ++; } } result = get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG); ASSERT (result == FILE_TAG_END); // // link into database // new_formation_component->next = formation_component_database; formation_component_database = new_formation_component; break; } case FILE_TAG_END: { fclose (file_ptr); return; } } } }
static void ship_movement_get_waypoint_position (entity *en, vec3d *wp_pos) { entity *wp, *group, *guide; float distance; vec3d *pos; ASSERT (en); ASSERT (wp_pos); group = get_local_entity_parent (en, LIST_TYPE_MEMBER); ASSERT (group); guide = get_local_entity_parent (en, LIST_TYPE_FOLLOWER); ASSERT (guide); wp = get_local_entity_parent (guide, LIST_TYPE_CURRENT_WAYPOINT); ASSERT (wp); // // Should vehicle follow leader, or follow guide in set waypoint formation? // if (get_local_entity_int_value (wp, INT_TYPE_MOBILE_FOLLOW_WAYPOINT_OFFSET)) { vec3d offset; get_local_entity_vec3d (guide, VEC3D_TYPE_GUIDE_POSITION, wp_pos); get_local_entity_formation_position_offset (en, wp, &offset); wp_pos->x += offset.x; wp_pos->y += offset.y; wp_pos->z += offset.z; } else { // // Task leader follows guide,.... other members follow task leader // if (get_local_entity_int_value (en, INT_TYPE_TASK_LEADER)) { get_local_entity_vec3d (guide, VEC3D_TYPE_GUIDE_POSITION, wp_pos); } else { // // set wp pos to offset from task leader // entity *task_leader; vec3d *xv, *leader_pos; formation_type *formation; int type, formation_count, formation_index, leader_formation_index; // // find task leader // task_leader = get_local_entity_ptr_value (guide, PTR_TYPE_TASK_LEADER); ASSERT (task_leader); // // get formation // type = get_local_entity_int_value (group, INT_TYPE_GROUP_FORMATION); formation = get_formation (type); formation_count = formation->number_in_formation; formation_index = get_local_entity_int_value (en, INT_TYPE_GROUP_MEMBER_NUMBER); leader_formation_index = get_local_entity_int_value (task_leader, INT_TYPE_GROUP_MEMBER_NUMBER); ASSERT (formation_index < formation_count); ASSERT (leader_formation_index < formation_count); // // calculate position // leader_pos = get_local_entity_vec3d_ptr (task_leader, VEC3D_TYPE_POSITION); xv = get_local_entity_vec3d_ptr (task_leader, VEC3D_TYPE_XV); // // take leader position and SUBTRACT leaders formation position (coz leader is not necessarily formation pos 0) // wp_pos->x = leader_pos->x - ((xv->x * formation->sites [leader_formation_index].x) + (xv->z * formation->sites [leader_formation_index].z)); wp_pos->y = 0; wp_pos->z = leader_pos->z - ((xv->z * formation->sites [leader_formation_index].x) + (xv->x * formation->sites [leader_formation_index].z)); // // then ADD members formation position // wp_pos->x += ((xv->x * formation->sites [formation_index].x) + (xv->z * formation->sites [formation_index].z)); wp_pos->z += ((xv->z * formation->sites [formation_index].x) + (xv->x * formation->sites [formation_index].z)); } } // // calculate distance of entity to desired position // pos = get_local_entity_vec3d_ptr (en, VEC3D_TYPE_POSITION); distance = get_2d_range (pos, wp_pos); #if DEBUG_WAYPOINT_VECTOR if (distance > 0.0) { create_debug_3d_line (pos, wp_pos, sys_col_black, 0.0); } #endif set_local_entity_float_value (en, FLOAT_TYPE_DISTANCE, distance); }