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+
127186static Bool isSystemMessage ( const GameMessage *msg );
128187
129188enum { 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