Skip to content

Commit

Permalink
mastaba: finalize mastaba on phase 8
Browse files Browse the repository at this point in the history
  • Loading branch information
s.kushnirenko committed Jan 10, 2024
1 parent 054710e commit fde66f6
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 29 deletions.
12 changes: 7 additions & 5 deletions src/building/construction/build_planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,27 @@ static void add_mastaba(building *b, int orientation) {
{ BUILDING_SMALL_MASTABA_ENTRANCE, {2, 4}}, { BUILDING_SMALL_MASTABA_WALL, {0, 4}},
{ BUILDING_SMALL_MASTABA_WALL, {0, 6}}, { BUILDING_SMALL_MASTABA_WALL, {2, 6}},
{ BUILDING_SMALL_MASTABA_SIDE, {0, 8}}, { BUILDING_SMALL_MASTABA_SIDE, {2, 8}} };
break;
break;
case 1: parts = {{ BUILDING_SMALL_MASTABA, {-2, 0}},
{ BUILDING_SMALL_MASTABA_WALL, {0, 2}}, {BUILDING_SMALL_MASTABA_WALL, {-2, 2}},
{ BUILDING_SMALL_MASTABA_ENTRANCE, {0, 4}}, { BUILDING_SMALL_MASTABA_WALL, {-2, 4}},
{ BUILDING_SMALL_MASTABA_WALL, {0, 6}}, { BUILDING_SMALL_MASTABA_WALL, {-2, 6}},
{ BUILDING_SMALL_MASTABA_SIDE, {0, 8}}, { BUILDING_SMALL_MASTABA_SIDE, {-2, 8}} };
break;
break;
case 2: parts = {{ BUILDING_SMALL_MASTABA, {-2, -8}}, { BUILDING_SMALL_MASTABA, {0, -8}},
{ BUILDING_SMALL_MASTABA_WALL, {0, -2}}, { BUILDING_SMALL_MASTABA_WALL, {-2, -2}},
{ BUILDING_SMALL_MASTABA_ENTRANCE, {0, -4}}, { BUILDING_SMALL_MASTABA_WALL, {-2, -4}},
{ BUILDING_SMALL_MASTABA_WALL, {0, -6}}, { BUILDING_SMALL_MASTABA_WALL, {-2, -6}},
{ BUILDING_SMALL_MASTABA_SIDE, {-2, 0}}
};
b->type = BUILDING_SMALL_MASTABA_SIDE;
break;
case 3: parts = {{ BUILDING_SMALL_MASTABA_SIDE, {0, -8}}, { BUILDING_SMALL_MASTABA_SIDE, {2, -8}},
case 3: parts = {{ BUILDING_SMALL_MASTABA, {0, -8}}, { BUILDING_SMALL_MASTABA, {2, -8}},
{ BUILDING_SMALL_MASTABA_WALL, {0, -6}}, { BUILDING_SMALL_MASTABA_WALL, {2, -6}},
{ BUILDING_SMALL_MASTABA_ENTRANCE, {0, -4}}, { BUILDING_SMALL_MASTABA_WALL, {2, -4}},
{ BUILDING_SMALL_MASTABA_ENTRANCE, {2, -4}}, { BUILDING_SMALL_MASTABA_WALL, {0, -4}},
{ BUILDING_SMALL_MASTABA_WALL, {0, -2}}, {BUILDING_SMALL_MASTABA_WALL, {2, -2}},
{ BUILDING_SMALL_MASTABA, {2, 0}} };
{ BUILDING_SMALL_MASTABA_SIDE, {2, 0}} };
b->type = BUILDING_SMALL_MASTABA_SIDE;
break;
}

Expand Down
55 changes: 35 additions & 20 deletions src/building/monument_mastaba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,37 @@ tile2i building_small_mastaba_tile4work(building *b) {
return map_grid_area_first(tiles, [] (tile2i tile) { return !map_monuments_get_progress(tile); });
}

void building_small_mastabe_update_images(building *b, int curr_phase) {
building *main = b->main();
building *part = b;

while (part) {
int image_id = 0;
if (curr_phase < 2) {
image_id = building_small_mastabe_get_image(b->data.monuments.orientation, part->tile, main->tile, main->tile.shifted(3, 9));
} else {
image_id = building_small_mastabe_get_bricks_image(b->data.monuments.orientation, part->type, part->tile, main->tile, main->tile.shifted(3, 9), curr_phase - 2);
}
for (int dy = 0; dy < part->size; dy++) {
for (int dx = 0; dx < part->size; dx++) {
int grid_offset = part->tile.shifted(dx, dy).grid_offset();
map_image_set(grid_offset, image_id);
}
}
part = part->has_next() ? part->next() : nullptr;
}
}

void building_small_mastabe_finalize(building *b) {
building *part = b;
building *main = b->main();
building_small_mastabe_update_images(b, 8);
while (!!part) {
part->data.monuments.phase = MONUMENT_FINISHED;
part = part->has_next() ? part->next() : nullptr;
}
}

void building_small_mastabe_update_day(building *b) {
if (!building_monument_is_monument(b)) {
return;
Expand All @@ -87,11 +118,7 @@ void building_small_mastabe_update_day(building *b) {
}

if (b->data.monuments.phase >= 8) {
building *part = b;
while (!!part) {
part->data.monuments.phase = MONUMENT_FINISHED;
part = part->has_next() ? part->next() : nullptr;
}
building_small_mastabe_finalize(b);
return;
}

Expand All @@ -102,22 +129,10 @@ void building_small_mastabe_update_day(building *b) {
building *part = b;
if (all_tiles_finished) {
int curr_phase = b->data.monuments.phase;
int next_phase = curr_phase + 1;
map_grid_area_foreach(tiles, [] (tile2i tile) { map_monuments_set_progress(tile, 0); });
building_small_mastabe_update_images(b, curr_phase);
while (part) {
map_grid_area_foreach(tiles, [] (tile2i tile) { map_monuments_set_progress(tile, 0); });
int image_id = 0;
if (curr_phase < 2) {
image_id = building_small_mastabe_get_image(b->data.monuments.orientation, part->tile, main->tile, main->tile.shifted(3, 9));
} else {
image_id = building_small_mastabe_get_bricks_image(b->data.monuments.orientation, part->type, part->tile, main->tile, main->tile.shifted(3, 9), curr_phase - 2);
}
for (int dy = 0; dy < part->size; dy++) {
for (int dx = 0; dx < part->size; dx++) {
int grid_offset = part->tile.shifted(dx, dy).grid_offset();
map_image_set(grid_offset, image_id);
}
}
building_monument_set_phase(part, next_phase);
building_monument_set_phase(part, curr_phase + 1);
part = part->has_next() ? part->next() : nullptr;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/building/monument_mastaba.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ void map_mastaba_tiles_add(int building_id, tile2i tile, int size, int image_id,
void draw_small_mastaba_anim_flat(painter &ctx, vec2i pixel, building *b, int color_mask);
void draw_small_mastaba_anim(painter &ctx, vec2i pixel, building *b, int color_mask);
int building_small_mastabe_get_image(int orientation, tile2i tile, tile2i start, tile2i end);
void building_small_mastabe_update_images(building *b, int curr_phase);
void building_small_mastabe_update_day(building *b);
int building_small_mastabe_get_image(int orientation, tile2i tile, tile2i start, tile2i end);
tile2i building_small_mastaba_bricks_waiting_tile(building *b);
tile2i building_small_mastaba_tile4work(building *b);
int building_small_mastabe_get_bricks_image(int orientation, e_building_type type, tile2i tile, tile2i start, tile2i end, int layer);
13 changes: 12 additions & 1 deletion src/grid/orientation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

#include "building.h"
#include "building/rotation.h"
#include "building/construction/build_planner.h"
#include "building/monuments.h"
#include "building/construction/build_planner.h"
#include "building/monument_mastaba.h"
#include "building/building_statue.h"
#include "core/direction.h"
#include "core/log.h"
Expand Down Expand Up @@ -185,6 +186,16 @@ void map_orientation_update_buildings(void) {
map_add_bandstand_tiles(b);
}
break;
case BUILDING_SMALL_MASTABA:
case BUILDING_SMALL_MASTABA_ENTRANCE:
case BUILDING_SMALL_MASTABA_SIDE:
if (building_monument_is_finished(b)) {
building *main = b->main();
int image_id = building_small_mastabe_get_bricks_image(b->data.monuments.orientation, b->type, b->tile, main->tile, main->tile.shifted(3, 9), 6);
map_building_tiles_add(i, b->tile, b->size, image_id, TERRAIN_BUILDING);
}
break;

case BUILDING_LARGE_STATUE:
case BUILDING_MEDIUM_STATUE:
case BUILDING_SMALL_STATUE:
Expand Down
8 changes: 5 additions & 3 deletions src/widget/city/tile_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "core/svector.h"
#include "building/construction/build_planner.h"
#include "graphics/view/view.h"
#include "building/monuments.h"
#include "game/state.h"
#include "graphics/boilerplate.h"
#include "grid/building.h"
Expand Down Expand Up @@ -272,10 +273,11 @@ bool draw_isometric_flat_building(building *b, tile2i point, painter &ctx) {
case BUILDING_SMALL_MASTABA_WALL:
case BUILDING_SMALL_MASTABA_ENTRANCE:
case BUILDING_SMALL_MASTABA: {
if (b->data.monuments.phase == 0) {
tile_id = map_image_at(point.grid_offset());
if (building_monument_is_finished(b)) {
return false;
}
return true;

return ( b->data.monuments.phase < 2);
}
break;

Expand Down

0 comments on commit fde66f6

Please sign in to comment.