Skip to content

Commit

Permalink
Move cloak code from unit_csv to cloak class
Browse files Browse the repository at this point in the history
Add missing return.
Other minor fixes.
  • Loading branch information
royfalk committed Oct 10, 2023
1 parent 8668683 commit e38f3fa
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 22 deletions.
9 changes: 9 additions & 0 deletions engine/src/cmd/cloak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ Cloak::Cloak(std::string unit_key)
current = 0;
}

void Cloak::Save(std::map<std::string, std::string>& unit)
{
unit["Cloak_Min"] = std::to_string(minimum);
unit["Can_Cloak"] = std::to_string(Capable());
unit["Cloak_Rate"] = std::to_string(rate);
unit["Cloak_Energy"] = std::to_string(energy);
unit["Cloak_Glass"] = std::to_string(glass);
}

void Cloak::Update(Energetic *energetic)
{
// Unit is not capable of cloaking or damaged or just not cloaking
Expand Down
19 changes: 13 additions & 6 deletions engine/src/cmd/cloak.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define CLOAK_H

#include <string>
#include <map>

#include "energetic.h"
#include "damageable_layer.h"
Expand Down Expand Up @@ -64,6 +65,7 @@ class Cloak
public:
Cloak();
Cloak(std::string unit_key);
void Save(std::map<std::string, std::string>& unit);

void Update(Energetic *energetic);
void Toggle(); // Toggle cloak on/off
Expand All @@ -76,7 +78,7 @@ class Cloak
return (status == CloakingStatus::cloaking);
}

bool Cloaked() {
bool Cloaked() const {
return (status == CloakingStatus::cloaked);
}

Expand All @@ -99,16 +101,21 @@ class Cloak
return glass;
}

double Current() {
return current;
}

double Energy() {
return energy;
}

// Is the ship visible
bool Visible() {
return !Cloaked();
}

double Current() const {
return current;
}

//how visible the ship is from 0 to 1
double Visible() const {
double Visibility() const {
return 1-current;
}

Expand Down
4 changes: 2 additions & 2 deletions engine/src/cmd/drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ void Drawable::DrawNow(const Matrix &mato, float lod) {
if (!(unit->docked & (unit->DOCKED | unit->DOCKED_INSIDE))) {
halos->Draw(mat,
Scale,
unit->cloak.Visible(),
unit->cloak.Visibility(),
0,
unit->GetHullPercent(),
velocity,
Expand Down Expand Up @@ -735,7 +735,7 @@ void Drawable::DrawHalo(bool on_screen, float apparent_size, Matrix wmat, Cloak
//nor is maxaccel. Instead, each halo should have its own limits specified in units.csv
float nebd = (_Universe->AccessCamera()->GetNebula() == unit->nebula && unit->nebula != nullptr) ? -1 : 0;
float hulld = unit->GetHull() > 0 ? damage_level : 1.0;
halos->Draw(wmat, Scale, unit->cloak.Visible(), nebd, hulld, velocity,
halos->Draw(wmat, Scale, unit->cloak.Visibility(), nebd, hulld, velocity,
linaccel, angaccel, maxaccel, cmas, unit->faction);

}
Expand Down
7 changes: 1 addition & 6 deletions engine/src/cmd/unit_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1365,12 +1365,7 @@ string Unit::WriteUnitString() {
unit["Max_Cone"] = tos(acos(computer.radar.maxcone) * 180. / VS_PI);
unit["Lock_Cone"] = tos(acos(computer.radar.lockcone) * 180. / VS_PI);

// TODO: move to Cloak
unit["Cloak_Min"] = tos(cloak.minimum);
unit["Can_Cloak"] = tos(cloak.Capable());
unit["Cloak_Rate"] = tos(cloak.rate);
unit["Cloak_Energy"] = tos(cloak.energy);
unit["Cloak_Glass"] = tos(cloak.glass);
cloak.Save(unit);
unit["Repair_Droid"] = tos(repair_droid);
unit["ECM_Rating"] = tos(ecm > 0 ? ecm : -ecm);
unit["Hud_Functionality"] = WriteHudDamage(this);
Expand Down
7 changes: 5 additions & 2 deletions engine/src/cmd/unit_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void Unit::SetNebula(Nebula *neb) {
bool Unit::InRange(const Unit *target, double &mm, bool cone, bool cap, bool lock) const {
const float capship_size = configuration()->physics_config.capship_size;

if (this == target || !target->cloak.Visible()) {
if (this == target || target->cloak.Cloaked()) {
return false;
}
if (cone && computer.radar.maxcone > -.98) {
Expand Down Expand Up @@ -3335,7 +3335,10 @@ bool Unit::UpAndDownGrade(const Unit *up,
++numave;
++percentage;
if (gen_downgrade_list) {
AddToDowngradeMap(up->name, up->cloak.current, ((char *) &this->cloak.current) - ((char *) this), tempdownmap);
AddToDowngradeMap(up->name,
up->cloak.current,
((char *) &this->cloak.current) - ((char *) this),
tempdownmap);
}
}
//NOTE: Afterburner type 2 (jmp)
Expand Down
4 changes: 2 additions & 2 deletions engine/src/cmd/unit_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ class Unit : public Armed, public Audible, public Drawable, public Damageable, p

// how visible the ship is from 0 to 1
// Need this function to expose it to python
float CloakVisible() const {
cloak.Visible();
float CloakVisible() {
cloak.Visibility();
}

//cloaks or decloaks the starship depending on the bool
Expand Down
6 changes: 3 additions & 3 deletions engine/src/gfx/mesh_gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,9 @@ void Mesh::Draw(float lod,
c.mesh_seq = 2; //MESH_SPECIAL_FX_ONLY;
} else {
c.mesh_seq = 2;
c.CloakFX.r = (1-cloak.Current());
c.CloakFX.g = (1-cloak.Current());
c.CloakFX.b = (1-cloak.Current());
c.CloakFX.r = cloak.Visibility();
c.CloakFX.g = cloak.Visibility();
c.CloakFX.b = cloak.Visibility();
c.CloakFX.a = cloak.Current();
}
}
Expand Down
2 changes: 1 addition & 1 deletion engine/src/resource/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Resource {
T adjusted_max_value_;
bool no_max_;
public:
Resource(const T &value, const T &min_value = 0, const T &max_value = -1);
Resource(const T &value = 0, const T &min_value = 0, const T &max_value = -1);

Resource<T> operator+=(const T &value);
Resource<T> operator-=(const T &value);
Expand Down

0 comments on commit e38f3fa

Please sign in to comment.