penguins  1.0.0
board.c File Reference

Go to the source code of this file.

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).

bool is_tile_in_bounds (const Game *game, Coords coords)
 Checks if the given coords are within the bounds of the board. More...
 
bool get_tile_attr (const Game *game, Coords coords, short attr)
 Checks whether the attribute attr of the tile at coords is set. More...
 
void set_tile_attr (Game *game, Coords coords, short attr, bool value)
 Sets (or resets) the attribute attr of the tile at coords. More...
 
void set_all_tiles_attr (Game *game, short attr, bool value)
 Sets the attribute attr on all tiles. More...
 
short get_tile (const Game *game, Coords coords)
 Returns the value of the tile at coords. Fails if coords are outside the bounds. More...
 
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...
 

Function Documentation

◆ setup_board()

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().

◆ generate_board_random()

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.

Definition at line 26 of file board.c.

Referenced by GamePanel::GamePanel(), run_autonomous_mode(), and run_interactive_mode().

◆ generate_board_island()

void generate_board_island ( Game game,
Rng rng 
)

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().

◆ is_tile_in_bounds()

◆ get_tile_attr()

ALWAYS_INLINE bool get_tile_attr ( const Game game,
Coords  coords,
short  attr 
)
inline

Checks whether the attribute attr of the tile at coords is set.

See also
Game::tile_attributes

Definition at line 78 of file board.h.

Referenced by CanvasPanel::on_paint(), CanvasPanel::paint_board(), PlayerTurnController::paint_overlay(), and CanvasPanel::paint_tiles().

◆ set_tile_attr()

ALWAYS_INLINE void set_tile_attr ( Game game,
Coords  coords,
short  attr,
bool  value 
)
inline

◆ set_all_tiles_attr()

ALWAYS_INLINE void set_all_tiles_attr ( Game game,
short  attr,
bool  value 
)
inline

◆ get_tile()

ALWAYS_INLINE short get_tile ( const Game game,
Coords  coords 
)
inline

◆ set_tile()

ALWAYS_INLINE void set_tile ( Game game,
Coords  coords,
short  value 
)
inline

Sets the value of the tile at coords (and also sets the attribute TILE_DIRTY). Fails if coords are outside the bounds.

See also
Game::board_grid

Definition at line 117 of file board.h.