penguins
1.0.0
|
Go to the source code of this file.
Functions for working with the game board (and the specifics of its encoding)
Definition in file board.h.
Macros | |
Macros for encoding/decoding board tiles | |
See Game::board_grid for more info. Also note that since these are macros, they unfortunately may evaluate their arguments multiple times, so don't do stuff like | |
#define | WATER_TILE 0 |
#define | FISH_TILE(fish) ((fish) > 0 ? (fish) : 0) |
#define | PENGUIN_TILE(player_id) ((player_id) > 0 ? -(player_id) : 0) |
#define | is_water_tile(tile) ((tile) == 0) |
#define | is_fish_tile(tile) ((tile) > 0) |
#define | is_penguin_tile(tile) ((tile) < 0) |
#define | get_tile_fish(tile) ((tile) > 0 ? (tile) : 0) |
#define | get_tile_player_id(tile) ((tile) < 0 ? -(tile) : 0) |
Enumerations | |
enum | TileAttribute { TILE_DIRTY , TILE_ATTR_MAX } |
The list of attributes built into the common library. More... | |
Functions | |
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_attributes. Can only be called within GAME_PHASE_SETUP. The width and height values must be positive. More... | |
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 a maze. More... | |
void | generate_board_island (Game *game, Rng *rng) |
Generates the board which looks sort of like a big icy island. More... | |
Functions for accessing the board tiles and attributes | |
All of these are inline because they are used very very frequently in virtually every module of the app, thus in computation-heavy code, such as the bot, inlining those functions enables very efficient optimizations by the compiler (the bot in particular has been sped up 2 times). | |
ALWAYS_INLINE bool | is_tile_in_bounds (const Game *game, Coords coords) |
Checks if the given coords are within the bounds of the board. More... | |
ALWAYS_INLINE bool | get_tile_attr (const Game *game, Coords coords, short attr) |
Checks whether the attribute attr of the tile at coords is set. More... | |
ALWAYS_INLINE void | set_tile_attr (Game *game, Coords coords, short attr, bool value) |
Sets (or resets) the attribute attr of the tile at coords . More... | |
ALWAYS_INLINE void | set_all_tiles_attr (Game *game, short attr, bool value) |
Sets the attribute attr on all tiles. More... | |
ALWAYS_INLINE short | get_tile (const Game *game, Coords coords) |
Returns the value of the tile at coords . Fails if coords are outside the bounds. More... | |
ALWAYS_INLINE void | set_tile (Game *game, Coords coords, short value) |
Sets the value of the tile at coords (and also sets the attribute TILE_DIRTY). Fails if coords are outside the bounds. More... | |
#define PENGUIN_TILE | ( | player_id | ) | ((player_id) > 0 ? -(player_id) : 0) |
#define get_tile_player_id | ( | tile | ) | ((tile) < 0 ? -(tile) : 0) |
enum TileAttribute |
The list of attributes built into the common library.
The variants of this enum are indexes into the bits in the numeric values that the tile attributes are, so they must be sequential numbers starting at zero. Because of this property this enum can be "extended" by UIs as follows:
Enumerator | |
---|---|
TILE_DIRTY | Set when a tile is changed with set_tile, can be unset by the UI. All tiles initially have this attribute on when the board is initialized. |
TILE_ATTR_MAX |
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_attributes. Can only be called within GAME_PHASE_SETUP. The width
and height
values must be positive.
Definition at line 12 of file board.c.
Referenced by GamePanel::GamePanel().
Generates the board by setting every tile purely randomly. The resulting board will look sort of like a maze.
Definition at line 26 of file board.c.
Referenced by GamePanel::GamePanel(), run_autonomous_mode(), and run_interactive_mode().
Generates the board which looks sort of like a big icy island.
Definition at line 37 of file board.c.
Referenced by GamePanel::GamePanel(), and run_autonomous_mode().
|
inline |
Checks if the given coords
are within the bounds of the board.
Definition at line 70 of file board.h.
Referenced by CanvasPanel::get_selected_penguin_coords(), PlayerMovementController::on_mouse_move(), PlayerPlacementController::on_mouse_up(), PlayerMovementController::on_mouse_up(), CanvasPanel::on_paint(), CanvasPanel::paint_board(), PlayerTurnController::paint_overlay(), PlayerMovementController::paint_overlay(), CanvasPanel::paint_tiles(), PlayerPlacementController::update_status_bar(), PlayerMovementController::update_status_bar(), PlayerPlacementController::update_tile_attributes(), and PlayerMovementController::update_tile_attributes().
|
inline |
Checks whether the attribute attr
of the tile at coords
is set.
Definition at line 78 of file board.h.
Referenced by CanvasPanel::on_paint(), CanvasPanel::paint_board(), PlayerTurnController::paint_overlay(), and CanvasPanel::paint_tiles().
|
inline |
Sets (or resets) the attribute attr
of the tile at coords
.
Definition at line 86 of file board.h.
Referenced by PlayerMovementController::on_mouse_move(), CanvasPanel::on_paint(), CanvasPanel::paint_board(), CanvasPanel::paint_tiles(), PlayerPlacementController::update_tile_attributes(), and PlayerMovementController::update_tile_attributes().
|
inline |
Sets the attribute attr
on all tiles.
Definition at line 95 of file board.h.
Referenced by GameController::update_tile_attributes(), PlayerMovementController::update_tile_attributes(), and BotTurnController::update_tile_attributes().
|
inline |
Returns the value of the tile at coords
. Fails if coords
are outside the bounds.
Definition at line 108 of file board.h.
Referenced by GamePanel::GamePanel(), CanvasPanel::get_selected_penguin_coords(), CanvasPanel::paint_board(), CanvasPanel::paint_tiles(), PlayerMovementController::update_status_bar(), and PlayerMovementController::update_tile_attributes().
|
inline |
Sets the value of the tile at coords
(and also sets the attribute TILE_DIRTY). Fails if coords
are outside the bounds.