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

[Customized] Fast access vehicle #1475

Open
wants to merge 2 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 @@ -375,6 +375,7 @@ This page lists all the individual contributions to the project by their author.
- Fix `LimboKill` not working reliably
- Allow using waypoints, area guard and attack move with aircraft
- Fix `Stop` command not working so well in some cases
- Fast access vehicle
- **Ollerus**
- Build limit group enhancement
- Customizable rocker amplitude
Expand Down
15 changes: 15 additions & 0 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,21 @@ Convert.HumanToComputer = ; TechnoType
Convert.ComputerToHuman = ; TechnoType
```

### Fast access vehicle

- Now you can let passengers quickly enter or leave the transport vehicles (useless for buildings) without queuing. Defaults to `[General]` -> `NoQueueUpToEnter` or `NoQueueUpToUnload`.

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

[SOMEUNIT] ; UnitType
NoQueueUpToEnter= ; boolean
NoQueueUpToUnload= ; boolean
```

## Terrain

### Destroy animation & sound
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,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)
- Fast access vehicle (by CrimRecya)
- Unit `Speed` setting now accepts floating point values (by Starkku)

Vanilla fixes:
Expand Down
4 changes: 4 additions & 0 deletions src/Ext/Rules/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
this->HeightShadowScaling_MinScale.Read(exINI, GameStrings::AudioVisual, "HeightShadowScaling.MinScale");

this->ExtendedAircraftMissions.Read(exINI, GameStrings::General, "ExtendedAircraftMissions");
this->NoQueueUpToEnter.Read(exINI, GameStrings::General, "NoQueueUpToEnter");
this->NoQueueUpToUnload.Read(exINI, GameStrings::General, "NoQueueUpToUnload");

this->AllowParallelAIQueues.Read(exINI, "GlobalControls", "AllowParallelAIQueues");
this->ForbidParallelAIQueues_Aircraft.Read(exINI, "GlobalControls", "ForbidParallelAIQueues.Aircraft");
Expand Down Expand Up @@ -333,6 +335,8 @@ void RulesExt::ExtData::Serialize(T& Stm)
.Process(this->HeightShadowScaling)
.Process(this->HeightShadowScaling_MinScale)
.Process(this->ExtendedAircraftMissions)
.Process(this->NoQueueUpToEnter)
.Process(this->NoQueueUpToUnload)
.Process(this->AllowParallelAIQueues)
.Process(this->ForbidParallelAIQueues_Aircraft)
.Process(this->ForbidParallelAIQueues_Building)
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 @@ -94,6 +94,8 @@ class RulesExt
double AirShadowBaseScale_log;

Valueable<bool> ExtendedAircraftMissions;
Valueable<bool> NoQueueUpToEnter;
Valueable<bool> NoQueueUpToUnload;

Valueable<bool> AllowParallelAIQueues;
Valueable<bool> ForbidParallelAIQueues_Aircraft;
Expand Down Expand Up @@ -226,6 +228,8 @@ class RulesExt
, AirShadowBaseScale_log { 0.693376137 }

, ExtendedAircraftMissions { false }
, NoQueueUpToEnter { false }
, NoQueueUpToUnload { false }

, AllowParallelAIQueues { true }
, ForbidParallelAIQueues_Aircraft { false }
Expand Down
212 changes: 212 additions & 0 deletions src/Ext/Techno/Hooks.Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,215 @@ DEFINE_HOOK(0x710552, TechnoClass_SetOpenTransportCargoTarget_ShareTarget, 0x6)

return 0;
}

#pragma region NoQueueUpToEnterAndUnload

bool __fastcall CanEnterNow(UnitClass* pTransport, FootClass* pPassenger)
{
const auto pOwner = pTransport->Owner;

if (!pOwner || !pOwner->IsAlliedWith(pPassenger) || pTransport->IsBeingWarpedOut())
return false;

if (pPassenger->IsMindControlled() || pPassenger->ParasiteEatingMe)
return false;

const auto pManager = pPassenger->CaptureManager;

if (pManager && pManager->IsControllingSomething())
return false;

const auto passengerSize = pPassenger->GetTechnoType()->Size;
const auto pTransportType = pTransport->Type;

if (passengerSize > pTransportType->SizeLimit)
return false;

const auto maxSize = pTransportType->Passengers;
const auto predictSize = pTransport->Passengers.GetTotalSize() + static_cast<int>(passengerSize);
const auto pLink = pTransport->GetNthLink();
const auto needCalculate = pLink && pLink != pPassenger;

if (needCalculate)
{
const auto linkCell = pLink->GetCoords();
const auto tranCell = pTransport->GetCoords();

// When the most important passenger is close, need to prevent overlap
if (abs(linkCell.X - tranCell.X) <= 384 && abs(linkCell.Y - tranCell.Y) <= 384)
return (predictSize <= (maxSize - pLink->GetTechnoType()->Size));
}

const auto remain = maxSize - predictSize;

if (remain < 0)
return false;

if (needCalculate && remain < static_cast<int>(pLink->GetTechnoType()->Size))
{
// Avoid passenger moving forward, resulting in overlap with transport and create invisible barrier
pLink->SendToFirstLink(RadioCommand::NotifyUnlink);
pLink->EnterIdleMode(false, true);
}

return true;
}

DEFINE_HOOK(0x51A0D4, InfantryClass_UpdatePosition_NoQueueUpToEnter, 0x6)
{
enum { EnteredThenReturn = 0x51A47E };

GET(InfantryClass* const, pThis, ESI);

if (const auto pDest = abstract_cast<UnitClass*>(pThis->CurrentMission == Mission::Enter ? pThis->Destination : pThis->QueueUpToEnter))
{
if (pDest->Type->Passengers > 0 && TechnoTypeExt::ExtMap.Find(pDest->Type)->NoQueueUpToEnter.Get(RulesExt::Global()->NoQueueUpToEnter))
{
const auto thisCell = pThis->GetCoords();
const auto destCell = pDest->GetCoords();

if (abs(thisCell.X - destCell.X) <= 384 && abs(thisCell.Y - destCell.Y) <= 384)
{
if (CanEnterNow(pDest, pThis)) // Replace send radio command: QueryCanEnter
{
if (const auto pTag = pDest->AttachedTag)
pTag->RaiseEvent(TriggerEvent::EnteredBy, pThis, CellStruct::Empty);

pThis->ArchiveTarget = nullptr;
pThis->OnBridge = false;
pThis->MissionAccumulateTime = 0;
pThis->GattlingValue = 0;
pThis->CurrentGattlingStage = 0;

if (const auto pMind = pThis->MindControlledBy)
{
if (const auto pManager = pMind->CaptureManager)
pManager->FreeUnit(pThis);
}

pThis->Limbo();

if (pDest->Type->OpenTopped)
pDest->EnteredOpenTopped(pThis);

pThis->Transporter = pDest;
pDest->AddPassenger(pThis);
pThis->Undiscover();

pThis->QueueUpToEnter = nullptr; // Added, to prevent passengers from wanting to get on after getting off
pThis->SetSpeedPercentage(0.0); // Added, to stop the passengers and let OpenTopped work normally

return EnteredThenReturn;
}
}
}
}

return 0;
}

DEFINE_HOOK(0x73A5EA, UnitClass_UpdatePosition_NoQueueUpToEnter, 0x5)
{
enum { EnteredThenReturn = 0x73A78C };

GET(UnitClass* const, pThis, EBP);

if (const auto pDest = abstract_cast<UnitClass*>(pThis->CurrentMission == Mission::Enter ? pThis->Destination : pThis->QueueUpToEnter))
{
if (pDest->Type->Passengers > 0 && TechnoTypeExt::ExtMap.Find(pDest->Type)->NoQueueUpToEnter.Get(RulesExt::Global()->NoQueueUpToEnter))
{
const auto thisCell = pThis->GetCoords();
const auto destCell = pDest->GetCoords();

if (abs(thisCell.X - destCell.X) <= 384 && abs(thisCell.Y - destCell.Y) <= 384)
{
if (CanEnterNow(pDest, pThis)) // Replace send radio command: QueryCanEnter
{
// I don't know why units have no trigger

pThis->ArchiveTarget = nullptr;
pThis->OnBridge = false;
pThis->MissionAccumulateTime = 0;
pThis->GattlingValue = 0;
pThis->CurrentGattlingStage = 0;

if (const auto pMind = pThis->MindControlledBy)
{
if (const auto pManager = pMind->CaptureManager)
pManager->FreeUnit(pThis);
}

pThis->Limbo();
pDest->AddPassenger(pThis);

if (pDest->Type->OpenTopped)
pDest->EnteredOpenTopped(pThis);

pThis->Transporter = pDest;

if (pThis->Type->OpenTopped)
pThis->SetTargetForPassengers(nullptr);

pThis->Undiscover();

pThis->QueueUpToEnter = nullptr; // Added, to prevent passengers from wanting to get on after getting off
pThis->SetSpeedPercentage(0.0); // Added, to stop the passengers and let OpenTopped work normally

return EnteredThenReturn;
}
}
}
}

return 0;
}

static inline void PlayUnitLeaveTransportSound(UnitClass* pThis)
{
const int sound = pThis->Type->LeaveTransportSound;

if (sound != -1)
VoxClass::PlayAtPos(sound, &pThis->Location);
}

DEFINE_HOOK(0x73DC9C, UnitClass_Mission_Unload_NoQueueUpToUnloadBreak, 0xA)
{
enum { SkipGameCode = 0x73E289 };

GET(UnitClass* const, pThis, ESI);
GET(FootClass* const, pPassenger, EDI);

pPassenger->Undiscover();

// Play the sound when interrupted for some reason
if (TechnoTypeExt::ExtMap.Find(pThis->Type)->NoQueueUpToUnload.Get(RulesExt::Global()->NoQueueUpToUnload))
PlayUnitLeaveTransportSound(pThis);

return SkipGameCode;
}

DEFINE_HOOK(0x73DC1E, UnitClass_Mission_Unload_NoQueueUpToUnloadLoop, 0xA)
{
enum { UnloadLoop = 0x73D8CB, UnloadReturn = 0x73E289 };

GET(UnitClass* const, pThis, ESI);

if (TechnoTypeExt::ExtMap.Find(pThis->Type)->NoQueueUpToUnload.Get(RulesExt::Global()->NoQueueUpToUnload))
{
if (pThis->Passengers.NumPassengers <= pThis->NonPassengerCount)
{
// If unloading is required within one frame, the sound will only be played when the last passenger leaves
PlayUnitLeaveTransportSound(pThis);
pThis->MissionStatus = 4;
return UnloadReturn;
}

R->EBX(0); // Reset
return UnloadLoop;
}

PlayUnitLeaveTransportSound(pThis);
return UnloadReturn;
}

#pragma endregion
7 changes: 7 additions & 0 deletions src/Ext/TechnoType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->BuildLimitGroup_ExtraLimit_Nums.Read(exINI, pSection, "BuildLimitGroup.ExtraLimit.Nums");
this->BuildLimitGroup_ExtraLimit_MaxCount.Read(exINI, pSection, "BuildLimitGroup.ExtraLimit.MaxCount");
this->BuildLimitGroup_ExtraLimit_MaxNum.Read(exINI, pSection, "BuildLimitGroup.ExtraLimit.MaxNum");

this->NoQueueUpToEnter.Read(exINI, pSection, "NoQueueUpToEnter");
this->NoQueueUpToUnload.Read(exINI, pSection, "NoQueueUpToUnload");

this->Wake.Read(exINI, pSection, "Wake");
this->Wake_Grapple.Read(exINI, pSection, "Wake.Grapple");
this->Wake_Sinking.Read(exINI, pSection, "Wake.Sinking");
Expand Down Expand Up @@ -825,6 +829,9 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)
.Process(this->BuildLimitGroup_ExtraLimit_MaxCount)
.Process(this->BuildLimitGroup_ExtraLimit_MaxNum)

.Process(this->NoQueueUpToEnter)
.Process(this->NoQueueUpToUnload)

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

Nullable<bool> NoQueueUpToEnter;
Nullable<bool> NoQueueUpToUnload;

Nullable<AnimTypeClass*> Wake;
Nullable<AnimTypeClass*> Wake_Grapple;
Nullable<AnimTypeClass*> Wake_Sinking;
Expand Down Expand Up @@ -449,6 +452,9 @@ class TechnoTypeExt
, BuildLimitGroup_ExtraLimit_MaxCount {}
, BuildLimitGroup_ExtraLimit_MaxNum { 0 }

, NoQueueUpToEnter {}
, NoQueueUpToUnload {}

, Wake { }
, Wake_Grapple { }
, Wake_Sinking { }
Expand Down
Loading