Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(gameclient): takeover click only for human and takeover seats

Olcay Seygan1386a03a85aa
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp
index fd4087860..812ccbc26 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp
@@ -59,6 +59,7 @@
#include "GameClient/SelectionPriority.h"
#include "GameClient/SelectionXlat.h"
#include "GameClient/TerrainVisual.h"
+#include "GameNetwork/GameInfo.h"
#include "GameNetwork/NetworkInterface.h"
#ifdef _INTERNAL
@@ -81,6 +82,26 @@ static Bool TheHurtSelectionMode = false;
static Bool TheDebugSelectionMode = false;
#endif
+//-----------------------------------------------------------------------------
+/** The takeover click is for the seats the skirmish screen gave a person: your own and the Human
+ * (takeover) opponents. A computer seat can be human too, when no skirmish scripts were found for
+ * its general, and clicking one of those used to hand you the enemy's base. */
+static Bool isHumanSeat( const Player *p )
+{
+ if (TheGameInfo == NULL)
+ return FALSE;
+ for (Int i = 0; i < MAX_SLOTS; ++i)
+ {
+ AsciiString name;
+ name.format("player%d", i);
+ if (p->getPlayerNameKey() != NAMEKEY(name))
+ continue;
+ const GameSlot *slot = TheGameInfo->getConstSlot(i);
+ return slot != NULL && (slot->isHuman() || slot->isTakeover());
+ }
+ return FALSE;
+}
+
//-----------------------------------------------------------------------------
static Bool currentlyLookingForSelection( )
{
@@ -434,10 +455,9 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
}
// with attack move or guard armed a left drag draws the order line over in CommandXlat, so
- // no selection box grows under it. Classic draws no lines: its left drag is always the box
- const Bool leftDragIsOrder = !TheGlobalData->isClassicMouse()
- && TheInGameUI->isLineOrderArmed()
- && TheInGameUI->getSelectCount() > 0;
+ // no selection box grows under it, whichever mouse is set. A drag with no key armed is the box
+ const Bool leftDragIsOrder = TheInGameUI->isLineOrderArmed()
+ && TheInGameUI->getSelectCount() > 0;
if (m_leftMouseButtonIsDown && !leftDragIsOrder)
{
ICoord2D delta;
@@ -790,14 +810,16 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa
/* Single-player test hook: a click that is not a command (nothing of yours selected, or
nothing to do to it) on a base that nobody is driving - a Human seat from the skirmish
- screen, or a player you already took over - hands you that player, so the command bar,
- the money and the shroud become its own. Computer opponents are left alone; only
- Shift-Ctrl-T takes one of those. */
+ screen, or your own seat after you left it - hands you that player, so the command bar,
+ the money and the shroud become its own. Computer seats are left alone, one you took
+ and left again and one that ended up human for want of scripts included (isHumanSeat);
+ only Shift-Ctrl-T takes those. takeControlOfPlayer refuses network games and replays, and the logic
+ drops the message in a network game whoever sends it. */
for (DrawableListIt cit = drawablesThatWillSelect.begin(); cit != drawablesThatWillSelect.end(); ++cit)
{
Object *clicked = (*cit) ? (*cit)->getObject() : NULL;
Player *owner = clicked ? clicked->getControllingPlayer() : NULL;
- if (owner == NULL || owner->getPlayerType() != PLAYER_HUMAN)
+ if (owner == NULL || owner->getPlayerType() != PLAYER_HUMAN || !isHumanSeat(owner))
continue;
if (takeControlOfPlayer(owner))