Technically refactored.

This commit is contained in:
2021-11-14 22:42:10 -08:00
parent 54d01b5ed6
commit 9b4acae63c
74 changed files with 1161 additions and 744 deletions

View File

@@ -0,0 +1,15 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "action.h"
queueaction_t * pokerGameActionAdd(pokergame_t *game) {
queueaction_t *action;
action = queueAdd(&game->scene.conversation.actionQueue);
action->data = (void *)game;
return action;
}

View File

@@ -0,0 +1,19 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../../../libs.h"
#include "../../../display/animation/queue.h"
#include "../pokergame.h"
/**
* Adds an action to the poker game scene's queue.
*
* @param game Game to add the action to.
* @return Action that was added to the game.
*/
queueaction_t * pokerGameActionAdd(pokergame_t *game);

View File

@@ -0,0 +1,89 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "bet.h"
void _pokerGameActionBetOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
) {
bool isHuman;
pokergame_t *game = (pokergame_t *)action->data;
// Reset the UI state.
isHuman = game->poker.better == POKER_WORLD_HUMAN_INDEX;
// if(isHuman) pokerUiBetShow(&game->ui);
}
void _pokerGameActionBetOnUpdate(
queue_t *queue, queueaction_t *action, uint8_t i
) {
// Restack
bool isHuman;
bool turnMade = false;
pokerturn_t turn;
pokergame_t *game = (pokergame_t *)action->data;
pokerdiscussiondata_t discussion;
// Are they human?
isHuman = game->poker.better == POKER_WORLD_HUMAN_INDEX;
// Handle as an AI
if(isHuman) {
// turn = game->ui.betTurn;
// turnMade = game->ui.betTurnMade;
turn = pokerTurnGetForPlayer(&game->poker, game->poker.better);
turnMade = true;
} else {
turn = pokerTurnGetForPlayer(&game->poker, game->poker.better);
turnMade = true;
}
// Now decide if we should do something.
if(!turnMade) return;
// Perform the action
pokerTurnAction(&game->poker, game->poker.better, turn);
// Speak
discussion.reason = pokerDiscussionGetTypeFromTurnType(turn.type);
discussion.poker = game;
discussion.playerCause = game->poker.better;
pokerDiscussionQueue(&discussion);
// Next.
queueNext(queue);
}
void _pokerGameActionBetOnEnd(
queue_t *queue, queueaction_t *action, uint8_t i
) {
pokergame_t *game = (pokergame_t *)action->data;
// // Get which player is remaining to move.
game->poker.better = pokerBetGetNextPlayer(&game->poker);
// Restack
pokerGameActionRestackAdd(game);
// Are we waiting on any players?
if(game->poker.better != 0xFF) {
pokerGameActionLookAdd(game, game->poker.better);
pokerGameActionBetAdd(game);
return;
}
// Not waiting, do next action.
pokerGameActionFlopAdd(game);
}
queueaction_t * pokerGameActionBetAdd(pokergame_t *game) {
queueaction_t *action = pokerGameActionAdd(game);
action->onStart = &_pokerGameActionBetOnStart;
action->onUpdate = &_pokerGameActionBetOnUpdate;
action->onEnd = &_pokerGameActionBetOnEnd;
return action;
}

View File

@@ -0,0 +1,34 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../../../libs.h"
#include "../../../poker/bet.h"
#include "../../../poker/turn.h"
#include "../pokerdiscussion.h"
#include "action.h"
#include "restack.h"
#include "winner.h"
#include "flop.h"
/** Callback when the bet action is updated. */
void _pokerGameActionBetOnUpdate(
queue_t *queue, queueaction_t *action, uint8_t i
);
/** Callback for when the bet action ends. */
void _pokerGameActionBetOnEnd(
queue_t *queue, queueaction_t *action, uint8_t i
);
/**
* Queues the bet action to the queue.
*
* @param game Game to queue onto.
* @return The action that was queued.
*/
queueaction_t * pokerGameActionBetAdd(pokergame_t *game);

View File

@@ -0,0 +1,81 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "flop.h"
void _pokerGameActionFlopOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
) {
pokergame_t *game = (pokergame_t *)action->data;
pokerdiscussiondata_t discussion;
bool hasDoneFlop;
// Prep convo
discussion.poker = game;
// Get how many players are left in the round.
if(pokerInRoundGetCount(&game->poker) > 1) {// Still more than 1
// Reset all the players
pokerResetBettingRound(&game->poker);
// Do actual flop action
hasDoneFlop = true;
switch(game->poker.communitySize) {
case 0x00:
pokerDealerBurn(&game->poker, POKER_FLOP_BURN_COUNT);
pokerDealerTurn(&game->poker, POKER_FLOP_CARD_COUNT);
break;
case POKER_FLOP_CARD_COUNT:
pokerDealerBurn(&game->poker, POKER_FLOP_BURN_COUNT);
pokerDealerTurn(&game->poker, POKER_TURN_CARD_COUNT);
break;
case POKER_FLOP_CARD_COUNT+POKER_TURN_CARD_COUNT:
pokerDealerBurn(&game->poker, POKER_FLOP_BURN_COUNT);
pokerDealerTurn(&game->poker, POKER_RIVER_CARD_COUNT);
break;
default:
hasDoneFlop = false;
break;
}
// Is there any flop "left to do" ?
if(hasDoneFlop) {
// Talk about it.
discussion.reason = POKER_DISCUSSION_REASON_FLOP;
pokerDiscussionQueue(&discussion);
// Now, get the count of players left to bet. If "everyone is all in" then
// this will be 0 and no actual betting needs to happen.
if(pokerBetGetRemainingBetterCount(&game->poker) > 0x01) {
// Begin betting.
game->poker.better = pokerBetGetNextPlayer(&game->poker);
pokerGameActionLookAdd(game, game->poker.better);
pokerGameActionBetAdd(game);
} else {
//No actual players to bet, so add the following flop instead.
pokerGameActionFlopAdd(game);
}
// Do next action.
queueNext(queue);
return;
}
}
// Done betting
pokerGameActionRestackAdd(game);
pokerGameActionWinnerAdd(game);
// Do next action
queueNext(queue);
}
queueaction_t * pokerGameActionFlopAdd(pokergame_t *game) {
queueaction_t *action = pokerGameActionAdd(game);
action->onStart = &_pokerGameActionFlopOnStart;
return action;
}

View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../../../libs.h"
#include "../pokerdiscussion.h"
#include "action.h"
#include "restack.h"
#include "winner.h"
#include "bet.h"
/** Callback that is fired when the flop action starts */
void _pokerGameActionFlopOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
);
/**
* Queues a flop action on to the queue.
*
* @param game Game to queue on to.
* @return queueaction_t*
*/
queueaction_t * pokerGameActionFlopAdd(pokergame_t *game);

View File

@@ -0,0 +1,24 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "look.h"
void _pokerGameActionLookOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
) {
pokergame_t *game = (pokergame_t *)action->data;
pokergameactiondata_t *data = game->actionData + i;
pokerWorldLookAtPlayer(&game->scene, data->lookAtPlayer);
queueNext(queue);
}
queueaction_t * pokerGameActionLookAdd(pokergame_t *game, uint8_t playerIndex) {
queueaction_t *action = pokerGameActionAdd(game);
action->onStart = &_pokerGameActionLookOnStart;
game->actionData[action->index].lookAtPlayer = playerIndex;
return action;
}

View File

@@ -0,0 +1,26 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "action.h"
#include "../../../libs.h"
#include "../../../display/animation/queue.h"
#include "../pokerworld.h"
/** Callback when the look action starts. */
void _pokerGameActionLookOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
);
/**
* Queues a look action to the poker game.
*
* @param game Game to add to.
* @param playerIndex The player index to look at.
* @return The queued action.
*/
queueaction_t * pokerGameActionLookAdd(pokergame_t *game, uint8_t playerIndex);

View File

@@ -0,0 +1,22 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "restack.h"
void _pokerGameActionRestackOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
) {
pokergame_t *game = (pokergame_t *)action->data;
pokerGameQueueRestack(game);
queueNext(queue);
}
queueaction_t * pokerGameActionRestackAdd(pokergame_t *game) {
queueaction_t *action = pokerGameActionAdd(game);
action->onStart = &_pokerGameActionRestackOnStart;
return action;
}

View File

@@ -0,0 +1,26 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../../../libs.h"
#include "../../../util/math.h"
#include "action.h"
#include "../pokergame.h"
#include "../../../display/animation/queue.h"
/** Callback for when the queue restack action stars. */
void _pokerGameActionRestackOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
);
/**
* Adds a restack action to the queue.
*
* @param game Game to restack.
* @return The queued action.
*/
queueaction_t * pokerGameActionRestackAdd(pokergame_t *game);

View File

@@ -0,0 +1,51 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "round.h"
void _pokerGameActionRoundOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
) {
queueNext(queue);
}
void _pokerGameActionRoundOnEnd(queue_t *queue,queueaction_t *action,uint8_t i){
pokerdiscussiondata_t data;
pokergame_t *game = (pokergame_t *)action->data;
// Start the round
pokerResetRound(&game->poker);
pokerDealerNew(&game->poker);
pokerTakeBlinds(&game->poker);
// Speak
data.poker = game;
data.reason = POKER_DISCUSSION_REASON_ROUND_START;
pokerDiscussionQueue(&data);
// Speak
data.reason = POKER_DISCUSSION_REASON_BLINDS_TAKEN;
pokerDiscussionQueue(&data);
// Deal
cardShuffle(game->poker.deck, CARD_DECK_SIZE);
pokerDealAllPlayers(&game->poker, POKER_PLAYER_HAND_SIZE_MAX);
// Speak
data.reason = POKER_DISCUSSION_REASON_DEAL;
pokerDiscussionQueue(&data);
// Begin Betting Round
pokerGameActionBetAdd(game);
}
queueaction_t * pokerGameActionRoundAdd(pokergame_t *game) {
queueaction_t *action = pokerGameActionAdd(game);
action->onStart = &_pokerGameActionRoundOnStart;
action->onEnd = &_pokerGameActionRoundOnEnd;
return action;
}

View File

@@ -0,0 +1,29 @@
// Copyright (c) 2021 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "../../../libs.h"
#include "../../../poker/player.h"
#include "../../../poker/dealer.h"
#include "../../../poker/poker.h"
#include "action.h"
#include "../pokerdiscussion.h"
#include "bet.h"
/** Callback that is fired when the round start event starts. */
void _pokerGameActionRoundOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
);
/** Callback that is fired when the round action ends. */
void _pokerGameActionRoundOnEnd(queue_t *queue,queueaction_t *action,uint8_t i);
/**
* Queues the round starting action onto the game. Handles talking VN logic.
*
* @param game Game to add to.
* @return The queued action.
*/
queueaction_t * pokerGameActionRoundAdd(pokergame_t *game);

View File

@@ -0,0 +1,46 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "start.h"
void _pokerGameActionStartOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
) {
queueNext(queue);
}
void _pokerGameActionStartOnEnd(queue_t *queue,queueaction_t *action,uint8_t i){
pokerdiscussiondata_t data;
uint8_t j, k;
pokergame_t *game = (pokergame_t *)action->data;
//TODO: Init Players betterer.
pokerInit(&game->poker);
pokerSetBlinds(
&game->poker, POKER_BET_BLIND_SMALL_DEFAULT, POKER_BET_BLIND_BIG_DEFAULT
);
for(j = 0; j < POKER_PLAYER_COUNT_MAX; j++) {
k = pokerPlayerAdd(&game->poker);
pokerPlayerChipsAdd(game->poker.players+k, POKER_BET_PLAYER_CHIPS_DEFAULT);
}
pokerDealerSet(&game->poker, game->poker.playerCount/2);
// Say that.
data.poker = game;
data.reason = POKER_DISCUSSION_REASON_MATCH_START;
pokerDiscussionQueue(&data);
// Begin Round.
pokerGameActionRoundAdd(game);
}
queueaction_t * pokerGameActionStartAdd(pokergame_t *game) {
queueaction_t *action = pokerGameActionAdd(game);
action->onStart = &_pokerGameActionStartOnStart;
action->onEnd = &_pokerGameActionStartOnEnd;
return action;
}

View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../../../libs.h"
#include "../../../vn/conversation/talk.h"
#include "../../../display/animation/queue.h"
#include "../pokerdiscussion.h"
#include "round.h"
#include "action.h"
/** Callback fired when the game action first starts */
void _pokerGameActionStartOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
);
/** Callback fired when the game start action ends */
void _pokerGameActionStartOnEnd(queue_t *queue,queueaction_t *action,uint8_t i);
/**
* Queues a match starting action onto the queue, also handles game logic for
* speaking VN style.
*
* @param game Game to add to.
* @return The queued action.
*/
queueaction_t * pokerGameActionStartAdd(pokergame_t *game);

View File

@@ -0,0 +1,41 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "winner.h"
void _pokerGameActionWinnerOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
) {
pokerdiscussiondata_t discussion;
pokergame_t *game = (pokergame_t *)action->data;
// Calculate the winners
// TODO: Calculate Winners
// pokerWinnerCalculate(
// &game->poker.winner,
// &game->poker.dealer,
// game->poker.players
// );
// Action
// pokerGameWin(&game->poker);
// Say stuff
discussion.reason = POKER_DISCUSSION_REASON_BETTING_DONE;
discussion.poker = game;
pokerDiscussionQueue(&discussion);
// Begin next round.
pokerGameActionRoundAdd(game);
queueNext(queue);
}
queueaction_t * pokerGameActionWinnerAdd(pokergame_t *game) {
queueaction_t *action = pokerGameActionAdd(game);
action->onStart = &_pokerGameActionWinnerOnStart;
return action;
}

View File

@@ -0,0 +1,25 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../../../libs.h"
#include "../pokerdiscussion.h"
#include "action.h"
#include "round.h"
/** Callback to fire when the winner starts */
void _pokerGameActionWinnerOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
);
/**
* Queue a winning game action.
*
* @param game Game to queue for.
* @return The queued winning action.
*/
queueaction_t * pokerGameActionWinnerAdd(pokergame_t *game);