Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
royfalk committed Aug 15, 2024
2 parents 7fb35f5 + bff6ff3 commit ad5c297
Show file tree
Hide file tree
Showing 27 changed files with 466 additions and 221 deletions.
15 changes: 8 additions & 7 deletions engine/src/cmd/armed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "unit_util.h"
#include "vs_logging.h"
#include "resource/resource.h"
#include "vega_cast_utils.h"

#include <vector>

Expand Down Expand Up @@ -250,14 +251,14 @@ void Armed::Fire(unsigned int weapon_type_bitmask, bool listen_to_owner) {
//&& ( (ROLES::EVERYTHING_ELSE&weapon_type_bitmask&i->type->role_bits) || i->type->role_bits == 0 )
((locked_on && missile_and_want_to_fire_missiles) || gun_and_want_to_fire_guns);
if ((*i).type->type == WEAPON_TYPE::BEAM) {
if ((*i).type->energy_rate * simulation_atom_var > unit->energy) {
if ((*i).type->energy_rate * static_cast<double>(simulation_atom_var) > unit->energy.Level()) {
//NOT ONLY IN non-networking mode : anyway, the server will tell everyone including us to stop if not already done
(*i).UnFire();
continue;
}
} else
//Only in non-networking mode
if (i->type->energy_rate > unit->energy) {
if (i->type->energy_rate > unit->energy.Level()) {
if (!want_to_fire) {
i->UnFire();
}
Expand All @@ -277,11 +278,11 @@ void Armed::Fire(unsigned int weapon_type_bitmask, bool listen_to_owner) {
if (i->type->type == WEAPON_TYPE::BEAM) {
if (i->ref.gun) {
if ((!i->ref.gun->Dissolved()) || i->ref.gun->Ready()) {
unit->energy -= i->type->energy_rate * simulation_atom_var;
unit->energy.Deplete(true, i->type->energy_rate * static_cast<double>(simulation_atom_var));
}
}
} else if (i->type->isMissile()) { // FIXME other than beams, only missiles are processed here?
unit->energy -= i->type->energy_rate;
unit->energy.Deplete(true, i->type->energy_rate);
}
//IF WE REFRESH ENERGY FROM SERVER : Think to send the energy update to the firing client with ACK TO fireRequest
//fire only 1 missile at a time
Expand Down Expand Up @@ -333,7 +334,7 @@ void Armed::LockTarget(bool myboo) {
}

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

bool Armed::TargetLocked(const Unit *checktarget) const {
const Unit *unit = static_cast<const Unit *>(this);
const Unit *unit = vega_dynamic_cast_ptr<const Unit>(this);
if (!unit->computer.radar.locked) {
return false;
}
Expand Down Expand Up @@ -449,7 +450,7 @@ void Armed::ToggleWeapon(bool missile, bool forward) {
}

float Armed::TrackingGuns(bool &missilelock) {
const Unit *unit = static_cast<const Unit *>(this);
Unit *unit = vega_dynamic_cast_ptr<Unit>(this);
float trackingcone = 0;
missilelock = false;
for (int i = 0; i < getNumMounts(); ++i) {
Expand Down
1 change: 1 addition & 0 deletions engine/src/cmd/armed.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Armed {

public:
Armed();
virtual ~Armed() = default;

//Fires all active guns that are or arent Missiles
//if bitmask is (1<<31) then fire off autotracking of that type;
Expand Down
7 changes: 7 additions & 0 deletions engine/src/cmd/basecomputer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3656,6 +3656,7 @@ void BaseComputer::SellUpgradeOperation::selectMount(void) {
}

//Check, and verify user wants Sell Upgrade transaction. Returns true if more input is required.
// Only applies to mounts!
bool BaseComputer::SellUpgradeOperation::checkTransaction(void) {
Unit *playerUnit = m_parent.m_player.GetUnit();
if (!playerUnit) {
Expand All @@ -3675,6 +3676,7 @@ bool BaseComputer::SellUpgradeOperation::checkTransaction(void) {
}

//Finish the transaction.
// Only applies to mounts!
void BaseComputer::SellUpgradeOperation::concludeTransaction(void) {
Unit *playerUnit = m_parent.m_player.GetUnit();
Unit *baseUnit = m_parent.m_base.GetUnit();
Expand Down Expand Up @@ -3750,7 +3752,12 @@ bool BaseComputer::sellUpgrade(const EventCommandId &command, Control *control)
Unit *baseUnit = m_base.GetUnit();
if (baseUnit && playerUnit) {
playerUnit->SellCargo(item->GetName(), quantity, _Universe->AccessCockpit()->credits, sold, baseUnit);

// Old system
UnitUtil::RecomputeUnitUpgrades(playerUnit);

// New system
UpgradeOperationResult result = playerUnit->UpgradeUnit(item->GetName(), false, true);
refresh();
}
return true;
Expand Down
27 changes: 14 additions & 13 deletions engine/src/cmd/carrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "missile.h"
#include "vs_random.h"
#include "vs_logging.h"
#include "vega_cast_utils.h"

#include "json.h"

Expand Down Expand Up @@ -494,12 +495,12 @@ bool cargoIsUpgrade(const Cargo &c) {
}

float Carrier::getHiddenCargoVolume() const {
const Unit *unit = static_cast<const Unit *>(this);
const Unit *unit = vega_dynamic_cast_ptr<const Unit>(this);
return unit->HiddenCargoVolume;
}

bool Carrier::CanAddCargo(const Cargo &carg) const {
const Unit *unit = static_cast<const Unit *>(this);
const Unit *unit = vega_dynamic_cast_ptr<const Unit>(this);

//Always can, in this case (this accounts for some odd precision issues)
if ((carg.quantity == 0) || (carg.GetVolume() == 0)) {
Expand All @@ -523,17 +524,17 @@ bool Carrier::CanAddCargo(const Cargo &carg) const {

//The cargo volume of this ship when empty. Max cargo volume.
float Carrier::getEmptyCargoVolume(void) const {
const Unit *unit = static_cast<const Unit *>(this);
const Unit *unit = vega_dynamic_cast_ptr<const Unit>(this);
return unit->CargoVolume;
}

float Carrier::getEmptyUpgradeVolume(void) const {
const Unit *unit = static_cast<const Unit *>(this);
const Unit *unit = vega_dynamic_cast_ptr<const Unit>(this);
return unit->UpgradeVolume;
}

float Carrier::getCargoVolume(void) const {
const Unit *unit = static_cast<const Unit *>(this);
const Unit *unit = vega_dynamic_cast_ptr<const Unit>(this);
float result = 0.0;
for (unsigned int i = 0; i < unit->cargo.size(); ++i) {
if (!cargoIsUpgrade(unit->cargo[i])) {
Expand Down Expand Up @@ -567,7 +568,7 @@ float Carrier::PriceCargo(const std::string &s) {
}

float Carrier::getUpgradeVolume(void) const {
const Unit *unit = static_cast<const Unit *>(this);
const Unit *unit = vega_dynamic_cast_ptr<const Unit>(this);
float result = 0.0;
for (unsigned int i = 0; i < unit->cargo.size(); ++i) {
if (cargoIsUpgrade(unit->cargo[i])) {
Expand All @@ -583,7 +584,7 @@ Cargo &Carrier::GetCargo(unsigned int i) {
}

const Cargo &Carrier::GetCargo(unsigned int i) const {
const Unit *unit = static_cast<const Unit *>(this);
const Unit *unit = vega_dynamic_cast_ptr<const Unit>(this);
return unit->cargo[i];
}

Expand All @@ -609,15 +610,15 @@ void Carrier::GetSortedCargoCat(const std::string &cat, size_t &begin, size_t &e
// The game also crashed due to endless loop.
// I returned the code and now it works and I don't know why.
Cargo *Carrier::GetCargo(const std::string &s, unsigned int &i) {
const Unit *unit = static_cast<const Unit *>(this);
const Unit *unit = vega_dynamic_cast_ptr<const Unit>(this);
if (unit->GetCargo(s, i)) {
return &GetCargo(i);
}
return NULL;
}

const Cargo *Carrier::GetCargo(const std::string &s, unsigned int &i) const {
const Unit *unit = static_cast<const Unit *>(this);
const Unit *unit = vega_dynamic_cast_ptr<const Unit>(this);

static Hashtable<string, unsigned int, 2047> index_cache_table;
Unit *mpl = getMasterPartList();
Expand Down Expand Up @@ -670,12 +671,12 @@ const Cargo *Carrier::GetCargo(const std::string &s, unsigned int &i) const {
}

unsigned int Carrier::numCargo() const {
const Unit *unit = static_cast<const Unit *>(this);
const Unit *unit = vega_dynamic_cast_ptr<const Unit>(this);
return unit->cargo.size();
}

std::string Carrier::GetManifest(unsigned int i, Unit *scanningUnit, const Vector &oldspd) const {
const Unit *unit = static_cast<const Unit *>(this);
const Unit *unit = vega_dynamic_cast_ptr<const Unit>(this);

///FIXME somehow mangle string
string mangled = unit->cargo[i].name;
Expand All @@ -700,7 +701,7 @@ std::string Carrier::GetManifest(unsigned int i, Unit *scanningUnit, const Vecto
}

bool Carrier::SellCargo(unsigned int i, int quantity, float &creds, Cargo &carg, Unit *buyer) {
const Unit *unit = static_cast<const Unit *>(this);
Unit *unit = vega_dynamic_cast_ptr<Unit>(this);

if (i < 0 || i >= unit->cargo.size() || !buyer->CanAddCargo(unit->cargo[i])
|| unit->getMass() < unit->cargo[i].GetMass()) {
Expand All @@ -721,7 +722,7 @@ bool Carrier::SellCargo(unsigned int i, int quantity, float &creds, Cargo &carg,
}

bool Carrier::SellCargo(const std::string &s, int quantity, float &creds, Cargo &carg, Unit *buyer) {
const Unit *unit = static_cast<const Unit *>(this);
Unit *unit = vega_dynamic_cast_ptr<Unit>(this);

Cargo tmp;
tmp.name = s;
Expand Down
1 change: 1 addition & 0 deletions engine/src/cmd/carrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Carrier {
std::vector<Cargo> cargo;

Carrier();
virtual ~Carrier() = default;
void SortCargo();
static std::string cargoSerializer(const struct XMLType &input, void *mythis);

Expand Down
9 changes: 5 additions & 4 deletions engine/src/cmd/cloak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "unit_csv_factory.h"
#include "vegastrike.h"
#include "configuration/configuration.h"
#include "unit_generic.h"

Cloak::Cloak()
{
Expand Down Expand Up @@ -63,7 +64,7 @@ void Cloak::Save(std::map<std::string, std::string>& unit)
unit["Cloak_Glass"] = std::to_string(glass);
}

void Cloak::Update(Energetic *energetic)
void Cloak::Update(Unit *unit)
{
// Unit is not capable of cloaking or damaged or just not cloaking
if(status == CloakingStatus::disabled ||
Expand All @@ -74,7 +75,7 @@ void Cloak::Update(Energetic *energetic)

// Use warp power for cloaking (SPEC capacitor)
const static bool warp_energy_for_cloak = configuration()->warp_config.use_warp_energy_for_cloak;
double available_energy = warp_energy_for_cloak ? energetic->warpenergy : energetic->energy.Value();
double available_energy = warp_energy_for_cloak ? unit->ftl_energy.Level() : unit->energy.Level();


// Insufficient energy to cloak ship
Expand All @@ -83,9 +84,9 @@ void Cloak::Update(Energetic *energetic)
} else {
// Subtract the energy used
if (warp_energy_for_cloak) {
energetic->warpenergy -= (simulation_atom_var * energy);
unit->ftl_energy.Deplete(true, simulation_atom_var * energy);
} else {
energetic->energy -= (simulation_atom_var * energy);
unit->energy.Deplete(true, simulation_atom_var * energy);
}
}

Expand Down
5 changes: 4 additions & 1 deletion engine/src/cmd/cloak.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include "energetic.h"
#include "damageable_layer.h"

// TODO: remove dependency on unit
class Unit;

enum class CloakingStatus {
disabled,
damaged,
Expand Down Expand Up @@ -67,7 +70,7 @@ class Cloak
Cloak(std::string unit_key);
void Save(std::map<std::string, std::string>& unit);

void Update(Energetic *energetic);
void Update(Unit *unit);
void Toggle(); // Toggle cloak on/off

bool Capable() const {
Expand Down
Loading

0 comments on commit ad5c297

Please sign in to comment.