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

Draft - Lib Component #810

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2701083
Fix bug - Store::Subtract adds quantity instead of subtracting it
royfalk Jan 23, 2023
7e0e45f
Merge from master
royfalk Feb 3, 2023
0cb1a73
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Apr 25, 2023
c6dba50
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk May 30, 2023
b2d8681
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Jul 30, 2023
8668683
Refactor cloaking in the game
royfalk Aug 31, 2023
e38f3fa
Move cloak code from unit_csv to cloak class
royfalk Oct 10, 2023
0dd2465
Add missing return statement
royfalk Oct 11, 2023
e74dd23
Merge branch 'task_aug_unit' into task_almost_september
royfalk Oct 17, 2023
c663324
Implement radar code as a separate component
royfalk Oct 17, 2023
7c357ba
Fix bug in the radar where small ships are not tracked.
royfalk Oct 26, 2023
474e401
Merge branch 'task_almost_september' into task_october
royfalk Oct 26, 2023
9d5551e
Introduce lib_component
royfalk Nov 10, 2023
2c0e12b
Refactor resource class
royfalk Mar 12, 2024
fec840e
Introduce armor hull and shield components
royfalk Mar 22, 2024
f509220
Move regeneration from health to shield
royfalk Mar 24, 2024
a4a8a7d
Further work on Armor class
royfalk Mar 26, 2024
ab8538a
Make Shield a super class of DamageableLayer
royfalk Mar 27, 2024
799a732
Make armor class a superclass of DamageableLayer
royfalk Mar 29, 2024
77d3dab
Make Hull a superclass of DamageableLayer
royfalk Mar 29, 2024
019b507
Add fuel component
royfalk Apr 10, 2024
7f53ea9
Implement afterburners and Drive
royfalk Apr 18, 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
29 changes: 28 additions & 1 deletion engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ INCLUDE_DIRECTORIES(
${Vega_Strike_SOURCE_DIR}/src/cmd
${Vega_Strike_SOURCE_DIR}/src/damage
${Vega_Strike_SOURCE_DIR}/src/resource
${Vega_Strike_SOURCE_DIR}/src/components
${Vega_Strike_BINARY_DIR}
)
ELSE (MSVC)
Expand All @@ -134,6 +135,7 @@ INCLUDE_DIRECTORIES(
${Vega_Strike_SOURCE_DIR}/src/cmd
${Vega_Strike_SOURCE_DIR}/src/damage
${Vega_Strike_SOURCE_DIR}/src/resource
${Vega_Strike_SOURCE_DIR}/src/components
${Vega_Strike_BINARY_DIR}
/usr/include/harfbuzz/
)
Expand Down Expand Up @@ -657,6 +659,26 @@ SET(LIBRESOURCE
src/resource/product.cpp
)

SET(LIBCOMPONENT
src/components/component.cpp
src/components/energy_types.cpp

src/components/armor.cpp
src/components/hull.cpp
src/components/shield.cpp

src/components/afterburner.cpp
src/components/cloak.cpp
src/components/drive.cpp
src/components/energy_consumer.cpp
src/components/energy_container.cpp
src/components/energy_manager.cpp
src/components/fuel.cpp
src/components/jump_drive.cpp
src/components/radar.cpp
src/components/reactor.cpp
)

SET(LIBGUI_SOURCES
src/gui/button.cpp
src/gui/control.cpp
Expand Down Expand Up @@ -826,7 +848,7 @@ SET(LIBCMD_SOURCES
src/cmd/computer.cpp

src/cmd/intelligent.cpp
src/cmd/energetic.cpp


src/cmd/planetary_orbit.cpp

Expand Down Expand Up @@ -1058,6 +1080,7 @@ ADD_LIBRARY(vegastrike-engine_com
${LIBCONFIG}
${LIBDAMAGE}
${LIBRESOURCE}
${LIBCOMPONENT}
${LIBAI_SOURCES}
${LIBCMD_SOURCES}
${LIBNET_SOURCES}
Expand Down Expand Up @@ -1619,12 +1642,16 @@ IF (USE_GTEST)
src/resource/tests/buy_sell.cpp
src/resource/tests/resource_test.cpp
src/exit_unit_tests.cpp
src/components/tests/energy_container_tests.cpp
src/components/tests/balancing_tests.cpp
src/components/tests/armor_tests.cpp
)

ADD_LIBRARY(vegastrike-testing
${LIBCONFIG}
${LIBDAMAGE}
${LIBRESOURCE}
${LIBCOMPONENT}
${LIBCMD_SOURCES}
${LIBVS_LOGGING}
)
Expand Down
13 changes: 7 additions & 6 deletions engine/src/cmd/ai/aggressive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "docking.h"
#include "star_system.h"
#include "universe.h"
#include "jump_capable.h"

extern double aggfire;

Expand Down Expand Up @@ -1292,7 +1293,7 @@ static Unit *ChooseNavPoint(Unit *parent, Unit **otherdest, float *lurk_on_arriv
int whichlist = 1; //friendly
std::string fgname = UnitUtil::getFlightgroupName(parent);

bool insys = (parent->GetJumpStatus().drive == -2) || fgname.find(insysString) != std::string::npos;
bool insys = (parent->jump.drive == -2) || fgname.find(insysString) != std::string::npos;
royfalk marked this conversation as resolved.
Show resolved Hide resolved
std::string::size_type whereconvoy = fgname.find(arrowString);
bool convoy = (whereconvoy != std::string::npos);
size_t total_size = stats->navs[0].size() + stats->navs[whichlist].size(); //friendly and neutral
Expand Down Expand Up @@ -1325,7 +1326,7 @@ static Unit *ChooseNavPoint(Unit *parent, Unit **otherdest, float *lurk_on_arriv
if (a != b) {
int retrycount = maxrand;
while (--retrycount > 0
&& (UnitUtil::getDistance(a, b) < parent->GetComputerData().radar.maxrange * 4 || a == b)) {
&& (UnitUtil::getDistance(a, b) < parent->radar.GetMaxRange() * 4 || a == b)) {
b = GetRandomNav(stats->navs, additionalrand[retrycount]);
}
if (retrycount != 0) {
Expand Down Expand Up @@ -1640,9 +1641,9 @@ void AggressiveAI::Execute() {
bool isjumpable = target ? (!target->GetDestinations().empty()) : false;
if (!ProcessCurrentFgDirective(fg)) {
if (isjumpable) {
if (parent->GetJumpStatus().drive < 0) {
if (parent->jump.drive < 0) {
parent->ActivateJumpDrive(0);
if (parent->GetJumpStatus().drive == -2) {
if (parent->jump.drive == -2) {
static bool AIjumpCheat =
XMLSupport::parse_bool(vs_config->getVariable("AI",
"always_have_jumpdrive_cheat",
Expand All @@ -1657,7 +1658,7 @@ void AggressiveAI::Execute() {
} else {
parent->Target(NULL);
}
} else if (parent->GetJumpStatus().drive < 0) {
} else if (parent->jump.drive < 0) {
static bool
AIjumpCheat = XMLSupport::parse_bool(vs_config->getVariable("AI", "jump_cheat", "true"));
if (AIjumpCheat) {
Expand Down Expand Up @@ -1733,7 +1734,7 @@ void AggressiveAI::Execute() {

isjumpable = target ? (!target->GetDestinations().empty()) : false;
if (!isjumpable) {
if (parent->GetJumpStatus().drive >= 0) {
if (parent->jump.drive >= 0) {
parent->ActivateJumpDrive(-1);
}
}
Expand Down
4 changes: 2 additions & 2 deletions engine/src/cmd/ai/comm_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ Unit *CommunicatingAI::GetRandomUnit(float playaprob, float targprob) {
}
//FIXME FOR TESTING ONLY
//return parent->Target();
QVector where = parent->Position() + parent->GetComputerData().radar.maxrange * QVector(vsrandom.uniformInc(-1, 1),
QVector where = parent->Position() + parent->radar.GetMaxRange() * QVector(vsrandom.uniformInc(-1, 1),
vsrandom.uniformInc(-1, 1),
vsrandom.uniformInc(-1, 1));
Collidable wherewrapper(0, 0, where);
Expand Down Expand Up @@ -393,7 +393,7 @@ void CommunicatingAI::RandomInitiateCommunication(float playaprob, float targpro
if (target != NULL) {
if (UnitUtil::getUnitSystemFile(target) == UnitUtil::getUnitSystemFile(parent)
&& UnitUtil::getFlightgroupName(parent) != "Base" && !isDockedAtAll(target)
&& UnitUtil::getDistance(parent, target) <= target->GetComputerData().radar.maxrange) {
&& UnitUtil::getDistance(parent, target) <= target->radar.GetMaxRange()) {
//warning--odd hack they can talk to you if you can sense them--it's like SETI@home
for (std::list<CommunicationMessage *>::iterator i = messagequeue.begin(); i != messagequeue.end(); i++) {
Unit *un = (*i)->sender.GetUnit();
Expand Down
10 changes: 2 additions & 8 deletions engine/src/cmd/ai/docking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,7 @@ bool DockingOps::DockToTarget(Unit *utdw) {
if (physicallyDock) {
return parent->Dock(utdw);
} else {
float maxWillingToRefill = utdw->warpCapData();
if (maxWillingToRefill >= MinimumCapacityToRefuelOnLand) {
parent->refillWarpEnergy();
} //BUCO! This needs its own units.csv column to see how much we refill!
utdw->ftl_energy.Refill();
return true;
}
} else if (diss <= 1.2 * rad * rad) {
Expand All @@ -219,10 +216,7 @@ bool DockingOps::DockToTarget(Unit *utdw) {
if (physicallyDock) {
return parent->Dock(utdw);
} else {
float maxWillingToRefill = utdw->warpCapData();
if (maxWillingToRefill >= MinimumCapacityToRefuelOnLand) {
parent->refillWarpEnergy();
} //BUCO! This needs its own units.csv column to see how much we refill!
parent->ftl_energy.Refill();
return true;
}
}
Expand Down
12 changes: 6 additions & 6 deletions engine/src/cmd/ai/fire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ class ChooseTargetClass {
}

bool ShouldTargetUnit(Unit *un, float distance) {
if (un->CloakVisible() > .8) {
if (un->cloak.Visible()) {
float rangetotarget = distance;
float rel0 = parent->getRelation(un);
float rel[] = {
Expand Down Expand Up @@ -577,7 +577,7 @@ void FireAt::ChooseTargets(int numtargs, bool force) {
"Targetting",
"search_max_candidates",
"64")); //Cutoff candidate count (if that many hostiles found, stop search - performance/quality tradeoff, 0=no cutoff)
UnitWithinRangeLocator<ChooseTargetClass<2> > unitLocator(parent->GetComputerData().radar.maxrange, unitRad);
UnitWithinRangeLocator<ChooseTargetClass<2> > unitLocator(parent->radar.GetMaxRange(), unitRad);
StaticTuple<float, 2> maxranges{};

maxranges[0] = gunrange;
Expand Down Expand Up @@ -629,7 +629,7 @@ void FireAt::ChooseTargets(int numtargs, bool force) {
for (vector<TurretBin>::iterator k = tbin.begin(); k != tbin.end(); ++k) {
k->AssignTargets(my_target, parent->cumulative_transformation_matrix);
}
parent->LockTarget(false);
parent->radar.Unlock();
if (wasnull) {
if (mytarg) {
nextframenumpollers[hastarg] += 2;
Expand Down Expand Up @@ -657,7 +657,7 @@ void FireAt::ChooseTargets(int numtargs, bool force) {
}
}
parent->Target(mytarg);
parent->LockTarget(true);
parent->radar.Lock();
SignalChosenTarget();
}

Expand Down Expand Up @@ -773,7 +773,7 @@ bool FireAt::isJumpablePlanet(Unit *targ) {
bool istargetjumpableplanet = targ->isUnit() == Vega_UnitType::planet;
if (istargetjumpableplanet) {
istargetjumpableplanet =
(!((Planet *) targ)->GetDestinations().empty()) && (parent->GetJumpStatus().drive >= 0);
(!((Planet *) targ)->GetDestinations().empty()) && (parent->jump.drive >= 0);
}
return istargetjumpableplanet;
}
Expand Down Expand Up @@ -841,7 +841,7 @@ void FireAt::Execute() {
bool istargetjumpableplanet = false;
if ((targ = parent->Target())) {
istargetjumpableplanet = isJumpablePlanet(targ);
if (targ->CloakVisible() > .8 && !targ->Destroyed()) {
if (targ->cloak.Visible() && !targ->Destroyed()) {
had_target = true;
if (parent->getNumMounts() > 0) {
if (!istargetjumpableplanet) {
Expand Down
24 changes: 12 additions & 12 deletions engine/src/cmd/ai/firekeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ extern bool toggle_pause();
FireKeyboard::FireKeyboard(unsigned int whichplayer, unsigned int whichjoystick) : Order(WEAPON, 0) {
memset(savedTargets, 0, sizeof(void *) * NUMSAVEDTARGETS);
this->autotrackingtoggle = 1;
this->cloaktoggle = true;
this->whichjoystick = whichjoystick;
this->whichplayer = whichplayer;
gunspeed = gunrange = .0001;
Expand Down Expand Up @@ -1732,7 +1731,7 @@ void FireKeyboard::Execute() {

float f_result = f().shieldpowerstate;
if (f_result != 1) {
parent->shield->AdjustPower(f_result);
parent->shield->SetPower(f_result);
}
if (f().firekey == PRESS || f().jfirekey == PRESS || j().firekey == DOWN || j().jfirekey == DOWN) {
if (!_Universe->AccessCockpit()->CanDrawNavSystem()) {
Expand Down Expand Up @@ -1779,12 +1778,11 @@ void FireKeyboard::Execute() {
}
if (f().cloakkey == PRESS) {
f().cloakkey = DOWN;
parent->Cloak(cloaktoggle);
cloaktoggle = !cloaktoggle;
parent->cloak.Toggle();
}
if (f().lockkey == PRESS) {
f().lockkey = DOWN;
parent->LockTarget(!parent->TargetLocked());
parent->radar.ToggleLock();
}
if (f().ECMkey == PRESS) {
f().ECMkey = DOWN;
Expand Down Expand Up @@ -1815,7 +1813,7 @@ void FireKeyboard::Execute() {
f().targetskey = DOWN;
ChooseTargets(parent, TargSig, false);
refresh_target = true;
parent->LockTarget(true);
parent->radar.Lock();
}
if (f().targetukey == PRESS) {
f().targetukey = DOWN;
Expand Down Expand Up @@ -1896,7 +1894,7 @@ void FireKeyboard::Execute() {
f().rtargetskey = DOWN;
ChooseTargets(parent, TargSig, true);
refresh_target = true;
parent->LockTarget(true);
parent->radar.Lock();
}
if (f().rtargetukey == PRESS) {
f().rtargetukey = DOWN;
Expand Down Expand Up @@ -2034,7 +2032,7 @@ void FireKeyboard::Execute() {
}
if (f().toggleautotracking == PRESS) {
f().toggleautotracking = DOWN;
parent->GetComputerData().radar.trackingactive = !parent->GetComputerData().radar.trackingactive;
parent->radar.ToggleTracking();
}
if (f().misk == PRESS || f().rmisk == PRESS) {
bool forward;
Expand All @@ -2060,7 +2058,7 @@ void FireKeyboard::Execute() {
f().saveTargetKeys[i] = RELEASE;
savedTargets[i] = parent->Target();
}
if (f().restoreTargetKeys[i] == PRESS && parent->GetComputerData().radar.canlock) {
if (f().restoreTargetKeys[i] == PRESS && parent->radar.CanLock()) {
f().restoreTargetKeys[i] = RELEASE;
Unit *un;
for (un_iter u = _Universe->activeStarSystem()->getUnitList().createIterator();
Expand Down Expand Up @@ -2178,9 +2176,11 @@ void FireKeyboard::Execute() {
cp->EjectDock();
} //use specialized ejectdock in the future
}
static bool actually_arrest = XMLSupport::parse_bool(vs_config->getVariable("AI", "arrest_energy_zero", "false"));
if (actually_arrest && parent->energyRechargeData() == 0) {

// TODO: something with this. It's very unlikely reactor will be 0
/*static bool actually_arrest = XMLSupport::parse_bool(vs_config->getVariable("AI", "arrest_energy_zero", "false"));
if (actually_arrest && parent->energy_manager.GetReactorCapacity() == 0) {
Arrested(parent);
}
}*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this was put in for a story line. If so, we should find a different way to implement it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if they did, if we run out of reactor before we get to a base, life support goes out and we die (to be implemented). This straight out doesn't make sense on any level.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is one of those "fence" situations. I would like to ask some of the long-term project members whether they remember what this code was for.

}

1 change: 0 additions & 1 deletion engine/src/cmd/ai/firekeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#define NUMSAVEDTARGETS 10
class FireKeyboard : public Order {
bool itts;
bool cloaktoggle;
bool refresh_target;
float gunspeed;
float gunrange;
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/ai/flykeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ void FlyByKeyboard::Execute(bool resetangvelocity) {
if ((counter - last_jumped) > static_cast<unsigned>(jump_key_delay / SIMULATION_ATOM) || last_jumped == 0) {
last_jumped = counter;
parent->ActivateJumpDrive();
if (parent->GetJumpStatus().drive >= 0) {
if (parent->jump.drive >= 0) {
static soundContainer foobar;
if (foobar.sound == -2) {
static string str = vs_config->getVariable("cockpitaudio", "jump_engaged", "jump");
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/ai/ikarus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void Ikarus::Execute() {
DecideTarget();
if (!ProcessCurrentFgDirective(fg)) {
Unit *target = parent->Target();
bool isjumpable = target ? ((!target->GetDestinations().empty()) && parent->GetJumpStatus().drive >= 0) : false;
bool isjumpable = target ? ((!target->GetDestinations().empty()) && parent->jump.drive >= 0) : false;
if (isjumpable) {
AfterburnTurnTowards(this, parent);
} else {
Expand Down
6 changes: 3 additions & 3 deletions engine/src/cmd/ai/tactics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

void CloakFor::Execute() {
if (time == 0) {
parent->Cloak(enable);
parent->cloak.Activate();
}
time += SIMULATION_ATOM;
if (time > maxtime) {
done = true;
if (maxtime != 0) {
parent->Cloak(!enable);
parent->cloak.Deactivate();
}
return;
}
Expand All @@ -48,7 +48,7 @@ CloakFor::~CloakFor() {
VS_LOG_AND_FLUSH(trace, (boost::format("clk%1$x") % this));
#endif
if (parent && time <= maxtime) {
parent->Cloak(!enable);
parent->cloak.Deactivate();
}
}

4 changes: 3 additions & 1 deletion engine/src/cmd/ai/warpto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ static void ActuallyWarpTo(Unit *parent, const QVector &tarpos, Vector tarvel, U
dir *= -1;
float chasedot = dir.Dot(tarvel);
if (dirveldot > mindirveldot) {
// TODO: this needs to be factored for mass and consumption.
// 0.33 and 1.5 are low values for larger ships
static float min_energy_to_enter_warp =
XMLSupport::parse_float(vs_config->getVariable("AI", "min_energy_to_enter_warp", ".33"));
static float min_warpfield_to_enter_warp =
XMLSupport::parse_float(vs_config->getVariable("AI", "min_warp_to_try", "1.5"));
if ((parent->warpEnergyData() > min_energy_to_enter_warp)
if ((parent->ftl_energy.Percent() > min_energy_to_enter_warp)
&& (parent->GetMaxWarpFieldStrength(1) > min_warpfield_to_enter_warp)) {
if (parent->graphicOptions.InWarp == 0) {
parent->graphicOptions.InWarp = 1; //don't want the AI thrashing
Expand Down
Loading