void read_flying_controls( object * obj ) { if ((Players[Player_num].spec_flags & PLAYER_FLAGS_SPECTATING) && (!in_free)) return; // jinx 08-07-13 spec fix afterburner_thrust; fix spec_booster = 0; fix spec_speed_x = 0; fix spec_speed_y = 0; fix spec_speed_z = 0; Assert(FrameTime > 0); //Get MATT if hit this! // Couldn't the "50" in the next three lines be changed to "64" with no ill effect? obj->mtype.phys_info.rotthrust.x = Controls.pitch_time; obj->mtype.phys_info.rotthrust.y = Controls.heading_time; obj->mtype.phys_info.rotthrust.z = Controls.bank_time; afterburner_thrust = 0; if (Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER) afterburner_thrust = FrameTime; if (Players[Player_num].spec_flags & PLAYER_FLAGS_SPECTATING) // jinx 08-07-13 spec { spec_booster = Cruise_speed / F1_0 * SPEC_SPEED_MOD; // jinx 08-07-13 spec // Cruise_speed / (F1_0 * 10) = a scale of 100% normal thrust time to 110% total // 6553600 Cruise_speed == F1_0 * 100 if (spec_booster) // jinx 08-07-13 spec { spec_speed_z = (Controls.forward_thrust_time * spec_booster / 100); spec_speed_x = (Controls.sideways_thrust_time * spec_booster / 100); spec_speed_y = (Controls.vertical_thrust_time * spec_booster / 100); } } //if (f2i(Cruise_speed) < 50) spec_booster *= -1; // Set object's thrust vector for forward/backward vm_vec_copy_scale(&obj->mtype.phys_info.thrust,&obj->orient.fvec, Controls.forward_thrust_time + afterburner_thrust + spec_speed_z); // jinx 08-07-13 spec // slide left/right vm_vec_scale_add2(&obj->mtype.phys_info.thrust,&obj->orient.rvec, Controls.sideways_thrust_time + spec_speed_x); // jinx 08-07-13 spec // slide up/down vm_vec_scale_add2(&obj->mtype.phys_info.thrust,&obj->orient.uvec, Controls.vertical_thrust_time + spec_speed_y); // jinx 08-07-13 spec if (obj->mtype.phys_info.flags & PF_WIGGLE) { fix swiggle; fix_fastsincos(((fix)GameTime64), &swiggle, NULL); if (FrameTime < F1_0) // Only scale wiggle if getting at least 1 FPS, to avoid causing the opposite problem. swiggle = fixmul(swiggle*20, FrameTime); //make wiggle fps-independant (based on pre-scaled amount of wiggle at 20 FPS) vm_vec_scale_add2(&obj->mtype.phys_info.velocity,&obj->orient.uvec,fixmul(swiggle,Player_ship->wiggle)); } // As of now, obj->mtype.phys_info.thrust & obj->mtype.phys_info.rotthrust are // in units of time... In other words, if thrust==FrameTime, that // means that the user was holding down the Max_thrust key for the // whole frame. So we just scale them up by the max, and divide by // FrameTime to make them independant of framerate // Prevent divide overflows on high frame rates. // In a signed divide, you get an overflow if num >= div<<15 { fix ft = FrameTime; // Note, you must check for ft < F1_0/2, else you can get an overflow on the << 15. if ((ft < F1_0/2) && (ft << 15 <= Player_ship->max_thrust)) { ft = (Player_ship->max_thrust >> 15) + 1; } vm_vec_scale( &obj->mtype.phys_info.thrust, fixdiv(Player_ship->max_thrust,ft) ); if ((ft < F1_0/2) && (ft << 15 <= Player_ship->max_rotthrust)) { ft = (Player_ship->max_thrust >> 15) + 1; }
void read_flying_controls( object * obj ) { //if ((Players[Player_num].spec_flags & PLAYER_FLAGS_SPECTATING) && (!in_free)) return; // jinx 02-01-13 spec fix forward_thrust_time; Assert(FrameTime > 0); //Get MATT if hit this! // this section commented and moved to the bottom by WraithX // if (Player_is_dead) { // vm_vec_zero(&obj->mtype.phys_info.rotthrust); // vm_vec_zero(&obj->mtype.phys_info.thrust); // return; // } // end of section to be moved. if (((obj->type!=OBJ_PLAYER) || (obj->id!=Player_num)) && (!(Players[Player_num].spec_flags & PLAYER_FLAGS_SPECTATING))) return; //references to player_ship require that this obj be the player // jinx 02-01-13 spec if (Guided_missile[Player_num] && Guided_missile[Player_num]->signature==Guided_missile_sig[Player_num]) { vms_angvec rotangs; vms_matrix rotmat,tempm; fix speed; //this is a horrible hack. guided missile stuff should not be //handled in the middle of a routine that is dealing with the player vm_vec_zero(&obj->mtype.phys_info.rotthrust); rotangs.p = Controls.pitch_time / 2 + Seismic_tremor_magnitude/64; rotangs.b = Controls.bank_time / 2 + Seismic_tremor_magnitude/16; rotangs.h = Controls.heading_time / 2 + Seismic_tremor_magnitude/64; vm_angles_2_matrix(&rotmat,&rotangs); vm_matrix_x_matrix(&tempm,&Guided_missile[Player_num]->orient,&rotmat); Guided_missile[Player_num]->orient = tempm; speed = Weapon_info[Guided_missile[Player_num]->id].speed[Difficulty_level]; vm_vec_copy_scale(&Guided_missile[Player_num]->mtype.phys_info.velocity,&Guided_missile[Player_num]->orient.fvec,speed); #ifdef NETWORK if (Game_mode & GM_MULTI) multi_send_guided_info (Guided_missile[Player_num],0); #endif } else { obj->mtype.phys_info.rotthrust.x = Controls.pitch_time; obj->mtype.phys_info.rotthrust.y = Controls.heading_time; obj->mtype.phys_info.rotthrust.z = Controls.bank_time; } forward_thrust_time = Controls.forward_thrust_time; if ((Players[Player_num].flags & PLAYER_FLAGS_AFTERBURNER) || (Players[Player_num].spec_flags & PLAYER_FLAGS_SPECTATING)) // jinx 02-01-13 spec { if (Controls.afterburner_state) { //player has key down //if (forward_thrust_time >= 0) { //..and isn't moving backward { fix afterburner_scale; int old_count,new_count; //add in value from 0..1 afterburner_scale = f1_0 + min(f1_0/2,Afterburner_charge) * 2; forward_thrust_time = fixmul(FrameTime,afterburner_scale); //based on full thrust if (Players[Player_num].spec_flags & PLAYER_FLAGS_SPECTATING) forward_thrust_time *= 1.3; // jinx 01-25-13 spec old_count = (Afterburner_charge / (DROP_DELTA_TIME/AFTERBURNER_USE_SECS)); if (!(Players[Player_num].spec_flags & PLAYER_FLAGS_SPECTATING)) // jinx 01-25-13 spec Afterburner_charge -= FrameTime/AFTERBURNER_USE_SECS; if (Afterburner_charge < 0) Afterburner_charge = 0; new_count = (Afterburner_charge / (DROP_DELTA_TIME/AFTERBURNER_USE_SECS)); if (old_count != new_count) Drop_afterburner_blob_flag = 1; //drop blob (after physics called) } } else { fix cur_energy,charge_up; //charge up to full charge_up = min(FrameTime/8,f1_0 - Afterburner_charge); //recharge over 8 seconds cur_energy = max(Players[Player_num].energy-i2f(10),0); //don't drop below 10 //maybe limit charge up by energy charge_up = min(charge_up,cur_energy/10); Afterburner_charge += charge_up; if (!(Players[Player_num].spec_flags & PLAYER_FLAGS_SPECTATING)) // jinx 01-25-13 spec Players[Player_num].energy -= charge_up * 100 / 10; //full charge uses 10% of energy } } // Set object's thrust vector for forward/backward vm_vec_copy_scale(&obj->mtype.phys_info.thrust,&obj->orient.fvec, forward_thrust_time ); // slide left/right vm_vec_scale_add2(&obj->mtype.phys_info.thrust,&obj->orient.rvec, Controls.sideways_thrust_time ); // slide up/down vm_vec_scale_add2(&obj->mtype.phys_info.thrust,&obj->orient.uvec, Controls.vertical_thrust_time ); if (obj->mtype.phys_info.flags & PF_WIGGLE) { fix swiggle; fix_fastsincos(((fix)GameTime64), &swiggle, NULL); if (FrameTime < F1_0) // Only scale wiggle if getting at least 1 FPS, to avoid causing the opposite problem. swiggle = fixmul(swiggle*20, FrameTime); //make wiggle fps-independent (based on pre-scaled amount of wiggle at 20 FPS) vm_vec_scale_add2(&obj->mtype.phys_info.velocity,&obj->orient.uvec,fixmul(swiggle,Player_ship->wiggle)); } // As of now, obj->mtype.phys_info.thrust & obj->mtype.phys_info.rotthrust are // in units of time... In other words, if thrust==FrameTime, that // means that the user was holding down the Max_thrust key for the // whole frame. So we just scale them up by the max, and divide by // FrameTime to make them independant of framerate // Prevent divide overflows on high frame rates. // In a signed divide, you get an overflow if num >= div<<15 { fix ft = FrameTime; // Note, you must check for ft < F1_0/2, else you can get an overflow on the << 15. if ((ft < F1_0/2) && (ft << 15 <= Player_ship->max_thrust)) { ft = (Player_ship->max_thrust >> 15) + 1; } vm_vec_scale( &obj->mtype.phys_info.thrust, fixdiv(Player_ship->max_thrust,ft) ); if ((ft < F1_0/2) && (ft << 15 <= Player_ship->max_rotthrust)) { ft = (Player_ship->max_thrust >> 15) + 1; }