Skip to content
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 @@ -662,6 +662,7 @@ This page lists all the individual contributions to the project by their author.
- Toggle per-target warhead effects apply timing
- Extra range for chasing and pre-firing
- Fix an issue that rockets do not consider the destination altitude during climbing
- Replace vanilla repairing with togglable auto repairing
- **solar-III (凤九歌)**
- Target scanning delay customization (documentation)
- Skip target scanning function calling for unarmed technos (documentation)
Expand Down
2 changes: 2 additions & 0 deletions Phobos.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Ext\Cell\Hooks.cpp" />
<ClCompile Include="src\Ext\Event\Body.cpp" />
<ClCompile Include="src\Ext\Infantry\Hooks.cpp" />
<ClCompile Include="src\Ext\Infantry\Hooks.Firing.cpp" />
<ClCompile Include="src\Ext\TechnoType\Hooks.MultiWeapon.cpp" />
Expand Down Expand Up @@ -218,6 +219,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Ext\EBolt\Body.h" />
<ClInclude Include="src\Ext\Event\Body.h" />
<ClInclude Include="src\New\Entity\Ares\RadarJammerClass.h" />
<ClInclude Include="src\New\Type\Affiliated\CreateUnitTypeClass.h" />
<ClInclude Include="src\Blowfish\blowfish.h" />
Expand Down
12 changes: 12 additions & 0 deletions docs/User-Interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,18 @@ In `rulesmd.ini`:
Sidebar.ProducingProgress.Offset=0,0 ; X,Y, pixels relative to default
```

### Replace vanilla repairing with togglable auto repairing

- Now you can replace the vanilla repair method with a togglable auto-repair.
- Pressing repair button or hotkey will no longer change your mouse, but will toggle your auto-repair state on/off.
- When auto-repair state is toggled off, buildings will stop repairing.

In `rulesmd.ini`:
```ini
[General]
ExtendedPlayerRepair=false ; boolean
```

### Specify Sidebar style

- It's now possible to switch hardcoded sidebar button coords to use GDI sidebar coords by setting `Sidebar.GDIPosition`. Defaults to true for first side, false for all others.
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ New:
- Allow techno type considered as other type when recruiting techno for teams (by NetsuNegi)
- Map Action [`511` Undeploy Building to Waypoint](AI-Scripting-and-Mapping.md#undeploy-building-to-waypoint), [`609` Set Radar Mode](AI-Scripting-and-Mapping.md#set-radar-mode), [`610` Set house's `TeamDelays` value](AI-Scripting-and-Mapping.md#set-house-s-teamdelays-value) (by FlyStar)
- Fixed an issue that rockets do not consider the destination altitude during climbing (by TaranDahl)
- [Replace vanilla repairing with togglable auto repairing](User-Interface.md#replace-vanilla-repairing-with-togglable-auto-repairing) (by TaranDahl)

Vanilla fixes:
- Fixed sidebar not updating queued unit numbers when adding or removing units when the production is on hold (by CrimRecya)
Expand Down
50 changes: 44 additions & 6 deletions src/Ext/Event/Body.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/*

#include "Body.h"

#include <Ext/House/Body.h>

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

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

void EventExt::RaiseTogglePlayerAutoRepair()
{
EventExt eventExt {};
eventExt.Type = EventTypeExt::TogglePlayerAutoRepair;
eventExt.HouseIndex = (char)HouseClass::CurrentPlayer->ArrayIndex; // not used
eventExt.Frame = Unsorted::CurrentFrame;
eventExt.AddEvent();
Debug::LogGame("Adding event TOGGLE_PLAYER_AUTOREPAIR\n");
}

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

return 0;
Expand All @@ -35,6 +49,30 @@ bool EventExt::IsValidType(EventTypeExt type)
return (type >= EventTypeExt::FIRST && type <= EventTypeExt::LAST);
}

void EventExt::RespondToTogglePlayerAutoRepair()
{
if (this->HouseIndex >= HouseClass::Array.Count)
return;

if (!RulesExt::Global()->ExtendedPlayerRepair)
return;

auto pHouse = HouseClass::Array.GetItem(this->HouseIndex);
auto pHouseExt = HouseExt::ExtMap.Find(pHouse);
pHouseExt->PlayerAutoRepair = !pHouseExt->PlayerAutoRepair;

if (HouseClass::CurrentPlayer == pHouse)
{
SidebarClass::Instance.SidebarNeedsRedraw = true;
auto pButton = &Make_Global<ShapeButtonClass>(0xB0B3A0);

if (pHouseExt->PlayerAutoRepair)
pButton->TurnOn();
else
pButton->TurnOff();
}
}

// hooks

DEFINE_HOOK(0x4C6CC8, Networking_RespondToEvent, 0x5)
Expand Down Expand Up @@ -98,4 +136,4 @@ DEFINE_HOOK(0x64C30E, sub_64BDD0_GetEventSize2, 0x6)

return 0;
}
*/

21 changes: 12 additions & 9 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 <HouseClass.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
TogglePlayerAutoRepair = 0x40,

FIRST = Sample,
LAST = Sample
FIRST = TogglePlayerAutoRepair,
LAST = TogglePlayerAutoRepair
};

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

struct Sample
{
char DataBuffer[104];
} Sample;
struct TogglePlayerAutoRepair
{ } TogglePlayerAutoRepair;
};

bool AddEvent();
void RespondEvent();

static void RaiseTogglePlayerAutoRepair();
void RespondToTogglePlayerAutoRepair();

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)
*/

1 change: 1 addition & 0 deletions src/Ext/House/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ void HouseExt::ExtData::Serialize(T& Stm)
.Process(this->TeamDelay)
.Process(this->FreeRadar)
.Process(this->ForceRadar)
.Process(this->PlayerAutoRepair)
;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Ext/House/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class HouseExt
bool FreeRadar;
bool ForceRadar;

bool PlayerAutoRepair;

ExtData(HouseClass* OwnerObject) : Extension<HouseClass>(OwnerObject)
, PowerPlantEnhancers {}
, OwnedLimboDeliveredBuildings {}
Expand Down Expand Up @@ -105,6 +107,7 @@ class HouseExt
, TeamDelay(-1)
, FreeRadar(false)
, ForceRadar(false)
, PlayerAutoRepair(false)
{ }

bool OwnsLimboDeliveredBuilding(BuildingClass* pBuilding) const;
Expand Down
54 changes: 54 additions & 0 deletions src/Ext/House/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <Ext/Scenario/Body.h>
#include "Ext/Techno/Body.h"
#include "Ext/Building/Body.h"
#include <Ext/Event/Body.h>

#include <unordered_map>

DEFINE_HOOK(0x508C30, HouseClass_UpdatePower_UpdateCounter, 0x5)
Expand Down Expand Up @@ -528,3 +530,55 @@ DEFINE_HOOK(0x508E17, HouseClass_UpdateRadar_FreeRadar, 0x8)

return Continue;
}

#pragma region PlayerAutoRepair

DEFINE_HOOK(0x536FA0, ToggleRepariModeCommandClass_Execute_PlayerAutoRepair, 0x7)
{
if (!RulesExt::Global()->ExtendedPlayerRepair)
return 0;

EventExt::RaiseTogglePlayerAutoRepair();
return 0x536FAC;
}

DEFINE_HOOK(0x6A78F6, SidebarClass_Update_ToggleRepair, 0x9)
{
if (!RulesExt::Global()->ExtendedPlayerRepair)
MapClass::Instance.SetRepairMode(-1);
else
EventExt::RaiseTogglePlayerAutoRepair();
return 0x6A78FF;
}

DEFINE_HOOK(0x6A7AE1, SidebarClass_Update_RepairButton, 0x6)
{
if (!RulesExt::Global()->ExtendedPlayerRepair)
return 0;

R->AL(HouseExt::ExtMap.Find(HouseClass::CurrentPlayer)->PlayerAutoRepair);
return 0x6A7AE7;
}

DEFINE_HOOK(0x45063F, BuildingClass_UpdateRepairSell_PlayerAutoRepair, 0x6)
{
enum { CanAutoRepair = 0x450659, CanNotAutoRepair = 0x450813 };

if (!RulesExt::Global()->ExtendedPlayerRepair)
return 0;

GET(BuildingClass*, pThis, ESI);

if (HouseExt::ExtMap.Find(pThis->Owner)->PlayerAutoRepair)
{
return CanAutoRepair;
}
else
{
if (pThis->IsBeingRepaired)
pThis->SetRepairState(0);
return CanNotAutoRepair;
}
}

#pragma endregion
3 changes: 3 additions & 0 deletions src/Ext/Rules/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
this->ExtraRange_Prefiring.Read(exINI, GameStrings::General, "ExtraRange.Prefiring");
this->ExtraRange_Prefiring_IncludeBurst.Read(exINI, GameStrings::General, "ExtraRange.Prefiring.IncludeBurst");

this->ExtendedPlayerRepair.Read(exINI, GameStrings::General, "ExtendedPlayerRepair");

// Section AITargetTypes
int itemsCount = pINI->GetKeyCount("AITargetTypes");
for (int i = 0; i < itemsCount; ++i)
Expand Down Expand Up @@ -634,6 +636,7 @@ void RulesExt::ExtData::Serialize(T& Stm)
.Process(this->ExtraRange_FirerMoving)
.Process(this->ExtraRange_Prefiring)
.Process(this->ExtraRange_Prefiring_IncludeBurst)
.Process(this->ExtendedPlayerRepair)
;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Ext/Rules/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ class RulesExt
Valueable<bool> ExtraRange_Prefiring_IncludeBurst;

Valueable<bool> ApplyPerTargetEffectsOnDetonate;

Valueable<bool> ExtendedPlayerRepair;

ExtData(RulesClass* OwnerObject) : Extension<RulesClass>(OwnerObject)
, Storage_TiberiumIndex { -1 }
Expand Down Expand Up @@ -536,6 +538,8 @@ class RulesExt
, ExtraRange_FirerMoving { Leptons(0) }
, ExtraRange_Prefiring { Leptons(0) }
, ExtraRange_Prefiring_IncludeBurst { true }

, ExtendedPlayerRepair { false }
{ }

virtual ~ExtData() = default;
Expand Down