void kill_routed_vehicles_on_segment (entity *en) { float range, damage_radius; int sx, sz; vec3d *segment_position, *object_position; entity *sect, *object; bridge_segment_types bridge_segment_type; // // get damage radius ( plus a little overlap ) // bridge_segment_type = (bridge_segment_types) get_local_entity_int_value (en, INT_TYPE_BRIDGE_SEGMENT_TYPE); damage_radius = bridge_segment_length (bridge_segment_type); if (damage_radius == 0.0) { return; } damage_radius *= ROOT2; // // get sector which the segment is in ( don't bother with adjacent sectors for now ) // segment_position = get_local_entity_vec3d_ptr (en, VEC3D_TYPE_POSITION); get_x_sector (sx, segment_position->x); get_z_sector (sz, segment_position->z); sect = get_local_raw_sector_entity (sx, sz); // // search for routed vehicles // object = get_local_entity_first_child (sect, LIST_TYPE_SECTOR); while (object) { if (object->type == ENTITY_TYPE_ROUTED_VEHICLE) { if (get_local_entity_int_value (object, INT_TYPE_ALIVE)) { object_position = get_local_entity_vec3d_ptr (object, VEC3D_TYPE_POSITION); if (object_position) { range = get_approx_3d_range (segment_position, object_position); if (range < damage_radius) { kill_client_server_entity (object); } } } } object = get_local_entity_child_succ (object, LIST_TYPE_SECTOR); } }
int debug_engage_targets_in_area (entity *group, vec3d *target_point, float radius, unsigned int target_type) { // // Engages all targets in area, regardless of side // int sx, sz, min_sector_x, max_sector_x, min_sector_z, max_sector_z; entity *new_task, *objective, *target_sector; entity_sides side; sector *raw; float range, temp_x, temp_z; vec3d *pos; new_task = NULL; temp_x = target_point->x - radius; temp_z = target_point->z - radius; get_x_sector (min_sector_x, temp_x); get_z_sector (min_sector_z, temp_z); temp_x = target_point->x + radius; temp_z = target_point->z + radius; get_x_sector (max_sector_x, temp_x); get_z_sector (max_sector_z, temp_z); min_sector_x = bound (min_sector_x, MIN_MAP_X_SECTOR, MAX_MAP_X_SECTOR); max_sector_x = bound (max_sector_x, MIN_MAP_X_SECTOR, MAX_MAP_X_SECTOR); min_sector_z = bound (min_sector_z, MIN_MAP_Z_SECTOR, MAX_MAP_Z_SECTOR); max_sector_z = bound (max_sector_z, MIN_MAP_Z_SECTOR, MAX_MAP_Z_SECTOR); side = (entity_sides) get_local_entity_int_value (group, INT_TYPE_SIDE); for (sz = min_sector_z; sz <= max_sector_z; sz ++) { for (sx = min_sector_x; sx <= max_sector_x; sx ++) { target_sector = get_local_raw_sector_entity (sx, sz); raw = (sector *) get_local_entity_data (target_sector); // // search for viable targets // objective = raw->sector_root.first_child; while (objective) { // // criteria for target is that it is a valid target, and not in your group // if (get_local_entity_int_value (objective, INT_TYPE_TARGET_TYPE) == target_type) { if (get_local_entity_int_value (objective, INT_TYPE_ALIVE)) { if ((!get_local_entity_int_value (objective, INT_TYPE_IDENTIFY_MOBILE)) || (get_local_entity_parent (objective, LIST_TYPE_MEMBER) != group)) { pos = get_local_entity_vec3d_ptr (objective, VEC3D_TYPE_POSITION); range = get_approx_2d_range (target_point, pos); if (range <= radius) { new_task = create_engage_task (group, objective, group, FALSE); if (new_task) { assign_task_to_group (group, new_task, TASK_ASSIGN_NO_MEMBERS); } } } } } objective = get_local_entity_child_succ (objective, LIST_TYPE_SECTOR); } } } if (assign_engage_tasks_to_group (group, TASK_ASSIGN_ALL_MEMBERS) != TASK_ASSIGN_ALL_MEMBERS) { return TRUE; } else { return FALSE; } }
int engage_targets_in_sector (entity *group, int sx, int sz, unsigned int task_target_type, int expire) { unsigned int objective_target_type; entity *new_task, *objective, *target_sector; entity_sides side; sector *raw; new_task = NULL; target_sector = get_local_raw_sector_entity (sx, sz); raw = (sector *) get_local_entity_data (target_sector); // // search for viable targets // side = (entity_sides) get_local_entity_int_value (group, INT_TYPE_SIDE); objective = raw->sector_root.first_child; while (objective) { // // criteria for target is that it is a valid target, and not on your side // if ((get_local_entity_int_value (objective, INT_TYPE_SIDE) != side) && ((get_local_entity_int_value (objective, INT_TYPE_TARGET_TYPE) != TARGET_TYPE_INVALID))) { objective_target_type = get_local_entity_int_value (objective, INT_TYPE_TASK_TARGET_TYPE); if (task_target_type & objective_target_type) { if (get_local_entity_int_value (objective, INT_TYPE_ALIVE)) { new_task = create_engage_task (group, objective, group, expire); if (new_task) { assign_task_to_group (group, new_task, TASK_ASSIGN_NO_MEMBERS); } } } } objective = get_local_entity_child_succ (objective, LIST_TYPE_SECTOR); } if (assign_engage_tasks_to_group (group, TASK_ASSIGN_ALL_MEMBERS) != TASK_ASSIGN_ALL_MEMBERS) { return TRUE; } else { return FALSE; } }
static void set_local_vec3d (entity *en, vec3d_types type, vec3d *v) { keysite *raw; ASSERT (v); #if DEBUG_MODULE debug_log_entity_args (ENTITY_DEBUG_LOCAL, ENTITY_DEBUG_VEC3D, en, type, v); #endif raw = (keysite *) get_local_entity_data (en); switch (type) { //////////////////////////////////////// case VEC3D_TYPE_POSITION: //////////////////////////////////////// { int old_x_sec, old_z_sec, new_x_sec, new_z_sec; entity *parent; get_x_sector (old_x_sec, raw->position.x); get_z_sector (old_z_sec, raw->position.z); get_x_sector (new_x_sec, v->x); get_z_sector (new_z_sec, v->z); if ((old_x_sec != new_x_sec) || (old_z_sec != new_z_sec)) { delete_local_entity_from_parents_child_list (en, LIST_TYPE_SECTOR); raw->position = *v; parent = get_local_raw_sector_entity (new_x_sec, new_z_sec); insert_local_entity_into_parents_child_list (en, LIST_TYPE_SECTOR, parent, NULL); } else { raw->position = *v; } break; } //////////////////////////////////////// default: //////////////////////////////////////// { debug_fatal_invalid_vec3d_type (en, type); break; } } }
void unpack_local_sector_data (pack_modes mode) { entity *en; sector *raw; entity_sides side; int z_sec, x_sec, side_count; ASSERT (mode != PACK_MODE_UPDATE_ENTITY); if (mode == PACK_MODE_BROWSE_SESSION) { return; } // // RLE unencode the sector sides // debug_log ("RLE SECTOR"); en = NULL; side = unpack_int_value (NULL, INT_TYPE_SIDE); side_count = unpack_int_value (NULL, INT_TYPE_LENGTH); en = *entity_sector_map; while (side_count != 0) { while (side_count > 0) { raw = get_local_entity_data (en); raw->side = side; side_count --; en ++; } side = unpack_int_value (NULL, INT_TYPE_SIDE); side_count = unpack_int_value (NULL, INT_TYPE_LENGTH); } // // Unpack FOG OF WAR // for (z_sec = MIN_MAP_Z_SECTOR; z_sec <= MAX_MAP_Z_SECTOR; z_sec++) { for (x_sec = MIN_MAP_X_SECTOR; x_sec <= MAX_MAP_X_SECTOR; x_sec++) { en = get_local_raw_sector_entity(x_sec, z_sec); raw = get_local_entity_data (en); raw->fog_of_war [ENTITY_SIDE_BLUE_FORCE] = unpack_float_value (en, FLOAT_TYPE_FOG_OF_WAR); raw->fog_of_war [ENTITY_SIDE_RED_FORCE] = unpack_float_value (en, FLOAT_TYPE_FOG_OF_WAR); } } // // If loading game read in sector values (threat etc) // if (mode == PACK_MODE_SERVER_SESSION) { for (z_sec = MIN_MAP_Z_SECTOR; z_sec <= MAX_MAP_Z_SECTOR; z_sec++) { for (x_sec = MIN_MAP_X_SECTOR; x_sec <= MAX_MAP_X_SECTOR; x_sec++) { en = get_local_raw_sector_entity(x_sec, z_sec); raw = get_local_entity_data (en); if (unpack_int_value (en, INT_TYPE_VALID)) { unpack_list_root (en, LIST_TYPE_SECTOR_TASK, &raw->sector_task_root); } if (unpack_int_value (en, INT_TYPE_VALID)) { unpack_list_root (en, LIST_TYPE_SPECIAL_EFFECT, &raw->special_effect_root); } //debug_log ("SC_PACK: unpacking sector %d, %d", raw->x_sector, raw->z_sector); raw->keysite_count = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_COUNT); raw->tallest_structure_height = unpack_float_value (en, FLOAT_TYPE_PROTOTYPE_1); } } } }
void pack_local_sector_data (pack_modes mode) { entity *en; sector *raw; entity_sides current_side; int sector_pack_size, side_count, x_sec, z_sec, total_side_count; ASSERT (mode != PACK_MODE_UPDATE_ENTITY); if (mode == PACK_MODE_BROWSE_SESSION) { return; } // // RLE encode the sector sides // debug_log ("RLE SECTOR"); sector_pack_size = 0; en = get_local_raw_sector_entity (0, 0); raw = get_local_entity_data (en); pack_int_value (NULL, INT_TYPE_SIDE, raw->side); sector_pack_size += NUM_SIDE_BITS; current_side = raw->side; side_count = 0; total_side_count = 0; for (z_sec = MIN_MAP_Z_SECTOR; z_sec <= MAX_MAP_Z_SECTOR; z_sec++) { for (x_sec = MIN_MAP_X_SECTOR; x_sec <= MAX_MAP_X_SECTOR; x_sec++) { en = get_local_raw_sector_entity(x_sec, z_sec); raw = get_local_entity_data (en); if (current_side != raw->side) { current_side = raw->side; pack_int_value (NULL, INT_TYPE_LENGTH, side_count); #if DEBUG_MODULE debug_log ("SC_PACK : packed %d sectors for %s", side_count, entity_side_names [current_side]); #endif total_side_count += side_count; sector_pack_size += NUM_LENGTH_BITS; pack_int_value (NULL, INT_TYPE_SIDE, raw->side); sector_pack_size += NUM_SIDE_BITS; side_count = 1; } else { side_count ++; } } } pack_int_value (NULL, INT_TYPE_LENGTH, side_count); #if DEBUG_MODULE debug_log ("SC_PACK : packed %d sectors for %s", side_count, entity_side_names [current_side]); #endif total_side_count += side_count; sector_pack_size += NUM_LENGTH_BITS; // // Termination // pack_int_value (NULL, INT_TYPE_SIDE, ENTITY_SIDE_NEUTRAL); sector_pack_size += NUM_SIDE_BITS; pack_int_value (NULL, INT_TYPE_LENGTH, 0); sector_pack_size += NUM_LENGTH_BITS; debug_log ("SC_PACK : packed %d sectors", total_side_count); ASSERT (total_side_count == (NUM_MAP_Z_SECTORS * NUM_MAP_X_SECTORS)); // // Pack FOG OF WAR // for (z_sec = MIN_MAP_Z_SECTOR; z_sec <= MAX_MAP_Z_SECTOR; z_sec++) { for (x_sec = MIN_MAP_X_SECTOR; x_sec <= MAX_MAP_X_SECTOR; x_sec++) { en = get_local_raw_sector_entity(x_sec, z_sec); raw = get_local_entity_data (en); pack_float_value (en, FLOAT_TYPE_FOG_OF_WAR, raw->fog_of_war [ENTITY_SIDE_BLUE_FORCE]); pack_float_value (en, FLOAT_TYPE_FOG_OF_WAR, raw->fog_of_war [ENTITY_SIDE_RED_FORCE]); } } // // If saving game write out sector values (threat etc) // if (mode == PACK_MODE_SERVER_SESSION) { for (z_sec = MIN_MAP_Z_SECTOR; z_sec <= MAX_MAP_Z_SECTOR; z_sec++) { for (x_sec = MIN_MAP_X_SECTOR; x_sec <= MAX_MAP_X_SECTOR; x_sec++) { en = get_local_raw_sector_entity(x_sec, z_sec); raw = get_local_entity_data (en); ///////////////////////////////////////////////////////////////// if (raw->sector_task_root.first_child) { pack_int_value (en, INT_TYPE_VALID, TRUE); pack_list_root (en, LIST_TYPE_SECTOR_TASK, &raw->sector_task_root); } else { pack_int_value (en, INT_TYPE_VALID, FALSE); } ///////////////////////////////////////////////////////////////// if (raw->special_effect_root.first_child) { pack_int_value (en, INT_TYPE_VALID, TRUE); pack_list_root (en, LIST_TYPE_SPECIAL_EFFECT, &raw->special_effect_root); } else { pack_int_value (en, INT_TYPE_VALID, FALSE); } //debug_log ("SC_PACK: packing sector %d, %d", raw->x_sector, raw->z_sector); pack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_COUNT, raw->keysite_count); pack_float_value (en, FLOAT_TYPE_PROTOTYPE_1, raw->tallest_structure_height); } } } //debug_log ("SC_PACK: packing %d sectors took %d bytes (%d bits)", NUM_MAP_X_SECTORS * NUM_MAP_Z_SECTORS, sector_pack_size / 8, sector_pack_size); }