So today first up I decided I'd start working on turn system. Given that GameMode is only on the server, I concluded that the decision of which player gets first turn should be my first job. With that in mind I spent about 3 hours compiler bashing and googling trying to figure out how to a) get a list of players in game mode and b) print that data meaningfully. About two hours in after I finally managed to get this little snippet done.
auto players = this->GetGameState<AcppGameState>()->PlayerArray;
auto playercount = players.Num();
UE_LOG(LogTemp, Warning, TEXT("Player array contains %c players."), playercount);
Unfortunately the output from that in UE4 was less than useful.
I also battled pretty hard because I was getting an error about PlayerController being unable to spawn even though I hadn't made a change to PlayerController.
Turns out that one was caused by me failing to include cppPlayerController.h in cppGameMode.h. It wasn't an issue until I tried to do something involving playercontrollers I think. It's frustrating how meaningless the error messages can be. I was getting one about having to derefernce the players.Num reference using &, when in fact I'd forgotten I had to use players.Num(). You would think the compiler would be a bit more helpful in that case.
Once I had that fixed and realised how unhelpful my efforts on printing a count on the playercontroller array was, I decided to move in a different direction and see if I could print Names obtained from the player controllers instead. After much more googling, compiler bashing and swearing I finally got this code snippet.
When the game runs now it outputs
LogTemp: Warning: Game state has now been loaded
LogTemp: Warning: Player controller is now loaded
LogTemp: Warning: The game has started
LogTemp: Warning: Player found with name -2034984760.
So now I know I can get a list of players, I'll justchoose a player randomly and figure out how to pass that information along to the gamestate module (I could probably put it in playerstate, but at this point I don't think it matters) so that each client is aware of who is currently has control on the board. Since game state is being loaded before BeginPlay is called I'll have to put a variable in GameState that contains the player in control.
Ended up having a lot of trouble generating a random number and plugging it into the array (since there was only player in the array it was pretty much an exercise in futility anyway) so after about an hour of playing around I gave up on that and decided just to force the first player in the array as going first for now and I'll randomise it later. Added a string into GameState to contain the name of the player to make first move and BeginPlay now stores the chosen player there.
At this point I'm getting mentally exhausted. Turns out my c++ skills are actually nowhere near where they need to be. Maybe I should have done this in blueprints. Maybe I'll improve over the next few days. I need to take a break at this point for sure. Might swing back later and take a crack and doing a FinishTurn function in GameMode or a card basetype. I'll put another post up tomorrow detailing how I went.
--Pillboxing