Enabled building buildings through RFR

develop
JapaMala 2018-07-02 00:37:02 +05:30
parent d9b910f79c
commit c489147657
2 changed files with 66 additions and 29 deletions

@ -53,6 +53,7 @@ message SidebarCommand
optional proto.enums.ui_sidebar_mode.ui_sidebar_mode mode = 1; optional proto.enums.ui_sidebar_mode.ui_sidebar_mode mode = 1;
optional int32 menu_index = 2; optional int32 menu_index = 2;
optional MenuAction action = 3; optional MenuAction action = 3;
optional RemoteFortressReader.Coord selection_coord = 4;
} }
message BuiildReqChoice message BuiildReqChoice
@ -80,4 +81,9 @@ message BuildSelector
repeated BuildItemReq requirements = 5; repeated BuildItemReq requirements = 5;
optional int32 req_index = 6; optional int32 req_index = 6;
repeated string errors = 7; repeated string errors = 7;
optional int32 radius_x_low = 8;
optional int32 radius_y_low = 9;
optional int32 radius_x_high = 10;
optional int32 radius_y_high = 11;
optional RemoteFortressReader.Coord cursor = 12;
} }

@ -41,16 +41,16 @@ void GetBuildingSize(
int16_t type, int16_t type,
int16_t subtype, int16_t subtype,
int16_t custom, int16_t custom,
int16_t &x_min, int16_t &rad_x_low,
int16_t &y_min, int16_t &rad_y_low,
int16_t &x_max, int16_t &rad_x_high,
int16_t &y_max int16_t &rad_y_high
) )
{ {
x_min = 0; rad_x_low = 0;
y_min = 0; rad_y_low = 0;
x_max = 0; rad_x_high = 0;
y_max = 0; rad_y_high = 0;
df::building_def* customBuilding = 0; df::building_def* customBuilding = 0;
switch (type) switch (type)
{ {
@ -65,30 +65,32 @@ void GetBuildingSize(
case building_type::AxleHorizontal: case building_type::AxleHorizontal:
case building_type::WaterWheel: case building_type::WaterWheel:
case building_type::Rollers: case building_type::Rollers:
{
bool widthOdd = world->building_width % 2; bool widthOdd = world->building_width % 2;
x_min = world->building_width / 2; rad_x_low = world->building_width / 2;
if(widthOdd) if(widthOdd)
x_max = world->building_width / 2; rad_x_high = world->building_width / 2;
else else
x_max = (world->building_width / 2) - 1; rad_x_high = (world->building_width / 2) - 1;
bool heightOdd = world->building_width % 2; bool heightOdd = world->building_width % 2;
y_min = world->building_height / 2; rad_y_low = world->building_height / 2;
if (widthOdd) if (widthOdd)
y_max = world->building_height / 2; rad_y_high = world->building_height / 2;
else else
y_max = (world->building_height / 2) - 1; rad_y_high = (world->building_height / 2) - 1;
}
return; return;
case building_type::Furnace: case building_type::Furnace:
if (subtype != furnace_type::Custom) if (subtype != furnace_type::Custom)
{ {
x_min = y_min = x_max = y_max = 1; rad_x_low = rad_y_low = rad_x_high = rad_y_high = 1;
return; return;
} }
customBuilding = binsearch_in_vector(world->raws.buildings.furnaces, custom); customBuilding = world->raws.buildings.furnaces[custom];
break; break;
case building_type::TradeDepot: case building_type::TradeDepot:
case building_type::Shop: case building_type::Shop:
x_min = y_min = x_max = y_max = 2; rad_x_low = rad_y_low = rad_x_high = rad_y_high = 2;
return; return;
case building_type::Workshop: case building_type::Workshop:
switch (subtype) switch (subtype)
@ -112,14 +114,14 @@ void GetBuildingSize(
case workshop_type::Kitchen: case workshop_type::Kitchen:
case workshop_type::Ashery: case workshop_type::Ashery:
case workshop_type::Dyers: case workshop_type::Dyers:
x_min = y_min = x_max = y_max = 1; rad_x_low = rad_y_low = rad_x_high = rad_y_high = 1;
return; return;
case workshop_type::Siege: case workshop_type::Siege:
case workshop_type::Kennels: case workshop_type::Kennels:
x_min = y_min = x_max = y_max = 2; rad_x_low = rad_y_low = rad_x_high = rad_y_high = 2;
return; return;
case workshop_type::Custom: case workshop_type::Custom:
customBuilding = binsearch_in_vector(world->raws.buildings.workshops, custom); customBuilding = world->raws.buildings.workshops[custom];
break; break;
default: default:
return; return;
@ -128,17 +130,17 @@ void GetBuildingSize(
case building_type::SiegeEngine: case building_type::SiegeEngine:
case building_type::Wagon: case building_type::Wagon:
case building_type::Windmill: case building_type::Windmill:
x_min = y_min = x_max = y_max = 1; rad_x_low = rad_y_low = rad_x_high = rad_y_high = 1;
return; return;
default: default:
return; return;
} }
if (customBuilding) if (customBuilding)
{ {
x_min = customBuilding->workloc_x; rad_x_low = customBuilding->workloc_x;
y_min = customBuilding->workloc_y; rad_y_low = customBuilding->workloc_y;
x_max = customBuilding->dim_x - x_min - 1; rad_x_high = customBuilding->dim_x - rad_x_low - 1;
y_max = customBuilding->dim_y - y_min - 1; rad_y_high = customBuilding->dim_y - rad_y_low - 1;
return; return;
} }
} }
@ -276,6 +278,19 @@ void CopyBuildMenu(DwarfControl::SidebarState * out)
send_choice->set_num_candidates(choice->getNumCandidates()); send_choice->set_num_candidates(choice->getNumCandidates());
send_choice->set_used_count(choice->getUsedCount()); send_choice->set_used_count(choice->getUsedCount());
} }
int16_t x_low, y_low, x_high, y_high;
GetBuildingSize(build_selector->building_type, build_selector->building_subtype, build_selector->custom_type, x_low, y_low, x_high, y_high);
send_selector->set_radius_x_low(x_low);
send_selector->set_radius_y_low(y_low);
send_selector->set_radius_x_high(x_high);
send_selector->set_radius_y_high(y_high);
if (build_selector->stage >= 1)
{
auto send_cursor = send_selector->mutable_cursor();
send_cursor->set_x(cursor->x);
send_cursor->set_y(cursor->y);
send_cursor->set_z(cursor->z);
}
} }
} }
@ -428,12 +443,28 @@ command_result SetSideMenu(DFHack::color_ostream &stream, const DwarfControl::Si
case ui_sidebar_mode::Build: case ui_sidebar_mode::Build:
if (in->has_action()) if (in->has_action())
{ {
int index = 0;
if (in->has_menu_index()) if (in->has_menu_index())
df::global::ui_sidebar_menus->building.cursor = in->menu_index(); index = in->menu_index();
else if(ui_build_selector->building_type == -1)
df::global::ui_sidebar_menus->building.cursor = 0; df::global::ui_sidebar_menus->building.cursor = index;
break; if (ui_build_selector->stage == 2)
{
ui_build_selector->sel_index = index;
}
}
if (ui_build_selector->stage == 1)
{
if (in->has_selection_coord())
{
df::global::cursor->x = in->selection_coord().x();
df::global::cursor->y = in->selection_coord().y();
df::global::cursor->z = in->selection_coord().z();
getCurViewscreen()->feed_key(interface_key::CURSOR_LEFT);
getCurViewscreen()->feed_key(interface_key::CURSOR_RIGHT);
}
} }
break;
default: default:
break; break;
} }