Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Drive and Afterburner #896

Merged
merged 32 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5e0c681
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Dec 1, 2023
d5f7361
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Dec 3, 2023
d08bfcf
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Apr 25, 2024
5126833
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk May 3, 2024
7fb35f5
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Jul 22, 2024
ad5c297
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Aug 15, 2024
08daa5b
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Sep 2, 2024
4be1d7f
Add support for ftl and jump drives
royfalk Sep 11, 2024
4354d63
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Oct 3, 2024
606f5d4
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Oct 14, 2024
d7dc075
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Oct 14, 2024
c358886
Merge from master
royfalk Oct 16, 2024
99e9fa3
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Oct 16, 2024
105c9f9
Periodic housekeeping 1
royfalk Oct 19, 2024
aadb810
Implement Drive and Afterburner
royfalk Oct 21, 2024
170fc7c
Fix some minor issues
royfalk Oct 28, 2024
f841bc0
Make tests use boost::pi and not M_PI
royfalk Oct 28, 2024
5b0d122
Fix code to remove warning
royfalk Oct 29, 2024
8f85312
Fix code QL issues
royfalk Oct 29, 2024
f5f854a
Fix bug in jump code
royfalk Oct 30, 2024
b7ce610
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Nov 2, 2024
7d19772
Disable most of test
royfalk Nov 2, 2024
be4e9ae
re-enable 1
royfalk Nov 2, 2024
d6d03f0
Re-enable 2
royfalk Nov 2, 2024
58db3fa
Re-enable 3
royfalk Nov 2, 2024
089e004
Re-enable 4
royfalk Nov 3, 2024
ed3957e
Fix test fail in modern systems
royfalk Nov 14, 2024
bd42430
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Nov 15, 2024
128317f
Merge from master
royfalk Nov 20, 2024
4f72ce2
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Nov 21, 2024
fe81691
Fix second fail in test
royfalk Nov 22, 2024
54c798f
Merge from master
royfalk Nov 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -727,13 +727,18 @@ SET(LIBPYTHON

SET(LIBCOMPONENT
src/components/component.cpp
src/components/dummy_component.cpp
src/components/component_utils

src/components/energy_consumer.cpp
src/components/energy_container.cpp
src/components/reactor.cpp

src/components/afterburner.cpp
src/components/afterburner_upgrade.cpp
src/components/cloak.cpp
src/components/drive.cpp
src/components/drive_upgrade.cpp
src/components/ftl_drive.cpp
src/components/jump_drive.cpp
)
Expand Down Expand Up @@ -1753,6 +1758,8 @@ IF (USE_GTEST)
src/exit_unit_tests.cpp
src/components/tests/energy_container_tests.cpp
src/components/tests/balancing_tests.cpp
src/components/tests/drive_tests.cpp
src/components/tests/afterburner_tests.cpp
src/components/tests/jump_drive_tests.cpp
)

Expand Down
10 changes: 5 additions & 5 deletions engine/src/cmd/ai/aggressive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ bool AggressiveAI::ExecuteLogicItem(const AIEvents::AIEvresult &item) {
}

bool AggressiveAI::ProcessLogicItem(const AIEvents::AIEvresult &item) {
float value = 0.0;
double value = 0.0;

switch (abs(item.type)) {
case DISTANCE:
Expand All @@ -317,11 +317,11 @@ bool AggressiveAI::ProcessLogicItem(const AIEvents::AIEvresult &item) {
Unit *targ = parent->Target();
if (targ) {
Vector PosDifference = targ->Position().Cast() - parent->Position().Cast();
float pdmag = PosDifference.Magnitude();
double pdmag = PosDifference.Magnitude();
value = (pdmag - parent->rSize() - targ->rSize());
float myvel = PosDifference.Dot(parent->GetVelocity() - targ->GetVelocity()) / value; ///pdmag;
double myvel = PosDifference.Dot(parent->GetVelocity() - targ->GetVelocity()) / value; ///pdmag;
if (myvel > 0) {
value -= myvel * myvel / (2 * (parent->limits.retro / parent->getMass()));
value -= myvel * myvel / (2 * (parent->drive.retro / parent->getMass()));
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
}
} else {
value = 10000;
Expand Down Expand Up @@ -1727,7 +1727,7 @@ void AggressiveAI::Execute() {
mag = 1 / mag;
}
parent->SetVelocity(
parent->GetVelocity() * (mag * parent->GetComputerData().max_speed() / getTimeCompression()));
parent->GetVelocity() * (mag * parent->MaxSpeed() / getTimeCompression()));
parent->NetLocalForce = parent->NetForce = Vector(0, 0, 0);
}
target = parent->Target();
Expand Down
4 changes: 2 additions & 2 deletions engine/src/cmd/ai/fire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ bool FireAt::PursueTarget(Unit *un, bool leader) {
bool CanFaceTarget(Unit *su, Unit *targ, const Matrix &matrix) {
return true;

float limitmin = su->limits.limitmin;
float limitmin = su->limit_min;
if (limitmin > -.99) {
QVector pos = (targ->Position() - su->Position()).Normalize();
QVector pnorm = pos.Cast();
Vector structurelimits = su->limits.structurelimits;
Vector structurelimits = su->structure_limits;
Vector worldlimit = TransformNormal(matrix, structurelimits);
if (pnorm.Dot(worldlimit) < limitmin) {
return false;
Expand Down
48 changes: 24 additions & 24 deletions engine/src/cmd/ai/flybywire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,16 @@ FlyByWire::FlyByWire() : MatchVelocity(Vector(0, 0, 0), Vector(0, 0, 0), true, f
}

void FlyByWire::Stop(float per) {
SetDesiredVelocity(Vector(0, 0, per * parent->GetComputerData().max_speed()), true);
SetDesiredVelocity(Vector(0, 0, per * parent->MaxSpeed()), true);

parent->GetComputerData().set_speed = per * parent->GetComputerData().max_speed();
parent->GetComputerData().set_speed = per * parent->MaxSpeed();
}

void FlyByWire::Right(float per) {
desired_ang_velocity +=
(-per
* (per
> 0 ? parent->GetComputerData().max_yaw_left : parent->GetComputerData().max_yaw_right)
> 0 ? parent->drive.max_yaw_left : parent->drive.max_yaw_right)
/ getTimeCompression()) * Vector(
0,
1,
Expand All @@ -212,7 +212,7 @@ void FlyByWire::Up(float per) {
desired_ang_velocity +=
(-per
* (per
> 0 ? parent->GetComputerData().max_pitch_down : parent->GetComputerData().max_pitch_up)
> 0 ? parent->drive.max_pitch_down : parent->drive.max_pitch_up)
/ getTimeCompression()) * Vector(
1,
0,
Expand All @@ -223,7 +223,7 @@ void FlyByWire::RollRight(float per) {
desired_ang_velocity +=
(-per
* (per
> 0 ? parent->GetComputerData().max_roll_left : parent->GetComputerData().max_roll_right)
> 0 ? parent->drive.max_roll_left : parent->drive.max_roll_right)
/ getTimeCompression()) * Vector(
0,
0,
Expand All @@ -235,9 +235,9 @@ void FlyByWire::Afterburn(float per) {

afterburn = (per > .1);
if (!sheltonslide && !inertial_flight_model) {
desired_velocity = Vector(0, 0, cpu->set_speed + per * (cpu->max_ab_speed() - cpu->set_speed));
desired_velocity = Vector(0, 0, cpu->set_speed + per * (parent->MaxAfterburnerSpeed() - cpu->set_speed));
} else if (inertial_flight_model) {
DirectThrust += Vector(0, 0, parent->limits.afterburn * per);
DirectThrust += Vector(0, 0, parent->afterburner.thrust * per);
}
if (parent == _Universe->AccessCockpit()->GetParent()) {
//printf("afterburn is %d\n",afterburn); // DELETEME WTF all this force feedback code and its unused.
Expand All @@ -254,22 +254,22 @@ void FlyByWire::MatchSpeed(const Vector &vec) {
Computer *cpu = &parent->GetComputerData();

cpu->set_speed = (vec).Magnitude();
if (cpu->set_speed > cpu->max_speed()) {
cpu->set_speed = cpu->max_speed();
if (cpu->set_speed > parent->MaxSpeed()) {
cpu->set_speed = parent->MaxSpeed();
}
}

void FlyByWire::Accel(float per) {
Computer *cpu = &parent->GetComputerData();

cpu->set_speed += per * cpu->max_speed() * simulation_atom_var; //SIMULATION_ATOM?
if (cpu->set_speed > cpu->max_speed()) {
cpu->set_speed = cpu->max_speed();
cpu->set_speed += per * parent->MaxSpeed() * simulation_atom_var; //SIMULATION_ATOM?
if (cpu->set_speed > parent->MaxSpeed()) {
cpu->set_speed = parent->MaxSpeed();
}
static float reverse_speed_limit =
XMLSupport::parse_float(vs_config->getVariable("physics", "reverse_speed_limit", "1.0"));
if (cpu->set_speed < -cpu->max_speed() * reverse_speed_limit) {
cpu->set_speed = -cpu->max_speed() * reverse_speed_limit;
if (cpu->set_speed < -parent->MaxSpeed() * reverse_speed_limit) {
cpu->set_speed = -parent->MaxSpeed() * reverse_speed_limit;
}
afterburn = false;

Expand All @@ -279,30 +279,30 @@ void FlyByWire::Accel(float per) {
#define FBWABS(m) (m >= 0 ? m : -m)

void FlyByWire::ThrustRight(float percent) {
DesiredShiftVelocity.i = parent->GetComputerData().max_speed() * percent;
DesiredShiftVelocity.i = parent->MaxSpeed() * percent;
}

void FlyByWire::ThrustUp(float percent) {
DesiredShiftVelocity.j = parent->GetComputerData().max_speed() * percent;
DesiredShiftVelocity.j = parent->MaxSpeed() * percent;
}

void FlyByWire::ThrustFront(float percent) {
DesiredShiftVelocity.k = parent->GetComputerData().max_speed() * percent;
DesiredShiftVelocity.k = parent->MaxSpeed() * percent;
}

void FlyByWire::DirectThrustRight(float percent) {
DirectThrust.i = parent->limits.lateral * percent;
DirectThrust.i = parent->drive.lateral * percent;
}

void FlyByWire::DirectThrustUp(float percent) {
DirectThrust.j = parent->limits.vertical * percent;
DirectThrust.j = parent->drive.vertical * percent;
}

void FlyByWire::DirectThrustFront(float percent) {
if (percent > 0) {
DirectThrust.k = parent->limits.forward * percent;
DirectThrust.k = parent->drive.forward * percent;
} else {
DirectThrust.k = parent->limits.retro * percent;
DirectThrust.k = parent->drive.retro * percent;
}
}

Expand All @@ -312,8 +312,8 @@ void FlyByWire::Execute() {
if (!inertial_flight_model) {
//Must translate the thrust values to velocities, which is somewhat cumbersome.
Vector Limit(
parent->limits.lateral, parent->limits.vertical,
((DirectThrust.k > 0) ? parent->limits.forward : parent->limits.retro)
parent->drive.lateral, parent->drive.vertical,
((DirectThrust.k > 0) ? parent->drive.forward : parent->drive.retro)
);
if (Limit.i <= 1) {
Limit.i = 1;
Expand All @@ -330,7 +330,7 @@ void FlyByWire::Execute() {
DirectThrust.k / Limit.k
);
//Now, scale so that maximum shift velocity is max_speed
DesiredDrift *= parent->GetComputerData().max_speed();
DesiredDrift *= parent->MaxSpeed();
//And apply
DesiredShiftVelocity += DesiredDrift;
}
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/ai/flyjoystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void FlyByJoystick::Execute() {
float(expamountc * (exp(expfactorc * axis_value) - 1) / norm
+ pamountc * pow(axis_value, pfactorc));
}
cpu->set_speed = axis_value * cpu->max_speed();
cpu->set_speed = axis_value * parent->MaxSpeed();
desired_velocity = Vector(0, 0, cpu->set_speed);
}
}
Expand Down
28 changes: 13 additions & 15 deletions engine/src/cmd/ai/hard_coded_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void BarrelRoll(Order *aisc, Unit *un) {
bool afterburn = useAfterburner();
broll->MatchSpeed(Vector(0,
0,
afterburn ? un->GetComputerData().max_ab_speed() : un->GetComputerData().max_speed()));
afterburn ? un->MaxAfterburnerSpeed() : un->MaxSpeed()));
broll->Afterburn(afterburn);
}

Expand All @@ -246,7 +246,7 @@ static void EvadeWavy(Order *aisc, Unit *un, bool updown, bool ab) {
bool afterburn = ab && useAfterburner();
broll->MatchSpeed(Vector(0,
0,
afterburn ? un->GetComputerData().max_ab_speed() : un->GetComputerData().max_speed()));
afterburn ? un->MaxAfterburnerSpeed() : un->MaxSpeed()));
broll->Afterburn(afterburn);
}

Expand Down Expand Up @@ -330,11 +330,10 @@ class LoopAround : public Orders::FaceTargetITTS {
Vector r = targ->cumulative_transformation_matrix.getR();
bool afterburn = useAfterburner() && this->afterburn;
bool ab_needed =
force_afterburn || targ->GetVelocity().MagnitudeSquared() > parent->GetComputerData().max_speed();
force_afterburn || targ->GetVelocity().MagnitudeSquared() > parent->MaxSpeed();
m.SetDesiredVelocity(Vector(0, 0, afterburn
&& ab_needed ? parent->GetComputerData().max_ab_speed()
: parent->GetComputerData().
max_speed()), true);
&& ab_needed ? parent->MaxAfterburnerSpeed()
: parent->MaxSpeed()), true);
float spseed, grange = 0, mrange = 0;
parent->getAverageGunSpeed(spseed, grange, mrange);
if (r.Dot(relloc) < 0) {
Expand Down Expand Up @@ -429,7 +428,7 @@ class LoopAroundAgro : public Orders::FaceTargetITTS {
Vector r = targ->cumulative_transformation_matrix.getR();
bool afterburn = useAfterburner() && this->afterburn;
bool ab_needed =
force_afterburn || targ->GetVelocity().MagnitudeSquared() > parent->GetComputerData().max_speed();
force_afterburn || targ->GetVelocity().MagnitudeSquared() > parent->MaxSpeed();
if (r.Dot(relloc) < 0) {
FaceTargetITTS::Execute();
m.SetAfterburn(afterburn && ab_needed);
Expand Down Expand Up @@ -530,11 +529,10 @@ class FacePerpendicular : public Orders::FaceTargetITTS {
Vector r = targ->cumulative_transformation_matrix.getR();
bool afterburn = useAfterburner() && this->afterburn;
bool ab_needed =
force_afterburn || targ->GetVelocity().MagnitudeSquared() > parent->GetComputerData().max_speed();
force_afterburn || targ->GetVelocity().MagnitudeSquared() > parent->MaxSpeed();
m.SetDesiredVelocity(Vector(0, 0, afterburn
&& ab_needed ? parent->GetComputerData().max_ab_speed()
: parent->GetComputerData().
max_speed()), true);
&& ab_needed ? parent->MaxAfterburnerSpeed()
: parent->MaxSpeed()), true);
float speed, grange = 0, mrange = 0;
parent->getAverageGunSpeed(speed, grange, mrange);
if (r.Dot(relloc) < 0) {
Expand Down Expand Up @@ -585,15 +583,15 @@ void RollLeft(Order *aisc, Unit *un) {
if (un->aistate) {
AddOrd(un->aistate,
un,
new Orders::ExecuteFor(new Orders::MatchRoll(un->GetComputerData().max_roll_right, false), 1.0f));
new Orders::ExecuteFor(new Orders::MatchRoll(un->drive.max_roll_right, false), 1.0f));
}
}

void RollRight(Order *aisc, Unit *un) {
if (un->aistate) {
AddOrd(un->aistate,
un,
new Orders::ExecuteFor(new Orders::MatchRoll(-un->GetComputerData().max_roll_left, false), 1.0f));
new Orders::ExecuteFor(new Orders::MatchRoll(-un->drive.max_roll_left, false), 1.0f));
}
}

Expand All @@ -602,7 +600,7 @@ void RollLeftHard(Order *aisc, Unit *un) {
if (un->aistate) {
AddOrd(un->aistate,
un,
new Orders::ExecuteFor(new Orders::MatchRoll(un->GetComputerData().max_roll_right, false), durvar));
new Orders::ExecuteFor(new Orders::MatchRoll(un->drive.max_roll_right, false), durvar));
}
}

Expand All @@ -611,7 +609,7 @@ void RollRightHard(Order *aisc, Unit *un) {
if (un->aistate) {
AddOrd(un->aistate,
un,
new Orders::ExecuteFor(new Orders::MatchRoll(-un->GetComputerData().max_roll_left, false), durvar));
new Orders::ExecuteFor(new Orders::MatchRoll(-un->drive.max_roll_left, false), durvar));
}
}

Expand Down
Loading
Loading