diff --git a/common/main/laser.h b/common/main/laser.h index 33dee5e49..258943c12 100644 --- a/common/main/laser.h +++ b/common/main/laser.h @@ -107,17 +107,16 @@ enum weapon_type_t // MIN_TRACKABLE_DOT gets inversely scaled by FrameTime and stuffed in // Min_trackable_dot #if defined(DXX_BUILD_DESCENT_I) -#define MIN_TRACKABLE_DOT (3*F1_0/4) +#define HOMING_MAX_TRACKABLE_DOT (3*F1_0/4) #elif defined(DXX_BUILD_DESCENT_II) -#define MIN_TRACKABLE_DOT (7*F1_0/8) +#define HOMING_MAX_TRACKABLE_DOT (7*F1_0/8) #endif -#define MAX_TRACKABLE_DIST (F1_0*250) -#define HOMING_MISSILE_STRAIGHT_TIME (F1_0/8) // Changed as per request of John, Adam, Yuan, but mostly John +#define HOMING_MIN_TRACKABLE_DOT (3*(F1_0 - HOMING_MAX_TRACKABLE_DOT)/4 + HOMING_MAX_TRACKABLE_DOT) +#define HOMING_MAX_TRACKABLE_DIST (F1_0*250) +#define HOMING_FLY_STRAIGHT_TIME (F1_0/8) struct object; -extern fix Min_trackable_dot; // MIN_TRACKABLE_DOT inversely scaled by FrameTime - void Laser_render(struct object *obj); void Laser_player_fire(struct object * obj, int type, int gun_num, int make_sound, int harmless_flag); void Laser_player_fire_spread(struct object *obj, int laser_type, int gun_num, fix spreadr, fix spreadu, int make_sound, int harmless); diff --git a/common/main/multi.h b/common/main/multi.h index cd3c38150..265e1d64d 100644 --- a/common/main/multi.h +++ b/common/main/multi.h @@ -60,7 +60,7 @@ extern int multi_protocol; // set and determinate used protocol #define MULTI_PROTO_UDP 1 // UDP protocol // What version of the multiplayer protocol is this? Increment each time something drastic changes in Multiplayer without the version number changes. Can be reset to 0 each time the version of the game changes -#define MULTI_PROTO_VERSION 0 +#define MULTI_PROTO_VERSION 1 // PROTOCOL VARIABLES AND DEFINES - END diff --git a/d1x-rebirth/main/laser.c b/d1x-rebirth/main/laser.c index 325273055..5e6b59c85 100644 --- a/d1x-rebirth/main/laser.c +++ b/d1x-rebirth/main/laser.c @@ -470,7 +470,6 @@ int object_to_object_visibility(object *obj1, object *obj2, int trans_type) return 0; } -fix Min_trackable_dot = 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT; //MIN_TRACKABLE_DOT; // ----------------------------------------------------------------------------------------------------------- // Return true if weapon *tracker is able to track object Objects[track_goal], else return false. @@ -502,12 +501,7 @@ int object_is_trackable(int track_goal, object *tracker, fix *dot) vm_vec_normalize_quick(&vector_to_goal); *dot = vm_vec_dot(&vector_to_goal, &tracker->orient.fvec); - if ((*dot < Min_trackable_dot) && (*dot > F1_0*9/10)) { - vm_vec_normalize(&vector_to_goal); - *dot = vm_vec_dot(&vector_to_goal, &tracker->orient.fvec); - } - - if (*dot >= Min_trackable_dot) { + if (*dot >= HOMING_MIN_TRACKABLE_DOT) { int rval; // dot is in legal range, now see if object is visible rval = object_to_object_visibility(tracker, objp, FQ_TRANSWALL); @@ -546,11 +540,15 @@ int find_homing_object(vms_vector *curpos, object *tracker) } } else { + int cur_min_trackable_dot = HOMING_MAX_TRACKABLE_DOT; + // Not in network mode. If not fired by player, then track player. if (tracker->ctype.laser_info.parent_num != Players[Player_num].objnum) { if (!(Players[Player_num].flags & PLAYER_FLAGS_CLOAKED)) best_objnum = ConsoleObject - Objects; } else { + fix dist, max_trackable_dist = HOMING_MAX_TRACKABLE_DIST; + // Not in network mode and fired by player. for (i=Window_rendered_data[0].num_objects-1; i>=0; i--) { fix dot; //, dist; @@ -567,13 +565,11 @@ int find_homing_object(vms_vector *curpos, object *tracker) continue; vm_vec_sub(&vec_to_curobj, &curobjp->pos, curpos); - vm_vec_normalize_quick(&vec_to_curobj); - dot = vm_vec_dot(&vec_to_curobj, &tracker->orient.fvec); + dist = vm_vec_normalize_quick(&vec_to_curobj); + if (dist < max_trackable_dist) { + dot = vm_vec_dot(&vec_to_curobj, &tracker->orient.fvec); - // Note: This uses the constant, not-scaled-by-frametime value, because it is only used - // to determine if an object is initially trackable. find_homing_object is called on subsequent - // frames to determine if the object remains trackable. - if (dot > MIN_TRACKABLE_DOT) { + if (dot > cur_min_trackable_dot) { if (dot > max_dot) { if (object_to_object_visibility(tracker, &Objects[objnum], FQ_TRANSWALL)) { max_dot = dot; @@ -581,6 +577,7 @@ int find_homing_object(vms_vector *curpos, object *tracker) } } } + } } } } @@ -598,8 +595,8 @@ int find_homing_object_complete(vms_vector *curpos, object *tracker, int track_o fix max_dot = -F1_0*2; int best_objnum = -1; - fix max_trackable_dist = MAX_TRACKABLE_DIST; - fix min_trackable_dot = MIN_TRACKABLE_DOT; + fix max_trackable_dist = HOMING_MAX_TRACKABLE_DIST; + fix min_trackable_dot = HOMING_MAX_TRACKABLE_DOT; if (!Weapon_info[tracker->id].homing_flag) { Int3(); // Contact Mike: This is a bad and stupid thing. Who called this routine with an illegal laser type?? @@ -652,9 +649,6 @@ int find_homing_object_complete(vms_vector *curpos, object *tracker, int track_o if (is_proximity) dot = ((dot << 3) + dot) >> 3; // I suspect Watcom would be too stupid to figure out the obvious... - // Note: This uses the constant, not-scaled-by-frametime value, because it is only used - // to determine if an object is initially trackable. find_homing_object is called on subsequent - // frames to determine if the object remains trackable. if (dot > min_trackable_dot) { if (dot > max_dot) { if (object_to_object_visibility(tracker, &Objects[objnum], FQ_TRANSWALL)) { @@ -676,9 +670,9 @@ int find_homing_object_complete(vms_vector *curpos, object *tracker, int track_o int track_track_goal(int track_goal, object *tracker, fix *dot) { #ifdef NEWHOMER - if (object_is_trackable(track_goal, tracker, dot) && (tracker-Objects)) { + if (object_is_trackable(track_goal, tracker, dot)) { return track_goal; - } else if (tracker-Objects) + } else if ((((tracker-Objects) ^ d_tick_count) % 4) == 0) #else // Every 8 frames for each object, scan all objects. if (object_is_trackable(track_goal, tracker, dot) && ((((tracker-Objects) ^ d_tick_count) % 8) != 0)) { @@ -899,9 +893,8 @@ void homing_missile_turn_towards_velocity(object *objp, vms_vector *norm_vel) /* * In the original game homers turned sharper in higher FPS-values. We do not want that so we need to scale vector_to_object to FrameTime. * For each difficulty setting we have a base value the homers will align to. This we express in a FPS value representing the homers turn radius of the original game (i.e. "The homer will turn like on XXFPS"). - * NOTE: Old homers only get valid track_goal every 8 frames. This does not apply anymore so these values are divided by 4 to compensate this. */ -fix homing_turn_base[NDL] = { 4, 5, 6, 7, 8 }; +fix homing_turn_base[NDL] = { 22, 24, 26, 28, 30 }; #endif //------------------------------------------------------------------------------------------- @@ -939,8 +932,8 @@ void Laser_do_weapon_sequence(object *obj) fix dot=F1_0; fix speed, max_speed; - // For first 1/2 second of life, missile flies straight. - if (obj->ctype.laser_info.creation_time + HOMING_MISSILE_STRAIGHT_TIME < GameTime64) { + // For first 125ms of life, missile flies straight. + if (obj->ctype.laser_info.creation_time + HOMING_FLY_STRAIGHT_TIME < GameTime64) { int track_goal = obj->ctype.laser_info.track_goal; @@ -965,9 +958,12 @@ void Laser_do_weapon_sequence(object *obj) #ifdef NEWHOMER vm_vec_sub(&vector_to_object, &Objects[track_goal].pos, &obj->pos); + // Scale vector to object to current FrameTime. + vm_vec_scale(&vector_to_object, F1_0/((float)(F1_0/homing_turn_base[Difficulty_level])/FrameTime)); + vm_vec_normalize_quick(&vector_to_object); temp_vec = obj->mtype.phys_info.velocity; - speed = vm_vec_normalize(&temp_vec); + speed = vm_vec_normalize_quick(&temp_vec); max_speed = Weapon_info[obj->id].speed[Difficulty_level]; if (speed+F1_0 < max_speed) { speed += fixmul(max_speed, FrameTime/2); @@ -975,14 +971,13 @@ void Laser_do_weapon_sequence(object *obj) speed = max_speed; } - // Scale vector to object to current FrameTime. - vm_vec_scale(&vector_to_object, F1_0/((float)(F1_0/homing_turn_base[Difficulty_level])/FrameTime)); + dot = vm_vec_dot(&temp_vec, &vector_to_object); vm_vec_add2(&temp_vec, &vector_to_object); // The boss' smart children track better... if (Weapon_info[obj->id].render_type != WEAPON_RENDER_POLYMODEL) vm_vec_add2(&temp_vec, &vector_to_object); - vm_vec_normalize(&temp_vec); + vm_vec_normalize_quick(&temp_vec); vm_vec_scale(&temp_vec, speed); obj->mtype.phys_info.velocity = temp_vec; @@ -999,7 +994,7 @@ void Laser_do_weapon_sequence(object *obj) // Only polygon objects have visible orientation, so only they should turn. if (Weapon_info[obj->id].render_type == WEAPON_RENDER_POLYMODEL) - homing_missile_turn_towards_velocity(obj, &temp_vec); // temp_vec is normalized velocity. + homing_missile_turn_towards_velocity(obj, &temp_vec); // temp_vec is normalized velocity. #else // OLD - ORIGINAL - MISSILE TRACKING CODE vm_vec_sub(&vector_to_object, &Objects[track_goal].pos, &obj->pos); diff --git a/d2x-rebirth/main/laser.c b/d2x-rebirth/main/laser.c index db89f2393..a6ac73514 100644 --- a/d2x-rebirth/main/laser.c +++ b/d2x-rebirth/main/laser.c @@ -860,7 +860,6 @@ int object_to_object_visibility(object *obj1, object *obj2, int trans_type) return 0; } -fix Min_trackable_dot = 3*(F1_0 - MIN_TRACKABLE_DOT)/4 + MIN_TRACKABLE_DOT; //MIN_TRACKABLE_DOT; // ----------------------------------------------------------------------------------------------------------- // Return true if weapon *tracker is able to track object Objects[track_goal], else return false. @@ -896,12 +895,7 @@ int object_is_trackable(int track_goal, object *tracker, fix *dot) vm_vec_normalize_quick(&vector_to_goal); *dot = vm_vec_dot(&vector_to_goal, &tracker->orient.fvec); - if ((*dot < Min_trackable_dot) && (*dot > F1_0*9/10)) { - vm_vec_normalize(&vector_to_goal); - *dot = vm_vec_dot(&vector_to_goal, &tracker->orient.fvec); - } - - if (*dot >= Min_trackable_dot) { + if (*dot >= HOMING_MIN_TRACKABLE_DOT) { int rval; // dot is in legal range, now see if object is visible rval = object_to_object_visibility(tracker, objp, FQ_TRANSWALL); @@ -950,9 +944,8 @@ int find_homing_object(vms_vector *curpos, object *tracker) if (Game_mode & GM_MULTI) return call_find_homing_object_complete(tracker, curpos); else { - int cur_min_trackable_dot; + int cur_min_trackable_dot = HOMING_MAX_TRACKABLE_DOT; - cur_min_trackable_dot = MIN_TRACKABLE_DOT; if ((tracker->type == OBJ_WEAPON) && (tracker->id == OMEGA_ID)) cur_min_trackable_dot = OMEGA_MIN_TRACKABLE_DOT; @@ -962,7 +955,10 @@ int find_homing_object(vms_vector *curpos, object *tracker) best_objnum = ConsoleObject - Objects; } else { int window_num = -1; - fix dist, max_trackable_dist; + fix dist, max_trackable_dist = HOMING_MAX_TRACKABLE_DIST; + + if (tracker->id == OMEGA_ID) + max_trackable_dist = OMEGA_MAX_TRACKABLE_DIST; // Find the window which has the forward view. for (i=0; iid == OMEGA_ID) - max_trackable_dist = OMEGA_MAX_TRACKABLE_DIST; - // Not in network mode and fired by player. for (i=Window_rendered_data[window_num].num_objects-1; i>=0; i--) { fix dot; //, dist; @@ -1008,9 +1000,6 @@ int find_homing_object(vms_vector *curpos, object *tracker) if (dist < max_trackable_dist) { dot = vm_vec_dot(&vec_to_curobj, &tracker->orient.fvec); - // Note: This uses the constant, not-scaled-by-frametime value, because it is only used - // to determine if an object is initially trackable. find_homing_object is called on subsequent - // frames to determine if the object remains trackable. if (dot > cur_min_trackable_dot) { if (dot > max_dot) { if (object_to_object_visibility(tracker, &Objects[objnum], FQ_TRANSWALL)) { @@ -1018,17 +1007,6 @@ int find_homing_object(vms_vector *curpos, object *tracker) best_objnum = objnum; } } - } else if (dot > F1_0 - (F1_0 - cur_min_trackable_dot)*2) { - vm_vec_normalize(&vec_to_curobj); - dot = vm_vec_dot(&vec_to_curobj, &tracker->orient.fvec); - if (dot > cur_min_trackable_dot) { - if (dot > max_dot) { - if (object_to_object_visibility(tracker, &Objects[objnum], FQ_TRANSWALL)) { - max_dot = dot; - best_objnum = objnum; - } - } - } } } } @@ -1055,8 +1033,8 @@ int find_homing_object_complete(vms_vector *curpos, object *tracker, int track_o // Contact Mike: This is a bad and stupid thing. Who called this routine with an illegal laser type?? Assert((Weapon_info[tracker->id].homing_flag) || (tracker->id == OMEGA_ID)); - max_trackable_dist = MAX_TRACKABLE_DIST; - min_trackable_dot = MIN_TRACKABLE_DOT; + max_trackable_dist = HOMING_MAX_TRACKABLE_DIST; + min_trackable_dot = HOMING_MAX_TRACKABLE_DOT; if (tracker->id == OMEGA_ID) { max_trackable_dist = OMEGA_MAX_TRACKABLE_DIST; @@ -1115,9 +1093,6 @@ int find_homing_object_complete(vms_vector *curpos, object *tracker, int track_o if (is_proximity) dot = ((dot << 3) + dot) >> 3; // I suspect Watcom would be too stupid to figure out the obvious... - // Note: This uses the constant, not-scaled-by-frametime value, because it is only used - // to determine if an object is initially trackable. find_homing_object is called on subsequent - // frames to determine if the object remains trackable. if (dot > min_trackable_dot) { if (dot > max_dot) { if (object_to_object_visibility(tracker, &Objects[objnum], FQ_TRANSWALL)) { @@ -1140,12 +1115,12 @@ int find_homing_object_complete(vms_vector *curpos, object *tracker, int track_o int track_track_goal(int track_goal, object *tracker, fix *dot) { #ifdef NEWHOMER - if (object_is_trackable(track_goal, tracker, dot) && (tracker-Objects)) { + if (object_is_trackable(track_goal, tracker, dot)) { return track_goal; - } else if (tracker-Objects) + } else if ((((tracker-Objects) ^ d_tick_count) % 4) == 0) #else // Every 8 frames for each object, scan all objects. - if (object_is_trackable(track_goal, tracker, dot) && ((((tracker-Objects) ^ d_tick_count) % 8) != 0)) { + if (object_is_trackable(track_goal, tracker, dot)) { return track_goal; } else if ((((tracker-Objects) ^ d_tick_count) % 4) == 0) #endif @@ -1396,7 +1371,7 @@ void homing_missile_turn_towards_velocity(object *objp, vms_vector *norm_vel) * For each difficulty setting we have a base value the homers will align to. This we express in a FPS value representing the homers turn radius of the original game (i.e. "The homer will turn like on XXFPS"). * NOTE: Old homers only get valid track_goal every 8 frames. This does not apply anymore so these values are divided by 4 to compensate this. */ -fix homing_turn_base[NDL] = { 4, 5, 6, 7, 8 }; +fix homing_turn_base[NDL] = { 22, 24, 26, 28, 30 }; #endif //------------------------------------------------------------------------------------------- @@ -1438,8 +1413,8 @@ void Laser_do_weapon_sequence(object *obj) fix dot=F1_0; fix speed, max_speed; - // For first 1/2 second of life, missile flies straight. - if (obj->ctype.laser_info.creation_time + HOMING_MISSILE_STRAIGHT_TIME < GameTime64) { + // For first 125ms of life, missile flies straight. + if (obj->ctype.laser_info.creation_time + HOMING_FLY_STRAIGHT_TIME < GameTime64) { int track_goal = obj->ctype.laser_info.track_goal; @@ -1464,9 +1439,12 @@ void Laser_do_weapon_sequence(object *obj) #ifdef NEWHOMER vm_vec_sub(&vector_to_object, &Objects[track_goal].pos, &obj->pos); + // Scale vector to object to current FrameTime. + vm_vec_scale(&vector_to_object, F1_0/((float)(F1_0/homing_turn_base[Difficulty_level])/FrameTime)); + vm_vec_normalize_quick(&vector_to_object); temp_vec = obj->mtype.phys_info.velocity; - speed = vm_vec_normalize(&temp_vec); + speed = vm_vec_normalize_quick(&temp_vec); max_speed = Weapon_info[obj->id].speed[Difficulty_level]; if (speed+F1_0 < max_speed) { speed += fixmul(max_speed, FrameTime/2); @@ -1474,14 +1452,13 @@ void Laser_do_weapon_sequence(object *obj) speed = max_speed; } - // Scale vector to object to current FrameTime. - vm_vec_scale(&vector_to_object, F1_0/((float)(F1_0/homing_turn_base[Difficulty_level])/FrameTime)); + dot = vm_vec_dot(&temp_vec, &vector_to_object); vm_vec_add2(&temp_vec, &vector_to_object); // The boss' smart children track better... if (Weapon_info[obj->id].render_type != WEAPON_RENDER_POLYMODEL) vm_vec_add2(&temp_vec, &vector_to_object); - vm_vec_normalize(&temp_vec); + vm_vec_normalize_quick(&temp_vec); vm_vec_scale(&temp_vec, speed); obj->mtype.phys_info.velocity = temp_vec; @@ -1498,7 +1475,7 @@ void Laser_do_weapon_sequence(object *obj) // Only polygon objects have visible orientation, so only they should turn. if (Weapon_info[obj->id].render_type == WEAPON_RENDER_POLYMODEL) - homing_missile_turn_towards_velocity(obj, &temp_vec); // temp_vec is normalized velocity. + homing_missile_turn_towards_velocity(obj, &temp_vec); // temp_vec is normalized velocity. #else // OLD - ORIGINAL - MISSILE TRACKING CODE vm_vec_sub(&vector_to_object, &Objects[track_goal].pos, &obj->pos);