#ifndef RULES_H
#define RULES_H

/* Number of tiles in the game */
#define NUM_GAME_TILES  128

/* Tile graphics size */
#define TILE_SIZE    48

/* Tile flags */
#define TILEF_SHIELD    0x0001
#define TILEF_MONASTERY 0x0002
#define TILEF_CATHEDRAL 0x0004
#define TILEF_INN       0x0010

#define TILEF_TRADE1    0x0100
#define TILEF_TRADE2    0x0200
#define TILEF_TRADE3    0x0300
#define TILEF_TRADEANY  0x0300

#define TILEF_BONUS     0x0fff   /* Tile bonuses */

#define TILEF_DBLBEND   0x1000   /* Double bend */
#define TILEF_BRIDGE    0x2000   /* Road bridge */
#define TILEF_CBRIDGE   0x4000   /* City bridge */

#define TILEF_MOD       0xf000   /* Tile modifiers */

/* Identifier to indicate an end of a tile list */
#define NOTILE          -1

/* Types of men */
#define PEASANTS        0
#define BIGMEN          1
#define MASTERBUILDERS  2
#define PIGS            3
#define MENTYPES        4

/* And also in singular */
#define PEASANT         PEASANTS        
#define BIGMAN          BIGMEN          
#define MASTERBUILDER   MASTERBUILDERS  
#define PIG             PIGS            

/* Feature types */
#define FEATURE_NONE      -1
#define FEATURE_ROAD       0
#define FEATURE_FARM       1
#define FEATURE_MONASTERY  2
#define FEATURE_CITY       3
#define FEATURE_TYPES      4

/* Trade goods */
#define GOODS_WINE         1
#define GOODS_CLOTH        2
#define GOODS_CORN         3
#define GOODS_TYPES        4


/* Centre of the map */
#define MAP_CX    128
#define MAP_CY    128

/* Rule flags */

/* Rule modifiers */
extern int rule_flags;
extern int city_shield_bonus;
extern int base_farm_multi;
extern int bonus_farm_multi;
extern int game_cathedral_multi;
extern int final_cathedral_multi;
extern int game_inn_multi;
extern int final_inn_multi;
extern int tradegood_bonus;

extern void load_theme(const char *filename);
extern void unload_theme(void);

extern void initialize_tileset(void);

extern void initialize_tiles(void);
extern void destroy_tiles(void);

extern void load_tileset(const char *filename);

extern void initialize_gameboard(void);

extern void initialize_teams(const int peasants, const int bigmen, const int builders, const int pigs);
extern void destroy_teams(void);

extern void rotate_big_tile_270(int id);
extern void rotate_big_tile_180(int id);
extern void rotate_big_tile_90(int id);

extern BITMAP *get_tile_bitmap(int id);

extern int pop_tile(void);
extern int tiles_remaining(void);

extern int get_partial_team_score(const int team_nr, const int ft);
extern int get_team_good_count(const int team_nr, const int ft);
extern int get_team_score(const int team);
extern int get_team_colour(const int team);
extern int get_num_team_names(void);
extern const char *get_team_names(const int c);
extern const RLE_SPRITE *get_feature_man_attribute(int feature_type);
extern const RLE_SPRITE *get_team_man_sprite(const int team, const int type);

extern int get_tile_feature_men(const int tile_id, const int team, const int man_type);
extern int get_team_men_count(const int team, const int type);
extern void place_man(const int tx, const int ty, const int mtx, const int mty, const int team, const int type);

extern BITMAP *get_goods_bitmap(const int type);
extern int get_goods_count(const int team_nr, const int type);

extern void score_tile(int x, int y, int trader);
extern void end_score(void);

extern void connect_tile(int x, int y);
extern void place_tile(int id, int map_x, int map_y);

extern int tile_fits(const int id, const int x, const int y);
extern int tile_fits_anywhere(const int id);
extern int tile_fits_anywhere_anyway(const int id);
extern int can_place_flag(int tile_x, int tile_y, int mx, int my, int team, int type);

extern void draw_flags(BITMAP *dest, int dest_x, int dest_y, int tx, int ty, int team, int type);
extern int count_number_flags(int tx, int ty);
extern void draw_tilemap(BITMAP *dest, int float_tile, int dest_x, int dest_y, int tx, int ty, int w, int h);
#endif
