64 lines
2.9 KiB
C
64 lines
2.9 KiB
C
#pragma once
|
|
|
|
#include "fleet_generator.h"
|
|
#include "bot_player.h"
|
|
#include "game_engine.h"
|
|
#include "session_manager.h"
|
|
#include "statistics.h"
|
|
|
|
typedef uint8_t lifecycle_result_t;
|
|
enum {
|
|
LIFECYCLE_RESULT_OK,
|
|
LIFECYCLE_RESULT_INVALID_NAME,
|
|
LIFECYCLE_RESULT_INVALID_ROLE,
|
|
LIFECYCLE_RESULT_INVALID_MODE,
|
|
LIFECYCLE_RESULT_UNAUTHORIZED,
|
|
LIFECYCLE_RESULT_NO_PLAYER_SLOT,
|
|
LIFECYCLE_RESULT_NO_SPECTATOR_SLOT,
|
|
LIFECYCLE_RESULT_FORBIDDEN_ROLE,
|
|
LIFECYCLE_RESULT_WRONG_PHASE,
|
|
LIFECYCLE_RESULT_NOT_YOUR_TURN,
|
|
LIFECYCLE_RESULT_CELL_ALREADY_SHOT,
|
|
LIFECYCLE_RESULT_INVALID_COORDINATE,
|
|
LIFECYCLE_RESULT_STALE_GAME,
|
|
LIFECYCLE_RESULT_GENERATION_FAILED,
|
|
};
|
|
|
|
typedef uint8_t recovery_reason_t;
|
|
enum { RECOVERY_REASON_NONE, RECOVERY_REASON_SESSION_LEFT, RECOVERY_REASON_PROFILE_RESET, RECOVERY_REASON_GAME_RESET };
|
|
|
|
typedef struct {
|
|
game_engine_t game;
|
|
session_manager_t sessions;
|
|
cumulative_statistics_t cumulative[kPlayerCapacity];
|
|
random_source_t random;
|
|
bot_player_t bot;
|
|
scheduler_t bot_scheduler;
|
|
bool bot_reserved;
|
|
bool rematch_confirmed[kPlayerCapacity];
|
|
uint32_t next_game_id;
|
|
uint32_t recovery_generation;
|
|
recovery_reason_t recovery_reason;
|
|
} game_lifecycle_t;
|
|
|
|
void game_lifecycle_init(game_lifecycle_t *lifecycle, random_source_t random);
|
|
void game_lifecycle_set_bot_scheduler(game_lifecycle_t *lifecycle, scheduler_t scheduler);
|
|
lifecycle_result_t game_lifecycle_join(game_lifecycle_t *lifecycle, role_t requested_role, const char *name,
|
|
uint8_t *session_index);
|
|
lifecycle_result_t game_lifecycle_resume(game_lifecycle_t *lifecycle,
|
|
const uint8_t token[kSessionTokenBytes], uint8_t *session_index);
|
|
lifecycle_result_t game_lifecycle_disconnect(game_lifecycle_t *lifecycle, uint8_t session_index);
|
|
lifecycle_result_t game_lifecycle_leave(game_lifecycle_t *lifecycle, uint8_t session_index);
|
|
lifecycle_result_t game_lifecycle_reset(game_lifecycle_t *lifecycle, uint8_t session_index, uint32_t game_id);
|
|
void game_lifecycle_set_recovery_reason(game_lifecycle_t *lifecycle, recovery_reason_t reason);
|
|
lifecycle_result_t game_lifecycle_configure(game_lifecycle_t *lifecycle, uint8_t session_index,
|
|
uint32_t game_id, game_mode_t mode);
|
|
lifecycle_result_t game_lifecycle_start(game_lifecycle_t *lifecycle, uint8_t session_index, uint32_t game_id);
|
|
lifecycle_result_t game_lifecycle_shot(game_lifecycle_t *lifecycle, uint8_t session_index, uint32_t game_id,
|
|
coordinate_t coordinate, shot_result_t *result);
|
|
lifecycle_result_t game_lifecycle_rematch(game_lifecycle_t *lifecycle, uint8_t session_index, uint32_t game_id);
|
|
lifecycle_result_t game_lifecycle_abort(game_lifecycle_t *lifecycle, uint8_t session_index, uint32_t game_id);
|
|
bool game_lifecycle_bot_take_turn(game_lifecycle_t *lifecycle);
|
|
|
|
_Static_assert(sizeof(game_lifecycle_t) <= 1600, "lifecycle state grew beyond fixed budget");
|