6
6
#include " city/finance.h"
7
7
#include " building/properties.h"
8
8
#include " graphics/view/view.h"
9
+ #include " graphics/view/lookup.h"
9
10
#include " grid/grid.h"
10
11
11
12
#include " graphics/animation.h"
12
13
#include " js/js_game.h"
13
14
#include " city/labor.h"
14
15
15
- constexpr int MAX_TILES = 25 ;
16
-
17
16
namespace model {
18
17
19
18
struct fort_t {
20
19
static constexpr e_building_type type = BUILDING_COURTHOUSE;
21
20
e_labor_category labor_category;
22
21
animations_t anim;
23
22
struct {
24
- vec2i main_view_offset[4 ];
25
- vec2i ground_view_offset[4 ];
23
+ std::vector<vec2i> main_view_offset;
24
+ std::vector<vec2i> ground_view_offset;
25
+ std::vector<vec2i> ground_check_offset;
26
26
} ghost;
27
27
};
28
28
@@ -37,26 +37,21 @@ void config_load_building_fort() {
37
37
model::fort.anim .load (arch);
38
38
39
39
arch.r_section (" ghost" , [] (archive ghost_arch) {
40
- model::fort.ghost .main_view_offset [0 ] = ghost_arch.r_vec2i (" main_N" );
41
- model::fort.ghost .main_view_offset [1 ] = ghost_arch.r_vec2i (" main_W" );
42
- model::fort.ghost .main_view_offset [2 ] = ghost_arch.r_vec2i (" main_S" );
43
- model::fort.ghost .main_view_offset [3 ] = ghost_arch.r_vec2i (" main_E" );
44
- model::fort.ghost .ground_view_offset [0 ] = ghost_arch.r_vec2i (" ground_N" );
45
- model::fort.ghost .ground_view_offset [1 ] = ghost_arch.r_vec2i (" ground_W" );
46
- model::fort.ghost .ground_view_offset [2 ] = ghost_arch.r_vec2i (" ground_S" );
47
- model::fort.ghost .ground_view_offset [3 ] = ghost_arch.r_vec2i (" ground_E" );
40
+ model::fort.ghost .main_view_offset = ghost_arch.r_array_vec2i (" main" );
41
+ model::fort.ghost .ground_view_offset = ghost_arch.r_array_vec2i (" ground" );
42
+ model::fort.ghost .ground_check_offset = ghost_arch.r_array_vec2i (" ground_check" );
48
43
});
49
44
});
50
45
51
46
city_labor_set_category (model::fort);
52
47
}
53
48
54
- static const int FORT_GROUND_GRID_OFFSETS_PH[ 4 ][ 4 ] = {
55
- { GRID_OFFSET ( 3 , - 1 ), GRID_OFFSET ( 4 , - 1 ), GRID_OFFSET ( 4 , 0 ), GRID_OFFSET ( 3 , 0 )},
56
- { GRID_OFFSET (- 1 , - 4 ), GRID_OFFSET ( 0 , - 4 ), GRID_OFFSET ( 0 , - 3 ), GRID_OFFSET (- 1 , - 3 )},
57
- { GRID_OFFSET (- 4 , 0 ), GRID_OFFSET (- 3 , 0 ), GRID_OFFSET (- 3 , 1 ), GRID_OFFSET (- 4 , 1 )},
58
- { GRID_OFFSET ( 0 , 3 ), GRID_OFFSET ( 1 , 3 ), GRID_OFFSET ( 1 , 4 ), GRID_OFFSET ( 0 , 4 ) }
59
- };
49
+ void draw_partially_blocked (painter &ctx, int fully_blocked, const std::vector<blocked_tile> &blocked_tiles) {
50
+ for ( auto &tile: blocked_tiles) {
51
+ vec2i pixel = tile_to_pixel (tile. tile );
52
+ draw_flat_tile (ctx, pixel. x , pixel. y , (fully_blocked || tile. blocked ) ? COLOR_MASK_RED : COLOR_MASK_GREEN);
53
+ }
54
+ }
60
55
61
56
void draw_fort_ghost (painter &ctx, e_building_type build_type, tile2i &tile, vec2i pixel) {
62
57
bool fully_blocked = false ;
@@ -66,38 +61,37 @@ void draw_fort_ghost(painter &ctx, e_building_type build_type, tile2i &tile, vec
66
61
blocked = true ;
67
62
}
68
63
69
- int num_tiles_fort = building_properties_for_type (BUILDING_FORT_ARCHERS)->size ;
70
- num_tiles_fort *= num_tiles_fort;
71
- int num_tiles_ground = building_properties_for_type (BUILDING_FORT_GROUND)->size ;
72
- num_tiles_ground *= num_tiles_ground;
64
+ int fort_size = building_properties_for_type (BUILDING_FORT_ARCHERS)->size ;
65
+ int ground_size = building_properties_for_type (BUILDING_FORT_GROUND)->size ;
73
66
74
67
// int grid_offset_fort = tile->grid_offset;
75
68
int global_rotation = building_rotation_global_rotation ();
76
- int grid_offset_ground = tile.grid_offset () + FORT_GROUND_GRID_OFFSETS_PH[global_rotation][city_view_orientation () / 2 ];
69
+ vec2i tile_ground_offset = model::fort.ghost .ground_check_offset [global_rotation * 4 + (city_view_orientation () / 2 )];
70
+ tile2i tile_ground = tile.shifted (tile_ground_offset.x , tile_ground_offset.y );
77
71
78
- int blocked_tiles_fort[MAX_TILES] ;
79
- int blocked_tiles_ground[MAX_TILES] ;
72
+ std::vector<blocked_tile> blocked_tiles_fort;
73
+ std::vector<blocked_tile> blocked_tiles_ground;
80
74
81
- blocked += is_blocked_for_building (tile. grid_offset (), num_tiles_fort , blocked_tiles_fort);
82
- blocked += is_blocked_for_building (grid_offset_ground, num_tiles_ground , blocked_tiles_ground);
75
+ blocked += is_blocked_for_building (tile, fort_size , blocked_tiles_fort);
76
+ blocked += is_blocked_for_building (tile_ground, ground_size , blocked_tiles_ground);
83
77
84
78
int orientation_index = building_rotation_get_storage_fort_orientation (global_rotation) / 2 ;
85
- vec2i main = pixel + model::fort.ghost .main_view_offset [orientation_index];
86
- vec2i ground = pixel + model::fort.ghost .ground_view_offset [orientation_index];
79
+ vec2i main_pixel = pixel + model::fort.ghost .main_view_offset [orientation_index];
80
+ vec2i ground_pixel = pixel + model::fort.ghost .ground_view_offset [orientation_index];
87
81
88
82
if (blocked) {
89
- draw_partially_blocked (ctx, pixel, fully_blocked, num_tiles_fort , blocked_tiles_fort);
90
- draw_partially_blocked (ctx, ground, fully_blocked, num_tiles_ground , blocked_tiles_ground);
83
+ draw_partially_blocked (ctx, fully_blocked, blocked_tiles_fort);
84
+ draw_partially_blocked (ctx, fully_blocked, blocked_tiles_ground);
91
85
} else {
92
86
int image_id = image_id_from_group (GROUP_BUILDING_FORT);
93
87
if (orientation_index == 0 || orientation_index == 3 ) {
94
88
// draw fort first, then ground
95
- draw_building_ghost (ctx, image_id, main );
96
- draw_building_ghost (ctx, image_id + 1 , ground );
89
+ draw_building_ghost (ctx, image_id, main_pixel );
90
+ draw_building_ghost (ctx, image_id + 1 , ground_pixel );
97
91
} else {
98
92
// draw ground first, then fort
99
- draw_building_ghost (ctx, image_id + 1 , ground );
100
- draw_building_ghost (ctx, image_id, main );
93
+ draw_building_ghost (ctx, image_id + 1 , ground_pixel );
94
+ draw_building_ghost (ctx, image_id, main_pixel );
101
95
}
102
96
}
103
97
}
0 commit comments