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] Implement radar code as a separate component #804

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions 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,11 @@ SET(LIBRESOURCE
src/resource/product.cpp
)

SET(LIBCOMPONENT
src/components/component.cpp
src/components/radar.cpp
)

SET(LIBGUI_SOURCES
src/gui/button.cpp
src/gui/control.cpp
Expand Down Expand Up @@ -827,6 +834,7 @@ SET(LIBCMD_SOURCES

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

src/cmd/planetary_orbit.cpp

Expand Down Expand Up @@ -1058,6 +1066,7 @@ ADD_LIBRARY(vegastrike-engine_com
${LIBCONFIG}
${LIBDAMAGE}
${LIBRESOURCE}
${LIBCOMPONENT}
${LIBAI_SOURCES}
${LIBCMD_SOURCES}
${LIBNET_SOURCES}
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/ai/aggressive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,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
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: 5 additions & 5 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 @@ -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
14 changes: 6 additions & 8 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 @@ -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
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
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();
}
}

23 changes: 11 additions & 12 deletions engine/src/cmd/armed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void Armed::ActivateGuns(const WeaponInfo *sz, bool ms) {
void Armed::Fire(unsigned int weapon_type_bitmask, bool listen_to_owner) {
Unit *unit = static_cast<Unit *>(this);

if ((unit->cloaking >= 0 && !configuration()->weapons.can_fire_in_cloak) ||
if ((unit->cloak.Active() && !configuration()->weapons.can_fire_in_cloak) ||
(unit->graphicOptions.InWarp && !configuration()->weapons.can_fire_in_spec)) {
UnFire();
return;
Expand Down Expand Up @@ -324,13 +324,7 @@ int Armed::LockMissile() const {
return missilelock ? 1 : (dumblock ? -1 : 0);
}

void Armed::LockTarget(bool myboo) {
Unit *unit = static_cast<Unit *>(this);
unit->computer.radar.locked = myboo;
if (myboo && unit->computer.radar.canlock == false && false == UnitUtil::isSignificant(unit->Target())) {
unit->computer.radar.locked = false;
}
}


QVector Armed::PositionITTS(const QVector &absposit, Vector velocity, float speed, bool steady_itts) const {
const Unit *unit = static_cast<const Unit *>(this);
Expand Down Expand Up @@ -413,7 +407,7 @@ void Armed::setAverageGunSpeed() {

bool Armed::TargetLocked(const Unit *checktarget) const {
const Unit *unit = static_cast<const Unit *>(this);
if (!unit->computer.radar.locked) {
if (!unit->radar.locked) {
return false;
}
return (checktarget == NULL) || (unit->computer.target == checktarget);
Expand All @@ -423,19 +417,24 @@ bool Armed::TargetTracked(const Unit *checktarget) {
Unit *unit = static_cast<Unit *>(this);
static bool must_lock_to_autotrack = XMLSupport::parse_bool(
vs_config->getVariable("physics", "must_lock_to_autotrack", "true"));
bool we_do_track = unit->computer.radar.trackingactive

bool we_do_track = unit->radar.tracking_active
&& (!_Universe->isPlayerStarship(unit) || TargetLocked() || !must_lock_to_autotrack);
if (!we_do_track) {
return false;
}

if (checktarget == NULL) {
return true;
}

if (unit->computer.target != checktarget) {
return false;
}
float mycone = unit->computer.radar.trackingcone;

float mycone = unit->radar.tracking_cone;
we_do_track = CloseEnoughToAutotrack(unit, unit->computer.target.GetUnit(), mycone);

return we_do_track;
}

Expand All @@ -454,7 +453,7 @@ float Armed::TrackingGuns(bool &missilelock) {
missilelock = false;
for (int i = 0; i < getNumMounts(); ++i) {
if (mounts[i].status == Mount::ACTIVE && isAutoTrackingMount(mounts[i].size)) {
trackingcone = unit->computer.radar.trackingcone;
trackingcone = unit->radar.tracking_cone;
}
if (mounts[i].status == Mount::ACTIVE && mounts[i].type->lock_time > 0 && mounts[i].time_to_lock <= 0) {
missilelock = true;
Expand Down
2 changes: 0 additions & 2 deletions engine/src/cmd/armed.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ class Armed {
//-1 is no lock necessary 1 is locked
int LockMissile() const;

void LockTarget(bool myboo);

//Finds the position from the local position if guns are aimed at it with speed
QVector PositionITTS(const QVector &firingposit, Vector firingvelocity, float gunspeed, bool smooth_itts) const;

Expand Down
Loading