Skip to content

Commit bbbdc6b

Browse files
committed
core
Update Body.cpp update Update Hooks.cpp
1 parent 3bc76ba commit bbbdc6b

12 files changed

Lines changed: 121 additions & 1 deletion

File tree

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ This page lists all the individual contributions to the project by their author.
815815
- Framework for dynamic sight
816816
- Fix voxel projectile and animation lighting issues
817817
- Export interface for external call
818+
- Auto-remove earliest beacon
818819
- **solar-III (凤九歌)**
819820
- Target scanning delay customization (documentation)
820821
- Skip target scanning function calling for unarmed technos (documentation)

docs/Fixed-or-Improved-Logics.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,17 @@ In `rulesmd.ini`:
400400
AllowDeployControlledMCV=false ; boolean
401401
```
402402

403+
### Auto-remove earliest beacon
404+
405+
- In vanilla, each player can place up to 3 beacons. When all 3 beacon slots are occupied, attempting to place a new beacon does nothing. Now you can make the game automatically remove the earliest-placed beacon to free up a slot for the new one.
406+
- `[General] -> AutoRemoveEarliestBeacon` controls this behavior.
407+
408+
In `rulesmd.ini`:
409+
```ini
410+
[General]
411+
AutoRemoveEarliestBeacon=no ; boolean
412+
```
413+
403414
### Chrono sparkle animation customization & improvements
404415

405416
- It is now possible to customize the frame delay between instances of `[General] -> ChronoSparkle1` animations created on objects being warped by setting `[General] -> ChronoSparkleDisplayDelay`.

docs/Whats-New.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ HideShakeEffects=false ; boolean
598598
- [Customizable Berzerk mission](Fixed-or-Improved-Logics.md#enhanced-berzerk-behavior) (by TaranDahl)
599599
- [Tank Bunker foundation and state update delay improvements](Fixed-or-Improved-Logics.md#tank-bunker-improvements) (by Starkku)
600600
- [Custom cruise missiles](New-or-Enhanced-Logics.md#custom-cruise-missiles) (by Noble_Fish)
601+
- [Auto-remove earliest beacon](Fixed-or-Improved-Logics.md#auto-remove-earliest-beacon) (by TaranDahl)
601602
602603
#### Vanilla fixes:
603604
- Fixed sidebar not updating queued unit numbers when adding or removing units when the production is on hold (by CrimRecya)

docs/locale/zh_CN/LC_MESSAGES/CREDITS.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,6 +2758,9 @@ msgstr "修复了 Voxel 抛射体和动画的光照问题"
27582758
msgid "Export interface for external call"
27592759
msgstr "用于外部调用的导出接口"
27602760

2761+
msgid "Auto-remove earliest beacon"
2762+
msgstr "自动移除最早的信标"
2763+
27612764
msgid "**solar-III (凤九歌)**"
27622765
msgstr "**solar-III(凤九歌)**"
27632766

docs/locale/zh_CN/LC_MESSAGES/Fixed-or-Improved-Logics.po

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,19 @@ msgstr "在原版中你不能将一个被心灵控制的载具部署为 `Constru
19351935
msgid "In `rulesmd.ini`:"
19361936
msgstr "在 `rulesmd.ini`:"
19371937

1938+
msgid "Auto-remove earliest beacon"
1939+
msgstr "自动移除最早的信标"
1940+
1941+
msgid ""
1942+
"In vanilla, each player can place up to 3 beacons. When all 3 beacon slots "
1943+
"are occupied, attempting to place a new beacon does nothing. Now you can "
1944+
"make the game automatically remove the earliest-placed beacon to free up a "
1945+
"slot for the new one."
1946+
msgstr "在原版中,每个玩家最多可以放置 3 个信标。当 3 个信标槽位都被占用时,尝试放置新信标将不起作用。现在你可以让游戏自动移除最早放置的信标,为新信标腾出槽位。"
1947+
1948+
msgid "`[General] -> AutoRemoveEarliestBeacon` controls this behavior."
1949+
msgstr "`[General] -> AutoRemoveEarliestBeacon` 控制此行为。"
1950+
19381951
msgid "Chrono sparkle animation customization & improvements"
19391952
msgstr "超时空闪光动画的自定义与改进"
19401953

docs/locale/zh_CN/LC_MESSAGES/Whats-New.po

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,6 +2052,13 @@ msgid ""
20522052
msgstr ""
20532053
"[坦克碉堡面积和状态更新间隔改进](Fixed-or-Improved-Logics.md#tank-bunker-improvements) (by Starkku)"
20542054

2055+
msgid ""
2056+
"[Auto-remove earliest beacon](Fixed-or-Improved-Logics.md#auto-remove-"
2057+
"earliest-beacon) (by TaranDahl)"
2058+
msgstr ""
2059+
"[自动移除最早的信标](Fixed-or-Improved-Logics.md#auto-remove-earliest-"
2060+
"beacon)(by TaranDahl)"
2061+
20552062
msgid "Vanilla fixes:"
20562063
msgstr "原版问题修复:"
20572064

src/Ext/House/Body.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ void HouseExt::ExtData::Serialize(T& Stm)
712712
.Process(this->FreeRadar)
713713
.Process(this->ForceRadar)
714714
.Process(this->PlayerAutoRepair)
715+
//.Process(this->BeaconsPlacedOrder) beacon is not saved, so this follows it.
715716
;
716717
}
717718

src/Ext/House/Body.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <Utilities/Container.h>
55
#include <Utilities/TemplateDef.h>
66

7+
#include <array>
8+
79
class HouseExt
810
{
911
public:
@@ -69,6 +71,8 @@ class HouseExt
6971

7072
bool PlayerAutoRepair;
7173

74+
std::array<int, 3> BeaconsPlacedOrder;
75+
7276
ExtData(HouseClass* OwnerObject) : Extension<HouseClass>(OwnerObject)
7377
, PowerPlantEnhancers {}
7478
, OwnedLimboDeliveredBuildings {}
@@ -103,6 +107,7 @@ class HouseExt
103107
, FreeRadar(false)
104108
, ForceRadar(false)
105109
, PlayerAutoRepair(true)
110+
, BeaconsPlacedOrder { 0, 0, 0 }
106111
{ }
107112

108113
bool OwnsLimboDeliveredBuilding(BuildingClass* pBuilding) const;

src/Ext/House/Hooks.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
#include "Ext/Building/Body.h"
77
#include <Ext/Event/Body.h>
88

9+
#include <BeaconManagerClass.h>
10+
911
#include <unordered_map>
12+
#include <algorithm>
13+
#include <utility>
1014

1115
// Trigger power recalculation on gain/loss of any techno, not just buildings.
1216
DEFINE_HOOK_AGAIN(0x5025F0, HouseClass_RegisterGain, 0x5) // RegisterLoss
@@ -681,3 +685,72 @@ DEFINE_HOOK(0x45063F, BuildingClass_UpdateRepairSell_PlayerAutoRepair, 0x6)
681685
}
682686

683687
#pragma endregion
688+
689+
#pragma region BeaconOrder
690+
691+
DEFINE_HOOK(0x43131B, BeaconManagerClass_DeleteBeacon_RecordOrder, 0x5)
692+
{
693+
GET(int, beaconIdx, EBX);
694+
GET(int, houseIdx, ECX);
695+
696+
const auto pHouse = HouseClass::Array.GetItem(houseIdx);
697+
const auto pExt = HouseExt::ExtMap.Find(pHouse);
698+
699+
const int oldValue = std::exchange(pExt->BeaconsPlacedOrder[beaconIdx], 0);
700+
701+
if (oldValue != 0)
702+
{
703+
for (int i = 0; i < 3; ++i)
704+
{
705+
if (i != beaconIdx && pExt->BeaconsPlacedOrder[i] > oldValue)
706+
--pExt->BeaconsPlacedOrder[i];
707+
}
708+
}
709+
710+
return 0;
711+
}
712+
713+
DEFINE_HOOK_AGAIN(0x430E5D, BeaconManagerClass_PlaceBeacon_RecordOrder, 0x5)
714+
DEFINE_HOOK(0x430C64, BeaconManagerClass_PlaceBeacon_RecordOrder, 0x5)
715+
{
716+
GET(int, beaconIdx, EAX);
717+
GET(int, houseIdx, EBX);
718+
719+
const auto pHouse = HouseClass::Array.GetItem(houseIdx);
720+
const auto pExt = HouseExt::ExtMap.Find(pHouse);
721+
722+
const int maxVal = std::max({ pExt->BeaconsPlacedOrder[0], pExt->BeaconsPlacedOrder[1], pExt->BeaconsPlacedOrder[2] });
723+
pExt->BeaconsPlacedOrder[beaconIdx] = maxVal + 1;
724+
725+
return 0;
726+
}
727+
728+
DEFINE_HOOK(0x4AC9B2, MouseClass_ToggleBeaconMode_AllUsed, 0x6)
729+
{
730+
GET(bool, canPlace, EAX);
731+
732+
if (canPlace)
733+
return 0x4AC9B8;
734+
735+
const auto pHouse = HouseClass::CurrentPlayer;
736+
const auto pExt = HouseExt::ExtMap.Find(pHouse);
737+
738+
for (int i = 0; i < 3; ++i)
739+
{
740+
if (pExt->BeaconsPlacedOrder[i] == 1)
741+
{
742+
auto pManager = &BeaconManagerClass::Instance;
743+
auto pBeacon = pManager->Beacons[pHouse->ArrayIndex][i];
744+
// Select and delete beacon.
745+
// If you don't select the beacon, the game will not send the IPX packet.
746+
MapClass::UnselectAll();
747+
pBeacon->Bitfield |= 2;
748+
pManager->DeleteBeacon(-1, -1);
749+
break;
750+
}
751+
}
752+
753+
return 0x4AC9B8;
754+
}
755+
756+
#pragma endregion

0 commit comments

Comments
 (0)