Skip to content

Commit

Permalink
cleanup wayobj_besch_t interface
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@8012 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
Dwachs committed Jan 7, 2017
1 parent d00395c commit 5ac31ab
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 29 deletions.
32 changes: 12 additions & 20 deletions besch/way_obj_besch.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ class tool_t;
class checksum_t;

/**
* Way type description. Contains all needed values to describe a
* way type in Simutrans.
* Way objects type description (like overhead lines).
*
* Child nodes:
* 0 Name
* 1 Copyright
* 2 Flache Bilder mit ribis
* 3 Hangbilder
* 4 Flache Bilder Diagonalstrecken
* 5 Hajo: Skin (cursor and icon)
* Child nodes:
* 0 Name
* 1 Copyright
* 2 Image on flat ways
* 3 Image on sloped ways
* 4 Image on diagonal ways
* 5 Skin (cursor and icon)
*
* @author Volker Meyer, Hj. Malthaner
*/
Expand All @@ -38,21 +37,14 @@ class way_obj_desc_t : public obj_desc_transport_infrastructure_t {

private:

/**
* set to powerline of overheadwire or ignore
* @see waytype_t
* @author Hj. Malthaner
*/
/**
* Type of the object, only overheadlines_wt is currently used.
*/
uint8 own_wtyp;

public:

/**
* returns the system type of this way (mostly used with rails)
* @see weg_t::styp
* @author DarioK
*/
waytype_t get_own_wtyp() const { return (waytype_t)own_wtyp; }
bool is_overhead_line() const { return (waytype_t)own_wtyp == overheadlines_wt; }

// way objects can have a front and a backimage, unlike ways ...
image_id get_front_image_id(ribi_t::ribi ribi) const { return get_child<image_list_t>(2)->get_image_id(ribi); }
Expand Down
10 changes: 5 additions & 5 deletions obj/wayobj.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ wayobj_t::~wayobj_t()
if(get_owner()) {
player_t::add_maintenance(get_owner(), -desc->get_wartung(), get_waytype());
}
if(desc->get_own_wtyp()==overheadlines_wt) {
if(desc->is_overhead_line()) {
grund_t *gr=welt->lookup(get_pos());
weg_t *weg=NULL;
if(gr) {
Expand Down Expand Up @@ -202,7 +202,7 @@ void wayobj_t::finish_rd()
}

// electrify a way if we are a catenary
if(desc->get_own_wtyp()==overheadlines_wt) {
if(desc->is_overhead_line()) {
const waytype_t wt = (desc->get_wtyp()==tram_wt) ? track_wt : desc->get_wtyp();
weg_t *weg = welt->lookup(get_pos())->get_weg(wt);
if(weg) {
Expand Down Expand Up @@ -407,7 +407,7 @@ bool wayobj_t::successfully_loaded()
way_obj_desc_t const* def = 0;
FOR(stringhashtable_tpl<way_obj_desc_t const*>, const& i, table) {
way_obj_desc_t const& b = *i.value;
if (b.get_own_wtyp() != overheadlines_wt) continue;
if (!b.is_overhead_line()) continue;
if (b.get_wtyp() != track_wt) continue;
if (def && def->get_topspeed() >= b.get_topspeed()) continue;
def = &b;
Expand Down Expand Up @@ -483,11 +483,11 @@ void wayobj_t::fill_menu(tool_selector_t *tool_selector, waytype_t wtyp, sint16
}


const way_obj_desc_t *wayobj_t::wayobj_search(waytype_t wt, waytype_t own, uint16 time)
const way_obj_desc_t *wayobj_t::get_overhead_line(waytype_t wt, uint16 time)
{
FOR(stringhashtable_tpl<way_obj_desc_t const*>, const& i, table) {
way_obj_desc_t const* const desc = i.value;
if( desc->is_available(time) && desc->get_wtyp()==wt && desc->get_own_wtyp()==own ) {
if( desc->is_available(time) && desc->get_wtyp()==wt && desc->is_overhead_line() ) {
return desc;
}
}
Expand Down
2 changes: 1 addition & 1 deletion obj/wayobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class wayobj_t : public obj_no_info_t
static bool successfully_loaded();

// search an object (currently only used by AI for caternary)
static const way_obj_desc_t *wayobj_search(waytype_t wt,waytype_t own,uint16 time);
static const way_obj_desc_t *get_overhead_line(waytype_t wt, uint16 time);

static const way_obj_desc_t *find_desc(const char *);

Expand Down
2 changes: 1 addition & 1 deletion player/ai_goods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ void ai_goods_t::create_rail_transport_vehikel(const koord platz1, const koord p
// probably need to electrify the track?
if( rail_engine->get_engine_type()==vehikel_besch_t::electric ) {
// we need overhead wires
const way_obj_desc_t *e = wayobj_t::wayobj_search(track_wt,overheadlines_wt,welt->get_timeline_year_month());
const way_obj_desc_t *e = wayobj_t::get_overhead_line(track_wt, welt->get_timeline_year_month());
tool_build_wayobj_t tool;
tool.set_default_param(e->get_name());
tool.init( this );
Expand Down
4 changes: 2 additions & 2 deletions simtool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3236,7 +3236,7 @@ const char* tool_build_wayobj_t::get_tooltip(const player_t *) const
if(desc) {
tooltip_with_price_maintenance( welt, desc->get_name(), -desc->get_preis(), desc->get_wartung() );
size_t n= strlen(toolstr);
if (desc->get_own_wtyp()==overheadlines_wt) {
if (desc->is_overhead_line()) {
// only overheadlines impose topspeed
sprintf(toolstr+n, ", %dkm/h", desc->get_topspeed());
}
Expand All @@ -3257,7 +3257,7 @@ const way_obj_desc_t *tool_build_wayobj_t::get_desc() const
if(desc==NULL) {
desc = default_electric;
if(desc==NULL) {
desc = wayobj_t::wayobj_search( track_wt, overheadlines_wt, welt->get_timeline_year_month() );
desc = wayobj_t::get_overhead_line( track_wt, welt->get_timeline_year_month() );
}
}
return desc;
Expand Down

0 comments on commit 5ac31ab

Please sign in to comment.