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

Show designator & inhibitor range #1124

Merged

Conversation

MortonPL
Copy link
Member

@MortonPL MortonPL commented Aug 8, 2023

  • It is now possible to display range of designator and inhibitor units when in super weapon targeting mode. Each instance of player owned techno types listed in [SuperWeapon]->SW.Designators will display a circle with radius set in [TechnoType]->DesignatorRange or Sight.
    • In a similar manner, each instance of enemy owned techno types listed in [SuperWeapon]->SW.Inhibitors will display a circle with radius set in [TechnoType]->InhibitorRange or Sight.
  • This feature can be disabled globally with [AudioVisual]->ShowDesignatorRange=false or per SuperWeaponType with [SuperWeapon]->ShowDesignatorRange=false.
  • This feature can be toggled by the player (if enabled in the mod) with ShowDesignatorRange in Ra2MD.ini or with "Toggle Designator Range" hotkey in "Interface" category.
Due to technical reasons, this feature only works for super weapons with `Range` >= 1.

In rulesmd.ini:

[AudioVisual]
ShowDesignatorRange=true    ; boolean

[SOMESW]                    ; SuperWeapon
ShowDesignatorRange=true    ; boolean

In Ra2MD.ini:

[Phobos]
ShowDesignatorRange=false             ; boolean

@MortonPL MortonPL added the Feature / Enhancement Anything new not present in vanilla/Ares label Aug 8, 2023
@github-actions
Copy link

github-actions bot commented Aug 8, 2023

Nightly build for this pull request:

This comment is automatic and is meant to allow guests to get latest nightly builds for this pull request without registering. It is updated on every successful build.

docs/User-Interface.md Outdated Show resolved Hide resolved
docs/User-Interface.md Outdated Show resolved Hide resolved
@Starkku
Copy link
Contributor

Starkku commented Aug 24, 2023

Not sure if both hotkey and user INI setting are needed for this, should probably pick one or the other. Although I guess if it is just hotkey it won't save the preference across sessions but if it is a feature where you'd want that then just having the user INI option is better anyway.

Code itself looks good, but it should really be extended to work with inhibitors too. Display the indicators in the inhibitor's owner's color. Not sure what would do when/if Suppressors/Attractors (friendly inhibitors and enemy designators) are added but that is a bridge that can be crossed then.

@Metadorius
Copy link
Member

Considering those ranges only get displayed when you're firing a superweapon (btw does it only show relevant designators/inhibitors?) I don't think it's ever needed to be manually toggleable because it's not obstructive and it's kinda toggled automatically when firing the SW anyways.

@MortonPL MortonPL changed the title Show designator radius Show designator & inhibitor range Aug 24, 2023
@Starkku
Copy link
Contributor

Starkku commented Aug 26, 2023

Due to technical reasons, this feature only works for super weapons with Range >= 1.

What technical reasons? I replaced your hook with:

DEFINE_HOOK(0x6DBE74, Tactical_SuperLinesCircles_ShowDesignatorRange, 0x7)
{
	if (!Phobos::Config::ShowDesignatorRange || !(RulesExt::Global()->ShowDesignatorRange) || Unsorted::CurrentSWType == -1)
		return 0;

	const auto pSuperType = SuperWeaponTypeClass::Array()->GetItem(Unsorted::CurrentSWType);
	const auto pExt = SWTypeExt::ExtMap.Find(pSuperType);

	if (!pExt->ShowDesignatorRange)
		return 0;

	for (const auto pCurrentTechno : *TechnoClass::Array)
	{
		const auto pCurrentTechnoType = pCurrentTechno->GetTechnoType();
		const auto pOwner = pCurrentTechno->Owner;

		if (!pCurrentTechno->IsAlive
			|| pCurrentTechno->InLimbo
			|| !pExt->SW_Designators.Contains(pCurrentTechnoType)
			|| !((pOwner == HouseClass::CurrentPlayer)
				|| EnumFunctions::CanTargetHouse(AffectedHouse::Enemies, HouseClass::CurrentPlayer, pOwner)))
		{
			continue;
		}

		const auto pTechnoTypeExt = TechnoTypeExt::ExtMap.Find(pCurrentTechnoType);

		const float radius = pOwner == HouseClass::CurrentPlayer ?
			(float)(pTechnoTypeExt->DesignatorRange.Get(pCurrentTechnoType->Sight)) :
			(float)(pTechnoTypeExt->InhibitorRange.Get(pCurrentTechnoType->Sight));

		CoordStruct coords = pCurrentTechno->GetCenterCoords();
		coords.Z = MapClass::Instance->GetCellFloorHeight(coords);
		const auto color = pOwner->Color;
		Game::DrawRadialIndicator(false, true, coords, color, radius, false, true);
	}

	return 0;
}

E.g move it to the start of the function and fetch the SW type yourself. And it appears to work just fine, only issue is that the hook will be entered much more often (idk if this is a major performance hog though) and minor redundancy in fetching the SW type potentially twice but this comes in exchange for working independently from SW's Range or the target lines option. Couple of minor optimizations with the checks / their order as well. Checking extension class pointers for nullptr is generally speaking futile exercise - ExtMap::Find will under most circumstances only now return nullptr if you call it with nullptr, in which case you're gonna have other problems anyway (missing type) and if it is not a pointer of correct type it'll just crash or return garbage regardless. Cost of performance is security I suppose.

Copy link
Member

@Metadorius Metadorius left a comment

Choose a reason for hiding this comment

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

LGTM after fixing

docs/User-Interface.md Outdated Show resolved Hide resolved
src/Ext/SWType/Hooks.cpp Outdated Show resolved Hide resolved
@Metadorius Metadorius merged commit 68b7e17 into Phobos-developers:develop Aug 31, 2023
10 checks passed
@MortonPL MortonPL deleted the feature/designator-radius branch August 31, 2023 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature / Enhancement Anything new not present in vanilla/Ares
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants