2006-03-20 17:12:09 +00:00
|
|
|
/*
|
2014-06-01 17:55:23 +00:00
|
|
|
* Portions of this file are copyright Rebirth contributors and licensed as
|
|
|
|
* described in COPYING.txt.
|
|
|
|
* Portions of this file are copyright Parallax Software and licensed
|
|
|
|
* according to the Parallax license below.
|
|
|
|
* See COPYING.txt for license details.
|
|
|
|
|
2006-03-20 17:12:09 +00:00
|
|
|
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
|
|
|
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
|
|
|
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
|
|
|
|
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
|
|
|
|
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|
|
|
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
|
|
|
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
|
|
|
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
|
|
|
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
|
|
|
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Code for controlling player movement
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#include <algorithm>
|
2006-03-20 17:12:09 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "key.h"
|
|
|
|
#include "joy.h"
|
|
|
|
#include "timer.h"
|
2012-07-07 18:35:06 +00:00
|
|
|
#include "dxxerror.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "inferno.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include "object.h"
|
|
|
|
#include "player.h"
|
2015-07-25 23:10:45 +00:00
|
|
|
#include "weapon.h"
|
2013-11-17 00:50:32 +00:00
|
|
|
#include "bm.h"
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "controls.h"
|
|
|
|
#include "render.h"
|
|
|
|
#include "args.h"
|
|
|
|
#include "palette.h"
|
|
|
|
#include "mouse.h"
|
|
|
|
#include "kconfig.h"
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2006-03-20 17:12:09 +00:00
|
|
|
#include "laser.h"
|
|
|
|
#include "multi.h"
|
|
|
|
#include "vclip.h"
|
|
|
|
#include "fireball.h"
|
|
|
|
|
|
|
|
//look at keyboard, mouse, joystick, CyberMan, whatever, and set
|
|
|
|
//physics vars rotvel, velocity
|
|
|
|
|
|
|
|
fix Afterburner_charge=f1_0;
|
|
|
|
|
|
|
|
#define AFTERBURNER_USE_SECS 3 //use up in 3 seconds
|
|
|
|
#define DROP_DELTA_TIME (f1_0/15) //drop 3 per second
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
using std::min;
|
|
|
|
using std::max;
|
|
|
|
|
2016-08-25 04:05:32 +00:00
|
|
|
namespace dsx {
|
2018-06-24 05:06:15 +00:00
|
|
|
void read_flying_controls(object &obj)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
fix forward_thrust_time;
|
|
|
|
|
|
|
|
Assert(FrameTime > 0); //Get MATT if hit this!
|
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2018-06-24 05:06:15 +00:00
|
|
|
if (obj.type != OBJ_PLAYER || get_player_id(obj) != Player_num)
|
2015-11-27 03:56:13 +00:00
|
|
|
return; //references to player_ship require that this obj be the player
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2015-03-22 22:48:47 +00:00
|
|
|
const auto control_guided_missile = [&] {
|
2018-12-30 00:43:57 +00:00
|
|
|
const auto &&gimobj = LevelUniqueObjectState.Guided_missile.get_player_active_guided_missile(LevelUniqueObjectState.get_objects().vmptr, Player_num);
|
2018-10-08 03:58:48 +00:00
|
|
|
if (gimobj == nullptr)
|
2015-03-22 22:48:47 +00:00
|
|
|
return false;
|
2018-10-08 03:58:48 +00:00
|
|
|
auto &gmobj = *gimobj;
|
|
|
|
const auto gmid = get_weapon_id(gmobj);
|
2019-06-27 03:26:20 +00:00
|
|
|
const auto speed = Weapon_info[gmid].speed[GameUniqueState.Difficulty_level];
|
2006-03-20 17:12:09 +00:00
|
|
|
vms_angvec rotangs;
|
|
|
|
//this is a horrible hack. guided missile stuff should not be
|
|
|
|
//handled in the middle of a routine that is dealing with the player
|
|
|
|
|
2018-06-24 05:06:15 +00:00
|
|
|
vm_vec_zero(obj.mtype.phys_info.rotthrust);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2019-08-06 02:59:41 +00:00
|
|
|
const auto Seismic_tremor_magnitude = LevelUniqueSeismicState.Seismic_tremor_magnitude;
|
2006-03-20 17:12:09 +00:00
|
|
|
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;
|
|
|
|
|
2015-02-05 03:03:51 +00:00
|
|
|
const auto &&rotmat = vm_angles_2_matrix(rotangs);
|
2018-10-08 03:58:48 +00:00
|
|
|
gmobj.orient = vm_matrix_x_matrix(gmobj.orient, rotmat);
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2018-10-08 03:58:48 +00:00
|
|
|
vm_vec_copy_scale(gmobj.mtype.phys_info.velocity, gmobj.orient.fvec, speed);
|
2006-03-20 17:12:09 +00:00
|
|
|
if (Game_mode & GM_MULTI)
|
2018-10-08 03:58:48 +00:00
|
|
|
multi_send_guided_info(gmobj, 0);
|
2015-03-22 22:48:47 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
if (!control_guided_missile())
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
|
|
|
{
|
2018-06-24 05:06:15 +00:00
|
|
|
auto &rotthrust = obj.mtype.phys_info.rotthrust;
|
|
|
|
rotthrust.x = Controls.pitch_time;
|
|
|
|
rotthrust.y = Controls.heading_time;
|
|
|
|
rotthrust.z = Controls.bank_time;
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
forward_thrust_time = Controls.forward_thrust_time;
|
|
|
|
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_II)
|
2018-06-24 05:06:15 +00:00
|
|
|
auto &player_info = obj.ctype.player_info;
|
2016-10-02 00:34:40 +00:00
|
|
|
if (player_info.powerup_flags & PLAYER_FLAGS_AFTERBURNER)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2013-11-26 22:46:48 +00:00
|
|
|
if (Controls.state.afterburner) { //player has key down
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
|
old_count = (Afterburner_charge / (DROP_DELTA_TIME/AFTERBURNER_USE_SECS));
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-09-11 18:49:13 +00:00
|
|
|
auto &energy = player_info.energy;
|
2016-07-03 00:54:16 +00:00
|
|
|
cur_energy = max(energy - i2f(10), 0); //don't drop below 10
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
//maybe limit charge up by energy
|
|
|
|
charge_up = min(charge_up,cur_energy/10);
|
|
|
|
|
|
|
|
Afterburner_charge += charge_up;
|
|
|
|
|
2016-07-03 00:54:16 +00:00
|
|
|
energy -= charge_up * 100 / 10; //full charge uses 10% of energy
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// Set object's thrust vector for forward/backward
|
2018-06-24 05:06:15 +00:00
|
|
|
vm_vec_copy_scale(obj.mtype.phys_info.thrust, obj.orient.fvec, forward_thrust_time );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// slide left/right
|
2018-06-24 05:06:15 +00:00
|
|
|
vm_vec_scale_add2(obj.mtype.phys_info.thrust, obj.orient.rvec, Controls.sideways_thrust_time );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
// slide up/down
|
2018-06-24 05:06:15 +00:00
|
|
|
vm_vec_scale_add2(obj.mtype.phys_info.thrust, obj.orient.uvec, Controls.vertical_thrust_time );
|
2006-03-20 17:12:09 +00:00
|
|
|
|
2018-06-24 05:06:15 +00:00
|
|
|
if (obj.mtype.phys_info.flags & PF_WIGGLE)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2015-02-05 03:03:50 +00:00
|
|
|
auto swiggle = fix_fastsin(static_cast<fix>(GameTime64));
|
2006-03-20 17:12:09 +00:00
|
|
|
if (FrameTime < F1_0) // Only scale wiggle if getting at least 1 FPS, to avoid causing the opposite problem.
|
2013-08-08 20:07:29 +00:00
|
|
|
swiggle = fixmul(swiggle*DESIGNATED_GAME_FPS, FrameTime); //make wiggle fps-independent (based on pre-scaled amount of wiggle at DESIGNATED_GAME_FPS)
|
2018-06-24 05:06:15 +00:00
|
|
|
vm_vec_scale_add2(obj.mtype.phys_info.velocity, obj.orient.uvec, fixmul(swiggle, Player_ship->wiggle));
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 05:06:15 +00:00
|
|
|
// As of now, obj.mtype.phys_info.thrust & obj->mtype.phys_info.rotthrust are
|
2006-03-20 17:12:09 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2018-06-24 05:06:15 +00:00
|
|
|
vm_vec_scale(obj.mtype.phys_info.thrust, fixdiv(Player_ship->max_thrust, ft));
|
2006-03-20 17:12:09 +00:00
|
|
|
|
|
|
|
if ((ft < F1_0/2) && (ft << 15 <= Player_ship->max_rotthrust)) {
|
|
|
|
ft = (Player_ship->max_thrust >> 15) + 1;
|
|
|
|
}
|
|
|
|
|
2018-06-24 05:06:15 +00:00
|
|
|
vm_vec_scale(obj.mtype.phys_info.rotthrust, fixdiv(Player_ship->max_rotthrust, ft));
|
2006-03-20 17:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// moved here by WraithX
|
2015-12-15 04:09:35 +00:00
|
|
|
if (Player_dead_state != player_dead_state::no)
|
2006-03-20 17:12:09 +00:00
|
|
|
{
|
2018-06-24 05:06:15 +00:00
|
|
|
//vm_vec_zero(&obj.mtype.phys_info.rotthrust); // let dead players rotate, changed by WraithX
|
|
|
|
vm_vec_zero(obj.mtype.phys_info.thrust); // don't let dead players move, changed by WraithX
|
2006-03-20 17:12:09 +00:00
|
|
|
return;
|
|
|
|
}// end if
|
|
|
|
|
|
|
|
}
|
2016-08-25 04:05:32 +00:00
|
|
|
}
|