Skip to content

Commit

Permalink
Mex: Fix activation and propagation to neighbors (#521)
Browse files Browse the repository at this point in the history
Metal Extractors are supposed to only work if they are activated,
regardless of onoffable state. If a metal extractor is activated or
deactivated, propagate this state to neighbor extractors properly.

Setting extraction during FinishedBuilding is replaced with Activate,
since even not ononffable Extractors still require being activated to
function (fixes a bug where metal and extraction map is corrupted due to
this)
  • Loading branch information
badosu authored Nov 26, 2022
1 parent 5905553 commit 801cd6d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
4 changes: 2 additions & 2 deletions rts/Sim/Units/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class CUnit : public CSolidObject
// negative amount=reclaim, return= true -> build power was successfully applied
bool AddBuildPower(CUnit* builder, float amount);

void Activate();
void Deactivate();
virtual void Activate();
virtual void Deactivate();

void ForcedMove(const float3& newPos);

Expand Down
32 changes: 26 additions & 6 deletions rts/Sim/Units/UnitTypes/ExtractorBuilding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ CExtractorBuilding::~CExtractorBuilding()
/* resets the metalMap and notifies the neighbours */
void CExtractorBuilding::ResetExtraction()
{
metalExtract = 0;
script->ExtractionRateChanged(metalExtract);

// undo the extraction-area
for (auto si = metalAreaOfControl.begin(); si != metalAreaOfControl.end(); ++si) {
metalMap.RemoveExtraction(si->x, si->z, si->extractionDepth);
Expand Down Expand Up @@ -148,19 +151,36 @@ void CExtractorBuilding::ReCalculateMetalExtraction()
for (MetalSquareOfControl& msqr: metalAreaOfControl) {
metalMap.RemoveExtraction(msqr.x, msqr.z, msqr.extractionDepth);

// extraction is done in a cylinder
msqr.extractionDepth = metalMap.RequestExtraction(msqr.x, msqr.z, extractionDepth);
metalExtract += (msqr.extractionDepth * metalMap.GetMetalAmount(msqr.x, msqr.z));
if (activated) {
// extraction is done in a cylinder
msqr.extractionDepth = metalMap.RequestExtraction(msqr.x, msqr.z, extractionDepth);
metalExtract += (msqr.extractionDepth * metalMap.GetMetalAmount(msqr.x, msqr.z));
}
}

// set the new rotation-speed
script->ExtractionRateChanged(metalExtract);
}


/* Finds the amount of metal to extract and sets the rotationspeed when the extractor is built. */
void CExtractorBuilding::FinishedBuilding(bool postInit)
void CExtractorBuilding::Activate()
{
if (activated)
return;

CBuilding::Activate();

/* Finds the amount of metal to extract and sets the rotationspeed when the extractor is built. */
SetExtractionRangeAndDepth(unitDef->extractRange, unitDef->extractsMetal);
CUnit::FinishedBuilding(postInit);
}


void CExtractorBuilding::Deactivate()
{
if (!activated)
return;

CBuilding::Deactivate();

ResetExtraction();
}
5 changes: 3 additions & 2 deletions rts/Sim/Units/UnitTypes/ExtractorBuilding.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class CExtractorBuilding : public CBuilding {
public:
CR_DECLARE(CExtractorBuilding)
CR_DECLARE_DERIVED(CExtractorBuilding)
CR_DECLARE_SUB(MetalSquareOfControl)

CExtractorBuilding(): CBuilding() {
Expand All @@ -28,7 +28,8 @@ class CExtractorBuilding : public CBuilding {
float GetExtractionRange() const { return extractionRange; }
float GetExtractionDepth() const { return extractionDepth; }

void FinishedBuilding(bool postInit);
void Activate() override;
void Deactivate() override;

protected:
struct MetalSquareOfControl {
Expand Down

2 comments on commit 801cd6d

@6AKU
Copy link

@6AKU 6AKU commented on 801cd6d Feb 8, 2023

Choose a reason for hiding this comment

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

@badosu
It's bugged, Cor Advanced Exploiter mex (cormexp) unit cannot shoot after this commit.

@badosu
Copy link
Collaborator Author

@badosu badosu commented on 801cd6d Feb 8, 2023

Choose a reason for hiding this comment

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

Hmmm... Thank you, let me take a look

Please sign in to comment.