Skip to content

Commit 2c5c071

Browse files
authored
[Dehardcode] Make harvesters do addtional scan after unload (#1642)
### Make harvesters do addtional scan after unload - In vanilla, miners will remember their current location when they reach full load and move to that location after unloading. This makes miners to gradually move deeper into the mine and ignore the closer minerals. - Now you can have the miner search for the nearest mineral again after unloading. If a closer mineral is found, the miner will go to that location instead of the previously recorded location. In `rulesmd.ini`: ```ini [General] HarvesterScanAfterUnload=false ; boolean [SOMEVEHICLE] HarvesterScanAfterUnload= ; boolean, default to [General] -> HarvesterScanAfterUnload ```
1 parent 3412541 commit 2c5c071

File tree

8 files changed

+60
-3
lines changed

8 files changed

+60
-3
lines changed

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ This page lists all the individual contributions to the project by their author.
499499
- Prone speed customization
500500
- RadarInvisible for non-enemy house
501501
- Allow miners do area guard
502+
- Make harvesters do addtional scan after unload
502503
- **tyuah8**:
503504
- Drive/Jumpjet/Ship/Teleport locomotor did not power on when it is un-piggybacked bugfix
504505
- Destroyed unit leaves sensors bugfix

docs/Fixed-or-Improved-Logics.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,20 @@ DeployingAnim.ReverseForUndeploy=true ; boolean
14401440
DeployingAnim.UseUnitDrawer=true ; boolean
14411441
```
14421442

1443+
### Make harvesters do addtional scan after unload
1444+
1445+
- In vanilla, miners will remember their current location when they reach full load and move to that location after unloading. This makes miners to gradually move deeper into the mine and ignore the closer minerals.
1446+
- Now you can have the miner search for the nearest mineral again after unloading. If a closer mineral is found, the miner will go to that location instead of the previously recorded location.
1447+
1448+
In `rulesmd.ini`:
1449+
```ini
1450+
[General]
1451+
HarvesterScanAfterUnload=false ; boolean
1452+
1453+
[SOMEVEHICLE]
1454+
HarvesterScanAfterUnload= ; boolean, default to [General] -> HarvesterScanAfterUnload
1455+
```
1456+
14431457
### Preserve Iron Curtain / Force Shield status on type conversion
14441458

14451459
![image](_static/images/preserve-ic.gif)

docs/Whats-New.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ New:
371371
- Aggressive attack move mission (by CrimRecya)
372372
- Amphibious access vehicle (by CrimRecya)
373373
- Allow miners do area guard (by TaranDahl)
374+
- Make harvesters do addtional scan after unload (by TaranDahl)
374375
375376
Vanilla fixes:
376377
- Fixed sidebar not updating queued unit numbers when adding or removing units when the production is on hold (by CrimRecya)

src/Ext/Rules/Body.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
262262

263263
this->DamagedSpeed.Read(exINI, GameStrings::General, "DamagedSpeed");
264264

265+
this->HarvesterScanAfterUnload.Read(exINI, GameStrings::General, "HarvesterScanAfterUnload");
266+
265267
// Section AITargetTypes
266268
int itemsCount = pINI->GetKeyCount("AITargetTypes");
267269
for (int i = 0; i < itemsCount; ++i)
@@ -482,6 +484,7 @@ void RulesExt::ExtData::Serialize(T& Stm)
482484
.Process(this->ProneSpeed_Crawls)
483485
.Process(this->ProneSpeed_NoCrawls)
484486
.Process(this->DamagedSpeed)
487+
.Process(this->HarvesterScanAfterUnload)
485488
;
486489
}
487490

src/Ext/Rules/Body.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ class RulesExt
217217

218218
Valueable<double> DamagedSpeed;
219219

220+
Valueable<bool> HarvesterScanAfterUnload;
221+
220222
ExtData(RulesClass* OwnerObject) : Extension<RulesClass>(OwnerObject)
221223
, Storage_TiberiumIndex { -1 }
222224
, HarvesterDumpAmount { 0.0f }
@@ -379,6 +381,8 @@ class RulesExt
379381
, ProneSpeed_NoCrawls { 1.5 }
380382

381383
, DamagedSpeed { 0.75 }
384+
385+
, HarvesterScanAfterUnload { false }
382386
{ }
383387

384388
virtual ~ExtData() = default;

src/Ext/TechnoType/Body.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
550550
this->Overload_ParticleSysCount.Read(exINI, pSection, "Overload.ParticleSysCount");
551551

552552
this->Harvester_CanGuardArea.Read(exINI, pSection, "Harvester.CanGuardArea");
553+
this->HarvesterScanAfterUnload.Read(exINI, pSection, "HarvesterScanAfterUnload");
553554

554555
// Ares 0.2
555556
this->RadarJamRadius.Read(exINI, pSection, "RadarJamRadius");
@@ -1018,8 +1019,9 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)
10181019
.Process(this->Overload_DeathSound)
10191020
.Process(this->Overload_ParticleSys)
10201021
.Process(this->Overload_ParticleSysCount)
1021-
1022+
10221023
.Process(this->Harvester_CanGuardArea)
1024+
.Process(this->HarvesterScanAfterUnload)
10231025
;
10241026
}
10251027
void TechnoTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm)

src/Ext/TechnoType/Body.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ class TechnoTypeExt
345345
Valueable<int> Overload_ParticleSysCount;
346346

347347
Valueable<bool> Harvester_CanGuardArea;
348+
Nullable<bool> HarvesterScanAfterUnload;
348349

349350
ExtData(TechnoTypeClass* OwnerObject) : Extension<TechnoTypeClass>(OwnerObject)
350351
, HealthBar_Hide { false }
@@ -643,8 +644,9 @@ class TechnoTypeExt
643644
, Overload_DeathSound {}
644645
, Overload_ParticleSys {}
645646
, Overload_ParticleSysCount { 5 }
646-
647+
647648
, Harvester_CanGuardArea { false }
649+
, HarvesterScanAfterUnload {}
648650
{ }
649651

650652
virtual ~ExtData() = default;

src/Ext/Unit/Hooks.Harvester.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,34 @@ DEFINE_HOOK(0x4D6D34, FootClass_MissionAreaGuard_Miner, 0x5)
3030
auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType());
3131

3232
return pTypeExt->Harvester_CanGuardArea && pThis->Owner->IsControlledByHuman() ? GoGuardArea : 0;
33-
}
33+
}
34+
35+
#pragma region HarvesterScanAfterUnload
36+
37+
DEFINE_HOOK(0x73E730, UnitClass_MissionHarvest_HarvesterScanAfterUnload, 0x5)
38+
{
39+
GET(UnitClass* const, pThis, EBP);
40+
GET(AbstractClass* const, pFocus, EAX);
41+
42+
// Focus is set when the harvester is fully loaded and go home.
43+
if (pFocus && TechnoTypeExt::ExtMap.Find(pThis->Type)->HarvesterScanAfterUnload.Get(RulesExt::Global()->HarvesterScanAfterUnload))
44+
{
45+
auto cellBuffer = CellStruct::Empty;
46+
const auto pCellStru = pThis->ScanForTiberium(&cellBuffer, RulesClass::Instance->TiberiumLongScan / Unsorted::LeptonsPerCell, 0);
47+
48+
if (*pCellStru != CellStruct::Empty)
49+
{
50+
const auto pCell = MapClass::Instance.TryGetCellAt(*pCellStru);
51+
const auto distFromTiberium = pCell ? pThis->DistanceFrom(pCell) : -1;
52+
const auto distFromFocus = pThis->DistanceFrom(pFocus);
53+
54+
// Check if pCell is better than focus.
55+
if (distFromTiberium > 0 && distFromTiberium < distFromFocus)
56+
R->EAX(pCell);
57+
}
58+
}
59+
60+
return 0;
61+
}
62+
63+
#pragma endregion

0 commit comments

Comments
 (0)