Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/User-Interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,14 @@ For this command to work in multiplayer - you need to use a version of [YRpp spa
- `AllowDistributionCommand.SpreadMode` & `AllowDistributionCommand.FilterMode` allow you to set spread range and target filter by hotkeys, which default to `DefaultDistributionSpreadMode` and `DefaultDistributionFilterMode`.
- When the range is 0, it is the original default behavior of the game. The range can be adjusted to 4, 8 or 16 cells by another shortcut key. You can also adjust this by using the mouse wheel while holding down the specific hotkey if `AllowDistributionCommand.SpreadModeScroll` set to true;
- The targets within the range will be allocated equally to the selected technos. Only when the behavior to be performed by the current techno is the same as that displayed by the mouse will it be allocated. Otherwise, it will return to the original default behavior of the game (it will not be effective for technos in the air). This will display a range ring.
- You can also set a list of integers in `DistributionMode.SpreadRanges`. In this case, the range of each step will follow these settings instead of being 0, 4, 8 and 16.
- When the filter is `None`, it is the default behavior of the game. If the range is not zero at this time, a green ring will be displayed. You can adjust the filter mode to:
- `Like` - only targets with the same armor type (Completely identical `Armor`) will be selected among the targets allocated in the range. At this time, a blue ring will be displayed.
- `Type` - only targets of the same type (like infantries, vehicles or buildings) will be selected among the targets allocated in the range. At this time, a yellow ring will be displayed.
- `Name` - only targets of the same name (or with the same `GroupAs`) will be selected among the targets allocated in the range. At this time, a red ring will be displayed.
- `AllowDistributionCommand.AffectsAllies` & `AllowDistributionCommand.AffectsEnemies` allow the distribution command to work on allies (including owner) or enemies target. If picking a target that's not eligible, it'll fallback to vanilla command.
- `DistributionMode.AllowActions` & `DistributionMode.DisallowActions` determine the missions that can or can't be used for distribution command. If picking a target that's not eligible, it'll fallback to vanilla command.
- By default `DistributionMode.AllowActions` is an empty list, which means all missions are eligible for distribution command unless listed in `DistributionMode.DisallowActions`.
- It's possible to add a button for distribution mode in the bottom bar by adding `DistributionMode` in the `ButtonList` of `AdvancedCommandBar` and `MultiplayerAdvancedCommandBar`.
- The positions of each button are hardcoded, so it'll only decide whether enable this button or not. Distribute Mode button is now always listed after all the vanilla ones.
- The asset of these buttons should be added in `sidec0x.mix` files which correspond to different sides, with the name `button12.shp`.
Expand All @@ -530,6 +533,11 @@ AllowDistributionCommand.FilterMode=true ; boolean
AllowDistributionCommand.AffectsAllies=true ; boolean
AllowDistributionCommand.AffectsEnemies=true ; boolean

[General]
DistributionMode.AllowActions= ; list of Action
DistributionMode.DisallowActions= ; list of Action
DistributionMode.SpreadRanges=0,4,8,16 ; list of integer

[AudioVisual]
StartDistributionModeSound= ; sound entry
EndDistributionModeSound= ; sound entry
Expand All @@ -540,7 +548,7 @@ In `ra2md.ini`:
```ini
[Phobos]
DefaultApplyNoMoveCommand=true ; boolean
DefaultDistributionSpreadMode=2 ; integer, 0 - r=0 , 1 - r=4 , 2 - r=8 , 3 - r=16
DefaultDistributionSpreadMode=2 ; integer, index of values in DistributionMode.SpreadRanges
DefaultDistributionFilterMode=2 ; integer, 0 - None , 1 - Like , 2 - Type , 3 - Name
```

Expand Down
26 changes: 17 additions & 9 deletions src/Commands/DistributionMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const wchar_t* DistributionModeSpreadCommandClass::GetUIDescription() const

void DistributionModeSpreadCommandClass::Execute(WWKey eInput) const
{
Phobos::Config::DistributionSpreadMode = ((Phobos::Config::DistributionSpreadMode + 1) & 3);
const int size = RulesExt::Global()->DistributionMode_SpreadRanges.size() > 0 ? RulesExt::Global()->DistributionMode_SpreadRanges.size() - 1 : 3;
Phobos::Config::DistributionSpreadMode = ((Phobos::Config::DistributionSpreadMode + 1) & size);
DistributionModeHoldDownCommandClass::ShowTime = SystemTimer::GetTime();
}

Expand Down Expand Up @@ -174,7 +175,8 @@ void DistributionModeHoldDownCommandClass::DistributionModeOff()

void DistributionModeHoldDownCommandClass::DistributionSpreadModeExpand()
{
Phobos::Config::DistributionSpreadMode = std::min(3, Phobos::Config::DistributionSpreadMode + 1);
const int size = RulesExt::Global()->DistributionMode_SpreadRanges.size() > 0 ? RulesExt::Global()->DistributionMode_SpreadRanges.size() - 1 : 3;
Phobos::Config::DistributionSpreadMode = std::min(size, Phobos::Config::DistributionSpreadMode + 1);
}

void DistributionModeHoldDownCommandClass::DistributionSpreadModeReduce()
Expand Down Expand Up @@ -238,20 +240,25 @@ DEFINE_HOOK(0x4AE7B3, DisplayClass_ActiveClickWith_Iterate, 0x0)

// Distribution mode main
if (DistributionModeHoldDownCommandClass::Enabled
&& spreadMode
&& (spreadMode || RulesExt::Global()->DistributionMode_SpreadRanges.size() > 0)
&& count > 1
&& action != Action::NoMove
&& !PlanningNodeClass::PlanningModeActive
&& pTechno
&& !pTechno->IsInAir()
&& (HouseClass::CurrentPlayer->IsAlliedWith(pTechno->Owner)
? Phobos::Config::AllowDistributionCommand_AffectsAllies
: Phobos::Config::AllowDistributionCommand_AffectsEnemies))
: Phobos::Config::AllowDistributionCommand_AffectsEnemies)
&& (RulesExt::Global()->DistributionMode_AllowActions.size() > 0
&& std::any_of(RulesExt::Global()->DistributionMode_AllowActions.begin(), RulesExt::Global()->DistributionMode_AllowActions.end(),
[=](Action listedAction) { return action == listedAction; }))
&& !std::any_of(RulesExt::Global()->DistributionMode_DisallowActions.begin(), RulesExt::Global()->DistributionMode_DisallowActions.end(),
[=](Action listedAction) { return action == listedAction; }))
{
VocClass::PlayGlobal(RulesExt::Global()->AddDistributionModeCommandSound, 0x2000, 1.0);
const bool targetIsNeutral = pTechno->Owner->IsNeutral();
const auto pType = pTechno->GetTechnoType();
const int range = (2 << spreadMode);
const int range = RulesExt::Global()->DistributionMode_SpreadRanges.size() > 0 ? RulesExt::Global()->DistributionMode_SpreadRanges[spreadMode] : (2 << spreadMode);
const auto center = pTechno->GetCoords();
const auto pItems = Helpers::Alex::getCellSpreadItems(center, range);

Expand Down Expand Up @@ -410,16 +417,17 @@ DEFINE_HOOK(0x6DBE74, TacticalClass_DrawAllRadialIndicators_DrawDistributionRang
if (!DistributionModeHoldDownCommandClass::Enabled && SystemTimer::GetTime() - DistributionModeHoldDownCommandClass::ShowTime > 30)
return 0;

const auto spreadMode = Phobos::Config::DistributionSpreadMode;
const auto filterMode = Phobos::Config::DistributionFilterMode;
const int spreadMode = Phobos::Config::DistributionSpreadMode;
const int filterMode = Phobos::Config::DistributionFilterMode;

if (spreadMode || filterMode)
if (spreadMode || RulesExt::Global()->DistributionMode_SpreadRanges.size() > 0 || filterMode)
{
const auto pCell = MapClass::Instance.GetCellAt(DisplayClass::Instance.CurrentFoundation_CenterCell);
const auto color = (filterMode > 1)
? ((filterMode == 3) ? ColorStruct { 255, 0, 0 } : ColorStruct { 200, 200, 0 })
: ((filterMode == 1) ? ColorStruct { 0, 100, 255 } : ColorStruct { 0, 255, 50 });
Game::DrawRadialIndicator(false, true, pCell->GetCoords(), color, static_cast<float>(spreadMode ? (2 << spreadMode) : 0.5), false, true);
Game::DrawRadialIndicator(false, true, pCell->GetCoords(), color, static_cast<float>(RulesExt::Global()->DistributionMode_SpreadRanges.size() > 0
? RulesExt::Global()->DistributionMode_SpreadRanges[spreadMode] : (spreadMode ? (2 << spreadMode) : 0.5)), false, true);
}

return 0;
Expand Down
8 changes: 7 additions & 1 deletion src/Ext/Rules/Body.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Body.h"
#include "Body.h"
#include <Ext/Side/Body.h>
#include <Utilities/TemplateDef.h>
#include <FPSCounter.h>
Expand Down Expand Up @@ -263,6 +263,9 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
this->StartDistributionModeSound.Read(exINI, GameStrings::AudioVisual, "StartDistributionModeSound");
this->EndDistributionModeSound.Read(exINI, GameStrings::AudioVisual, "EndDistributionModeSound");
this->AddDistributionModeCommandSound.Read(exINI, GameStrings::AudioVisual, "AddDistributionModeCommandSound");
this->DistributionMode_AllowActions.Read(exINI, GameStrings::General, "DistributionMode.AllowActions");
this->DistributionMode_DisallowActions.Read(exINI, GameStrings::General, "DistributionMode.DisallowActions");
this->DistributionMode_SpreadRanges.Read(exINI, GameStrings::General, "DistributionMode.SpreadRanges");

this->ReplaceVoxelLightSources();

Expand Down Expand Up @@ -558,6 +561,9 @@ void RulesExt::ExtData::Serialize(T& Stm)
.Process(this->StartDistributionModeSound)
.Process(this->EndDistributionModeSound)
.Process(this->AddDistributionModeCommandSound)
.Process(this->DistributionMode_AllowActions)
.Process(this->DistributionMode_DisallowActions)
.Process(this->DistributionMode_SpreadRanges)
.Process(this->UseFixedVoxelLighting)
.Process(this->AIAutoDeployMCV)
.Process(this->AISetBaseCenter)
Expand Down
6 changes: 6 additions & 0 deletions src/Ext/Rules/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ class RulesExt
ValueableIdx<VocClass> StartDistributionModeSound;
ValueableIdx<VocClass> EndDistributionModeSound;
ValueableIdx<VocClass> AddDistributionModeCommandSound;
ValueableVector<Action> DistributionMode_AllowActions;
ValueableVector<Action> DistributionMode_DisallowActions;
ValueableVector<int> DistributionMode_SpreadRanges;

Nullable<Vector3D<float>> VoxelLightSource;
// Nullable<Vector3D<float>> VoxelShadowLightSource;
Expand Down Expand Up @@ -439,6 +442,9 @@ class RulesExt
, StartDistributionModeSound { -1 }
, EndDistributionModeSound { -1 }
, AddDistributionModeCommandSound { -1 }
, DistributionMode_AllowActions { }
, DistributionMode_DisallowActions { }
, DistributionMode_SpreadRanges { }
, UseFixedVoxelLighting { false }
, AIAutoDeployMCV { true }
, AISetBaseCenter { true }
Expand Down
2 changes: 1 addition & 1 deletion src/Phobos.INI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ DEFINE_HOOK(0x5FACDF, OptionsClass_LoadSettings_LoadPhobosSettings, 0x5)

Phobos::Config::ApplyNoMoveCommand = CCINIClass::INI_RA2MD.ReadBool(phobosSection, "DefaultApplyNoMoveCommand", true);
Phobos::Config::DistributionSpreadMode = CCINIClass::INI_RA2MD.ReadInteger(phobosSection, "DefaultDistributionSpreadMode", 2);
Phobos::Config::DistributionSpreadMode = std::clamp(Phobos::Config::DistributionSpreadMode, 0, 3);
//Phobos::Config::DistributionSpreadMode = std::clamp(Phobos::Config::DistributionSpreadMode, 0, 3);
Phobos::Config::DistributionFilterMode = CCINIClass::INI_RA2MD.ReadInteger(phobosSection, "DefaultDistributionFilterMode", 2);
Phobos::Config::DistributionFilterMode = std::clamp(Phobos::Config::DistributionFilterMode, 0, 3);

Expand Down
Loading