52 lines
2.3 KiB
C
52 lines
2.3 KiB
C
#pragma once
|
|
|
|
#include "fleet_generator.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 struct {
|
|
game_engine_t game;
|
|
session_manager_t sessions;
|
|
cumulative_statistics_t cumulative[kPlayerCapacity];
|
|
random_source_t random;
|
|
bool bot_reserved;
|
|
bool rematch_confirmed[kPlayerCapacity];
|
|
uint32_t next_game_id;
|
|
} game_lifecycle_t;
|
|
|
|
void game_lifecycle_init(game_lifecycle_t *lifecycle, random_source_t random);
|
|
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_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);
|
|
|
|
_Static_assert(sizeof(game_lifecycle_t) <= 1600, "lifecycle state grew beyond fixed budget");
|