Skip to content

Commit 019775a

Browse files
authored
Various fixes for observer (#49)
* Stop observer assignment by SpawnLocation * fix multi-observer colors & flag * fix MPDefeated logic for multi-observer * Accept any spawn location < 0 as random
1 parent b41beba commit 019775a

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

src/Misc/Observers.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,30 @@ DEFINE_HOOK(0x5C98E5, MultiplayerScore__5C98A0_SkipObserverScore, 0x6)
4444
}
4545

4646
// Use correct colors in diplomacy menu for all observers
47-
DEFINE_HOOK(0x65838B, RadarClass__658330_SetObserverColorScheme, 0x5)
47+
DEFINE_HOOK(0x6583B2, RadarClass__658330_SetObserverColorScheme, 0x5)
4848
{
4949
if (!Spawner::Enabled)
5050
return 0;
5151

52+
enum { SelectLightGrey = 0x658397 };
5253
GET(HouseClass*, pHouse, EBX);
53-
R->EAX<HouseClass*>(pHouse->IsInitiallyObserver() ? HouseClass::CurrentPlayer : (HouseClass*) nullptr);
54-
return 0x65838B + 0x5;
54+
55+
if (pHouse->IsHumanPlayer && pHouse->IsInitiallyObserver())
56+
return SelectLightGrey;
57+
58+
return 0;
5559
}
5660

5761
// Use correct flag icon in diplomacy menu for all observers
58-
DEFINE_HOOK(0x65846D, RadarClass__658330_SetObserverFlag, 0x6)
62+
DEFINE_HOOK(0x658473, RadarClass__658330_SetObserverFlag, 0x5)
5963
{
6064
if (!Spawner::Enabled)
6165
return 0;
6266

6367
GET(HouseClass*, pHouse, EBX);
64-
R->ECX(pHouse->IsInitiallyObserver() ? -3 : pHouse->Type->ArrayIndex);
68+
if (pHouse->IsHumanPlayer && pHouse->Defeated && pHouse->IsInitiallyObserver())
69+
R->ECX(HouseTypeClass::TempObserverID);
70+
6571
return 0x658485;
6672
}
6773

src/Spawner/Spawner.Hook.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ DEFINE_HOOK(0x4FC262, HouseClass__MPlayerDefeated_SkipObserver, 0x6)
129129
if (!MPlayerDefeated::pThis)
130130
return 0;
131131

132-
return MPlayerDefeated::pThis->IsObserver()
132+
return MPlayerDefeated::pThis->IsInitiallyObserver()
133133
? ProcEpilogue
134134
: 0;
135135
}
@@ -169,8 +169,24 @@ DEFINE_HOOK(0x4FC57C, HouseClass__MPlayerDefeated_CheckAliveAndHumans, 0x7)
169169
GET_STACK(int, numHumans, STACK_OFFSET(0xC0, -0xA8));
170170
GET_STACK(int, numAlive, STACK_OFFSET(0xC0, -0xAC));
171171

172-
bool continueWithoutHumans = Spawner::GetConfig()->ContinueWithoutHumans ||
173-
(SessionClass::IsSkirmish() && HouseClass::CurrentPlayer->IsInitiallyObserver());
172+
bool continueWithoutHumans = Spawner::GetConfig()->ContinueWithoutHumans
173+
|| MPlayerDefeated::pThis->IsInitiallyObserver();
174+
175+
if (!continueWithoutHumans && !MPlayerDefeated::pThis->IsHumanPlayer)
176+
{
177+
bool isHasAliveHumanPlayers = false;
178+
for (const auto pHouse : HouseClass::Array)
179+
{
180+
if (pHouse->IsHumanPlayer && !pHouse->Defeated)
181+
{
182+
isHasAliveHumanPlayers = true;
183+
break;
184+
}
185+
}
186+
187+
if (!isHasAliveHumanPlayers)
188+
continueWithoutHumans = true;
189+
}
174190

175191
if (numAlive > 1 && (numHumans != 0 || continueWithoutHumans))
176192
{

src/Spawner/Spawner.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,7 @@ void Spawner::AssignHouses()
107107

108108
const auto pHousesConfig = &Spawner::Config->Houses[indexOfHouseArray];
109109
const int nSpawnLocations = pHousesConfig->SpawnLocations;
110-
const bool isObserver = pHouse->IsHumanPlayer && (
111-
pHousesConfig->IsObserver
112-
|| nSpawnLocations == -1
113-
|| nSpawnLocations == 90
114-
);
110+
const bool isObserver = pHouse->IsHumanPlayer && pHousesConfig->IsObserver;
115111

116112
// Set Alliances
117113
for (char i = 0; i < (char)std::size(pHousesConfig->Alliances); ++i)
@@ -145,9 +141,9 @@ void Spawner::AssignHouses()
145141
// Set SpawnLocations
146142
if (!isObserver)
147143
{
148-
pHouse->StartingPoint = (nSpawnLocations != -2)
149-
? std::clamp(nSpawnLocations, 0, 7)
150-
: nSpawnLocations;
144+
pHouse->StartingPoint = (nSpawnLocations < 0)
145+
? -2
146+
: std::clamp(nSpawnLocations, 0, 7);
151147
}
152148
else
153149
{
@@ -268,7 +264,7 @@ bool Spawner::StartScenario(const char* pScenarioName)
268264
if (pPlayer->IsObserver && !Spawner::Config->IsCampaign)
269265
{
270266
if (pNode->Country < 0)
271-
pNode->Country = -3;
267+
pNode->Country = HouseTypeClass::TempObserverID;
272268

273269
pNode->SpectatorFlag = 0xFFFFFFFF;
274270

0 commit comments

Comments
 (0)