Skip to content

bugfix(object): Add support for object that has POWERED KindOf type without power - #3574

Open
Caball009 wants to merge 4 commits into
TheSuperHackers:mainfrom
Caball009:Caball009/fix_kindof_powered
Open

Caball009 wants to merge 4 commits into
TheSuperHackers:mainfrom
Caball009:Caball009/fix_kindof_powered

Conversation

@Caball009

@Caball009 Caball009 commented Oct 22, 2026 •

Copy link
Copy Markdown
Object AmericaTankAvengerLaserTurret
  KindOf = +POWERED
End

This PR makes 4 changes:

  1. Fixes a crash due to a nullptr dereference in Drawable::setColorTintEnvelope (see issue). The USA Avenger laser turret now turns dark when underpowered (if set to POWERED), but no low power icon because the unit itself is still responsive.
  2. Powered units that get built without sufficient power turn dark immediately.
  3. No-retail: Powered units go through the standard energy consumption logic, even when they consume no energy themselves. If a player has insufficient power, all powered units and unit modules are affected and their drawables are updated.
  4. Initializes Object::m_behaviors fields as nullptr. Strictly unnecessary but would otherwise implicitly rely on the memory manager which by default zeroes out newly allocated memory. Object::pauseAllSpecialPowers needs m_behaviors to be initialized.

See commits for clean diffs.

TODO:

  • Replicate to Generals.
  • Add PR to commit names.

@Caball009 Caball009 added Enhancement Is new feature or request Minor Severity: Minor < Major < Critical < Blocker Gen Relates to Generals ZH Relates to Zero Hour Crash This is a crash, very bad labels Oct 22, 2026
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The changes update tint-envelope access and transfer for Overlord riders. They also add non-retail-compatible handling for powered objects: brownout signaling for qualifying zero-energy objects, disabled tint during initialization, and attack rejection while underpowered.

Changes

Tint-envelope transfer

Layer / File(s) Summary
Tint-envelope API and rider draw calls
GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h, Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DOverlordAircraftDraw.cpp, Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DOverlordTankDraw.cpp, Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DOverlordTruckDraw.cpp
getColorTintEnvelope returns a const pointer. setColorTintEnvelope accepts a const pointer and copies only when the destination and source pointers are non-null. The three Overlord rider draw paths pass the envelope pointer directly.

Powered-object behavior

Layer / File(s) Summary
Zero-energy powered-object influence handling
GeneralsMD/Code/GameEngine/Source/Common/RTS/Energy.cpp
Energy influence entry and exit retain their production and consumption adjustments. Outside retail-compatible builds, each method signals a brownout for a zero-energy powered object when power is insufficient and an owner exists.
Underpowered tint and attack eligibility
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
Initialization applies disabled tint to powered objects disabled by DISABLED_UNDERPOWERED. Outside retail-compatible builds, Object::isAbleToAttack rejects underpowered objects.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: Bug, Fix, Stability, Rendering, NoRetail

Suggested reviewers: bobtista

Merge Risk: Moderate · previous review be685

Creating a powered unit with zero energy while its owner is out of power can crash the game. A captured or transferred powered unit can also stay disabled under an owner that has power. Both problems should be fixed before this draft is merged.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Linked Issues check Warning Issue [#7] requires no crash, no attack or turret turning, a black texture, a lightning symbol, and free transporter movement when the portable Avenger turret loses power. The null-safe `Drawable::set… Implement the complete underpowered behavior for issue [#7]. Add the lightning-symbol indicator and block turret turning while DISABLED_UNDERPOWERED is active. Apply the attack restriction in every intended build configuration. Add regres…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title clearly summarizes the main change: support for objects with the POWERED KindOf type when they have no power.
Out of Scope Changes check Passed The Drawable changes prevent null tint-envelope dereferences in rider draw paths. The Object, Energy, and tint changes implement underpowered powered-object behavior. These changes directly supp…
Description check Passed The description states the PR fixes a nullptr dereference in Drawable::setColorTintEnvelope (linked to issue #7) and lists related changes: underpowered tint for powered units, energy consumption logi…
Full details: Out of Scope Changes check

Explanation

The Drawable changes prevent null tint-envelope dereferences in rider draw paths. The Object, Energy, and tint changes implement underpowered powered-object behavior. These changes directly support issue [#7].

Full details: Description check

Explanation

The description states the PR fixes a nullptr dereference in Drawable::setColorTintEnvelope (linked to issue #7) and lists related changes: underpowered tint for powered units, energy consumption logic for powered units, and initialization of Object::m_behaviors. These match the changeset, which touches Drawable.h, the Overlord draw modules, Object.cpp, and Energy.cpp.

Full details: Linked Issues check

Explanation

Issue [#7] requires no crash, no attack or turret turning, a black texture, a lightning symbol, and free transporter movement when the portable Avenger turret loses power. The null-safe Drawable::setColorTintEnvelope call addresses the reported crash. Object::initObject applies TINT_STATUS_DISABLED to newly initialized underpowered objects, and Object::isAbleToAttack blocks attacks only when RETAIL_COMPATIBLE_CRC is disabled. The current description confirms that the lightning symbol is still absent. The reviewed changes do not establish that the turret cannot turn or that the transporter remains movable. No regression test evidence is present.

Resolution

Implement the complete underpowered behavior for issue [#7]. Add the lightning-symbol indicator and block turret turning while DISABLED_UNDERPOWERED is active. Apply the attack restriction in every intended build configuration. Add regression coverage for the crash and the powered Avenger behavior, including transporter movement.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 19178bd7-d94a-4f90-903d-ecfebd6d3e0f
📥 Commits

Reviewing files that changed from the base of the PR and between b7f0e31 and ea67714.

📒 Files selected for processing: 7
  • Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DOverlordAircraftDraw.cpp
  • Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DOverlordTankDraw.cpp
  • Core/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DOverlordTruckDraw.cpp
  • Generals/Code/GameEngine/Include/GameClient/Drawable.h
  • Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp
  • GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
  • GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (2)

🟡 Minor · Underpowered turrets can still rotate through recentering and idle… · Object.cpp:2995-2999

Generals/Code/GameEngine/Source/GameLogic/Object/Object.cpp:2995-2999
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Underpowered turrets can still rotate through recentering and idle scanning.

The DISABLED_UNDERPOWERED check in Object::isAbleToAttack() blocks only the object-target attack path. The turret recentering and idle-scan states call friend_turnTowardsAngle() with no power check. An underpowered turret can therefore keep turning, which Issue #7 does not allow.

Apply the power check in both Generals/ and GeneralsMD/, because each variant has its own TurretAI.cpp. A check in the shared turn helper would cover the recentering, idle-scan, and object-aim states in each variant. The body of that helper was not inspected, so no diff is given.

🟡 Minor · Allocate the rider's tint envelope before copying the carrier tint. · Drawable.h:317-318

Generals/Code/GameEngine/Include/GameClient/Drawable.h:317-318
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Allocate the rider's tint envelope before copying the carrier tint.

When a rider is added after the carrier becomes underpowered, the containment path does not propagate the carrier's existing disabled state. The new rider Drawable starts with a null tint envelope. Each Overlord draw path then calls setColorTintEnvelope(...), but the setter skips the copy. The rider can therefore miss the dark underpowered tint.

Update the shared setter in both game-variant headers.

Suggested fix
--- a/Generals/Code/GameEngine/Include/GameClient/Drawable.h
+++ b/Generals/Code/GameEngine/Include/GameClient/Drawable.h
@@
-	void setColorTintEnvelope( const TintEnvelope* source ) { if (m_colorTintEnvelope && source) *m_colorTintEnvelope = *source; }
+	void setColorTintEnvelope( const TintEnvelope* source )
+	{
+		if (source)
+		{
+			if (m_colorTintEnvelope == nullptr)
+				m_colorTintEnvelope = newInstance(TintEnvelope);
+			*m_colorTintEnvelope = *source;
+		}
+	}
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
@@
-	void setColorTintEnvelope( const TintEnvelope* source ) { if (m_colorTintEnvelope && source) *m_colorTintEnvelope = *source; }
+	void setColorTintEnvelope( const TintEnvelope* source )
+	{
+		if (source)
+		{
+			if (m_colorTintEnvelope == nullptr)
+				m_colorTintEnvelope = newInstance(TintEnvelope);
+			*m_colorTintEnvelope = *source;
+		}
+	}
🧹 Nitpick comments: 2
Generals/Code/GameEngine/Source/Common/RTS/Energy.cpp: 1

128-129: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Limit zero-energy power updates to the affected object.

A zero-energy KINDOF_POWERED object reaches addConsumption(0) on both entry and exit. This call still scans all player objects through Player::onPowerBrownOutChange, although the energy state does not change. Apply the current brownout state directly to the entering object. Remove the player-wide refresh from the zero-energy exit path.

Suggested fix
 #if !RETAIL_COMPATIBLE_CRC
-	else if (obj->isKindOf(KINDOF_POWERED))
-		addConsumption(-energy);
+	else if (obj->isKindOf(KINDOF_POWERED)) {
+		if (hasSufficientPower())
+			obj->clearDisabled(DISABLED_UNDERPOWERED);
+		else
+			obj->setDisabled(DISABLED_UNDERPOWERED);
+	}
 #endif
@@
-#if !RETAIL_COMPATIBLE_CRC
-	else if (obj->isKindOf(KINDOF_POWERED))
-		addConsumption(energy);
-#endif
GeneralsMD/Code/GameEngine/Source/Common/RTS/Energy.cpp: 1

147-148: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Avoid the player-wide refresh for zero-energy powered objects.

When energy == 0 and the object is KINDOF_POWERED, addConsumption(0) still calls Player::onPowerBrownOutChange, which iterates the player's objects. The same unnecessary scan occurs when the object leaves.

Synchronize only the entering object with hasSufficientPower(). Remove the zero-energy exit callback. Apply the same change in Generals and GeneralsMD.

Suggested fix
 #if !RETAIL_COMPATIBLE_CRC
-	else if (obj->isKindOf(KINDOF_POWERED))
-		addConsumption(-energy);
+	else if (obj->isKindOf(KINDOF_POWERED)) {
+		if (hasSufficientPower())
+			obj->clearDisabled(DISABLED_UNDERPOWERED);
+		else
+			obj->setDisabled(DISABLED_UNDERPOWERED);
+	}
 #endif
-#if !RETAIL_COMPATIBLE_CRC
-	else if (obj->isKindOf(KINDOF_POWERED))
-		addConsumption(energy);
-#endif

ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fb6eac9b-42e5-433f-891e-4a3f0baa40be
📥 Commits

Reviewing files that changed from the base of the PR and between ea67714 and 611cd56.

📒 Files selected for processing: 2
  • Generals/Code/GameEngine/Source/Common/RTS/Energy.cpp
  • GeneralsMD/Code/GameEngine/Source/Common/RTS/Energy.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@Caball009
Caball009 force-pushed the Caball009/fix_kindof_powered branch 2 times, most recently from 311a978 to be68507 Compare October 24, 2026 00:45

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6db375ef-f6e8-4cf0-a696-c4e0e3f4452f
📥 Commits

Reviewing files that changed from the base of the PR and between 311a978 and be68507.

📒 Files selected for processing: 2
  • GeneralsMD/Code/GameEngine/Source/Common/RTS/Energy.cpp
  • GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@Caball009
Caball009 force-pushed the Caball009/fix_kindof_powered branch 5 times, most recently from 8b39d33 to cffe846 Compare October 24, 2026 18:57
@Caball009 Caball009 added the NoRetail This fix or change is not applicable with Retail game compatibility label Oct 24, 2026
@Caball009
Caball009 force-pushed the Caball009/fix_kindof_powered branch 2 times, most recently from fb56f09 to 08d6abf Compare October 29, 2026 02:06
@Caball009
Caball009 marked this pull request as ready for review October 29, 2026 02:08
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes reach powered-object behavior and its drawable presentation.

The PR should wait until newly created special-power modules respect the object's initial underpowered state.

Findings

  1. P1 Special powers charge without power ▶

Summary

Adds power-shortage support for zero-energy POWERED objects and fixes tint-related crashes.

  • Powered objects that use no energy now respond to power shortages.
  • Underpowered objects and their contained riders show the right tint.
  • Object construction starts its behavior-module slots empty.

Caball009 accepted deferring the Generals update to the open TODO. The destruction-sound finding was withdrawn after Caball009 explained that energy-producing and energy-consuming objects already follow the same path.

Reviews (7) · Last reviewed commit: "fix(object): Initialize Object::m_behavi..." · Reviewed by Greptile

@Caball009 Caball009 added the Mod Relates to Mods or modding label Oct 29, 2026
@Caball009
Caball009 force-pushed the Caball009/fix_kindof_powered branch from 08d6abf to 773acdb Compare October 29, 2026 20:03
@Caball009
Caball009 force-pushed the Caball009/fix_kindof_powered branch from 773acdb to 2adabd0 Compare October 29, 2026 20:06

@xezon xezon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this meant to be merged with Rebase?

else if( energy > 0 )
addProduction( energy );
#if !RETAIL_COMPATIBLE_CRC
// TheSuperHackers @tweak Add support for powered objects that consume no energy.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks odd because it is unpaired in objectLeavingInfluence and it does not match the previous intent of the function - see EA comment above the function.

Does this perhaps belong somewhere else?

Was this change needed to make it properly work, for example if a structure is captured and the player has not enough power?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It could be added here, but it was deemed undesirable (#3574 (comment)).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Github brings me nowhere good when clicking that link.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

How about now? I unresolved that particular conversation.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It seems the branch was force pushed after that pull comment, so I am unable to understand the context of the comment, aka where it was placed before.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I don't think this is relevant anymore now that the code's updated.

@Caball009
Caball009 force-pushed the Caball009/fix_kindof_powered branch from 533d79f to 9f3a031 Compare November 11, 2026 18:44
@Caball009

Copy link
Copy Markdown
Author

Is this meant to be merged with Rebase?

Yeah, I think that's for the best.

Comment on lines +154 to +156
else if (!obj->isDisabledByType(DISABLED_UNDERPOWERED))
{
obj->setDisabled(DISABLED_UNDERPOWERED);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Special powers charge without power

A zero-energy POWERED object created during a power shortage gets DISABLED_UNDERPOWERED before its modules exist. The call to pauseAllSpecialPowers(TRUE) therefore pauses nothing. SpecialPowerModule later starts its countdown without checking that flag. Restoring power cannot extend the countdown because m_pausedCount is still zero.

The special power charges during the outage and becomes available too soon after power returns. Apply the initial disabled state to the modules after creating them.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This seems like a larger issue, though, quite possibly outside the scope of this PR. Is there any reason why this wouldn't already be an issue for powered objects that do require energy?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, that could already affect powered objects that consume energy. Their path goes through addConsumption(), which calls the owner’s onPowerBrownOutChange(!hasSufficientPower()); if that brownout handling disables a newly created object before its special-power modules are ready, the same missed-pause can occur.

The difference is only how the underpowered state is triggered: the new zero-energy branch calls setDisabled() directly, while consumers reach the brownout callback through energy accounting. That difference alone doesn’t establish that consumers avoid the timing issue. I didn’t verify the callback/module-construction ordering, so my previous comment was too narrowly attributed; this looks like a broader lifecycle question and may be outside this PR’s scope.

// rather than needing to rely on Energy::objectLeavingInfluence.
if (isKindOf(KINDOF_POWERED))
{
clearDisabled(DISABLED_UNDERPOWERED);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this one is new behavior. setTeam(nullptr) removes the object from its team before objectLeavingInfluence runs, so doPowerDisable never touched the dying object before. Now a powered structure that's destroyed or sold during low power plays the re-enabled sound through clearDisabled. What goes wrong if the flag is left set on a dying object? If something does, could it be cleared without the audio and tint side effects?

@Caball009 Caball009 Nov 12, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think this one is new behavior.

I don't think it is. Put a breakpoint on Energy::objectLeavingInfluence and sell a power plant. You'll see this call stack:

generalszh.exe!Energy::objectLeavingInfluence(Object * obj)
generalszh.exe!Object::friend_adjustPowerForPlayer(bool incoming)
generalszh.exe!Player::becomingTeamMember(Object * obj, bool yes)
generalszh.exe!Object::setOrRestoreTeam(Team * team, bool restoring)
generalszh.exe!Object::setTemporaryTeam(Team * team)
generalszh.exe!Object::setTeam(Team * team)
generalszh.exe!Object::~Object()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Same goes for destroying an Avenger with and without ini modifications.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The stack is right, but objectLeavingInfluence only changes the energy totals. The object is already removed from the team list in setOrRestoreTeam (Object.cpp:872-874), so doPowerDisable never reaches it. The new clearDisabled in the destructor is the first thing to touch the dying object, and it plays the re-enabled sound for structures and vehicles (Object.cpp:2283-2304). Is there a case where leaving the flag set on a deleted object causes a problem?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The stack is right, but objectLeavingInfluence only changes the energy totals.

That's not what I'm seeing.

Should I have my LLM answer yours?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

lol sure why not. Mine says "You're right that it does more than adjust the totals - addProduction/addConsumption call onPowerBrownOutChange, which clears the flag on the remaining objects. It can't reach the dying one though. setOrRestoreTeam removes it from the team member list at Object.cpp:934 before calling becomingTeamMember, and Player::iterateObjects walks those lists. My line numbers were off too, sorry. If you break in doPowerDisable while selling a powered building during low power, is obj ever the building being sold?"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Looks like you were right.

My line numbers were off too, sorry.

I wasn't seeing what you were seeing and your comment threw me off; sorry about that.

If you break in doPowerDisable while selling a powered building during low power, is obj ever the building being sold?"

No, I don't think so.


Looks like the disabled status is never cleaned up for powered objects, anyway, so this would be new behavior and probably unnecessary. I've removed it for now.

// rather than needing to rely on Energy::objectLeavingInfluence.
if (isKindOf(KINDOF_POWERED))
{
clearDisabled(DISABLED_UNDERPOWERED);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Despite the comment it is not clear to me why the flag needs unsetting like this.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed. Would be new behavior and doesn't appear necessary.

{
obj->clearDisabled(DISABLED_UNDERPOWERED);
}
else if (!obj->isDisabledByType(DISABLED_UNDERPOWERED))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe can omit this test? Does not hurt to just write again the same result.

@Caball009 Caball009 Nov 19, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I added the test here, because there's no early return in Object::setDisabledUntil.

{
obj->setDisabled(DISABLED_UNDERPOWERED);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can do

void Object::doPowerDisable( bool disabling )
{
	if( isKindOf(KINDOF_POWERED) )
	{
		if( disabling )
			setDisabled( DISABLED_UNDERPOWERED ); //set disabled has a pauseAllSpecialPowers that prevents double pausing
		else
			clearDisabled( DISABLED_UNDERPOWERED );
	}
}

static void Player::doPowerDisable( Object *obj, void *userData )
{
	if (obj)
	{
		Bool disabling = *((Bool*)userData);
		obj->doPowerDisable(&disabling);
	}
}

void Energy::objectEnteringInfluence( Object *obj )
{
...
	else
	{
		obj->doPowerDisable(!hasSufficientPower());
	}
...
}

Or better flip to enablePower to avoid the double negative.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Changed.

else if( energy > 0 )
addProduction( energy );
#if !RETAIL_COMPATIBLE_CRC
// TheSuperHackers @tweak Add support for powered objects that consume no energy.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It seems the branch was force pushed after that pull comment, so I am unable to understand the context of the comment, aka where it was placed before.

@xezon xezon left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This change is tricky.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

While we are at it, can we do an optimization here for

void Energy::addProduction(Int amt)
{
	const Bool hadPower = hasSufficientPower();
	m_energyProduction += amt;

	if( m_owner == nullptr )
		return;

	const Bool hasPower = hasSufficientPower();

	if( hasPower != hadPower )
	{
		m_owner->onPowerBrownOutChange( !hasPower );
	}
}

Maybe can be a follow up. Needs to be careful for Retail compatibility because originally it sets flags for new objects too and with the optimization it does not.

@Caball009 Caball009 Nov 19, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Seems like a reasonable optimization but not according to the comment in Energy::addProduction:

// A repeated Brownout signal does nothing bad, and we need to handle more than just edge cases.
// Like low power, now even more low power, refresh disable.

I don't see the point of 'even more low power', though, do you?

@Caball009 Caball009 Nov 19, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I think this is better suited for a separate change, though. Energy::addConsumption can be optimized similarly, but requires a bit larger change.

I've added a new issue / task for it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This condition can prevent setting the new DISABLED_UNDERPOWERED in objectEnteringInfluence, indicating that the handling inside objectEnteringInfluence is misplaced.

@Caball009
Caball009 force-pushed the Caball009/fix_kindof_powered branch from 9f3a031 to c7d557d Compare November 19, 2026 20:43
@Caball009
Caball009 force-pushed the Caball009/fix_kindof_powered branch from c7d557d to daf2959 Compare November 19, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Crash This is a crash, very bad Enhancement Is new feature or request Gen Relates to Generals Minor Severity: Minor < Major < Critical < Blocker Mod Relates to Mods or modding NoRetail This fix or change is not applicable with Retail game compatibility ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding POWERED KindOf to portable structures crashed the game

5 participants