Add a new command to reverse turn order (#3802)

This commit is contained in:
ctrlaltca 2019-08-28 02:04:27 +02:00 committed by Zach H
parent 013137c418
commit f54165025e
13 changed files with 113 additions and 7 deletions

View file

@ -38,6 +38,7 @@ SET(PROTO_FILES
command_replay_download.proto
command_replay_modify_match.proto
command_reveal_cards.proto
command_reverse_turn.proto
command_roll_die.proto
command_set_active_phase.proto
command_set_card_attr.proto
@ -88,6 +89,7 @@ SET(PROTO_FILES
event_remove_from_list.proto
event_replay_added.proto
event_reveal_cards.proto
event_reverse_turn.proto
event_roll_die.proto
event_room_say.proto
event_server_complete_list.proto
@ -172,7 +174,7 @@ target_link_libraries(cockatrice_protocol ${cockatrice_protocol_LIBS})
# ubuntu uses an outdated package for protobuf, 3.1.0 is required
if(${Protobuf_VERSION} VERSION_LESS "3.1.0")
# remove unused parameter and misleading indentation warnings when compiling to avoid errors
set(CMAKE_CXX_FLAGS_DEBUG
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -Wno-unused-parameter -Wno-misleading-indentation")
message(WARNING "Outdated protobuf version found (${Protobuf_VERSION} < 3.1.0), "
"disabled warnings to avoid compilation errors.")

View file

@ -0,0 +1,8 @@
syntax = "proto2";
import "game_commands.proto";
message Command_ReverseTurn {
extend GameCommand {
optional Command_ReverseTurn ext = 1034;
}
}

View file

@ -0,0 +1,9 @@
syntax = "proto2";
import "game_event.proto";
message Event_ReverseTurn {
extend GameEvent {
optional Event_ReverseTurn ext = 2021;
}
optional bool reversed = 1;
}

View file

@ -35,6 +35,7 @@ message GameCommand {
CHANGE_ZONE_PROPERTIES = 1031;
UNCONCEDE = 1032;
JUDGE = 1033;
REVERSE_TURN = 1034;
}
extensions 100 to max;
}

View file

@ -30,6 +30,7 @@ message GameEvent {
DUMP_ZONE = 2018;
STOP_DUMP_ZONE = 2019;
CHANGE_ZONE_PROPERTIES = 2020;
REVERSE_TURN = 2021;
}
optional sint32 player_id = 1 [default = -1];
extensions 100 to max;

View file

@ -66,7 +66,8 @@ Server_Game::Server_Game(const ServerInfo_User &_creatorInfo,
onlyRegistered(_onlyRegistered), spectatorsAllowed(_spectatorsAllowed),
spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk),
spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0), startTimeOfThisGame(0),
secondsElapsed(0), firstGameStarted(false), startTime(QDateTime::currentDateTime()), gameMutex(QMutex::Recursive)
secondsElapsed(0), firstGameStarted(false), turnOrderReversed(false), startTime(QDateTime::currentDateTime()),
gameMutex(QMutex::Recursive)
{
currentReplay = new GameReplay;
currentReplay->set_replay_id(room->getServer()->getDatabaseInterface()->getNextReplayId());
@ -657,9 +658,17 @@ void Server_Game::nextTurn()
if (activePlayer != -1)
listPos = keys.indexOf(activePlayer);
do {
++listPos;
if (listPos == keys.size())
listPos = 0;
if (turnOrderReversed) {
--listPos;
if (listPos < 0) {
listPos = keys.size() - 1;
}
} else {
++listPos;
if (listPos == keys.size()) {
listPos = 0;
}
}
} while (players.value(keys[listPos])->getSpectator() || players.value(keys[listPos])->getConceded());
setActivePlayer(keys[listPos]);

View file

@ -68,6 +68,7 @@ private:
int inactivityCounter;
int startTimeOfThisGame, secondsElapsed;
bool firstGameStarted;
bool turnOrderReversed;
QDateTime startTime;
QTimer *pingClock;
QList<GameReplay *> replayList;
@ -185,6 +186,10 @@ public:
{
return secondsElapsed;
}
bool reverseTurnOrder()
{
return turnOrderReversed = !turnOrderReversed;
}
void createGameJoinedEvent(Server_Player *player, ResponseContainer &rc, bool resuming);

View file

@ -35,6 +35,7 @@
#include "pb/command_next_turn.pb.h"
#include "pb/command_ready_start.pb.h"
#include "pb/command_reveal_cards.pb.h"
#include "pb/command_reverse_turn.pb.h"
#include "pb/command_roll_die.pb.h"
#include "pb/command_set_active_phase.pb.h"
#include "pb/command_set_card_attr.pb.h"
@ -60,6 +61,7 @@
#include "pb/event_move_card.pb.h"
#include "pb/event_player_properties_changed.pb.h"
#include "pb/event_reveal_cards.pb.h"
#include "pb/event_reverse_turn.pb.h"
#include "pb/event_roll_die.pb.h"
#include "pb/event_set_card_attr.pb.h"
#include "pb/event_set_card_counter.pb.h"
@ -1990,6 +1992,30 @@ Response::ResponseCode Server_Player::cmdChangeZoneProperties(const Command_Chan
}
}
Response::ResponseCode
Server_Player::cmdReverseTurn(const Command_ReverseTurn & /*cmd*/, ResponseContainer & /*rc*/, GameEventStorage &ges)
{
if (spectator) {
return Response::RespFunctionNotAllowed;
}
if (!game->getGameStarted()) {
return Response::RespGameNotStarted;
}
if (conceded) {
return Response::RespContextError;
}
bool reversedTurn = game->reverseTurnOrder();
Event_ReverseTurn event;
event.set_reversed(reversedTurn);
ges.enqueueGameEvent(event, playerId);
return Response::RespOk;
}
Response::ResponseCode
Server_Player::processGameCommand(const GameCommand &command, ResponseContainer &rc, GameEventStorage &ges)
{
@ -2096,7 +2122,9 @@ Server_Player::processGameCommand(const GameCommand &command, ResponseContainer
case GameCommand::JUDGE:
return cmdJudge(command.GetExtension(Command_Judge::ext), rc, ges);
break;
case GameCommand::REVERSE_TURN:
return cmdReverseTurn(command.GetExtension(Command_ReverseTurn::ext), rc, ges);
break;
default:
return Response::RespInvalidCommand;
}

View file

@ -57,6 +57,7 @@ class Command_SetActivePhase;
class Command_DumpZone;
class Command_StopDumpZone;
class Command_RevealCards;
class Command_ReverseTurn;
class Command_MoveCard;
class Command_SetSideboardPlan;
class Command_DeckSelect;
@ -228,6 +229,8 @@ public:
cmdStopDumpZone(const Command_StopDumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode
cmdReverseTurn(const Command_ReverseTurn & /*cmd*/, ResponseContainer & /*rc*/, GameEventStorage &ges);
Response::ResponseCode
cmdChangeZoneProperties(const Command_ChangeZoneProperties &cmd, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode processGameCommand(const GameCommand &command, ResponseContainer &rc, GameEventStorage &ges);