Skip to content

Commit 90ddb0c

Browse files
committed
Replicate in Generals
1 parent 3063bf7 commit 90ddb0c

File tree

4 files changed

+120
-38
lines changed

4 files changed

+120
-38
lines changed

Generals/Code/GameEngine/Include/Common/MessageStream.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ class GameMessage : public MemoryPoolObject
315315
MSG_META_DEMO_BEGIN_ADJUST_FOV, ///< enter adjust-FOV mode
316316
MSG_META_DEMO_END_ADJUST_FOV, ///< exit adjust-FOV mode
317317
MSG_META_DEMO_LOCK_CAMERA_TO_PLANES, ///< lock camera to airborne thingies
318-
MSG_META_DEMO_REMOVE_PREREQ, ///< Turn of Prerequisite checks in building legality
319-
MSG_META_DEMO_INSTANT_BUILD, ///< All building is with a timer of 1
320-
MSG_META_DEMO_FREE_BUILD, ///< All building is for 0 money
318+
MSG_META_DEMO_REMOVE_PREREQ, ///< Turn off Prerequisite checks in building legality, works in MULTIPLAYER for all humans
319+
MSG_META_DEMO_INSTANT_BUILD, ///< All building is with a timer of 1, works in MULTIPLAYER for all humans
320+
MSG_META_DEMO_FREE_BUILD, ///< All building is for 0 money, works in MULTIPLAYER for all humans
321321
MSG_META_DEMO_RUNSCRIPT1, ///< run script named "KEY_F1"
322322
MSG_META_DEMO_RUNSCRIPT2, ///< run script named "KEY_F2"
323323
MSG_META_DEMO_RUNSCRIPT3, ///< run script named "KEY_F3"
@@ -377,10 +377,10 @@ class GameMessage : public MemoryPoolObject
377377
MSG_META_DEMO_TOGGLE_THREATDEBUG, ///< Toggle the threat debugger on/off
378378
MSG_META_DEMO_TOGGLE_CASHMAPDEBUG, ///< Toggle the cash map debugger on/off
379379
MSG_META_DEMO_TOGGLE_GRAPHICALFRAMERATEBAR, ///< Toggle the graphical framerate bar on/off
380-
MSG_META_DEMO_GIVE_ALL_SCIENCES, ///< grant all grantable sciences
381-
MSG_META_DEMO_GIVE_RANKLEVEL, ///< up one RankLevel
382-
MSG_META_DEMO_TAKE_RANKLEVEL, ///< up one RankLevel
383-
MSG_META_DEMO_GIVE_SCIENCEPURCHASEPOINTS, ///< give yourself an SPP (but no rank change)
380+
MSG_META_DEMO_GIVE_ALL_SCIENCES, ///< grant all available sciences, works in MULTIPLAYER for all humans
381+
MSG_META_DEMO_GIVE_RANKLEVEL, ///< up one rank level
382+
MSG_META_DEMO_TAKE_RANKLEVEL, ///< up one rank level
383+
MSG_META_DEMO_GIVE_SCIENCEPURCHASEPOINTS, ///< give a science purchase point (but no rank change)
384384
MSG_META_DEBUG_TOGGLE_NETWORK, ///< toggle between having and not having network traffic.
385385
MSG_META_DEBUG_DUMP_PLAYER_OBJECTS, ///< Dump numbers of objects owned by each player to the script debug window
386386
MSG_META_DEBUG_DUMP_ALL_PLAYER_OBJECTS, ///< Dump numbers of objects owned by each player to the script debug window, and additional object info

Generals/Code/GameEngine/Include/Common/Player.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,17 @@ class Player : public Snapshot
310310
#if defined(RTS_DEBUG)
311311
/// Prereq disabling cheat key
312312
void toggleIgnorePrereqs(){ m_DEMO_ignorePrereqs = !m_DEMO_ignorePrereqs; }
313+
void enableIgnorePrereqs(Bool enable) { m_DEMO_ignorePrereqs = enable; }
313314
Bool ignoresPrereqs() const { return m_DEMO_ignorePrereqs; }
314315

315316
/// No cost building cheat key
316317
void toggleFreeBuild(){ m_DEMO_freeBuild = !m_DEMO_freeBuild; }
318+
void enableFreeBuild(Bool enable) { m_DEMO_freeBuild = enable; }
317319
Bool buildsForFree() const { return m_DEMO_freeBuild; }
318320

319321
/// No time building cheat key
320322
void toggleInstantBuild(){ m_DEMO_instantBuild = !m_DEMO_instantBuild; }
323+
void enableInstantBuild(Bool enable) { m_DEMO_instantBuild = enable; }
321324
Bool buildsInstantly() const { return m_DEMO_instantBuild; }
322325
#endif
323326

Generals/Code/GameEngine/Source/Common/MessageStream.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,13 @@ Bool isInvalidDebugCommand( GameMessage::Type t )
987987
{
988988
switch (t)
989989
{
990+
case GameMessage::MSG_META_DEMO_REMOVE_PREREQ:
991+
case GameMessage::MSG_META_DEMO_INSTANT_BUILD:
992+
case GameMessage::MSG_META_DEMO_FREE_BUILD:
993+
case GameMessage::MSG_META_DEMO_GIVE_ALL_SCIENCES:
994+
// Usable in multiplayer!
995+
return false;
996+
990997
case GameMessage::MSG_META_DEMO_INSTANT_QUIT:
991998
case GameMessage::MSG_META_DEMO_SWITCH_TEAMS:
992999
case GameMessage::MSG_META_DEMO_SWITCH_TEAMS_BETWEEN_CHINA_USA:
@@ -997,9 +1004,6 @@ Bool isInvalidDebugCommand( GameMessage::Type t )
9971004
case GameMessage::MSG_META_DEMO_TOGGLE_SPECIAL_POWER_DELAYS:
9981005
case GameMessage::MSG_META_DEMO_TIME_OF_DAY:
9991006
case GameMessage::MSG_META_DEMO_LOCK_CAMERA_TO_PLANES:
1000-
case GameMessage::MSG_META_DEMO_REMOVE_PREREQ:
1001-
case GameMessage::MSG_META_DEMO_INSTANT_BUILD:
1002-
case GameMessage::MSG_META_DEMO_FREE_BUILD:
10031007
case GameMessage::MSG_META_DEMO_RUNSCRIPT1:
10041008
case GameMessage::MSG_META_DEMO_RUNSCRIPT2:
10051009
case GameMessage::MSG_META_DEMO_RUNSCRIPT3:
@@ -1013,7 +1017,6 @@ Bool isInvalidDebugCommand( GameMessage::Type t )
10131017
case GameMessage::MSG_META_DEMO_DESHROUD:
10141018
case GameMessage::MSG_META_DEBUG_GIVE_VETERANCY:
10151019
case GameMessage::MSG_META_DEBUG_TAKE_VETERANCY:
1016-
//#pragma MESSAGE ("WARNING - DEBUG key in multiplayer!")
10171020
case GameMessage::MSG_META_DEMO_ADD_CASH:
10181021
case GameMessage::MSG_META_DEBUG_INCR_ANIM_SKATE_SPEED:
10191022
case GameMessage::MSG_META_DEBUG_DECR_ANIM_SKATE_SPEED:
@@ -1036,7 +1039,6 @@ Bool isInvalidDebugCommand( GameMessage::Type t )
10361039
case GameMessage::MSG_DEBUG_HURT_OBJECT:
10371040
case GameMessage::MSG_DEBUG_KILL_OBJECT:
10381041
case GameMessage::MSG_META_DEMO_GIVE_SCIENCEPURCHASEPOINTS:
1039-
case GameMessage::MSG_META_DEMO_GIVE_ALL_SCIENCES:
10401042
case GameMessage::MSG_META_DEMO_GIVE_RANKLEVEL:
10411043
case GameMessage::MSG_META_DEMO_TAKE_RANKLEVEL:
10421044
case GameMessage::MSG_META_DEBUG_WIN:

Generals/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp

Lines changed: 103 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include "GameLogic/ExperienceTracker.h"
6969
#include "GameLogic/GameLogic.h"
7070
#include "GameLogic/Module/BodyModule.h"
71+
#include "GameLogic/Module/ProductionUpdate.h"
7172
#include "GameLogic/Object.h"
7273
#include "GameLogic/PartitionManager.h"
7374
#include "GameLogic/ScriptEngine.h"
@@ -123,7 +124,65 @@ void printObjects(Object *obj, void *userData)
123124
TheScriptEngine->AppendDebugMessage(line, FALSE);
124125
}
125126

126-
#endif
127+
#endif // defined(RTS_DEBUG)
128+
129+
130+
#if defined(RTS_DEBUG) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)
131+
132+
void giveAllSciences(Player* player)
133+
{
134+
// cheese festival: do NOT imitate this code. it is for debug purposes only.
135+
std::vector<AsciiString> v = TheScienceStore->friend_getScienceNames();
136+
for (size_t i = 0; i < v.size(); ++i)
137+
{
138+
ScienceType st = TheScienceStore->getScienceFromInternalName(v[i]);
139+
if (st != SCIENCE_INVALID && TheScienceStore->isScienceGrantable(st))
140+
{
141+
player->grantScience(st);
142+
}
143+
}
144+
}
145+
146+
void objectUnderConstruction(Object* obj, void *underConstruction)
147+
{
148+
if (obj->testStatus(OBJECT_STATUS_UNDER_CONSTRUCTION))
149+
{
150+
*(Bool*)underConstruction = true;
151+
return;
152+
}
153+
154+
ProductionUpdateInterface *pui = ProductionUpdate::getProductionUpdateInterfaceFromObject(obj);
155+
if(pui != NULL && pui->getProductionCount() > 0)
156+
{
157+
*(Bool*)underConstruction = true;
158+
return;
159+
}
160+
}
161+
162+
Bool hasThingsInProduction(Player* player)
163+
{
164+
Bool hasThingInProduction = false;
165+
player->iterateObjects( objectUnderConstruction, &hasThingInProduction );
166+
return hasThingInProduction;
167+
}
168+
169+
Bool hasThingsInProduction(PlayerType playerType)
170+
{
171+
for (Int n = 0; n < ThePlayerList->getPlayerCount(); ++n)
172+
{
173+
Player* player = ThePlayerList->getNthPlayer(n);
174+
if (player->getPlayerType() == playerType)
175+
{
176+
if (hasThingsInProduction(player))
177+
return true;
178+
}
179+
}
180+
return false;
181+
}
182+
183+
#endif // defined(RTS_DEBUG) || defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)
184+
185+
127186
static Bool isSystemMessage( const GameMessage *msg );
128187

129188
enum{ DROPPED_MAX_PARTICLE_COUNT = 1000};
@@ -4119,10 +4178,17 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
41194178
case GameMessage::MSG_META_DEMO_REMOVE_PREREQ:
41204179
{
41214180
// Doesn't make a valid network message
4122-
Player *localPlayer = ThePlayerList->getLocalPlayer();
4123-
localPlayer->toggleIgnorePrereqs();
4181+
// In multiplayer, all clients need to enable this cheat at the same time, otherwise game will mismatch
4182+
Bool enable = !ThePlayerList->getLocalPlayer()->ignoresPrereqs();
4183+
4184+
for (Int n = 0; n < ThePlayerList->getPlayerCount(); ++n)
4185+
{
4186+
Player* player = ThePlayerList->getNthPlayer(n);
4187+
if (player->getPlayerType() == PLAYER_HUMAN)
4188+
player->enableIgnorePrereqs(enable);
4189+
}
41244190

4125-
if (localPlayer->ignoresPrereqs())
4191+
if (enable)
41264192
TheInGameUI->messageNoFormat( TheGameText->FETCH_OR_SUBSTITUTE("GUI:DebugIgnorePrereqOn", L"Ignore Prerequisites is ON") );
41274193
else
41284194
TheInGameUI->messageNoFormat( TheGameText->FETCH_OR_SUBSTITUTE("GUI:DebugIgnorePrereqOff", L"Ignore Prerequisites is OFF") );
@@ -4136,15 +4202,25 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
41364202
case GameMessage::MSG_META_DEMO_INSTANT_BUILD:
41374203
{
41384204
// Doesn't make a valid network message
4139-
Player *localPlayer = ThePlayerList->getLocalPlayer();
4140-
localPlayer->toggleInstantBuild();
4205+
// In multiplayer, all clients need to enable this cheat at the same time, otherwise game will mismatch
4206+
if (!TheGameLogic->isInMultiplayerGame() || !hasThingsInProduction(PLAYER_HUMAN))
4207+
{
4208+
Bool enable = !ThePlayerList->getLocalPlayer()->buildsInstantly();
41414209

4142-
if (localPlayer->buildsInstantly())
4143-
TheInGameUI->messageNoFormat( TheGameText->FETCH_OR_SUBSTITUTE("GUI:DebugInstantBuildOn", L"Instant Build is ON") );
4144-
else
4145-
TheInGameUI->messageNoFormat( TheGameText->FETCH_OR_SUBSTITUTE("GUI:DebugInstantBuildOff", L"Instant Build is OFF") );
4210+
for (Int n = 0; n < ThePlayerList->getPlayerCount(); ++n)
4211+
{
4212+
Player* player = ThePlayerList->getNthPlayer(n);
4213+
if (player->getPlayerType() == PLAYER_HUMAN)
4214+
player->enableInstantBuild(enable);
4215+
}
41464216

4147-
disp = DESTROY_MESSAGE;
4217+
if (enable)
4218+
TheInGameUI->messageNoFormat( TheGameText->FETCH_OR_SUBSTITUTE("GUI:DebugInstantBuildOn", L"Instant Build is ON") );
4219+
else
4220+
TheInGameUI->messageNoFormat( TheGameText->FETCH_OR_SUBSTITUTE("GUI:DebugInstantBuildOff", L"Instant Build is OFF") );
4221+
4222+
disp = DESTROY_MESSAGE;
4223+
}
41484224
break;
41494225
}
41504226

@@ -4153,10 +4229,17 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
41534229
case GameMessage::MSG_META_DEMO_FREE_BUILD:
41544230
{
41554231
// Doesn't make a valid network message
4156-
Player *localPlayer = ThePlayerList->getLocalPlayer();
4157-
localPlayer->toggleFreeBuild();
4232+
// In multiplayer, all clients need to enable this cheat at the same time, otherwise game will mismatch
4233+
Bool enable = !ThePlayerList->getLocalPlayer()->buildsForFree();
4234+
4235+
for (Int n = 0; n < ThePlayerList->getPlayerCount(); ++n)
4236+
{
4237+
Player* player = ThePlayerList->getNthPlayer(n);
4238+
if (player->getPlayerType() == PLAYER_HUMAN)
4239+
player->enableFreeBuild(enable);
4240+
}
41584241

4159-
if (localPlayer->buildsForFree())
4242+
if (enable)
41604243
TheInGameUI->messageNoFormat( TheGameText->FETCH_OR_SUBSTITUTE("GUI:DebugFreeBuildOn", L"Free Build is ON") );
41614244
else
41624245
TheInGameUI->messageNoFormat( TheGameText->FETCH_OR_SUBSTITUTE("GUI:DebugFreeBuildOff", L"Free Build is OFF") );
@@ -4352,20 +4435,14 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
43524435
//-----------------------------------------------------------------------------------------
43534436
case GameMessage::MSG_META_DEMO_GIVE_ALL_SCIENCES:
43544437
{
4355-
Player *player = ThePlayerList->getLocalPlayer();
4356-
if (player)
4438+
// In multiplayer, all clients need to enable this cheat at the same time, otherwise game will mismatch
4439+
for (Int n = 0; n < ThePlayerList->getPlayerCount(); ++n)
43574440
{
4358-
// cheese festival: do NOT imitate this code. it is for debug purposes only.
4359-
std::vector<AsciiString> v = TheScienceStore->friend_getScienceNames();
4360-
for (size_t i = 0; i < v.size(); ++i)
4361-
{
4362-
ScienceType st = TheScienceStore->getScienceFromInternalName(v[i]);
4363-
if (st != SCIENCE_INVALID && TheScienceStore->isScienceGrantable(st))
4364-
{
4365-
player->grantScience(st);
4366-
}
4367-
}
4441+
Player* player = ThePlayerList->getNthPlayer(n);
4442+
if (player->getPlayerType() == PLAYER_HUMAN)
4443+
giveAllSciences(player);
43684444
}
4445+
43694446
TheInGameUI->messageNoFormat( TheGameText->FETCH_OR_SUBSTITUTE("GUI:DebugGiveAllSciences", L"Granting all sciences!") );
43704447
disp = DESTROY_MESSAGE;
43714448
break;

0 commit comments

Comments
 (0)