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

[General Purpose] Manually empty and reload ammo #1493

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ This page lists all the individual contributions to the project by their author.
- Enhanced Bombard trajectory
- No turret unit turn to the target
- Damage multiplier for different houses
- Manually empty and reload ammo
- **Ollerus**
- Build limit group enhancement
- Customizable rocker amplitude
Expand Down
4 changes: 4 additions & 0 deletions Phobos.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<ClCompile Include="src\Commands\NextIdleHarvester.cpp" />
<ClCompile Include="src\Commands\ObjectInfo.cpp" />
<ClCompile Include="src\Commands\QuickSave.cpp" />
<ClCompile Include="src\Commands\ManualReloadAmmo.cpp" />
<ClCompile Include="src\Commands\ToggleDesignatorRange.cpp" />
<ClCompile Include="src\Commands\ToggleDigitalDisplay.cpp" />
<ClCompile Include="src\Commands\SaveVariablesToFile.cpp" />
Expand All @@ -41,6 +42,7 @@
<ClCompile Include="src\Ext\Bullet\Trajectories\ParabolaTrajectory.cpp" />
<ClCompile Include="src\Ext\CaptureManager\Hooks.cpp" />
<ClCompile Include="src\Ext\CaptureManager\Body.cpp" />
<ClCompile Include="src\Ext\Event\Body.cpp" />
<ClCompile Include="src\Ext\OverlayType\Body.cpp" />
<ClCompile Include="src\Ext\OverlayType\Hooks.cpp" />
<ClCompile Include="src\Ext\ParticleType\Body.cpp" />
Expand Down Expand Up @@ -194,13 +196,15 @@
<ClInclude Include="src\Commands\Commands.h" />
<ClInclude Include="src\Commands\DamageDisplay.h" />
<ClInclude Include="src\Commands\QuickSave.h" />
<ClInclude Include="src\Commands\ManualReloadAmmo.h" />
<ClInclude Include="src\Commands\ToggleDesignatorRange.h" />
<ClInclude Include="src\Commands\ToggleDigitalDisplay.h" />
<ClInclude Include="src\Commands\SaveVariablesToFile.h" />
<ClInclude Include="src\Ext\Bullet\Trajectories\BombardTrajectory.h" />
<ClInclude Include="src\Ext\Bullet\Trajectories\PhobosTrajectory.h" />
<ClInclude Include="src\Ext\Bullet\Trajectories\StraightTrajectory.h" />
<ClInclude Include="src\Ext\Bullet\Trajectories\ParabolaTrajectory.h" />
<ClInclude Include="src\Ext\Event\Body.h" />
<ClInclude Include="src\Ext\OverlayType\Body.h" />
<ClInclude Include="src\Ext\ParticleType\Body.h" />
<ClInclude Include="src\Ext\Sidebar\Body.h" />
Expand Down
18 changes: 18 additions & 0 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,24 @@ Convert.HumanToComputer= ; TechnoType
Convert.ComputerToHuman= ; TechnoType
```

### Manually empty and reload ammo

- You can now use the shortcut key to manually empty and reload ammo for units. Aircraft still needs to return to the airport to reload.
- `CanManualReload` controls whether this type of techno can manually empty and reload ammo.
- `CanManualReload.ResetROF` controls whether need to reset rearm timer when manually empty and reload ammo.
- `CanManualReload.DetonateWarhead` controls whether need to detonate a warhead at the techno's location with 1 damage when manually empty and reload ammo.
- `CanManualReload.DetonateConsume` controls whether `CanManualReload.DetonateWarhead` require the techno to have more ammo than this value (or equal to) before reloading in order to detonate.
- For shortcut keys, see [User Interface -> Manually Reload](User-Interface.md#Manual-Reload).

In `rulesmd.ini`:
```ini
[SOMETECHNO] ; TechnoType
CanManualReload=false ; boolean
CanManualReload.ResetROF=true ; boolean
CanManualReload.DetonateWarhead= ; WarheadType
CanManualReload.DetonateConsume=0 ; integer
```

## Terrain

### Destroy animation & sound
Expand Down
5 changes: 5 additions & 0 deletions docs/User-Interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ ShowFlashOnSelecting=false ; boolean
- These vanilla CSF entries will be used: `TXT_SAVING_GAME`, `TXT_GAME_WAS_SAVED` and `TXT_ERROR_SAVING_GAME`.
- The save should be looks like `Allied Mission 25: Esther's Money - QuickSaved`.

### `[ ]` Manual Reload

- Manually empty and reload ammo if [CanManualReload=true](New-or-Enhanced-Logics.md#Manually-empty-and-reload-ammo).
- For localization add `TXT_MANUAL_RELOAD` and `TXT_MANUAL_RELOAD_DESC` into your `.csf` file.

## Loading screen

- PCX files can now be used as loadscreen images.
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ New:
- Allow infantry to use land sequences in water (by Starkku)
- `<Player @ X>` can now be used as owner for pre-placed objects on skirmish and multiplayer maps (by Starkku)
- Allow customizing charge turret delays per burst on a weapon (by Starkku)
- Manually empty and reload ammo (by CrimRecya)
- Unit `Speed` setting now accepts floating point values (by Starkku)
- Extending `Power` to all TechnoTypes (by Morton)

Expand Down
2 changes: 2 additions & 0 deletions src/Commands/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ToggleDigitalDisplay.h"
#include "ToggleDesignatorRange.h"
#include "SaveVariablesToFile.h"
#include "ManualReloadAmmo.h"

DEFINE_HOOK(0x533066, CommandClassCallback_Register, 0x6)
{
Expand All @@ -19,6 +20,7 @@ DEFINE_HOOK(0x533066, CommandClassCallback_Register, 0x6)
MakeCommand<QuickSaveCommandClass>();
MakeCommand<ToggleDigitalDisplayCommandClass>();
MakeCommand<ToggleDesignatorRangeCommandClass>();
MakeCommand<ManualReloadAmmoCommandClass>();

if (Phobos::Config::DevelopmentCommands)
{
Expand Down
38 changes: 38 additions & 0 deletions src/Commands/ManualReloadAmmo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "ManualReloadAmmo.h"

#include <HouseClass.h>

#include <Ext/TechnoType/Body.h>
#include <Ext/Event/Body.h>

const char* ManualReloadAmmoCommandClass::GetName() const
{
return "Manual Reload Ammo";
}

const wchar_t* ManualReloadAmmoCommandClass::GetUIName() const
{
return GeneralUtils::LoadStringUnlessMissing("TXT_MANUAL_RELOAD", L"Manual Reload Ammo");
}

const wchar_t* ManualReloadAmmoCommandClass::GetUICategory() const
{
return CATEGORY_CONTROL;
}

const wchar_t* ManualReloadAmmoCommandClass::GetUIDescription() const
{
return GeneralUtils::LoadStringUnlessMissing("TXT_MANUAL_RELOAD_DESC", L"Manual Reload Ammo");
}

void ManualReloadAmmoCommandClass::Execute(WWKey eInput) const
{
for (const auto& pObj : ObjectClass::CurrentObjects())
{
if (const auto pTechno = abstract_cast<TechnoClass*>(pObj))
{
if (pTechno->Owner->IsControlledByCurrentPlayer())
EventExt::RaiseManualReloadEvent(pTechno);
}
}
}
15 changes: 15 additions & 0 deletions src/Commands/ManualReloadAmmo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include "Commands.h"

// Select next idle harvester
class ManualReloadAmmoCommandClass : public CommandClass
{
public:
// CommandClass
virtual const char* GetName() const override;
virtual const wchar_t* GetUIName() const override;
virtual const wchar_t* GetUICategory() const override;
virtual const wchar_t* GetUIDescription() const override;
virtual void Execute(WWKey eInput) const override;
};
57 changes: 49 additions & 8 deletions src/Ext/Event/Body.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/*
#include "Body.h"

#include <Helpers/Macro.h>
#include <EventClass.h>
#include <HouseClass.h>

#include <Ext/TechnoType/Body.h>
#include <Ext/WarheadType/Body.h>

bool EventExt::AddEvent()
{
Expand All @@ -13,18 +16,59 @@ void EventExt::RespondEvent()
{
switch (this->Type)
{
case EventTypeExt::Sample:
// Place the handler here
case EventTypeExt::ManualReload:
this->RespondToManualReloadEvent();
break;
}
}

void EventExt::RaiseManualReloadEvent(TechnoClass* pTechno)
{
EventExt eventExt {};
eventExt.Type = EventTypeExt::ManualReload;
eventExt.HouseIndex = static_cast<char>(pTechno->Owner->ArrayIndex);
eventExt.Frame = Unsorted::CurrentFrame;
eventExt.ManualReloadEvent.Who = TargetClass(pTechno);
eventExt.AddEvent();
Debug::LogGame("Adding event MANUAL_RELOAD\n");
}

void EventExt::RespondToManualReloadEvent()
{
if (const auto pTechno = this->ManualReloadEvent.Who.As_Techno())
{
if (pTechno->Ammo > 0 && pTechno->IsAlive && !pTechno->Berzerk)
{
const auto pType = pTechno->GetTechnoType();

if (pTechno->Ammo != pType->Ammo)
{
const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pType);

if (pTypeExt->CanManualReload)
{
if (pTypeExt->CanManualReload_DetonateWarhead && pTypeExt->CanManualReload_DetonateConsume <= pTechno->Ammo)
WarheadTypeExt::DetonateAt(pTypeExt->CanManualReload_DetonateWarhead.Get(), pTechno->GetCoords(), pTechno, 1, pTechno->Owner, pTechno->Target);

if (pTypeExt->CanManualReload_ResetROF)
pTechno->RearmTimer.Stop();

pTechno->Ammo = 0;

if (pTechno->WhatAmI() != AbstractType::Aircraft)
pTechno->StartReloading();
}
}
}
}
}

size_t EventExt::GetDataSize(EventTypeExt type)
{
switch (type)
{
case EventTypeExt::Sample:
return sizeof(EventExt::Sample);
case EventTypeExt::ManualReload:
return sizeof(EventExt::ManualReloadEvent);
}

return 0;
Expand All @@ -42,9 +86,7 @@ DEFINE_HOOK(0x4C6CC8, Networking_RespondToEvent, 0x5)
GET(EventExt*, pEvent, ESI);

if (EventExt::IsValidType(pEvent->Type))
{
pEvent->RespondEvent();
}

return 0;
}
Expand Down Expand Up @@ -98,4 +140,3 @@ DEFINE_HOOK(0x64C30E, sub_64BDD0_GetEventSize2, 0x6)

return 0;
}
*/
20 changes: 12 additions & 8 deletions src/Ext/Event/Body.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#pragma once
/*

#include <cstddef>
#include <stdint.h>
#include <TechnoClass.h>
#include <TargetClass.h>

enum class EventTypeExt : uint8_t
{
// Vanilla game used Events from 0x00 to 0x2F
// CnCNet reserved Events from 0x30 to 0x3F
// Ares used Events 0x60 and 0x61

Sample = 0x40, // Sample event, remove it when Phobos needs its own events
ManualReload = 0x80,

FIRST = Sample,
LAST = Sample
FIRST = ManualReload,
LAST = ManualReload
};

#pragma pack(push, 1)
Expand All @@ -27,20 +29,22 @@ class EventExt
{
char DataBuffer[104];

struct Sample
struct ManualReloadEvent
{
char DataBuffer[104];
} Sample;
TargetClass Who;
} ManualReloadEvent;
};

bool AddEvent();
void RespondEvent();

static void RaiseManualReloadEvent(TechnoClass* pTechno);
void RespondToManualReloadEvent();

static size_t GetDataSize(EventTypeExt type);
static bool IsValidType(EventTypeExt type);
};

static_assert(sizeof(EventExt) == 111);
static_assert(offsetof(EventExt, DataBuffer) == 7);
#pragma pack(pop)
*/
10 changes: 10 additions & 0 deletions src/Ext/TechnoType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,11 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->BuildLimitGroup_ExtraLimit_MaxCount.Read(exINI, pSection, "BuildLimitGroup.ExtraLimit.MaxCount");
this->BuildLimitGroup_ExtraLimit_MaxNum.Read(exINI, pSection, "BuildLimitGroup.ExtraLimit.MaxNum");

this->CanManualReload.Read(exINI, pSection, "CanManualReload");
this->CanManualReload_ResetROF.Read(exINI, pSection, "CanManualReload.ResetROF");
this->CanManualReload_DetonateWarhead.Read(exINI, pSection, "CanManualReload.DetonateWarhead");
this->CanManualReload_DetonateConsume.Read(exINI, pSection, "CanManualReload.DetonateConsume");

this->NoTurret_TrackTarget.Read(exINI, pSection, "NoTurret.TrackTarget");

this->Wake.Read(exINI, pSection, "Wake");
Expand Down Expand Up @@ -849,6 +854,11 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)
.Process(this->BuildLimitGroup_ExtraLimit_MaxCount)
.Process(this->BuildLimitGroup_ExtraLimit_MaxNum)

.Process(this->CanManualReload)
.Process(this->CanManualReload_ResetROF)
.Process(this->CanManualReload_DetonateWarhead)
.Process(this->CanManualReload_DetonateConsume)

.Process(this->NoTurret_TrackTarget)

.Process(this->Wake)
Expand Down
10 changes: 10 additions & 0 deletions src/Ext/TechnoType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ class TechnoTypeExt
ValueableVector<int> BuildLimitGroup_ExtraLimit_MaxCount;
Valueable<int> BuildLimitGroup_ExtraLimit_MaxNum;

Valueable<bool> CanManualReload;
Valueable<bool> CanManualReload_ResetROF;
Valueable<WarheadTypeClass*> CanManualReload_DetonateWarhead;
Valueable<int> CanManualReload_DetonateConsume;

Nullable<bool> NoTurret_TrackTarget;

Nullable<AnimTypeClass*> Wake;
Expand Down Expand Up @@ -471,6 +476,11 @@ class TechnoTypeExt
, BuildLimitGroup_ExtraLimit_MaxCount {}
, BuildLimitGroup_ExtraLimit_MaxNum { 0 }

, CanManualReload { false }
, CanManualReload_ResetROF { true }
, CanManualReload_DetonateWarhead {}
, CanManualReload_DetonateConsume { 0 }

, NoTurret_TrackTarget {}

, Wake { }
Expand Down