Skip to content

Commit

Permalink
(HyperSim & prissi) roating buildings patch
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@8481 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
prissi committed Jun 2, 2018
1 parent 2ba8961 commit 5b73800
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions simmenu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ tool_t *create_general_tool(int toolnr)
case TOOL_ERROR_MESSAGE: tool = new tool_error_message_t(); break;
case TOOL_CHANGE_WATER_HEIGHT: tool = new tool_change_water_height_t(); break;
case TOOL_SET_CLIMATE: tool = new tool_set_climate_t(); break;
case TOOL_ROTATE_BUILDING: tool = new tool_rotate_building_t(); break;
default: dbg->error("create_general_tool()","cannot satisfy request for general_tool[%i]!",toolnr);
return NULL;
}
Expand Down
1 change: 1 addition & 0 deletions simmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ enum {
TOOL_ERROR_MESSAGE,
TOOL_CHANGE_WATER_HEIGHT,
TOOL_SET_CLIMATE,
TOOL_ROTATE_BUILDING,
GENERAL_TOOL_COUNT,
GENERAL_TOOL = 0x1000
};
Expand Down
91 changes: 91 additions & 0 deletions simtool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "obj/field.h"
#include "obj/label.h"

#include "dataobj/koord.h"
#include "dataobj/settings.h"
#include "dataobj/environment.h"
#include "dataobj/schedule.h"
Expand Down Expand Up @@ -4611,6 +4612,96 @@ const char *tool_build_station_t::work( player_t *player, koord3d pos )
}



const char *tool_rotate_building_t::work( player_t *player, koord3d pos )
{
const grund_t *gr = welt->lookup(pos);
if(!gr) {
return "";
}

if( gebaeude_t* gb = gr->find<gebaeude_t>() ) {

if( !player_t::check_owner( gb->get_owner(), player ) ) {
return "Das Feld gehoert\neinem anderen Spieler\n";
}

// check for harbour (must no rotate)
const building_desc_t *desc = gb->get_tile()->get_desc();
if( desc->get_all_layouts() == 1 ) {
// non rotatable =<> finish
}
if( desc->get_type() == building_desc_t::dock ) {
// cannot roatate a harbour
return "Cannot rotate this building!";
}
if( desc->get_all_layouts()==2 && desc->get_x()!=desc->get_y() ) {
// cannot rotate an aszmmetric building with onlz two rotations
return "Cannot rotate this building!";
}

if( gr->hat_wege() ) {
// this is almost certainlz a station ...
if( desc->get_all_layouts()<16 ) {
// either symmetrical (==2, ==8) or freight loading station, so do not rotate!
return "Cannot rotate this building!";
}
int layout = gb->get_tile()->get_layout();
gb->set_tile( gb->get_tile()->get_desc()->get_tile( layout^8, 0, 0 ), false );
}
else if( desc->get_x()==1 && desc->get_y()==1 ) {
// just rotate single tile buildings
gb->rotate90();
}
else {
// multitile buildings possible!
bool rotate180 = desc->get_x() != desc->get_y();

if( desc->get_x() != desc->get_y() && desc->get_all_layouts()==2 ) {
// asymmetrical with onlz one rotation so do not rotate!
return "Cannot rotate this building!";
}

gb = gb->get_first_tile();
uint8 layout = gb->get_tile()->get_layout();
uint8 newlayout = (layout+1+rotate180) % desc->get_all_layouts();

// first test if all tiles are present (check for holes)
koord k;
for(k.x=0; k.x<desc->get_x(layout); k.x++) {
for(k.y=0; k.y<desc->get_y(layout); k.y++) {
grund_t *gr = welt->lookup( gb->get_pos()+k );
if( !gr ) {
return "Cannot rotate this building!";
}
const building_tile_desc_t *tile = desc->get_tile(newlayout, k.x, k.y);
gebaeude_t *gbt = gr->find<gebaeude_t>();
if( tile==NULL && gbt ) {
return "Cannot rotate this building!";
}
if( tile && gbt==NULL ) {
return "Cannot rotate this building!";
}
}
}
// ok, we can roate it
for(k.x=0; k.x<desc->get_x(layout); k.x++) {
for(k.y=0; k.y<desc->get_y(layout); k.y++) {
grund_t *gr = welt->lookup( gb->get_pos()+k );
// there could be still holes, so the if is needed
if( gebaeude_t *gb = gr->find<gebaeude_t>() ) {
const building_tile_desc_t *tile = desc->get_tile(newlayout, k.x, k.y);
gb->set_tile( tile, false );
}
}
}
}
}
return "";
}



char const* tool_build_roadsign_t::get_tooltip(player_t const*) const
{
const roadsign_desc_t * desc = roadsign_t::find_desc(default_param);
Expand Down
12 changes: 12 additions & 0 deletions simtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,18 @@ class tool_build_station_t : public tool_t {
waytype_t get_waytype() const OVERRIDE;
};

class tool_rotate_building_t : public tool_t {
private:
const char *tool_rotate_platform(koord3d);
const char *tool_rotate_building(koord3d);

public:
tool_rotate_building_t() : tool_t(TOOL_ROTATE_BUILDING | GENERAL_TOOL) {}
char const* get_tooltip(player_t const*) const OVERRIDE { return translator::translate("Rotate Building"); }
char const* work(player_t *, koord3d) OVERRIDE;
bool is_init_network_save() const OVERRIDE { return true; }
};

// builds roadsigns and signals
class tool_build_roadsign_t : public two_click_tool_t {
private:
Expand Down

0 comments on commit 5b73800

Please sign in to comment.