13 #include "penguins-version.h"
47 auto menu_file =
new wxMenu();
48 menu_bar->Append(menu_file,
"&File");
55 menu_file->Append(
wxID_CLOSE,
"&Close game\tCtrl-W",
"Close the current game");
59 menu_file->AppendSeparator();
65 auto menu_help =
new wxMenu();
66 menu_bar->Append(menu_help,
"&Help");
73 #if !defined(__WXOSX__)
83 int status_bar_widths[2] = { -3, -1 };
99 progress_hbox->AddStretchSpacer(1);
125 if (panel !=
nullptr) {
141 int result = dialog->ShowModal();
152 panel->update_game_state();
164 :
wxPanel(parent, id), frame(parent) {}
180 title_label->SetFont(title_label->GetFont().MakeBold().Scale(2.0f));
187 buttons_vbox->Add(start_game_btn,
wxSizerFlags().Expand().Border());
191 buttons_vbox->Add(exit_btn,
wxSizerFlags().Expand().Border());
205 start_game_btn->SetFocus();
211 this->game.reset(
game);
222 for (
int i = 0; i <
game->players_count; i++) {
251 panel_grid->AddGrowableCol(1);
252 panel_grid->AddGrowableRow(1);
261 #if ((defined(__WXGTK__) || defined(__WXMSW__)) && wxCHECK_VERSION(3, 1, 3)) || \
262 (defined(__WXOSX__) && wxCHECK_VERSION(3, 1, 6))
278 for (
int y = 0; y <
game->board_height; y++) {
279 for (
int x = 0; x <
game->board_width; x++) {
287 for (
int i = 0; i <
game->players_count; i++) {
289 int border_dir = (i > 0 ?
wxLEFT : 0) | (i + 1 <
game->players_count ?
wxRIGHT : 0);
290 players_box->Add(player_box->GetContainingSizer(),
wxSizerFlags().
Border(border_dir));
302 panel_vbox->Add(panel_grid,
wxSizerFlags(1).Expand().Border());
348 wxFAIL_MSG(
"No appropriate controller for the current game state");
359 if (next_controller !=
nullptr) {
404 size_t new_count = this->
game->log_length;
405 for (
size_t i = old_count; i < new_count; i++) {
408 if (description.
IsEmpty())
continue;
421 return "Start of the game";
424 return "Placement phase";
426 return "Movement phase";
428 return "End of the game";
432 Coords target = entry_data->target;
436 Coords penguin = entry_data->penguin, target = entry_data->target;
438 "(%d, %d) -> (%d, %d)", penguin.
x + 1, penguin.
y + 1, target.x + 1, target.y + 1
445 std::unique_ptr<GameEndDialog> dialog(
453 for (
int i = 0; i <
game->players_count; i++) {
short get_tile(const Game *game, Coords coords)
Returns the value of the tile at coords. Fails if coords are outside the bounds.
void generate_board_random(Game *game, Rng *rng)
Generates the board by setting every tile purely randomly. The resulting board will look sort of like...
void generate_board_island(Game *game, Rng *rng)
Generates the board which looks sort of like a big icy island.
void setup_board(Game *game, int width, int height)
Sets Game::board_width and Game::board_height and allocates Game::board_grid and Game::tile_attribute...
Functions for working with the game board (and the specifics of its encoding)
#define get_tile_fish(tile)
void init_bot_parameters(BotParameters *self)
Initializes all fields of the given BotParameters to default values.
BaseGamePanel(GameFrame *parent, wxWindowID id)
virtual void update_layout()
Responsible for drawing the board and painting the UI overlays.
virtual void on_deactivated(GameController *next_controller)
virtual void on_activated()
void set_panel(BaseGamePanel *panel)
GameFrame(wxWindow *parent, wxWindowID id)
wxMenuItem * menu_close_game
wxWindow * progress_container
wxMenuItem * menu_new_game
BaseGamePanel * current_panel
std::unique_ptr< wxBusyCursor > busy_cursor_changer
wxSizer * game_controls_box
wxString describe_game_log_entry(size_t index) const
GamePanel(GameFrame *parent, wxWindowID id, NewGameDialog *dialog)
wxButton * show_current_turn_btn
void on_show_current_turn_clicked(wxCommandEvent &event)
size_t displayed_log_entries
wxVector< PlayerInfoBox * > player_info_boxes
wxVector< PlayerType > player_types
std::shared_ptr< BotParameters > bot_params
GameController * controller
wxScrolledWindow * scrolled_panel
void set_controller(GameController *next_controller)
std::unique_ptr< Game, decltype(&game_free)> game
void start_bot_progress()
void on_exit_game_clicked(wxCommandEvent &event)
wxVector< wxString > player_names
GameController * get_controller_for_current_turn()
void update_player_info_boxes()
void on_game_log_select(wxCommandEvent &event)
virtual void update_layout() override
GameStartPanel(GameFrame *parent, wxWindowID id)
void SetName(const wxString &name)
void SetIcon(const wxIcon &icon)
void SetVersion(const wxString &version, const wxString &longVersion=wxString())
wxClientData * GetClientObject() const
void Bind(const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
void CallAfter(void(T::*method)(T1,...), T1 x1,...)
virtual void SetStatusText(const wxString &text, int number=0)
void Centre(int direction=wxBOTH)
virtual void SetStatusWidths(int n, const int *widths_field)
virtual void SetMenuBar(wxMenuBar *menuBar)
virtual wxStatusBar * GetStatusBar() const
virtual wxStatusBar * CreateStatusBar(int number=1, long style=wxSTB_DEFAULT_STYLE, wxWindowID id=0, const wxString &name=wxStatusBarNameStr)
int Append(const wxString &item)
virtual void EnsureVisible(int n)
virtual void SetSelection(int n)
wxSizerFlags & Border(int direction, int borderinpixels)
void SetSizeHints(wxWindow *window)
static wxString Format(const wxString &format,...)
virtual bool Start(int milliseconds=-1, bool oneShot=wxTIMER_CONTINUOUS)
virtual void SetIcons(const wxIconBundle &icons)
wxSizer * GetSizer() const
void SetSize(int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO)
void SetInitialSize(const wxSize &size=wxDefaultSize)
bool Close(bool force=false)
void Centre(int direction=wxBOTH)
virtual bool Show(bool show=true)
void SetSizer(wxSizer *sizer, bool deleteOld=true)
void game_set_penguins_per_player(Game *self, int value)
Sets Game::penguins_per_player (the value mustn't be negative) and allocates Player::penguins lists o...
const GameLogEntry * game_get_log_entry(const Game *self, size_t idx)
Returns a pointer to the entry at the given index. Note that the returned pointer is const because th...
void game_begin_setup(Game *self)
Switches to the GAME_PHASE_SETUP phase, can only be called in GAME_PHASE_NONE. Should be called right...
void game_advance_state(Game *self)
The all-in-one phase switcher that progresses of the game.
void game_end_setup(Game *self)
Verifies that all fields have been initialized and configured and switches the phase from GAME_PHASE_...
void game_rewind_state_to_log_entry(Game *self, size_t target_entry)
Successively undoes or redoes log entries in order to reset the game state to the entry at the given ...
void game_set_player_name(Game *self, int idx, const char *name)
Sets the Player::name of a player at the given index. Only available in the GAME_PHASE_SETUP phase.
Game * game_new(void)
Constructs a Game. Allocates memory for storing the struct itself, setting all fields to default valu...
bool game_check_player_index(const Game *self, int idx)
Checks if idx is within the bounds of Game::players.
void game_set_players_count(Game *self, int count)
Sets Game::players_count (the value mustn't be negative) and allocates the Game::players list....
The core of the unified game logic library, contains the Game struct.
@ GAME_PHASE_PLACEMENT
Set by placement_begin.
@ GAME_PHASE_MOVEMENT
Set by movement_begin.
@ GAME_PHASE_SETUP
Set by game_begin_setup.
@ GAME_PHASE_SETUP_DONE
Set by game_end_setup, placement_end, movement_end.
@ GAME_PHASE_END
Set by game_end.
@ GAME_LOG_ENTRY_PHASE_CHANGE
See GameLogPhaseChange.
@ GAME_LOG_ENTRY_PLACEMENT
See GameLogPlacement.
@ GAME_LOG_ENTRY_MOVEMENT
See GameLogMovement.
const wxSize wxDefaultSize
const wxPoint wxDefaultPosition
wxScrolled< wxPanel > wxScrolledWindow
wxAppDerivedClass & wxGetApp()
#define wxASSERT(condition)
#define wxFAIL_MSG(message)
void wxAboutBox(const wxAboutDialogInfo &info, wxWindow *parent=NULL)
wxEventType wxEVT_LISTBOX
bool wxPersistentRegisterAndRestore(T *obj, const wxString &name=wxString())
An implementation of Rng for C++ using the standard functions from <random>.
Various parameters for the bot algorithm.
A pair of 2D coordinates, used for addressing the Game::board_grid.
An entry in the Game::log_buffer, implemented as a tagged union.
union GameLogEntry::GameLogEntryData data
The central struct of the application, holds the game data and settings.
int current_player_index
A negative value means that there is no current player selected. Use game_set_current_player for sett...
int players_count
Use game_set_players_count for setting this.
GameLogPlacement placement
GameLogPhaseChange phase_change