Skip to content

Commit

Permalink
Make 'autogame' work in *debug* mp games.
Browse files Browse the repository at this point in the history
fixes ticket:3369
  • Loading branch information
vexed committed Apr 28, 2012
1 parent 8f91346 commit 0ad220b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/keybind.cpp
Expand Up @@ -93,6 +93,8 @@
#include "research.h"
#include "template.h"
#include "qtscript.h"
#include "multigifts.h"

/*
KeyBind.c
Holds all the functions that can be mapped to a key.
Expand Down Expand Up @@ -147,10 +149,21 @@ void kf_AutoGame(void)
return;
}
#endif
// obviously, this just sets a flag, the AI scripts still need to take care of the request
// FIXME: move to script side
NetPlay.players[selectedPlayer].autoGame = !NetPlay.players[selectedPlayer].autoGame;
CONPRINTF(ConsoleString, (ConsoleString, "autogame request is %s. AI script *must* support this command!", NetPlay.players[selectedPlayer].autoGame ? "Enabled" : "Disabled"));
if (game.type == CAMPAIGN)
{
CONPRINTF(ConsoleString, (ConsoleString, "Not possible with the campaign!"));
return;
}
// Notify all human players that we are trying to enable autogame
for (int i = 0; i < MAX_PLAYERS; i++)
{
if(NetPlay.players[i].allocated)
{
sendGift(AUTOGAME_GIFT, i);
}
}

CONPRINTF(ConsoleString, (ConsoleString, "autogame request has been sent to all players. AI script *must* support this command!"));
}

void kf_ToggleMissionTimer( void )
Expand Down
39 changes: 38 additions & 1 deletion src/multigifts.cpp
Expand Up @@ -62,7 +62,7 @@
static void recvGiftDroids (uint8_t from, uint8_t to, uint32_t droidID);
static void sendGiftDroids (uint8_t from, uint8_t to);
static void giftResearch (uint8_t from, uint8_t to, bool send);

static void giftAutoGame(uint8_t from, uint8_t to, bool send);
///////////////////////////////////////////////////////////////////////////////
// gifts..

Expand Down Expand Up @@ -105,6 +105,10 @@ bool recvGift(NETQUEUE queue)
audioTrack = ID_POWER_TRANSMIT;
giftPower(from, to, droidID, false);
break;
case AUTOGAME_GIFT:
audioTrack = ID_SOUND_NEXUS_SYNAPTIC_LINK;
giftAutoGame(from, to, false);
break;
default:
debug(LOG_ERROR, "recvGift: Unknown Gift recvd");
return false;
Expand Down Expand Up @@ -141,6 +145,10 @@ bool sendGift(uint8_t type, uint8_t to)
audioTrack = ID_POWER_TRANSMIT;
giftPower(selectedPlayer, to, 0, true);
break;
case AUTOGAME_GIFT:
giftAutoGame(selectedPlayer, to, true);
return true;
break;
default:
debug( LOG_ERROR, "Unknown Gift sent" );

Expand All @@ -154,6 +162,35 @@ bool sendGift(uint8_t type, uint8_t to)
return true;
}

static void giftAutoGame(uint8_t from, uint8_t to, bool send)
{
uint32_t dummy = 0;

if (send)
{
uint8_t subType = AUTOGAME_GIFT;

NETbeginEncode(NETgameQueue(selectedPlayer), GAME_GIFT);
NETuint8_t(&subType);
NETuint8_t(&from);
NETuint8_t(&to);
NETuint32_t(&dummy);
NETend();
debug(LOG_SYNC, "We (%d) are telling %d we want to enable/disable a autogame", from, to);
}
// If we are recieving the "gift"
else
{
if (to == selectedPlayer)
{
NetPlay.players[from].autoGame = !NetPlay.players[from].autoGame ;
CONPRINTF(ConsoleString, (ConsoleString, "%s has %s the autoGame command", getPlayerName(from), NetPlay.players[from].autoGame ? "Enabled" : "Disabled"));
debug(LOG_SYNC, "We (%d) are being told that %d has %s autogame", selectedPlayer, from, NetPlay.players[from].autoGame ? "Enabled" : "Disabled");
}
}
}


// ////////////////////////////////////////////////////////////////////////////
// give radar information
void giftRadar(uint8_t from, uint8_t to, bool send)
Expand Down
1 change: 1 addition & 0 deletions src/multigifts.h
Expand Up @@ -48,5 +48,6 @@ extern void giftRadar (uint8_t from, uint8_t to, bool send);
#define RESEARCH_GIFT 3
#define POWER_GIFT 4
#define STRUCTURE_GIFT 5 // Unused
#define AUTOGAME_GIFT 6 // Notify others that we are now being controled by the AI

#endif // __INCLUDED_SRC_MULTIGIFTS_H__

0 comments on commit 0ad220b

Please sign in to comment.